Skip to content

Commit

Permalink
improve compatibility with OpenCloudOS 7/8/9 and TencentOS Server 2.4…
Browse files Browse the repository at this point in the history
…/3.1 (#91)

closes #89
  • Loading branch information
mozillazg authored Jul 20, 2024
1 parent 9a639ef commit 1fb0f66
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
8 changes: 5 additions & 3 deletions bpf/bpf.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ func (b *BPF) Load(opts Options) error {
}
}

if b.isLegacyKernel || !supportGetSocketCookieWithCgroup() {
if b.isLegacyKernel || !supportCgroupSock() {
log.Debug("will load the objs for legacy kernel")
b.skipAttachCgroup = true
objs := BpfObjectsForLegacyKernel{}
if err = b.spec.LoadAndAssign(&objs, &ebpf.CollectionOptions{
Expand Down Expand Up @@ -261,6 +262,7 @@ func (b *BPF) AttachKprobes() error {

lk, err = link.Kprobe("udp_send_skb", b.objs.KprobeUdpSendSkb, &link.KprobeOptions{})
if err != nil {
log.Debugf("%+v", err)
if strings.Contains(err.Error(), "no such file or directory") {
lk, err = link.Kprobe("udp_sendmsg", b.objs.KprobeUdpSendmsg, &link.KprobeOptions{})
if err != nil {
Expand All @@ -276,7 +278,7 @@ func (b *BPF) AttachKprobes() error {
b.objs.KprobeNfNatPacket, &link.KprobeOptions{})
if err != nil {
if strings.Contains(err.Error(), "nf_nat_packet: not found: no such file or directory") {
log.Warn("current system doest not enable netfilter based NAT feature, skip attach kprobe/nf_nat_packet")
log.Warn("the kernel does not support netfilter based NAT feature, skip attach kprobe/nf_nat_packet")
} else {
return fmt.Errorf("attach kprobe/nf_nat_packet: %w", err)
}
Expand All @@ -289,7 +291,7 @@ func (b *BPF) AttachKprobes() error {
b.objs.KprobeNfNatManipPkt, &link.KprobeOptions{})
if err != nil {
if strings.Contains(err.Error(), "nf_nat_manip_pkt: not found: no such file or directory") {
log.Warn("current system doest not enable netfilter based NAT feature, skip attach kprobe/nf_nat_manip_pkt")
log.Warn("the kernel does not support netfilter based NAT feature, skip attach kprobe/nf_nat_manip_pkt")
} else {
return fmt.Errorf("attach kprobe/nf_nat_manip_pkt: %w", err)
}
Expand Down
10 changes: 7 additions & 3 deletions bpf/bpf_legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,16 @@ func (b *BpfObjects) FromLegacy(o *BpfObjectsForLegacyKernel) {
b.BpfMaps = o.BpfMaps
}

func supportGetSocketCookieWithCgroup() bool {
err := features.HaveProgramHelper(ebpf.CGroupSock, asm.FnGetSocketCookie)
if err != nil {
func supportCgroupSock() bool {
if err := features.HaveProgramHelper(ebpf.CGroupSock, asm.FnGetSocketCookie); err != nil {
log.Debugf("%+v", err)
return false
}
if err := features.HaveProgramHelper(ebpf.CGroupSock, asm.FnGetCurrentTask); err != nil {
log.Debugf("%+v", err)
return false
}

return true
}

Expand Down

0 comments on commit 1fb0f66

Please sign in to comment.