aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2007-07-11 22:42:31 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-07-11 22:45:36 -0400
commit0e06877c6fdbc67b1132be895f995acd1ff30135 (patch)
treeddaba8cddc8a95d23ee18f812c6aba67dd9b1c6f
parent2d85cba2b272a5201a60966a65a4f8c0bcc0bb71 (diff)
[RTNETLINK]: rtnl_link: allow specifying initial device address
Drivers need to validate the initial addresses in their netlink attribute validation function or manually reject them if they can't support this. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/dummy.c12
-rw-r--r--drivers/net/ifb.c12
-rw-r--r--net/8021q/vlan.c8
-rw-r--r--net/8021q/vlan_netlink.c7
-rw-r--r--net/core/rtnetlink.c9
5 files changed, 44 insertions, 4 deletions
diff --git a/drivers/net/dummy.c b/drivers/net/dummy.c
index 373ff700404f..756a6bcb038d 100644
--- a/drivers/net/dummy.c
+++ b/drivers/net/dummy.c
@@ -84,9 +84,21 @@ static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)
84 return 0; 84 return 0;
85} 85}
86 86
87static int dummy_validate(struct nlattr *tb[], struct nlattr *data[])
88{
89 if (tb[IFLA_ADDRESS]) {
90 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
91 return -EINVAL;
92 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
93 return -EADDRNOTAVAIL;
94 }
95 return 0;
96}
97
87static struct rtnl_link_ops dummy_link_ops __read_mostly = { 98static struct rtnl_link_ops dummy_link_ops __read_mostly = {
88 .kind = "dummy", 99 .kind = "dummy",
89 .setup = dummy_setup, 100 .setup = dummy_setup,
101 .validate = dummy_validate,
90}; 102};
91 103
92/* Number of dummy devices to be set up by this module. */ 104/* Number of dummy devices to be set up by this module. */
diff --git a/drivers/net/ifb.c b/drivers/net/ifb.c
index c8e7c8f6ba3e..f5c3598e59af 100644
--- a/drivers/net/ifb.c
+++ b/drivers/net/ifb.c
@@ -221,10 +221,22 @@ static int ifb_open(struct net_device *dev)
221 return 0; 221 return 0;
222} 222}
223 223
224static int ifb_validate(struct nlattr *tb[], struct nlattr *data[])
225{
226 if (tb[IFLA_ADDRESS]) {
227 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
228 return -EINVAL;
229 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
230 return -EADDRNOTAVAIL;
231 }
232 return 0;
233}
234
224static struct rtnl_link_ops ifb_link_ops __read_mostly = { 235static struct rtnl_link_ops ifb_link_ops __read_mostly = {
225 .kind = "ifb", 236 .kind = "ifb",
226 .priv_size = sizeof(struct ifb_private), 237 .priv_size = sizeof(struct ifb_private),
227 .setup = ifb_setup, 238 .setup = ifb_setup,
239 .validate = ifb_validate,
228}; 240};
229 241
230/* Number of ifb devices to be set up by this module. */ 242/* Number of ifb devices to be set up by this module. */
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 34c1d0b241ca..abb9900edb3f 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -324,8 +324,10 @@ static int vlan_dev_init(struct net_device *dev)
324 (1<<__LINK_STATE_DORMANT))) | 324 (1<<__LINK_STATE_DORMANT))) |
325 (1<<__LINK_STATE_PRESENT); 325 (1<<__LINK_STATE_PRESENT);
326 326
327 memcpy(dev->broadcast, real_dev->broadcast, real_dev->addr_len); 327 if (is_zero_ether_addr(dev->dev_addr))
328 memcpy(dev->dev_addr, real_dev->dev_addr, real_dev->addr_len); 328 memcpy(dev->dev_addr, real_dev->dev_addr, dev->addr_len);
329 if (is_zero_ether_addr(dev->broadcast))
330 memcpy(dev->broadcast, real_dev->broadcast, dev->addr_len);
329 331
330 if (real_dev->features & NETIF_F_HW_VLAN_TX) { 332 if (real_dev->features & NETIF_F_HW_VLAN_TX) {
331 dev->hard_header = real_dev->hard_header; 333 dev->hard_header = real_dev->hard_header;
@@ -373,6 +375,8 @@ void vlan_setup(struct net_device *new_dev)
373 new_dev->set_multicast_list = vlan_dev_set_multicast_list; 375 new_dev->set_multicast_list = vlan_dev_set_multicast_list;
374 new_dev->destructor = free_netdev; 376 new_dev->destructor = free_netdev;
375 new_dev->do_ioctl = vlan_dev_ioctl; 377 new_dev->do_ioctl = vlan_dev_ioctl;
378
379 memset(new_dev->broadcast, 0, sizeof(ETH_ALEN));
376} 380}
377 381
378static void vlan_transfer_operstate(const struct net_device *dev, struct net_device *vlandev) 382static void vlan_transfer_operstate(const struct net_device *dev, struct net_device *vlandev)
diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c
index 844c7e43d0fa..6cdd1e015e2d 100644
--- a/net/8021q/vlan_netlink.c
+++ b/net/8021q/vlan_netlink.c
@@ -41,6 +41,13 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[])
41 u16 id; 41 u16 id;
42 int err; 42 int err;
43 43
44 if (tb[IFLA_ADDRESS]) {
45 if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN)
46 return -EINVAL;
47 if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS])))
48 return -EADDRNOTAVAIL;
49 }
50
44 if (!data) 51 if (!data)
45 return -EINVAL; 52 return -EINVAL;
46 53
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 7b6b16396745..864cbdf31ed7 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1032,8 +1032,7 @@ replay:
1032 1032
1033 if (ifm->ifi_index || ifm->ifi_flags || ifm->ifi_change) 1033 if (ifm->ifi_index || ifm->ifi_flags || ifm->ifi_change)
1034 return -EOPNOTSUPP; 1034 return -EOPNOTSUPP;
1035 if (tb[IFLA_ADDRESS] || tb[IFLA_BROADCAST] || tb[IFLA_MAP] || 1035 if (tb[IFLA_MAP] || tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
1036 tb[IFLA_MASTER] || tb[IFLA_PROTINFO])
1037 return -EOPNOTSUPP; 1036 return -EOPNOTSUPP;
1038 1037
1039 if (!ops) { 1038 if (!ops) {
@@ -1065,6 +1064,12 @@ replay:
1065 1064
1066 if (tb[IFLA_MTU]) 1065 if (tb[IFLA_MTU])
1067 dev->mtu = nla_get_u32(tb[IFLA_MTU]); 1066 dev->mtu = nla_get_u32(tb[IFLA_MTU]);
1067 if (tb[IFLA_ADDRESS])
1068 memcpy(dev->dev_addr, nla_data(tb[IFLA_ADDRESS]),
1069 nla_len(tb[IFLA_ADDRESS]));
1070 if (tb[IFLA_BROADCAST])
1071 memcpy(dev->broadcast, nla_data(tb[IFLA_BROADCAST]),
1072 nla_len(tb[IFLA_BROADCAST]));
1068 if (tb[IFLA_TXQLEN]) 1073 if (tb[IFLA_TXQLEN])
1069 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]); 1074 dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
1070 if (tb[IFLA_WEIGHT]) 1075 if (tb[IFLA_WEIGHT])