Skip to content

Commit 01dde20

Browse files
Maciej Fijalkowskiborkmann
authored andcommitted
xdp: Provide extack messages when prog attachment failed
In order to provide more meaningful messages to user when the process of loading xdp program onto network interface failed, let's add extack messages within dev_change_xdp_fd. Suggested-by: Jakub Kicinski <[email protected]> Signed-off-by: Maciej Fijalkowski <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 6a54576 commit 01dde20

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

net/core/dev.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7983,20 +7983,26 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
79837983
query = flags & XDP_FLAGS_HW_MODE ? XDP_QUERY_PROG_HW : XDP_QUERY_PROG;
79847984

79857985
bpf_op = bpf_chk = ops->ndo_bpf;
7986-
if (!bpf_op && (flags & (XDP_FLAGS_DRV_MODE | XDP_FLAGS_HW_MODE)))
7986+
if (!bpf_op && (flags & (XDP_FLAGS_DRV_MODE | XDP_FLAGS_HW_MODE))) {
7987+
NL_SET_ERR_MSG(extack, "underlying driver does not support XDP in native mode");
79877988
return -EOPNOTSUPP;
7989+
}
79887990
if (!bpf_op || (flags & XDP_FLAGS_SKB_MODE))
79897991
bpf_op = generic_xdp_install;
79907992
if (bpf_op == bpf_chk)
79917993
bpf_chk = generic_xdp_install;
79927994

79937995
if (fd >= 0) {
79947996
if (__dev_xdp_query(dev, bpf_chk, XDP_QUERY_PROG) ||
7995-
__dev_xdp_query(dev, bpf_chk, XDP_QUERY_PROG_HW))
7997+
__dev_xdp_query(dev, bpf_chk, XDP_QUERY_PROG_HW)) {
7998+
NL_SET_ERR_MSG(extack, "native and generic XDP can't be active at the same time");
79967999
return -EEXIST;
8000+
}
79978001
if ((flags & XDP_FLAGS_UPDATE_IF_NOEXIST) &&
7998-
__dev_xdp_query(dev, bpf_op, query))
8002+
__dev_xdp_query(dev, bpf_op, query)) {
8003+
NL_SET_ERR_MSG(extack, "XDP program already attached");
79998004
return -EBUSY;
8005+
}
80008006

80018007
prog = bpf_prog_get_type_dev(fd, BPF_PROG_TYPE_XDP,
80028008
bpf_op == ops->ndo_bpf);

0 commit comments

Comments
 (0)