From: Ido Schimmel <idosch@nvidia.com>
To: netdev@vger.kernel.org, bpf@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, pabeni@redhat.com,
edumazet@google.com, dsahern@gmail.com, petrm@nvidia.com,
horms@kernel.org, ast@kernel.org, daniel@iogearbox.net,
andrii@kernel.org, martin.lau@linux.dev,
john.fastabend@gmail.com, sdf@fomichev.me,
Ido Schimmel <idosch@nvidia.com>
Subject: [RFC PATCH bpf-next 5/9] selftests/bpf: fib_lookup: Add IPv4 output route tests
Date: Thu, 26 Feb 2026 09:59:59 +0200 [thread overview]
Message-ID: <20260226080003.524935-6-idosch@nvidia.com> (raw)
In-Reply-To: <20260226080003.524935-1-idosch@nvidia.com>
When the BPF_FIB_LOOKUP_OUTPUT flag is passed to the bpf_fib_lookup()
helper the expectation is that the helper will resolve the most specific
route whose nexthop device matches the specified ifindex. This is useful
when we already know the nexthop device, but need the helper to resolve
the destination MAC.
Add test cases to test this behavior. To that end, configure two
identical routes that differ in their metric and nexthop device and test
that the correct route is resolved each time.
Also test the scenario where a matching route for the destination
address exists, but with the wrong nexthop device. Expect the helper to
return an error.
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
.../selftests/bpf/prog_tests/fib_lookup.c | 37 +++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/tools/testing/selftests/bpf/prog_tests/fib_lookup.c b/tools/testing/selftests/bpf/prog_tests/fib_lookup.c
index 0541fd982e63..6ceeecbdca43 100644
--- a/tools/testing/selftests/bpf/prog_tests/fib_lookup.c
+++ b/tools/testing/selftests/bpf/prog_tests/fib_lookup.c
@@ -43,6 +43,8 @@
#define DMAC_INIT2 { 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, }
#define IFINDEX_VETH1 10010
#define IFINDEX_VETH2 10020
+#define IPV4_OUTPUT_NET "192.0.2.0"
+#define IPV4_OUTPUT_DST "192.0.2.1"
struct fib_lookup_test {
const char *desc;
@@ -146,6 +148,35 @@ static const struct fib_lookup_test tests[] = {
.expected_dst = IPV6_GW1,
.lookup_flags = BPF_FIB_LOOKUP_SKIP_NEIGH,
.mark = MARK, },
+ /* output routes */
+ { .desc = "IPv4 output route, without source, via first device",
+ .daddr = IPV4_OUTPUT_DST, .expected_ret = BPF_FIB_LKUP_RET_SUCCESS,
+ .lookup_flags = BPF_FIB_LOOKUP_OUTPUT | BPF_FIB_LOOKUP_SRC,
+ .dmac = DMAC_INIT, .ifindex = IFINDEX_VETH1,
+ .expected_ifindex = IFINDEX_VETH1, },
+ { .desc = "IPv4 output route, without source, via second device",
+ .daddr = IPV4_OUTPUT_DST, .expected_ret = BPF_FIB_LKUP_RET_SUCCESS,
+ .lookup_flags = BPF_FIB_LOOKUP_OUTPUT | BPF_FIB_LOOKUP_SRC,
+ .dmac = DMAC_INIT2, .ifindex = IFINDEX_VETH2,
+ .expected_ifindex = IFINDEX_VETH2, },
+ { .desc = "IPv4 output route, with source, via first device",
+ .daddr = IPV4_OUTPUT_DST, .expected_ret = BPF_FIB_LKUP_RET_SUCCESS,
+ .lookup_flags = BPF_FIB_LOOKUP_OUTPUT, .dmac = DMAC_INIT,
+ .ifindex = IFINDEX_VETH1, .expected_ifindex = IFINDEX_VETH1, },
+ { .desc = "IPv4 output route, with source, via second device",
+ .daddr = IPV4_OUTPUT_DST, .expected_ret = BPF_FIB_LKUP_RET_SUCCESS,
+ .lookup_flags = BPF_FIB_LOOKUP_OUTPUT, .dmac = DMAC_INIT2,
+ .ifindex = IFINDEX_VETH2, .expected_ifindex = IFINDEX_VETH2, },
+ { .desc = "IPv4 output route, oif match",
+ .daddr = IPV4_NUD_STALE_ADDR,
+ .expected_ret = BPF_FIB_LKUP_RET_SUCCESS,
+ .lookup_flags = BPF_FIB_LOOKUP_OUTPUT | BPF_FIB_LOOKUP_SKIP_NEIGH,
+ .ifindex = IFINDEX_VETH1, .expected_ifindex = IFINDEX_VETH1, },
+ { .desc = "IPv4 output route, oif mismatch",
+ .daddr = IPV4_NUD_STALE_ADDR,
+ .expected_ret = BPF_FIB_LKUP_RET_NOT_FWDED,
+ .lookup_flags = BPF_FIB_LOOKUP_OUTPUT | BPF_FIB_LOOKUP_SKIP_NEIGH,
+ .ifindex = IFINDEX_VETH2, },
};
static int setup_netns(void)
@@ -217,6 +248,12 @@ static int setup_netns(void)
SYS(fail, "ip rule add prio 2 fwmark %d lookup %s", MARK, MARK_TABLE);
SYS(fail, "ip -6 rule add prio 2 fwmark %d lookup %s", MARK, MARK_TABLE);
+ /* Setup for output route tests */
+ SYS(fail, "ip route add %s/24 dev veth1 metric 100", IPV4_OUTPUT_NET);
+ SYS(fail, "ip route add %s/24 dev veth2 metric 200", IPV4_OUTPUT_NET);
+ SYS(fail, "ip neigh add %s dev veth1 lladdr %s nud perm", IPV4_OUTPUT_DST, DMAC);
+ SYS(fail, "ip neigh add %s dev veth2 lladdr %s nud perm", IPV4_OUTPUT_DST, DMAC2);
+
return 0;
fail:
return -1;
--
2.53.0
next prev parent reply other threads:[~2026-02-26 8:01 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-26 7:59 [RFC PATCH bpf-next 0/9] bpf: fib_lookup: IPv6 output routes enhancements Ido Schimmel
2026-02-26 7:59 ` [RFC PATCH bpf-next 1/9] selftests/bpf: fib_lookup: Force specific interface indexes Ido Schimmel
2026-02-26 7:59 ` [RFC PATCH bpf-next 2/9] selftests/bpf: fib_lookup: Enable forwarding on second net device Ido Schimmel
2026-02-26 7:59 ` [RFC PATCH bpf-next 3/9] selftests/bpf: fib_lookup: Allow parametrizing ifindex Ido Schimmel
2026-02-26 7:59 ` [RFC PATCH bpf-next 4/9] selftests/bpf: fib_lookup: Allow testing for expected ifindex Ido Schimmel
2026-02-26 7:59 ` Ido Schimmel [this message]
2026-02-26 8:00 ` [RFC PATCH bpf-next 6/9] bpf: fib_lookup: Honor oif in IPv6 output route lookups Ido Schimmel
2026-02-26 8:41 ` bot+bpf-ci
2026-02-26 15:31 ` David Ahern
2026-02-26 8:00 ` [RFC PATCH bpf-next 7/9] selftests/bpf: fib_lookup: Add IPv6 output route tests Ido Schimmel
2026-02-26 8:00 ` [RFC PATCH bpf-next 8/9] bpf: fib_lookup: Allow output lookups for IPv6 link-local addresses Ido Schimmel
2026-02-26 15:36 ` David Ahern
2026-02-26 8:00 ` [RFC PATCH bpf-next 9/9] selftests/bpf: fib_lookup: Add IPv6 link-local tests Ido Schimmel
2026-02-26 17:14 ` [RFC PATCH bpf-next 0/9] bpf: fib_lookup: IPv6 output routes enhancements Alexei Starovoitov
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=20260226080003.524935-6-idosch@nvidia.com \
--to=idosch@nvidia.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dsahern@gmail.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=martin.lau@linux.dev \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=petrm@nvidia.com \
--cc=sdf@fomichev.me \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox