提交 266e8347 编写于 作者: M Michael S. Tsirkin 提交者: David S. Miller

macvlan: better mode validation

macvlan passthrough mode is special: it's not possible to switch to or
from it through a netlink command.

But if you try, the command will succeed, which is
confusing.

Validate input and return error to user.

Cc:  Sridhar Samudrala <sri@us.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: NMichael S. Tsirkin <mst@redhat.com>
Signed-off-by: NDavid S. Miller <davem@davemloft.net>
上级 c756891a
...@@ -863,6 +863,18 @@ static int macvlan_changelink(struct net_device *dev, ...@@ -863,6 +863,18 @@ static int macvlan_changelink(struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[]) struct nlattr *tb[], struct nlattr *data[])
{ {
struct macvlan_dev *vlan = netdev_priv(dev); struct macvlan_dev *vlan = netdev_priv(dev);
enum macvlan_mode mode;
bool set_mode = false;
/* Validate mode, but don't set yet: setting flags may fail. */
if (data && data[IFLA_MACVLAN_MODE]) {
set_mode = true;
mode = nla_get_u32(data[IFLA_MACVLAN_MODE]);
/* Passthrough mode can't be set or cleared dynamically */
if ((mode == MACVLAN_MODE_PASSTHRU) !=
(vlan->mode == MACVLAN_MODE_PASSTHRU))
return -EINVAL;
}
if (data && data[IFLA_MACVLAN_FLAGS]) { if (data && data[IFLA_MACVLAN_FLAGS]) {
__u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); __u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
...@@ -879,8 +891,8 @@ static int macvlan_changelink(struct net_device *dev, ...@@ -879,8 +891,8 @@ static int macvlan_changelink(struct net_device *dev,
} }
vlan->flags = flags; vlan->flags = flags;
} }
if (data && data[IFLA_MACVLAN_MODE]) if (set_mode)
vlan->mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); vlan->mode = mode;
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册