aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael S. Tsirkin <mst@redhat.com>2013-08-01 06:43:19 -0400
committerDavid S. Miller <davem@davemloft.net>2013-08-01 19:32:05 -0400
commit266e83474c98e9f18d31f4837cfe05819a660d32 (patch)
treeee1ee950654dcb6eab2f2d3f78f03db4a29e3ae1
parentc756891a4e1c08c43780e17aca1d2b849ef31d1a (diff)
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: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/macvlan.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 18373b6ae37d..13937f9c04ad 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -863,6 +863,18 @@ static int macvlan_changelink(struct net_device *dev,
863 struct nlattr *tb[], struct nlattr *data[]) 863 struct nlattr *tb[], struct nlattr *data[])
864{ 864{
865 struct macvlan_dev *vlan = netdev_priv(dev); 865 struct macvlan_dev *vlan = netdev_priv(dev);
866 enum macvlan_mode mode;
867 bool set_mode = false;
868
869 /* Validate mode, but don't set yet: setting flags may fail. */
870 if (data && data[IFLA_MACVLAN_MODE]) {
871 set_mode = true;
872 mode = nla_get_u32(data[IFLA_MACVLAN_MODE]);
873 /* Passthrough mode can't be set or cleared dynamically */
874 if ((mode == MACVLAN_MODE_PASSTHRU) !=
875 (vlan->mode == MACVLAN_MODE_PASSTHRU))
876 return -EINVAL;
877 }
866 878
867 if (data && data[IFLA_MACVLAN_FLAGS]) { 879 if (data && data[IFLA_MACVLAN_FLAGS]) {
868 __u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]); 880 __u16 flags = nla_get_u16(data[IFLA_MACVLAN_FLAGS]);
@@ -879,8 +891,8 @@ static int macvlan_changelink(struct net_device *dev,
879 } 891 }
880 vlan->flags = flags; 892 vlan->flags = flags;
881 } 893 }
882 if (data && data[IFLA_MACVLAN_MODE]) 894 if (set_mode)
883 vlan->mode = nla_get_u32(data[IFLA_MACVLAN_MODE]); 895 vlan->mode = mode;
884 return 0; 896 return 0;
885} 897}
886 898