diff options
author | Daniel Borkmann <daniel@iogearbox.net> | 2016-09-08 20:45:30 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2016-09-09 22:36:04 -0400 |
commit | 374fb54eeaaa6b2cb82bca73a11273687bb2a96a (patch) | |
tree | 3521b6faa6bf34b90ad0c4b8b733a018e858c119 | |
parent | f035a51536af9802f55d8c79bd87f184ebffb093 (diff) |
bpf: add own ctx rewriter on ifindex for clsact progs
When fetching ifindex, we don't need to test dev for being NULL since
we're always guaranteed to have a valid dev for clsact programs. Thus,
avoid this test in fast path.
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | net/core/filter.c | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 120c813ef030..d6d9bb89ce3a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c | |||
@@ -2634,10 +2634,10 @@ void bpf_warn_invalid_xdp_action(u32 act) | |||
2634 | } | 2634 | } |
2635 | EXPORT_SYMBOL_GPL(bpf_warn_invalid_xdp_action); | 2635 | EXPORT_SYMBOL_GPL(bpf_warn_invalid_xdp_action); |
2636 | 2636 | ||
2637 | static u32 bpf_net_convert_ctx_access(enum bpf_access_type type, int dst_reg, | 2637 | static u32 sk_filter_convert_ctx_access(enum bpf_access_type type, int dst_reg, |
2638 | int src_reg, int ctx_off, | 2638 | int src_reg, int ctx_off, |
2639 | struct bpf_insn *insn_buf, | 2639 | struct bpf_insn *insn_buf, |
2640 | struct bpf_prog *prog) | 2640 | struct bpf_prog *prog) |
2641 | { | 2641 | { |
2642 | struct bpf_insn *insn = insn_buf; | 2642 | struct bpf_insn *insn = insn_buf; |
2643 | 2643 | ||
@@ -2785,6 +2785,31 @@ static u32 bpf_net_convert_ctx_access(enum bpf_access_type type, int dst_reg, | |||
2785 | return insn - insn_buf; | 2785 | return insn - insn_buf; |
2786 | } | 2786 | } |
2787 | 2787 | ||
2788 | static u32 tc_cls_act_convert_ctx_access(enum bpf_access_type type, int dst_reg, | ||
2789 | int src_reg, int ctx_off, | ||
2790 | struct bpf_insn *insn_buf, | ||
2791 | struct bpf_prog *prog) | ||
2792 | { | ||
2793 | struct bpf_insn *insn = insn_buf; | ||
2794 | |||
2795 | switch (ctx_off) { | ||
2796 | case offsetof(struct __sk_buff, ifindex): | ||
2797 | BUILD_BUG_ON(FIELD_SIZEOF(struct net_device, ifindex) != 4); | ||
2798 | |||
2799 | *insn++ = BPF_LDX_MEM(BPF_FIELD_SIZEOF(struct sk_buff, dev), | ||
2800 | dst_reg, src_reg, | ||
2801 | offsetof(struct sk_buff, dev)); | ||
2802 | *insn++ = BPF_LDX_MEM(BPF_W, dst_reg, dst_reg, | ||
2803 | offsetof(struct net_device, ifindex)); | ||
2804 | break; | ||
2805 | default: | ||
2806 | return sk_filter_convert_ctx_access(type, dst_reg, src_reg, | ||
2807 | ctx_off, insn_buf, prog); | ||
2808 | } | ||
2809 | |||
2810 | return insn - insn_buf; | ||
2811 | } | ||
2812 | |||
2788 | static u32 xdp_convert_ctx_access(enum bpf_access_type type, int dst_reg, | 2813 | static u32 xdp_convert_ctx_access(enum bpf_access_type type, int dst_reg, |
2789 | int src_reg, int ctx_off, | 2814 | int src_reg, int ctx_off, |
2790 | struct bpf_insn *insn_buf, | 2815 | struct bpf_insn *insn_buf, |
@@ -2811,13 +2836,13 @@ static u32 xdp_convert_ctx_access(enum bpf_access_type type, int dst_reg, | |||
2811 | static const struct bpf_verifier_ops sk_filter_ops = { | 2836 | static const struct bpf_verifier_ops sk_filter_ops = { |
2812 | .get_func_proto = sk_filter_func_proto, | 2837 | .get_func_proto = sk_filter_func_proto, |
2813 | .is_valid_access = sk_filter_is_valid_access, | 2838 | .is_valid_access = sk_filter_is_valid_access, |
2814 | .convert_ctx_access = bpf_net_convert_ctx_access, | 2839 | .convert_ctx_access = sk_filter_convert_ctx_access, |
2815 | }; | 2840 | }; |
2816 | 2841 | ||
2817 | static const struct bpf_verifier_ops tc_cls_act_ops = { | 2842 | static const struct bpf_verifier_ops tc_cls_act_ops = { |
2818 | .get_func_proto = tc_cls_act_func_proto, | 2843 | .get_func_proto = tc_cls_act_func_proto, |
2819 | .is_valid_access = tc_cls_act_is_valid_access, | 2844 | .is_valid_access = tc_cls_act_is_valid_access, |
2820 | .convert_ctx_access = bpf_net_convert_ctx_access, | 2845 | .convert_ctx_access = tc_cls_act_convert_ctx_access, |
2821 | }; | 2846 | }; |
2822 | 2847 | ||
2823 | static const struct bpf_verifier_ops xdp_ops = { | 2848 | static const struct bpf_verifier_ops xdp_ops = { |