From: Antonio Quartulli <ordex@autistici.org>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org,
Antonio Quartulli <ordex@autistici.org>
Subject: [PATCH 03/11] batman-adv: prevent using any virtual device created on batman-adv as hard-interface
Date: Wed, 14 Nov 2012 21:16:21 +0100 [thread overview]
Message-ID: <1352924189-18843-4-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1352924189-18843-1-git-send-email-ordex@autistici.org>
Any virtual device created on top of a batman-adv mesh interface must be
prevented to be used to create a new mesh network (this would lead to an
unwanted batman-over-batman configuration)
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
net/batman-adv/hard-interface.c | 41 ++++++++++++++++++++++++++++++++++++++++-
1 file changed, 40 insertions(+), 1 deletion(-)
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index 6b7a5d3..365ed74 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -59,6 +59,45 @@ out:
return hard_iface;
}
+/**
+ * batadv_is_on_batman_iface - check if a device is a batman iface descendant
+ * @net_dev: the device to check
+ *
+ * If the user creates any virtual device on top of a batman-adv interface, it
+ * is important to prevent this new interface to be used to create a new mesh
+ * network (this behaviour would lead to a batman-over-batman configuration).
+ * This function recursively checks all the fathers of the device passed as
+ * argument looking for a batman-adv soft interface.
+ *
+ * Returns true if the device is descendant of a batman-adv mesh interface (or
+ * if it is a batman-adv interface itself), false otherwise
+ */
+static bool batadv_is_on_batman_iface(const struct net_device *net_dev)
+{
+ struct net_device *parent_dev;
+ bool ret;
+
+ /* check if this is a batman-adv mesh interface */
+ if (batadv_softif_is_valid(net_dev))
+ return true;
+
+ /* no more parents..stop recursion */
+ if (net_dev->iflink == net_dev->ifindex)
+ return false;
+
+ /* recurse over the parent device */
+ parent_dev = dev_get_by_index(&init_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;
+
+ ret = batadv_is_on_batman_iface(parent_dev);
+
+ if (parent_dev)
+ dev_put(parent_dev);
+ return ret;
+}
+
static int batadv_is_valid_iface(const struct net_device *net_dev)
{
if (net_dev->flags & IFF_LOOPBACK)
@@ -71,7 +110,7 @@ static int batadv_is_valid_iface(const struct net_device *net_dev)
return 0;
/* no batman over batman */
- if (batadv_softif_is_valid(net_dev))
+ if (batadv_is_on_batman_iface(net_dev))
return 0;
return 1;
--
1.8.0
next prev parent reply other threads:[~2012-11-14 20:17 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-14 20:16 pull request: batman-adv 2012-11-14 Antonio Quartulli
[not found] ` <1352924189-18843-1-git-send-email-ordex-GaUfNO9RBHfsrOwW+9ziJQ@public.gmane.org>
2012-11-14 20:16 ` [PATCH 01/11] batman-adv: don't rely on positions in struct for hashing Antonio Quartulli
2012-11-14 20:16 ` [PATCH 02/11] batman-adv: fix wrong spinlock inline comment Antonio Quartulli
2012-11-14 20:16 ` Antonio Quartulli [this message]
2012-11-14 20:16 ` [PATCH 04/11] batman-adv: send announcement when backbone gw is registered Antonio Quartulli
2012-11-14 20:16 ` [PATCH 05/11] batman-adv: allow bla traffic only after first worker period Antonio Quartulli
2012-11-14 20:16 ` [PATCH 06/11] batman-adv: wait multiple periods before activating bla Antonio Quartulli
2012-11-14 20:16 ` [PATCH 07/11] batman-adv: substitute tt_poss_change with a per-tt_entry flag Antonio Quartulli
2012-11-14 20:16 ` [PATCH 08/11] batman-adv: refactor code to simplify long lines Antonio Quartulli
2012-11-14 20:16 ` [PATCH 09/11] batman-adv: refactor tt_global_del_struct() Antonio Quartulli
2012-11-14 20:16 ` [PATCH 10/11] batman-adv: roaming handling mechanism redesign Antonio Quartulli
2012-11-14 20:16 ` [PATCH 11/11] batman-adv: Remove instant overwritten variable initialization Antonio Quartulli
2012-11-14 23:01 ` [B.A.T.M.A.N.] pull request: batman-adv 2012-11-14 David Miller
2012-11-15 3:11 ` David Miller
-- strict thread matches above, loose matches on Subject: below --
2012-11-13 9:15 pull request: batman-adv 2012-11-13 Antonio Quartulli
2012-11-13 9:15 ` [PATCH 03/11] batman-adv: prevent using any virtual device created on batman-adv as hard-interface Antonio Quartulli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1352924189-18843-4-git-send-email-ordex@autistici.org \
--to=ordex@autistici.org \
--cc=b.a.t.m.a.n@lists.open-mesh.org \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox