Skip to content

Commit

Permalink
NETOBSERV-934: Add support for SCTP, ICMPv4/v6 protocols to ebpf agent (
Browse files Browse the repository at this point in the history
netobserv#103)

* Add support for SCTP, ICMP amd ICMPv6 protocols to ebpf code

Signed-off-by: Mohamed Mahmoud <[email protected]>

* update GRPC protobuf definition to include icmp fields

Signed-off-by: msherif1234 <[email protected]>

* Add ICMP and ICMPv6 ipfix support

Signed-off-by: msherif1234 <[email protected]>

* Add ICMPv4/6 ebpf agent support

Signed-off-by: msherif1234 <[email protected]>

* Update unit-test cases

Signed-off-by: msherif1234 <[email protected]>

* Add verifier error check to catch JIT errors

Signed-off-by: msherif1234 <[email protected]>

* update flowlogs dump collector tool to include ICMP

Signed-off-by: msherif1234 <[email protected]>

---------

Signed-off-by: Mohamed Mahmoud <[email protected]>
Signed-off-by: msherif1234 <[email protected]>
  • Loading branch information
msherif1234 authored and shach33 committed Apr 6, 2023
1 parent 351c4d3 commit 2d99585
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 1 deletion.
66 changes: 65 additions & 1 deletion bpf/flows.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,73 @@ static inline bool set_flags(struct tcphdr *th, int direction, u16 *flags) {
*flags |= CWR_FLAG;
}
}

// L4_info structure contains L4 headers parsed information.
struct l4_info_t {
// TCP/UDP/SCTP source port in host byte order
u16 src_port;
// TCP/UDP/SCTP destination port in host byte order
u16 dst_port;
// ICMPv4/ICMPv6 type value
u8 icmp_type;
// ICMPv4/ICMPv6 code value
u8 icmp_code;
// TCP flags
u16 flags;
};

// Extract L4 info for the supported protocols
static inline void fill_l4info(void *l4_hdr_start, void *data_end, u8 protocol,
struct l4_info_t *l4_info) {
switch (protocol) {
case IPPROTO_TCP: {
struct tcphdr *tcp = l4_hdr_start;
if ((void *)tcp + sizeof(*tcp) <= data_end) {
l4_info->src_port = __bpf_ntohs(tcp->source);
l4_info->dst_port = __bpf_ntohs(tcp->dest);
set_flags(tcp, &l4_info->flags);
}
} break;
case IPPROTO_UDP: {
struct udphdr *udp = l4_hdr_start;
if ((void *)udp + sizeof(*udp) <= data_end) {
l4_info->src_port = __bpf_ntohs(udp->source);
l4_info->dst_port = __bpf_ntohs(udp->dest);
}
} break;
case IPPROTO_SCTP: {
struct sctphdr *sctph = l4_hdr_start;
if ((void *)sctph + sizeof(*sctph) <= data_end) {
l4_info->src_port = __bpf_ntohs(sctph->source);
l4_info->dst_port = __bpf_ntohs(sctph->dest);
}
} break;
case IPPROTO_ICMP: {
struct icmphdr *icmph = l4_hdr_start;
if ((void *)icmph + sizeof(*icmph) <= data_end) {
l4_info->icmp_type = icmph->type;
l4_info->icmp_code = icmph->code;
}
} break;
case IPPROTO_ICMPV6: {
struct icmp6hdr *icmp6h = l4_hdr_start;
if ((void *)icmp6h + sizeof(*icmp6h) <= data_end) {
l4_info->icmp_type = icmp6h->icmp6_type;
l4_info->icmp_code = icmp6h->icmp6_code;
}
} break;
default:
break;
}
}

// sets flow fields from IPv4 header information
static inline int fill_iphdr(struct iphdr *ip, void *data_end, flow_id *id, u16 *flags) {
if ((void *)ip + sizeof(*ip) > data_end) {
struct l4_info_t l4_info;
void *l4_hdr_start;

l4_hdr_start = (void *)ip + sizeof(*ip);
if (l4_hdr_start > data_end) {
return DISCARD;
}
return false;
Expand Down
2 changes: 2 additions & 0 deletions pkg/ebpf/bpf_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_bpfeb.o
Binary file not shown.
2 changes: 2 additions & 0 deletions pkg/ebpf/bpf_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_bpfel.o
Binary file not shown.
1 change: 1 addition & 0 deletions pkg/ebpf/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cilium/ebpf/perf"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/perf"
"github.com/cilium/ebpf"
"github.com/cilium/ebpf/ringbuf"
"github.com/cilium/ebpf/rlimit"
"github.com/netobserv/netobserv-ebpf-agent/pkg/ifaces"
Expand Down

0 comments on commit 2d99585

Please sign in to comment.