[NET]: Introduce the sk_detach_filter() call

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>
This commit is contained in:
Pavel Emelyanov 2007-10-17 21:21:26 -07:00 committed by David S. Miller
parent d114f399b4
commit 55b333253d
3 changed files with 18 additions and 11 deletions

View 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__ */

View 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);

View 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 @@ int sock_setsockopt(struct socket *sock, int level, int optname,
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: