netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [Patch net-next] vxlan: do not use vxlan_net before checking event type
@ 2014-01-17  4:20 Cong Wang
  2014-01-17  4:28 ` Fan Du
  0 siblings, 1 reply; 3+ messages in thread
From: Cong Wang @ 2014-01-17  4:20 UTC (permalink / raw)
  To: netdev; +Cc: Daniel Borkmann, David S. Miller, Cong Wang

When cloning a netns, loopback device will be registered
and therefore an event will be notified. Of course
vxlan doesn't care about it, therefore should check if it
is NETDEV_UNREGISTER before getting the vxlan_net struct.
Otherwise, vxlan_net is probably not initialized yet at
this point.

Fixes: commit acaf4e70997ff5ef3588f5a 
Reported-by: Jesse Brandeburg <jesse.brandeburg@intel.com>
Cc: Daniel Borkmann <dborkman@redhat.com>
Cc: David S. Miller <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>

---
diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index a2dee80..2812559 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2655,36 +2655,30 @@ static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
 	.fill_info	= vxlan_fill_info,
 };
 
-static void vxlan_handle_lowerdev_unregister(struct vxlan_net *vn,
-					     struct net_device *dev)
-{
-	struct vxlan_dev *vxlan, *next;
-	LIST_HEAD(list_kill);
-
-	list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next) {
-		struct vxlan_rdst *dst = &vxlan->default_dst;
-
-		/* In case we created vxlan device with carrier
-		 * and we loose the carrier due to module unload
-		 * we also need to remove vxlan device. In other
-		 * cases, it's not necessary and remote_ifindex
-		 * is 0 here, so no matches.
-		 */
-		if (dst->remote_ifindex == dev->ifindex)
-			vxlan_dellink(vxlan->dev, &list_kill);
-	}
-
-	unregister_netdevice_many(&list_kill);
-}
-
 static int vxlan_lowerdev_event(struct notifier_block *unused,
 				unsigned long event, void *ptr)
 {
-	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
-	struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
+	if (event == NETDEV_UNREGISTER) {
+		struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+		struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
+		struct vxlan_dev *vxlan, *next;
+		LIST_HEAD(list_kill);
+
+		list_for_each_entry_safe(vxlan, next, &vn->vxlan_list, next) {
+			struct vxlan_rdst *dst = &vxlan->default_dst;
+
+			/* In case we created vxlan device with carrier
+			 * and we loose the carrier due to module unload
+			 * we also need to remove vxlan device. In other
+			 * cases, it's not necessary and remote_ifindex
+			 * is 0 here, so no matches.
+			 */
+			if (dst->remote_ifindex == dev->ifindex)
+				vxlan_dellink(vxlan->dev, &list_kill);
+		}
 
-	if (event == NETDEV_UNREGISTER)
-		vxlan_handle_lowerdev_unregister(vn, dev);
+		unregister_netdevice_many(&list_kill);
+	}
 
 	return NOTIFY_DONE;
 }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Patch net-next] vxlan: do not use vxlan_net before checking event type
  2014-01-17  4:20 [Patch net-next] vxlan: do not use vxlan_net before checking event type Cong Wang
@ 2014-01-17  4:28 ` Fan Du
  2014-01-17  8:39   ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Fan Du @ 2014-01-17  4:28 UTC (permalink / raw)
  To: Cong Wang; +Cc: netdev, Daniel Borkmann, David S. Miller

Hi, Cong

On 2014年01月17日 12:20, Cong Wang wrote:
> When cloning a netns, loopback device will be registered
> and therefore an event will be notified. Of course
> vxlan doesn't care about it, therefore should check if it
> is NETDEV_UNREGISTER before getting the vxlan_net struct.
> Otherwise, vxlan_net is probably not initialized yet at
> this point.

I'm bit new to vxlan, but in vxlan_init_module

register_pernet_device is called before register_netdevice_notifier.
By my understanding once register_pernet_device is called,
then subsequent vxlan_notifier_block callback see a valid vxlan_net_id.
I mean execute vxlan_notifier_block callback indicates a valid vxlan_net_id,
or I miss somewhere else.


-- 
浮沉随浪只记今朝笑

--fan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Patch net-next] vxlan: do not use vxlan_net before checking event type
  2014-01-17  4:28 ` Fan Du
@ 2014-01-17  8:39   ` Daniel Borkmann
  0 siblings, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2014-01-17  8:39 UTC (permalink / raw)
  To: Fan Du; +Cc: Cong Wang, netdev, David S. Miller

On 01/17/2014 05:28 AM, Fan Du wrote:
> Hi, Cong
>
> On 2014年01月17日 12:20, Cong Wang wrote:
>> When cloning a netns, loopback device will be registered
>> and therefore an event will be notified. Of course
>> vxlan doesn't care about it, therefore should check if it
>> is NETDEV_UNREGISTER before getting the vxlan_net struct.
>> Otherwise, vxlan_net is probably not initialized yet at
>> this point.
>
> I'm bit new to vxlan, but in vxlan_init_module
>
> register_pernet_device is called before register_netdevice_notifier.
> By my understanding once register_pernet_device is called,
> then subsequent vxlan_notifier_block callback see a valid vxlan_net_id.
> I mean execute vxlan_notifier_block callback indicates a valid vxlan_net_id,
> or I miss somewhere else.

That was also my understanding, but apparently I missed that.
Very sorry. Then, it would have been enough to just provide this:

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index a2dee80..d6ec71f 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2681,10 +2681,12 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
  				unsigned long event, void *ptr)
  {
  	struct net_device *dev = netdev_notifier_info_to_dev(ptr);
-	struct vxlan_net *vn = net_generic(dev_net(dev), vxlan_net_id);
+	struct vxlan_net *vn;

-	if (event == NETDEV_UNREGISTER)
+	if (event == NETDEV_UNREGISTER) {
+		vn = net_generic(dev_net(dev), vxlan_net_id);
  		vxlan_handle_lowerdev_unregister(vn, dev);
+	}

  	return NOTIFY_DONE;
  }

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-01-17  8:39 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-17  4:20 [Patch net-next] vxlan: do not use vxlan_net before checking event type Cong Wang
2014-01-17  4:28 ` Fan Du
2014-01-17  8:39   ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).