Skip to contentSkip to conversation

ieee802154: 6lowpan: improve packet registration

PATCH In review Alexander Aring 2 participants 4 messages Oct 13, 2014 – Oct 15, 2014

Subsystems (2)
lore
Share & tools
lore

Alexander Aring

author maintainer
#0 lore raw

PATCH 1/2 ieee802154: 6lowpan: improve packet registration

This patch improves the packet registration handling. Instead of registration with module init we have a open count variable and registration the lowpan packet handler when it's needed.

The open count variable should be protected by RTNL.

---
 net/ieee802154/6lowpan_rtnl.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
net/ieee802154/6lowpan_rtnl.c +18 -12
index c7e07b8..da78fae 100644
@@ -58,6 +58,7 @@
 #include "reassembly.h"
 
 static LIST_HEAD(lowpan_devices);
+static int lowpan_open_count;
 
 /* private device info */
 struct lowpan_dev_info {
@@ -571,11 +572,17 @@ drop:
 	return NET_RX_DROP;
 }
 
+static struct packet_type lowpan_packet_type = {
+	.type = htons(ETH_P_IEEE802154),
+	.func = lowpan_rcv,
+};
+
 static int lowpan_newlink(struct net *src_net, struct net_device *dev,
 			  struct nlattr *tb[], struct nlattr *data[])
 {
 	struct net_device *real_dev;
 	struct lowpan_dev_record *entry;
+	int ret;
 
 	pr_debug("adding new link\n");
 
@@ -610,9 +617,14 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
 	list_add_tail(&entry->list, &lowpan_devices);
 	mutex_unlock(&lowpan_dev_info(dev)->dev_list_mtx);
 
-	register_netdevice(dev);
+	ret = register_netdevice(dev);
+	if (ret >= 0) {
+		if (!lowpan_open_count)
+			dev_add_pack(&lowpan_packet_type);
+		lowpan_open_count++;
+	}
 
-	return 0;
+	return ret;
 }
 
 static void lowpan_dellink(struct net_device *dev, struct list_head *head)
@@ -623,6 +635,10 @@ static void lowpan_dellink(struct net_device *dev, struct list_head *head)
 
 	ASSERT_RTNL();
 
+	lowpan_open_count--;
+	if (!lowpan_open_count)
+		dev_remove_pack(&lowpan_packet_type);
+
 	mutex_lock(&lowpan_dev_info(dev)->dev_list_mtx);
 	list_for_each_entry_safe(entry, tmp, &lowpan_devices, list) {
 		if (entry->ldev == dev) {
@@ -685,11 +701,6 @@ static struct notifier_block lowpan_dev_notifier = {
 	.notifier_call = lowpan_device_event,
 };
 
-static struct packet_type lowpan_packet_type = {
-	.type = htons(ETH_P_IEEE802154),
-	.func = lowpan_rcv,
-};
-
 static int __init lowpan_init_module(void)
 {
 	int err = 0;
@@ -702,8 +713,6 @@ static int __init lowpan_init_module(void)
 	if (err < 0)
 		goto out_frag;
 
-	dev_add_pack(&lowpan_packet_type);
-
 	err = register_netdevice_notifier(&lowpan_dev_notifier);
 	if (err < 0)
 		goto out_pack;
@@ -711,7 +720,6 @@ static int __init lowpan_init_module(void)
 	return 0;
 
 out_pack:
-	dev_remove_pack(&lowpan_packet_type);
 	lowpan_netlink_fini();
 out_frag:
 	lowpan_net_frag_exit();
@@ -723,8 +731,6 @@ static void __exit lowpan_cleanup_module(void)
 {
 	lowpan_netlink_fini();
 
-	dev_remove_pack(&lowpan_packet_type);
-
 	lowpan_net_frag_exit();
 
 	unregister_netdevice_notifier(&lowpan_dev_notifier);
Signature · 1 line
2.1.2
author maintainer
#1 lore raw

PATCH 2/2 ieee802154: 6lowpan: add RTNL assertion

This patch ensure that the rtnl lock is hold while newlink callback.

---
 net/ieee802154/6lowpan_rtnl.c | 2 ++
 1 file changed, 2 insertions(+)
net/ieee802154/6lowpan_rtnl.c +2 -0
index da78fae..0c1a49b 100644
@@ -584,6 +584,8 @@ static int lowpan_newlink(struct net *src_net, struct net_device *dev,
 	struct lowpan_dev_record *entry;
 	int ret;
 
+	ASSERT_RTNL();
+
 	pr_debug("adding new link\n");
 
 	if (!tb[IFLA_LINK])
Signature · 1 line
2.1.2
#2 lore raw

Re: [PATCH bluetooth-next 2/2] ieee802154: 6lowpan: add RTNL assertion

Hi Alex,

Quoted 6 lines

This patch ensure that the rtnl lock is hold while newlink callback.

---
net/ieee802154/6lowpan_rtnl.c | 2 ++

1 file changed, 2 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#3 lore raw
In reply to Alexander Aring

Hi Alex,

Quoted 10 lines

This patch improves the packet registration handling. Instead of registration with module init we have a open count variable and registration the lowpan packet handler when it's needed.

The open count variable should be protected by RTNL.

---
net/ieee802154/6lowpan_rtnl.c | 30 ++++++++++++++++++------------

1 file changed, 18 insertions(+), 12 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel