: rtnl_link improvements
Subsystems (2)
cover : rtnl_link improvements
These patches simplify the rtnl_link API and add support for specifying the initial device address. The rtnl_link patches depend on the VLAN fix because I didn't want to build on top of the broken address handling.
Please apply, thanks.
drivers/net/dummy.c | 61 ++++++++------------------------------------ drivers/net/ifb.c | 62 ++++++++++---------------------------------- include/linux/if_vlan.h | 1 + net/8021q/vlan.c | 64 ++++++++++++++++++++++++++-------------------- net/8021q/vlan.h | 1 - net/8021q/vlan_dev.c | 57 +++++++++++++---------------------------- net/8021q/vlan_netlink.c | 7 +++++ net/core/rtnetlink.c | 27 +++++++++++++++---- net/ethernet/eth.c | 3 ++ 9 files changed, 111 insertions(+), 172 deletions(-)
Patrick McHardy (4):
[ETH]: Validate address in eth_mac_addr
[VLAN]: Fix MAC address handling
[RTNETLINK]: rtnl_link API simplification [RTNETLINK]: rtnl_link: allow specifying initial device address
PATCH 1/4 : Validate address in eth_mac_addr
[ETH]: Validate address in eth_mac_addr
---
commit 690fb4dbafa9f60f8cb520d5def544580107b3a4
tree ded62c0fcd8497b5cf9459213e1579cc700abb39
parent 99d24edeb6abc6ca3a0d0fbdb83c664c04403c8c
author Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:23:22 +0200 committer Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:23:22 +0200
net/ethernet/eth.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
net/ethernet/eth.c +3 -0
@@ -266,8 +266,11 @@ void eth_header_cache_update(struct hh_cache *hh, struct net_device *dev,static int eth_mac_addr (struct net_device *dev,void *p) {struct sockaddr *addr = p; +if (netif_running (dev))return -EBUSY ; +if (!is_valid_ether_addr (addr->sa_data)) +return -EADDRNOTAVAIL ;memcpy (dev->dev_addr, addr->sa_data, dev->addr_len);return 0 ; }
Re: [ETH 01/04]: Validate address in eth_mac_addr
From: Patrick McHardy <[email protected]>
Date: Wed, 11 Jul 2007 19:38:14 +0200 (MEST)
Quoted 3 lines
[ETH]: Validate address in
eth_mac_addrSigned-off-by Patrick McHardy <[email protected]>
Applied.
PATCH 2/4 : Fix MAC address handling
In reply to Patrick McHardy[VLAN]: Fix MAC address handling
The VLAN MAC address handling is broken in multiple ways. When the address differs when setting it, the real device is put in promiscous mode twice, but never taken out again. Additionally it doesn't resync when the real device's address is changed and needlessly puts it in promiscous mode when the vlan device is still down.
Fix by moving address handling to vlan_dev_open/vlan_dev_stop and properly deal with address changes in the device notifier. Also switch to dev_unicast_add (which needs the exact same handling).
Since the set_mac_address handler is identical to the generic ethernet one with these changes, kill it and use ether_setup().
---
commit f5402e5ada051f17384c089fc49b247fa62e9723
tree 9e4642678929a19229893c7c8656cf11e1ad7401
parent 690fb4dbafa9f60f8cb520d5def544580107b3a4
author Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:27:21 +0200 committer Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:27:21 +0200
include/linux/if_vlan.h | 1 + net/8021q/vlan.c | 35 +++++++++++++++++++++++++---- net/8021q/vlan.h | 1 - net/8021q/vlan_dev.c | 57 +++++++++++++++-------------------------------- 4 files changed, 49 insertions(+), 45 deletions(-)
include/linux/if_vlan.h +1 -0
@@ -135,6 +135,7 @@ struct vlan_dev_info {int old_allmulti;/* similar to above. */ int old_promiscuity;/* similar to above. */ struct net_device *real_dev;/* the underlying device/interface */ +unsigned char real_dev_addr[ETH_ALEN ];struct proc_dir_entry *dent;/* Holds the proc data */ unsigned long cnt_inc_headroom_on_tx;/* How many times did we have to grow the skb on TX. */ unsigned long cnt_encap_on_xmit;/* How many times did we have to encapsulate the skb on TX. */
net/8021q/vlan.c +30 -5
@@ -345,12 +345,8 @@ static int vlan_dev_init(struct net_device *dev) (1<<__LINK_STATE_DORMANT))) | (1 <<__LINK_STATE_PRESENT); -/* TODO: maybe just assign it to be ETHERNET? */ - dev->type = real_dev->type; -memcpy (dev->broadcast, real_dev->broadcast, real_dev->addr_len);memcpy (dev->dev_addr, real_dev->dev_addr, real_dev->addr_len); - dev->addr_len = real_dev->addr_len;if (real_dev->features &NETIF_F_HW_VLAN_TX ) { dev->hard_header = real_dev->hard_header;
@@ -364,6 +360,7 @@ static int vlan_dev_init(struct net_device *dev) dev->rebuild_header = vlan_dev_rebuild_header; } dev->hard_header_parse = real_dev->hard_header_parse; + dev->hard_header_cache =NULL ;lockdep_set_class (&dev->_xmit_lock, &vlan_netdev_xmit_lock_key);return 0 ;
@@ -373,6 +370,8 @@ void vlan_setup(struct net_device *new_dev) {SET_MODULE_OWNER (new_dev); +ether_setup (new_dev); +/* new_dev->ifindex = 0; it will be set when added to * the global list. * iflink is set as well.
@@ -392,7 +391,6 @@ void vlan_setup(struct net_device *new_dev) new_dev->init = vlan_dev_init; new_dev->open = vlan_dev_open; new_dev->stop = vlan_dev_stop; - new_dev->set_mac_address = vlan_dev_set_mac_address; new_dev->set_multicast_list = vlan_dev_set_multicast_list; new_dev->destructor = free_netdev; new_dev->do_ioctl = vlan_dev_ioctl;
@@ -592,6 +590,22 @@ out_free_newdev:return err; } +static void vlan_sync_address (struct net_device *dev, +struct net_device *vlandev) +{ +struct vlan_dev_info *vlan =VLAN_DEV_INFO (vlandev); + +if (!compare_ether_addr (vlan->real_dev_addr, dev->dev_addr)) +return ; + +if (compare_ether_addr (vlandev->dev_addr, dev->dev_addr)) +dev_unicast_add (dev, vlandev->dev_addr,ETH_ALEN ); +else +dev_unicast_delete (dev, vlandev->dev_addr,ETH_ALEN ); + +memcpy (vlan->real_dev_addr, dev->dev_addr,ETH_ALEN ); +} +static int vlan_device_event (struct notifier_block *unused,unsigned long event,void *ptr) {struct net_device *dev = ptr;
@@ -618,6 +632,17 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event, }break ; +case NETDEV_CHANGEADDR : +/* Adjust unicast filters on underlying device */ +for (i =0 ; i <VLAN_GROUP_ARRAY_LEN ; i++) { + vlandev =vlan_group_get_device (grp, i); +if (!vlandev) +continue ; + +vlan_sync_address (dev, vlandev); + } +break ; +case NETDEV_DOWN :/* Put all VLANs for this dev in the down state too. */ for (i =0 ; i <VLAN_GROUP_ARRAY_LEN ; i++) {
net/8021q/vlan.h +0 -1
@@ -58,7 +58,6 @@ int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,int vlan_dev_hard_start_xmit (struct sk_buff *skb,struct net_device *dev);int vlan_dev_hwaccel_hard_start_xmit (struct sk_buff *skb,struct net_device *dev);int vlan_dev_change_mtu (struct net_device *dev,int new_mtu); -int vlan_dev_set_mac_address (struct net_device *dev,void * addr);int vlan_dev_open (struct net_device * dev);int vlan_dev_stop (struct net_device * dev);int vlan_dev_ioctl (struct net_device * dev,struct ifreq *ifr,int cmd);
net/8021q/vlan_dev.c +18 -39
77 lines not on this page · raw message
Re: [VLAN 02/04]: Fix MAC address handling
Quoted 7 lines · Patrick McHardy
[VLAN]: Fix MAC address handling
(quoted diff) +5
-0+static void vlan_sync_address(struct net_device *dev, + struct net_device *vlandev) +{ + struct vlan_dev_info *vlan = VLAN_DEV_INFO(vlandev); +
Review
Quoted 10 lines
(quoted diff) +10
-0+ if (!compare_ether_addr(vlan->real_dev_addr, dev->dev_addr)) + return; + + if (compare_ether_addr(vlandev->dev_addr, dev->dev_addr)) + dev_unicast_add(dev, vlandev->dev_addr, ETH_ALEN); + else + dev_unicast_delete(dev, vlandev->dev_addr, ETH_ALEN); + + memcpy(vlan->real_dev_addr, dev->dev_addr, ETH_ALEN); +}
Unfortunately the one case I didn't test is still wrong :|
The above synchronization incorrectly removes the address in case if was different before and is still different afterwards. This patch is fixed and contains a few comments as an added bonus :)
[VLAN]: Fix MAC address handling
The VLAN MAC address handling is broken in multiple ways. When the address differs when setting it, the real device is put in promiscous mode twice, but never taken out again. Additionally it doesn't resync when the real device's address is changed and needlessly puts it in promiscous mode when the vlan device is still down.
Fix by moving address handling to vlan_dev_open/vlan_dev_stop and properly deal with address changes in the device notifier. Also switch to dev_unicast_add (which needs the exact same handling).
Since the set_mac_address handler is identical to the generic ethernet one with these changes, kill it and use ether_setup().
---
commit 7d0a5d2f8d28ebe95cda8d2e16bf6d8030efc8b3
tree d91afa76b1aaaaa069a435967b8627f6aa820e13
parent 690fb4dbafa9f60f8cb520d5def544580107b3a4
author Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:52:08 +0200 committer Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:52:08 +0200
include/linux/if_vlan.h | 1 + net/8021q/vlan.c | 43 +++++++++++++++++++++++++++++++---- net/8021q/vlan.h | 1 - net/8021q/vlan_dev.c | 57 +++++++++++++++-------------------------------- 4 files changed, 57 insertions(+), 45 deletions(-)
include/linux/if_vlan.h +1 -0
@@ -135,6 +135,7 @@ struct vlan_dev_info {int old_allmulti;/* similar to above. */ int old_promiscuity;/* similar to above. */ struct net_device *real_dev;/* the underlying device/interface */ +unsigned char real_dev_addr[ETH_ALEN ];struct proc_dir_entry *dent;/* Holds the proc data */ unsigned long cnt_inc_headroom_on_tx;/* How many times did we have to grow the skb on TX. */ unsigned long cnt_encap_on_xmit;/* How many times did we have to encapsulate the skb on TX. */
net/8021q/vlan.c +38 -5
81 lines not on this page · raw message
net/8021q/vlan.h +0 -1
@@ -58,7 +58,6 @@ int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,int vlan_dev_hard_start_xmit (struct sk_buff *skb,struct net_device *dev);int vlan_dev_hwaccel_hard_start_xmit (struct sk_buff *skb,struct net_device *dev);int vlan_dev_change_mtu (struct net_device *dev,int new_mtu); -int vlan_dev_set_mac_address (struct net_device *dev,void * addr);int vlan_dev_open (struct net_device * dev);int vlan_dev_stop (struct net_device * dev);int vlan_dev_ioctl (struct net_device * dev,struct ifreq *ifr,int cmd);
net/8021q/vlan_dev.c +18 -39
77 lines not on this page · raw message
Re: [VLAN 02/04]: Fix MAC address handling
Quoted 22 lines · Patrick McHardy
Quoted 7 lines · Patrick McHardy
[VLAN]: Fix MAC address handling
net/8021q/vlan.c +5
-0+static void vlan_sync_address (struct net_device *dev, +struct net_device *vlandev) +{ +struct vlan_dev_info *vlan =VLAN_DEV_INFO (vlandev); +net/8021q/vlan.c out_free_newdev: · line 615
Quoted 10 lines
net/8021q/vlan.c +10
-0+if (!compare_ether_addr (vlan->real_dev_addr, dev->dev_addr)) +return ; + +if (compare_ether_addr (vlandev->dev_addr, dev->dev_addr)) +dev_unicast_add (dev, vlandev->dev_addr,ETH_ALEN ); +else +dev_unicast_delete (dev, vlandev->dev_addr,ETH_ALEN ); + +memcpy (vlan->real_dev_addr, dev->dev_addr,ETH_ALEN ); +}Unfortunately the one case I didn't test is still wrong :|
Quoted 3 lines
The above synchronization incorrectly removes the address in case if was different before and is still different afterwards. This patch is fixed and contains a few comments as an added bonus :)
The new patch looks good to me..though this is some tricky code so I might have missed something...
Thanks,
Ben
Signature · 2 lines
Ben Greear <[email protected]> Candela Technologies Inc http://www.candelatech.com
Re: [VLAN 02/04]: Fix MAC address handling
Quoted 6 lines · Ben Greear
Quoted 3 lines
Quoted 1 line · Patrick McHardy
[VLAN]: Fix MAC address handling
The new patch looks good to me..though this is some tricky code so I might have missed something...
Thanks Ben. I'm pretty sure the new one is fine. Definitely not worse than before :)
David Miller
maintainerRe: [VLAN 02/04]: Fix MAC address handling
In reply to Patrick McHardyFrom: Patrick McHardy <[email protected]>
Date: Wed, 11 Jul 2007 19:54:18 +0200
Quoted 22 lines
Quoted 7 lines · Patrick McHardy
[VLAN]: Fix MAC address handling
net/8021q/vlan.c +5
-0+static void vlan_sync_address (struct net_device *dev, +struct net_device *vlandev) +{ +struct vlan_dev_info *vlan =VLAN_DEV_INFO (vlandev); +net/8021q/vlan.c out_free_newdev: · line 615
Quoted 10 lines
net/8021q/vlan.c +10
-0+if (!compare_ether_addr (vlan->real_dev_addr, dev->dev_addr)) +return ; + +if (compare_ether_addr (vlandev->dev_addr, dev->dev_addr)) +dev_unicast_add (dev, vlandev->dev_addr,ETH_ALEN ); +else +dev_unicast_delete (dev, vlandev->dev_addr,ETH_ALEN ); + +memcpy (vlan->real_dev_addr, dev->dev_addr,ETH_ALEN ); +}Unfortunately the one case I didn't test is still wrong :|
Quoted 3 lines
The above synchronization incorrectly removes the address in case if was different before and is still different afterwards. This patch is fixed and contains a few comments as an added bonus :)
So there is no confusion, I made sure to use this updated version of the patch. :)
Re: [VLAN 02/04]: Fix MAC address handling
In reply to Patrick McHardyFrom: Patrick McHardy <[email protected]>
Date: Wed, 11 Jul 2007 19:38:16 +0200 (MEST)
Quoted 8 lines
[VLAN]: Fix MAC address handling
The VLAN MAC address handling is broken in multiple ways. When the address differs when setting it, the real device is put in promiscous mode twice, but never taken out again. Additionally it doesn't resync when the real device's address is changed and needlessly puts it in promiscous mode when the vlan device is still down.
Quoted 8 lines
Fix by moving address handling to vlan_dev_open/vlan_dev_stop and properly deal with address changes in the device notifier. Also switch to
dev_unicast_add(which needs the exact same handling).Since the
set_mac_addresshandler is identical to the generic ethernet one with these changes, kill it and useether_setup().Signed-off-by Patrick McHardy <[email protected]>
Applied, thanks.
PATCH 3/4 : rtnl_link API simplification
In reply to Patrick McHardy[RTNETLINK]: rtnl_link API simplification
All drivers need to unregister their devices in the module unload function. While doing so they must hold the rtnl and atomically unregister the rtnl_link ops as well. This makes the rtnl_link_unregister function that takes the rtnl itself completely useless.
Provide default newlink/dellink functions, make __rtnl_link_unregister and rtnl_link_unregister unregister all devices with matching rtnl_link_ops and change the existing users to take advantage of that.
---
commit 88fcde1e75dbfad7e7210642c0364850eed2591e
tree 0d1fd7e324bc69b02a01d8499a48abb6aeae5704
parent f5402e5ada051f17384c089fc49b247fa62e9723
author Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:27:32 +0200 committer Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:27:32 +0200
drivers/net/dummy.c | 57 +++---------------------------------------------- drivers/net/ifb.c | 58 +++++--------------------------------------------- net/8021q/vlan.c | 21 ------------------ net/core/rtnetlink.c | 18 ++++++++++++---- 4 files changed, 23 insertions(+), 131 deletions(-)
drivers/net/dummy.c +3 -54
@@ -37,11 +37,6 @@#include <linux/rtnetlink.h> #include <net/rtnetlink.h> -struct dummy_priv { -struct net_device *dev; -struct list_head list; -}; -static int numdummies =1 ;static int dummy_xmit (struct sk_buff *skb,struct net_device *dev);
@@ -89,37 +84,9 @@ static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)return 0 ; } -static LIST_HEAD (dummies); - -static int dummy_newlink (struct net_device *dev, -struct nlattr *tb[],struct nlattr *data[]) -{ -struct dummy_priv *priv =netdev_priv (dev); -int err; - - err =register_netdevice (dev); -if (err <0 ) -return err; - - priv->dev = dev; -list_add_tail (&priv->list, &dummies); -return 0 ; -} - -static void dummy_dellink (struct net_device *dev) -{ -struct dummy_priv *priv =netdev_priv (dev); - -list_del (&priv->list); -unregister_netdevice (dev); -} -static struct rtnl_link_ops dummy_link_ops__read_mostly = { .kind ="dummy" , - .priv_size =sizeof (struct dummy_priv ), .setup = dummy_setup, - .newlink = dummy_newlink, - .dellink = dummy_dellink, };/* Number of dummy devices to be set up by this module. */
@@ -129,12 +96,9 @@ MODULE_PARM_DESC(numdummies, "Number of dummy pseudo devices");static int __init dummy_init_one (void ) {struct net_device *dev_dummy; -struct dummy_priv *priv;int err; - dev_dummy =alloc_netdev (sizeof (struct dummy_priv ),"dummy%d" , - dummy_setup); - + dev_dummy =alloc_netdev (0 ,"dummy%d" , dummy_setup);if (!dev_dummy)return -ENOMEM ;
@@ -146,10 +110,6 @@ static int __init dummy_init_one(void) err =register_netdevice (dev_dummy);if (err <0 ) goto err; - - priv =netdev_priv (dev_dummy); - priv->dev = dev_dummy; -list_add_tail (&priv->list, &dummies);return 0 ; err:
@@ -159,7 +119,6 @@ err:static int __init dummy_init_module (void ) { -struct dummy_priv *priv, *next;int i, err =0 ;rtnl_lock ();
@@ -167,11 +126,8 @@ static int __init dummy_init_module(void)for (i =0 ; i < numdummies && !err; i++) err =dummy_init_one (); -if (err <0 ) { -list_for_each_entry_safe (priv, next, &dummies, list) -dummy_dellink (priv->dev); +if (err <0 )__rtnl_link_unregister (&dummy_link_ops); - }rtnl_unlock ();return err;
@@ -179,14 +135,7 @@ static int __init dummy_init_module(void) static void __exit dummy_cleanup_module(void) { -struct dummy_priv *priv, *next; - -rtnl_lock (); -list_for_each_entry_safe (priv, next, &dummies, list) -dummy_dellink (priv->dev); - -__rtnl_link_unregister (&dummy_link_ops); -rtnl_unlock (); +rtnl_link_unregister (&dummy_link_ops); }module_init (dummy_init_module);
drivers/net/ifb.c +6 -52
116 lines not on this page · raw message
net/8021q/vlan.c +0 -21
@@ -115,26 +115,6 @@ err1:return err; } -/* Cleanup all vlan devices -* Note: devices that have been registered that but not -* brought up will exist but have no module ref count. -*/ -static void __exit vlan_cleanup_devices(void) -{ -struct net_device *dev, *nxt; - -rtnl_lock (); -for_each_netdev_safe (dev, nxt) { -if (dev->priv_flags &IFF_802_1Q_VLAN ) { -unregister_vlan_dev (VLAN_DEV_INFO (dev)->real_dev, -VLAN_DEV_INFO (dev)->vlan_id); - -unregister_netdevice (dev); - } - } -rtnl_unlock (); -} -/* * Module 'remove' entry point. * o delete /proc/net/router directory and static entries.
@@ -150,7 +130,6 @@ static void __exit vlan_cleanup_module(void)unregister_netdevice_notifier (&vlan_notifier_block);dev_remove_pack (&vlan_packet_type); -vlan_cleanup_devices ();/* This table must be empty if there are no module * references left.
net/core/rtnetlink.c +14 -4
@@ -270,6 +270,9 @@ static LIST_HEAD(link_ops);*/ int __rtnl_link_register (struct rtnl_link_ops *ops) { +if (!ops->dellink) + ops->dellink = unregister_netdevice; +list_add_tail (&ops->list, &link_ops);return 0 ; }
@@ -298,12 +301,16 @@ EXPORT_SYMBOL_GPL(rtnl_link_register);* __rtnl_link_unregister - Unregister rtnl_link_ops from rtnetlink. * @ops: struct rtnl_link_ops * to unregister * -* The caller must hold the rtnl_mutex. This function should be used -* by drivers that unregister devices during module unloading. It must -* be called after unregistering the devices. +* The caller must hold the rtnl_mutex. */ void __rtnl_link_unregister (struct rtnl_link_ops *ops) { +struct net_device *dev, *n; + +for_each_netdev_safe (dev, n) { +if (dev->rtnl_link_ops == ops) + ops->dellink (dev); + }list_del (&ops->list); }
@@ -1067,7 +1074,10 @@ replay:if (tb[IFLA_LINKMODE ]) dev->link_mode =nla_get_u8 (tb[IFLA_LINKMODE ]); - err = ops->newlink (dev, tb, data); +if (ops->newlink) + err = ops->newlink (dev, tb, data); +else + err =register_netdevice (dev); err_free:if (err <0 )free_netdev (dev);
Re: [RTNETLINK 03/04]: rtnl_link API simplification
From: Patrick McHardy <[email protected]>
Date: Wed, 11 Jul 2007 19:38:17 +0200 (MEST)
Quoted 7 lines
[RTNETLINK]:
rtnl_linkAPI simplificationAll drivers need to unregister their devices in the module unload function. While doing so they must hold the rtnl and atomically unregister the
rtnl_linkops as well. This makes thertnl_link_unregisterfunction that takes the rtnl itself completely useless.
Quoted 5 lines
Provide default newlink/dellink functions, make
__rtnl_link_unregisterandrtnl_link_unregisterunregister all devices with matchingrtnl_link_opsand change the existing users to take advantage of that.Signed-off-by Patrick McHardy <[email protected]>
Applied.
PATCH 4/4 : rtnl_link: allow specifying initial device address
In reply to Patrick McHardy[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.
---
commit 2b73b83f72018cea40557afa0bce0a1b40a717be
tree e1f492495fe9d12bcbc5d623704c2ee476ffb914
parent 88fcde1e75dbfad7e7210642c0364850eed2591e
author Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:28:17 +0200 committer Patrick McHardy <[email protected]> Wed, 11 Jul 2007 19:28:17 +0200
drivers/net/dummy.c | 12 ++++++++++++ drivers/net/ifb.c | 12 ++++++++++++ net/8021q/vlan.c | 8 ++++++-- net/8021q/vlan_netlink.c | 7 +++++++ net/core/rtnetlink.c | 9 +++++++-- 5 files changed, 44 insertions(+), 4 deletions(-)
drivers/net/dummy.c +12 -0
@@ -84,9 +84,21 @@ static int dummy_xmit(struct sk_buff *skb, struct net_device *dev)return 0 ; } +static int dummy_validate (struct nlattr *tb[],struct nlattr *data[]) +{ +if (tb[IFLA_ADDRESS ]) { +if (nla_len (tb[IFLA_ADDRESS ]) !=ETH_ALEN ) +return -EINVAL ; +if (!is_valid_ether_addr (nla_data (tb[IFLA_ADDRESS ]))) +return -EADDRNOTAVAIL ; + } +return 0 ; +} +static struct rtnl_link_ops dummy_link_ops__read_mostly = { .kind ="dummy" , .setup = dummy_setup, + .validate = dummy_validate, };/* Number of dummy devices to be set up by this module. */
drivers/net/ifb.c +12 -0
@@ -221,10 +221,22 @@ static int ifb_open(struct net_device *dev)return 0 ; } +static int ifb_validate (struct nlattr *tb[],struct nlattr *data[]) +{ +if (tb[IFLA_ADDRESS ]) { +if (nla_len (tb[IFLA_ADDRESS ]) !=ETH_ALEN ) +return -EINVAL ; +if (!is_valid_ether_addr (nla_data (tb[IFLA_ADDRESS ]))) +return -EADDRNOTAVAIL ; + } +return 0 ; +} +static struct rtnl_link_ops ifb_link_ops__read_mostly = { .kind ="ifb" , .priv_size =sizeof (struct ifb_private ), .setup = ifb_setup, + .validate = ifb_validate, };/* Number of ifb devices to be set up by this module. */
net/8021q/vlan.c +6 -2
@@ -324,8 +324,10 @@ static int vlan_dev_init(struct net_device *dev) (1<<__LINK_STATE_DORMANT))) | (1 <<__LINK_STATE_PRESENT); -memcpy (dev->broadcast, real_dev->broadcast, real_dev->addr_len); -memcpy (dev->dev_addr, real_dev->dev_addr, real_dev->addr_len); +if (is_zero_ether_addr (dev->dev_addr)) +memcpy (dev->dev_addr, real_dev->dev_addr, dev->addr_len); +if (is_zero_ether_addr (dev->broadcast)) +memcpy (dev->broadcast, real_dev->broadcast, dev->addr_len);if (real_dev->features &NETIF_F_HW_VLAN_TX ) { dev->hard_header = real_dev->hard_header;
@@ -373,6 +375,8 @@ void vlan_setup(struct net_device *new_dev) new_dev->set_multicast_list = vlan_dev_set_multicast_list; new_dev->destructor = free_netdev; new_dev->do_ioctl = vlan_dev_ioctl; + +memset (new_dev->broadcast,0 ,sizeof (ETH_ALEN )); }static void vlan_transfer_operstate (const struct net_device *dev,struct net_device *vlandev)
net/8021q/vlan_netlink.c +7 -0
@@ -41,6 +41,13 @@ static int vlan_validate(struct nlattr *tb[], struct nlattr *data[])u16 id;int err; +if (tb[IFLA_ADDRESS ]) { +if (nla_len (tb[IFLA_ADDRESS ]) !=ETH_ALEN ) +return -EINVAL ; +if (!is_valid_ether_addr (nla_data (tb[IFLA_ADDRESS ]))) +return -EADDRNOTAVAIL ; + } +if (!data)return -EINVAL ;
net/core/rtnetlink.c +7 -2
@@ -1032,8 +1032,7 @@ replay:if (ifm->ifi_index || ifm->ifi_flags || ifm->ifi_change)return -EOPNOTSUPP ; -if (tb[IFLA_ADDRESS ] || tb[IFLA_BROADCAST ] || tb[IFLA_MAP ] || - tb[IFLA_MASTER ] || tb[IFLA_PROTINFO ]) +if (tb[IFLA_MAP ] || tb[IFLA_MASTER ] || tb[IFLA_PROTINFO ])return -EOPNOTSUPP ;if (!ops) {
@@ -1065,6 +1064,12 @@ replay:if (tb[IFLA_MTU ]) dev->mtu =nla_get_u32 (tb[IFLA_MTU ]); +if (tb[IFLA_ADDRESS ]) +memcpy (dev->dev_addr,nla_data (tb[IFLA_ADDRESS ]), +nla_len (tb[IFLA_ADDRESS ])); +if (tb[IFLA_BROADCAST ]) +memcpy (dev->broadcast,nla_data (tb[IFLA_BROADCAST ]), +nla_len (tb[IFLA_BROADCAST ]));if (tb[IFLA_TXQLEN ]) dev->tx_queue_len =nla_get_u32 (tb[IFLA_TXQLEN ]);if (tb[IFLA_WEIGHT ])
Re: [RTNETLINK 04/04]: rtnl_link: allow specifying initial device address
From: Patrick McHardy <[email protected]>
Date: Wed, 11 Jul 2007 19:38:19 +0200 (MEST)
Quoted 6 lines
[RTNETLINK]:
rtnl_link: allow specifying initial device addressDrivers 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 <[email protected]>
Applied.
Thanks Patrick.