mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-02 07:04:24 +00:00
net: filter: move load_pointer() into filter.h
load_pointer() is already a static inline function. Let's move it into filter.h so BPF JIT implementations can reuse this function. Since we're exporting this function, let's also rename it to bpf_load_pointer() for clarity. Signed-off-by: Zi Shen Lim <zlim.lnx@gmail.com> Reviewed-by: Daniel Borkmann <dborkman@redhat.com> Acked-by: Alexei Starovoitov <ast@plumgrid.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
3d5baba0ec
commit
9f12fbe603
2 changed files with 16 additions and 12 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include <linux/atomic.h>
|
#include <linux/atomic.h>
|
||||||
#include <linux/compat.h>
|
#include <linux/compat.h>
|
||||||
|
#include <linux/skbuff.h>
|
||||||
#include <linux/workqueue.h>
|
#include <linux/workqueue.h>
|
||||||
#include <uapi/linux/filter.h>
|
#include <uapi/linux/filter.h>
|
||||||
|
|
||||||
|
@ -406,6 +407,18 @@ static inline u16 bpf_anc_helper(const struct sock_filter *ftest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb,
|
||||||
|
int k, unsigned int size);
|
||||||
|
|
||||||
|
static inline void *bpf_load_pointer(const struct sk_buff *skb, int k,
|
||||||
|
unsigned int size, void *buffer)
|
||||||
|
{
|
||||||
|
if (k >= 0)
|
||||||
|
return skb_header_pointer(skb, k, size, buffer);
|
||||||
|
|
||||||
|
return bpf_internal_load_pointer_neg_helper(skb, k, size);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_BPF_JIT
|
#ifdef CONFIG_BPF_JIT
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <linux/linkage.h>
|
#include <linux/linkage.h>
|
||||||
|
|
|
@ -84,15 +84,6 @@ void *bpf_internal_load_pointer_neg_helper(const struct sk_buff *skb, int k, uns
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void *load_pointer(const struct sk_buff *skb, int k,
|
|
||||||
unsigned int size, void *buffer)
|
|
||||||
{
|
|
||||||
if (k >= 0)
|
|
||||||
return skb_header_pointer(skb, k, size, buffer);
|
|
||||||
|
|
||||||
return bpf_internal_load_pointer_neg_helper(skb, k, size);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sk_filter - run a packet through a socket filter
|
* sk_filter - run a packet through a socket filter
|
||||||
* @sk: sock associated with &sk_buff
|
* @sk: sock associated with &sk_buff
|
||||||
|
@ -537,7 +528,7 @@ static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *ins
|
||||||
* BPF_R0 - 8/16/32-bit skb data converted to cpu endianness
|
* BPF_R0 - 8/16/32-bit skb data converted to cpu endianness
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp);
|
ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 4, &tmp);
|
||||||
if (likely(ptr != NULL)) {
|
if (likely(ptr != NULL)) {
|
||||||
BPF_R0 = get_unaligned_be32(ptr);
|
BPF_R0 = get_unaligned_be32(ptr);
|
||||||
CONT;
|
CONT;
|
||||||
|
@ -547,7 +538,7 @@ static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *ins
|
||||||
LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */
|
LD_ABS_H: /* BPF_R0 = ntohs(*(u16 *) (skb->data + imm32)) */
|
||||||
off = IMM;
|
off = IMM;
|
||||||
load_half:
|
load_half:
|
||||||
ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp);
|
ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 2, &tmp);
|
||||||
if (likely(ptr != NULL)) {
|
if (likely(ptr != NULL)) {
|
||||||
BPF_R0 = get_unaligned_be16(ptr);
|
BPF_R0 = get_unaligned_be16(ptr);
|
||||||
CONT;
|
CONT;
|
||||||
|
@ -557,7 +548,7 @@ static unsigned int __sk_run_filter(void *ctx, const struct sock_filter_int *ins
|
||||||
LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */
|
LD_ABS_B: /* BPF_R0 = *(u8 *) (skb->data + imm32) */
|
||||||
off = IMM;
|
off = IMM;
|
||||||
load_byte:
|
load_byte:
|
||||||
ptr = load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp);
|
ptr = bpf_load_pointer((struct sk_buff *) (unsigned long) CTX, off, 1, &tmp);
|
||||||
if (likely(ptr != NULL)) {
|
if (likely(ptr != NULL)) {
|
||||||
BPF_R0 = *(u8 *)ptr;
|
BPF_R0 = *(u8 *)ptr;
|
||||||
CONT;
|
CONT;
|
||||||
|
|
Loading…
Reference in a new issue