Skip to content

Commit e41327e

Browse files
authored
NETOBSERV-1408: migrating netobserv-agent to TCx for new kernels (#262)
Signed-off-by: Mohamed Mahmoud <[email protected]>
1 parent 59822b8 commit e41327e

17 files changed

+345
-108
lines changed

bpf/flows.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,27 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
214214
}
215215

216216
SEC("tc_ingress")
217-
int ingress_flow_parse(struct __sk_buff *skb) {
217+
int tc_ingress_flow_parse(struct __sk_buff *skb) {
218218
return flow_monitor(skb, INGRESS);
219219
}
220220

221221
SEC("tc_egress")
222-
int egress_flow_parse(struct __sk_buff *skb) {
222+
int tc_egress_flow_parse(struct __sk_buff *skb) {
223223
return flow_monitor(skb, EGRESS);
224224
}
225225

226+
SEC("tcx_ingress")
227+
int tcx_ingress_flow_parse(struct __sk_buff *skb) {
228+
flow_monitor(skb, INGRESS);
229+
// return TCX_NEXT to allow existing with other TCX hooks
230+
return TCX_NEXT;
231+
}
232+
233+
SEC("tcx_egress")
234+
int tcx_egress_flow_parse(struct __sk_buff *skb) {
235+
flow_monitor(skb, EGRESS);
236+
// return TCX_NEXT to allow existing with other TCX hooks
237+
return TCX_NEXT;
238+
}
239+
226240
char _license[] SEC("license") = "GPL";

bpf/headers/vmlinux_amd64.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59957,6 +59957,13 @@ struct netdev_notifier_bonding_info {
5995759957
struct netdev_bonding_info bonding_info;
5995859958
};
5995959959

59960+
enum tcx_action_base {
59961+
TCX_NEXT = -1,
59962+
TCX_PASS = 0,
59963+
TCX_DROP = 2,
59964+
TCX_REDIRECT = 7,
59965+
};
59966+
5996059967
enum qdisc_state_t {
5996159968
__QDISC_STATE_SCHED = 0,
5996259969
__QDISC_STATE_DEACTIVATED = 1,

bpf/headers/vmlinux_arm64.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77797,6 +77797,13 @@ struct netdev_notifier_bonding_info {
7779777797
struct netdev_bonding_info bonding_info;
7779877798
};
7779977799

77800+
enum tcx_action_base {
77801+
TCX_NEXT = -1,
77802+
TCX_PASS = 0,
77803+
TCX_DROP = 2,
77804+
TCX_REDIRECT = 7,
77805+
};
77806+
7780077807
enum qdisc_state2_t {
7780177808
__QDISC_STATE2_RUNNING = 0,
7780277809
};

bpf/headers/vmlinux_s390.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96143,6 +96143,13 @@ struct netdev_notifier_bonding_info {
9614396143
struct netdev_bonding_info bonding_info;
9614496144
};
9614596145

96146+
enum tcx_action_base {
96147+
TCX_NEXT = -1,
96148+
TCX_PASS = 0,
96149+
TCX_DROP = 2,
96150+
TCX_REDIRECT = 7,
96151+
};
96152+
9614696153
typedef int (*bpf_op_t)(struct net_device *, struct netdev_bpf *);
9614796154

9614896155
struct dev_kfree_skb_cb {

bpf/pca.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,22 @@ static inline int export_packet_payload(struct __sk_buff *skb) {
106106
}
107107

108108
SEC("tc_pca_ingress")
109-
int ingress_pca_parse(struct __sk_buff *skb) {
109+
int tc_ingress_pca_parse(struct __sk_buff *skb) {
110110
return export_packet_payload(skb);
111111
}
112112

113113
SEC("tc_pca_egress")
114-
int egress_pca_parse(struct __sk_buff *skb) {
114+
int tc_egress_pca_parse(struct __sk_buff *skb) {
115+
return export_packet_payload(skb);
116+
}
117+
118+
SEC("tcx_pca_ingress")
119+
int tcx_ingress_pca_parse(struct __sk_buff *skb) {
120+
return export_packet_payload(skb);
121+
}
122+
123+
SEC("tcx_pca_egress")
124+
int tcx_egress_pca_parse(struct __sk_buff *skb) {
115125
return export_packet_payload(skb);
116126
}
117127

pkg/agent/agent.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ type Flows struct {
125125
type ebpfFlowFetcher interface {
126126
io.Closer
127127
Register(iface ifaces.Interface) error
128+
AttachTCX(iface ifaces.Interface) error
128129

129130
LookupAndDeleteMap(*metrics.Metrics) map[ebpf.BpfFlowId][]ebpf.BpfFlowMetrics
130131
DeleteMapsStaleEntries(timeOut time.Duration)
@@ -509,10 +510,14 @@ func (f *Flows) onInterfaceAdded(iface ifaces.Interface) {
509510
Debug("interface does not match the allow/exclusion filters. Ignoring")
510511
return
511512
}
512-
alog.WithField("interface", iface).Info("interface detected. Registering flow ebpfFetcher")
513-
if err := f.ebpf.Register(iface); err != nil {
513+
alog.WithField("interface", iface).Info("interface detected. trying to attach TCX hook")
514+
if err := f.ebpf.AttachTCX(iface); err != nil {
514515
alog.WithField("interface", iface).WithError(err).
515-
Warn("can't register flow ebpfFetcher. Ignoring")
516-
return
516+
Info("can't attach to TCx hook flow ebpfFetcher. fall back to use legacy TC hook")
517+
if err := f.ebpf.Register(iface); err != nil {
518+
alog.WithField("interface", iface).WithError(err).
519+
Warn("can't register flow ebpfFetcher. Ignoring")
520+
return
521+
}
517522
}
518523
}

pkg/agent/packets_agent.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type Packets struct {
4040
type ebpfPacketFetcher interface {
4141
io.Closer
4242
Register(iface ifaces.Interface) error
43-
43+
AttachTCX(iface ifaces.Interface) error
4444
LookupAndDeleteMap(*metrics.Metrics) map[int][]*byte
4545
ReadPerf() (perf.Record, error)
4646
}
@@ -246,10 +246,14 @@ func (p *Packets) onInterfaceAdded(iface ifaces.Interface) {
246246
Debug("[PCA]interface does not match the allow/exclusion filters. Ignoring")
247247
return
248248
}
249-
plog.WithField("[PCA]interface", iface).Info("interface detected. Registering packets ebpfFetcher")
250-
if err := p.ebpf.Register(iface); err != nil {
249+
plog.WithField("interface", iface).Info("interface detected. trying to attach TCX hook")
250+
if err := p.ebpf.AttachTCX(iface); err != nil {
251251
plog.WithField("[PCA]interface", iface).WithError(err).
252-
Warn("can't register packet ebpfFetcher. Ignoring")
253-
return
252+
Info("can't attach to TCx hook packet ebpfFetcher. fall back to use legacy TC hook")
253+
if err := p.ebpf.Register(iface); err != nil {
254+
plog.WithField("[PCA]interface", iface).WithError(err).
255+
Warn("can't register packet ebpfFetcher. Ignoring")
256+
return
257+
}
254258
}
255259
}

pkg/ebpf/bpf_arm64_bpfel.go

Lines changed: 30 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/ebpf/bpf_arm64_bpfel.o

1.8 KB
Binary file not shown.

pkg/ebpf/bpf_powerpc_bpfel.go

Lines changed: 30 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)