aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/soft-interface.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/batman-adv/soft-interface.c')
-rw-r--r--net/batman-adv/soft-interface.c304
1 files changed, 186 insertions, 118 deletions
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index a0ec0e4ada4c..109ea2aae96c 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -1,5 +1,4 @@
1/* 1/* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
2 * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
3 * 2 *
4 * Marek Lindner, Simon Wunderlich 3 * Marek Lindner, Simon Wunderlich
5 * 4 *
@@ -16,7 +15,6 @@
16 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 * 02110-1301, USA 17 * 02110-1301, USA
19 *
20 */ 18 */
21 19
22#include "main.h" 20#include "main.h"
@@ -24,12 +22,12 @@
24#include "hard-interface.h" 22#include "hard-interface.h"
25#include "routing.h" 23#include "routing.h"
26#include "send.h" 24#include "send.h"
27#include "bat_debugfs.h" 25#include "debugfs.h"
28#include "translation-table.h" 26#include "translation-table.h"
29#include "hash.h" 27#include "hash.h"
30#include "gateway_common.h" 28#include "gateway_common.h"
31#include "gateway_client.h" 29#include "gateway_client.h"
32#include "bat_sysfs.h" 30#include "sysfs.h"
33#include "originator.h" 31#include "originator.h"
34#include <linux/slab.h> 32#include <linux/slab.h>
35#include <linux/ethtool.h> 33#include <linux/ethtool.h>
@@ -39,27 +37,33 @@
39#include "bridge_loop_avoidance.h" 37#include "bridge_loop_avoidance.h"
40 38
41 39
42static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd); 40static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
43static void bat_get_drvinfo(struct net_device *dev, 41static void batadv_get_drvinfo(struct net_device *dev,
44 struct ethtool_drvinfo *info); 42 struct ethtool_drvinfo *info);
45static u32 bat_get_msglevel(struct net_device *dev); 43static u32 batadv_get_msglevel(struct net_device *dev);
46static void bat_set_msglevel(struct net_device *dev, u32 value); 44static void batadv_set_msglevel(struct net_device *dev, u32 value);
47static u32 bat_get_link(struct net_device *dev); 45static u32 batadv_get_link(struct net_device *dev);
48 46static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data);
49static const struct ethtool_ops bat_ethtool_ops = { 47static void batadv_get_ethtool_stats(struct net_device *dev,
50 .get_settings = bat_get_settings, 48 struct ethtool_stats *stats, u64 *data);
51 .get_drvinfo = bat_get_drvinfo, 49static int batadv_get_sset_count(struct net_device *dev, int stringset);
52 .get_msglevel = bat_get_msglevel, 50
53 .set_msglevel = bat_set_msglevel, 51static const struct ethtool_ops batadv_ethtool_ops = {
54 .get_link = bat_get_link, 52 .get_settings = batadv_get_settings,
53 .get_drvinfo = batadv_get_drvinfo,
54 .get_msglevel = batadv_get_msglevel,
55 .set_msglevel = batadv_set_msglevel,
56 .get_link = batadv_get_link,
57 .get_strings = batadv_get_strings,
58 .get_ethtool_stats = batadv_get_ethtool_stats,
59 .get_sset_count = batadv_get_sset_count,
55}; 60};
56 61
57int my_skb_head_push(struct sk_buff *skb, unsigned int len) 62int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)
58{ 63{
59 int result; 64 int result;
60 65
61 /** 66 /* TODO: We must check if we can release all references to non-payload
62 * TODO: We must check if we can release all references to non-payload
63 * data using skb_header_release in our skbs to allow skb_cow_header to 67 * data using skb_header_release in our skbs to allow skb_cow_header to
64 * work optimally. This means that those skbs are not allowed to read 68 * work optimally. This means that those skbs are not allowed to read
65 * or write any data which is before the current position of skb->data 69 * or write any data which is before the current position of skb->data
@@ -74,37 +78,37 @@ int my_skb_head_push(struct sk_buff *skb, unsigned int len)
74 return 0; 78 return 0;
75} 79}
76 80
77static int interface_open(struct net_device *dev) 81static int batadv_interface_open(struct net_device *dev)
78{ 82{
79 netif_start_queue(dev); 83 netif_start_queue(dev);
80 return 0; 84 return 0;
81} 85}
82 86
83static int interface_release(struct net_device *dev) 87static int batadv_interface_release(struct net_device *dev)
84{ 88{
85 netif_stop_queue(dev); 89 netif_stop_queue(dev);
86 return 0; 90 return 0;
87} 91}
88 92
89static struct net_device_stats *interface_stats(struct net_device *dev) 93static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
90{ 94{
91 struct bat_priv *bat_priv = netdev_priv(dev); 95 struct batadv_priv *bat_priv = netdev_priv(dev);
92 return &bat_priv->stats; 96 return &bat_priv->stats;
93} 97}
94 98
95static int interface_set_mac_addr(struct net_device *dev, void *p) 99static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
96{ 100{
97 struct bat_priv *bat_priv = netdev_priv(dev); 101 struct batadv_priv *bat_priv = netdev_priv(dev);
98 struct sockaddr *addr = p; 102 struct sockaddr *addr = p;
99 103
100 if (!is_valid_ether_addr(addr->sa_data)) 104 if (!is_valid_ether_addr(addr->sa_data))
101 return -EADDRNOTAVAIL; 105 return -EADDRNOTAVAIL;
102 106
103 /* only modify transtable if it has been initialized before */ 107 /* only modify transtable if it has been initialized before */
104 if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) { 108 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE) {
105 tt_local_remove(bat_priv, dev->dev_addr, 109 batadv_tt_local_remove(bat_priv, dev->dev_addr,
106 "mac address changed", false); 110 "mac address changed", false);
107 tt_local_add(dev, addr->sa_data, NULL_IFINDEX); 111 batadv_tt_local_add(dev, addr->sa_data, BATADV_NULL_IFINDEX);
108 } 112 }
109 113
110 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); 114 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
@@ -112,10 +116,10 @@ static int interface_set_mac_addr(struct net_device *dev, void *p)
112 return 0; 116 return 0;
113} 117}
114 118
115static int interface_change_mtu(struct net_device *dev, int new_mtu) 119static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
116{ 120{
117 /* check ranges */ 121 /* check ranges */
118 if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev))) 122 if ((new_mtu < 68) || (new_mtu > batadv_hardif_min_mtu(dev)))
119 return -EINVAL; 123 return -EINVAL;
120 124
121 dev->mtu = new_mtu; 125 dev->mtu = new_mtu;
@@ -123,13 +127,15 @@ static int interface_change_mtu(struct net_device *dev, int new_mtu)
123 return 0; 127 return 0;
124} 128}
125 129
126static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface) 130static int batadv_interface_tx(struct sk_buff *skb,
131 struct net_device *soft_iface)
127{ 132{
128 struct ethhdr *ethhdr = (struct ethhdr *)skb->data; 133 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
129 struct bat_priv *bat_priv = netdev_priv(soft_iface); 134 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
130 struct hard_iface *primary_if = NULL; 135 struct batadv_hard_iface *primary_if = NULL;
131 struct bcast_packet *bcast_packet; 136 struct batadv_bcast_packet *bcast_packet;
132 struct vlan_ethhdr *vhdr; 137 struct vlan_ethhdr *vhdr;
138 __be16 ethertype = __constant_htons(BATADV_ETH_P_BATMAN);
133 static const uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00, 139 static const uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00,
134 0x00}; 140 0x00};
135 unsigned int header_len = 0; 141 unsigned int header_len = 0;
@@ -137,7 +143,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
137 short vid __maybe_unused = -1; 143 short vid __maybe_unused = -1;
138 bool do_bcast = false; 144 bool do_bcast = false;
139 145
140 if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE) 146 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
141 goto dropped; 147 goto dropped;
142 148
143 soft_iface->trans_start = jiffies; 149 soft_iface->trans_start = jiffies;
@@ -147,45 +153,47 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
147 vhdr = (struct vlan_ethhdr *)skb->data; 153 vhdr = (struct vlan_ethhdr *)skb->data;
148 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; 154 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
149 155
150 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN) 156 if (vhdr->h_vlan_encapsulated_proto != ethertype)
151 break; 157 break;
152 158
153 /* fall through */ 159 /* fall through */
154 case ETH_P_BATMAN: 160 case BATADV_ETH_P_BATMAN:
155 goto dropped; 161 goto dropped;
156 } 162 }
157 163
158 if (bla_tx(bat_priv, skb, vid)) 164 if (batadv_bla_tx(bat_priv, skb, vid))
159 goto dropped; 165 goto dropped;
160 166
161 /* Register the client MAC in the transtable */ 167 /* Register the client MAC in the transtable */
162 tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif); 168 batadv_tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
163 169
164 /* don't accept stp packets. STP does not help in meshes. 170 /* don't accept stp packets. STP does not help in meshes.
165 * better use the bridge loop avoidance ... 171 * better use the bridge loop avoidance ...
166 */ 172 */
167 if (compare_eth(ethhdr->h_dest, stp_addr)) 173 if (batadv_compare_eth(ethhdr->h_dest, stp_addr))
168 goto dropped; 174 goto dropped;
169 175
170 if (is_multicast_ether_addr(ethhdr->h_dest)) { 176 if (is_multicast_ether_addr(ethhdr->h_dest)) {
171 do_bcast = true; 177 do_bcast = true;
172 178
173 switch (atomic_read(&bat_priv->gw_mode)) { 179 switch (atomic_read(&bat_priv->gw_mode)) {
174 case GW_MODE_SERVER: 180 case BATADV_GW_MODE_SERVER:
175 /* gateway servers should not send dhcp 181 /* gateway servers should not send dhcp
176 * requests into the mesh */ 182 * requests into the mesh
177 ret = gw_is_dhcp_target(skb, &header_len); 183 */
184 ret = batadv_gw_is_dhcp_target(skb, &header_len);
178 if (ret) 185 if (ret)
179 goto dropped; 186 goto dropped;
180 break; 187 break;
181 case GW_MODE_CLIENT: 188 case BATADV_GW_MODE_CLIENT:
182 /* gateway clients should send dhcp requests 189 /* gateway clients should send dhcp requests
183 * via unicast to their gateway */ 190 * via unicast to their gateway
184 ret = gw_is_dhcp_target(skb, &header_len); 191 */
192 ret = batadv_gw_is_dhcp_target(skb, &header_len);
185 if (ret) 193 if (ret)
186 do_bcast = false; 194 do_bcast = false;
187 break; 195 break;
188 case GW_MODE_OFF: 196 case BATADV_GW_MODE_OFF:
189 default: 197 default:
190 break; 198 break;
191 } 199 }
@@ -193,22 +201,24 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
193 201
194 /* ethernet packet should be broadcasted */ 202 /* ethernet packet should be broadcasted */
195 if (do_bcast) { 203 if (do_bcast) {
196 primary_if = primary_if_get_selected(bat_priv); 204 primary_if = batadv_primary_if_get_selected(bat_priv);
197 if (!primary_if) 205 if (!primary_if)
198 goto dropped; 206 goto dropped;
199 207
200 if (my_skb_head_push(skb, sizeof(*bcast_packet)) < 0) 208 if (batadv_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
201 goto dropped; 209 goto dropped;
202 210
203 bcast_packet = (struct bcast_packet *)skb->data; 211 bcast_packet = (struct batadv_bcast_packet *)skb->data;
204 bcast_packet->header.version = COMPAT_VERSION; 212 bcast_packet->header.version = BATADV_COMPAT_VERSION;
205 bcast_packet->header.ttl = TTL; 213 bcast_packet->header.ttl = BATADV_TTL;
206 214
207 /* batman packet type: broadcast */ 215 /* batman packet type: broadcast */
208 bcast_packet->header.packet_type = BAT_BCAST; 216 bcast_packet->header.packet_type = BATADV_BCAST;
217 bcast_packet->reserved = 0;
209 218
210 /* hw address of first interface is the orig mac because only 219 /* hw address of first interface is the orig mac because only
211 * this mac is known throughout the mesh */ 220 * this mac is known throughout the mesh
221 */
212 memcpy(bcast_packet->orig, 222 memcpy(bcast_packet->orig,
213 primary_if->net_dev->dev_addr, ETH_ALEN); 223 primary_if->net_dev->dev_addr, ETH_ALEN);
214 224
@@ -216,21 +226,22 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
216 bcast_packet->seqno = 226 bcast_packet->seqno =
217 htonl(atomic_inc_return(&bat_priv->bcast_seqno)); 227 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
218 228
219 add_bcast_packet_to_list(bat_priv, skb, 1); 229 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
220 230
221 /* a copy is stored in the bcast list, therefore removing 231 /* a copy is stored in the bcast list, therefore removing
222 * the original skb. */ 232 * the original skb.
233 */
223 kfree_skb(skb); 234 kfree_skb(skb);
224 235
225 /* unicast packet */ 236 /* unicast packet */
226 } else { 237 } else {
227 if (atomic_read(&bat_priv->gw_mode) != GW_MODE_OFF) { 238 if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_OFF) {
228 ret = gw_out_of_range(bat_priv, skb, ethhdr); 239 ret = batadv_gw_out_of_range(bat_priv, skb, ethhdr);
229 if (ret) 240 if (ret)
230 goto dropped; 241 goto dropped;
231 } 242 }
232 243
233 ret = unicast_send_skb(skb, bat_priv); 244 ret = batadv_unicast_send_skb(skb, bat_priv);
234 if (ret != 0) 245 if (ret != 0)
235 goto dropped_freed; 246 goto dropped_freed;
236 } 247 }
@@ -245,22 +256,23 @@ dropped_freed:
245 bat_priv->stats.tx_dropped++; 256 bat_priv->stats.tx_dropped++;
246end: 257end:
247 if (primary_if) 258 if (primary_if)
248 hardif_free_ref(primary_if); 259 batadv_hardif_free_ref(primary_if);
249 return NETDEV_TX_OK; 260 return NETDEV_TX_OK;
250} 261}
251 262
252void interface_rx(struct net_device *soft_iface, 263void batadv_interface_rx(struct net_device *soft_iface,
253 struct sk_buff *skb, struct hard_iface *recv_if, 264 struct sk_buff *skb, struct batadv_hard_iface *recv_if,
254 int hdr_size) 265 int hdr_size)
255{ 266{
256 struct bat_priv *bat_priv = netdev_priv(soft_iface); 267 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
257 struct ethhdr *ethhdr; 268 struct ethhdr *ethhdr;
258 struct vlan_ethhdr *vhdr; 269 struct vlan_ethhdr *vhdr;
259 struct batman_header *batadv_header = (struct batman_header *)skb->data; 270 struct batadv_header *batadv_header = (struct batadv_header *)skb->data;
260 short vid __maybe_unused = -1; 271 short vid __maybe_unused = -1;
272 __be16 ethertype = __constant_htons(BATADV_ETH_P_BATMAN);
261 bool is_bcast; 273 bool is_bcast;
262 274
263 is_bcast = (batadv_header->packet_type == BAT_BCAST); 275 is_bcast = (batadv_header->packet_type == BATADV_BCAST);
264 276
265 /* check if enough space is available for pulling, and pull */ 277 /* check if enough space is available for pulling, and pull */
266 if (!pskb_may_pull(skb, hdr_size)) 278 if (!pskb_may_pull(skb, hdr_size))
@@ -276,11 +288,11 @@ void interface_rx(struct net_device *soft_iface,
276 vhdr = (struct vlan_ethhdr *)skb->data; 288 vhdr = (struct vlan_ethhdr *)skb->data;
277 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; 289 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
278 290
279 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN) 291 if (vhdr->h_vlan_encapsulated_proto != ethertype)
280 break; 292 break;
281 293
282 /* fall through */ 294 /* fall through */
283 case ETH_P_BATMAN: 295 case BATADV_ETH_P_BATMAN:
284 goto dropped; 296 goto dropped;
285 } 297 }
286 298
@@ -291,22 +303,23 @@ void interface_rx(struct net_device *soft_iface,
291 303
292 /* should not be necessary anymore as we use skb_pull_rcsum() 304 /* should not be necessary anymore as we use skb_pull_rcsum()
293 * TODO: please verify this and remove this TODO 305 * TODO: please verify this and remove this TODO
294 * -- Dec 21st 2009, Simon Wunderlich */ 306 * -- Dec 21st 2009, Simon Wunderlich
307 */
295 308
296/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/ 309 /* skb->ip_summed = CHECKSUM_UNNECESSARY; */
297 310
298 bat_priv->stats.rx_packets++; 311 bat_priv->stats.rx_packets++;
299 bat_priv->stats.rx_bytes += skb->len + ETH_HLEN; 312 bat_priv->stats.rx_bytes += skb->len + ETH_HLEN;
300 313
301 soft_iface->last_rx = jiffies; 314 soft_iface->last_rx = jiffies;
302 315
303 if (is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest)) 316 if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest))
304 goto dropped; 317 goto dropped;
305 318
306 /* Let the bridge loop avoidance check the packet. If will 319 /* Let the bridge loop avoidance check the packet. If will
307 * not handle it, we can safely push it up. 320 * not handle it, we can safely push it up.
308 */ 321 */
309 if (bla_rx(bat_priv, skb, vid, is_bcast)) 322 if (batadv_bla_rx(bat_priv, skb, vid, is_bcast))
310 goto out; 323 goto out;
311 324
312 netif_rx(skb); 325 netif_rx(skb);
@@ -318,49 +331,50 @@ out:
318 return; 331 return;
319} 332}
320 333
321static const struct net_device_ops bat_netdev_ops = { 334static const struct net_device_ops batadv_netdev_ops = {
322 .ndo_open = interface_open, 335 .ndo_open = batadv_interface_open,
323 .ndo_stop = interface_release, 336 .ndo_stop = batadv_interface_release,
324 .ndo_get_stats = interface_stats, 337 .ndo_get_stats = batadv_interface_stats,
325 .ndo_set_mac_address = interface_set_mac_addr, 338 .ndo_set_mac_address = batadv_interface_set_mac_addr,
326 .ndo_change_mtu = interface_change_mtu, 339 .ndo_change_mtu = batadv_interface_change_mtu,
327 .ndo_start_xmit = interface_tx, 340 .ndo_start_xmit = batadv_interface_tx,
328 .ndo_validate_addr = eth_validate_addr 341 .ndo_validate_addr = eth_validate_addr
329}; 342};
330 343
331static void interface_setup(struct net_device *dev) 344static void batadv_interface_setup(struct net_device *dev)
332{ 345{
333 struct bat_priv *priv = netdev_priv(dev); 346 struct batadv_priv *priv = netdev_priv(dev);
334 347
335 ether_setup(dev); 348 ether_setup(dev);
336 349
337 dev->netdev_ops = &bat_netdev_ops; 350 dev->netdev_ops = &batadv_netdev_ops;
338 dev->destructor = free_netdev; 351 dev->destructor = free_netdev;
339 dev->tx_queue_len = 0; 352 dev->tx_queue_len = 0;
340 353
341 /** 354 /* can't call min_mtu, because the needed variables
342 * can't call min_mtu, because the needed variables
343 * have not been initialized yet 355 * have not been initialized yet
344 */ 356 */
345 dev->mtu = ETH_DATA_LEN; 357 dev->mtu = ETH_DATA_LEN;
346 /* reserve more space in the skbuff for our header */ 358 /* reserve more space in the skbuff for our header */
347 dev->hard_header_len = BAT_HEADER_LEN; 359 dev->hard_header_len = BATADV_HEADER_LEN;
348 360
349 /* generate random address */ 361 /* generate random address */
350 eth_hw_addr_random(dev); 362 eth_hw_addr_random(dev);
351 363
352 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops); 364 SET_ETHTOOL_OPS(dev, &batadv_ethtool_ops);
353 365
354 memset(priv, 0, sizeof(*priv)); 366 memset(priv, 0, sizeof(*priv));
355} 367}
356 368
357struct net_device *softif_create(const char *name) 369struct net_device *batadv_softif_create(const char *name)
358{ 370{
359 struct net_device *soft_iface; 371 struct net_device *soft_iface;
360 struct bat_priv *bat_priv; 372 struct batadv_priv *bat_priv;
361 int ret; 373 int ret;
374 size_t cnt_len = sizeof(uint64_t) * BATADV_CNT_NUM;
362 375
363 soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup); 376 soft_iface = alloc_netdev(sizeof(*bat_priv), name,
377 batadv_interface_setup);
364 378
365 if (!soft_iface) 379 if (!soft_iface)
366 goto out; 380 goto out;
@@ -378,18 +392,18 @@ struct net_device *softif_create(const char *name)
378 atomic_set(&bat_priv->bonding, 0); 392 atomic_set(&bat_priv->bonding, 0);
379 atomic_set(&bat_priv->bridge_loop_avoidance, 0); 393 atomic_set(&bat_priv->bridge_loop_avoidance, 0);
380 atomic_set(&bat_priv->ap_isolation, 0); 394 atomic_set(&bat_priv->ap_isolation, 0);
381 atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE); 395 atomic_set(&bat_priv->vis_mode, BATADV_VIS_TYPE_CLIENT_UPDATE);
382 atomic_set(&bat_priv->gw_mode, GW_MODE_OFF); 396 atomic_set(&bat_priv->gw_mode, BATADV_GW_MODE_OFF);
383 atomic_set(&bat_priv->gw_sel_class, 20); 397 atomic_set(&bat_priv->gw_sel_class, 20);
384 atomic_set(&bat_priv->gw_bandwidth, 41); 398 atomic_set(&bat_priv->gw_bandwidth, 41);
385 atomic_set(&bat_priv->orig_interval, 1000); 399 atomic_set(&bat_priv->orig_interval, 1000);
386 atomic_set(&bat_priv->hop_penalty, 30); 400 atomic_set(&bat_priv->hop_penalty, 30);
387 atomic_set(&bat_priv->log_level, 0); 401 atomic_set(&bat_priv->log_level, 0);
388 atomic_set(&bat_priv->fragmentation, 1); 402 atomic_set(&bat_priv->fragmentation, 1);
389 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN); 403 atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
390 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN); 404 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
391 405
392 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); 406 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
393 atomic_set(&bat_priv->bcast_seqno, 1); 407 atomic_set(&bat_priv->bcast_seqno, 1);
394 atomic_set(&bat_priv->ttvn, 0); 408 atomic_set(&bat_priv->ttvn, 0);
395 atomic_set(&bat_priv->tt_local_changes, 0); 409 atomic_set(&bat_priv->tt_local_changes, 0);
@@ -403,28 +417,34 @@ struct net_device *softif_create(const char *name)
403 bat_priv->primary_if = NULL; 417 bat_priv->primary_if = NULL;
404 bat_priv->num_ifaces = 0; 418 bat_priv->num_ifaces = 0;
405 419
406 ret = bat_algo_select(bat_priv, bat_routing_algo); 420 bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(uint64_t));
407 if (ret < 0) 421 if (!bat_priv->bat_counters)
408 goto unreg_soft_iface; 422 goto unreg_soft_iface;
409 423
410 ret = sysfs_add_meshif(soft_iface); 424 ret = batadv_algo_select(bat_priv, batadv_routing_algo);
411 if (ret < 0) 425 if (ret < 0)
412 goto unreg_soft_iface; 426 goto free_bat_counters;
413 427
414 ret = debugfs_add_meshif(soft_iface); 428 ret = batadv_sysfs_add_meshif(soft_iface);
429 if (ret < 0)
430 goto free_bat_counters;
431
432 ret = batadv_debugfs_add_meshif(soft_iface);
415 if (ret < 0) 433 if (ret < 0)
416 goto unreg_sysfs; 434 goto unreg_sysfs;
417 435
418 ret = mesh_init(soft_iface); 436 ret = batadv_mesh_init(soft_iface);
419 if (ret < 0) 437 if (ret < 0)
420 goto unreg_debugfs; 438 goto unreg_debugfs;
421 439
422 return soft_iface; 440 return soft_iface;
423 441
424unreg_debugfs: 442unreg_debugfs:
425 debugfs_del_meshif(soft_iface); 443 batadv_debugfs_del_meshif(soft_iface);
426unreg_sysfs: 444unreg_sysfs:
427 sysfs_del_meshif(soft_iface); 445 batadv_sysfs_del_meshif(soft_iface);
446free_bat_counters:
447 free_percpu(bat_priv->bat_counters);
428unreg_soft_iface: 448unreg_soft_iface:
429 unregister_netdevice(soft_iface); 449 unregister_netdevice(soft_iface);
430 return NULL; 450 return NULL;
@@ -435,24 +455,24 @@ out:
435 return NULL; 455 return NULL;
436} 456}
437 457
438void softif_destroy(struct net_device *soft_iface) 458void batadv_softif_destroy(struct net_device *soft_iface)
439{ 459{
440 debugfs_del_meshif(soft_iface); 460 batadv_debugfs_del_meshif(soft_iface);
441 sysfs_del_meshif(soft_iface); 461 batadv_sysfs_del_meshif(soft_iface);
442 mesh_free(soft_iface); 462 batadv_mesh_free(soft_iface);
443 unregister_netdevice(soft_iface); 463 unregister_netdevice(soft_iface);
444} 464}
445 465
446int softif_is_valid(const struct net_device *net_dev) 466int batadv_softif_is_valid(const struct net_device *net_dev)
447{ 467{
448 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx) 468 if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx)
449 return 1; 469 return 1;
450 470
451 return 0; 471 return 0;
452} 472}
453 473
454/* ethtool */ 474/* ethtool */
455static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 475static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
456{ 476{
457 cmd->supported = 0; 477 cmd->supported = 0;
458 cmd->advertising = 0; 478 cmd->advertising = 0;
@@ -468,25 +488,73 @@ static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
468 return 0; 488 return 0;
469} 489}
470 490
471static void bat_get_drvinfo(struct net_device *dev, 491static void batadv_get_drvinfo(struct net_device *dev,
472 struct ethtool_drvinfo *info) 492 struct ethtool_drvinfo *info)
473{ 493{
474 strcpy(info->driver, "B.A.T.M.A.N. advanced"); 494 strcpy(info->driver, "B.A.T.M.A.N. advanced");
475 strcpy(info->version, SOURCE_VERSION); 495 strcpy(info->version, BATADV_SOURCE_VERSION);
476 strcpy(info->fw_version, "N/A"); 496 strcpy(info->fw_version, "N/A");
477 strcpy(info->bus_info, "batman"); 497 strcpy(info->bus_info, "batman");
478} 498}
479 499
480static u32 bat_get_msglevel(struct net_device *dev) 500static u32 batadv_get_msglevel(struct net_device *dev)
481{ 501{
482 return -EOPNOTSUPP; 502 return -EOPNOTSUPP;
483} 503}
484 504
485static void bat_set_msglevel(struct net_device *dev, u32 value) 505static void batadv_set_msglevel(struct net_device *dev, u32 value)
486{ 506{
487} 507}
488 508
489static u32 bat_get_link(struct net_device *dev) 509static u32 batadv_get_link(struct net_device *dev)
490{ 510{
491 return 1; 511 return 1;
492} 512}
513
514/* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
515 * Declare each description string in struct.name[] to get fixed sized buffer
516 * and compile time checking for strings longer than ETH_GSTRING_LEN.
517 */
518static const struct {
519 const char name[ETH_GSTRING_LEN];
520} batadv_counters_strings[] = {
521 { "forward" },
522 { "forward_bytes" },
523 { "mgmt_tx" },
524 { "mgmt_tx_bytes" },
525 { "mgmt_rx" },
526 { "mgmt_rx_bytes" },
527 { "tt_request_tx" },
528 { "tt_request_rx" },
529 { "tt_response_tx" },
530 { "tt_response_rx" },
531 { "tt_roam_adv_tx" },
532 { "tt_roam_adv_rx" },
533};
534
535static void batadv_get_strings(struct net_device *dev, uint32_t stringset,
536 uint8_t *data)
537{
538 if (stringset == ETH_SS_STATS)
539 memcpy(data, batadv_counters_strings,
540 sizeof(batadv_counters_strings));
541}
542
543static void batadv_get_ethtool_stats(struct net_device *dev,
544 struct ethtool_stats *stats,
545 uint64_t *data)
546{
547 struct batadv_priv *bat_priv = netdev_priv(dev);
548 int i;
549
550 for (i = 0; i < BATADV_CNT_NUM; i++)
551 data[i] = batadv_sum_counter(bat_priv, i);
552}
553
554static int batadv_get_sset_count(struct net_device *dev, int stringset)
555{
556 if (stringset == ETH_SS_STATS)
557 return BATADV_CNT_NUM;
558
559 return -EOPNOTSUPP;
560}