summaryrefslogtreecommitdiff
path: root/samples/bpf/sock_flags_kern.c
diff options
context:
space:
mode:
authorDavid Ahern <dsahern@gmail.com>2017-09-01 01:05:50 +0300
committerDavid S. Miller <davem@davemloft.net>2017-09-01 08:05:15 +0300
commit0adc3dd90050538ac543c6c0bea8e8527a9e2e2c (patch)
tree0455bd99d3cc18191b603ef13342b1b4386e38e3 /samples/bpf/sock_flags_kern.c
parent33aeb5e30acac9ae68cb5acc4eecc1fca4358859 (diff)
downloadlinux-0adc3dd90050538ac543c6c0bea8e8527a9e2e2c.tar.xz
samples/bpf: Update cgroup socket examples to use uid gid helper
Signed-off-by: David Ahern <dsahern@gmail.com> Acked-by: Alexei Starovoitov <ast@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf/sock_flags_kern.c')
-rw-r--r--samples/bpf/sock_flags_kern.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/samples/bpf/sock_flags_kern.c b/samples/bpf/sock_flags_kern.c
index 533dd11a6baa..05dcdf8a4baa 100644
--- a/samples/bpf/sock_flags_kern.c
+++ b/samples/bpf/sock_flags_kern.c
@@ -9,8 +9,13 @@ 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