Enables us to use batman-adv inside of network namespaces. Unfortunately it does not enable us to use multiple batX interfaces in different namespaces. This limitation results from using debugfs and its unawareness of namespaces.
Signed-off-by: Daniel Ehlers danielehlers@mindeye.net --- hard-interface.c | 10 ++++++---- hard-interface.h | 2 +- soft-interface.c | 8 ++++++-- soft-interface.h | 2 +- sysfs.c | 4 +++- translation-table.c | 4 +++- 6 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/hard-interface.c b/hard-interface.c index b851cc5..c3497de 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -31,6 +31,7 @@ #include <linux/if_arp.h> #include <linux/if_ether.h> +#include <net/net_namespace.h> void batadv_hardif_free_rcu(struct rcu_head *rcu) { @@ -76,6 +77,7 @@ out: static bool batadv_is_on_batman_iface(const struct net_device *net_dev) { struct net_device *parent_dev; + struct net *net = dev_net(net_dev); bool ret; /* check if this is a batman-adv mesh interface */ @@ -87,7 +89,7 @@ static bool batadv_is_on_batman_iface(const struct net_device *net_dev) return false; /* recurse over the parent device */ - parent_dev = __dev_get_by_index(&init_net, net_dev->iflink); + parent_dev = __dev_get_by_index(net, net_dev->iflink); /* if we got a NULL parent_dev there is something broken.. */ if (WARN(!parent_dev, "Cannot find parent device")) return false; @@ -365,7 +367,7 @@ static int batadv_master_del_slave(struct batadv_hard_iface *slave, } int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, - const char *iface_name) + struct net *net, const char *iface_name) { struct batadv_priv *bat_priv; struct net_device *soft_iface, *master; @@ -379,10 +381,10 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, if (!atomic_inc_not_zero(&hard_iface->refcount)) goto out; - soft_iface = dev_get_by_name(&init_net, iface_name); + soft_iface = dev_get_by_name(net, iface_name); if (!soft_iface) { - soft_iface = batadv_softif_create(iface_name); + soft_iface = batadv_softif_create(net, iface_name); if (!soft_iface) { ret = -ENOMEM; diff --git a/hard-interface.h b/hard-interface.h index 1918cd5..00ba971 100644 --- a/hard-interface.h +++ b/hard-interface.h @@ -44,7 +44,7 @@ bool batadv_is_wifi_iface(int ifindex); struct batadv_hard_iface* batadv_hardif_get_by_netdev(const struct net_device *net_dev); int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, - const char *iface_name); + struct net *net, const char *iface_name); void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface, enum batadv_hard_if_cleanup autodel); void batadv_hardif_remove_interfaces(void); diff --git a/soft-interface.c b/soft-interface.c index dcaf02b..79c7243 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -35,6 +35,7 @@ #include "multicast.h" #include "bridge_loop_avoidance.h" #include "network-coding.h" +#include <net/net_namespace.h> static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd); @@ -822,13 +823,14 @@ static int batadv_softif_slave_add(struct net_device *dev, struct net_device *slave_dev) { struct batadv_hard_iface *hard_iface; + struct net *net = dev_net(dev); int ret = -EINVAL; hard_iface = batadv_hardif_get_by_netdev(slave_dev); if (!hard_iface || hard_iface->soft_iface != NULL) goto out; - ret = batadv_hardif_enable_interface(hard_iface, dev->name); + ret = batadv_hardif_enable_interface(hard_iface, net, dev->name); out: if (hard_iface) @@ -927,7 +929,7 @@ static void batadv_softif_init_early(struct net_device *dev) memset(priv, 0, sizeof(*priv)); } -struct net_device *batadv_softif_create(const char *name) +struct net_device *batadv_softif_create(struct net *net, const char *name) { struct net_device *soft_iface; int ret; @@ -937,6 +939,8 @@ struct net_device *batadv_softif_create(const char *name) if (!soft_iface) return NULL; + dev_net_set(soft_iface, net); + soft_iface->rtnl_link_ops = &batadv_link_ops; ret = register_netdevice(soft_iface); diff --git a/soft-interface.h b/soft-interface.h index dbab22f..c213c80 100644 --- a/soft-interface.h +++ b/soft-interface.h @@ -22,7 +22,7 @@ int batadv_skb_head_push(struct sk_buff *skb, unsigned int len); void batadv_interface_rx(struct net_device *soft_iface, struct sk_buff *skb, struct batadv_hard_iface *recv_if, int hdr_size, struct batadv_orig_node *orig_node); -struct net_device *batadv_softif_create(const char *name); +struct net_device *batadv_softif_create(struct net *net, const char *name); void batadv_softif_destroy_sysfs(struct net_device *soft_iface); int batadv_softif_is_valid(const struct net_device *net_dev); extern struct rtnl_link_ops batadv_link_ops; diff --git a/sysfs.c b/sysfs.c index fc47baa..cbd5534 100644 --- a/sysfs.c +++ b/sysfs.c @@ -25,6 +25,7 @@ #include "soft-interface.h" #include "gateway_common.h" #include "gateway_client.h" +#include <net/net_namespace.h> static struct net_device *batadv_kobj_to_netdev(struct kobject *obj) { @@ -754,6 +755,7 @@ static ssize_t batadv_store_mesh_iface(struct kobject *kobj, size_t count) { struct net_device *net_dev = batadv_kobj_to_netdev(kobj); + struct net *net = dev_net(net_dev); struct batadv_hard_iface *hard_iface; int status_tmp = -1; int ret = count; @@ -797,7 +799,7 @@ static ssize_t batadv_store_mesh_iface(struct kobject *kobj, batadv_hardif_disable_interface(hard_iface, BATADV_IF_CLEANUP_AUTO); - ret = batadv_hardif_enable_interface(hard_iface, buff); + ret = batadv_hardif_enable_interface(hard_iface, net, buff); unlock: rtnl_unlock(); diff --git a/translation-table.c b/translation-table.c index 5f59e7f..08d7e7d 100644 --- a/translation-table.c +++ b/translation-table.c @@ -27,6 +27,7 @@ #include "multicast.h" #include <linux/crc32c.h> +#include <net/net_namespace.h> /* hash class keys */ static struct lock_class_key batadv_tt_local_hash_lock_class_key; @@ -513,6 +514,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, struct batadv_tt_global_entry *tt_global = NULL; struct batadv_softif_vlan *vlan; struct net_device *in_dev = NULL; + struct net *net = dev_net(soft_iface); struct hlist_head *head; struct batadv_tt_orig_list_entry *orig_entry; int hash_added, table_size, packet_size_max; @@ -521,7 +523,7 @@ bool batadv_tt_local_add(struct net_device *soft_iface, const uint8_t *addr, uint32_t match_mark; if (ifindex != BATADV_NULL_IFINDEX) - in_dev = dev_get_by_index(&init_net, ifindex); + in_dev = dev_get_by_index(net, ifindex); tt_local = batadv_tt_local_hash_find(bat_priv, addr, vid); -- 1.9.2
On Monday 26 May 2014 12:18:38 Daniel Ehlers wrote:
Enables us to use batman-adv inside of network namespaces. Unfortunately it does not enable us to use multiple batX interfaces in different namespaces. This limitation results from using debugfs and its unawareness of namespaces.
Signed-off-by: Daniel Ehlers danielehlers@mindeye.net
hard-interface.c | 10 ++++++---- hard-interface.h | 2 +- soft-interface.c | 8 ++++++-- soft-interface.h | 2 +- sysfs.c | 4 +++- translation-table.c | 4 +++- 6 files changed, 20 insertions(+), 10 deletions(-)
Would you mind re-sending both patches while cc'ing the netdev list and specifically asking for reviews from the namespace people ? None of us has any experience with netns. As such a meaningful review is difficult for us.
Furthermore, your commit message should be more explicit about what the patch is trying to fix / improve. Things like 'issue #179' are too vague to be understandable by everyone.
Thanks, Marek
On 12/06/14 11:48, Marek Lindner wrote:
On Monday 26 May 2014 12:18:38 Daniel Ehlers wrote:
Enables us to use batman-adv inside of network namespaces. Unfortunately it does not enable us to use multiple batX interfaces in different namespaces. This limitation results from using debugfs and its unawareness of namespaces.
Signed-off-by: Daniel Ehlers danielehlers@mindeye.net
hard-interface.c | 10 ++++++---- hard-interface.h | 2 +- soft-interface.c | 8 ++++++-- soft-interface.h | 2 +- sysfs.c | 4 +++- translation-table.c | 4 +++- 6 files changed, 20 insertions(+), 10 deletions(-)
Would you mind re-sending both patches while cc'ing the netdev list and specifically asking for reviews from the namespace people ? None of us has any experience with netns. As such a meaningful review is difficult for us.
Furthermore, your commit message should be more explicit about what the patch is trying to fix / improve. Things like 'issue #179' are too vague to be understandable by everyone.
Please specify "RFC" instead of "PATCH" in the subject when sending it to netdev, this way nobody thinks that it was sent for a direct inclusion (net-next is closed now, so somebody might not be happy).
Cheers,
On Mon, May 26, 2014 at 12:18:38PM +0200, Daniel Ehlers wrote:
Enables us to use batman-adv inside of network namespaces. Unfortunately it does not enable us to use multiple batX interfaces in different namespaces. This limitation results from using debugfs and its unawareness of namespaces.
Signed-off-by: Daniel Ehlers danielehlers@mindeye.net
The two patches are indeed doing what they are saying.
PATCH 1/2 fixes the issue I had in #179, no more kernel panics with that one - by disallowing the scenario I was using. But not allowing to have the slave interfaces in one and the master interface (batX) in the other seems like a sane solution and the way to go. The bridge does the same, compare:
"netns bridge: allow bridges in netns!" (4aa678ba44aa35759c04f300afbc97d3dab5faa2)
Maybe reference that one in the commit message, too?
If you'd change the commit message like Marek suggested as well (e.g. don't name the ticket number within the commit message - the netdev folks don't know it; specifically name the kernel panic this prevents) and make it appliable (see later), I'd give it a Tested-by + Acked-by.
PATCH 2/2 correctly initializes the batX interface in the same namespace in my tests. And again, straight forward when comparing it to the bridge-patch referenced above. PATCH 1/2 + PATCH 2/2 are logically the same as the bridge patch.
But there's one more issue I'm having with PATCH 2/2, I'm getting the following warning when doing an "init 0" in the LXC host:
--- [ 248.679142] batman_adv: bat1: Removing interface: eth1 [ 248.685206] ------------[ cut here ]------------ [ 248.688746] WARNING: CPU: 0 PID: 2694 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x5c/0x68() [ 248.692551] sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:03.0/net/eth1/batman_adv' ... ---
Going to add the full calltrace to #179.
So it looks like next to PATCH 1/2 and PATCH 2/2 (and potentially a third patch $later for the debugfs limitation you named) another patch for the sysfs seems to be necessary to get netns support working correctly.
-----
Also, your MTA seems to break your patches. I can't apply them (for instance see PATCH 2/2, there's a whitespace added before the final '-- 1.9.2', PATCH 1/2 has an extra newline at the end). The patches you sent me privately as attachments apply fine though.
If I recall correctly, you were using "git imap-send". Maybe try using "git send-email" instead.
Cheers, Linus
On Tue, Jul 15, 2014 at 12:28:13AM +0200, Linus Lüssing wrote:
But there's one more issue I'm having with PATCH 2/2, I'm getting the following warning when doing an "init 0" in the LXC host:
[ 248.679142] batman_adv: bat1: Removing interface: eth1 [ 248.685206] ------------[ cut here ]------------ [ 248.688746] WARNING: CPU: 0 PID: 2694 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x5c/0x68() [ 248.692551] sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:03.0/net/eth1/batman_adv' ...
Going to add the full calltrace to #179.
Or going to add it here, right away since #179 doesn't reference PATCH 2/2 yet anyways.
After that LXC shutdown and calltrace, the batman_adv sysfs folder is missing for eth1 on the upper host.
Not sure why batman-adv tries to re-register eth1 on the upper host before having unregistered it from within the LXC host. Maybe a race condition caused by the hard-if-registering event being done immediately while the unregistering gets scheduled in a worker queue?
Cheers, Linus
---
[ 248.679142] batman_adv: bat1: Removing interface: eth1 [ 248.685206] ------------[ cut here ]------------ [ 248.688746] WARNING: CPU: 0 PID: 2694 at fs/sysfs/dir.c:31 sysfs_warn_dup+0x5c/0x68() [ 248.692551] sysfs: cannot create duplicate filename '/devices/pci0000:00/0000:00:03.0/net/eth1/batman_adv' [ 248.697806] Modules linked in: batman_adv(O) bridge stp llc crc32c_generic libcrc32c crc16 dm_crypt md_mod ppdev kvm_amd kvm snd_pcm snd_timer snd soundcore psmouse evdev serio_raw pcspkr 8139too parport_pc parport i2c_piix4 i2c_core 8139cp processor mii thermal_sys button ata_generic 9p fscache ata_piix virtio_pci libata scsi_mod floppy dm_mirror dm_region_hash dm_log dm_mod 9pnet_virtio virtio_ring virtio 9pnet [ 248.704734] CPU: 0 PID: 2694 Comm: lxc-start Tainted: G O 3.16.0-rc2+ #1 [ 248.705824] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007 [ 248.706606] 0000000000000000 0000000000000009 ffffffff81399ffb ffff88000b53f598 [ 248.707653] ffffffff8103c183 ffffffff81682700 ffffffff81168f78 ffffffff81682700 [ 248.708707] ffff88000e3e7000 ffff88000d1d6a60 ffff880000057b88 ffff88000e325068 [ 248.709761] Call Trace: [ 248.710104] [<ffffffff81399ffb>] ? dump_stack+0x41/0x51 [ 248.710907] [<ffffffff8103c183>] ? warn_slowpath_common+0x78/0x90 [ 248.711827] [<ffffffff81168f78>] ? sysfs_warn_dup+0x5c/0x68 [ 248.712633] [<ffffffff8103c233>] ? warn_slowpath_fmt+0x45/0x4a [ 248.713331] [<ffffffff811667c3>] ? kernfs_path+0x46/0x52 [ 248.714065] [<ffffffff81168f78>] ? sysfs_warn_dup+0x5c/0x68 [ 248.714842] [<ffffffff81168fdf>] ? sysfs_create_dir_ns+0x5b/0x72 [ 248.715705] [<ffffffff811d5412>] ? kobject_add_internal+0xd2/0x269 [ 248.716571] [<ffffffff811d5769>] ? kobject_add+0x8e/0xa2 [ 248.717189] [<ffffffff811d57b1>] ? kobject_create_and_add+0x34/0x63 [ 248.718034] [<ffffffffa024d633>] ? batadv_sysfs_add_hardif+0x24/0xb4 [batman_adv] [ 248.719048] [<ffffffffa024713a>] ? batadv_hard_if_event+0x112/0x2f6 [batman_adv] [ 248.720142] [<ffffffff81057efd>] ? notifier_call_chain+0x2e/0x59 [ 248.720974] [<ffffffff812ddedd>] ? call_netdevice_notifiers+0xe/0x13 [ 248.721833] [<ffffffff812e281e>] ? dev_change_net_namespace+0x1c4/0x1f8 [ 248.722778] [<ffffffff812ece71>] ? do_setlink+0x8d/0x794 [ 248.723587] [<ffffffffa00037ae>] ? p9pdu_writef+0x39/0x3e [9pnet] [ 248.724468] [<ffffffff812efb79>] ? rtnl_newlink+0x378/0x5c7 [ 248.725240] [<ffffffff812ef909>] ? rtnl_newlink+0x108/0x5c7 [ 248.726060] [<ffffffff810e37a3>] ? zone_statistics+0x41/0x74 [ 248.726910] [<ffffffff810d3ec8>] ? get_page_from_freelist+0x620/0x722 [ 248.727796] [<ffffffff812ef7ee>] ? rtnetlink_rcv_msg+0x17e/0x191 [ 248.728635] [<ffffffff812ef670>] ? __rtnl_unlock+0xc/0xc [ 248.729417] [<ffffffff81305970>] ? netlink_rcv_skb+0x36/0x7c [ 248.730199] [<ffffffff812eca1f>] ? rtnetlink_rcv+0x1f/0x28 [ 248.730960] [<ffffffff8130541e>] ? netlink_unicast+0xff/0x17f [ 248.731872] [<ffffffff8130579d>] ? netlink_sendmsg+0x2ff/0x32d [ 248.732805] [<ffffffff812cf42d>] ? sock_sendmsg+0x49/0x64 [ 248.733585] [<ffffffff8111ffba>] ? do_last+0x923/0xa0f [ 248.734285] [<ffffffff81124848>] ? dput+0x19/0x150 [ 248.734943] [<ffffffff812cfdcd>] ? move_addr_to_kernel+0x2e/0x53 [ 248.735772] [<ffffffff812d91be>] ? verify_iovec+0x4c/0x9a [ 248.736530] [<ffffffff812cfd15>] ? ___sys_sendmsg+0x1e7/0x271 [ 248.737329] [<ffffffff81304892>] ? netlink_autobind.isra.23+0xc6/0xe7 [ 248.738197] [<ffffffff81304c79>] ? netlink_bind+0xed/0x199 [ 248.738945] [<ffffffff812ce716>] ? move_addr_to_user+0x5f/0x90 [ 248.739753] [<ffffffff812ce853>] ? SYSC_getsockname+0x7b/0x8c [ 248.740539] [<ffffffff812d00a1>] ? __sys_sendmsg+0x39/0x57 [ 248.741312] [<ffffffff8139e4d2>] ? system_call_fastpath+0x16/0x1b [ 248.742146] ---[ end trace 3d613ca14aa39b99 ]--- [ 248.742814] ------------[ cut here ]------------ [ 248.743450] WARNING: CPU: 0 PID: 2694 at lib/kobject.c:240 kobject_add_internal+0x1e1/0x269() [ 248.744598] kobject_add_internal failed for batman_adv with -EEXIST, don't try to register things with the same name in the same directory. [ 248.746324] Modules linked in: batman_adv(O) bridge stp llc crc32c_generic libcrc32c crc16 dm_crypt md_mod ppdev kvm_amd kvm snd_pcm snd_timer snd soundcore psmouse evdev serio_raw pcspkr 8139too parport_pc parport i2c_piix4 i2c_core 8139cp processor mii thermal_sys button ata_generic 9p fscache ata_piix virtio_pci libata scsi_mod floppy dm_mirror dm_region_hash dm_log dm_mod 9pnet_virtio virtio_ring virtio 9pnet [ 248.751820] CPU: 0 PID: 2694 Comm: lxc-start Tainted: G W O 3.16.0-rc2+ #1 [ 248.752858] Hardware name: Bochs Bochs, BIOS Bochs 01/01/2007 [ 248.753636] 0000000000000000 0000000000000009 ffffffff81399ffb ffff88000b53f5d8 [ 248.754664] ffffffff8103c183 ffff88000e3e7000 ffffffff811d5521 ffff88000b53f5f8 [ 248.755707] ffff88000b43bdc0 00000000ffffffef ffff88000d042498 ffff88000e325068 [ 248.756769] Call Trace: [ 248.757107] [<ffffffff81399ffb>] ? dump_stack+0x41/0x51 [ 248.757844] [<ffffffff8103c183>] ? warn_slowpath_common+0x78/0x90 [ 248.758680] [<ffffffff811d5521>] ? kobject_add_internal+0x1e1/0x269 [ 248.759553] [<ffffffff8103c233>] ? warn_slowpath_fmt+0x45/0x4a [ 248.760372] [<ffffffff811d5521>] ? kobject_add_internal+0x1e1/0x269 [ 248.761290] [<ffffffff811d5769>] ? kobject_add+0x8e/0xa2 [ 248.762035] [<ffffffff811d57b1>] ? kobject_create_and_add+0x34/0x63 [ 248.762918] [<ffffffffa024d633>] ? batadv_sysfs_add_hardif+0x24/0xb4 [batman_adv] [ 248.763979] [<ffffffffa024713a>] ? batadv_hard_if_event+0x112/0x2f6 [batman_adv] [ 248.765012] [<ffffffff81057efd>] ? notifier_call_chain+0x2e/0x59 [ 248.765846] [<ffffffff812ddedd>] ? call_netdevice_notifiers+0xe/0x13 [ 248.766746] [<ffffffff812e281e>] ? dev_change_net_namespace+0x1c4/0x1f8 [ 248.767710] [<ffffffff812ece71>] ? do_setlink+0x8d/0x794 [ 248.768462] [<ffffffffa00037ae>] ? p9pdu_writef+0x39/0x3e [9pnet] [ 248.769355] [<ffffffff812efb79>] ? rtnl_newlink+0x378/0x5c7 [ 248.770236] [<ffffffff812ef909>] ? rtnl_newlink+0x108/0x5c7 [ 248.770885] [<ffffffff810e37a3>] ? zone_statistics+0x41/0x74 [ 248.771609] [<ffffffff810d3ec8>] ? get_page_from_freelist+0x620/0x722 [ 248.772569] [<ffffffff812ef7ee>] ? rtnetlink_rcv_msg+0x17e/0x191 [ 248.773455] [<ffffffff812ef670>] ? __rtnl_unlock+0xc/0xc [ 248.774187] [<ffffffff81305970>] ? netlink_rcv_skb+0x36/0x7c [ 248.774960] [<ffffffff812eca1f>] ? rtnetlink_rcv+0x1f/0x28 [ 248.775677] [<ffffffff8130541e>] ? netlink_unicast+0xff/0x17f [ 248.776491] [<ffffffff8130579d>] ? netlink_sendmsg+0x2ff/0x32d [ 248.777292] [<ffffffff812cf42d>] ? sock_sendmsg+0x49/0x64 [ 248.778056] [<ffffffff8111ffba>] ? do_last+0x923/0xa0f [ 248.778777] [<ffffffff81124848>] ? dput+0x19/0x150 [ 248.779558] [<ffffffff812cfdcd>] ? move_addr_to_kernel+0x2e/0x53 [ 248.780437] [<ffffffff812d91be>] ? verify_iovec+0x4c/0x9a [ 248.781218] [<ffffffff812cfd15>] ? ___sys_sendmsg+0x1e7/0x271 [ 248.782006] [<ffffffff81304892>] ? netlink_autobind.isra.23+0xc6/0xe7 [ 248.782924] [<ffffffff81304c79>] ? netlink_bind+0xed/0x199 [ 248.783878] [<ffffffff812ce716>] ? move_addr_to_user+0x5f/0x90 [ 248.784732] [<ffffffff812ce853>] ? SYSC_getsockname+0x7b/0x8c [ 248.785549] [<ffffffff812d00a1>] ? __sys_sendmsg+0x39/0x57 [ 248.786304] [<ffffffff8139e4d2>] ? system_call_fastpath+0x16/0x1b [ 248.787103] ---[ end trace 3d613ca14aa39b9a ]--- [ 248.787773] kobject_create_and_add: kobject_add error: -17 [ 248.788529] batman_adv: eth1: Can't add sysfs directory: eth1/batman_adv
---
On Mon, May 26, 2014 at 12:18:38PM +0200, Daniel Ehlers wrote:
diff --git a/hard-interface.c b/hard-interface.c index b851cc5..c3497de 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -31,6 +31,7 @@ #include <linux/if_arp.h> #include <linux/if_ether.h> +#include <net/net_namespace.h>
These includes in the various, changed files seem unnecessary, too. At least it compiles fine with out them for me, too.
b.a.t.m.a.n@lists.open-mesh.org