batman-adv: remove unused variable from orig_node struct
[deliverable/linux.git] / net / batman-adv / soft-interface.c
CommitLineData
9cfc7bd6 1/* Copyright (C) 2007-2012 B.A.T.M.A.N. contributors:
c6c8fea2
SE
2 *
3 * Marek Lindner, Simon Wunderlich
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
c6c8fea2
SE
18 */
19
20#include "main.h"
21#include "soft-interface.h"
22#include "hard-interface.h"
c384ea3e 23#include "distributed-arp-table.h"
c6c8fea2
SE
24#include "routing.h"
25#include "send.h"
b706b13b 26#include "debugfs.h"
c6c8fea2 27#include "translation-table.h"
c6c8fea2
SE
28#include "hash.h"
29#include "gateway_common.h"
30#include "gateway_client.h"
b706b13b 31#include "sysfs.h"
43676ab5 32#include "originator.h"
c6c8fea2
SE
33#include <linux/slab.h>
34#include <linux/ethtool.h>
35#include <linux/etherdevice.h>
36#include <linux/if_vlan.h>
af5d4f77 37#include <linux/if_ether.h>
c6c8fea2 38#include "unicast.h"
23721387 39#include "bridge_loop_avoidance.h"
c6c8fea2
SE
40
41
0294ca0d
SE
42static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd);
43static void batadv_get_drvinfo(struct net_device *dev,
44 struct ethtool_drvinfo *info);
45static u32 batadv_get_msglevel(struct net_device *dev);
46static void batadv_set_msglevel(struct net_device *dev, u32 value);
47static u32 batadv_get_link(struct net_device *dev);
f8214865
MH
48static void batadv_get_strings(struct net_device *dev, u32 stringset, u8 *data);
49static void batadv_get_ethtool_stats(struct net_device *dev,
50 struct ethtool_stats *stats, u64 *data);
51static int batadv_get_sset_count(struct net_device *dev, int stringset);
c6c8fea2 52
0294ca0d
SE
53static const struct ethtool_ops batadv_ethtool_ops = {
54 .get_settings = batadv_get_settings,
55 .get_drvinfo = batadv_get_drvinfo,
56 .get_msglevel = batadv_get_msglevel,
57 .set_msglevel = batadv_set_msglevel,
58 .get_link = batadv_get_link,
f8214865
MH
59 .get_strings = batadv_get_strings,
60 .get_ethtool_stats = batadv_get_ethtool_stats,
61 .get_sset_count = batadv_get_sset_count,
c6c8fea2
SE
62};
63
04b482a2 64int batadv_skb_head_push(struct sk_buff *skb, unsigned int len)
c6c8fea2
SE
65{
66 int result;
67
9cfc7bd6 68 /* TODO: We must check if we can release all references to non-payload
c6c8fea2
SE
69 * data using skb_header_release in our skbs to allow skb_cow_header to
70 * work optimally. This means that those skbs are not allowed to read
71 * or write any data which is before the current position of skb->data
72 * after that call and thus allow other skbs with the same data buffer
73 * to write freely in that area.
74 */
75 result = skb_cow_head(skb, len);
76 if (result < 0)
77 return result;
78
79 skb_push(skb, len);
80 return 0;
81}
82
0294ca0d 83static int batadv_interface_open(struct net_device *dev)
c6c8fea2
SE
84{
85 netif_start_queue(dev);
86 return 0;
87}
88
0294ca0d 89static int batadv_interface_release(struct net_device *dev)
c6c8fea2
SE
90{
91 netif_stop_queue(dev);
92 return 0;
93}
94
0294ca0d 95static struct net_device_stats *batadv_interface_stats(struct net_device *dev)
c6c8fea2 96{
56303d34 97 struct batadv_priv *bat_priv = netdev_priv(dev);
1c9b0550
ML
98 struct net_device_stats *stats = &bat_priv->stats;
99
100 stats->tx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_TX);
101 stats->tx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_TX_BYTES);
102 stats->tx_dropped = batadv_sum_counter(bat_priv, BATADV_CNT_TX_DROPPED);
103 stats->rx_packets = batadv_sum_counter(bat_priv, BATADV_CNT_RX);
104 stats->rx_bytes = batadv_sum_counter(bat_priv, BATADV_CNT_RX_BYTES);
105 return stats;
c6c8fea2
SE
106}
107
0294ca0d 108static int batadv_interface_set_mac_addr(struct net_device *dev, void *p)
c6c8fea2 109{
56303d34 110 struct batadv_priv *bat_priv = netdev_priv(dev);
c6c8fea2 111 struct sockaddr *addr = p;
40a3eb33 112 uint8_t old_addr[ETH_ALEN];
c6c8fea2
SE
113
114 if (!is_valid_ether_addr(addr->sa_data))
115 return -EADDRNOTAVAIL;
116
40a3eb33
D
117 memcpy(old_addr, dev->dev_addr, ETH_ALEN);
118 memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN);
119
015758d0 120 /* only modify transtable if it has been initialized before */
39c75a51 121 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE) {
40a3eb33 122 batadv_tt_local_remove(bat_priv, old_addr,
08c36d3e 123 "mac address changed", false);
42d0b044 124 batadv_tt_local_add(dev, addr->sa_data, BATADV_NULL_IFINDEX);
c6c8fea2
SE
125 }
126
c6c8fea2
SE
127 return 0;
128}
129
0294ca0d 130static int batadv_interface_change_mtu(struct net_device *dev, int new_mtu)
c6c8fea2
SE
131{
132 /* check ranges */
9563877e 133 if ((new_mtu < 68) || (new_mtu > batadv_hardif_min_mtu(dev)))
c6c8fea2
SE
134 return -EINVAL;
135
136 dev->mtu = new_mtu;
137
138 return 0;
139}
140
0294ca0d
SE
141static int batadv_interface_tx(struct sk_buff *skb,
142 struct net_device *soft_iface)
c6c8fea2
SE
143{
144 struct ethhdr *ethhdr = (struct ethhdr *)skb->data;
56303d34
SE
145 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
146 struct batadv_hard_iface *primary_if = NULL;
96412690 147 struct batadv_bcast_packet *bcast_packet;
c6c8fea2 148 struct vlan_ethhdr *vhdr;
af5d4f77 149 __be16 ethertype = __constant_htons(ETH_P_BATMAN);
4934ab95
SW
150 static const uint8_t stp_addr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00,
151 0x00, 0x00};
152 static const uint8_t ectp_addr[ETH_ALEN] = {0xCF, 0x00, 0x00, 0x00,
153 0x00, 0x00};
be7af5cf 154 unsigned int header_len = 0;
c6c8fea2 155 int data_len = skb->len, ret;
7a5cc242 156 short vid __maybe_unused = -1;
be7af5cf 157 bool do_bcast = false;
bbb1f90e 158 uint32_t seqno;
c384ea3e 159 unsigned long brd_delay = 1;
c6c8fea2 160
39c75a51 161 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE)
c6c8fea2
SE
162 goto dropped;
163
164 soft_iface->trans_start = jiffies;
165
166 switch (ntohs(ethhdr->h_proto)) {
167 case ETH_P_8021Q:
168 vhdr = (struct vlan_ethhdr *)skb->data;
169 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
170
7e071c79 171 if (vhdr->h_vlan_encapsulated_proto != ethertype)
c6c8fea2
SE
172 break;
173
174 /* fall through */
af5d4f77 175 case ETH_P_BATMAN:
c6c8fea2 176 goto dropped;
a7f6ee94 177 }
c6c8fea2 178
08adf151 179 if (batadv_bla_tx(bat_priv, skb, vid))
23721387
SW
180 goto dropped;
181
a73105b8 182 /* Register the client MAC in the transtable */
02233e0c
LL
183 if (!is_multicast_ether_addr(ethhdr->h_source))
184 batadv_tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif);
c6c8fea2 185
b1a8c04b
SW
186 /* don't accept stp packets. STP does not help in meshes.
187 * better use the bridge loop avoidance ...
4934ab95
SW
188 *
189 * The same goes for ECTP sent at least by some Cisco Switches,
190 * it might confuse the mesh when used with bridge loop avoidance.
b1a8c04b 191 */
1eda58bf 192 if (batadv_compare_eth(ethhdr->h_dest, stp_addr))
b1a8c04b
SW
193 goto dropped;
194
4934ab95
SW
195 if (batadv_compare_eth(ethhdr->h_dest, ectp_addr))
196 goto dropped;
197
be7af5cf
ML
198 if (is_multicast_ether_addr(ethhdr->h_dest)) {
199 do_bcast = true;
c6c8fea2 200
be7af5cf 201 switch (atomic_read(&bat_priv->gw_mode)) {
cd646ab1 202 case BATADV_GW_MODE_SERVER:
be7af5cf 203 /* gateway servers should not send dhcp
9cfc7bd6
SE
204 * requests into the mesh
205 */
7cf06bc6 206 ret = batadv_gw_is_dhcp_target(skb, &header_len);
be7af5cf
ML
207 if (ret)
208 goto dropped;
209 break;
cd646ab1 210 case BATADV_GW_MODE_CLIENT:
be7af5cf 211 /* gateway clients should send dhcp requests
9cfc7bd6
SE
212 * via unicast to their gateway
213 */
7cf06bc6 214 ret = batadv_gw_is_dhcp_target(skb, &header_len);
be7af5cf
ML
215 if (ret)
216 do_bcast = false;
217 break;
cd646ab1 218 case BATADV_GW_MODE_OFF:
be7af5cf
ML
219 default:
220 break;
221 }
c6c8fea2
SE
222 }
223
224 /* ethernet packet should be broadcasted */
225 if (do_bcast) {
e5d89254 226 primary_if = batadv_primary_if_get_selected(bat_priv);
32ae9b22 227 if (!primary_if)
c6c8fea2
SE
228 goto dropped;
229
c384ea3e
AQ
230 /* in case of ARP request, we do not immediately broadcasti the
231 * packet, instead we first wait for DAT to try to retrieve the
232 * correct ARP entry
233 */
234 if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))
235 brd_delay = msecs_to_jiffies(ARP_REQ_DELAY);
236
04b482a2 237 if (batadv_skb_head_push(skb, sizeof(*bcast_packet)) < 0)
c6c8fea2
SE
238 goto dropped;
239
96412690 240 bcast_packet = (struct batadv_bcast_packet *)skb->data;
7e071c79 241 bcast_packet->header.version = BATADV_COMPAT_VERSION;
42d0b044 242 bcast_packet->header.ttl = BATADV_TTL;
c6c8fea2
SE
243
244 /* batman packet type: broadcast */
acd34afa 245 bcast_packet->header.packet_type = BATADV_BCAST;
162d549c 246 bcast_packet->reserved = 0;
c6c8fea2
SE
247
248 /* hw address of first interface is the orig mac because only
9cfc7bd6
SE
249 * this mac is known throughout the mesh
250 */
c6c8fea2 251 memcpy(bcast_packet->orig,
32ae9b22 252 primary_if->net_dev->dev_addr, ETH_ALEN);
c6c8fea2
SE
253
254 /* set broadcast sequence number */
bbb1f90e
SE
255 seqno = atomic_inc_return(&bat_priv->bcast_seqno);
256 bcast_packet->seqno = htonl(seqno);
c6c8fea2 257
c384ea3e 258 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
c6c8fea2
SE
259
260 /* a copy is stored in the bcast list, therefore removing
9cfc7bd6
SE
261 * the original skb.
262 */
c6c8fea2
SE
263 kfree_skb(skb);
264
265 /* unicast packet */
266 } else {
cd646ab1 267 if (atomic_read(&bat_priv->gw_mode) != BATADV_GW_MODE_OFF) {
7cf06bc6 268 ret = batadv_gw_out_of_range(bat_priv, skb, ethhdr);
be7af5cf
ML
269 if (ret)
270 goto dropped;
271 }
272
c384ea3e
AQ
273 if (batadv_dat_snoop_outgoing_arp_request(bat_priv, skb))
274 goto dropped;
275
276 batadv_dat_snoop_outgoing_arp_reply(bat_priv, skb);
277
7cdcf6dd 278 ret = batadv_unicast_send_skb(bat_priv, skb);
c6c8fea2
SE
279 if (ret != 0)
280 goto dropped_freed;
281 }
282
1c9b0550
ML
283 batadv_inc_counter(bat_priv, BATADV_CNT_TX);
284 batadv_add_counter(bat_priv, BATADV_CNT_TX_BYTES, data_len);
c6c8fea2
SE
285 goto end;
286
287dropped:
288 kfree_skb(skb);
289dropped_freed:
1c9b0550 290 batadv_inc_counter(bat_priv, BATADV_CNT_TX_DROPPED);
c6c8fea2 291end:
32ae9b22 292 if (primary_if)
e5d89254 293 batadv_hardif_free_ref(primary_if);
c6c8fea2
SE
294 return NETDEV_TX_OK;
295}
296
04b482a2 297void batadv_interface_rx(struct net_device *soft_iface,
56303d34 298 struct sk_buff *skb, struct batadv_hard_iface *recv_if,
37135173 299 int hdr_size, struct batadv_orig_node *orig_node)
c6c8fea2 300{
56303d34 301 struct batadv_priv *bat_priv = netdev_priv(soft_iface);
c6c8fea2
SE
302 struct ethhdr *ethhdr;
303 struct vlan_ethhdr *vhdr;
04c9f416 304 struct batadv_header *batadv_header = (struct batadv_header *)skb->data;
7a5cc242 305 short vid __maybe_unused = -1;
af5d4f77 306 __be16 ethertype = __constant_htons(ETH_P_BATMAN);
2d3f6ccc
SW
307 bool is_bcast;
308
04c9f416 309 is_bcast = (batadv_header->packet_type == BATADV_BCAST);
c6c8fea2
SE
310
311 /* check if enough space is available for pulling, and pull */
312 if (!pskb_may_pull(skb, hdr_size))
313 goto dropped;
314
315 skb_pull_rcsum(skb, hdr_size);
316 skb_reset_mac_header(skb);
317
318 ethhdr = (struct ethhdr *)skb_mac_header(skb);
319
320 switch (ntohs(ethhdr->h_proto)) {
321 case ETH_P_8021Q:
322 vhdr = (struct vlan_ethhdr *)skb->data;
323 vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK;
324
7e071c79 325 if (vhdr->h_vlan_encapsulated_proto != ethertype)
c6c8fea2
SE
326 break;
327
328 /* fall through */
af5d4f77 329 case ETH_P_BATMAN:
c6c8fea2
SE
330 goto dropped;
331 }
332
c6c8fea2
SE
333 /* skb->dev & skb->pkt_type are set here */
334 if (unlikely(!pskb_may_pull(skb, ETH_HLEN)))
335 goto dropped;
336 skb->protocol = eth_type_trans(skb, soft_iface);
337
25985edc 338 /* should not be necessary anymore as we use skb_pull_rcsum()
c6c8fea2 339 * TODO: please verify this and remove this TODO
9cfc7bd6
SE
340 * -- Dec 21st 2009, Simon Wunderlich
341 */
c6c8fea2 342
9cfc7bd6 343 /* skb->ip_summed = CHECKSUM_UNNECESSARY; */
c6c8fea2 344
1c9b0550
ML
345 batadv_inc_counter(bat_priv, BATADV_CNT_RX);
346 batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
347 skb->len + ETH_HLEN);
c6c8fea2
SE
348
349 soft_iface->last_rx = jiffies;
350
74490f96
AQ
351 /* Let the bridge loop avoidance check the packet. If will
352 * not handle it, we can safely push it up.
353 */
354 if (batadv_bla_rx(bat_priv, skb, vid, is_bcast))
355 goto out;
356
37135173
AQ
357 if (orig_node)
358 batadv_tt_add_temporary_global_entry(bat_priv, orig_node,
359 ethhdr->h_source);
360
08c36d3e 361 if (batadv_is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest))
59b699cd
AQ
362 goto dropped;
363
c6c8fea2 364 netif_rx(skb);
ba85fac2 365 goto out;
c6c8fea2
SE
366
367dropped:
368 kfree_skb(skb);
369out:
370 return;
371}
372
36c1d153
SE
373/* batman-adv network devices have devices nesting below it and are a special
374 * "super class" of normal network devices; split their locks off into a
375 * separate class since they always nest.
376 */
377static struct lock_class_key batadv_netdev_xmit_lock_key;
378static struct lock_class_key batadv_netdev_addr_lock_key;
379
380/**
381 * batadv_set_lockdep_class_one - Set lockdep class for a single tx queue
382 * @dev: device which owns the tx queue
383 * @txq: tx queue to modify
384 * @_unused: always NULL
385 */
386static void batadv_set_lockdep_class_one(struct net_device *dev,
387 struct netdev_queue *txq,
388 void *_unused)
389{
390 lockdep_set_class(&txq->_xmit_lock, &batadv_netdev_xmit_lock_key);
391}
392
393/**
394 * batadv_set_lockdep_class - Set txq and addr_list lockdep class
395 * @dev: network device to modify
396 */
397static void batadv_set_lockdep_class(struct net_device *dev)
398{
399 lockdep_set_class(&dev->addr_list_lock, &batadv_netdev_addr_lock_key);
400 netdev_for_each_tx_queue(dev, batadv_set_lockdep_class_one, NULL);
401}
402
403/**
404 * batadv_softif_init - Late stage initialization of soft interface
405 * @dev: registered network device to modify
406 *
407 * Returns error code on failures
408 */
409static int batadv_softif_init(struct net_device *dev)
410{
411 batadv_set_lockdep_class(dev);
412
413 return 0;
414}
415
0294ca0d 416static const struct net_device_ops batadv_netdev_ops = {
36c1d153 417 .ndo_init = batadv_softif_init,
0294ca0d
SE
418 .ndo_open = batadv_interface_open,
419 .ndo_stop = batadv_interface_release,
420 .ndo_get_stats = batadv_interface_stats,
421 .ndo_set_mac_address = batadv_interface_set_mac_addr,
422 .ndo_change_mtu = batadv_interface_change_mtu,
423 .ndo_start_xmit = batadv_interface_tx,
c6c8fea2
SE
424 .ndo_validate_addr = eth_validate_addr
425};
c6c8fea2 426
0294ca0d 427static void batadv_interface_setup(struct net_device *dev)
c6c8fea2 428{
56303d34 429 struct batadv_priv *priv = netdev_priv(dev);
c6c8fea2
SE
430
431 ether_setup(dev);
432
0294ca0d 433 dev->netdev_ops = &batadv_netdev_ops;
c6c8fea2 434 dev->destructor = free_netdev;
af20b710 435 dev->tx_queue_len = 0;
c6c8fea2 436
9cfc7bd6 437 /* can't call min_mtu, because the needed variables
c6c8fea2
SE
438 * have not been initialized yet
439 */
440 dev->mtu = ETH_DATA_LEN;
6e215fd8 441 /* reserve more space in the skbuff for our header */
c11fdfae 442 dev->hard_header_len = BATADV_HEADER_LEN;
c6c8fea2
SE
443
444 /* generate random address */
28009a6c 445 eth_hw_addr_random(dev);
c6c8fea2 446
0294ca0d 447 SET_ETHTOOL_OPS(dev, &batadv_ethtool_ops);
c6c8fea2 448
704509b8 449 memset(priv, 0, sizeof(*priv));
c6c8fea2
SE
450}
451
04b482a2 452struct net_device *batadv_softif_create(const char *name)
c6c8fea2
SE
453{
454 struct net_device *soft_iface;
56303d34 455 struct batadv_priv *bat_priv;
c6c8fea2 456 int ret;
d69909d2 457 size_t cnt_len = sizeof(uint64_t) * BATADV_CNT_NUM;
c6c8fea2 458
0294ca0d
SE
459 soft_iface = alloc_netdev(sizeof(*bat_priv), name,
460 batadv_interface_setup);
c6c8fea2 461
320f422f 462 if (!soft_iface)
c6c8fea2 463 goto out;
c6c8fea2 464
1c9b0550
ML
465 bat_priv = netdev_priv(soft_iface);
466
467 /* batadv_interface_stats() needs to be available as soon as
468 * register_netdevice() has been called
469 */
470 bat_priv->bat_counters = __alloc_percpu(cnt_len, __alignof__(uint64_t));
471 if (!bat_priv->bat_counters)
472 goto free_soft_iface;
473
c3caf519 474 ret = register_netdevice(soft_iface);
c6c8fea2
SE
475 if (ret < 0) {
476 pr_err("Unable to register the batman interface '%s': %i\n",
477 name, ret);
1c9b0550 478 goto free_bat_counters;
c6c8fea2
SE
479 }
480
c6c8fea2
SE
481 atomic_set(&bat_priv->aggregated_ogms, 1);
482 atomic_set(&bat_priv->bonding, 0);
fa706554 483#ifdef CONFIG_BATMAN_ADV_BLA
23721387 484 atomic_set(&bat_priv->bridge_loop_avoidance, 0);
fa706554 485#endif
33af49ad
AQ
486#ifdef CONFIG_BATMAN_ADV_DAT
487 atomic_set(&bat_priv->distributed_arp_table, 1);
488#endif
59b699cd 489 atomic_set(&bat_priv->ap_isolation, 0);
acd34afa 490 atomic_set(&bat_priv->vis_mode, BATADV_VIS_TYPE_CLIENT_UPDATE);
cd646ab1 491 atomic_set(&bat_priv->gw_mode, BATADV_GW_MODE_OFF);
c6c8fea2
SE
492 atomic_set(&bat_priv->gw_sel_class, 20);
493 atomic_set(&bat_priv->gw_bandwidth, 41);
494 atomic_set(&bat_priv->orig_interval, 1000);
8681a1c4 495 atomic_set(&bat_priv->hop_penalty, 30);
c6c8fea2
SE
496 atomic_set(&bat_priv->log_level, 0);
497 atomic_set(&bat_priv->fragmentation, 1);
42d0b044
SE
498 atomic_set(&bat_priv->bcast_queue_left, BATADV_BCAST_QUEUE_LEN);
499 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
c6c8fea2 500
39c75a51 501 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
c6c8fea2 502 atomic_set(&bat_priv->bcast_seqno, 1);
807736f6
SE
503 atomic_set(&bat_priv->tt.vn, 0);
504 atomic_set(&bat_priv->tt.local_changes, 0);
505 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
506#ifdef CONFIG_BATMAN_ADV_BLA
507 atomic_set(&bat_priv->bla.num_requests, 0);
508#endif
509 bat_priv->tt.last_changeset = NULL;
510 bat_priv->tt.last_changeset_len = 0;
c6c8fea2
SE
511
512 bat_priv->primary_if = NULL;
513 bat_priv->num_ifaces = 0;
c6c8fea2 514
3193e8fd 515 ret = batadv_algo_select(bat_priv, batadv_routing_algo);
1c280471 516 if (ret < 0)
1c9b0550 517 goto unreg_soft_iface;
1c280471 518
5853e22c 519 ret = batadv_sysfs_add_meshif(soft_iface);
c6c8fea2 520 if (ret < 0)
1c9b0550 521 goto unreg_soft_iface;
c6c8fea2 522
40a072d7 523 ret = batadv_debugfs_add_meshif(soft_iface);
c6c8fea2
SE
524 if (ret < 0)
525 goto unreg_sysfs;
526
3193e8fd 527 ret = batadv_mesh_init(soft_iface);
c6c8fea2
SE
528 if (ret < 0)
529 goto unreg_debugfs;
530
531 return soft_iface;
532
533unreg_debugfs:
40a072d7 534 batadv_debugfs_del_meshif(soft_iface);
c6c8fea2 535unreg_sysfs:
5853e22c 536 batadv_sysfs_del_meshif(soft_iface);
c6c8fea2 537unreg_soft_iface:
1c9b0550 538 free_percpu(bat_priv->bat_counters);
06ba7ce2 539 unregister_netdevice(soft_iface);
c6c8fea2
SE
540 return NULL;
541
1c9b0550
ML
542free_bat_counters:
543 free_percpu(bat_priv->bat_counters);
c6c8fea2
SE
544free_soft_iface:
545 free_netdev(soft_iface);
546out:
547 return NULL;
548}
549
04b482a2 550void batadv_softif_destroy(struct net_device *soft_iface)
c6c8fea2 551{
40a072d7 552 batadv_debugfs_del_meshif(soft_iface);
5853e22c 553 batadv_sysfs_del_meshif(soft_iface);
3193e8fd 554 batadv_mesh_free(soft_iface);
c6c8fea2
SE
555 unregister_netdevice(soft_iface);
556}
557
04b482a2 558int batadv_softif_is_valid(const struct net_device *net_dev)
e44d8fe2 559{
0294ca0d 560 if (net_dev->netdev_ops->ndo_start_xmit == batadv_interface_tx)
e44d8fe2 561 return 1;
e44d8fe2
SE
562
563 return 0;
564}
565
c6c8fea2 566/* ethtool */
0294ca0d 567static int batadv_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
c6c8fea2
SE
568{
569 cmd->supported = 0;
570 cmd->advertising = 0;
70739497 571 ethtool_cmd_speed_set(cmd, SPEED_10);
c6c8fea2
SE
572 cmd->duplex = DUPLEX_FULL;
573 cmd->port = PORT_TP;
574 cmd->phy_address = 0;
575 cmd->transceiver = XCVR_INTERNAL;
576 cmd->autoneg = AUTONEG_DISABLE;
577 cmd->maxtxpkt = 0;
578 cmd->maxrxpkt = 0;
579
580 return 0;
581}
582
0294ca0d
SE
583static void batadv_get_drvinfo(struct net_device *dev,
584 struct ethtool_drvinfo *info)
c6c8fea2 585{
7826d43f
JP
586 strlcpy(info->driver, "B.A.T.M.A.N. advanced", sizeof(info->driver));
587 strlcpy(info->version, BATADV_SOURCE_VERSION, sizeof(info->version));
588 strlcpy(info->fw_version, "N/A", sizeof(info->fw_version));
589 strlcpy(info->bus_info, "batman", sizeof(info->bus_info));
c6c8fea2
SE
590}
591
0294ca0d 592static u32 batadv_get_msglevel(struct net_device *dev)
c6c8fea2
SE
593{
594 return -EOPNOTSUPP;
595}
596
0294ca0d 597static void batadv_set_msglevel(struct net_device *dev, u32 value)
c6c8fea2
SE
598{
599}
600
0294ca0d 601static u32 batadv_get_link(struct net_device *dev)
c6c8fea2
SE
602{
603 return 1;
604}
f8214865
MH
605
606/* Inspired by drivers/net/ethernet/dlink/sundance.c:1702
607 * Declare each description string in struct.name[] to get fixed sized buffer
608 * and compile time checking for strings longer than ETH_GSTRING_LEN.
609 */
610static const struct {
611 const char name[ETH_GSTRING_LEN];
0294ca0d 612} batadv_counters_strings[] = {
1c9b0550
ML
613 { "tx" },
614 { "tx_bytes" },
615 { "tx_dropped" },
616 { "rx" },
617 { "rx_bytes" },
f8214865
MH
618 { "forward" },
619 { "forward_bytes" },
620 { "mgmt_tx" },
621 { "mgmt_tx_bytes" },
622 { "mgmt_rx" },
623 { "mgmt_rx_bytes" },
624 { "tt_request_tx" },
625 { "tt_request_rx" },
626 { "tt_response_tx" },
627 { "tt_response_rx" },
628 { "tt_roam_adv_tx" },
629 { "tt_roam_adv_rx" },
4046b24a
MH
630#ifdef CONFIG_BATMAN_ADV_DAT
631 { "dat_get_tx" },
632 { "dat_get_rx" },
633 { "dat_put_tx" },
634 { "dat_put_rx" },
635 { "dat_cached_reply_tx" },
636#endif
f8214865
MH
637};
638
639static void batadv_get_strings(struct net_device *dev, uint32_t stringset,
640 uint8_t *data)
641{
642 if (stringset == ETH_SS_STATS)
0294ca0d
SE
643 memcpy(data, batadv_counters_strings,
644 sizeof(batadv_counters_strings));
f8214865
MH
645}
646
647static void batadv_get_ethtool_stats(struct net_device *dev,
648 struct ethtool_stats *stats,
649 uint64_t *data)
650{
56303d34 651 struct batadv_priv *bat_priv = netdev_priv(dev);
f8214865
MH
652 int i;
653
d69909d2 654 for (i = 0; i < BATADV_CNT_NUM; i++)
f8214865
MH
655 data[i] = batadv_sum_counter(bat_priv, i);
656}
657
658static int batadv_get_sset_count(struct net_device *dev, int stringset)
659{
660 if (stringset == ETH_SS_STATS)
d69909d2 661 return BATADV_CNT_NUM;
f8214865
MH
662
663 return -EOPNOTSUPP;
664}
This page took 0.183743 seconds and 5 git commands to generate.