From: Martynas Pumputis <m@lambda.lt>
To: bpf@vger.kernel.org
Cc: ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
m@lambda.lt, dsahern@gmail.com
Subject: [PATCH bpf] bpf: Fix fib lookup when ifindex is not set
Date: Wed, 22 Dec 2021 16:15:48 +0100 [thread overview]
Message-ID: <20211222151548.100494-1-m@lambda.lt> (raw)
Previously, bpf_ipv{4,6}_fib_lookup() with !BPF_FIB_LOOKUP_DIRECT
required a netdev identified by bpf_fib_lookup->ifindex to exist even if
the netdev's FIB table was not used for the lookup.
This commit makes the ifindex mandatory only if BPF_FIB_LOOKUP_DIRECT is
set.
Fixes: 87f5fc7e48d ("bpf: Provide helper to do forwarding lookups in kernel FIB table")
Signed-off-by: Martynas Pumputis <m@lambda.lt>
---
net/core/filter.c | 30 +++++++++++++++++-------------
1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/net/core/filter.c b/net/core/filter.c
index 6102f093d59a..7c8f34d9e042 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -5389,14 +5389,16 @@ static int bpf_ipv4_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
u32 mtu = 0;
int err;
- dev = dev_get_by_index_rcu(net, params->ifindex);
- if (unlikely(!dev))
- return -ENODEV;
+ if (flags & BPF_FIB_LOOKUP_DIRECT) {
+ dev = dev_get_by_index_rcu(net, params->ifindex);
+ if (unlikely(!dev))
+ return -ENODEV;
- /* verify forwarding is enabled on this interface */
- in_dev = __in_dev_get_rcu(dev);
- if (unlikely(!in_dev || !IN_DEV_FORWARD(in_dev)))
- return BPF_FIB_LKUP_RET_FWD_DISABLED;
+ /* verify forwarding is enabled on this interface */
+ in_dev = __in_dev_get_rcu(dev);
+ if (unlikely(!in_dev || !IN_DEV_FORWARD(in_dev)))
+ return BPF_FIB_LKUP_RET_FWD_DISABLED;
+ }
if (flags & BPF_FIB_LOOKUP_OUTPUT) {
fl4.flowi4_iif = 1;
@@ -5514,13 +5516,15 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
if (rt6_need_strict(dst) || rt6_need_strict(src))
return BPF_FIB_LKUP_RET_NOT_FWDED;
- dev = dev_get_by_index_rcu(net, params->ifindex);
- if (unlikely(!dev))
- return -ENODEV;
+ if (flags & BPF_FIB_LOOKUP_DIRECT) {
+ dev = dev_get_by_index_rcu(net, params->ifindex);
+ if (unlikely(!dev))
+ return -ENODEV;
- idev = __in6_dev_get_safely(dev);
- if (unlikely(!idev || !idev->cnf.forwarding))
- return BPF_FIB_LKUP_RET_FWD_DISABLED;
+ idev = __in6_dev_get_safely(dev);
+ if (unlikely(!idev || !idev->cnf.forwarding))
+ return BPF_FIB_LKUP_RET_FWD_DISABLED;
+ }
if (flags & BPF_FIB_LOOKUP_OUTPUT) {
fl6.flowi6_iif = 1;
--
2.34.1
next reply other threads:[~2021-12-22 15:12 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-22 15:15 Martynas Pumputis [this message]
2021-12-22 21:26 ` [PATCH bpf] bpf: Fix fib lookup when ifindex is not set David Ahern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211222151548.100494-1-m@lambda.lt \
--to=m@lambda.lt \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=dsahern@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.