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