diff options
author | Mark Pashmfouroush <markpash@cloudflare.com> | 2021-11-10 11:10:15 +0000 |
---|---|---|
committer | Alexei Starovoitov <ast@kernel.org> | 2021-11-10 16:29:58 -0800 |
commit | f89315650ba34ec6c91a8bded72796980bee2a4d (patch) | |
tree | c860a28dda8d188d6cdc7c863942d5dd7d77b83e /net/core | |
parent | 1a8b597ddabe7dc25aa9defd33949d455ee9cde8 (diff) | |
download | linux-stable-f89315650ba34ec6c91a8bded72796980bee2a4d.tar.gz linux-stable-f89315650ba34ec6c91a8bded72796980bee2a4d.tar.bz2 linux-stable-f89315650ba34ec6c91a8bded72796980bee2a4d.zip |
bpf: Add ingress_ifindex to bpf_sk_lookup
It may be helpful to have access to the ifindex during bpf socket
lookup. An example may be to scope certain socket lookup logic to
specific interfaces, i.e. an interface may be made exempt from custom
lookup code.
Add the ifindex of the arriving connection to the bpf_sk_lookup API.
Signed-off-by: Mark Pashmfouroush <markpash@cloudflare.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20211110111016.5670-2-markpash@cloudflare.com
Diffstat (limited to 'net/core')
-rw-r--r-- | net/core/filter.c | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/net/core/filter.c b/net/core/filter.c index 8e8d3b49c297..315a58466fc9 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -10491,6 +10491,7 @@ static bool sk_lookup_is_valid_access(int off, int size, case bpf_ctx_range_till(struct bpf_sk_lookup, local_ip6[0], local_ip6[3]): case bpf_ctx_range(struct bpf_sk_lookup, remote_port): case bpf_ctx_range(struct bpf_sk_lookup, local_port): + case bpf_ctx_range(struct bpf_sk_lookup, ingress_ifindex): bpf_ctx_record_field_size(info, sizeof(__u32)); return bpf_ctx_narrow_access_ok(off, size, sizeof(__u32)); @@ -10580,6 +10581,12 @@ static u32 sk_lookup_convert_ctx_access(enum bpf_access_type type, bpf_target_off(struct bpf_sk_lookup_kern, dport, 2, target_size)); break; + + case offsetof(struct bpf_sk_lookup, ingress_ifindex): + *insn++ = BPF_LDX_MEM(BPF_W, si->dst_reg, si->src_reg, + bpf_target_off(struct bpf_sk_lookup_kern, + ingress_ifindex, 4, target_size)); + break; } return insn - insn_buf; |