1 // SPDX-License-Identifier: GPL-2.0
3 #include "net_shared.h"
4 #include <bpf/bpf_helpers.h>
7 int bpf_prog1(struct bpf_sock *sk)
9 char fmt[] = "socket: family %d type %d protocol %d\n";
10 char fmt2[] = "socket: uid %u gid %u\n";
11 __u64 gid_uid = bpf_get_current_uid_gid();
12 __u32 uid = gid_uid & 0xffffffff;
13 __u32 gid = gid_uid >> 32;
15 bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol);
16 bpf_trace_printk(fmt2, sizeof(fmt2), uid, gid);
18 /* block AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6 sockets
19 * ie., make ping6 fail
21 if (sk->family == AF_INET6 &&
22 sk->type == SOCK_DGRAM &&
23 sk->protocol == IPPROTO_ICMPV6)
30 int bpf_prog2(struct bpf_sock *sk)
32 char fmt[] = "socket: family %d type %d protocol %d\n";
34 bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol);
36 /* block AF_INET, SOCK_DGRAM, IPPROTO_ICMP sockets
39 if (sk->family == AF_INET &&
40 sk->type == SOCK_DGRAM &&
41 sk->protocol == IPPROTO_ICMP)
47 char _license[] SEC("license") = "GPL";