From patchwork Mon Feb 11 09:10:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 2755 Return-Path: Received: from nm17-vm8.bullet.mail.sg3.yahoo.com (nm17-vm8.bullet.mail.sg3.yahoo.com [106.10.149.87]) by open-mesh.org (Postfix) with ESMTPS id 5CB41601BAF for ; Mon, 11 Feb 2013 10:11:02 +0100 (CET) Received: from [106.10.166.116] by nm17.bullet.mail.sg3.yahoo.com with NNFMP; 11 Feb 2013 09:10:58 -0000 Received: from [106.10.167.132] by tm5.bullet.mail.sg3.yahoo.com with NNFMP; 11 Feb 2013 09:10:58 -0000 Received: from [127.0.0.1] by smtp105.mail.sg3.yahoo.com with NNFMP; 11 Feb 2013 09:10:58 -0000 X-Yahoo-Newman-Id: 779851.39226.bm@smtp105.mail.sg3.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: Pj_txRsVM1nAeAsySG0a6XJJC.VT.i5GtYdLCT6VdWHV7XO Z51POrydbeL.gbKu_6T297JInQdZcJbJQjkTfnvAZUa6Ecx7ENuAjmCHyw2Q 2EzQejVaUbxyeKpmaqEsoWtAfp7NJhB.JtvOpUthJlC3.FKzHxtlrI8bNggK czm0_v6azTsxoz6oxj6CHP2mv3BeANX3Dd185NdC5c1gVlEBxe.5roUXmIjX 5T1.GKa2Q15.L9qZ32tNk1wnsRs6YMSa_IvnnDtQCFXSI97XEfcQRvz7rvzQ 2T3bI0zotKoqPkhZrsjwPkFjEC7JlsKEBEjKmVVHK5G489UtNRsW_B2Q_BgJ BCynaP1WwmuRS6frL6SyXXyl_3x2eOFUF2TzsPzKV8BmG82QHLbr434cbIok sMqArI5nDw6jCqdhtIeGqxMazUU1O2eJAw.T0oQVl2OYT X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@1.36.145.66 with plain) by smtp105.mail.sg3.yahoo.com with SMTP; 11 Feb 2013 01:10:58 -0800 PST From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Mon, 11 Feb 2013 17:10:26 +0800 Message-Id: <1360573828-24399-5-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 5/6] batman-adv: Allow to use rntl_link for device creation/deletion 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:09 -0000 From: Sven Eckelmann The sysfs configuration interface of batman-adv to add/remove soft-interfaces is not deadlock free and doesn't follow the currently common way to create new virtual interfaces. An additional interface though rtnl_link is introduced which provides easy device creation/deletion with tools like "ip": $ ip link add dev bat0 type batadv $ ip link del dev bat0 Signed-off-by: Sven Eckelmann --- main.c | 2 ++ main.h | 1 + soft-interface.c | 29 +++++++++++++++++++++++++++++ soft-interface.h | 1 + 4 files changed, 33 insertions(+) diff --git a/main.c b/main.c index bbb91a5..afccc3d 100644 --- a/main.c +++ b/main.c @@ -71,6 +71,7 @@ static int __init batadv_init(void) batadv_debugfs_init(); register_netdevice_notifier(&batadv_hard_if_notifier); + rtnl_link_register(&batadv_link_ops); pr_info("B.A.T.M.A.N. advanced %s (compatibility version %i) loaded\n", BATADV_SOURCE_VERSION, BATADV_COMPAT_VERSION); @@ -81,6 +82,7 @@ static int __init batadv_init(void) static void __exit batadv_exit(void) { batadv_debugfs_destroy(); + rtnl_link_unregister(&batadv_link_ops); unregister_netdevice_notifier(&batadv_hard_if_notifier); batadv_hardif_remove_interfaces(); diff --git a/main.h b/main.h index 8a9caa0..140f008 100644 --- a/main.h +++ b/main.h @@ -152,6 +152,7 @@ enum batadv_uev_type { #include #include #include /* struct sock */ +#include #include #include #include "compat.h" diff --git a/soft-interface.c b/soft-interface.c index bc77a5b..4ef1649 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -570,6 +570,8 @@ struct net_device *batadv_softif_create(const char *name) if (!soft_iface) return NULL; + soft_iface->rtnl_link_ops = &batadv_link_ops; + ret = register_netdevice(soft_iface); if (ret < 0) { pr_err("Unable to register the batman interface '%s': %i\n", @@ -592,6 +594,26 @@ void batadv_softif_destroy_sysfs(struct net_device *soft_iface) queue_work(batadv_event_workqueue, &bat_priv->cleanup_work); } +/** + * batadv_softif_destroy_netlink - deletion of batadv_soft_interface via netlink + * @soft_iface: the to-be-removed batman-adv interface + * @head: list pointer + */ +void batadv_softif_destroy_netlink(struct net_device *soft_iface, + struct list_head *head) +{ + struct batadv_hard_iface *hard_iface; + + list_for_each_entry(hard_iface, &batadv_hardif_list, list) { + if (hard_iface->soft_iface == soft_iface) + batadv_hardif_disable_interface(hard_iface, + BATADV_IF_CLEANUP_KEEP); + } + + batadv_sysfs_del_meshif(soft_iface); + unregister_netdevice_queue(soft_iface, head); +} + int batadv_softif_is_valid(const struct net_device *net_dev) { if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx) @@ -600,6 +622,13 @@ int batadv_softif_is_valid(const struct net_device *net_dev) return 0; } +struct rtnl_link_ops batadv_link_ops __read_mostly = { + .kind = "batadv", + .priv_size = sizeof(struct batadv_priv), + .setup = batadv_softif_init_early, + .dellink = batadv_softif_destroy_netlink, +}; + /* ethtool */ static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) { diff --git a/soft-interface.h b/soft-interface.h index 49bc66b..2f2472c 100644 --- a/soft-interface.h +++ b/soft-interface.h @@ -27,5 +27,6 @@ void batadv_interface_rx(struct net_device *soft_iface, struct net_device *batadv_softif_create(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; #endif /* _NET_BATMAN_ADV_SOFT_INTERFACE_H_ */