bpf: Post-hooks for sys_bind
[muen/linux.git] / net / ipv4 / af_inet.c
index 488fe26ac8e51ea64bff9a77d1d7632a81561c04..142d4c35b49318717283391d6302c70cf2243c59 100644 (file)
@@ -519,12 +519,18 @@ int __inet_bind(struct sock *sk, struct sockaddr *uaddr, int addr_len,
                inet->inet_saddr = 0;  /* Use device */
 
        /* Make sure we are allowed to bind here. */
-       if ((snum || !(inet->bind_address_no_port ||
-                      force_bind_address_no_port)) &&
-           sk->sk_prot->get_port(sk, snum)) {
-               inet->inet_saddr = inet->inet_rcv_saddr = 0;
-               err = -EADDRINUSE;
-               goto out_release_sock;
+       if (snum || !(inet->bind_address_no_port ||
+                     force_bind_address_no_port)) {
+               if (sk->sk_prot->get_port(sk, snum)) {
+                       inet->inet_saddr = inet->inet_rcv_saddr = 0;
+                       err = -EADDRINUSE;
+                       goto out_release_sock;
+               }
+               err = BPF_CGROUP_RUN_PROG_INET4_POST_BIND(sk);
+               if (err) {
+                       inet->inet_saddr = inet->inet_rcv_saddr = 0;
+                       goto out_release_sock;
+               }
        }
 
        if (inet->inet_rcv_saddr)