mirror of
https://github.com/torvalds/linux.git
synced 2024-12-29 14:21:47 +00:00
7cf245a37e
Fix all files in samples/bpf to include libbpf header files with the bpf/
prefix, to be consistent with external users of the library. Also ensure
that all includes of exported libbpf header files (those that are exported
on 'make install' of the library) use bracketed includes instead of quoted.
To make sure no new files are introduced that doesn't include the bpf/
prefix in its include, remove tools/lib/bpf from the include path entirely,
and use tools/lib instead.
Fixes: 6910d7d386
("selftests/bpf: Ensure bpf_helper_defs.h are taken from selftests dir")
Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Acked-by: Jesper Dangaard Brouer <brouer@redhat.com>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/157952560911.1683545.8795966751309534150.stgit@toke.dk
50 lines
1.2 KiB
C
50 lines
1.2 KiB
C
#include <uapi/linux/bpf.h>
|
|
#include <linux/socket.h>
|
|
#include <linux/net.h>
|
|
#include <uapi/linux/in.h>
|
|
#include <uapi/linux/in6.h>
|
|
#include <bpf/bpf_helpers.h>
|
|
|
|
SEC("cgroup/sock1")
|
|
int bpf_prog1(struct bpf_sock *sk)
|
|
{
|
|
char fmt[] = "socket: family %d type %d protocol %d\n";
|
|
char fmt2[] = "socket: uid %u gid %u\n";
|
|
__u64 gid_uid = bpf_get_current_uid_gid();
|
|
__u32 uid = gid_uid & 0xffffffff;
|
|
__u32 gid = gid_uid >> 32;
|
|
|
|
bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol);
|
|
bpf_trace_printk(fmt2, sizeof(fmt2), uid, gid);
|
|
|
|
/* block PF_INET6, SOCK_RAW, IPPROTO_ICMPV6 sockets
|
|
* ie., make ping6 fail
|
|
*/
|
|
if (sk->family == PF_INET6 &&
|
|
sk->type == SOCK_RAW &&
|
|
sk->protocol == IPPROTO_ICMPV6)
|
|
return 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
SEC("cgroup/sock2")
|
|
int bpf_prog2(struct bpf_sock *sk)
|
|
{
|
|
char fmt[] = "socket: family %d type %d protocol %d\n";
|
|
|
|
bpf_trace_printk(fmt, sizeof(fmt), sk->family, sk->type, sk->protocol);
|
|
|
|
/* block PF_INET, SOCK_RAW, IPPROTO_ICMP sockets
|
|
* ie., make ping fail
|
|
*/
|
|
if (sk->family == PF_INET &&
|
|
sk->type == SOCK_RAW &&
|
|
sk->protocol == IPPROTO_ICMP)
|
|
return 0;
|
|
|
|
return 1;
|
|
}
|
|
|
|
char _license[] SEC("license") = "GPL";
|