From: Mitchell Blank Jr <mitch@sfgoth.com>
To: "David S. Miller" <davem@redhat.com>, romieu@fr.zoreil.com
Cc: netdev@oss.sgi.com
Subject: Re: [PATCH] tiny af_packet.c cleanup
Date: Mon, 15 Sep 2003 20:13:55 -0700 [thread overview]
Message-ID: <20030916031355.GC7982@gaz.sfgoth.com> (raw)
In-Reply-To: <20030915155652.3e5e89a0.davem@redhat.com>
David S. Miller wrote:
> When you guys decide on a final patch let me know, the semantic
> parts of Mitchell's changes look perfectly fine to me.
How about something like the following. It expands the comment but turns
that bit of code into an inline function so we onlt have to explain it
once.
Untested, but compiles fine.
-Mitch
--- linux-2.6.0-test5-VIRGIN/net/packet/af_packet.c 2003-09-08 12:39:53.000000000 -0700
+++ linux-2.6.0-test5mnb1/net/packet/af_packet.c 2003-09-15 10:56:26.313218168 -0700
@@ -381,6 +381,23 @@
}
#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
are discarded by BPF.
@@ -429,15 +446,7 @@
snaplen = skb->len;
if (sk->sk_filter) {
- unsigned res = 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);
-
+ unsigned res = run_filter(skb, sk, snaplen);
if (res == 0)
goto drop_n_restore;
if (snaplen > res)
@@ -533,15 +542,7 @@
snaplen = skb->len;
if (sk->sk_filter) {
- unsigned res = 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);
-
+ unsigned res = run_filter(skb, sk, snaplen);
if (res == 0)
goto drop_n_restore;
if (snaplen > res)
next prev parent reply other threads:[~2003-09-16 3:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-09-13 5:50 [PATCH] tiny af_packet.c cleanup Mitchell Blank Jr
2003-09-13 7:35 ` Francois Romieu
2003-09-13 8:02 ` Mitchell Blank Jr
2003-09-13 9:03 ` Francois Romieu
2003-09-13 20:15 ` Mitchell Blank Jr
2003-09-14 10:55 ` Francois Romieu
2003-09-14 11:26 ` Mitchell Blank Jr
2003-09-15 22:56 ` David S. Miller
2003-09-16 3:13 ` Mitchell Blank Jr [this message]
2003-09-16 5:41 ` David S. Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030916031355.GC7982@gaz.sfgoth.com \
--to=mitch@sfgoth.com \
--cc=davem@redhat.com \
--cc=netdev@oss.sgi.com \
--cc=romieu@fr.zoreil.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).