diff options
author | Hannes Frederic Sowa <hannes@stressinduktion.org> | 2014-09-12 08:04:43 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-09-13 17:07:21 -0400 |
commit | 233577a22089facf5271ab5e845b2262047c971f (patch) | |
tree | c93ec43dbf3adb316b3af67a3d315984b3cc5f10 /arch/mips/net/bpf_jit.c | |
parent | ac7a04c33dd7f8e429df4b929ba3a3e8e729cc89 (diff) |
net: filter: constify detection of pkt_type_offset
Currently we have 2 pkt_type_offset functions doing the same thing and
spread across the architecture files. Remove those and replace them
with a PKT_TYPE_OFFSET macro helper which gets the constant value from a
zero sized sk_buff member right in front of the bitfield with offsetof.
This new offset marker does not change size of struct sk_buff.
Cc: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Markos Chandras <markos.chandras@imgtec.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Daniel Borkmann <dborkman@redhat.com>
Cc: Alexei Starovoitov <alexei.starovoitov@gmail.com>
Signed-off-by: Denis Kirjanov <kda@linux-powerpc.org>
Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org>
Acked-by: Alexei Starovoitov <ast@plumgrid.com>
Acked-by: Daniel Borkmann <dborkman@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/mips/net/bpf_jit.c')
-rw-r--r-- | arch/mips/net/bpf_jit.c | 27 |
1 files changed, 1 insertions, 26 deletions
diff --git a/arch/mips/net/bpf_jit.c b/arch/mips/net/bpf_jit.c index 0e97ccd29fe3..7edc08398c4a 100644 --- a/arch/mips/net/bpf_jit.c +++ b/arch/mips/net/bpf_jit.c | |||
@@ -765,27 +765,6 @@ static u64 jit_get_skb_w(struct sk_buff *skb, unsigned offset) | |||
765 | return (u64)err << 32 | ntohl(ret); | 765 | return (u64)err << 32 | ntohl(ret); |
766 | } | 766 | } |
767 | 767 | ||
768 | #ifdef __BIG_ENDIAN_BITFIELD | ||
769 | #define PKT_TYPE_MAX (7 << 5) | ||
770 | #else | ||
771 | #define PKT_TYPE_MAX 7 | ||
772 | #endif | ||
773 | static int pkt_type_offset(void) | ||
774 | { | ||
775 | struct sk_buff skb_probe = { | ||
776 | .pkt_type = ~0, | ||
777 | }; | ||
778 | u8 *ct = (u8 *)&skb_probe; | ||
779 | unsigned int off; | ||
780 | |||
781 | for (off = 0; off < sizeof(struct sk_buff); off++) { | ||
782 | if (ct[off] == PKT_TYPE_MAX) | ||
783 | return off; | ||
784 | } | ||
785 | pr_err_once("Please fix pkt_type_offset(), as pkt_type couldn't be found\n"); | ||
786 | return -1; | ||
787 | } | ||
788 | |||
789 | static int build_body(struct jit_ctx *ctx) | 768 | static int build_body(struct jit_ctx *ctx) |
790 | { | 769 | { |
791 | void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; | 770 | void *load_func[] = {jit_get_skb_b, jit_get_skb_h, jit_get_skb_w}; |
@@ -1332,11 +1311,7 @@ jmp_cmp: | |||
1332 | case BPF_ANC | SKF_AD_PKTTYPE: | 1311 | case BPF_ANC | SKF_AD_PKTTYPE: |
1333 | ctx->flags |= SEEN_SKB; | 1312 | ctx->flags |= SEEN_SKB; |
1334 | 1313 | ||
1335 | off = pkt_type_offset(); | 1314 | emit_load_byte(r_tmp, r_skb, PKT_TYPE_OFFSET(), ctx); |
1336 | |||
1337 | if (off < 0) | ||
1338 | return -1; | ||
1339 | emit_load_byte(r_tmp, r_skb, off, ctx); | ||
1340 | /* Keep only the last 3 bits */ | 1315 | /* Keep only the last 3 bits */ |
1341 | emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx); | 1316 | emit_andi(r_A, r_tmp, PKT_TYPE_MAX, ctx); |
1342 | #ifdef __BIG_ENDIAN_BITFIELD | 1317 | #ifdef __BIG_ENDIAN_BITFIELD |