Re: [PATCH net-next 0/6] Phonet improvements

Previous thread: [PATCH] af_key: initialize xfrm encap_oa by Timo Teras on Friday, January 23, 2009 - 5:30 am. (3 messages)

Next thread: [PATCH 0/21][next] qlge: Clean up and add firmware support. by Ron Mercer on Friday, January 23, 2009 - 8:15 am. (28 messages)
From: Rémi
Date: Friday, January 23, 2009 - 5:59 am

Hello,

There come a few fixes and cleanups of the Phonet stack.
Comments welcome.

Diff stat:
 include/net/phonet/phonet.h |    1
 include/net/phonet/pn_dev.h |    7 +-
 net/Kconfig                 |    2
 net/phonet/af_phonet.c      |   29 +++++-----
 net/phonet/pn_dev.c         |  127 +++++++++++++++++++++++++++++---------------
 net/phonet/pn_netlink.c     |   24 ++++----
 6 files changed, 119 insertions(+), 71 deletions(-)

-- 
Rémi Denis-Courmont
Maemo Software, Nokia Devices R&D

--

From: Rémi Denis-Courmont
Date: Friday, January 23, 2009 - 6:00 am

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/Kconfig |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/net/Kconfig b/net/Kconfig
index bf27760..4640c3b 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -193,6 +193,7 @@ source "net/x25/Kconfig"
 source "net/lapb/Kconfig"
 source "net/econet/Kconfig"
 source "net/wanrouter/Kconfig"
+source "net/phonet/Kconfig"
 source "net/sched/Kconfig"
 source "net/dcb/Kconfig"
 
@@ -237,7 +238,6 @@ source "net/can/Kconfig"
 source "net/irda/Kconfig"
 source "net/bluetooth/Kconfig"
 source "net/rxrpc/Kconfig"
-source "net/phonet/Kconfig"
 
 config FIB_RULES
 	bool
-- 
1.5.6.3

--

From: Rémi Denis-Courmont
Date: Friday, January 23, 2009 - 6:00 am

Incoming packets and sockets are already gone.
The netdevice notifier is unregistered under the RTNL lock
There remains a race with the rtnetlink handlers unregistration, but it
is a generic RTNL issue that was already present before this change.

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/pn_dev.c |    7 +------
 1 files changed, 1 insertions(+), 6 deletions(-)

diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index fd41810..3e24c05 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -204,13 +204,8 @@ void phonet_device_exit(void)
 	struct phonet_device *pnd, *n;
 
 	rtnl_unregister_all(PF_PHONET);
-	rtnl_lock();
-	spin_lock_bh(&pndevs.lock);
+	unregister_netdevice_notifier(&phonet_device_notifier);
 
 	list_for_each_entry_safe(pnd, n, &pndevs.list, list)
 		__phonet_device_free(pnd);
-
-	spin_unlock_bh(&pndevs.lock);
-	rtnl_unlock();
-	unregister_netdevice_notifier(&phonet_device_notifier);
 }
-- 
1.5.6.3

--

From: Rémi Denis-Courmont
Date: Friday, January 23, 2009 - 6:00 am

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 net/phonet/af_phonet.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)

diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index 13cb323..c7c39d9 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -275,8 +275,6 @@ static inline int can_respond(struct sk_buff *skb)
 		return 0;
 
 	ph = pn_hdr(skb);
-	if (phonet_address_get(skb->dev, ph->pn_rdev) != ph->pn_rdev)
-		return 0; /* we are not the destination */
 	if (ph->pn_res == PN_PREFIX && !pskb_may_pull(skb, 5))
 		return 0;
 	if (ph->pn_res == PN_COMMGR) /* indications */
@@ -344,8 +342,8 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
 			struct packet_type *pkttype,
 			struct net_device *orig_dev)
 {
+	struct net *net = dev_net(dev);
 	struct phonethdr *ph;
-	struct sock *sk;
 	struct sockaddr_pn sa;
 	u16 len;
 
@@ -364,21 +362,21 @@ static int phonet_rcv(struct sk_buff *skb, struct net_device *dev,
 	skb_reset_transport_header(skb);
 
 	pn_skb_get_dst_sockaddr(skb, &sa);
-	if (pn_sockaddr_get_addr(&sa) == 0)
-		goto out; /* currently, we cannot be device 0 */
 
-	sk = pn_find_sock_by_sa(dev_net(dev), &sa);
-	if (sk == NULL) {
+	/* check if we are the destination */
+	if (phonet_address_lookup(net, pn_sockaddr_get_addr(&sa)) == 0) {
+		/* Phonet packet input */
+		struct sock *sk = pn_find_sock_by_sa(net, &sa);
+
+		if (sk)
+			return sk_receive_skb(sk, skb, 0);
+
 		if (can_respond(skb)) {
 			send_obj_unreachable(skb);
 			send_reset_indications(skb);
 		}
-		goto out;
 	}
 
-	/* Push data to the socket (or other sockets connected to it). */
-	return sk_receive_skb(sk, skb, 0);
-
 out:
 	kfree_skb(skb);
 	return NET_RX_DROP;
-- 
1.5.6.3

--

From: Rémi Denis-Courmont
Date: Friday, January 23, 2009 - 6:00 am

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/net/phonet/pn_dev.h |    2 +-
 net/phonet/pn_dev.c         |    8 ++++++--
 net/phonet/pn_netlink.c     |   13 +++++++++----
 3 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index 59ae628..4ba2aed 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -38,7 +38,7 @@ struct phonet_device {
 
 int phonet_device_init(void);
 void phonet_device_exit(void);
-void phonet_netlink_register(void);
+int phonet_netlink_register(void);
 struct net_device *phonet_device_get(struct net *net);
 
 int phonet_address_add(struct net_device *dev, u8 addr);
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index af49db0..fd41810 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -190,9 +190,13 @@ static struct notifier_block phonet_device_notifier = {
 /* Initialize Phonet devices list */
 int __init phonet_device_init(void)
 {
+	int err;
+
 	register_netdevice_notifier(&phonet_device_notifier);
-	phonet_netlink_register();
-	return 0;
+	err = phonet_netlink_register();
+	if (err)
+		phonet_device_exit();
+	return err;
 }
 
 void phonet_device_exit(void)
diff --git a/net/phonet/pn_netlink.c b/net/phonet/pn_netlink.c
index 242fe8f..918a4f0 100644
--- a/net/phonet/pn_netlink.c
+++ b/net/phonet/pn_netlink.c
@@ -160,9 +160,14 @@ out:
 	return skb->len;
 }
 
-void __init phonet_netlink_register(void)
+int __init phonet_netlink_register(void)
 {
-	rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL);
-	rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL);
-	rtnl_register(PF_PHONET, RTM_GETADDR, NULL, getaddr_dumpit);
+	int err = __rtnl_register(PF_PHONET, RTM_NEWADDR, addr_doit, NULL);
+	if (err)
+		return err;
+
+	/* Further __rtnl_register() cannot fail */
+	__rtnl_register(PF_PHONET, RTM_DELADDR, addr_doit, NULL);
+	__rtnl_register(PF_PHONET, RTM_GETADDR, NULL, ...
From: Rémi Denis-Courmont
Date: Friday, January 23, 2009 - 6:00 am

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/net/phonet/pn_dev.h |    2 +-
 net/phonet/pn_dev.c         |  108 ++++++++++++++++++++++++++++++-------------
 net/phonet/pn_netlink.c     |   11 ++--
 3 files changed, 81 insertions(+), 40 deletions(-)

diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index 4ba2aed..5054dc5 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -28,7 +28,7 @@ struct phonet_device_list {
 	spinlock_t lock;
 };
 
-extern struct phonet_device_list pndevs;
+struct phonet_device_list *phonet_device_list(struct net *net);
 
 struct phonet_device {
 	struct list_head list;
diff --git a/net/phonet/pn_dev.c b/net/phonet/pn_dev.c
index 3e24c05..80a322d 100644
--- a/net/phonet/pn_dev.c
+++ b/net/phonet/pn_dev.c
@@ -28,32 +28,41 @@
 #include <linux/netdevice.h>
 #include <linux/phonet.h>
 #include <net/sock.h>
+#include <net/netns/generic.h>
 #include <net/phonet/pn_dev.h>
 
-/* when accessing, remember to lock with spin_lock(&pndevs.lock); */
-struct phonet_device_list pndevs = {
-	.list = LIST_HEAD_INIT(pndevs.list),
-	.lock = __SPIN_LOCK_UNLOCKED(pndevs.lock),
+struct phonet_net {
+	struct phonet_device_list pndevs;
 };
 
+int phonet_net_id;
+
+struct phonet_device_list *phonet_device_list(struct net *net)
+{
+	struct phonet_net *pnn = net_generic(net, phonet_net_id);
+	return &pnn->pndevs;
+}
+
 /* Allocate new Phonet device. */
 static struct phonet_device *__phonet_device_alloc(struct net_device *dev)
 {
+	struct phonet_device_list *pndevs = phonet_device_list(dev_net(dev));
 	struct phonet_device *pnd = kmalloc(sizeof(*pnd), GFP_ATOMIC);
 	if (pnd == NULL)
 		return NULL;
 	pnd->netdev = dev;
 	bitmap_zero(pnd->addrs, 64);
 
-	list_add(&pnd->list, &pndevs.list);
+	list_add(&pnd->list, &pndevs->list);
 	return pnd;
 }
 
 static struct phonet_device *__phonet_get(struct net_device *dev)
 {
+	struct phonet_device_list *pndevs = ...
From: Rémi Denis-Courmont
Date: Friday, January 23, 2009 - 6:00 am

Signed-off-by: Rémi Denis-Courmont <remi.denis-courmont@nokia.com>
---
 include/net/phonet/phonet.h |    1 -
 include/net/phonet/pn_dev.h |    3 ++-
 net/phonet/af_phonet.c      |    9 ++++++---
 net/phonet/pn_dev.c         |    4 +++-
 4 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/include/net/phonet/phonet.h b/include/net/phonet/phonet.h
index 057b0a8..d43f71b 100644
--- a/include/net/phonet/phonet.h
+++ b/include/net/phonet/phonet.h
@@ -105,7 +105,6 @@ void phonet_proto_unregister(int protocol, struct phonet_protocol *pp);
 
 int phonet_sysctl_init(void);
 void phonet_sysctl_exit(void);
-void phonet_netlink_register(void);
 int isi_register(void);
 void isi_unregister(void);
 
diff --git a/include/net/phonet/pn_dev.h b/include/net/phonet/pn_dev.h
index aa1c59a..59ae628 100644
--- a/include/net/phonet/pn_dev.h
+++ b/include/net/phonet/pn_dev.h
@@ -36,8 +36,9 @@ struct phonet_device {
 	DECLARE_BITMAP(addrs, 64);
 };
 
-void phonet_device_init(void);
+int phonet_device_init(void);
 void phonet_device_exit(void);
+void phonet_netlink_register(void);
 struct net_device *phonet_device_get(struct net *net);
 
 int phonet_address_add(struct net_device *dev, u8 addr);
diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
index c7c39d9..95bc49d 100644
--- a/net/phonet/af_phonet.c
+++ b/net/phonet/af_phonet.c
@@ -426,16 +426,18 @@ static int __init phonet_init(void)
 {
 	int err;
 
+	err = phonet_device_init();
+	if (err)
+		return err;
+
 	err = sock_register(&phonet_proto_family);
 	if (err) {
 		printk(KERN_ALERT
 			"phonet protocol family initialization failed\n");
-		return err;
+		goto err_sock;
 	}
 
-	phonet_device_init();
 	dev_add_pack(&phonet_packet_type);
-	phonet_netlink_register();
 	phonet_sysctl_init();
 
 	err = isi_register();
@@ -447,6 +449,7 @@ err:
 	phonet_sysctl_exit();
 	sock_unregister(PF_PHONET);
 	dev_remove_pack(&phonet_packet_type);
+err_sock:
 	phonet_device_exit();
 	return err;
 }
diff --git ...
From: David Miller
Date: Monday, January 26, 2009 - 10:04 pm

From: "Rémi Denis-Courmont" <remi.denis-courmont@nokia.com>

All applied, thanks Rémi.
--

Previous thread: [PATCH] af_key: initialize xfrm encap_oa by Timo Teras on Friday, January 23, 2009 - 5:30 am. (3 messages)

Next thread: [PATCH 0/21][next] qlge: Clean up and add firmware support. by Ron Mercer on Friday, January 23, 2009 - 8:15 am. (28 messages)