Skip to content

Commit

Permalink
NETOBSERV-1408: migrating netobserv-agent to TCx for new kernels (#262)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 authored Apr 17, 2024
1 parent 59822b8 commit e41327e
Show file tree
Hide file tree
Showing 17 changed files with 345 additions and 108 deletions.
18 changes: 16 additions & 2 deletions bpf/flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,13 +214,27 @@ static inline int flow_monitor(struct __sk_buff *skb, u8 direction) {
}

SEC("tc_ingress")
int ingress_flow_parse(struct __sk_buff *skb) {
int tc_ingress_flow_parse(struct __sk_buff *skb) {
return flow_monitor(skb, INGRESS);
}

SEC("tc_egress")
int egress_flow_parse(struct __sk_buff *skb) {
int tc_egress_flow_parse(struct __sk_buff *skb) {
return flow_monitor(skb, EGRESS);
}

SEC("tcx_ingress")
int tcx_ingress_flow_parse(struct __sk_buff *skb) {
flow_monitor(skb, INGRESS);
// return TCX_NEXT to allow existing with other TCX hooks
return TCX_NEXT;
}

SEC("tcx_egress")
int tcx_egress_flow_parse(struct __sk_buff *skb) {
flow_monitor(skb, EGRESS);
// return TCX_NEXT to allow existing with other TCX hooks
return TCX_NEXT;
}

char _license[] SEC("license") = "GPL";
7 changes: 7 additions & 0 deletions bpf/headers/vmlinux_amd64.h
Original file line number Diff line number Diff line change
Expand Up @@ -59957,6 +59957,13 @@ struct netdev_notifier_bonding_info {
struct netdev_bonding_info bonding_info;
};

enum tcx_action_base {
TCX_NEXT = -1,
TCX_PASS = 0,
TCX_DROP = 2,
TCX_REDIRECT = 7,
};

enum qdisc_state_t {
__QDISC_STATE_SCHED = 0,
__QDISC_STATE_DEACTIVATED = 1,
Expand Down
7 changes: 7 additions & 0 deletions bpf/headers/vmlinux_arm64.h
Original file line number Diff line number Diff line change
Expand Up @@ -77797,6 +77797,13 @@ struct netdev_notifier_bonding_info {
struct netdev_bonding_info bonding_info;
};

enum tcx_action_base {
TCX_NEXT = -1,
TCX_PASS = 0,
TCX_DROP = 2,
TCX_REDIRECT = 7,
};

enum qdisc_state2_t {
__QDISC_STATE2_RUNNING = 0,
};
Expand Down
7 changes: 7 additions & 0 deletions bpf/headers/vmlinux_s390.h
Original file line number Diff line number Diff line change
Expand Up @@ -96143,6 +96143,13 @@ struct netdev_notifier_bonding_info {
struct netdev_bonding_info bonding_info;
};

enum tcx_action_base {
TCX_NEXT = -1,
TCX_PASS = 0,
TCX_DROP = 2,
TCX_REDIRECT = 7,
};

typedef int (*bpf_op_t)(struct net_device *, struct netdev_bpf *);

struct dev_kfree_skb_cb {
Expand Down
14 changes: 12 additions & 2 deletions bpf/pca.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,22 @@ static inline int export_packet_payload(struct __sk_buff *skb) {
}

SEC("tc_pca_ingress")
int ingress_pca_parse(struct __sk_buff *skb) {
int tc_ingress_pca_parse(struct __sk_buff *skb) {
return export_packet_payload(skb);
}

SEC("tc_pca_egress")
int egress_pca_parse(struct __sk_buff *skb) {
int tc_egress_pca_parse(struct __sk_buff *skb) {
return export_packet_payload(skb);
}

SEC("tcx_pca_ingress")
int tcx_ingress_pca_parse(struct __sk_buff *skb) {
return export_packet_payload(skb);
}

SEC("tcx_pca_egress")
int tcx_egress_pca_parse(struct __sk_buff *skb) {
return export_packet_payload(skb);
}

Expand Down
13 changes: 9 additions & 4 deletions pkg/agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type Flows struct {
type ebpfFlowFetcher interface {
io.Closer
Register(iface ifaces.Interface) error
AttachTCX(iface ifaces.Interface) error

LookupAndDeleteMap(*metrics.Metrics) map[ebpf.BpfFlowId][]ebpf.BpfFlowMetrics
DeleteMapsStaleEntries(timeOut time.Duration)
Expand Down Expand Up @@ -509,10 +510,14 @@ func (f *Flows) onInterfaceAdded(iface ifaces.Interface) {
Debug("interface does not match the allow/exclusion filters. Ignoring")
return
}
alog.WithField("interface", iface).Info("interface detected. Registering flow ebpfFetcher")
if err := f.ebpf.Register(iface); err != nil {
alog.WithField("interface", iface).Info("interface detected. trying to attach TCX hook")
if err := f.ebpf.AttachTCX(iface); err != nil {
alog.WithField("interface", iface).WithError(err).
Warn("can't register flow ebpfFetcher. Ignoring")
return
Info("can't attach to TCx hook flow ebpfFetcher. fall back to use legacy TC hook")
if err := f.ebpf.Register(iface); err != nil {
alog.WithField("interface", iface).WithError(err).
Warn("can't register flow ebpfFetcher. Ignoring")
return
}
}
}
14 changes: 9 additions & 5 deletions pkg/agent/packets_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Packets struct {
type ebpfPacketFetcher interface {
io.Closer
Register(iface ifaces.Interface) error

AttachTCX(iface ifaces.Interface) error
LookupAndDeleteMap(*metrics.Metrics) map[int][]*byte
ReadPerf() (perf.Record, error)
}
Expand Down Expand Up @@ -246,10 +246,14 @@ func (p *Packets) onInterfaceAdded(iface ifaces.Interface) {
Debug("[PCA]interface does not match the allow/exclusion filters. Ignoring")
return
}
plog.WithField("[PCA]interface", iface).Info("interface detected. Registering packets ebpfFetcher")
if err := p.ebpf.Register(iface); err != nil {
plog.WithField("interface", iface).Info("interface detected. trying to attach TCX hook")
if err := p.ebpf.AttachTCX(iface); err != nil {
plog.WithField("[PCA]interface", iface).WithError(err).
Warn("can't register packet ebpfFetcher. Ignoring")
return
Info("can't attach to TCx hook packet ebpfFetcher. fall back to use legacy TC hook")
if err := p.ebpf.Register(iface); err != nil {
plog.WithField("[PCA]interface", iface).WithError(err).
Warn("can't register packet ebpfFetcher. Ignoring")
return
}
}
}
48 changes: 30 additions & 18 deletions pkg/ebpf/bpf_arm64_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/ebpf/bpf_arm64_bpfel.o
Binary file not shown.
48 changes: 30 additions & 18 deletions pkg/ebpf/bpf_powerpc_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/ebpf/bpf_powerpc_bpfel.o
Binary file not shown.
48 changes: 30 additions & 18 deletions pkg/ebpf/bpf_s390_bpfeb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified pkg/ebpf/bpf_s390_bpfeb.o
Binary file not shown.
Loading

0 comments on commit e41327e

Please sign in to comment.