Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1 | /* |
Sven Eckelmann | 567db7b | 2012-01-01 00:41:38 +0100 | [diff] [blame] | 2 | * Copyright (C) 2007-2012 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 3 | * |
| 4 | * Marek Lindner, Simon Wunderlich |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of version 2 of the GNU General Public |
| 8 | * License as published by the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 18 | * 02110-1301, USA |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include "main.h" |
| 23 | #include "soft-interface.h" |
| 24 | #include "hard-interface.h" |
| 25 | #include "routing.h" |
| 26 | #include "send.h" |
| 27 | #include "bat_debugfs.h" |
| 28 | #include "translation-table.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 29 | #include "hash.h" |
| 30 | #include "gateway_common.h" |
| 31 | #include "gateway_client.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 32 | #include "bat_sysfs.h" |
Antonio Quartulli | 43676ab | 2011-04-26 21:31:45 +0200 | [diff] [blame] | 33 | #include "originator.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 34 | #include <linux/slab.h> |
| 35 | #include <linux/ethtool.h> |
| 36 | #include <linux/etherdevice.h> |
| 37 | #include <linux/if_vlan.h> |
| 38 | #include "unicast.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 39 | |
| 40 | |
| 41 | static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd); |
| 42 | static void bat_get_drvinfo(struct net_device *dev, |
| 43 | struct ethtool_drvinfo *info); |
| 44 | static u32 bat_get_msglevel(struct net_device *dev); |
| 45 | static void bat_set_msglevel(struct net_device *dev, u32 value); |
| 46 | static u32 bat_get_link(struct net_device *dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 47 | |
| 48 | static const struct ethtool_ops bat_ethtool_ops = { |
| 49 | .get_settings = bat_get_settings, |
| 50 | .get_drvinfo = bat_get_drvinfo, |
| 51 | .get_msglevel = bat_get_msglevel, |
| 52 | .set_msglevel = bat_set_msglevel, |
| 53 | .get_link = bat_get_link, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | int my_skb_head_push(struct sk_buff *skb, unsigned int len) |
| 57 | { |
| 58 | int result; |
| 59 | |
| 60 | /** |
| 61 | * TODO: We must check if we can release all references to non-payload |
| 62 | * data using skb_header_release in our skbs to allow skb_cow_header to |
| 63 | * work optimally. This means that those skbs are not allowed to read |
| 64 | * or write any data which is before the current position of skb->data |
| 65 | * after that call and thus allow other skbs with the same data buffer |
| 66 | * to write freely in that area. |
| 67 | */ |
| 68 | result = skb_cow_head(skb, len); |
| 69 | if (result < 0) |
| 70 | return result; |
| 71 | |
| 72 | skb_push(skb, len); |
| 73 | return 0; |
| 74 | } |
| 75 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 76 | static int interface_open(struct net_device *dev) |
| 77 | { |
| 78 | netif_start_queue(dev); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | static int interface_release(struct net_device *dev) |
| 83 | { |
| 84 | netif_stop_queue(dev); |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static struct net_device_stats *interface_stats(struct net_device *dev) |
| 89 | { |
| 90 | struct bat_priv *bat_priv = netdev_priv(dev); |
| 91 | return &bat_priv->stats; |
| 92 | } |
| 93 | |
| 94 | static int interface_set_mac_addr(struct net_device *dev, void *p) |
| 95 | { |
| 96 | struct bat_priv *bat_priv = netdev_priv(dev); |
| 97 | struct sockaddr *addr = p; |
| 98 | |
| 99 | if (!is_valid_ether_addr(addr->sa_data)) |
| 100 | return -EADDRNOTAVAIL; |
| 101 | |
Antonio Quartulli | 015758d | 2011-07-09 17:52:13 +0200 | [diff] [blame] | 102 | /* only modify transtable if it has been initialized before */ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 103 | if (atomic_read(&bat_priv->mesh_state) == MESH_ACTIVE) { |
Antonio Quartulli | 2dafb49 | 2011-05-05 08:42:45 +0200 | [diff] [blame] | 104 | tt_local_remove(bat_priv, dev->dev_addr, |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 105 | "mac address changed", false); |
Antonio Quartulli | bc27908 | 2011-07-07 15:35:35 +0200 | [diff] [blame] | 106 | tt_local_add(dev, addr->sa_data, NULL_IFINDEX); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | memcpy(dev->dev_addr, addr->sa_data, ETH_ALEN); |
Danny Kukawka | 28009a6 | 2012-02-17 05:43:27 +0000 | [diff] [blame] | 110 | dev->addr_assign_type &= ~NET_ADDR_RANDOM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int interface_change_mtu(struct net_device *dev, int new_mtu) |
| 115 | { |
| 116 | /* check ranges */ |
| 117 | if ((new_mtu < 68) || (new_mtu > hardif_min_mtu(dev))) |
| 118 | return -EINVAL; |
| 119 | |
| 120 | dev->mtu = new_mtu; |
| 121 | |
| 122 | return 0; |
| 123 | } |
| 124 | |
Sven Eckelmann | db69ecf | 2011-06-15 15:17:21 +0200 | [diff] [blame] | 125 | static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 126 | { |
| 127 | struct ethhdr *ethhdr = (struct ethhdr *)skb->data; |
| 128 | struct bat_priv *bat_priv = netdev_priv(soft_iface); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 129 | struct hard_iface *primary_if = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 130 | struct bcast_packet *bcast_packet; |
| 131 | struct vlan_ethhdr *vhdr; |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 132 | unsigned int header_len = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 133 | int data_len = skb->len, ret; |
| 134 | short vid = -1; |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 135 | bool do_bcast = false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 136 | |
| 137 | if (atomic_read(&bat_priv->mesh_state) != MESH_ACTIVE) |
| 138 | goto dropped; |
| 139 | |
| 140 | soft_iface->trans_start = jiffies; |
| 141 | |
| 142 | switch (ntohs(ethhdr->h_proto)) { |
| 143 | case ETH_P_8021Q: |
| 144 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 145 | vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; |
| 146 | |
| 147 | if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN) |
| 148 | break; |
| 149 | |
| 150 | /* fall through */ |
| 151 | case ETH_P_BATMAN: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 152 | goto dropped; |
Simon Wunderlich | a7f6ee9 | 2012-01-22 20:00:18 +0100 | [diff] [blame^] | 153 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 154 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 155 | /* Register the client MAC in the transtable */ |
Antonio Quartulli | bc27908 | 2011-07-07 15:35:35 +0200 | [diff] [blame] | 156 | tt_local_add(soft_iface, ethhdr->h_source, skb->skb_iif); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 157 | |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 158 | if (is_multicast_ether_addr(ethhdr->h_dest)) { |
| 159 | do_bcast = true; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 160 | |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 161 | switch (atomic_read(&bat_priv->gw_mode)) { |
| 162 | case GW_MODE_SERVER: |
| 163 | /* gateway servers should not send dhcp |
| 164 | * requests into the mesh */ |
| 165 | ret = gw_is_dhcp_target(skb, &header_len); |
| 166 | if (ret) |
| 167 | goto dropped; |
| 168 | break; |
| 169 | case GW_MODE_CLIENT: |
| 170 | /* gateway clients should send dhcp requests |
| 171 | * via unicast to their gateway */ |
| 172 | ret = gw_is_dhcp_target(skb, &header_len); |
| 173 | if (ret) |
| 174 | do_bcast = false; |
| 175 | break; |
| 176 | case GW_MODE_OFF: |
| 177 | default: |
| 178 | break; |
| 179 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | /* ethernet packet should be broadcasted */ |
| 183 | if (do_bcast) { |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 184 | primary_if = primary_if_get_selected(bat_priv); |
| 185 | if (!primary_if) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 186 | goto dropped; |
| 187 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 188 | if (my_skb_head_push(skb, sizeof(*bcast_packet)) < 0) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 189 | goto dropped; |
| 190 | |
| 191 | bcast_packet = (struct bcast_packet *)skb->data; |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 192 | bcast_packet->header.version = COMPAT_VERSION; |
| 193 | bcast_packet->header.ttl = TTL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 194 | |
| 195 | /* batman packet type: broadcast */ |
Sven Eckelmann | 76543d1 | 2011-11-20 15:47:38 +0100 | [diff] [blame] | 196 | bcast_packet->header.packet_type = BAT_BCAST; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 197 | |
| 198 | /* hw address of first interface is the orig mac because only |
| 199 | * this mac is known throughout the mesh */ |
| 200 | memcpy(bcast_packet->orig, |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 201 | primary_if->net_dev->dev_addr, ETH_ALEN); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 202 | |
| 203 | /* set broadcast sequence number */ |
| 204 | bcast_packet->seqno = |
| 205 | htonl(atomic_inc_return(&bat_priv->bcast_seqno)); |
| 206 | |
Antonio Quartulli | 8698529 | 2011-06-25 19:09:12 +0200 | [diff] [blame] | 207 | add_bcast_packet_to_list(bat_priv, skb, 1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 208 | |
| 209 | /* a copy is stored in the bcast list, therefore removing |
| 210 | * the original skb. */ |
| 211 | kfree_skb(skb); |
| 212 | |
| 213 | /* unicast packet */ |
| 214 | } else { |
Marek Lindner | be7af5c | 2011-09-08 13:12:53 +0200 | [diff] [blame] | 215 | if (atomic_read(&bat_priv->gw_mode) != GW_MODE_OFF) { |
| 216 | ret = gw_out_of_range(bat_priv, skb, ethhdr); |
| 217 | if (ret) |
| 218 | goto dropped; |
| 219 | } |
| 220 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 221 | ret = unicast_send_skb(skb, bat_priv); |
| 222 | if (ret != 0) |
| 223 | goto dropped_freed; |
| 224 | } |
| 225 | |
| 226 | bat_priv->stats.tx_packets++; |
| 227 | bat_priv->stats.tx_bytes += data_len; |
| 228 | goto end; |
| 229 | |
| 230 | dropped: |
| 231 | kfree_skb(skb); |
| 232 | dropped_freed: |
| 233 | bat_priv->stats.tx_dropped++; |
| 234 | end: |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 235 | if (primary_if) |
| 236 | hardif_free_ref(primary_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 237 | return NETDEV_TX_OK; |
| 238 | } |
| 239 | |
| 240 | void interface_rx(struct net_device *soft_iface, |
Marek Lindner | e6c10f4 | 2011-02-18 12:33:20 +0000 | [diff] [blame] | 241 | struct sk_buff *skb, struct hard_iface *recv_if, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 242 | int hdr_size) |
| 243 | { |
| 244 | struct bat_priv *bat_priv = netdev_priv(soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 245 | struct ethhdr *ethhdr; |
| 246 | struct vlan_ethhdr *vhdr; |
| 247 | short vid = -1; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 248 | |
| 249 | /* check if enough space is available for pulling, and pull */ |
| 250 | if (!pskb_may_pull(skb, hdr_size)) |
| 251 | goto dropped; |
| 252 | |
| 253 | skb_pull_rcsum(skb, hdr_size); |
| 254 | skb_reset_mac_header(skb); |
| 255 | |
| 256 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
| 257 | |
| 258 | switch (ntohs(ethhdr->h_proto)) { |
| 259 | case ETH_P_8021Q: |
| 260 | vhdr = (struct vlan_ethhdr *)skb->data; |
| 261 | vid = ntohs(vhdr->h_vlan_TCI) & VLAN_VID_MASK; |
| 262 | |
| 263 | if (ntohs(vhdr->h_vlan_encapsulated_proto) != ETH_P_BATMAN) |
| 264 | break; |
| 265 | |
| 266 | /* fall through */ |
| 267 | case ETH_P_BATMAN: |
| 268 | goto dropped; |
| 269 | } |
| 270 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 271 | /* skb->dev & skb->pkt_type are set here */ |
| 272 | if (unlikely(!pskb_may_pull(skb, ETH_HLEN))) |
| 273 | goto dropped; |
| 274 | skb->protocol = eth_type_trans(skb, soft_iface); |
| 275 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 276 | /* should not be necessary anymore as we use skb_pull_rcsum() |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 277 | * TODO: please verify this and remove this TODO |
| 278 | * -- Dec 21st 2009, Simon Wunderlich */ |
| 279 | |
| 280 | /* skb->ip_summed = CHECKSUM_UNNECESSARY;*/ |
| 281 | |
| 282 | bat_priv->stats.rx_packets++; |
| 283 | bat_priv->stats.rx_bytes += skb->len + sizeof(struct ethhdr); |
| 284 | |
| 285 | soft_iface->last_rx = jiffies; |
| 286 | |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 287 | if (is_ap_isolated(bat_priv, ethhdr->h_source, ethhdr->h_dest)) |
| 288 | goto dropped; |
| 289 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 290 | netif_rx(skb); |
Simon Wunderlich | ba85fac | 2011-04-17 20:34:27 +0200 | [diff] [blame] | 291 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 292 | |
| 293 | dropped: |
| 294 | kfree_skb(skb); |
| 295 | out: |
| 296 | return; |
| 297 | } |
| 298 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 299 | static const struct net_device_ops bat_netdev_ops = { |
| 300 | .ndo_open = interface_open, |
| 301 | .ndo_stop = interface_release, |
| 302 | .ndo_get_stats = interface_stats, |
| 303 | .ndo_set_mac_address = interface_set_mac_addr, |
| 304 | .ndo_change_mtu = interface_change_mtu, |
| 305 | .ndo_start_xmit = interface_tx, |
| 306 | .ndo_validate_addr = eth_validate_addr |
| 307 | }; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 308 | |
| 309 | static void interface_setup(struct net_device *dev) |
| 310 | { |
| 311 | struct bat_priv *priv = netdev_priv(dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 312 | |
| 313 | ether_setup(dev); |
| 314 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 315 | dev->netdev_ops = &bat_netdev_ops; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 316 | dev->destructor = free_netdev; |
Andrew Lunn | af20b71 | 2011-04-17 20:39:07 +0200 | [diff] [blame] | 317 | dev->tx_queue_len = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 318 | |
| 319 | /** |
| 320 | * can't call min_mtu, because the needed variables |
| 321 | * have not been initialized yet |
| 322 | */ |
| 323 | dev->mtu = ETH_DATA_LEN; |
Sven Eckelmann | 6e215fd | 2011-05-08 12:45:45 +0200 | [diff] [blame] | 324 | /* reserve more space in the skbuff for our header */ |
| 325 | dev->hard_header_len = BAT_HEADER_LEN; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 326 | |
| 327 | /* generate random address */ |
Danny Kukawka | 28009a6 | 2012-02-17 05:43:27 +0000 | [diff] [blame] | 328 | eth_hw_addr_random(dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 329 | |
| 330 | SET_ETHTOOL_OPS(dev, &bat_ethtool_ops); |
| 331 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 332 | memset(priv, 0, sizeof(*priv)); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 335 | struct net_device *softif_create(const char *name) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 336 | { |
| 337 | struct net_device *soft_iface; |
| 338 | struct bat_priv *bat_priv; |
| 339 | int ret; |
| 340 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 341 | soft_iface = alloc_netdev(sizeof(*bat_priv), name, interface_setup); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 342 | |
Joe Perches | 320f422 | 2011-08-29 14:17:24 -0700 | [diff] [blame] | 343 | if (!soft_iface) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 344 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 345 | |
Sven Eckelmann | c3caf51 | 2011-05-03 11:51:38 +0200 | [diff] [blame] | 346 | ret = register_netdevice(soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 347 | if (ret < 0) { |
| 348 | pr_err("Unable to register the batman interface '%s': %i\n", |
| 349 | name, ret); |
| 350 | goto free_soft_iface; |
| 351 | } |
| 352 | |
| 353 | bat_priv = netdev_priv(soft_iface); |
| 354 | |
| 355 | atomic_set(&bat_priv->aggregated_ogms, 1); |
| 356 | atomic_set(&bat_priv->bonding, 0); |
Antonio Quartulli | 59b699c | 2011-07-07 15:35:36 +0200 | [diff] [blame] | 357 | atomic_set(&bat_priv->ap_isolation, 0); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 358 | atomic_set(&bat_priv->vis_mode, VIS_TYPE_CLIENT_UPDATE); |
| 359 | atomic_set(&bat_priv->gw_mode, GW_MODE_OFF); |
| 360 | atomic_set(&bat_priv->gw_sel_class, 20); |
| 361 | atomic_set(&bat_priv->gw_bandwidth, 41); |
| 362 | atomic_set(&bat_priv->orig_interval, 1000); |
Marek Lindner | 8681a1c | 2012-01-27 23:11:55 +0800 | [diff] [blame] | 363 | atomic_set(&bat_priv->hop_penalty, 30); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 364 | atomic_set(&bat_priv->log_level, 0); |
| 365 | atomic_set(&bat_priv->fragmentation, 1); |
| 366 | atomic_set(&bat_priv->bcast_queue_left, BCAST_QUEUE_LEN); |
| 367 | atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN); |
| 368 | |
| 369 | atomic_set(&bat_priv->mesh_state, MESH_INACTIVE); |
| 370 | atomic_set(&bat_priv->bcast_seqno, 1); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 371 | atomic_set(&bat_priv->ttvn, 0); |
| 372 | atomic_set(&bat_priv->tt_local_changes, 0); |
| 373 | atomic_set(&bat_priv->tt_ogm_append_cnt, 0); |
| 374 | |
| 375 | bat_priv->tt_buff = NULL; |
| 376 | bat_priv->tt_buff_len = 0; |
Antonio Quartulli | cc47f66 | 2011-04-27 14:27:57 +0200 | [diff] [blame] | 377 | bat_priv->tt_poss_change = false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 378 | |
| 379 | bat_priv->primary_if = NULL; |
| 380 | bat_priv->num_ifaces = 0; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 381 | |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 382 | ret = bat_algo_select(bat_priv, bat_routing_algo); |
| 383 | if (ret < 0) |
| 384 | goto unreg_soft_iface; |
| 385 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 386 | ret = sysfs_add_meshif(soft_iface); |
| 387 | if (ret < 0) |
| 388 | goto unreg_soft_iface; |
| 389 | |
| 390 | ret = debugfs_add_meshif(soft_iface); |
| 391 | if (ret < 0) |
| 392 | goto unreg_sysfs; |
| 393 | |
| 394 | ret = mesh_init(soft_iface); |
| 395 | if (ret < 0) |
| 396 | goto unreg_debugfs; |
| 397 | |
| 398 | return soft_iface; |
| 399 | |
| 400 | unreg_debugfs: |
| 401 | debugfs_del_meshif(soft_iface); |
| 402 | unreg_sysfs: |
| 403 | sysfs_del_meshif(soft_iface); |
| 404 | unreg_soft_iface: |
Simon Wunderlich | 06ba7ce | 2011-11-07 13:57:48 +0100 | [diff] [blame] | 405 | unregister_netdevice(soft_iface); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 406 | return NULL; |
| 407 | |
| 408 | free_soft_iface: |
| 409 | free_netdev(soft_iface); |
| 410 | out: |
| 411 | return NULL; |
| 412 | } |
| 413 | |
| 414 | void softif_destroy(struct net_device *soft_iface) |
| 415 | { |
| 416 | debugfs_del_meshif(soft_iface); |
| 417 | sysfs_del_meshif(soft_iface); |
| 418 | mesh_free(soft_iface); |
| 419 | unregister_netdevice(soft_iface); |
| 420 | } |
| 421 | |
Sven Eckelmann | 747e422 | 2011-05-14 23:14:50 +0200 | [diff] [blame] | 422 | int softif_is_valid(const struct net_device *net_dev) |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 423 | { |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 424 | if (net_dev->netdev_ops->ndo_start_xmit == interface_tx) |
| 425 | return 1; |
Sven Eckelmann | e44d8fe | 2011-03-04 21:36:41 +0000 | [diff] [blame] | 426 | |
| 427 | return 0; |
| 428 | } |
| 429 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 430 | /* ethtool */ |
| 431 | static int bat_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 432 | { |
| 433 | cmd->supported = 0; |
| 434 | cmd->advertising = 0; |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 435 | ethtool_cmd_speed_set(cmd, SPEED_10); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 436 | cmd->duplex = DUPLEX_FULL; |
| 437 | cmd->port = PORT_TP; |
| 438 | cmd->phy_address = 0; |
| 439 | cmd->transceiver = XCVR_INTERNAL; |
| 440 | cmd->autoneg = AUTONEG_DISABLE; |
| 441 | cmd->maxtxpkt = 0; |
| 442 | cmd->maxrxpkt = 0; |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | static void bat_get_drvinfo(struct net_device *dev, |
| 448 | struct ethtool_drvinfo *info) |
| 449 | { |
| 450 | strcpy(info->driver, "B.A.T.M.A.N. advanced"); |
| 451 | strcpy(info->version, SOURCE_VERSION); |
| 452 | strcpy(info->fw_version, "N/A"); |
| 453 | strcpy(info->bus_info, "batman"); |
| 454 | } |
| 455 | |
| 456 | static u32 bat_get_msglevel(struct net_device *dev) |
| 457 | { |
| 458 | return -EOPNOTSUPP; |
| 459 | } |
| 460 | |
| 461 | static void bat_set_msglevel(struct net_device *dev, u32 value) |
| 462 | { |
| 463 | } |
| 464 | |
| 465 | static u32 bat_get_link(struct net_device *dev) |
| 466 | { |
| 467 | return 1; |
| 468 | } |