Skip to content

Commit 4f91da2

Browse files
Jakub Kicinskiborkmann
authored andcommitted
xdp: add per mode attributes for attached programs
In preparation for support of simultaneous driver and hardware XDP support add per-mode attributes. The catch-all IFLA_XDP_PROG_ID will still be reported, but user space can now also access the program ID in a new IFLA_XDP_<mode>_PROG_ID attribute. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Quentin Monnet <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]>
1 parent 9c48b1d commit 4f91da2

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

include/uapi/linux/if_link.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,9 @@ enum {
928928
IFLA_XDP_ATTACHED,
929929
IFLA_XDP_FLAGS,
930930
IFLA_XDP_PROG_ID,
931+
IFLA_XDP_DRV_PROG_ID,
932+
IFLA_XDP_SKB_PROG_ID,
933+
IFLA_XDP_HW_PROG_ID,
931934
__IFLA_XDP_MAX,
932935
};
933936

net/core/rtnetlink.c

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,8 @@ static size_t rtnl_xdp_size(void)
964964
{
965965
size_t xdp_size = nla_total_size(0) + /* nest IFLA_XDP */
966966
nla_total_size(1) + /* XDP_ATTACHED */
967-
nla_total_size(4); /* XDP_PROG_ID */
967+
nla_total_size(4) + /* XDP_PROG_ID */
968+
nla_total_size(4); /* XDP_<mode>_PROG_ID */
968969

969970
return xdp_size;
970971
}
@@ -1378,23 +1379,44 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id)
13781379

13791380
static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
13801381
{
1382+
u32 prog_attr, prog_id;
13811383
struct nlattr *xdp;
1382-
u32 prog_id;
13831384
int err;
1385+
u8 mode;
13841386

13851387
xdp = nla_nest_start(skb, IFLA_XDP);
13861388
if (!xdp)
13871389
return -EMSGSIZE;
13881390

1389-
err = nla_put_u8(skb, IFLA_XDP_ATTACHED,
1390-
rtnl_xdp_attached_mode(dev, &prog_id));
1391+
mode = rtnl_xdp_attached_mode(dev, &prog_id);
1392+
err = nla_put_u8(skb, IFLA_XDP_ATTACHED, mode);
13911393
if (err)
13921394
goto err_cancel;
13931395

13941396
if (prog_id) {
13951397
err = nla_put_u32(skb, IFLA_XDP_PROG_ID, prog_id);
13961398
if (err)
13971399
goto err_cancel;
1400+
1401+
switch (mode) {
1402+
case XDP_ATTACHED_DRV:
1403+
prog_attr = IFLA_XDP_DRV_PROG_ID;
1404+
break;
1405+
case XDP_ATTACHED_SKB:
1406+
prog_attr = IFLA_XDP_SKB_PROG_ID;
1407+
break;
1408+
case XDP_ATTACHED_HW:
1409+
prog_attr = IFLA_XDP_HW_PROG_ID;
1410+
break;
1411+
case XDP_ATTACHED_NONE:
1412+
default:
1413+
err = -EINVAL;
1414+
goto err_cancel;
1415+
}
1416+
1417+
err = nla_put_u32(skb, prog_attr, prog_id);
1418+
if (err)
1419+
goto err_cancel;
13981420
}
13991421

14001422
nla_nest_end(skb, xdp);

0 commit comments

Comments
 (0)