All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bluetooth-next 1/3] nl802154: move PAD to right position
@ 2016-05-11  9:44 Alexander Aring
  2016-05-11  9:44 ` [PATCH bluetooth-next 2/3] ieee802154: add netns support Alexander Aring
                   ` (3 more replies)
  0 siblings, 4 replies; 13+ messages in thread
From: Alexander Aring @ 2016-05-11  9:44 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring, Nicolas Dichtel

The PAD define should be above the experimental support. We don't care
about if we break userspace in experimental stuff but PAD is part of the
existing UAPI.

Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Alexander Aring <aar@pengutronix.de>
---
 include/net/nl802154.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/net/nl802154.h b/include/net/nl802154.h
index fcab4de..7aad2fd 100644
--- a/include/net/nl802154.h
+++ b/include/net/nl802154.h
@@ -124,6 +124,8 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_ACKREQ_DEFAULT,
 
+	NL802154_ATTR_PAD,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
@@ -138,8 +140,6 @@ enum nl802154_attrs {
 	NL802154_ATTR_SEC_KEY,
 #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
 
-	NL802154_ATTR_PAD,
-
 	__NL802154_ATTR_AFTER_LAST,
 	NL802154_ATTR_MAX = __NL802154_ATTR_AFTER_LAST - 1
 };
-- 
2.8.2


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

* [PATCH bluetooth-next 2/3] ieee802154: add netns support
  2016-05-11  9:44 [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Alexander Aring
@ 2016-05-11  9:44 ` Alexander Aring
  2016-05-11 15:28   ` Stefan Schmidt
  2016-05-11  9:44 ` [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface Alexander Aring
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 13+ messages in thread
From: Alexander Aring @ 2016-05-11  9:44 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring, Nicolas Dichtel

This patch adds netns support for 802.15.4 subsystem. Most parts are
copy&pasted from wireless subsystem, it has the identically userspace
API.

Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Alexander Aring <aar@pengutronix.de>
---
 include/net/cfg802154.h   | 13 +++++++++
 include/net/nl802154.h    |  5 ++++
 net/ieee802154/core.c     | 70 ++++++++++++++++++++++++++++++++++++++++++++++-
 net/ieee802154/core.h     |  2 ++
 net/ieee802154/nl802154.c | 54 ++++++++++++++++++++++++++++++++----
 5 files changed, 138 insertions(+), 6 deletions(-)

diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
index 171cd76..795ca40 100644
--- a/include/net/cfg802154.h
+++ b/include/net/cfg802154.h
@@ -219,9 +219,22 @@ struct wpan_phy {
 
 	struct device dev;
 
+	/* the network namespace this phy lives in currently */
+	possible_net_t _net;
+
 	char priv[0] __aligned(NETDEV_ALIGN);
 };
 
+static inline struct net *wpan_phy_net(struct wpan_phy *wpan_phy)
+{
+	return read_pnet(&wpan_phy->_net);
+}
+
+static inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
+{
+	write_pnet(&wpan_phy->_net, net);
+}
+
 struct ieee802154_addr {
 	u8 mode;
 	__le16 pan_id;
diff --git a/include/net/nl802154.h b/include/net/nl802154.h
index 7aad2fd..ddcee12 100644
--- a/include/net/nl802154.h
+++ b/include/net/nl802154.h
@@ -54,6 +54,8 @@ enum nl802154_commands {
 
 	NL802154_CMD_SET_ACKREQ_DEFAULT,
 
+	NL802154_CMD_SET_WPAN_PHY_NETNS,
+
 	/* add new commands above here */
 
 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
@@ -126,6 +128,9 @@ enum nl802154_attrs {
 
 	NL802154_ATTR_PAD,
 
+	NL802154_ATTR_PID,
+	NL802154_ATTR_NETNS_FD,
+
 	/* add attributes here, update the policy in nl802154.c */
 
 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
index c35fdfa..cb7176c 100644
--- a/net/ieee802154/core.c
+++ b/net/ieee802154/core.c
@@ -140,6 +140,8 @@ wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size)
 	rdev->wpan_phy.dev.class = &wpan_phy_class;
 	rdev->wpan_phy.dev.platform_data = rdev;
 
+	wpan_phy_net_set(&rdev->wpan_phy, &init_net);
+
 	init_waitqueue_head(&rdev->dev_wait);
 
 	return &rdev->wpan_phy;
@@ -207,6 +209,49 @@ void wpan_phy_free(struct wpan_phy *phy)
 }
 EXPORT_SYMBOL(wpan_phy_free);
 
+int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
+			   struct net *net)
+{
+	struct wpan_dev *wpan_dev;
+	int err = 0;
+
+	list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
+		if (!wpan_dev->netdev)
+			continue;
+		wpan_dev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
+		err = dev_change_net_namespace(wpan_dev->netdev, net, "wpan%d");
+		if (err)
+			break;
+		wpan_dev->netdev->features |= NETIF_F_NETNS_LOCAL;
+	}
+
+	if (err) {
+		/* failed -- clean up to old netns */
+		net = wpan_phy_net(&rdev->wpan_phy);
+
+		list_for_each_entry_continue_reverse(wpan_dev,
+						     &rdev->wpan_dev_list,
+						     list) {
+			if (!wpan_dev->netdev)
+				continue;
+			wpan_dev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
+			err = dev_change_net_namespace(wpan_dev->netdev, net,
+						       "wpan%d");
+			WARN_ON(err);
+			wpan_dev->netdev->features |= NETIF_F_NETNS_LOCAL;
+		}
+
+		return err;
+	}
+
+	wpan_phy_net_set(&rdev->wpan_phy, net);
+
+	err = device_rename(&rdev->wpan_phy.dev, dev_name(&rdev->wpan_phy.dev));
+	WARN_ON(err);
+
+	return 0;
+}
+
 void cfg802154_dev_free(struct cfg802154_registered_device *rdev)
 {
 	kfree(rdev);
@@ -286,14 +331,34 @@ static struct notifier_block cfg802154_netdev_notifier = {
 	.notifier_call = cfg802154_netdev_notifier_call,
 };
 
+static void __net_exit cfg802154_pernet_exit(struct net *net)
+{
+	struct cfg802154_registered_device *rdev;
+
+	rtnl_lock();
+	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
+		if (net_eq(wpan_phy_net(&rdev->wpan_phy), net))
+			WARN_ON(cfg802154_switch_netns(rdev, &init_net));
+	}
+	rtnl_unlock();
+}
+
+static struct pernet_operations cfg802154_pernet_ops = {
+	.exit = cfg802154_pernet_exit,
+};
+
 static int __init wpan_phy_class_init(void)
 {
 	int rc;
 
-	rc = wpan_phy_sysfs_init();
+	rc = register_pernet_device(&cfg802154_pernet_ops);
 	if (rc)
 		goto err;
 
+	rc = wpan_phy_sysfs_init();
+	if (rc)
+		goto err_sysfs;
+
 	rc = register_netdevice_notifier(&cfg802154_netdev_notifier);
 	if (rc)
 		goto err_nl;
@@ -315,6 +380,8 @@ err_notifier:
 	unregister_netdevice_notifier(&cfg802154_netdev_notifier);
 err_nl:
 	wpan_phy_sysfs_exit();
+err_sysfs:
+	unregister_pernet_device(&cfg802154_pernet_ops);
 err:
 	return rc;
 }
@@ -326,6 +393,7 @@ static void __exit wpan_phy_class_exit(void)
 	ieee802154_nl_exit();
 	unregister_netdevice_notifier(&cfg802154_netdev_notifier);
 	wpan_phy_sysfs_exit();
+	unregister_pernet_device(&cfg802154_pernet_ops);
 }
 module_exit(wpan_phy_class_exit);
 
diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
index 231fade..81141f5 100644
--- a/net/ieee802154/core.h
+++ b/net/ieee802154/core.h
@@ -38,6 +38,8 @@ wpan_phy_to_rdev(struct wpan_phy *wpan_phy)
 extern struct list_head cfg802154_rdev_list;
 extern int cfg802154_rdev_list_generation;
 
+int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
+			   struct net *net);
 /* free object */
 void cfg802154_dev_free(struct cfg802154_registered_device *rdev);
 struct cfg802154_registered_device *
diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
index ca207db..644c9f0 100644
--- a/net/ieee802154/nl802154.c
+++ b/net/ieee802154/nl802154.c
@@ -80,7 +80,8 @@ __cfg802154_wpan_dev_from_attrs(struct net *netns, struct nlattr **attrs)
 	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
 		struct wpan_dev *wpan_dev;
 
-		/* TODO netns compare */
+		if (wpan_phy_net(&rdev->wpan_phy) != netns)
+			continue;
 
 		if (have_wpan_dev_id && rdev->wpan_phy_idx != wpan_phy_idx)
 			continue;
@@ -175,7 +176,8 @@ __cfg802154_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
 	if (!rdev)
 		return ERR_PTR(-ENODEV);
 
-	/* TODO netns compare */
+	if (netns != wpan_phy_net(&rdev->wpan_phy))
+		return ERR_PTR(-ENODEV);
 
 	return rdev;
 }
@@ -233,6 +235,8 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
 
 	[NL802154_ATTR_ACKREQ_DEFAULT] = { .type = NLA_U8 },
 
+	[NL802154_ATTR_PID] = { .type = NLA_U32 },
+	[NL802154_ATTR_NETNS_FD] = { .type = NLA_U32 },
 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
 	[NL802154_ATTR_SEC_ENABLED] = { .type = NLA_U8, },
 	[NL802154_ATTR_SEC_OUT_LEVEL] = { .type = NLA_U32, },
@@ -590,7 +594,6 @@ static int nl802154_dump_wpan_phy_parse(struct sk_buff *skb,
 		struct cfg802154_registered_device *rdev;
 		int ifidx = nla_get_u32(tb[NL802154_ATTR_IFINDEX]);
 
-		/* TODO netns */
 		netdev = __dev_get_by_index(&init_net, ifidx);
 		if (!netdev)
 			return -ENODEV;
@@ -629,7 +632,8 @@ nl802154_dump_wpan_phy(struct sk_buff *skb, struct netlink_callback *cb)
 	}
 
 	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
-		/* TODO net ns compare */
+		if (!net_eq(wpan_phy_net(&rdev->wpan_phy), sock_net(skb->sk)))
+			continue;
 		if (++idx <= state->start)
 			continue;
 		if (state->filter_wpan_phy != -1 &&
@@ -871,7 +875,8 @@ nl802154_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
 
 	rtnl_lock();
 	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
-		/* TODO netns compare */
+		if (!net_eq(wpan_phy_net(&rdev->wpan_phy), sock_net(skb->sk)))
+			continue;
 		if (wp_idx < wp_start) {
 			wp_idx++;
 			continue;
@@ -1271,6 +1276,37 @@ nl802154_set_ackreq_default(struct sk_buff *skb, struct genl_info *info)
 	return rdev_set_ackreq_default(rdev, wpan_dev, ackreq);
 }
 
+static int nl802154_wpan_phy_netns(struct sk_buff *skb, struct genl_info *info)
+{
+	struct cfg802154_registered_device *rdev = info->user_ptr[0];
+	struct net *net;
+	int err;
+
+	if (info->attrs[NL802154_ATTR_PID]) {
+		u32 pid = nla_get_u32(info->attrs[NL802154_ATTR_PID]);
+
+		net = get_net_ns_by_pid(pid);
+	} else if (info->attrs[NL802154_ATTR_NETNS_FD]) {
+		u32 fd = nla_get_u32(info->attrs[NL802154_ATTR_NETNS_FD]);
+
+		net = get_net_ns_by_fd(fd);
+	} else {
+		return -EINVAL;
+	}
+
+	if (IS_ERR(net))
+		return PTR_ERR(net);
+
+	err = 0;
+
+	/* check if anything to do */
+	if (!net_eq(wpan_phy_net(&rdev->wpan_phy), net))
+		err = cfg802154_switch_netns(rdev, net);
+
+	put_net(net);
+	return err;
+}
+
 #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
 static const struct nla_policy nl802154_dev_addr_policy[NL802154_DEV_ADDR_ATTR_MAX + 1] = {
 	[NL802154_DEV_ADDR_ATTR_PAN_ID] = { .type = NLA_U16 },
@@ -2262,6 +2298,14 @@ static const struct genl_ops nl802154_ops[] = {
 				  NL802154_FLAG_NEED_RTNL,
 	},
 	{
+		.cmd = NL802154_CMD_SET_WPAN_PHY_NETNS,
+		.doit = nl802154_wpan_phy_netns,
+		.policy = nl802154_policy,
+		.flags = GENL_ADMIN_PERM,
+		.internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
+				  NL802154_FLAG_NEED_RTNL,
+	},
+	{
 		.cmd = NL802154_CMD_SET_PAN_ID,
 		.doit = nl802154_set_pan_id,
 		.policy = nl802154_policy,
-- 
2.8.2


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

* [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface
  2016-05-11  9:44 [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Alexander Aring
  2016-05-11  9:44 ` [PATCH bluetooth-next 2/3] ieee802154: add netns support Alexander Aring
@ 2016-05-11  9:44 ` Alexander Aring
  2016-05-11 15:19   ` Stefan Schmidt
  2016-05-11 17:14   ` Michael Richardson
  2016-05-11 14:32 ` [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Nicolas Dichtel
  2016-05-11 15:18 ` Stefan Schmidt
  3 siblings, 2 replies; 13+ messages in thread
From: Alexander Aring @ 2016-05-11  9:44 UTC (permalink / raw)
  To: linux-wpan; +Cc: kernel, Alexander Aring, Nicolas Dichtel

This patch reverts commit f9d1ce8f81eb ("ieee802154: fix netns settings").
The lowpan interface need to be created inside the net namespace where
the wpan interface is available. The wpan namespace can be changed only
by nl802154 before. Without this patch it's not possible to create a
lowpan interface for a wpan interface which isn't inside init_net
namespace.

Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Alexander Aring <aar@pengutronix.de>
---
 net/ieee802154/6lowpan/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c
index dd085db..096e3db 100644
--- a/net/ieee802154/6lowpan/core.c
+++ b/net/ieee802154/6lowpan/core.c
@@ -131,8 +131,7 @@ static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
 
 	pr_debug("adding new link\n");
 
-	if (!tb[IFLA_LINK] ||
-	    !net_eq(dev_net(ldev), &init_net))
+	if (!tb[IFLA_LINK])
 		return -EINVAL;
 	/* find and hold wpan device */
 	wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));
-- 
2.8.2


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

* Re: [PATCH bluetooth-next 1/3] nl802154: move PAD to right position
  2016-05-11  9:44 [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Alexander Aring
  2016-05-11  9:44 ` [PATCH bluetooth-next 2/3] ieee802154: add netns support Alexander Aring
  2016-05-11  9:44 ` [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface Alexander Aring
@ 2016-05-11 14:32 ` Nicolas Dichtel
  2016-05-11 15:18 ` Stefan Schmidt
  3 siblings, 0 replies; 13+ messages in thread
From: Nicolas Dichtel @ 2016-05-11 14:32 UTC (permalink / raw)
  To: Alexander Aring, linux-wpan; +Cc: kernel

Le 11/05/2016 11:44, Alexander Aring a écrit :
> The PAD define should be above the experimental support. We don't care
> about if we break userspace in experimental stuff but PAD is part of the
> existing UAPI.
> 
> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Signed-off-by: Alexander Aring <aar@pengutronix.de>
Acked-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

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

* Re: [PATCH bluetooth-next 1/3] nl802154: move PAD to right position
  2016-05-11  9:44 [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Alexander Aring
                   ` (2 preceding siblings ...)
  2016-05-11 14:32 ` [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Nicolas Dichtel
@ 2016-05-11 15:18 ` Stefan Schmidt
  3 siblings, 0 replies; 13+ messages in thread
From: Stefan Schmidt @ 2016-05-11 15:18 UTC (permalink / raw)
  To: Alexander Aring, linux-wpan; +Cc: kernel, Nicolas Dichtel

Hello.

On 11/05/16 11:44, Alexander Aring wrote:
> The PAD define should be above the experimental support. We don't care
> about if we break userspace in experimental stuff but PAD is part of the
> existing UAPI.
>
> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Signed-off-by: Alexander Aring <aar@pengutronix.de>
> ---
>   include/net/nl802154.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/nl802154.h b/include/net/nl802154.h
> index fcab4de..7aad2fd 100644
> --- a/include/net/nl802154.h
> +++ b/include/net/nl802154.h
> @@ -124,6 +124,8 @@ enum nl802154_attrs {
>   
>   	NL802154_ATTR_ACKREQ_DEFAULT,
>   
> +	NL802154_ATTR_PAD,
> +
>   	/* add attributes here, update the policy in nl802154.c */
>   
>   #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
> @@ -138,8 +140,6 @@ enum nl802154_attrs {
>   	NL802154_ATTR_SEC_KEY,
>   #endif /* CONFIG_IEEE802154_NL802154_EXPERIMENTAL */
>   
> -	NL802154_ATTR_PAD,
> -
>   	__NL802154_ATTR_AFTER_LAST,
>   	NL802154_ATTR_MAX = __NL802154_ATTR_AFTER_LAST - 1
>   };

Reviewed-by: Stefan Schmidt<stefan@osg.samsung.com>

regards
Stefan Schmidt

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

* Re: [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface
  2016-05-11  9:44 ` [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface Alexander Aring
@ 2016-05-11 15:19   ` Stefan Schmidt
  2016-05-11 17:14   ` Michael Richardson
  1 sibling, 0 replies; 13+ messages in thread
From: Stefan Schmidt @ 2016-05-11 15:19 UTC (permalink / raw)
  To: Alexander Aring, linux-wpan; +Cc: kernel, Nicolas Dichtel

Hello.

On 11/05/16 11:44, Alexander Aring wrote:
> This patch reverts commit f9d1ce8f81eb ("ieee802154: fix netns settings").
> The lowpan interface need to be created inside the net namespace where
> the wpan interface is available. The wpan namespace can be changed only
> by nl802154 before. Without this patch it's not possible to create a
> lowpan interface for a wpan interface which isn't inside init_net
> namespace.
>
> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Signed-off-by: Alexander Aring <aar@pengutronix.de>
> ---
>   net/ieee802154/6lowpan/core.c | 3 +--
>   1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/net/ieee802154/6lowpan/core.c b/net/ieee802154/6lowpan/core.c
> index dd085db..096e3db 100644
> --- a/net/ieee802154/6lowpan/core.c
> +++ b/net/ieee802154/6lowpan/core.c
> @@ -131,8 +131,7 @@ static int lowpan_newlink(struct net *src_net, struct net_device *ldev,
>   
>   	pr_debug("adding new link\n");
>   
> -	if (!tb[IFLA_LINK] ||
> -	    !net_eq(dev_net(ldev), &init_net))
> +	if (!tb[IFLA_LINK])
>   		return -EINVAL;
>   	/* find and hold wpan device */
>   	wdev = dev_get_by_index(dev_net(ldev), nla_get_u32(tb[IFLA_LINK]));

Reviewed-by: Stefan Schmidt<stefan@osg.samsung.com>

regards
Stefan Schmidt

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

* Re: [PATCH bluetooth-next 2/3] ieee802154: add netns support
  2016-05-11  9:44 ` [PATCH bluetooth-next 2/3] ieee802154: add netns support Alexander Aring
@ 2016-05-11 15:28   ` Stefan Schmidt
  2016-05-12  0:14     ` Alexander Aring
  0 siblings, 1 reply; 13+ messages in thread
From: Stefan Schmidt @ 2016-05-11 15:28 UTC (permalink / raw)
  To: Alexander Aring, linux-wpan; +Cc: kernel, Nicolas Dichtel

Hello.

On 11/05/16 11:44, Alexander Aring wrote:
> This patch adds netns support for 802.15.4 subsystem. Most parts are
> copy&pasted from wireless subsystem, it has the identically userspace
> API.
>
> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> Signed-off-by: Alexander Aring <aar@pengutronix.de>
> ---
>   include/net/cfg802154.h   | 13 +++++++++
>   include/net/nl802154.h    |  5 ++++
>   net/ieee802154/core.c     | 70 ++++++++++++++++++++++++++++++++++++++++++++++-
>   net/ieee802154/core.h     |  2 ++
>   net/ieee802154/nl802154.c | 54 ++++++++++++++++++++++++++++++++----
>   5 files changed, 138 insertions(+), 6 deletions(-)
>
> diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
> index 171cd76..795ca40 100644
> --- a/include/net/cfg802154.h
> +++ b/include/net/cfg802154.h
> @@ -219,9 +219,22 @@ struct wpan_phy {
>   
>   	struct device dev;
>   
> +	/* the network namespace this phy lives in currently */
> +	possible_net_t _net;
> +
>   	char priv[0] __aligned(NETDEV_ALIGN);
>   };
>   
> +static inline struct net *wpan_phy_net(struct wpan_phy *wpan_phy)

Hmm if you name the setter wpan_phy_net_set() you might ant to name the 
getter wpan_phy_net_get() and not only wpan_phy_ne().

> +{
> +	return read_pnet(&wpan_phy->_net);
> +}
> +
> +static inline void wpan_phy_net_set(struct wpan_phy *wpan_phy, struct net *net)
> +{
> +	write_pnet(&wpan_phy->_net, net);
> +}
> +
>   struct ieee802154_addr {
>   	u8 mode;
>   	__le16 pan_id;
> diff --git a/include/net/nl802154.h b/include/net/nl802154.h
> index 7aad2fd..ddcee12 100644
> --- a/include/net/nl802154.h
> +++ b/include/net/nl802154.h
> @@ -54,6 +54,8 @@ enum nl802154_commands {
>   
>   	NL802154_CMD_SET_ACKREQ_DEFAULT,
>   
> +	NL802154_CMD_SET_WPAN_PHY_NETNS,
> +
>   	/* add new commands above here */
>   
>   #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
> @@ -126,6 +128,9 @@ enum nl802154_attrs {
>   
>   	NL802154_ATTR_PAD,
>   
> +	NL802154_ATTR_PID,
> +	NL802154_ATTR_NETNS_FD,
> +
>   	/* add attributes here, update the policy in nl802154.c */
>   
>   #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
> diff --git a/net/ieee802154/core.c b/net/ieee802154/core.c
> index c35fdfa..cb7176c 100644
> --- a/net/ieee802154/core.c
> +++ b/net/ieee802154/core.c
> @@ -140,6 +140,8 @@ wpan_phy_new(const struct cfg802154_ops *ops, size_t priv_size)
>   	rdev->wpan_phy.dev.class = &wpan_phy_class;
>   	rdev->wpan_phy.dev.platform_data = rdev;
>   
> +	wpan_phy_net_set(&rdev->wpan_phy, &init_net);
> +
>   	init_waitqueue_head(&rdev->dev_wait);
>   
>   	return &rdev->wpan_phy;
> @@ -207,6 +209,49 @@ void wpan_phy_free(struct wpan_phy *phy)
>   }
>   EXPORT_SYMBOL(wpan_phy_free);
>   
> +int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
> +			   struct net *net)
> +{
> +	struct wpan_dev *wpan_dev;
> +	int err = 0;
> +
> +	list_for_each_entry(wpan_dev, &rdev->wpan_dev_list, list) {
> +		if (!wpan_dev->netdev)
> +			continue;
> +		wpan_dev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
> +		err = dev_change_net_namespace(wpan_dev->netdev, net, "wpan%d");
> +		if (err)
> +			break;
> +		wpan_dev->netdev->features |= NETIF_F_NETNS_LOCAL;
> +	}
> +
> +	if (err) {
> +		/* failed -- clean up to old netns */
> +		net = wpan_phy_net(&rdev->wpan_phy);
> +
> +		list_for_each_entry_continue_reverse(wpan_dev,
> +						     &rdev->wpan_dev_list,
> +						     list) {
> +			if (!wpan_dev->netdev)
> +				continue;
> +			wpan_dev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
> +			err = dev_change_net_namespace(wpan_dev->netdev, net,
> +						       "wpan%d");
> +			WARN_ON(err);
> +			wpan_dev->netdev->features |= NETIF_F_NETNS_LOCAL;
> +		}
> +
> +		return err;
> +	}
> +
> +	wpan_phy_net_set(&rdev->wpan_phy, net);
> +
> +	err = device_rename(&rdev->wpan_phy.dev, dev_name(&rdev->wpan_phy.dev));
> +	WARN_ON(err);
> +
> +	return 0;
> +}
> +
>   void cfg802154_dev_free(struct cfg802154_registered_device *rdev)
>   {
>   	kfree(rdev);
> @@ -286,14 +331,34 @@ static struct notifier_block cfg802154_netdev_notifier = {
>   	.notifier_call = cfg802154_netdev_notifier_call,
>   };
>   
> +static void __net_exit cfg802154_pernet_exit(struct net *net)
> +{
> +	struct cfg802154_registered_device *rdev;
> +
> +	rtnl_lock();
> +	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
> +		if (net_eq(wpan_phy_net(&rdev->wpan_phy), net))
> +			WARN_ON(cfg802154_switch_netns(rdev, &init_net));
> +	}
> +	rtnl_unlock();
> +}
> +
> +static struct pernet_operations cfg802154_pernet_ops = {
> +	.exit = cfg802154_pernet_exit,
> +};
> +
>   static int __init wpan_phy_class_init(void)
>   {
>   	int rc;
>   
> -	rc = wpan_phy_sysfs_init();
> +	rc = register_pernet_device(&cfg802154_pernet_ops);
>   	if (rc)
>   		goto err;
>   
> +	rc = wpan_phy_sysfs_init();
> +	if (rc)
> +		goto err_sysfs;
> +
>   	rc = register_netdevice_notifier(&cfg802154_netdev_notifier);
>   	if (rc)
>   		goto err_nl;
> @@ -315,6 +380,8 @@ err_notifier:
>   	unregister_netdevice_notifier(&cfg802154_netdev_notifier);
>   err_nl:
>   	wpan_phy_sysfs_exit();
> +err_sysfs:
> +	unregister_pernet_device(&cfg802154_pernet_ops);
>   err:
>   	return rc;
>   }
> @@ -326,6 +393,7 @@ static void __exit wpan_phy_class_exit(void)
>   	ieee802154_nl_exit();
>   	unregister_netdevice_notifier(&cfg802154_netdev_notifier);
>   	wpan_phy_sysfs_exit();
> +	unregister_pernet_device(&cfg802154_pernet_ops);
>   }
>   module_exit(wpan_phy_class_exit);
>   
> diff --git a/net/ieee802154/core.h b/net/ieee802154/core.h
> index 231fade..81141f5 100644
> --- a/net/ieee802154/core.h
> +++ b/net/ieee802154/core.h
> @@ -38,6 +38,8 @@ wpan_phy_to_rdev(struct wpan_phy *wpan_phy)
>   extern struct list_head cfg802154_rdev_list;
>   extern int cfg802154_rdev_list_generation;
>   
> +int cfg802154_switch_netns(struct cfg802154_registered_device *rdev,
> +			   struct net *net);
>   /* free object */
>   void cfg802154_dev_free(struct cfg802154_registered_device *rdev);
>   struct cfg802154_registered_device *
> diff --git a/net/ieee802154/nl802154.c b/net/ieee802154/nl802154.c
> index ca207db..644c9f0 100644
> --- a/net/ieee802154/nl802154.c
> +++ b/net/ieee802154/nl802154.c
> @@ -80,7 +80,8 @@ __cfg802154_wpan_dev_from_attrs(struct net *netns, struct nlattr **attrs)
>   	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
>   		struct wpan_dev *wpan_dev;
>   
> -		/* TODO netns compare */
> +		if (wpan_phy_net(&rdev->wpan_phy) != netns)
> +			continue;
>   
>   		if (have_wpan_dev_id && rdev->wpan_phy_idx != wpan_phy_idx)
>   			continue;
> @@ -175,7 +176,8 @@ __cfg802154_rdev_from_attrs(struct net *netns, struct nlattr **attrs)
>   	if (!rdev)
>   		return ERR_PTR(-ENODEV);
>   
> -	/* TODO netns compare */
> +	if (netns != wpan_phy_net(&rdev->wpan_phy))
> +		return ERR_PTR(-ENODEV);
>   
>   	return rdev;
>   }
> @@ -233,6 +235,8 @@ static const struct nla_policy nl802154_policy[NL802154_ATTR_MAX+1] = {
>   
>   	[NL802154_ATTR_ACKREQ_DEFAULT] = { .type = NLA_U8 },
>   
> +	[NL802154_ATTR_PID] = { .type = NLA_U32 },
> +	[NL802154_ATTR_NETNS_FD] = { .type = NLA_U32 },
>   #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
>   	[NL802154_ATTR_SEC_ENABLED] = { .type = NLA_U8, },
>   	[NL802154_ATTR_SEC_OUT_LEVEL] = { .type = NLA_U32, },
> @@ -590,7 +594,6 @@ static int nl802154_dump_wpan_phy_parse(struct sk_buff *skb,
>   		struct cfg802154_registered_device *rdev;
>   		int ifidx = nla_get_u32(tb[NL802154_ATTR_IFINDEX]);
>   
> -		/* TODO netns */
>   		netdev = __dev_get_by_index(&init_net, ifidx);
>   		if (!netdev)
>   			return -ENODEV;
> @@ -629,7 +632,8 @@ nl802154_dump_wpan_phy(struct sk_buff *skb, struct netlink_callback *cb)
>   	}
>   
>   	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
> -		/* TODO net ns compare */
> +		if (!net_eq(wpan_phy_net(&rdev->wpan_phy), sock_net(skb->sk)))
> +			continue;
>   		if (++idx <= state->start)
>   			continue;
>   		if (state->filter_wpan_phy != -1 &&
> @@ -871,7 +875,8 @@ nl802154_dump_interface(struct sk_buff *skb, struct netlink_callback *cb)
>   
>   	rtnl_lock();
>   	list_for_each_entry(rdev, &cfg802154_rdev_list, list) {
> -		/* TODO netns compare */
> +		if (!net_eq(wpan_phy_net(&rdev->wpan_phy), sock_net(skb->sk)))
> +			continue;
>   		if (wp_idx < wp_start) {
>   			wp_idx++;
>   			continue;
> @@ -1271,6 +1276,37 @@ nl802154_set_ackreq_default(struct sk_buff *skb, struct genl_info *info)
>   	return rdev_set_ackreq_default(rdev, wpan_dev, ackreq);
>   }
>   
> +static int nl802154_wpan_phy_netns(struct sk_buff *skb, struct genl_info *info)
> +{
> +	struct cfg802154_registered_device *rdev = info->user_ptr[0];
> +	struct net *net;
> +	int err;
> +
> +	if (info->attrs[NL802154_ATTR_PID]) {
> +		u32 pid = nla_get_u32(info->attrs[NL802154_ATTR_PID]);
> +
> +		net = get_net_ns_by_pid(pid);
> +	} else if (info->attrs[NL802154_ATTR_NETNS_FD]) {
> +		u32 fd = nla_get_u32(info->attrs[NL802154_ATTR_NETNS_FD]);
> +
> +		net = get_net_ns_by_fd(fd);
> +	} else {
> +		return -EINVAL;
> +	}
> +
> +	if (IS_ERR(net))
> +		return PTR_ERR(net);
> +
> +	err = 0;
> +
> +	/* check if anything to do */
> +	if (!net_eq(wpan_phy_net(&rdev->wpan_phy), net))
> +		err = cfg802154_switch_netns(rdev, net);
> +
> +	put_net(net);
> +	return err;
> +}
> +
>   #ifdef CONFIG_IEEE802154_NL802154_EXPERIMENTAL
>   static const struct nla_policy nl802154_dev_addr_policy[NL802154_DEV_ADDR_ATTR_MAX + 1] = {
>   	[NL802154_DEV_ADDR_ATTR_PAN_ID] = { .type = NLA_U16 },
> @@ -2262,6 +2298,14 @@ static const struct genl_ops nl802154_ops[] = {
>   				  NL802154_FLAG_NEED_RTNL,
>   	},
>   	{
> +		.cmd = NL802154_CMD_SET_WPAN_PHY_NETNS,
> +		.doit = nl802154_wpan_phy_netns,
> +		.policy = nl802154_policy,
> +		.flags = GENL_ADMIN_PERM,
> +		.internal_flags = NL802154_FLAG_NEED_WPAN_PHY |
> +				  NL802154_FLAG_NEED_RTNL,
> +	},
> +	{
>   		.cmd = NL802154_CMD_SET_PAN_ID,
>   		.doit = nl802154_set_pan_id,
>   		.policy = nl802154_policy,

Reviewed-by: Stefan Schmidt<stefan@osg.samsung.com>

regards
Stefan Schmidt

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

* Re: [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface
  2016-05-11  9:44 ` [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface Alexander Aring
  2016-05-11 15:19   ` Stefan Schmidt
@ 2016-05-11 17:14   ` Michael Richardson
  2016-05-11 23:34     ` Alexander Aring
  1 sibling, 1 reply; 13+ messages in thread
From: Michael Richardson @ 2016-05-11 17:14 UTC (permalink / raw)
  To: Alexander Aring; +Cc: linux-wpan, kernel, Nicolas Dichtel

Alexander Aring <aar@pengutronix.de> wrote:
    > This patch reverts commit f9d1ce8f81eb ("ieee802154: fix netns settings").
    > The lowpan interface need to be created inside the net namespace where
    > the wpan interface is available. The wpan namespace can be changed only
    > by nl802154 before. Without this patch it's not possible to create a
    > lowpan interface for a wpan interface which isn't inside init_net
    > namespace.

I know that we can't support multiple lowpan interfaces on a single wpan
at this time.  If one could, via a macvlan like way, would we want to
put different lowpan interfaces in different netns on top of the same
physical radio.

I'm also ignorant here: can one create macvlan against a physical interface
into a netns?

--
]               Never tell me the odds!                 | ipv6 mesh networks [
]   Michael Richardson, Sandelman Software Works        | network architect  [
]     mcr@sandelman.ca  http://www.sandelman.ca/        |   ruby on rails    [


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

* Re: [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface
  2016-05-11 17:14   ` Michael Richardson
@ 2016-05-11 23:34     ` Alexander Aring
  2016-05-12  7:28       ` Nicolas Dichtel
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Aring @ 2016-05-11 23:34 UTC (permalink / raw)
  To: Michael Richardson; +Cc: linux-wpan, kernel, Nicolas Dichtel


Hi,

On 05/11/2016 07:14 PM, Michael Richardson wrote:
> Alexander Aring <aar@pengutronix.de> wrote:
>     > This patch reverts commit f9d1ce8f81eb ("ieee802154: fix netns settings").
>     > The lowpan interface need to be created inside the net namespace where
>     > the wpan interface is available. The wpan namespace can be changed only
>     > by nl802154 before. Without this patch it's not possible to create a
>     > lowpan interface for a wpan interface which isn't inside init_net
>     > namespace.
> 
> I know that we can't support multiple lowpan interfaces on a single wpan
> at this time.  If one could, via a macvlan like way, would we want to
> put different lowpan interfaces in different netns on top of the same
> physical radio.
> 

mhh, this patch currently sets the whole phy into a namespace and all
related interfaces wpan/lowpan can only exists according the namespace
which the phy belongs to.

Running wpan interface in netns A and running the corresponding lowpan
interface in an another namespace sounds wrong for me, because they should
known each other.

btw: I tried to use "ip link set $WPAN/$LOWPAN netns $NETNS" doesn't work,
it returns -EINVAL.
I think this works only if we set some flags/callbacks, don't know but
was one of my test cases.

If running iwpan $PHY set netns name $NETNS, the wpan interface will
unregister(deleting lowpan) and will be registered again (inside
different namespace).

---

(Creating multiple lowpans for one wpan)

This can be done when creating two wpan interfaces according one phy.
The bad news is, you can't change the mac address stuff and I think this
isn't what you want. The reason is simple, most hardwares has one
address filtering setting only. You could have two wpan interfaces with
different address settings, but then one interface can be in up state only.

To avoid such behaviour, I had in my mind to simple go into promiscuous
mode if two wpan interfaces are up with different address settings, then
let do linux do all filtering stuff. I had to avoid that because the
hardware will not filtering anything anymore and linux need to do more
"work".

Maybe just go into promiscuous when it's necessary and print some
WARNING that the device going into promiscuous mode in such setup.

> I'm also ignorant here: can one create macvlan against a physical interface
> into a netns?
> 

What I googled is, yes that's possible. But they use "ip link set
$INTERFACE netns $NETNS" for that, I think we need to implement such
feature for wpan/lowpan stuff.

But I don't know how it works when the $PHY isn't visible inside the
namespace where the interface should be changed to. But wireless should
have the same behaviour then, that the macvlan/veth/etc. the corresponding
wireless phy isn't visible in the namespace. Seems there exists some
"parent" device inside one namespace and macvlan/veth can be moved to
other namespaces, but I am not an expert into that. :-)

- Alex

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

* Re: [PATCH bluetooth-next 2/3] ieee802154: add netns support
  2016-05-11 15:28   ` Stefan Schmidt
@ 2016-05-12  0:14     ` Alexander Aring
  0 siblings, 0 replies; 13+ messages in thread
From: Alexander Aring @ 2016-05-12  0:14 UTC (permalink / raw)
  To: Stefan Schmidt, linux-wpan; +Cc: kernel, Nicolas Dichtel

Hi,

On 05/11/2016 05:28 PM, Stefan Schmidt wrote:
> Hello.
> 
> On 11/05/16 11:44, Alexander Aring wrote:
>> This patch adds netns support for 802.15.4 subsystem. Most parts are
>> copy&pasted from wireless subsystem, it has the identically userspace
>> API.
>>
>> Cc: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>> Signed-off-by: Alexander Aring <aar@pengutronix.de>
>> ---
>>   include/net/cfg802154.h   | 13 +++++++++
>>   include/net/nl802154.h    |  5 ++++
>>   net/ieee802154/core.c     | 70 ++++++++++++++++++++++++++++++++++++++++++++++-
>>   net/ieee802154/core.h     |  2 ++
>>   net/ieee802154/nl802154.c | 54 ++++++++++++++++++++++++++++++++----
>>   5 files changed, 138 insertions(+), 6 deletions(-)
>>
>> diff --git a/include/net/cfg802154.h b/include/net/cfg802154.h
>> index 171cd76..795ca40 100644
>> --- a/include/net/cfg802154.h
>> +++ b/include/net/cfg802154.h
>> @@ -219,9 +219,22 @@ struct wpan_phy {
>>         struct device dev;
>>   +    /* the network namespace this phy lives in currently */
>> +    possible_net_t _net;
>> +
>>       char priv[0] __aligned(NETDEV_ALIGN);
>>   };
>>   +static inline struct net *wpan_phy_net(struct wpan_phy *wpan_phy)
> 
> Hmm if you name the setter wpan_phy_net_set() you might ant to name the getter wpan_phy_net_get() and not only wpan_phy_ne().
> 

Took the naming from wireless stuff, see [0].

I would highly recommend to make similar naming stuff (but not 1:1 the
same). It's easier for maintenance changes from wireless which we want
to add into 802.15.4, the namespace stuff is an example which I think we
could really do the same.

In this case:

wiphy -> wpan_phy.

- Alex

[0] http://lxr.free-electrons.com/source/include/net/cfg80211.h#L3305

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

* Re: [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface
  2016-05-11 23:34     ` Alexander Aring
@ 2016-05-12  7:28       ` Nicolas Dichtel
  2016-05-13 12:27         ` Alexander Aring
  0 siblings, 1 reply; 13+ messages in thread
From: Nicolas Dichtel @ 2016-05-12  7:28 UTC (permalink / raw)
  To: Alexander Aring, Michael Richardson; +Cc: linux-wpan, kernel

Le 12/05/2016 01:34, Alexander Aring a écrit :
[snip]
> But I don't know how it works when the $PHY isn't visible inside the
> namespace where the interface should be changed to. But wireless should
> have the same behaviour then, that the macvlan/veth/etc. the corresponding
> wireless phy isn't visible in the namespace. Seems there exists some
> "parent" device inside one namespace and macvlan/veth can be moved to
> other namespaces, but I am not an expert into that. :-)
Yes, the virtual interface (macvlan/veth,ip tunnels, vxlan, etc.) is created in
the namespace of the physical netns. After, the virtual interface is moved to
another netns (with 'ip link set foo netns bar'). This is called x-netns: the
upper par of the interface and the link part are not in the same netns.
With 'ip -d link' it's possible to show the link netns. There is an nsid which
identified the link netns. The nsid is valid only in the current netns (ie the
same netns can have another nsid in another netns).
Usually, there are explicit boundary in the code when crossing netns (see
skb_scrub_packet for example).

Example with a gre interface:

# create a gre interface in netns1
ip netns exec netns1 ip link add dev tun1 type gre local 10.0.0.1 \
     remote 10.0.0.2
# move it in netns2: the link netns is still in netns1
ip netns exec netns1 ip link set tun1 netns netns2

or (completely equivalent):

# assign a nsid to netns1 in netns2
ip exec netns2 ip netns set netns1 1234
# create a gre interface in netns2 with its link netns in netns1
ip exec netns2 ip link add tun1 link-netnsid 1234 type gre local 10.0.0.1 \
     remote 10.0.0.2

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

* Re: [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface
  2016-05-12  7:28       ` Nicolas Dichtel
@ 2016-05-13 12:27         ` Alexander Aring
  2016-05-17 21:50           ` Alexander Aring
  0 siblings, 1 reply; 13+ messages in thread
From: Alexander Aring @ 2016-05-13 12:27 UTC (permalink / raw)
  To: nicolas.dichtel, Michael Richardson; +Cc: linux-wpan, kernel


Hi,

On 05/12/2016 09:28 AM, Nicolas Dichtel wrote:
> Le 12/05/2016 01:34, Alexander Aring a écrit :
> [snip]
>> But I don't know how it works when the $PHY isn't visible inside the
>> namespace where the interface should be changed to. But wireless should
>> have the same behaviour then, that the macvlan/veth/etc. the corresponding
>> wireless phy isn't visible in the namespace. Seems there exists some
>> "parent" device inside one namespace and macvlan/veth can be moved to
>> other namespaces, but I am not an expert into that. :-)
> Yes, the virtual interface (macvlan/veth,ip tunnels, vxlan, etc.) is created in
> the namespace of the physical netns. After, the virtual interface is moved to
> another netns (with 'ip link set foo netns bar'). This is called x-netns: the
> upper par of the interface and the link part are not in the same netns.
> With 'ip -d link' it's possible to show the link netns. There is an nsid which
> identified the link netns. The nsid is valid only in the current netns (ie the
> same netns can have another nsid in another netns).
> Usually, there are explicit boundary in the code when crossing netns (see
> skb_scrub_packet for example).
> 
> Example with a gre interface:
> 
> # create a gre interface in netns1
> ip netns exec netns1 ip link add dev tun1 type gre local 10.0.0.1 \
>      remote 10.0.0.2
> # move it in netns2: the link netns is still in netns1
> ip netns exec netns1 ip link set tun1 netns netns2
> 
> or (completely equivalent):
> 
> # assign a nsid to netns1 in netns2
> ip exec netns2 ip netns set netns1 1234
> # create a gre interface in netns2 with its link netns in netns1
> ip exec netns2 ip link add tun1 link-netnsid 1234 type gre local 10.0.0.1 \
>      remote 10.0.0.2

Thanks for the explanation.

The current patch series put the whole phy and all the interfaces into
one net namespace (like in wireless). The lowpan interface can also be
created in non init_net then.

So far I know it's not possible to move wpan or lowpan interfaces after
creation e.g. running "ip link set #IF netns $NETNS_NAME" and we need to
support such behaviour in future.

The current use-case is just for the fakelb driver (like hwsim in
wireless) which doesn't do any optimization in IPv6 stack if two
interfaces belongs to the same net namespace.

- Alex

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

* Re: [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface
  2016-05-13 12:27         ` Alexander Aring
@ 2016-05-17 21:50           ` Alexander Aring
  0 siblings, 0 replies; 13+ messages in thread
From: Alexander Aring @ 2016-05-17 21:50 UTC (permalink / raw)
  To: nicolas.dichtel, Michael Richardson; +Cc: linux-wpan, kernel


Hi,

On 05/13/2016 02:27 PM, Alexander Aring wrote:
> 
> Hi,
> 
> On 05/12/2016 09:28 AM, Nicolas Dichtel wrote:
>> Le 12/05/2016 01:34, Alexander Aring a écrit :
>> [snip]
>>> But I don't know how it works when the $PHY isn't visible inside the
>>> namespace where the interface should be changed to. But wireless should
>>> have the same behaviour then, that the macvlan/veth/etc. the corresponding
>>> wireless phy isn't visible in the namespace. Seems there exists some
>>> "parent" device inside one namespace and macvlan/veth can be moved to
>>> other namespaces, but I am not an expert into that. :-)
>> Yes, the virtual interface (macvlan/veth,ip tunnels, vxlan, etc.) is created in
>> the namespace of the physical netns. After, the virtual interface is moved to
>> another netns (with 'ip link set foo netns bar'). This is called x-netns: the
>> upper par of the interface and the link part are not in the same netns.
>> With 'ip -d link' it's possible to show the link netns. There is an nsid which
>> identified the link netns. The nsid is valid only in the current netns (ie the
>> same netns can have another nsid in another netns).
>> Usually, there are explicit boundary in the code when crossing netns (see
>> skb_scrub_packet for example).
>>
>> Example with a gre interface:
>>
>> # create a gre interface in netns1
>> ip netns exec netns1 ip link add dev tun1 type gre local 10.0.0.1 \
>>      remote 10.0.0.2
>> # move it in netns2: the link netns is still in netns1
>> ip netns exec netns1 ip link set tun1 netns netns2
>>
>> or (completely equivalent):
>>
>> # assign a nsid to netns1 in netns2
>> ip exec netns2 ip netns set netns1 1234
>> # create a gre interface in netns2 with its link netns in netns1
>> ip exec netns2 ip link add tun1 link-netnsid 1234 type gre local 10.0.0.1 \
>>      remote 10.0.0.2
> 
> Thanks for the explanation.
> 
> The current patch series put the whole phy and all the interfaces into
> one net namespace (like in wireless). The lowpan interface can also be
> created in non init_net then.
>

I detected today that on non init_net lowpan interfaces will not work with
our current "pending for real UAPI" solution which is "debugfs".

So this is broken right now, but I don't really care about that for
setting which will be part of some UAPI netlink/sysfs/etc. later, which
will be netns aware.

The files in debugfs entries will be not be available, maybe there
exists also solutions to do this namespace aware.

If somebody wants to test stateful compression with e.g. fakelb, etc.
init_net is the one namespace which will work only.

- Alex

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

end of thread, other threads:[~2016-05-17 21:50 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-11  9:44 [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Alexander Aring
2016-05-11  9:44 ` [PATCH bluetooth-next 2/3] ieee802154: add netns support Alexander Aring
2016-05-11 15:28   ` Stefan Schmidt
2016-05-12  0:14     ` Alexander Aring
2016-05-11  9:44 ` [PATCH bluetooth-next 3/3] ieee802154: allow netns create of lowpan interface Alexander Aring
2016-05-11 15:19   ` Stefan Schmidt
2016-05-11 17:14   ` Michael Richardson
2016-05-11 23:34     ` Alexander Aring
2016-05-12  7:28       ` Nicolas Dichtel
2016-05-13 12:27         ` Alexander Aring
2016-05-17 21:50           ` Alexander Aring
2016-05-11 14:32 ` [PATCH bluetooth-next 1/3] nl802154: move PAD to right position Nicolas Dichtel
2016-05-11 15:18 ` Stefan Schmidt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.