1 #include <uapi/linux/bpf.h>
2 #include <linux/socket.h>
4 #include <uapi/linux/in.h>
5 #include <uapi/linux/in6.h>
6 #include <bpf/bpf_helpers.h>
9 int bpf_prog1(struct bpf_sock
*sk
)
11 char fmt
[] = "socket: family %d type %d protocol %d\n";
12 char fmt2
[] = "socket: uid %u gid %u\n";
13 __u64 gid_uid
= bpf_get_current_uid_gid();
14 __u32 uid
= gid_uid
& 0xffffffff;
15 __u32 gid
= gid_uid
>> 32;
17 bpf_trace_printk(fmt
, sizeof(fmt
), sk
->family
, sk
->type
, sk
->protocol
);
18 bpf_trace_printk(fmt2
, sizeof(fmt2
), uid
, gid
);
20 /* block PF_INET6, SOCK_RAW, IPPROTO_ICMPV6 sockets
21 * ie., make ping6 fail
23 if (sk
->family
== PF_INET6
&&
24 sk
->type
== SOCK_RAW
&&
25 sk
->protocol
== IPPROTO_ICMPV6
)
32 int bpf_prog2(struct bpf_sock
*sk
)
34 char fmt
[] = "socket: family %d type %d protocol %d\n";
36 bpf_trace_printk(fmt
, sizeof(fmt
), sk
->family
, sk
->type
, sk
->protocol
);
38 /* block PF_INET, SOCK_RAW, IPPROTO_ICMP sockets
41 if (sk
->family
== PF_INET
&&
42 sk
->type
== SOCK_RAW
&&
43 sk
->protocol
== IPPROTO_ICMP
)
49 char _license
[] SEC("license") = "GPL";