Skip to content

Commit d527fc0

Browse files
committed
xdp-loader: Move querying for XDP feature flags into a util helper function
This will make it possible to reuse the query function in xdp-trafficgen in a subsequent commit. Signed-off-by: Toke Høiland-Jørgensen <[email protected]>
1 parent 5950651 commit d527fc0

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

lib/util/util.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -852,3 +852,21 @@ int iface_print_status(const struct iface *iface)
852852
out:
853853
return err;
854854
}
855+
856+
int iface_get_xdp_feature_flags(int ifindex, __u64 *feature_flags)
857+
{
858+
#ifdef HAVE_LIBBPF_BPF_XDP_QUERY
859+
LIBBPF_OPTS(bpf_xdp_query_opts, opts);
860+
int err;
861+
862+
err = bpf_xdp_query(ifindex, 0, &opts);
863+
if (err)
864+
return err;
865+
866+
*feature_flags = opts.feature_flags;
867+
return 0;
868+
#else
869+
return -EOPNOTSUPP;
870+
#endif
871+
872+
}

lib/util/util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,7 @@ int prog_lock_release(int lock_fd);
9393

9494
const char *get_libbpf_version(void);
9595
int iface_print_status(const struct iface *iface);
96+
int iface_get_xdp_feature_flags(int ifindex, __u64 *feature_flags);
97+
9698

9799
#endif

xdp-loader/xdp-loader.c

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -391,16 +391,20 @@ static struct prog_option features_options[] = {
391391
END_OPTIONS
392392
};
393393

394-
#define CHECK_XDP_FEATURE(f) (opts.feature_flags & (f) ? "yes" : "no")
394+
#define CHECK_XDP_FEATURE(f) (feature_flags & (f) ? "yes" : "no")
395395
static int iface_print_xdp_features(const struct iface *iface)
396396
{
397-
#ifdef HAVE_LIBBPF_BPF_XDP_QUERY
398-
LIBBPF_OPTS(bpf_xdp_query_opts, opts);
397+
__u64 feature_flags;
399398
int err;
400399

401-
err = bpf_xdp_query(iface->ifindex, 0, &opts);
400+
#ifndef HAVE_LIBBPF_BPF_XDP_QUERY
401+
pr_warn("Cannot display features, because xdp-tools was compiled against an "
402+
"old version of libbpf without support for querying features.\n");
403+
#endif
404+
405+
err = iface_get_xdp_feature_flags(iface->ifindex, &feature_flags);
402406
if (err) {
403-
pr_warn("The running kernel doesn't support querying XDP features (%d).\n", err);
407+
pr_warn("Couldn't query XDP features (%d).\n", err);
404408
return err;
405409
}
406410

@@ -420,19 +424,11 @@ static int iface_print_xdp_features(const struct iface *iface)
420424
printf("NETDEV_XDP_ACT_NDO_XMIT_SG:\t%s\n",
421425
CHECK_XDP_FEATURE(NETDEV_XDP_ACT_NDO_XMIT_SG));
422426

423-
if (opts.feature_flags & ~NETDEV_XDP_ACT_MASK)
427+
if (feature_flags & ~NETDEV_XDP_ACT_MASK)
424428
pr_debug("unknown reported xdp features: 0x%lx\n",
425-
(unsigned long)opts.feature_flags & ~NETDEV_XDP_ACT_MASK);
429+
(unsigned long)feature_flags & ~NETDEV_XDP_ACT_MASK);
426430

427431
return 0;
428-
#else
429-
__unused const void *i = iface;
430-
431-
pr_warn("Cannot display features, because xdp-loader was compiled against an "
432-
"old version of libbpf without support for querying features.\n");
433-
434-
return -EOPNOTSUPP;
435-
#endif
436432
}
437433

438434
int do_features(const void *cfg, __unused const char *pin_root_path)

0 commit comments

Comments
 (0)