Commit abea3264 authored by Mitchell Blank Jr's avatar Mitchell Blank Jr Committed by David S. Miller

[NET]: Tiny af_packet.c cleanup.

parent 7f1bc512
...@@ -381,6 +381,23 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock, ...@@ -381,6 +381,23 @@ static int packet_sendmsg_spkt(struct kiocb *iocb, struct socket *sock,
} }
#endif #endif
static inline unsigned run_filter(struct sk_buff *skb, struct sock *sk, unsigned res)
{
struct sk_filter *filter;
bh_lock_sock(sk);
filter = sk->sk_filter;
/*
* Our caller already checked that filter != NULL but we need to
* verify that under bh_lock_sock() to be safe
*/
if (likely(filter != NULL))
res = sk_run_filter(skb, filter->insns, filter->len);
bh_unlock_sock(sk);
return res;
}
/* /*
This function makes lazy skb cloning in hope that most of packets This function makes lazy skb cloning in hope that most of packets
are discarded by BPF. are discarded by BPF.
...@@ -429,15 +446,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packe ...@@ -429,15 +446,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev, struct packe
snaplen = skb->len; snaplen = skb->len;
if (sk->sk_filter) { if (sk->sk_filter) {
unsigned res = snaplen; unsigned res = run_filter(skb, sk, snaplen);
struct sk_filter *filter;
bh_lock_sock(sk);
if ((filter = sk->sk_filter) != NULL)
res = sk_run_filter(skb, sk->sk_filter->insns,
sk->sk_filter->len);
bh_unlock_sock(sk);
if (res == 0) if (res == 0)
goto drop_n_restore; goto drop_n_restore;
if (snaplen > res) if (snaplen > res)
...@@ -533,15 +542,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct pack ...@@ -533,15 +542,7 @@ static int tpacket_rcv(struct sk_buff *skb, struct net_device *dev, struct pack
snaplen = skb->len; snaplen = skb->len;
if (sk->sk_filter) { if (sk->sk_filter) {
unsigned res = snaplen; unsigned res = run_filter(skb, sk, snaplen);
struct sk_filter *filter;
bh_lock_sock(sk);
if ((filter = sk->sk_filter) != NULL)
res = sk_run_filter(skb, sk->sk_filter->insns,
sk->sk_filter->len);
bh_unlock_sock(sk);
if (res == 0) if (res == 0)
goto drop_n_restore; goto drop_n_restore;
if (snaplen > res) if (snaplen > res)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment