afs: Provide a splice-read wrapper
[linux-block.git] / samples / bpf / sock_flags.bpf.c
CommitLineData
e8acf8f4
DL
1// SPDX-License-Identifier: GPL-2.0
2#include "vmlinux.h"
c2f4f559 3#include "net_shared.h"
7cf245a3 4#include <bpf/bpf_helpers.h>
554ae6e7 5
31b12a41 6SEC("cgroup/sock")
554ae6e7
DA
7int bpf_prog1(struct bpf_sock *sk)
8{
9 char fmt[] = "socket: family %d type %d protocol %d\n";
0adc3dd9
DA
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;
554ae6e7
DA
14
15 bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol);
0adc3dd9 16 bpf_trace_printk(fmt2, sizeof(fmt2), uid, gid);
554ae6e7 17
c2f4f559 18 /* block AF_INET6, SOCK_DGRAM, IPPROTO_ICMPV6 sockets
554ae6e7
DA
19 * ie., make ping6 fail
20 */
c2f4f559 21 if (sk->family == AF_INET6 &&
31b12a41 22 sk->type == SOCK_DGRAM &&
554ae6e7
DA
23 sk->protocol == IPPROTO_ICMPV6)
24 return 0;
25
26 return 1;
27}
28
31b12a41 29SEC("cgroup/sock")
554ae6e7
DA
30int bpf_prog2(struct bpf_sock *sk)
31{
32 char fmt[] = "socket: family %d type %d protocol %d\n";
33
34 bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol);
35
c2f4f559 36 /* block AF_INET, SOCK_DGRAM, IPPROTO_ICMP sockets
554ae6e7
DA
37 * ie., make ping fail
38 */
c2f4f559 39 if (sk->family == AF_INET &&
31b12a41 40 sk->type == SOCK_DGRAM &&
554ae6e7
DA
41 sk->protocol == IPPROTO_ICMP)
42 return 0;
43
44 return 1;
45}
46
47char _license[] SEC("license") = "GPL";