@@ -32,6 +32,7 @@ import (
3232 "kmesh.net/kmesh/bpf/kmesh/bpf2go"
3333 "kmesh.net/kmesh/daemon/options"
3434 "kmesh.net/kmesh/pkg/constants"
35+ "kmesh.net/kmesh/pkg/utils"
3536)
3637
3738type BpfSockConnWorkload struct {
@@ -70,14 +71,21 @@ func (sc *BpfSockConnWorkload) loadKmeshSockConnObjects() (*ebpf.CollectionSpec,
7071 opts ebpf.CollectionOptions
7172 )
7273 opts .Maps .PinPath = sc .Info .MapPath
73- spec , err = bpf2go .LoadKmeshCgroupSockWorkload ()
7474
75- if err != nil || spec == nil {
75+ if utils .KernelVersionLowerThan5_13 () {
76+ spec , err = bpf2go .LoadKmeshCgroupSockWorkloadCompat ()
77+ } else {
78+ spec , err = bpf2go .LoadKmeshCgroupSockWorkload ()
79+ }
80+ if err != nil {
7681 return nil , err
7782 }
7883
7984 SetInnerMap (spec )
8085 setMapPinType (spec , ebpf .PinByName )
86+ // The real difference is in the .o file. The prog and map structures of the structure are exactly the same,
87+ // and the .o file has been loaded into the spec in bpf2go.LoadXX(),so when assigning spec to KmeshCgroupSockWorkloadObjects
88+ // here, there is no need to distinguish the type.
8189 if err = spec .LoadAndAssign (& sc .KmeshCgroupSockWorkloadObjects , & opts ); err != nil {
8290 return nil , err
8391 }
@@ -251,13 +259,14 @@ func (so *BpfSockOpsWorkload) loadKmeshSockopsObjects() (*ebpf.CollectionSpec, e
251259
252260 opts .Maps .PinPath = so .Info .MapPath
253261
254- spec , err = bpf2go .LoadKmeshSockopsWorkload ()
262+ if utils .KernelVersionLowerThan5_13 () {
263+ spec , err = bpf2go .LoadKmeshSockopsWorkloadCompat ()
264+ } else {
265+ spec , err = bpf2go .LoadKmeshSockopsWorkload ()
266+ }
255267 if err != nil {
256268 return nil , err
257269 }
258- if spec == nil {
259- return nil , fmt .Errorf ("error: loadKmeshSockopsObjects() spec is nil" )
260- }
261270
262271 SetInnerMap (spec )
263272 setMapPinType (spec , ebpf .PinByName )
@@ -382,7 +391,13 @@ func (sm *BpfSendMsgWorkload) loadKmeshSendmsgObjects() (*ebpf.CollectionSpec, e
382391 )
383392
384393 opts .Maps .PinPath = sm .Info .MapPath
385- if spec , err = bpf2go .LoadKmeshSendmsg (); err != nil {
394+
395+ if utils .KernelVersionLowerThan5_13 () {
396+ spec , err = bpf2go .LoadKmeshSendmsgCompat ()
397+ } else {
398+ spec , err = bpf2go .LoadKmeshSendmsg ()
399+ }
400+ if err != nil {
386401 return nil , err
387402 }
388403
@@ -518,13 +533,15 @@ func (xa *BpfXdpAuthWorkload) loadKmeshXdpAuthObjects() (*ebpf.CollectionSpec, e
518533 )
519534
520535 opts .Maps .PinPath = xa .Info .MapPath
521- spec , err = bpf2go .LoadKmeshXDPAuth ()
536+
537+ if utils .KernelVersionLowerThan5_13 () {
538+ spec , err = bpf2go .LoadKmeshXDPAuthCompat ()
539+ } else {
540+ spec , err = bpf2go .LoadKmeshXDPAuth ()
541+ }
522542 if err != nil {
523543 return nil , err
524544 }
525- if spec == nil {
526- return nil , fmt .Errorf ("error: loadKmeshXdpAuthObjects() spec is nil" )
527- }
528545
529546 SetInnerMap (spec )
530547 setMapPinType (spec , ebpf .PinByName )
0 commit comments