From patchwork Mon Feb 11 09:10:27 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 2764 Return-Path: Received: from nm17-vm1.bullet.mail.sg3.yahoo.com (nm17-vm1.bullet.mail.sg3.yahoo.com [106.10.149.80]) by open-mesh.org (Postfix) with ESMTPS id 94027601BB0 for ; Mon, 11 Feb 2013 10:11:05 +0100 (CET) Received: from [106.10.166.124] by nm17.bullet.mail.sg3.yahoo.com with NNFMP; 11 Feb 2013 09:11:01 -0000 Received: from [106.10.167.193] by tm13.bullet.mail.sg3.yahoo.com with NNFMP; 11 Feb 2013 09:11:01 -0000 Received: from [127.0.0.1] by smtp166.mail.sg3.yahoo.com with NNFMP; 11 Feb 2013 09:11:01 -0000 X-Yahoo-Newman-Id: 896478.37271.bm@smtp166.mail.sg3.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: rQh39wIVM1mg6vSdlTKinYKMFX_ny5dg7qbJBpignsGu_C7 x_8QTXZI6G1tAX9hdtPHtin.sf8YObOZ_e9FY_5vmGXsyqlfjwuSeAo.QZz6 85ddWhmFUeanoS85FRKKzz_bltbZ8K3meIjqNY47aoe.QMoy02VLSJs1DuBQ LErAIA9pjabqAWsIMyhovK9ngNXDeZYccLbaDC2s1CPzKfguoOjJft9YOigW PAqSk1al3XQb.zLwsCjyOsDuvjetppVNQVOuXdSjMUQw3xP0Bw7FxKG5SVg4 7z4wyWH28xgPFQgZkaWcfo2XL5pzZEhUAzmMQu_HiciuwQOojK0Z1PJnq2wL byBh7HMEVyUupuegfyHNg4.o1zUGtJu5sCfEwy2A9HWc6TAmuL_W8ugQu_6n ONUuZCEYsnyz0wGz6U6FvB2mxCYD6ubfHcdh21z06.pNz X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@1.36.145.66 with plain) by smtp166.mail.sg3.yahoo.com with SMTP; 11 Feb 2013 01:11:01 -0800 PST From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Mon, 11 Feb 2013 17:10:27 +0800 Message-Id: <1360573828-24399-6-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1360573828-24399-1-git-send-email-lindner_marek@yahoo.de> References: <201302111710.04911.lindner_marek@yahoo.de> <1360573828-24399-1-git-send-email-lindner_marek@yahoo.de> Cc: Sven Eckelmann Subject: [B.A.T.M.A.N.] [PATCHv3 6/6] batman-adv: Allow to modify slaves of soft-interfaces through rntl_link X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 11 Feb 2013 09:11:11 -0000 From: Sven Eckelmann The sysfs configuration interface of batman-adv to add/remove slaves of an soft-iface is not deadlock free and doesn't follow the currently common way to modify slaves of an interface. An additional configuration interface though rtnl_link is introduced which provides easy device adding/removing with tools like "ip": $ ip link set dev eth0 master bat0 $ ip link set dev eth0 nomaster Signed-off-by: Sven Eckelmann --- compat.h | 3 +++ hard-interface.c | 11 +++++++++-- soft-interface.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/compat.h b/compat.h index 48180e2..425b3d9 100644 --- a/compat.h +++ b/compat.h @@ -212,6 +212,9 @@ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p) \ }\ static int __batadv_interface_set_mac_addr(x, y) +#define netdev_master_upper_dev_link netdev_set_master +#define netdev_upper_dev_unlink(slave, master) netdev_set_master(slave, NULL) + #endif /* < KERNEL_VERSION(3, 9, 0) */ #endif /* _NET_BATMAN_ADV_COMPAT_H_ */ diff --git a/hard-interface.c b/hard-interface.c index 6c32607..c08e39e 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -350,9 +350,13 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, hard_iface->soft_iface = soft_iface; bat_priv = netdev_priv(hard_iface->soft_iface); + ret = netdev_master_upper_dev_link(hard_iface->net_dev, soft_iface); + if (ret) + goto err_dev; + ret = bat_priv->bat_algo_ops->bat_iface_enable(hard_iface); if (ret < 0) - goto err_dev; + goto err_upper; hard_iface->if_num = bat_priv->num_ifaces; bat_priv->num_ifaces++; @@ -362,7 +366,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, bat_priv->bat_algo_ops->bat_iface_disable(hard_iface); bat_priv->num_ifaces--; hard_iface->if_status = BATADV_IF_NOT_IN_USE; - goto err_dev; + goto err_upper; } hard_iface->batman_adv_ptype.type = ethertype; @@ -401,6 +405,8 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface, out: return 0; +err_upper: + netdev_upper_dev_unlink(hard_iface->net_dev, soft_iface); err_dev: dev_put(soft_iface); err: @@ -450,6 +456,7 @@ void batadv_hardif_disable_interface(struct batadv_hard_iface *hard_iface, if (!bat_priv->num_ifaces && autodel == BATADV_IF_CLEANUP_AUTO) batadv_softif_destroy_sysfs(hard_iface->soft_iface); + netdev_upper_dev_unlink(hard_iface->net_dev, hard_iface->soft_iface); hard_iface->soft_iface = NULL; batadv_hardif_free_ref(hard_iface); diff --git a/soft-interface.c b/soft-interface.c index 4ef1649..39caefa 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -509,6 +509,58 @@ free_bat_counters: return ret; } +/** + * batadv_softif_slave_add - Add a slave interface to a batadv_soft_interface + * @dev: batadv_soft_interface used as master interface + * @slave_dev: net_device which should become the slave interface + * + * Return 0 if successful or error otherwise. + */ +static int batadv_softif_slave_add(struct net_device *dev, + struct net_device *slave_dev) +{ + struct batadv_hard_iface *hard_iface; + 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); + +out: + if (hard_iface) + batadv_hardif_free_ref(hard_iface); + return ret; +} + +/** + * batadv_softif_slave_del - Delete a slave iface from a batadv_soft_interface + * @dev: batadv_soft_interface used as master interface + * @slave_dev: net_device which should be removed from the master interface + * + * Return 0 if successful or error otherwise. + */ +static int batadv_softif_slave_del(struct net_device *dev, + struct net_device *slave_dev) +{ + struct batadv_hard_iface *hard_iface; + int ret = -EINVAL; + + hard_iface = batadv_hardif_get_by_netdev(slave_dev); + + if (!hard_iface || hard_iface->soft_iface != dev) + goto out; + + batadv_hardif_disable_interface(hard_iface, BATADV_IF_CLEANUP_KEEP); + ret = 0; + +out: + if (hard_iface) + batadv_hardif_free_ref(hard_iface); + return ret; +} + static const struct net_device_ops batadv_netdev_ops = { .ndo_init = batadv_softif_init_late, .ndo_open = batadv_interface_open, @@ -517,7 +569,9 @@ static const struct net_device_ops batadv_netdev_ops = { .ndo_set_mac_address = batadv_interface_set_mac_addr, .ndo_change_mtu = batadv_interface_change_mtu, .ndo_start_xmit = batadv_interface_tx, - .ndo_validate_addr = eth_validate_addr + .ndo_validate_addr = eth_validate_addr, + .ndo_add_slave = batadv_softif_slave_add, + .ndo_del_slave = batadv_softif_slave_del, }; /**