Add ebpf check for failed kernel functions

This commit is contained in:
Vladimir Stoilov 2023-06-14 17:56:01 +03:00
parent cecce3ffcb
commit 2b65e8efe1
3 changed files with 10 additions and 0 deletions

View file

@ -90,6 +90,11 @@ int BPF_PROG(udp_v4_connect, struct sock *sk) {
return 0; return 0;
} }
// ip4_datagram_connect return error
if (sk->__sk_common.skc_dport == 0) {
return 0;
}
// Allocate space for the event. // Allocate space for the event.
struct Event *udp_info; struct Event *udp_info;
udp_info = bpf_ringbuf_reserve(&events, sizeof(struct Event), 0); udp_info = bpf_ringbuf_reserve(&events, sizeof(struct Event), 0);
@ -128,6 +133,11 @@ int BPF_PROG(udp_v6_connect, struct sock *sk) {
return 0; return 0;
} }
// ip6_datagram_connect return error
if (sk->__sk_common.skc_dport == 0) {
return 0;
}
// Make sure its udp6 socket // Make sure its udp6 socket
struct udp6_sock *us = bpf_skc_to_udp6_sock(sk); struct udp6_sock *us = bpf_skc_to_udp6_sock(sk);
if (!us) { if (!us) {