Re: [PATCH net-next v6 6/6] samples/bpf: add userspace example for prohibiting sockets

From
Alexei Starovoitov <hidden>
Date
2016-12-01 06:00:02
Reply to
David Ahern, 2016-11-30
On Wed, Nov 30, 2016 at 10:16:50AM -0800, David Ahern wrote:
Add examples preventing a process in a cgroup from opening a socket
based family, protocol and type.

Signed-off-by: David Ahern <redacted>
...
quoted hunk ↗ jump to hunk
+++ b/samples/bpf/sock_flags_kern.c
@@ -0,0 +1,37 @@
+#include <uapi/linux/bpf.h>
+#include <linux/socket.h>
+#include "bpf_helpers.h"
+
+SEC("cgroup/sock1")
+int bpf_prog1(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_INET6, SOCK_RAW, IPPROTO_ICMPV6 sockets
+	 * ie., make ping6 fail
+	 */
+	if (sk->family == PF_INET6 && sk->type == 3 && sk->protocol == 58)
+		return 0;
why not to use SOCK_RAW and IPPROTO_ICMPV6 instead of constants?

Thanks for the test!
Thread (12 messages) 12 messages, 3 authors, last reply 2016-12-05
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help