From patchwork Sun Jan 13 09:51:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 2698 Return-Path: Received: from nm23-vm1.bullet.mail.sg3.yahoo.com (nm23-vm1.bullet.mail.sg3.yahoo.com [106.10.151.64]) by open-mesh.org (Postfix) with ESMTPS id 78760601B05 for ; Sun, 13 Jan 2013 10:51:38 +0100 (CET) Received: from [106.10.166.60] by nm23.bullet.mail.sg3.yahoo.com with NNFMP; 13 Jan 2013 09:51:36 -0000 Received: from [106.10.167.206] by tm17.bullet.mail.sg3.yahoo.com with NNFMP; 13 Jan 2013 09:51:36 -0000 Received: from [127.0.0.1] by smtp179.mail.sg3.yahoo.com with NNFMP; 13 Jan 2013 09:51:36 -0000 X-Yahoo-Newman-Id: 369174.71606.bm@smtp179.mail.sg3.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: EUjNNGsVM1kJeOaaQKikJDXvkbK.FKFsW.eEzMXGYwxUaUF 1PYIOGcqanULY25MxkEAcTvZP6CK7P7h4iYEv_vp7bAQTJj8qZJi6JOPAJoQ RckVZ2PduXLMUYbes9J.WWaIg57nj8iIbUdRYWSV1sF5AOV.fY4EtMcH_kYA XsfmEwAM5t4RHia1o49Q4tzS8oP71Sl89dnYZwSjCAXwVuUa.x3.XQKhonYM zVbdIaCSdViHT_H0ujFdyDHpUx16xEMo7rXXoWkgM3fbo_2LKqFQmWOoARin 1xo6QAKWfgzlYwk6Rte8U6Ti4jCY6PmnUtIvRJazVcMJPmiHk88fWlC39wi_ q.DtcR6g7vBU9K5SBGnB70FxO5QlI2KaBhsSicjvbh9h5b_6qYv0g7JmR2Wm VE70XejwDUCFGnCYFSdnjU5XRPcgYhtAq57_F_bASJ6.Z X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@1.36.145.67 with plain) by smtp179.mail.sg3.yahoo.com with SMTP; 13 Jan 2013 01:51:36 -0800 PST From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 13 Jan 2013 17:51:03 +0800 Message-Id: <1358070663-8226-6-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1358070663-8226-1-git-send-email-lindner_marek@yahoo.de> References: <201301131750.39338.lindner_marek@yahoo.de> <1358070663-8226-1-git-send-email-lindner_marek@yahoo.de> Cc: Sven Eckelmann Subject: [B.A.T.M.A.N.] [PATCHv2 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: Sun, 13 Jan 2013 09:51:40 -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 --- soft-interface.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/soft-interface.c b/soft-interface.c index d9f27d5..ac34c55 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -506,6 +506,41 @@ 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 + */ +static int batadv_softif_slave_add(struct net_device *dev, + struct net_device *slave_dev) +{ + struct batadv_hard_iface *hard_iface; + + hard_iface = batadv_hardif_get_by_netdev(slave_dev); + if (!hard_iface || hard_iface->soft_iface != NULL) + return -EINVAL; + + return batadv_hardif_enable_interface(hard_iface, dev->name); +} + +/** + * 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 + */ +static int batadv_softif_slave_del(struct net_device *dev, + struct net_device *slave_dev) +{ + struct batadv_hard_iface *hard_iface; + + hard_iface = batadv_hardif_get_by_netdev(slave_dev); + if (!hard_iface || hard_iface->soft_iface != dev) + return -EINVAL; + + batadv_hardif_disable_interface(hard_iface, BATADV_IF_CLEANUP_KEEP); + return 0; +} + static const struct net_device_ops batadv_netdev_ops = { .ndo_init = batadv_softif_init_late, .ndo_open = batadv_interface_open, @@ -514,7 +549,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, }; /**