[NET]: Introduce the sk_detach_filter() call
authorPavel Emelyanov <xemul@openvz.org>
Thu, 18 Oct 2007 04:21:26 +0000 (21:21 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 18 Oct 2007 04:21:26 +0000 (21:21 -0700)
Filter is attached in a separate function, so do the
same for filter detaching.

This also removes one variable sock_setsockopt().

Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/filter.h
net/core/filter.c
net/core/sock.c

index 91b2e3b9251eb67ee57b19dd44ba0f84bb8fcb94..ddfa0372a3b723d978823bea9a3d4e267abf0506 100644 (file)
@@ -146,6 +146,7 @@ struct sock;
 
 extern unsigned int sk_run_filter(struct sk_buff *skb, struct sock_filter *filter, int flen);
 extern int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk);
+extern int sk_detach_filter(struct sock *sk);
 extern int sk_chk_filter(struct sock_filter *filter, int flen);
 #endif /* __KERNEL__ */
 
index bd903aaf7aa74fb871f4f4cdda14c6cd55755ee5..fd607581ab503bb69043cbbc154265c3799baf05 100644 (file)
@@ -433,5 +433,21 @@ int sk_attach_filter(struct sock_fprog *fprog, struct sock *sk)
        return err;
 }
 
+int sk_detach_filter(struct sock *sk)
+{
+       int ret = -ENOENT;
+       struct sk_filter *filter;
+
+       rcu_read_lock_bh();
+       filter = rcu_dereference(sk->sk_filter);
+       if (filter) {
+               rcu_assign_pointer(sk->sk_filter, NULL);
+               sk_filter_release(sk, filter);
+               ret = 0;
+       }
+       rcu_read_unlock_bh();
+       return ret;
+}
+
 EXPORT_SYMBOL(sk_chk_filter);
 EXPORT_SYMBOL(sk_run_filter);
index d45ecdccc6a153ec1ffccb1430e6085a3dd42f7d..07101381b8b78df697987325a421d37dd308537f 100644 (file)
@@ -428,7 +428,6 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
                    char __user *optval, int optlen)
 {
        struct sock *sk=sock->sk;
-       struct sk_filter *filter;
        int val;
        int valbool;
        struct linger ling;
@@ -652,16 +651,7 @@ set_rcvbuf:
                break;
 
        case SO_DETACH_FILTER:
-               rcu_read_lock_bh();
-               filter = rcu_dereference(sk->sk_filter);
-               if (filter) {
-                       rcu_assign_pointer(sk->sk_filter, NULL);
-                       sk_filter_release(sk, filter);
-                       rcu_read_unlock_bh();
-                       break;
-               }
-               rcu_read_unlock_bh();
-               ret = -ENONET;
+               ret = sk_detach_filter(sk);
                break;
 
        case SO_PASSSEC: