@@ -2487,6 +2487,53 @@ static int do_set_master(struct net_device *dev, int ifindex,
#define DO_SETLINK_MODIFIED 0x01
/* notify flag means notify + modified. */
#define DO_SETLINK_NOTIFY 0x03
+
+static int do_setlink_xdp(struct net_device *dev, struct nlattr *tb,
+ int *status, struct netlink_ext_ack *extack)
+{
+ struct nlattr *xdp[IFLA_XDP_MAX + 1];
+ u32 xdp_flags = 0;
+ int err;
+
+ err = nla_parse_nested_deprecated(xdp, IFLA_XDP_MAX, tb,
+ ifla_xdp_policy, NULL);
+ if (err < 0)
+ return err;
+
+ if (xdp[IFLA_XDP_ATTACHED] || xdp[IFLA_XDP_PROG_ID])
+ goto out_einval;
+
+ if (xdp[IFLA_XDP_FLAGS]) {
+ xdp_flags = nla_get_u32(xdp[IFLA_XDP_FLAGS]);
+ if (xdp_flags & ~XDP_FLAGS_MASK)
+ goto out_einval;
+ if (hweight32(xdp_flags & XDP_FLAGS_MODES) > 1)
+ goto out_einval;
+ }
+
+ if (xdp[IFLA_XDP_FD]) {
+ int expected_fd = -1;
+
+ if (xdp_flags & XDP_FLAGS_REPLACE) {
+ if (!xdp[IFLA_XDP_EXPECTED_FD])
+ goto out_einval;
+ expected_fd = nla_get_s32(xdp[IFLA_XDP_EXPECTED_FD]);
+ }
+
+ err = dev_change_xdp_fd(dev, extack,
+ nla_get_s32(xdp[IFLA_XDP_FD]),
+ expected_fd, xdp_flags);
+ if (err)
+ return err;
+
+ *status |= DO_SETLINK_NOTIFY;
+ }
+
+ return 0;
+out_einval:
+ return -EINVAL;
+}
+
static int do_setlink(const struct sk_buff *skb,
struct net_device *dev, struct ifinfomsg *ifm,
struct netlink_ext_ack *extack,
@@ -2781,52 +2828,9 @@ static int do_setlink(const struct sk_buff *skb,
}
if (tb[IFLA_XDP]) {
- struct nlattr *xdp[IFLA_XDP_MAX + 1];
- u32 xdp_flags = 0;
-
- err = nla_parse_nested_deprecated(xdp, IFLA_XDP_MAX,
- tb[IFLA_XDP],
- ifla_xdp_policy, NULL);
- if (err < 0)
- goto errout;
-
- if (xdp[IFLA_XDP_ATTACHED] || xdp[IFLA_XDP_PROG_ID]) {
- err = -EINVAL;
+ err = do_setlink_xdp(dev, tb[IFLA_XDP], &status, extack);
+ if (err)
goto errout;
- }
-
- if (xdp[IFLA_XDP_FLAGS]) {
- xdp_flags = nla_get_u32(xdp[IFLA_XDP_FLAGS]);
- if (xdp_flags & ~XDP_FLAGS_MASK) {
- err = -EINVAL;
- goto errout;
- }
- if (hweight32(xdp_flags & XDP_FLAGS_MODES) > 1) {
- err = -EINVAL;
- goto errout;
- }
- }
-
- if (xdp[IFLA_XDP_FD]) {
- int expected_fd = -1;
-
- if (xdp_flags & XDP_FLAGS_REPLACE) {
- if (!xdp[IFLA_XDP_EXPECTED_FD]) {
- err = -EINVAL;
- goto errout;
- }
- expected_fd =
- nla_get_s32(xdp[IFLA_XDP_EXPECTED_FD]);
- }
-
- err = dev_change_xdp_fd(dev, extack,
- nla_get_s32(xdp[IFLA_XDP_FD]),
- expected_fd,
- xdp_flags);
- if (err)
- goto errout;
- status |= DO_SETLINK_NOTIFY;
- }
}
errout: