From patchwork Sun Jan 13 09:51:02 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 2663 Return-Path: Received: from nm6-vm2.bullet.mail.sg3.yahoo.com (nm6-vm2.bullet.mail.sg3.yahoo.com [106.10.148.161]) by open-mesh.org (Postfix) with ESMTPS id 2BD9F601B06 for ; Sun, 13 Jan 2013 10:51:36 +0100 (CET) Received: from [106.10.166.112] by nm6.bullet.mail.sg3.yahoo.com with NNFMP; 13 Jan 2013 09:51:33 -0000 Received: from [106.10.167.128] by tm1.bullet.mail.sg3.yahoo.com with NNFMP; 13 Jan 2013 09:51:33 -0000 Received: from [127.0.0.1] by smtp101.mail.sg3.yahoo.com with NNFMP; 13 Jan 2013 09:51:33 -0000 X-Yahoo-Newman-Id: 686682.90095.bm@smtp101.mail.sg3.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: z9AN4OkVM1nzP_pwzG9gj.GL.UHVU5yC4Sva.JM.piQKDQA Fnytz1lSrJOwq_JugDPxHd2178xBuJJMP4.QancR_7MLhQSaLP5pI6IHOOZm KGyRkLJQn6qQ07cWZXvj16RkB8A0lq2iuDKbN5nwgem3XQcpheDaWHIpQioA 5Mg6uJYXk3wD21zU5ugVUw_KlSy_u0qsBd3u4bZbK9j3qcnFoFqYCeNhyOy_ JgZ7ZQ_SVstGum6vzKlermoYCi.sJVLo9a8V7AMjduflwMa5LuQhISkzRXwg FFx_jKJ2VgItlM5Wq439xKVCYLUqdXDLxlhJfeA6xz0K5fUTEe275yCENIYS orUISkvE9y4NSAtMW0dUowqUAClWiSaWhknYYm4toVS3d4xb0F9PerIZmJLZ Dt0werpxC45x7kRF_7FRsLPamBcHLouG9g6QWXC7PRldA X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@1.36.145.67 with plain) by smtp101.mail.sg3.yahoo.com with SMTP; 13 Jan 2013 01:51:33 -0800 PST From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Sun, 13 Jan 2013 17:51:02 +0800 Message-Id: <1358070663-8226-5-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 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: Sun, 13 Jan 2013 09:51:38 -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 21fe698..d3752a4 100644 --- a/main.c +++ b/main.c @@ -70,6 +70,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); @@ -80,6 +81,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 7cebbfd..d779303 100644 --- a/main.h +++ b/main.h @@ -150,6 +150,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 bf19605..d9f27d5 100644 --- a/soft-interface.c +++ b/soft-interface.c @@ -567,6 +567,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", @@ -589,6 +591,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) @@ -597,6 +619,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_ */