diff options
author | Antonio Quartulli <ordex@autistici.org> | 2012-09-09 04:46:46 -0400 |
---|---|---|
committer | Antonio Quartulli <ordex@autistici.org> | 2012-11-14 15:00:33 -0500 |
commit | b7eddd0b3950ea9dc863f1cbfa30d172dbf772f4 (patch) | |
tree | 1cf1d410c51381b1f02234c297a2650dee3fa7d5 | |
parent | a7528f8ddda9fba061148e18e71761b50b1c6d26 (diff) |
batman-adv: prevent using any virtual device created on batman-adv as hard-interface
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>
-rw-r--r-- | net/batman-adv/hard-interface.c | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c index 6b7a5d3eeb77..365ed74f3946 100644 --- a/net/batman-adv/hard-interface.c +++ b/net/batman-adv/hard-interface.c | |||
@@ -59,6 +59,45 @@ out: | |||
59 | return hard_iface; | 59 | return hard_iface; |
60 | } | 60 | } |
61 | 61 | ||
62 | /** | ||
63 | * batadv_is_on_batman_iface - check if a device is a batman iface descendant | ||
64 | * @net_dev: the device to check | ||
65 | * | ||
66 | * If the user creates any virtual device on top of a batman-adv interface, it | ||
67 | * is important to prevent this new interface to be used to create a new mesh | ||
68 | * network (this behaviour would lead to a batman-over-batman configuration). | ||
69 | * This function recursively checks all the fathers of the device passed as | ||
70 | * argument looking for a batman-adv soft interface. | ||
71 | * | ||
72 | * Returns true if the device is descendant of a batman-adv mesh interface (or | ||
73 | * if it is a batman-adv interface itself), false otherwise | ||
74 | */ | ||
75 | static bool batadv_is_on_batman_iface(const struct net_device *net_dev) | ||
76 | { | ||
77 | struct net_device *parent_dev; | ||
78 | bool ret; | ||
79 | |||
80 | /* check if this is a batman-adv mesh interface */ | ||
81 | if (batadv_softif_is_valid(net_dev)) | ||
82 | return true; | ||
83 | |||
84 | /* no more parents..stop recursion */ | ||
85 | if (net_dev->iflink == net_dev->ifindex) | ||
86 | return false; | ||
87 | |||
88 | /* recurse over the parent device */ | ||
89 | parent_dev = dev_get_by_index(&init_net, net_dev->iflink); | ||
90 | /* if we got a NULL parent_dev there is something broken.. */ | ||
91 | if (WARN(!parent_dev, "Cannot find parent device")) | ||
92 | return false; | ||
93 | |||
94 | ret = batadv_is_on_batman_iface(parent_dev); | ||
95 | |||
96 | if (parent_dev) | ||
97 | dev_put(parent_dev); | ||
98 | return ret; | ||
99 | } | ||
100 | |||
62 | static int batadv_is_valid_iface(const struct net_device *net_dev) | 101 | static int batadv_is_valid_iface(const struct net_device *net_dev) |
63 | { | 102 | { |
64 | if (net_dev->flags & IFF_LOOPBACK) | 103 | if (net_dev->flags & IFF_LOOPBACK) |
@@ -71,7 +110,7 @@ static int batadv_is_valid_iface(const struct net_device *net_dev) | |||
71 | return 0; | 110 | return 0; |
72 | 111 | ||
73 | /* no batman over batman */ | 112 | /* no batman over batman */ |
74 | if (batadv_softif_is_valid(net_dev)) | 113 | if (batadv_is_on_batman_iface(net_dev)) |
75 | return 0; | 114 | return 0; |
76 | 115 | ||
77 | return 1; | 116 | return 1; |