]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blobdiff - include/linux/bpf-cgroup.h
bpf: Add new cgroup attach type to enable sock modifications
[mirror_ubuntu-artful-kernel.git] / include / linux / bpf-cgroup.h
index af2ca8b432c07b387775e0f2c3ea276914318589..7b6e5d168c956063c37f614e2fe2f243435700db 100644 (file)
@@ -40,6 +40,9 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk,
                                struct sk_buff *skb,
                                enum bpf_attach_type type);
 
+int __cgroup_bpf_run_filter_sk(struct sock *sk,
+                              enum bpf_attach_type type);
+
 /* Wrappers for __cgroup_bpf_run_filter_skb() guarded by cgroup_bpf_enabled. */
 #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk, skb)                            \
 ({                                                                           \
@@ -63,6 +66,16 @@ int __cgroup_bpf_run_filter_skb(struct sock *sk,
        __ret;                                                                 \
 })
 
+#define BPF_CGROUP_RUN_PROG_INET_SOCK(sk)                                     \
+({                                                                            \
+       int __ret = 0;                                                         \
+       if (cgroup_bpf_enabled && sk) {                                        \
+               __ret = __cgroup_bpf_run_filter_sk(sk,                         \
+                                                BPF_CGROUP_INET_SOCK_CREATE); \
+       }                                                                      \
+       __ret;                                                                 \
+})
+
 #else
 
 struct cgroup_bpf {};
@@ -72,6 +85,7 @@ static inline void cgroup_bpf_inherit(struct cgroup *cgrp,
 
 #define BPF_CGROUP_RUN_PROG_INET_INGRESS(sk,skb) ({ 0; })
 #define BPF_CGROUP_RUN_PROG_INET_EGRESS(sk,skb) ({ 0; })
+#define BPF_CGROUP_RUN_PROG_INET_SOCK(sk) ({ 0; })
 
 #endif /* CONFIG_CGROUP_BPF */