Skip to content

Commit

Permalink
xdp: add per mode attributes for attached programs
Browse files Browse the repository at this point in the history
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 <jakub.kicinski@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
  • Loading branch information
Jakub Kicinski authored and Daniel Borkmann committed Jul 13, 2018
1 parent 9c48b1d commit 4f91da2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
3 changes: 3 additions & 0 deletions include/uapi/linux/if_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -928,6 +928,9 @@ enum {
IFLA_XDP_ATTACHED,
IFLA_XDP_FLAGS,
IFLA_XDP_PROG_ID,
IFLA_XDP_DRV_PROG_ID,
IFLA_XDP_SKB_PROG_ID,
IFLA_XDP_HW_PROG_ID,
__IFLA_XDP_MAX,
};

Expand Down
30 changes: 26 additions & 4 deletions net/core/rtnetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,8 @@ static size_t rtnl_xdp_size(void)
{
size_t xdp_size = nla_total_size(0) + /* nest IFLA_XDP */
nla_total_size(1) + /* XDP_ATTACHED */
nla_total_size(4); /* XDP_PROG_ID */
nla_total_size(4) + /* XDP_PROG_ID */
nla_total_size(4); /* XDP_<mode>_PROG_ID */

return xdp_size;
}
Expand Down Expand Up @@ -1378,23 +1379,44 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id)

static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)
{
u32 prog_attr, prog_id;
struct nlattr *xdp;
u32 prog_id;
int err;
u8 mode;

xdp = nla_nest_start(skb, IFLA_XDP);
if (!xdp)
return -EMSGSIZE;

err = nla_put_u8(skb, IFLA_XDP_ATTACHED,
rtnl_xdp_attached_mode(dev, &prog_id));
mode = rtnl_xdp_attached_mode(dev, &prog_id);
err = nla_put_u8(skb, IFLA_XDP_ATTACHED, mode);
if (err)
goto err_cancel;

if (prog_id) {
err = nla_put_u32(skb, IFLA_XDP_PROG_ID, prog_id);
if (err)
goto err_cancel;

switch (mode) {
case XDP_ATTACHED_DRV:
prog_attr = IFLA_XDP_DRV_PROG_ID;
break;
case XDP_ATTACHED_SKB:
prog_attr = IFLA_XDP_SKB_PROG_ID;
break;
case XDP_ATTACHED_HW:
prog_attr = IFLA_XDP_HW_PROG_ID;
break;
case XDP_ATTACHED_NONE:
default:
err = -EINVAL;
goto err_cancel;
}

err = nla_put_u32(skb, prog_attr, prog_id);
if (err)
goto err_cancel;
}

nla_nest_end(skb, xdp);
Expand Down

0 comments on commit 4f91da2

Please sign in to comment.