Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix xdp-forward loading and unloading in some cases #489

Merged
merged 5 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion xdp-forward/tests/test-xdp-forward.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
XDP_LOADER=${XDP_LOADER:-./xdp-loader}
XDP_FORWARD=${XDP_FORWARD:-./xdp-forward}
ALL_TESTS="test_ping test_load test_fwd_full test_fwd_direct test_flowtable"
ALL_TESTS="test_ping test_load test_load_high_ifindex test_fwd_full test_fwd_direct test_flowtable"

test_ping()
{
Expand All @@ -21,6 +21,19 @@ test_load()
check_run $XDP_FORWARD unload ${NS_NAMES[@]}
}

test_load_high_ifindex()
{
# Add a bunch of interfaces to run up the ifindex counter
for i in $(seq 64); do
ip link add dev veth-forw-test type veth
ip link del dev veth-forw-test
done

ip link add dev veth-forw-test type veth
check_run $XDP_FORWARD load veth-forw-test
check_run $XDP_FORWARD unload veth-forw-test
}

test_fwd_full()
{
# veth NAPI GRO support added this symbol; forwarding won't work without it
Expand Down Expand Up @@ -121,6 +134,8 @@ EOF
PID=$(start_background_ns_devnull "socat -6 TCP-LISTEN:10000,reuseaddr,fork -")
check_run ip netns exec ${NS_NAMES[0]} socat ${INPUT_FILE} TCP6:[${OUTSIDE_IP6}]:12345,connect-timeout=1
stop_background $PID

check_run $XDP_FORWARD unload ${NS_NAMES[@]}
}

cleanup_tests()
Expand All @@ -135,5 +150,6 @@ cleanup_tests()
$XDP_LOADER unload $NS --all
check_run ip netns exec ${NS_NAMES[-1]} nft flush ruleset
check_run nft flush ruleset
ip link del dev veth-forw-test
} >/dev/null 2>&1
}
14 changes: 8 additions & 6 deletions xdp-forward/xdp-forward.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ static int find_prog(struct iface *iface, bool detach)
check:
if (!strcmp(xdp_program__name(prog), "xdp_fwd_fib_full") ||
!strcmp(xdp_program__name(prog), "xdp_fwd_fib_direct") ||
!strcmp(xdp_program__name(prog), "xdp_fwd_flowtable")) {
!strcmp(xdp_program__name(prog), "xdp_fwd_flow_full") ||
!strcmp(xdp_program__name(prog), "xdp_fwd_flow_direct")) {
mode = xdp_multiprog__attach_mode(mp);
ret = 0;
if (detach) {
Expand Down Expand Up @@ -157,8 +158,8 @@ static int do_load(const void *cfg, __unused const char *pin_root_path)
break;
case FWD_FLOWTABLE:
opts.prog_name = opt->fib_mode == FIB_DIRECT
? "xdp_fwd_flowtable_direct"
: "xdp_fwd_flowtable_full";
? "xdp_fwd_flow_direct"
: "xdp_fwd_flow_full";
break;
default:
goto end;
Expand Down Expand Up @@ -201,9 +202,7 @@ static int do_load(const void *cfg, __unused const char *pin_root_path)
opts.obj = obj;
xdp_prog = xdp_program__create(&opts);
if (!xdp_prog) {
ret = -errno;
pr_warn("Couldn't open XDP program: %s\n",
strerror(-ret));
pr_warn("Couldn't open XDP program: %s\n", strerror(errno));
goto end_destroy;
}

Expand Down Expand Up @@ -244,6 +243,8 @@ static int do_load(const void *cfg, __unused const char *pin_root_path)
pr_info("Loaded on interface %s\n", iface->ifname);
}

ret = EXIT_SUCCESS;

end_destroy:
if (opt->fwd_mode == FWD_FLOWTABLE)
xdp_flowtable__destroy(skel);
Expand All @@ -253,6 +254,7 @@ static int do_load(const void *cfg, __unused const char *pin_root_path)
return ret;

end_detach:
ret = EXIT_FAILURE;
for (iface = opt->ifaces; iface; iface = iface->next)
xdp_program__detach(xdp_prog, iface->ifindex, opt->xdp_mode, 0);
goto end_destroy;
Expand Down
6 changes: 3 additions & 3 deletions xdp-forward/xdp_flowtable.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#define BIT(x) (1 << (x))

struct {
__uint(type, BPF_MAP_TYPE_DEVMAP);
__uint(type, BPF_MAP_TYPE_DEVMAP_HASH);
__uint(key_size, sizeof(int));
__uint(value_size, sizeof(int));
__uint(max_entries, 64);
Expand Down Expand Up @@ -607,13 +607,13 @@ static __always_inline int xdp_flowtable_flags(struct xdp_md *ctx,
}

SEC("xdp")
int xdp_fwd_flowtable_full(struct xdp_md *ctx)
int xdp_fwd_flow_full(struct xdp_md *ctx)
{
return xdp_flowtable_flags(ctx, 0);
}

SEC("xdp")
int xdp_fwd_flowtable_direct(struct xdp_md *ctx)
int xdp_fwd_flow_direct(struct xdp_md *ctx)
{
return xdp_flowtable_flags(ctx, BPF_FIB_LOOKUP_DIRECT);
}
Expand Down
2 changes: 1 addition & 1 deletion xdp-forward/xdp_forward.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define IPV6_FLOWINFO_MASK bpf_htons(0x0FFFFFFF)

struct {
__uint(type, BPF_MAP_TYPE_DEVMAP);
__uint(type, BPF_MAP_TYPE_DEVMAP_HASH);
__uint(key_size, sizeof(int));
__uint(value_size, sizeof(int));
__uint(max_entries, 64);
Expand Down