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 /net/core | |
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 'net/core')
-rw-r--r-- | net/core/filter.c | 31 |
1 files changed, 2 insertions, 29 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index dfc716ffa44b..601f28de7311 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
@@ -87,30 +87,6 @@ int sk_filter(struct sock *sk, struct sk_buff *skb) | |||
87 | } | 87 | } |
88 | EXPORT_SYMBOL(sk_filter); | 88 | EXPORT_SYMBOL(sk_filter); |
89 | 89 | ||
90 | /* Helper to find the offset of pkt_type in sk_buff structure. We want | ||
91 | * to make sure its still a 3bit field starting at a byte boundary; | ||
92 | * taken from arch/x86/net/bpf_jit_comp.c. | ||
93 | */ | ||
94 | #ifdef __BIG_ENDIAN_BITFIELD | ||
95 | #define PKT_TYPE_MAX (7 << 5) | ||
96 | #else | ||
97 | #define PKT_TYPE_MAX 7 | ||
98 | #endif | ||
99 | static unsigned int pkt_type_offset(void) | ||
100 | { | ||
101 | struct sk_buff skb_probe = { .pkt_type = ~0, }; | ||
102 | u8 *ct = (u8 *) &skb_probe; | ||
103 | unsigned int off; | ||
104 | |||
105 | for (off = 0; off < sizeof(struct sk_buff); off++) { | ||
106 | if (ct[off] == PKT_TYPE_MAX) | ||
107 | return off; | ||
108 | } | ||
109 | |||
110 | pr_err_once("Please fix %s, as pkt_type couldn't be found!\n", __func__); | ||
111 | return -1; | ||
112 | } | ||
113 | |||
114 | static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5) | 90 | static u64 __skb_get_pay_offset(u64 ctx, u64 a, u64 x, u64 r4, u64 r5) |
115 | { | 91 | { |
116 | return skb_get_poff((struct sk_buff *)(unsigned long) ctx); | 92 | return skb_get_poff((struct sk_buff *)(unsigned long) ctx); |
@@ -190,11 +166,8 @@ static bool convert_bpf_extensions(struct sock_filter *fp, | |||
190 | break; | 166 | break; |
191 | 167 | ||
192 | case SKF_AD_OFF + SKF_AD_PKTTYPE: | 168 | case SKF_AD_OFF + SKF_AD_PKTTYPE: |
193 | *insn = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX, | 169 | *insn++ = BPF_LDX_MEM(BPF_B, BPF_REG_A, BPF_REG_CTX, |
194 | pkt_type_offset()); | 170 | PKT_TYPE_OFFSET()); |
195 | if (insn->off < 0) | ||
196 | return false; | ||
197 | insn++; | ||
198 | *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, PKT_TYPE_MAX); | 171 | *insn = BPF_ALU32_IMM(BPF_AND, BPF_REG_A, PKT_TYPE_MAX); |
199 | #ifdef __BIG_ENDIAN_BITFIELD | 172 | #ifdef __BIG_ENDIAN_BITFIELD |
200 | insn++; | 173 | insn++; |