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.c257
1 files changed, 162 insertions, 95 deletions
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 6e2530b02043..c1b2ab2f37bb 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"
@@ -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,25 +78,25 @@ 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 bat_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 bat_priv *bat_priv = netdev_priv(dev);
98 struct sockaddr *addr = p; 102 struct sockaddr *addr = p;
@@ -102,9 +106,9 @@ static int interface_set_mac_addr(struct net_device *dev, void *p)
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) == 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 bat_priv *bat_priv = netdev_priv(soft_iface);
130 struct hard_iface *primary_if = NULL; 135 struct hard_iface *primary_if = NULL;
131 struct bcast_packet *bcast_packet; 136 struct 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;
@@ -147,24 +153,24 @@ 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)) {
@@ -173,15 +179,17 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
173 switch (atomic_read(&bat_priv->gw_mode)) { 179 switch (atomic_read(&bat_priv->gw_mode)) {
174 case GW_MODE_SERVER: 180 case 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 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;
@@ -193,22 +201,23 @@ 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 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 = BAT_BCAST;
209 217
210 /* hw address of first interface is the orig mac because only 218 /* hw address of first interface is the orig mac because only
211 * this mac is known throughout the mesh */ 219 * this mac is known throughout the mesh
220 */
212 memcpy(bcast_packet->orig, 221 memcpy(bcast_packet->orig,
213 primary_if->net_dev->dev_addr, ETH_ALEN); 222 primary_if->net_dev->dev_addr, ETH_ALEN);
214 223
@@ -216,21 +225,22 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
216 bcast_packet->seqno = 225 bcast_packet->seqno =
217 htonl(atomic_inc_return(&bat_priv->bcast_seqno)); 226 htonl(atomic_inc_return(&bat_priv->bcast_seqno));
218 227
219 add_bcast_packet_to_list(bat_priv, skb, 1); 228 batadv_add_bcast_packet_to_list(bat_priv, skb, 1);
220 229
221 /* a copy is stored in the bcast list, therefore removing 230 /* a copy is stored in the bcast list, therefore removing
222 * the original skb. */ 231 * the original skb.
232 */
223 kfree_skb(skb); 233 kfree_skb(skb);
224 234
225 /* unicast packet */ 235 /* unicast packet */
226 } else { 236 } else {
227 if (atomic_read(&bat_priv->gw_mode) != GW_MODE_OFF) { 237 if (atomic_read(&bat_priv->gw_mode) != GW_MODE_OFF) {
228 ret = gw_out_of_range(bat_priv, skb, ethhdr); 238 ret = batadv_gw_out_of_range(bat_priv, skb, ethhdr);
229 if (ret) 239 if (ret)
230 goto dropped; 240 goto dropped;
231 } 241 }
232 242
233 ret = unicast_send_skb(skb, bat_priv); 243 ret = batadv_unicast_send_skb(skb, bat_priv);
234 if (ret != 0) 244 if (ret != 0)
235 goto dropped_freed; 245 goto dropped_freed;
236 } 246 }
@@ -245,18 +255,19 @@ dropped_freed:
245 bat_priv->stats.tx_dropped++; 255 bat_priv->stats.tx_dropped++;
246end: 256end:
247 if (primary_if) 257 if (primary_if)
248 hardif_free_ref(primary_if); 258 batadv_hardif_free_ref(primary_if);
249 return NETDEV_TX_OK; 259 return NETDEV_TX_OK;
250} 260}
251 261
252void interface_rx(struct net_device *soft_iface, 262void batadv_interface_rx(struct net_device *soft_iface,
253 struct sk_buff *skb, struct hard_iface *recv_if, 263 struct sk_buff *skb, struct hard_iface *recv_if,
254 int hdr_size) 264 int hdr_size)
255{ 265{
256 struct bat_priv *bat_priv = netdev_priv(soft_iface); 266 struct bat_priv *bat_priv = netdev_priv(soft_iface);
257 struct ethhdr *ethhdr; 267 struct ethhdr *ethhdr;
258 struct vlan_ethhdr *vhdr; 268 struct vlan_ethhdr *vhdr;
259 short vid __maybe_unused = -1; 269 short vid __maybe_unused = -1;
270 __be16 ethertype = __constant_htons(BATADV_ETH_P_BATMAN);
260 271
261 /* check if enough space is available for pulling, and pull */ 272 /* check if enough space is available for pulling, and pull */
262 if (!pskb_may_pull(skb, hdr_size)) 273 if (!pskb_may_pull(skb, hdr_size))
@@ -272,11 +283,11 @@ void interface_rx(struct net_device *soft_iface,
272 vhdr = (struct vlan_ethhdr *)skb->data; 283 vhdr = (struct vlan_ethhdr *)skb->data;
273 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; 284 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
274 285
275 if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN) 286 if (vhdr->h_vlan_encapsulated_proto != ethertype)
276 break; 287 break;
277 288
278 /* fall through */ 289 /* fall through */
279 case ETH_P_BATMAN: 290 case BATADV_ETH_P_BATMAN:
280 goto dropped; 291 goto dropped;
281 } 292 }
282 293
@@ -287,22 +298,23 @@ void interface_rx(struct net_device *soft_iface,
287 298
288 /* should not be necessary anymore as we use skb_pull_rcsum() 299 /* should not be necessary anymore as we use skb_pull_rcsum()
289 * TODO: please verify this and remove this TODO 300 * TODO: please verify this and remove this TODO
290 * -- Dec 21st 2009, Simon Wunderlich */ 301 * -- Dec 21st 2009, Simon Wunderlich
302 */
291 303
292/* skb->ip_summed = CHECKSUM_UNNECESSARY;*/ 304 /* skb->ip_summed = CHECKSUM_UNNECESSARY; */
293 305
294 bat_priv->stats.rx_packets++; 306 bat_priv->stats.rx_packets++;
295 bat_priv->stats.rx_bytes += skb->len + ETH_HLEN; 307 bat_priv->stats.rx_bytes += skb->len + ETH_HLEN;
296 308
297 soft_iface->last_rx = jiffies; 309 soft_iface->last_rx = jiffies;
298 310
299 if (is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest)) 311 if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest))
300 goto dropped; 312 goto dropped;
301 313
302 /* Let the bridge loop avoidance check the packet. If will 314 /* Let the bridge loop avoidance check the packet. If will
303 * not handle it, we can safely push it up. 315 * not handle it, we can safely push it up.
304 */ 316 */
305 if (bla_rx(bat_priv, skb, vid)) 317 if (batadv_bla_rx(bat_priv, skb, vid))
306 goto out; 318 goto out;
307 319
308 netif_rx(skb); 320 netif_rx(skb);
@@ -314,49 +326,49 @@ out:
314 return; 326 return;
315} 327}
316 328
317static const struct net_device_ops bat_netdev_ops = { 329static const struct net_device_ops batadv_netdev_ops = {
318 .ndo_open = interface_open, 330 .ndo_open = batadv_interface_open,
319 .ndo_stop = interface_release, 331 .ndo_stop = batadv_interface_release,
320 .ndo_get_stats = interface_stats, 332 .ndo_get_stats = batadv_interface_stats,
321 .ndo_set_mac_address = interface_set_mac_addr, 333 .ndo_set_mac_address = batadv_interface_set_mac_addr,
322 .ndo_change_mtu = interface_change_mtu, 334 .ndo_change_mtu = batadv_interface_change_mtu,
323 .ndo_start_xmit = interface_tx, 335 .ndo_start_xmit = batadv_interface_tx,
324 .ndo_validate_addr = eth_validate_addr 336 .ndo_validate_addr = eth_validate_addr
325}; 337};
326 338
327static void interface_setup(struct net_device *dev) 339static void batadv_interface_setup(struct net_device *dev)
328{ 340{
329 struct bat_priv *priv = netdev_priv(dev); 341 struct bat_priv *priv = netdev_priv(dev);
330 342
331 ether_setup(dev); 343 ether_setup(dev);
332 344
333 dev->netdev_ops = &bat_netdev_ops; 345 dev->netdev_ops = &batadv_netdev_ops;
334 dev->destructor = free_netdev; 346 dev->destructor = free_netdev;
335 dev->tx_queue_len = 0; 347 dev->tx_queue_len = 0;
336 348
337 /** 349 /* can't call min_mtu, because the needed variables
338 * can't call min_mtu, because the needed variables
339 * have not been initialized yet 350 * have not been initialized yet
340 */ 351 */
341 dev->mtu = ETH_DATA_LEN; 352 dev->mtu = ETH_DATA_LEN;
342 /* reserve more space in the skbuff for our header */ 353 /* reserve more space in the skbuff for our header */
343 dev->hard_header_len = BAT_HEADER_LEN; 354 dev->hard_header_len = BATADV_HEADER_LEN;
344 355
345 /* generate random address */ 356 /* generate random address */
346 eth_hw_addr_random(dev); 357 eth_hw_addr_random(dev);
347 358
348 SET_ETHTOOL_OPS(dev, &bat_ethtool_ops); 359 SET_ETHTOOL_OPS(dev, &batadv_ethtool_ops);
349 360
350 memset(priv, 0, sizeof(*priv)); 361 memset(priv, 0, sizeof(*priv));
351} 362}
352 363
353struct net_device *softif_create(const char *name) 364struct net_device *batadv_softif_create(const char *name)
354{ 365{
355 struct net_device *soft_iface; 366 struct net_device *soft_iface;
356 struct bat_priv *bat_priv; 367 struct bat_priv *bat_priv;
357 int ret; 368 int ret;
358 369
359 soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup); 370 soft_iface = alloc_netdev(sizeof(*bat_priv), name,
371 batadv_interface_setup);
360 372
361 if (!soft_iface) 373 if (!soft_iface)
362 goto out; 374 goto out;
@@ -382,8 +394,8 @@ struct net_device *softif_create(const char *name)
382 atomic_set(&bat_priv->hop_penalty, 30); 394 atomic_set(&bat_priv->hop_penalty, 30);
383 atomic_set(&bat_priv->log_level, 0); 395 atomic_set(&bat_priv->log_level, 0);
384 atomic_set(&bat_priv->fragmentation, 1); 396 atomic_set(&bat_priv->fragmentation, 1);
385 atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN); 397 atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
386 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN); 398 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
387 399
388 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); 400 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
389 atomic_set(&bat_priv->bcast_seqno, 1); 401 atomic_set(&bat_priv->bcast_seqno, 1);
@@ -399,28 +411,35 @@ struct net_device *softif_create(const char *name)
399 bat_priv->primary_if = NULL; 411 bat_priv->primary_if = NULL;
400 bat_priv->num_ifaces = 0; 412 bat_priv->num_ifaces = 0;
401 413
402 ret = bat_algo_select(bat_priv, bat_routing_algo); 414 bat_priv->bat_counters = __alloc_percpu(sizeof(uint64_t) * BAT_CNT_NUM,
403 if (ret < 0) 415 __alignof__(uint64_t));
416 if (!bat_priv->bat_counters)
404 goto unreg_soft_iface; 417 goto unreg_soft_iface;
405 418
406 ret = sysfs_add_meshif(soft_iface); 419 ret = batadv_algo_select(bat_priv, batadv_routing_algo);
407 if (ret < 0) 420 if (ret < 0)
408 goto unreg_soft_iface; 421 goto free_bat_counters;
422
423 ret = batadv_sysfs_add_meshif(soft_iface);
424 if (ret < 0)
425 goto free_bat_counters;
409 426
410 ret = debugfs_add_meshif(soft_iface); 427 ret = batadv_debugfs_add_meshif(soft_iface);
411 if (ret < 0) 428 if (ret < 0)
412 goto unreg_sysfs; 429 goto unreg_sysfs;
413 430
414 ret = mesh_init(soft_iface); 431 ret = batadv_mesh_init(soft_iface);
415 if (ret < 0) 432 if (ret < 0)
416 goto unreg_debugfs; 433 goto unreg_debugfs;
417 434
418 return soft_iface; 435 return soft_iface;
419 436
420unreg_debugfs: 437unreg_debugfs:
421 debugfs_del_meshif(soft_iface); 438 batadv_debugfs_del_meshif(soft_iface);
422unreg_sysfs: 439unreg_sysfs:
423 sysfs_del_meshif(soft_iface); 440 batadv_sysfs_del_meshif(soft_iface);
441free_bat_counters:
442 free_percpu(bat_priv->bat_counters);
424unreg_soft_iface: 443unreg_soft_iface:
425 unregister_netdevice(soft_iface); 444 unregister_netdevice(soft_iface);
426 return NULL; 445 return NULL;
@@ -431,24 +450,24 @@ out:
431 return NULL; 450 return NULL;
432} 451}
433 452
434void softif_destroy(struct net_device *soft_iface) 453void batadv_softif_destroy(struct net_device *soft_iface)
435{ 454{
436 debugfs_del_meshif(soft_iface); 455 batadv_debugfs_del_meshif(soft_iface);
437 sysfs_del_meshif(soft_iface); 456 batadv_sysfs_del_meshif(soft_iface);
438 mesh_free(soft_iface); 457 batadv_mesh_free(soft_iface);
439 unregister_netdevice(soft_iface); 458 unregister_netdevice(soft_iface);
440} 459}
441 460
442int softif_is_valid(const struct net_device *net_dev) 461int batadv_softif_is_valid(const struct net_device *net_dev)
443{ 462{
444 if (net_dev->netdev_ops->ndo_start_xmit == interface_tx) 463 if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx)
445 return 1; 464 return 1;
446 465
447 return 0; 466 return 0;
448} 467}
449 468
450/* ethtool */ 469/* ethtool */
451static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) 470static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
452{ 471{
453 cmd->supported = 0; 472 cmd->supported = 0;
454 cmd->advertising = 0; 473 cmd->advertising = 0;
@@ -464,25 +483,73 @@ static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
464 return 0; 483 return 0;
465} 484}
466 485
467static void bat_get_drvinfo(struct net_device *dev, 486static void batadv_get_drvinfo(struct net_device *dev,
468 struct ethtool_drvinfo *info) 487 struct ethtool_drvinfo *info)
469{ 488{
470 strcpy(info->driver, "B.A.T.M.A.N. advanced"); 489 strcpy(info->driver, "B.A.T.M.A.N. advanced");
471 strcpy(info->version, SOURCE_VERSION); 490 strcpy(info->version, BATADV_SOURCE_VERSION);
472 strcpy(info->fw_version, "N/A"); 491 strcpy(info->fw_version, "N/A");
473 strcpy(info->bus_info, "batman"); 492 strcpy(info->bus_info, "batman");
474} 493}
475 494
476static u32 bat_get_msglevel(struct net_device *dev) 495static u32 batadv_get_msglevel(struct net_device *dev)
477{ 496{
478 return -EOPNOTSUPP; 497 return -EOPNOTSUPP;
479} 498}
480 499
481static void bat_set_msglevel(struct net_device *dev, u32 value) 500static void batadv_set_msglevel(struct net_device *dev, u32 value)
482{ 501{
483} 502}
484 503
485static u32 bat_get_link(struct net_device *dev) 504static u32 batadv_get_link(struct net_device *dev)
486{ 505{
487 return 1; 506 return 1;
488} 507}
508
509/* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
510 * Declare each description string in struct.name[] to get fixed sized buffer
511 * and compile time checking for strings longer than ETH_GSTRING_LEN.
512 */
513static const struct {
514 const char name[ETH_GSTRING_LEN];
515} batadv_counters_strings[] = {
516 { "forward" },
517 { "forward_bytes" },
518 { "mgmt_tx" },
519 { "mgmt_tx_bytes" },
520 { "mgmt_rx" },
521 { "mgmt_rx_bytes" },
522 { "tt_request_tx" },
523 { "tt_request_rx" },
524 { "tt_response_tx" },
525 { "tt_response_rx" },
526 { "tt_roam_adv_tx" },
527 { "tt_roam_adv_rx" },
528};
529
530static void batadv_get_strings(struct net_device *dev, uint32_t stringset,
531 uint8_t *data)
532{
533 if (stringset == ETH_SS_STATS)
534 memcpy(data, batadv_counters_strings,
535 sizeof(batadv_counters_strings));
536}
537
538static void batadv_get_ethtool_stats(struct net_device *dev,
539 struct ethtool_stats *stats,
540 uint64_t *data)
541{
542 struct bat_priv *bat_priv = netdev_priv(dev);
543 int i;
544
545 for (i = 0; i < BAT_CNT_NUM; i++)
546 data[i] = batadv_sum_counter(bat_priv, i);
547}
548
549static int batadv_get_sset_count(struct net_device *dev, int stringset)
550{
551 if (stringset == ETH_SS_STATS)
552 return BAT_CNT_NUM;
553
554 return -EOPNOTSUPP;
555}