From: Daniel Borkmann <dborkman@redhat.com>
To: davem@davemloft.net
Cc: ast@plumgrid.com, netdev@vger.kernel.org
Subject: [PATCH net-next v2 2/5] net: filter: misc/various cleanups
Date: Thu, 24 Apr 2014 08:45:24 +0200 [thread overview]
Message-ID: <1398321927-8845-3-git-send-email-dborkman@redhat.com> (raw)
In-Reply-To: <1398321927-8845-1-git-send-email-dborkman@redhat.com>
This contains only some minor misc cleanpus. We can spare us the
extra variable declaration in __skb_get_pay_offset(), we can mark
some unexpected conditions in the fast-path as unlikely(), the
cast in __get_random_u32() is rather unnecessary and in
__sk_migrate_realloc() we can remove the memcpy() and do a direct
assignment of the structs. Latter was suggested by Fengguang Wu
found with coccinelle.
Suggested-by: Fengguang Wu <fengguang.wu@intel.com>
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
---
net/core/filter.c | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index a1784e9..2fd2293 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -57,9 +57,9 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
ptr = skb_network_header(skb) + k - SKF_NET_OFF;
else if (k >= SKF_LL_OFF)
ptr = skb_mac_header(skb) + k - SKF_LL_OFF;
-
if (ptr >= skb->head && ptr + size <= skb_tail_pointer(skb))
return ptr;
+
return NULL;
}
@@ -68,6 +68,7 @@ static inline void *load_pointer(const struct sk_buff *skb, int k,
{
if (k >= 0)
return skb_header_pointer(skb, k, size, buffer);
+
return bpf_internal_load_pointer_neg_helper(skb, k, size);
}
@@ -596,9 +597,7 @@ static unsigned int pkt_type_offset(void)
static u64 __skb_get_pay_offset(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)
{
- struct sk_buff *skb = (struct sk_buff *)(long) ctx;
-
- return __skb_get_poff(skb);
+ return __skb_get_poff((struct sk_buff *)(long) ctx);
}
static u64 __skb_get_nlattr(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)
@@ -609,10 +608,10 @@ static u64 __skb_get_nlattr(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)
if (skb_is_nonlinear(skb))
return 0;
- if (skb->len < sizeof(struct nlattr))
+ if (unlikely(skb->len < sizeof(struct nlattr)))
return 0;
- if (A > skb->len - sizeof(struct nlattr))
+ if (unlikely(A > skb->len - sizeof(struct nlattr)))
return 0;
nla = nla_find((struct nlattr *) &skb->data[A], skb->len - A, X);
@@ -630,14 +629,14 @@ static u64 __skb_get_nlattr_nest(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)
if (skb_is_nonlinear(skb))
return 0;
- if (skb->len < sizeof(struct nlattr))
+ if (unlikely(skb->len < sizeof(struct nlattr)))
return 0;
- if (A > skb->len - sizeof(struct nlattr))
+ if (unlikely(A > skb->len - sizeof(struct nlattr)))
return 0;
nla = (struct nlattr *) &skb->data[A];
- if (nla->nla_len > skb->len - A)
+ if (unlikely(nla->nla_len > skb->len - A))
return 0;
nla = nla_find_nested(nla, X);
@@ -655,7 +654,7 @@ static u64 __get_raw_cpu_id(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)
/* note that this only generates 32-bit random numbers */
static u64 __get_random_u32(u64 ctx, u64 A, u64 X, u64 r4, u64 r5)
{
- return (u64)prandom_u32();
+ return prandom_u32();
}
static bool convert_bpf_extensions(struct sock_filter *fp,
@@ -1472,7 +1471,7 @@ static struct sk_filter *__sk_migrate_realloc(struct sk_filter *fp,
fp_new = sock_kmalloc(sk, len, GFP_KERNEL);
if (fp_new) {
- memcpy(fp_new, fp, sizeof(struct sk_filter));
+ *fp_new = *fp;
/* As we're kepping orig_prog in fp_new along,
* we need to make sure we're not evicting it
* from the old fp.
--
1.7.11.7
next prev parent reply other threads:[~2014-04-24 6:45 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-24 6:45 [PATCH net-next v2 0/5] BPF updates Daniel Borkmann
2014-04-24 6:45 ` [PATCH net-next v2 1/5] net: filter: simplify label names from jump-table Daniel Borkmann
2014-04-24 6:45 ` Daniel Borkmann [this message]
2014-04-24 20:00 ` [PATCH net-next v2 2/5] net: filter: misc/various cleanups David Miller
2014-04-25 7:52 ` Daniel Borkmann
2014-04-24 6:45 ` [PATCH net-next v2 3/5] net: filter: get rid of sock_fprog_kern Daniel Borkmann
2014-04-24 20:02 ` David Miller
2014-04-25 7:58 ` Daniel Borkmann
2014-04-24 6:45 ` [PATCH net-next v2 4/5] net: filter: make register namings more comprehensible Daniel Borkmann
2014-04-24 6:45 ` [PATCH net-next v2 5/5] net: filter: optimize BPF migration for ARG1/CTX handling Daniel Borkmann
2014-04-24 15:43 ` Alexei Starovoitov
2014-04-24 20:04 ` David Miller
2014-04-26 18:06 ` Alexei Starovoitov
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=1398321927-8845-3-git-send-email-dborkman@redhat.com \
--to=dborkman@redhat.com \
--cc=ast@plumgrid.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/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).