Skip to content

Commit 8fc3930

Browse files
committed
xdp-trafficgen: Error out if interface doesn't support sending packets
If a device doesn't support sending packets via XDP, xdp-trafficgen will still happily load and try to send packets, but no packets will actually be sent. Add a check for the NDO_XMIT XDP feature flag in xdp-trafficgen, and error out if the flag it not set. This should make it clearer to users why things don't work. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
1 parent 1dad1d6 commit 8fc3930

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

xdp-trafficgen/xdp-trafficgen.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,32 @@ static bool driver_needs_xdp_pass(const struct iface *iface)
9191
return false;
9292
}
9393

94+
static int check_iface_support(const struct iface *iface)
95+
{
96+
__u64 feature_flags = 0;
97+
int err;
98+
99+
err = iface_get_xdp_feature_flags(iface->ifindex, &feature_flags);
100+
if (err || !feature_flags) {
101+
/* The libbpf query function, doesn't distinguish between
102+
* "querying is not supported" and "no feature flags are set",
103+
* so treat a 0-value feature_flags as a failure to query
104+
* instead of refuring to run because the NDO_XMIT bit is not
105+
* set.
106+
*/
107+
pr_warn("Couldn't query XDP features for interface %s (%d).\n"
108+
"Continuing anyway, but running may fail!\n",
109+
iface->ifname, -err);
110+
} else if (!(feature_flags & NETDEV_XDP_ACT_NDO_XMIT)) {
111+
pr_warn("Interface %s does not support sending packets via XDP.\n"
112+
"Most likely the driver is missing support in this kernel version.\n",
113+
iface->ifname);
114+
return -EOPNOTSUPP;
115+
}
116+
117+
return 0;
118+
}
119+
94120
struct udp_packet {
95121
struct ethhdr eth;
96122
struct ipv6hdr iph;
@@ -521,6 +547,10 @@ int do_udp(const void *opt, __unused const char *pin_root_path)
521547
}
522548
}
523549

550+
err = check_iface_support(&cfg->iface);
551+
if (err)
552+
goto out;
553+
524554
err = bpf_map_update_elem(bpf_map__fd(skel->maps.state_map),
525555
&key, &bpf_state, BPF_EXIST);
526556
if (err) {
@@ -814,6 +844,10 @@ int do_tcp(const void *opt, __unused const char *pin_root_path)
814844
}
815845
attached = true;
816846

847+
err = check_iface_support(&cfg->iface);
848+
if (err)
849+
goto out;
850+
817851
err = bpf_map_update_elem(bpf_map__fd(state_map),
818852
&key, &bpf_state, BPF_EXIST);
819853

0 commit comments

Comments
 (0)