net: xdp: avoid output parameters when querying XDP prog

The output parameters will get unwieldy if we want to add more
information about the program.  Simply pass the entire
struct netdev_bpf in.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
Reviewed-by: Quentin Monnet <quentin.monnet@netronome.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
Jakub Kicinski 2017-12-01 15:08:55 -08:00 committed by Daniel Borkmann
parent 4485166519
commit 118b4aa25d
3 changed files with 21 additions and 12 deletions

View File

@ -3330,7 +3330,8 @@ struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf); typedef int (*bpf_op_t)(struct net_device *dev, struct netdev_bpf *bpf);
int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack, int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
int fd, u32 flags); int fd, u32 flags);
u8 __dev_xdp_attached(struct net_device *dev, bpf_op_t xdp_op, u32 *prog_id); void __dev_xdp_query(struct net_device *dev, bpf_op_t xdp_op,
struct netdev_bpf *xdp);
int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb); int __dev_forward_skb(struct net_device *dev, struct sk_buff *skb);
int dev_forward_skb(struct net_device *dev, struct sk_buff *skb); int dev_forward_skb(struct net_device *dev, struct sk_buff *skb);

View File

@ -7073,17 +7073,21 @@ int dev_change_proto_down(struct net_device *dev, bool proto_down)
} }
EXPORT_SYMBOL(dev_change_proto_down); EXPORT_SYMBOL(dev_change_proto_down);
u8 __dev_xdp_attached(struct net_device *dev, bpf_op_t bpf_op, u32 *prog_id) void __dev_xdp_query(struct net_device *dev, bpf_op_t bpf_op,
struct netdev_bpf *xdp)
{
memset(xdp, 0, sizeof(*xdp));
xdp->command = XDP_QUERY_PROG;
/* Query must always succeed. */
WARN_ON(bpf_op(dev, xdp) < 0);
}
static u8 __dev_xdp_attached(struct net_device *dev, bpf_op_t bpf_op)
{ {
struct netdev_bpf xdp; struct netdev_bpf xdp;
memset(&xdp, 0, sizeof(xdp)); __dev_xdp_query(dev, bpf_op, &xdp);
xdp.command = XDP_QUERY_PROG;
/* Query must always succeed. */
WARN_ON(bpf_op(dev, &xdp) < 0);
if (prog_id)
*prog_id = xdp.prog_id;
return xdp.prog_attached; return xdp.prog_attached;
} }
@ -7134,10 +7138,10 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
bpf_chk = generic_xdp_install; bpf_chk = generic_xdp_install;
if (fd >= 0) { if (fd >= 0) {
if (bpf_chk && __dev_xdp_attached(dev, bpf_chk, NULL)) if (bpf_chk && __dev_xdp_attached(dev, bpf_chk))
return -EEXIST; return -EEXIST;
if ((flags & XDP_FLAGS_UPDATE_IF_NOEXIST) && if ((flags & XDP_FLAGS_UPDATE_IF_NOEXIST) &&
__dev_xdp_attached(dev, bpf_op, NULL)) __dev_xdp_attached(dev, bpf_op))
return -EBUSY; return -EBUSY;
prog = bpf_prog_get_type_dev(fd, BPF_PROG_TYPE_XDP, prog = bpf_prog_get_type_dev(fd, BPF_PROG_TYPE_XDP,

View File

@ -1261,6 +1261,7 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id)
{ {
const struct net_device_ops *ops = dev->netdev_ops; const struct net_device_ops *ops = dev->netdev_ops;
const struct bpf_prog *generic_xdp_prog; const struct bpf_prog *generic_xdp_prog;
struct netdev_bpf xdp;
ASSERT_RTNL(); ASSERT_RTNL();
@ -1273,7 +1274,10 @@ static u8 rtnl_xdp_attached_mode(struct net_device *dev, u32 *prog_id)
if (!ops->ndo_bpf) if (!ops->ndo_bpf)
return XDP_ATTACHED_NONE; return XDP_ATTACHED_NONE;
return __dev_xdp_attached(dev, ops->ndo_bpf, prog_id); __dev_xdp_query(dev, ops->ndo_bpf, &xdp);
*prog_id = xdp.prog_id;
return xdp.prog_attached;
} }
static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev) static int rtnl_xdp_fill(struct sk_buff *skb, struct net_device *dev)