Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
@ -8655,15 +8655,17 @@ static void dev_xdp_uninstall(struct net_device *dev)
|
||||
* @dev: device
|
||||
* @extack: netlink extended ack
|
||||
* @fd: new program fd or negative value to clear
|
||||
* @expected_fd: old program fd that userspace expects to replace or clear
|
||||
* @flags: xdp-related flags
|
||||
*
|
||||
* Set or clear a bpf program for a device
|
||||
*/
|
||||
int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
|
||||
int fd, u32 flags)
|
||||
int fd, int expected_fd, u32 flags)
|
||||
{
|
||||
const struct net_device_ops *ops = dev->netdev_ops;
|
||||
enum bpf_netdev_command query;
|
||||
u32 prog_id, expected_id = 0;
|
||||
struct bpf_prog *prog = NULL;
|
||||
bpf_op_t bpf_op, bpf_chk;
|
||||
bool offload;
|
||||
@ -8684,15 +8686,29 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
|
||||
if (bpf_op == bpf_chk)
|
||||
bpf_chk = generic_xdp_install;
|
||||
|
||||
if (fd >= 0) {
|
||||
u32 prog_id;
|
||||
prog_id = __dev_xdp_query(dev, bpf_op, query);
|
||||
if (flags & XDP_FLAGS_REPLACE) {
|
||||
if (expected_fd >= 0) {
|
||||
prog = bpf_prog_get_type_dev(expected_fd,
|
||||
BPF_PROG_TYPE_XDP,
|
||||
bpf_op == ops->ndo_bpf);
|
||||
if (IS_ERR(prog))
|
||||
return PTR_ERR(prog);
|
||||
expected_id = prog->aux->id;
|
||||
bpf_prog_put(prog);
|
||||
}
|
||||
|
||||
if (prog_id != expected_id) {
|
||||
NL_SET_ERR_MSG(extack, "Active program does not match expected");
|
||||
return -EEXIST;
|
||||
}
|
||||
}
|
||||
if (fd >= 0) {
|
||||
if (!offload && __dev_xdp_query(dev, bpf_chk, XDP_QUERY_PROG)) {
|
||||
NL_SET_ERR_MSG(extack, "native and generic XDP can't be active at the same time");
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
prog_id = __dev_xdp_query(dev, bpf_op, query);
|
||||
if ((flags & XDP_FLAGS_UPDATE_IF_NOEXIST) && prog_id) {
|
||||
NL_SET_ERR_MSG(extack, "XDP program already attached");
|
||||
return -EBUSY;
|
||||
@ -8715,7 +8731,7 @@ int dev_change_xdp_fd(struct net_device *dev, struct netlink_ext_ack *extack,
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
if (!__dev_xdp_query(dev, bpf_op, query))
|
||||
if (!prog_id)
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user