Simon Wunderlich | e19f975 | 2014-01-04 18:04:25 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2007-2014 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 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 |
Antonio Quartulli | ebf38fb | 2013-11-03 20:40:48 +0100 | [diff] [blame] | 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include "main.h" |
| 19 | #include "routing.h" |
| 20 | #include "send.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 21 | #include "soft-interface.h" |
| 22 | #include "hard-interface.h" |
| 23 | #include "icmp_socket.h" |
| 24 | #include "translation-table.h" |
| 25 | #include "originator.h" |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 26 | #include "bridge_loop_avoidance.h" |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 27 | #include "distributed-arp-table.h" |
Martin Hundebøll | 9533247 | 2013-01-25 11:12:40 +0100 | [diff] [blame] | 28 | #include "network-coding.h" |
Martin Hundebøll | 610bfc6bc | 2013-05-23 16:53:02 +0200 | [diff] [blame] | 29 | #include "fragmentation.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 30 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 31 | #include <linux/if_vlan.h> |
| 32 | |
Sven Eckelmann | 63b0103 | 2012-05-16 20:23:13 +0200 | [diff] [blame] | 33 | static int batadv_route_unicast_packet(struct sk_buff *skb, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 34 | struct batadv_hard_iface *recv_if); |
Simon Wunderlich | a7f6ee9 | 2012-01-22 20:00:18 +0100 | [diff] [blame] | 35 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 36 | /** |
| 37 | * _batadv_update_route - set the router for this originator |
| 38 | * @bat_priv: the bat priv with all the soft interface information |
| 39 | * @orig_node: orig node which is to be configured |
| 40 | * @recv_if: the receive interface for which this route is set |
| 41 | * @neigh_node: neighbor which should be the next router |
| 42 | * |
| 43 | * This function does not perform any error checks |
| 44 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 45 | static void _batadv_update_route(struct batadv_priv *bat_priv, |
| 46 | struct batadv_orig_node *orig_node, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 47 | struct batadv_hard_iface *recv_if, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 48 | struct batadv_neigh_node *neigh_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 49 | { |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 50 | struct batadv_orig_ifinfo *orig_ifinfo; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 51 | struct batadv_neigh_node *curr_router; |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 52 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 53 | orig_ifinfo = batadv_orig_ifinfo_get(orig_node, recv_if); |
| 54 | if (!orig_ifinfo) |
| 55 | return; |
| 56 | |
| 57 | rcu_read_lock(); |
| 58 | curr_router = rcu_dereference(orig_ifinfo->router); |
| 59 | if (curr_router && !atomic_inc_not_zero(&curr_router->refcount)) |
| 60 | curr_router = NULL; |
| 61 | rcu_read_unlock(); |
Marek Lindner | a8e7f4b | 2010-12-12 21:57:10 +0000 | [diff] [blame] | 62 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 63 | /* route deleted */ |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 64 | if ((curr_router) && (!neigh_node)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 65 | batadv_dbg(BATADV_DBG_ROUTES, bat_priv, |
| 66 | "Deleting route towards: %pM\n", orig_node->orig); |
Antonio Quartulli | 95fb130 | 2013-08-07 18:28:55 +0200 | [diff] [blame] | 67 | batadv_tt_global_del_orig(bat_priv, orig_node, -1, |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 68 | "Deleted route towards originator"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 69 | |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 70 | /* route added */ |
| 71 | } else if ((!curr_router) && (neigh_node)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 72 | batadv_dbg(BATADV_DBG_ROUTES, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 73 | "Adding route towards: %pM (via %pM)\n", |
| 74 | orig_node->orig, neigh_node->addr); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 75 | /* route changed */ |
Sven Eckelmann | bb899b8 | 2011-05-10 11:22:37 +0200 | [diff] [blame] | 76 | } else if (neigh_node && curr_router) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 77 | batadv_dbg(BATADV_DBG_ROUTES, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 78 | "Changing route towards: %pM (now via %pM - was via %pM)\n", |
| 79 | orig_node->orig, neigh_node->addr, |
| 80 | curr_router->addr); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 83 | if (curr_router) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 84 | batadv_neigh_node_free_ref(curr_router); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 85 | |
| 86 | /* increase refcount of new best neighbor */ |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 87 | if (neigh_node && !atomic_inc_not_zero(&neigh_node->refcount)) |
| 88 | neigh_node = NULL; |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 89 | |
| 90 | spin_lock_bh(&orig_node->neigh_list_lock); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 91 | rcu_assign_pointer(orig_ifinfo->router, neigh_node); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 92 | spin_unlock_bh(&orig_node->neigh_list_lock); |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 93 | batadv_orig_ifinfo_free_ref(orig_ifinfo); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 94 | |
| 95 | /* decrease refcount of previous best neighbor */ |
| 96 | if (curr_router) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 97 | batadv_neigh_node_free_ref(curr_router); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 100 | /** |
| 101 | * batadv_update_route - set the router for this originator |
| 102 | * @bat_priv: the bat priv with all the soft interface information |
| 103 | * @orig_node: orig node which is to be configured |
| 104 | * @recv_if: the receive interface for which this route is set |
| 105 | * @neigh_node: neighbor which should be the next router |
| 106 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 107 | void batadv_update_route(struct batadv_priv *bat_priv, |
| 108 | struct batadv_orig_node *orig_node, |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 109 | struct batadv_hard_iface *recv_if, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 110 | struct batadv_neigh_node *neigh_node) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 111 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 112 | struct batadv_neigh_node *router = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 113 | |
| 114 | if (!orig_node) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 115 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 116 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 117 | router = batadv_orig_router_get(orig_node, recv_if); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 118 | |
| 119 | if (router != neigh_node) |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 120 | _batadv_update_route(bat_priv, orig_node, recv_if, neigh_node); |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 121 | |
| 122 | out: |
| 123 | if (router) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 124 | batadv_neigh_node_free_ref(router); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 125 | } |
| 126 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 127 | /* checks whether the host restarted and is in the protection time. |
| 128 | * returns: |
| 129 | * 0 if the packet is to be accepted |
| 130 | * 1 if the packet is to be ignored. |
| 131 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 132 | int batadv_window_protected(struct batadv_priv *bat_priv, int32_t seq_num_diff, |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 133 | unsigned long *last_reset) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 134 | { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 135 | if (seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE || |
| 136 | seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE) { |
| 137 | if (!batadv_has_timed_out(*last_reset, |
| 138 | BATADV_RESET_PROTECTION_MS)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 139 | return 1; |
Marek Lindner | 8c7bf24 | 2012-03-17 15:28:33 +0800 | [diff] [blame] | 140 | |
| 141 | *last_reset = jiffies; |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 142 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 143 | "old packet received, start protection\n"); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 144 | } |
Marek Lindner | 8c7bf24 | 2012-03-17 15:28:33 +0800 | [diff] [blame] | 145 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 146 | return 0; |
| 147 | } |
| 148 | |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 149 | bool batadv_check_management_packet(struct sk_buff *skb, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 150 | struct batadv_hard_iface *hard_iface, |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 151 | int header_len) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 152 | { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 153 | struct ethhdr *ethhdr; |
| 154 | |
| 155 | /* drop packet if it has not necessary minimum size */ |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 156 | if (unlikely(!pskb_may_pull(skb, header_len))) |
| 157 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 158 | |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 159 | ethhdr = eth_hdr(skb); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 160 | |
| 161 | /* packet with broadcast indication but unicast recipient */ |
| 162 | if (!is_broadcast_ether_addr(ethhdr->h_dest)) |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 163 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 164 | |
| 165 | /* packet with broadcast sender address */ |
| 166 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 167 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 168 | |
| 169 | /* create a copy of the skb, if needed, to modify it. */ |
| 170 | if (skb_cow(skb, 0) < 0) |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 171 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 172 | |
| 173 | /* keep skb linear */ |
| 174 | if (skb_linearize(skb) < 0) |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 175 | return false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 176 | |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 177 | return true; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 178 | } |
| 179 | |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 180 | /** |
| 181 | * batadv_recv_my_icmp_packet - receive an icmp packet locally |
| 182 | * @bat_priv: the bat priv with all the soft interface information |
| 183 | * @skb: icmp packet to process |
| 184 | * |
| 185 | * Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP |
| 186 | * otherwise. |
| 187 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 188 | static int batadv_recv_my_icmp_packet(struct batadv_priv *bat_priv, |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 189 | struct sk_buff *skb) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 190 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 191 | struct batadv_hard_iface *primary_if = NULL; |
| 192 | struct batadv_orig_node *orig_node = NULL; |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 193 | struct batadv_icmp_header *icmph; |
| 194 | int res, ret = NET_RX_DROP; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 195 | |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 196 | icmph = (struct batadv_icmp_header *)skb->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 197 | |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 198 | switch (icmph->msg_type) { |
| 199 | case BATADV_ECHO_REPLY: |
| 200 | case BATADV_DESTINATION_UNREACHABLE: |
| 201 | case BATADV_TTL_EXCEEDED: |
| 202 | /* receive the packet */ |
| 203 | if (skb_linearize(skb) < 0) |
| 204 | break; |
| 205 | |
| 206 | batadv_socket_receive_packet(icmph, skb->len); |
| 207 | break; |
| 208 | case BATADV_ECHO_REQUEST: |
| 209 | /* answer echo request (ping) */ |
| 210 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 211 | if (!primary_if) |
| 212 | goto out; |
| 213 | |
| 214 | /* get routing information */ |
| 215 | orig_node = batadv_orig_hash_find(bat_priv, icmph->orig); |
| 216 | if (!orig_node) |
| 217 | goto out; |
| 218 | |
| 219 | /* create a copy of the skb, if needed, to modify it. */ |
| 220 | if (skb_cow(skb, ETH_HLEN) < 0) |
| 221 | goto out; |
| 222 | |
| 223 | icmph = (struct batadv_icmp_header *)skb->data; |
| 224 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 225 | ether_addr_copy(icmph->dst, icmph->orig); |
| 226 | ether_addr_copy(icmph->orig, primary_if->net_dev->dev_addr); |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 227 | icmph->msg_type = BATADV_ECHO_REPLY; |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 228 | icmph->ttl = BATADV_TTL; |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 229 | |
| 230 | res = batadv_send_skb_to_orig(skb, orig_node, NULL); |
| 231 | if (res != NET_XMIT_DROP) |
| 232 | ret = NET_RX_SUCCESS; |
| 233 | |
| 234 | break; |
| 235 | default: |
| 236 | /* drop unknown type */ |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 237 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 238 | } |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 239 | out: |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 240 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 241 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 242 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 243 | batadv_orig_node_free_ref(orig_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 244 | return ret; |
| 245 | } |
| 246 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 247 | static int batadv_recv_icmp_ttl_exceeded(struct batadv_priv *bat_priv, |
Sven Eckelmann | 63b0103 | 2012-05-16 20:23:13 +0200 | [diff] [blame] | 248 | struct sk_buff *skb) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 249 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 250 | struct batadv_hard_iface *primary_if = NULL; |
| 251 | struct batadv_orig_node *orig_node = NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 252 | struct batadv_icmp_packet *icmp_packet; |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 253 | int ret = NET_RX_DROP; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 254 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 255 | icmp_packet = (struct batadv_icmp_packet *)skb->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 256 | |
| 257 | /* send TTL exceeded if packet is an echo request (traceroute) */ |
Antonio Quartulli | 27a417e | 2013-12-05 15:33:00 +0100 | [diff] [blame] | 258 | if (icmp_packet->msg_type != BATADV_ECHO_REQUEST) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 259 | pr_debug("Warning - can't forward icmp packet from %pM to %pM: ttl exceeded\n", |
Antonio Quartulli | 27a417e | 2013-12-05 15:33:00 +0100 | [diff] [blame] | 260 | icmp_packet->orig, icmp_packet->dst); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 261 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 262 | } |
| 263 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 264 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 265 | if (!primary_if) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 266 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 267 | |
| 268 | /* get routing information */ |
Antonio Quartulli | 27a417e | 2013-12-05 15:33:00 +0100 | [diff] [blame] | 269 | orig_node = batadv_orig_hash_find(bat_priv, icmp_packet->orig); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 270 | if (!orig_node) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 271 | goto out; |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 272 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 273 | /* create a copy of the skb, if needed, to modify it. */ |
Antonio Quartulli | 0d12507 | 2012-02-18 11:27:34 +0100 | [diff] [blame] | 274 | if (skb_cow(skb, ETH_HLEN) < 0) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 275 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 276 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 277 | icmp_packet = (struct batadv_icmp_packet *)skb->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 278 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 279 | ether_addr_copy(icmp_packet->dst, icmp_packet->orig); |
| 280 | ether_addr_copy(icmp_packet->orig, primary_if->net_dev->dev_addr); |
Antonio Quartulli | 27a417e | 2013-12-05 15:33:00 +0100 | [diff] [blame] | 281 | icmp_packet->msg_type = BATADV_TTL_EXCEEDED; |
| 282 | icmp_packet->ttl = BATADV_TTL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 283 | |
Martin Hundebøll | e91ecfc | 2013-04-20 13:54:39 +0200 | [diff] [blame] | 284 | if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP) |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 285 | ret = NET_RX_SUCCESS; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 286 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 287 | out: |
Marek Lindner | 32ae9b2 | 2011-04-20 15:40:58 +0200 | [diff] [blame] | 288 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 289 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 290 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 291 | batadv_orig_node_free_ref(orig_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 292 | return ret; |
| 293 | } |
| 294 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 295 | int batadv_recv_icmp_packet(struct sk_buff *skb, |
| 296 | struct batadv_hard_iface *recv_if) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 297 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 298 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 299 | struct batadv_icmp_header *icmph; |
| 300 | struct batadv_icmp_packet_rr *icmp_packet_rr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 301 | struct ethhdr *ethhdr; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 302 | struct batadv_orig_node *orig_node = NULL; |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 303 | int hdr_size = sizeof(struct batadv_icmp_header); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 304 | int ret = NET_RX_DROP; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 305 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 306 | /* drop packet if it has not necessary minimum size */ |
| 307 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 308 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 309 | |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 310 | ethhdr = eth_hdr(skb); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 311 | |
| 312 | /* packet with unicast indication but broadcast recipient */ |
| 313 | if (is_broadcast_ether_addr(ethhdr->h_dest)) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 314 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 315 | |
| 316 | /* packet with broadcast sender address */ |
| 317 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 318 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 319 | |
| 320 | /* not for me */ |
Antonio Quartulli | fe8a93b | 2013-04-03 19:10:26 +0200 | [diff] [blame] | 321 | if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest)) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 322 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 323 | |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 324 | icmph = (struct batadv_icmp_header *)skb->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 325 | |
| 326 | /* add record route information if not full */ |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 327 | if ((icmph->msg_type == BATADV_ECHO_REPLY || |
| 328 | icmph->msg_type == BATADV_ECHO_REQUEST) && |
| 329 | (skb->len >= sizeof(struct batadv_icmp_packet_rr))) { |
| 330 | if (skb_linearize(skb) < 0) |
| 331 | goto out; |
| 332 | |
| 333 | /* create a copy of the skb, if needed, to modify it. */ |
| 334 | if (skb_cow(skb, ETH_HLEN) < 0) |
| 335 | goto out; |
| 336 | |
| 337 | icmph = (struct batadv_icmp_header *)skb->data; |
| 338 | icmp_packet_rr = (struct batadv_icmp_packet_rr *)icmph; |
| 339 | if (icmp_packet_rr->rr_cur >= BATADV_RR_LEN) |
| 340 | goto out; |
| 341 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 342 | ether_addr_copy(icmp_packet_rr->rr[icmp_packet_rr->rr_cur], |
| 343 | ethhdr->h_dest); |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 344 | icmp_packet_rr->rr_cur++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | /* packet for me */ |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 348 | if (batadv_is_my_mac(bat_priv, icmph->dst)) |
| 349 | return batadv_recv_my_icmp_packet(bat_priv, skb); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 350 | |
| 351 | /* TTL exceeded */ |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 352 | if (icmph->ttl < 2) |
Sven Eckelmann | 63b0103 | 2012-05-16 20:23:13 +0200 | [diff] [blame] | 353 | return batadv_recv_icmp_ttl_exceeded(bat_priv, skb); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 354 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 355 | /* get routing information */ |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 356 | orig_node = batadv_orig_hash_find(bat_priv, icmph->dst); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 357 | if (!orig_node) |
Linus Lüssing | e1a5382f | 2011-03-14 22:43:37 +0000 | [diff] [blame] | 358 | goto out; |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 359 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 360 | /* create a copy of the skb, if needed, to modify it. */ |
Antonio Quartulli | 0d12507 | 2012-02-18 11:27:34 +0100 | [diff] [blame] | 361 | if (skb_cow(skb, ETH_HLEN) < 0) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 362 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 363 | |
Simon Wunderlich | da6b8c2 | 2013-10-22 22:50:09 +0200 | [diff] [blame] | 364 | icmph = (struct batadv_icmp_header *)skb->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 365 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 366 | /* decrement ttl */ |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 367 | icmph->ttl--; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 368 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 369 | /* route it */ |
Martin Hundebøll | e91ecfc | 2013-04-20 13:54:39 +0200 | [diff] [blame] | 370 | if (batadv_send_skb_to_orig(skb, orig_node, recv_if) != NET_XMIT_DROP) |
Martin Hundebøll | bb351ba | 2012-10-16 16:13:48 +0200 | [diff] [blame] | 371 | ret = NET_RX_SUCCESS; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 372 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 373 | out: |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 374 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 375 | batadv_orig_node_free_ref(orig_node); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 376 | return ret; |
| 377 | } |
| 378 | |
Martin Hundebøll | f86ce0a | 2013-01-14 00:20:32 +0100 | [diff] [blame] | 379 | /** |
| 380 | * batadv_check_unicast_packet - Check for malformed unicast packets |
David S. Miller | 6e0895c | 2013-04-22 20:32:51 -0400 | [diff] [blame] | 381 | * @bat_priv: the bat priv with all the soft interface information |
Martin Hundebøll | f86ce0a | 2013-01-14 00:20:32 +0100 | [diff] [blame] | 382 | * @skb: packet to check |
| 383 | * @hdr_size: size of header to pull |
| 384 | * |
| 385 | * Check for short header and bad addresses in given packet. Returns negative |
| 386 | * value when check fails and 0 otherwise. The negative value depends on the |
| 387 | * reason: -ENODATA for bad header, -EBADR for broadcast destination or source, |
| 388 | * and -EREMOTE for non-local (other host) destination. |
| 389 | */ |
Antonio Quartulli | fe8a93b | 2013-04-03 19:10:26 +0200 | [diff] [blame] | 390 | static int batadv_check_unicast_packet(struct batadv_priv *bat_priv, |
| 391 | struct sk_buff *skb, int hdr_size) |
Martin Hundebøll | ff51fd7 | 2012-07-05 11:34:27 +0200 | [diff] [blame] | 392 | { |
| 393 | struct ethhdr *ethhdr; |
| 394 | |
| 395 | /* drop packet if it has not necessary minimum size */ |
| 396 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
Martin Hundebøll | f86ce0a | 2013-01-14 00:20:32 +0100 | [diff] [blame] | 397 | return -ENODATA; |
Martin Hundebøll | ff51fd7 | 2012-07-05 11:34:27 +0200 | [diff] [blame] | 398 | |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 399 | ethhdr = eth_hdr(skb); |
Martin Hundebøll | ff51fd7 | 2012-07-05 11:34:27 +0200 | [diff] [blame] | 400 | |
| 401 | /* packet with unicast indication but broadcast recipient */ |
| 402 | if (is_broadcast_ether_addr(ethhdr->h_dest)) |
Martin Hundebøll | f86ce0a | 2013-01-14 00:20:32 +0100 | [diff] [blame] | 403 | return -EBADR; |
Martin Hundebøll | ff51fd7 | 2012-07-05 11:34:27 +0200 | [diff] [blame] | 404 | |
| 405 | /* packet with broadcast sender address */ |
| 406 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
Martin Hundebøll | f86ce0a | 2013-01-14 00:20:32 +0100 | [diff] [blame] | 407 | return -EBADR; |
Martin Hundebøll | ff51fd7 | 2012-07-05 11:34:27 +0200 | [diff] [blame] | 408 | |
| 409 | /* not for me */ |
Antonio Quartulli | fe8a93b | 2013-04-03 19:10:26 +0200 | [diff] [blame] | 410 | if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest)) |
Martin Hundebøll | f86ce0a | 2013-01-14 00:20:32 +0100 | [diff] [blame] | 411 | return -EREMOTE; |
Martin Hundebøll | ff51fd7 | 2012-07-05 11:34:27 +0200 | [diff] [blame] | 412 | |
| 413 | return 0; |
| 414 | } |
| 415 | |
Simon Wunderlich | f6c8b71 | 2013-11-13 19:14:45 +0100 | [diff] [blame] | 416 | /** |
| 417 | * batadv_find_router - find a suitable router for this originator |
| 418 | * @bat_priv: the bat priv with all the soft interface information |
| 419 | * @orig_node: the destination node |
| 420 | * @recv_if: pointer to interface this packet was received on |
| 421 | * |
| 422 | * Returns the router which should be used for this orig_node on |
| 423 | * this interface, or NULL if not available. |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 424 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 425 | struct batadv_neigh_node * |
| 426 | batadv_find_router(struct batadv_priv *bat_priv, |
| 427 | struct batadv_orig_node *orig_node, |
Simon Wunderlich | f3b3d90 | 2013-11-13 19:14:50 +0100 | [diff] [blame] | 428 | struct batadv_hard_iface *recv_if) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 429 | { |
Simon Wunderlich | f3b3d90 | 2013-11-13 19:14:50 +0100 | [diff] [blame] | 430 | struct batadv_algo_ops *bao = bat_priv->bat_algo_ops; |
| 431 | struct batadv_neigh_node *first_candidate_router = NULL; |
| 432 | struct batadv_neigh_node *next_candidate_router = NULL; |
| 433 | struct batadv_neigh_node *router, *cand_router = NULL; |
| 434 | struct batadv_neigh_node *last_cand_router = NULL; |
| 435 | struct batadv_orig_ifinfo *cand, *first_candidate = NULL; |
| 436 | struct batadv_orig_ifinfo *next_candidate = NULL; |
| 437 | struct batadv_orig_ifinfo *last_candidate; |
| 438 | bool last_candidate_found = false; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 439 | |
| 440 | if (!orig_node) |
| 441 | return NULL; |
| 442 | |
Simon Wunderlich | 7351a482 | 2013-11-13 19:14:47 +0100 | [diff] [blame] | 443 | router = batadv_orig_router_get(orig_node, recv_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 444 | |
Simon Wunderlich | 329887a | 2014-08-13 14:26:56 +0200 | [diff] [blame] | 445 | if (!router) |
| 446 | return router; |
| 447 | |
Simon Wunderlich | f3b3d90 | 2013-11-13 19:14:50 +0100 | [diff] [blame] | 448 | /* only consider bonding for recv_if == BATADV_IF_DEFAULT (first hop) |
| 449 | * and if activated. |
| 450 | */ |
Simon Wunderlich | 329887a | 2014-08-13 14:26:56 +0200 | [diff] [blame] | 451 | if (!(recv_if == BATADV_IF_DEFAULT && atomic_read(&bat_priv->bonding))) |
Simon Wunderlich | f3b3d90 | 2013-11-13 19:14:50 +0100 | [diff] [blame] | 452 | return router; |
| 453 | |
| 454 | /* bonding: loop through the list of possible routers found |
| 455 | * for the various outgoing interfaces and find a candidate after |
| 456 | * the last chosen bonding candidate (next_candidate). If no such |
| 457 | * router is found, use the first candidate found (the previously |
| 458 | * chosen bonding candidate might have been the last one in the list). |
Antonio Quartulli | 3f68785 | 2014-11-02 11:29:56 +0100 | [diff] [blame] | 459 | * If this can't be found either, return the previously chosen |
Simon Wunderlich | f3b3d90 | 2013-11-13 19:14:50 +0100 | [diff] [blame] | 460 | * router - obviously there are no other candidates. |
| 461 | */ |
| 462 | rcu_read_lock(); |
| 463 | last_candidate = orig_node->last_bonding_candidate; |
| 464 | if (last_candidate) |
| 465 | last_cand_router = rcu_dereference(last_candidate->router); |
| 466 | |
| 467 | hlist_for_each_entry_rcu(cand, &orig_node->ifinfo_list, list) { |
| 468 | /* acquire some structures and references ... */ |
| 469 | if (!atomic_inc_not_zero(&cand->refcount)) |
| 470 | continue; |
| 471 | |
| 472 | cand_router = rcu_dereference(cand->router); |
| 473 | if (!cand_router) |
| 474 | goto next; |
| 475 | |
| 476 | if (!atomic_inc_not_zero(&cand_router->refcount)) { |
| 477 | cand_router = NULL; |
| 478 | goto next; |
| 479 | } |
| 480 | |
| 481 | /* alternative candidate should be good enough to be |
| 482 | * considered |
| 483 | */ |
| 484 | if (!bao->bat_neigh_is_equiv_or_better(cand_router, |
| 485 | cand->if_outgoing, |
| 486 | router, recv_if)) |
| 487 | goto next; |
| 488 | |
| 489 | /* don't use the same router twice */ |
| 490 | if (last_cand_router == cand_router) |
| 491 | goto next; |
| 492 | |
| 493 | /* mark the first possible candidate */ |
| 494 | if (!first_candidate) { |
| 495 | atomic_inc(&cand_router->refcount); |
| 496 | atomic_inc(&cand->refcount); |
| 497 | first_candidate = cand; |
| 498 | first_candidate_router = cand_router; |
| 499 | } |
| 500 | |
| 501 | /* check if the loop has already passed the previously selected |
| 502 | * candidate ... this function should select the next candidate |
| 503 | * AFTER the previously used bonding candidate. |
| 504 | */ |
| 505 | if (!last_candidate || last_candidate_found) { |
| 506 | next_candidate = cand; |
| 507 | next_candidate_router = cand_router; |
| 508 | break; |
| 509 | } |
| 510 | |
| 511 | if (last_candidate == cand) |
| 512 | last_candidate_found = true; |
| 513 | next: |
| 514 | /* free references */ |
| 515 | if (cand_router) { |
| 516 | batadv_neigh_node_free_ref(cand_router); |
| 517 | cand_router = NULL; |
| 518 | } |
| 519 | batadv_orig_ifinfo_free_ref(cand); |
| 520 | } |
| 521 | rcu_read_unlock(); |
| 522 | |
| 523 | /* last_bonding_candidate is reset below, remove the old reference. */ |
| 524 | if (orig_node->last_bonding_candidate) |
| 525 | batadv_orig_ifinfo_free_ref(orig_node->last_bonding_candidate); |
| 526 | |
| 527 | /* After finding candidates, handle the three cases: |
| 528 | * 1) there is a next candidate, use that |
| 529 | * 2) there is no next candidate, use the first of the list |
| 530 | * 3) there is no candidate at all, return the default router |
| 531 | */ |
| 532 | if (next_candidate) { |
| 533 | batadv_neigh_node_free_ref(router); |
| 534 | |
| 535 | /* remove references to first candidate, we don't need it. */ |
| 536 | if (first_candidate) { |
| 537 | batadv_neigh_node_free_ref(first_candidate_router); |
| 538 | batadv_orig_ifinfo_free_ref(first_candidate); |
| 539 | } |
| 540 | router = next_candidate_router; |
| 541 | orig_node->last_bonding_candidate = next_candidate; |
| 542 | } else if (first_candidate) { |
| 543 | batadv_neigh_node_free_ref(router); |
| 544 | |
| 545 | /* refcounting has already been done in the loop above. */ |
| 546 | router = first_candidate_router; |
| 547 | orig_node->last_bonding_candidate = first_candidate; |
| 548 | } else { |
| 549 | orig_node->last_bonding_candidate = NULL; |
| 550 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 551 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 552 | return router; |
| 553 | } |
| 554 | |
Sven Eckelmann | 63b0103 | 2012-05-16 20:23:13 +0200 | [diff] [blame] | 555 | static int batadv_route_unicast_packet(struct sk_buff *skb, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 556 | struct batadv_hard_iface *recv_if) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 557 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 558 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
| 559 | struct batadv_orig_node *orig_node = NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 560 | struct batadv_unicast_packet *unicast_packet; |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 561 | struct ethhdr *ethhdr = eth_hdr(skb); |
Simon Wunderlich | c54f38c | 2013-07-29 17:56:44 +0200 | [diff] [blame] | 562 | int res, hdr_len, ret = NET_RX_DROP; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 563 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 564 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 565 | |
| 566 | /* TTL exceeded */ |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 567 | if (unicast_packet->ttl < 2) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 568 | pr_debug("Warning - can't forward unicast packet from %pM to %pM: ttl exceeded\n", |
| 569 | ethhdr->h_source, unicast_packet->dest); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 570 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | /* get routing information */ |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 574 | orig_node = batadv_orig_hash_find(bat_priv, unicast_packet->dest); |
Marek Lindner | 7aadf88 | 2011-02-18 12:28:09 +0000 | [diff] [blame] | 575 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 576 | if (!orig_node) |
Antonio Quartulli | b5a6f69 | 2011-04-16 11:30:57 +0200 | [diff] [blame] | 577 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 578 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 579 | /* create a copy of the skb, if needed, to modify it. */ |
Antonio Quartulli | 0d12507 | 2012-02-18 11:27:34 +0100 | [diff] [blame] | 580 | if (skb_cow(skb, ETH_HLEN) < 0) |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 581 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 582 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 583 | /* decrement ttl */ |
Martin Hundebøll | f097e25 | 2013-05-23 16:53:01 +0200 | [diff] [blame] | 584 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 585 | unicast_packet->ttl--; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 586 | |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 587 | switch (unicast_packet->packet_type) { |
Simon Wunderlich | c54f38c | 2013-07-29 17:56:44 +0200 | [diff] [blame] | 588 | case BATADV_UNICAST_4ADDR: |
| 589 | hdr_len = sizeof(struct batadv_unicast_4addr_packet); |
| 590 | break; |
| 591 | case BATADV_UNICAST: |
| 592 | hdr_len = sizeof(struct batadv_unicast_packet); |
| 593 | break; |
| 594 | default: |
| 595 | /* other packet types not supported - yet */ |
| 596 | hdr_len = -1; |
| 597 | break; |
| 598 | } |
| 599 | |
| 600 | if (hdr_len > 0) |
| 601 | batadv_skb_set_priority(skb, hdr_len); |
| 602 | |
Martin Hundebøll | e91ecfc | 2013-04-20 13:54:39 +0200 | [diff] [blame] | 603 | res = batadv_send_skb_to_orig(skb, orig_node, recv_if); |
Martin Hundebøll | 9533247 | 2013-01-25 11:12:40 +0100 | [diff] [blame] | 604 | |
Martin Hundebøll | e91ecfc | 2013-04-20 13:54:39 +0200 | [diff] [blame] | 605 | /* translate transmit result into receive result */ |
| 606 | if (res == NET_XMIT_SUCCESS) { |
| 607 | /* skb was transmitted and consumed */ |
Martin Hundebøll | 9533247 | 2013-01-25 11:12:40 +0100 | [diff] [blame] | 608 | batadv_inc_counter(bat_priv, BATADV_CNT_FORWARD); |
| 609 | batadv_add_counter(bat_priv, BATADV_CNT_FORWARD_BYTES, |
| 610 | skb->len + ETH_HLEN); |
Martin Hundebøll | e91ecfc | 2013-04-20 13:54:39 +0200 | [diff] [blame] | 611 | |
| 612 | ret = NET_RX_SUCCESS; |
| 613 | } else if (res == NET_XMIT_POLICED) { |
| 614 | /* skb was buffered and consumed */ |
| 615 | ret = NET_RX_SUCCESS; |
Martin Hundebøll | 9533247 | 2013-01-25 11:12:40 +0100 | [diff] [blame] | 616 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 617 | |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 618 | out: |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 619 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 620 | batadv_orig_node_free_ref(orig_node); |
Marek Lindner | 44524fc | 2011-02-10 14:33:53 +0000 | [diff] [blame] | 621 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 624 | /** |
| 625 | * batadv_reroute_unicast_packet - update the unicast header for re-routing |
| 626 | * @bat_priv: the bat priv with all the soft interface information |
| 627 | * @unicast_packet: the unicast header to be updated |
| 628 | * @dst_addr: the payload destination |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 629 | * @vid: VLAN identifier |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 630 | * |
| 631 | * Search the translation table for dst_addr and update the unicast header with |
| 632 | * the new corresponding information (originator address where the destination |
| 633 | * client currently is and its known TTVN) |
| 634 | * |
| 635 | * Returns true if the packet header has been updated, false otherwise |
| 636 | */ |
| 637 | static bool |
| 638 | batadv_reroute_unicast_packet(struct batadv_priv *bat_priv, |
| 639 | struct batadv_unicast_packet *unicast_packet, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 640 | uint8_t *dst_addr, unsigned short vid) |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 641 | { |
| 642 | struct batadv_orig_node *orig_node = NULL; |
| 643 | struct batadv_hard_iface *primary_if = NULL; |
| 644 | bool ret = false; |
| 645 | uint8_t *orig_addr, orig_ttvn; |
| 646 | |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 647 | if (batadv_is_my_client(bat_priv, dst_addr, vid)) { |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 648 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 649 | if (!primary_if) |
| 650 | goto out; |
| 651 | orig_addr = primary_if->net_dev->dev_addr; |
| 652 | orig_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn); |
| 653 | } else { |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 654 | orig_node = batadv_transtable_search(bat_priv, NULL, dst_addr, |
| 655 | vid); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 656 | if (!orig_node) |
| 657 | goto out; |
| 658 | |
| 659 | if (batadv_compare_eth(orig_node->orig, unicast_packet->dest)) |
| 660 | goto out; |
| 661 | |
| 662 | orig_addr = orig_node->orig; |
| 663 | orig_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); |
| 664 | } |
| 665 | |
| 666 | /* update the packet header */ |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 667 | ether_addr_copy(unicast_packet->dest, orig_addr); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 668 | unicast_packet->ttvn = orig_ttvn; |
| 669 | |
| 670 | ret = true; |
| 671 | out: |
| 672 | if (primary_if) |
| 673 | batadv_hardif_free_ref(primary_if); |
| 674 | if (orig_node) |
| 675 | batadv_orig_node_free_ref(orig_node); |
| 676 | |
| 677 | return ret; |
| 678 | } |
| 679 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 680 | static int batadv_check_unicast_ttvn(struct batadv_priv *bat_priv, |
Antonio Quartulli | dd981ab | 2013-04-03 10:14:20 +0200 | [diff] [blame] | 681 | struct sk_buff *skb, int hdr_len) { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 682 | struct batadv_unicast_packet *unicast_packet; |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 683 | struct batadv_hard_iface *primary_if; |
| 684 | struct batadv_orig_node *orig_node; |
| 685 | uint8_t curr_ttvn, old_ttvn; |
| 686 | struct ethhdr *ethhdr; |
| 687 | unsigned short vid; |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 688 | int is_old_ttvn; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 689 | |
Antonio Quartulli | b8fcfa4 | 2012-08-26 23:25:59 +0200 | [diff] [blame] | 690 | /* check if there is enough data before accessing it */ |
Antonio Quartulli | f179142 | 2014-01-30 00:12:24 +0100 | [diff] [blame] | 691 | if (!pskb_may_pull(skb, hdr_len + ETH_HLEN)) |
Antonio Quartulli | b8fcfa4 | 2012-08-26 23:25:59 +0200 | [diff] [blame] | 692 | return 0; |
| 693 | |
| 694 | /* create a copy of the skb (in case of for re-routing) to modify it. */ |
| 695 | if (skb_cow(skb, sizeof(*unicast_packet)) < 0) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 696 | return 0; |
| 697 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 698 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 699 | vid = batadv_get_vid(skb, hdr_len); |
Antonio Quartulli | dd981ab | 2013-04-03 10:14:20 +0200 | [diff] [blame] | 700 | ethhdr = (struct ethhdr *)(skb->data + hdr_len); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 701 | |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 702 | /* check if the destination client was served by this node and it is now |
| 703 | * roaming. In this case, it means that the node has got a ROAM_ADV |
| 704 | * message and that it knows the new destination in the mesh to re-route |
| 705 | * the packet to |
| 706 | */ |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 707 | if (batadv_tt_local_client_is_roaming(bat_priv, ethhdr->h_dest, vid)) { |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 708 | if (batadv_reroute_unicast_packet(bat_priv, unicast_packet, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 709 | ethhdr->h_dest, vid)) |
André Gaul | 23c4ec1 | 2014-06-10 17:50:31 +0200 | [diff] [blame] | 710 | batadv_dbg_ratelimited(BATADV_DBG_TT, |
| 711 | bat_priv, |
| 712 | "Rerouting unicast packet to %pM (dst=%pM): Local Roaming\n", |
| 713 | unicast_packet->dest, |
| 714 | ethhdr->h_dest); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 715 | /* at this point the mesh destination should have been |
| 716 | * substituted with the originator address found in the global |
| 717 | * table. If not, let the packet go untouched anyway because |
| 718 | * there is nothing the node can do |
| 719 | */ |
| 720 | return 1; |
| 721 | } |
| 722 | |
| 723 | /* retrieve the TTVN known by this node for the packet destination. This |
| 724 | * value is used later to check if the node which sent (or re-routed |
| 725 | * last time) the packet had an updated information or not |
| 726 | */ |
| 727 | curr_ttvn = (uint8_t)atomic_read(&bat_priv->tt.vn); |
Antonio Quartulli | fe8a93b | 2013-04-03 19:10:26 +0200 | [diff] [blame] | 728 | if (!batadv_is_my_mac(bat_priv, unicast_packet->dest)) { |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 729 | orig_node = batadv_orig_hash_find(bat_priv, |
| 730 | unicast_packet->dest); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 731 | /* if it is not possible to find the orig_node representing the |
| 732 | * destination, the packet can immediately be dropped as it will |
| 733 | * not be possible to deliver it |
| 734 | */ |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 735 | if (!orig_node) |
| 736 | return 0; |
| 737 | |
| 738 | curr_ttvn = (uint8_t)atomic_read(&orig_node->last_ttvn); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 739 | batadv_orig_node_free_ref(orig_node); |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 740 | } |
| 741 | |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 742 | /* check if the TTVN contained in the packet is fresher than what the |
| 743 | * node knows |
| 744 | */ |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 745 | is_old_ttvn = batadv_seq_before(unicast_packet->ttvn, curr_ttvn); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 746 | if (!is_old_ttvn) |
| 747 | return 1; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 748 | |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 749 | old_ttvn = unicast_packet->ttvn; |
| 750 | /* the packet was forged based on outdated network information. Its |
| 751 | * destination can possibly be updated and forwarded towards the new |
| 752 | * target host |
| 753 | */ |
| 754 | if (batadv_reroute_unicast_packet(bat_priv, unicast_packet, |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 755 | ethhdr->h_dest, vid)) { |
André Gaul | 23c4ec1 | 2014-06-10 17:50:31 +0200 | [diff] [blame] | 756 | batadv_dbg_ratelimited(BATADV_DBG_TT, bat_priv, |
| 757 | "Rerouting unicast packet to %pM (dst=%pM): TTVN mismatch old_ttvn=%u new_ttvn=%u\n", |
| 758 | unicast_packet->dest, ethhdr->h_dest, |
| 759 | old_ttvn, curr_ttvn); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 760 | return 1; |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 761 | } |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 762 | |
| 763 | /* the packet has not been re-routed: either the destination is |
| 764 | * currently served by this node or there is no destination at all and |
| 765 | * it is possible to drop the packet |
| 766 | */ |
Antonio Quartulli | c018ad3 | 2013-06-04 12:11:39 +0200 | [diff] [blame] | 767 | if (!batadv_is_my_client(bat_priv, ethhdr->h_dest, vid)) |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 768 | return 0; |
| 769 | |
| 770 | /* update the header in order to let the packet be delivered to this |
| 771 | * node's soft interface |
| 772 | */ |
| 773 | primary_if = batadv_primary_if_get_selected(bat_priv); |
| 774 | if (!primary_if) |
| 775 | return 0; |
| 776 | |
Antonio Quartulli | 8fdd015 | 2014-01-22 00:42:11 +0100 | [diff] [blame] | 777 | ether_addr_copy(unicast_packet->dest, primary_if->net_dev->dev_addr); |
Antonio Quartulli | 7c1fd91 | 2012-09-23 22:38:34 +0200 | [diff] [blame] | 778 | |
| 779 | batadv_hardif_free_ref(primary_if); |
| 780 | |
| 781 | unicast_packet->ttvn = curr_ttvn; |
| 782 | |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 783 | return 1; |
| 784 | } |
| 785 | |
Simon Wunderlich | a1f1ac5 | 2013-04-25 10:37:23 +0200 | [diff] [blame] | 786 | /** |
| 787 | * batadv_recv_unhandled_unicast_packet - receive and process packets which |
| 788 | * are in the unicast number space but not yet known to the implementation |
| 789 | * @skb: unicast tvlv packet to process |
| 790 | * @recv_if: pointer to interface this packet was received on |
| 791 | * |
| 792 | * Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP |
| 793 | * otherwise. |
| 794 | */ |
| 795 | int batadv_recv_unhandled_unicast_packet(struct sk_buff *skb, |
| 796 | struct batadv_hard_iface *recv_if) |
| 797 | { |
| 798 | struct batadv_unicast_packet *unicast_packet; |
| 799 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
| 800 | int check, hdr_size = sizeof(*unicast_packet); |
| 801 | |
| 802 | check = batadv_check_unicast_packet(bat_priv, skb, hdr_size); |
| 803 | if (check < 0) |
| 804 | return NET_RX_DROP; |
| 805 | |
| 806 | /* we don't know about this type, drop it. */ |
| 807 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
| 808 | if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) |
| 809 | return NET_RX_DROP; |
| 810 | |
| 811 | return batadv_route_unicast_packet(skb, recv_if); |
| 812 | } |
| 813 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 814 | int batadv_recv_unicast_packet(struct sk_buff *skb, |
| 815 | struct batadv_hard_iface *recv_if) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 816 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 817 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 818 | struct batadv_unicast_packet *unicast_packet; |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 819 | struct batadv_unicast_4addr_packet *unicast_4addr_packet; |
Antonio Quartulli | 9affec6 | 2012-10-14 17:19:19 +0200 | [diff] [blame] | 820 | uint8_t *orig_addr; |
| 821 | struct batadv_orig_node *orig_node = NULL; |
Martin Hundebøll | 612d2b4 | 2013-01-25 11:12:42 +0100 | [diff] [blame] | 822 | int check, hdr_size = sizeof(*unicast_packet); |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 823 | bool is4addr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 824 | |
Antonio Quartulli | 7cdcf6d | 2012-10-01 09:57:35 +0200 | [diff] [blame] | 825 | unicast_packet = (struct batadv_unicast_packet *)skb->data; |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 826 | unicast_4addr_packet = (struct batadv_unicast_4addr_packet *)skb->data; |
Antonio Quartulli | 7cdcf6d | 2012-10-01 09:57:35 +0200 | [diff] [blame] | 827 | |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 828 | is4addr = unicast_packet->packet_type == BATADV_UNICAST_4ADDR; |
Antonio Quartulli | 7cdcf6d | 2012-10-01 09:57:35 +0200 | [diff] [blame] | 829 | /* the caller function should have already pulled 2 bytes */ |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 830 | if (is4addr) |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 831 | hdr_size = sizeof(*unicast_4addr_packet); |
Antonio Quartulli | 7cdcf6d | 2012-10-01 09:57:35 +0200 | [diff] [blame] | 832 | |
Martin Hundebøll | 612d2b4 | 2013-01-25 11:12:42 +0100 | [diff] [blame] | 833 | /* function returns -EREMOTE for promiscuous packets */ |
David S. Miller | 6e0895c | 2013-04-22 20:32:51 -0400 | [diff] [blame] | 834 | check = batadv_check_unicast_packet(bat_priv, skb, hdr_size); |
Martin Hundebøll | 612d2b4 | 2013-01-25 11:12:42 +0100 | [diff] [blame] | 835 | |
| 836 | /* Even though the packet is not for us, we might save it to use for |
| 837 | * decoding a later received coded packet |
| 838 | */ |
| 839 | if (check == -EREMOTE) |
| 840 | batadv_nc_skb_store_sniffed_unicast(bat_priv, skb); |
| 841 | |
| 842 | if (check < 0) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 843 | return NET_RX_DROP; |
Antonio Quartulli | dd981ab | 2013-04-03 10:14:20 +0200 | [diff] [blame] | 844 | if (!batadv_check_unicast_ttvn(bat_priv, skb, hdr_size)) |
Antonio Quartulli | a73105b | 2011-04-27 14:27:44 +0200 | [diff] [blame] | 845 | return NET_RX_DROP; |
| 846 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 847 | /* packet for me */ |
Antonio Quartulli | fe8a93b | 2013-04-03 19:10:26 +0200 | [diff] [blame] | 848 | if (batadv_is_my_mac(bat_priv, unicast_packet->dest)) { |
Antonio Quartulli | 9affec6 | 2012-10-14 17:19:19 +0200 | [diff] [blame] | 849 | if (is4addr) { |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 850 | batadv_dat_inc_counter(bat_priv, |
| 851 | unicast_4addr_packet->subtype); |
Antonio Quartulli | 9affec6 | 2012-10-14 17:19:19 +0200 | [diff] [blame] | 852 | orig_addr = unicast_4addr_packet->src; |
| 853 | orig_node = batadv_orig_hash_find(bat_priv, orig_addr); |
| 854 | } |
Martin Hundebøll | 4046b24 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 855 | |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 856 | if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, |
| 857 | hdr_size)) |
| 858 | goto rx_success; |
| 859 | if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, |
| 860 | hdr_size)) |
| 861 | goto rx_success; |
| 862 | |
Antonio Quartulli | 3713517 | 2012-07-05 23:38:30 +0200 | [diff] [blame] | 863 | batadv_interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size, |
Antonio Quartulli | 9affec6 | 2012-10-14 17:19:19 +0200 | [diff] [blame] | 864 | orig_node); |
Antonio Quartulli | 3713517 | 2012-07-05 23:38:30 +0200 | [diff] [blame] | 865 | |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 866 | rx_success: |
Antonio Quartulli | 9affec6 | 2012-10-14 17:19:19 +0200 | [diff] [blame] | 867 | if (orig_node) |
| 868 | batadv_orig_node_free_ref(orig_node); |
| 869 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 870 | return NET_RX_SUCCESS; |
| 871 | } |
| 872 | |
Sven Eckelmann | 63b0103 | 2012-05-16 20:23:13 +0200 | [diff] [blame] | 873 | return batadv_route_unicast_packet(skb, recv_if); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 874 | } |
| 875 | |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 876 | /** |
| 877 | * batadv_recv_unicast_tvlv - receive and process unicast tvlv packets |
| 878 | * @skb: unicast tvlv packet to process |
| 879 | * @recv_if: pointer to interface this packet was received on |
| 880 | * @dst_addr: the payload destination |
| 881 | * |
| 882 | * Returns NET_RX_SUCCESS if the packet has been consumed or NET_RX_DROP |
| 883 | * otherwise. |
| 884 | */ |
| 885 | int batadv_recv_unicast_tvlv(struct sk_buff *skb, |
| 886 | struct batadv_hard_iface *recv_if) |
| 887 | { |
| 888 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
| 889 | struct batadv_unicast_tvlv_packet *unicast_tvlv_packet; |
| 890 | unsigned char *tvlv_buff; |
| 891 | uint16_t tvlv_buff_len; |
| 892 | int hdr_size = sizeof(*unicast_tvlv_packet); |
| 893 | int ret = NET_RX_DROP; |
| 894 | |
| 895 | if (batadv_check_unicast_packet(bat_priv, skb, hdr_size) < 0) |
| 896 | return NET_RX_DROP; |
| 897 | |
| 898 | /* the header is likely to be modified while forwarding */ |
| 899 | if (skb_cow(skb, hdr_size) < 0) |
| 900 | return NET_RX_DROP; |
| 901 | |
| 902 | /* packet needs to be linearized to access the tvlv content */ |
| 903 | if (skb_linearize(skb) < 0) |
| 904 | return NET_RX_DROP; |
| 905 | |
| 906 | unicast_tvlv_packet = (struct batadv_unicast_tvlv_packet *)skb->data; |
| 907 | |
| 908 | tvlv_buff = (unsigned char *)(skb->data + hdr_size); |
| 909 | tvlv_buff_len = ntohs(unicast_tvlv_packet->tvlv_len); |
| 910 | |
| 911 | if (tvlv_buff_len > skb->len - hdr_size) |
| 912 | return NET_RX_DROP; |
| 913 | |
| 914 | ret = batadv_tvlv_containers_process(bat_priv, false, NULL, |
| 915 | unicast_tvlv_packet->src, |
| 916 | unicast_tvlv_packet->dst, |
| 917 | tvlv_buff, tvlv_buff_len); |
| 918 | |
| 919 | if (ret != NET_RX_SUCCESS) |
| 920 | ret = batadv_route_unicast_packet(skb, recv_if); |
Antonio Quartulli | 05c3c8a | 2014-02-11 17:05:07 +0100 | [diff] [blame] | 921 | else |
| 922 | consume_skb(skb); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 923 | |
| 924 | return ret; |
| 925 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 926 | |
Martin Hundebøll | 610bfc6bc | 2013-05-23 16:53:02 +0200 | [diff] [blame] | 927 | /** |
| 928 | * batadv_recv_frag_packet - process received fragment |
| 929 | * @skb: the received fragment |
| 930 | * @recv_if: interface that the skb is received on |
| 931 | * |
| 932 | * This function does one of the three following things: 1) Forward fragment, if |
| 933 | * the assembled packet will exceed our MTU; 2) Buffer fragment, if we till |
| 934 | * lack further fragments; 3) Merge fragments, if we have all needed parts. |
| 935 | * |
| 936 | * Return NET_RX_DROP if the skb is not consumed, NET_RX_SUCCESS otherwise. |
| 937 | */ |
| 938 | int batadv_recv_frag_packet(struct sk_buff *skb, |
| 939 | struct batadv_hard_iface *recv_if) |
| 940 | { |
| 941 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
| 942 | struct batadv_orig_node *orig_node_src = NULL; |
| 943 | struct batadv_frag_packet *frag_packet; |
| 944 | int ret = NET_RX_DROP; |
| 945 | |
| 946 | if (batadv_check_unicast_packet(bat_priv, skb, |
| 947 | sizeof(*frag_packet)) < 0) |
| 948 | goto out; |
| 949 | |
| 950 | frag_packet = (struct batadv_frag_packet *)skb->data; |
| 951 | orig_node_src = batadv_orig_hash_find(bat_priv, frag_packet->orig); |
| 952 | if (!orig_node_src) |
| 953 | goto out; |
| 954 | |
| 955 | /* Route the fragment if it is not for us and too big to be merged. */ |
| 956 | if (!batadv_is_my_mac(bat_priv, frag_packet->dest) && |
| 957 | batadv_frag_skb_fwd(skb, recv_if, orig_node_src)) { |
| 958 | ret = NET_RX_SUCCESS; |
| 959 | goto out; |
| 960 | } |
| 961 | |
| 962 | batadv_inc_counter(bat_priv, BATADV_CNT_FRAG_RX); |
| 963 | batadv_add_counter(bat_priv, BATADV_CNT_FRAG_RX_BYTES, skb->len); |
| 964 | |
| 965 | /* Add fragment to buffer and merge if possible. */ |
| 966 | if (!batadv_frag_skb_buffer(&skb, orig_node_src)) |
| 967 | goto out; |
| 968 | |
| 969 | /* Deliver merged packet to the appropriate handler, if it was |
| 970 | * merged |
| 971 | */ |
| 972 | if (skb) |
| 973 | batadv_batman_skb_recv(skb, recv_if->net_dev, |
| 974 | &recv_if->batman_adv_ptype, NULL); |
| 975 | |
| 976 | ret = NET_RX_SUCCESS; |
| 977 | |
| 978 | out: |
| 979 | if (orig_node_src) |
| 980 | batadv_orig_node_free_ref(orig_node_src); |
| 981 | |
| 982 | return ret; |
| 983 | } |
| 984 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 985 | int batadv_recv_bcast_packet(struct sk_buff *skb, |
| 986 | struct batadv_hard_iface *recv_if) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 987 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 988 | struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); |
| 989 | struct batadv_orig_node *orig_node = NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 990 | struct batadv_bcast_packet *bcast_packet; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 991 | struct ethhdr *ethhdr; |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 992 | int hdr_size = sizeof(*bcast_packet); |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 993 | int ret = NET_RX_DROP; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 994 | int32_t seq_diff; |
Antonio Quartulli | 3fba732 | 2013-10-13 02:50:17 +0200 | [diff] [blame] | 995 | uint32_t seqno; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 996 | |
| 997 | /* drop packet if it has not necessary minimum size */ |
| 998 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 999 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1000 | |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 1001 | ethhdr = eth_hdr(skb); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1002 | |
| 1003 | /* packet with broadcast indication but unicast recipient */ |
| 1004 | if (!is_broadcast_ether_addr(ethhdr->h_dest)) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1005 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1006 | |
| 1007 | /* packet with broadcast sender address */ |
| 1008 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1009 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1010 | |
| 1011 | /* ignore broadcasts sent by myself */ |
Antonio Quartulli | fe8a93b | 2013-04-03 19:10:26 +0200 | [diff] [blame] | 1012 | if (batadv_is_my_mac(bat_priv, ethhdr->h_source)) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1013 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1014 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1015 | bcast_packet = (struct batadv_bcast_packet *)skb->data; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1016 | |
| 1017 | /* ignore broadcasts originated by myself */ |
Antonio Quartulli | fe8a93b | 2013-04-03 19:10:26 +0200 | [diff] [blame] | 1018 | if (batadv_is_my_mac(bat_priv, bcast_packet->orig)) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1019 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1020 | |
Simon Wunderlich | a40d9b0 | 2013-12-02 20:38:31 +0100 | [diff] [blame] | 1021 | if (bcast_packet->ttl < 2) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1022 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1023 | |
Sven Eckelmann | da64119 | 2012-05-12 13:48:56 +0200 | [diff] [blame] | 1024 | orig_node = batadv_orig_hash_find(bat_priv, bcast_packet->orig); |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1025 | |
| 1026 | if (!orig_node) |
Antonio Quartulli | b5a6f69 | 2011-04-16 11:30:57 +0200 | [diff] [blame] | 1027 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1028 | |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1029 | spin_lock_bh(&orig_node->bcast_seqno_lock); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1030 | |
Antonio Quartulli | 3fba732 | 2013-10-13 02:50:17 +0200 | [diff] [blame] | 1031 | seqno = ntohl(bcast_packet->seqno); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1032 | /* check whether the packet is a duplicate */ |
Sven Eckelmann | 9b4a115 | 2012-05-12 13:48:53 +0200 | [diff] [blame] | 1033 | if (batadv_test_bit(orig_node->bcast_bits, orig_node->last_bcast_seqno, |
Antonio Quartulli | 3fba732 | 2013-10-13 02:50:17 +0200 | [diff] [blame] | 1034 | seqno)) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1035 | goto spin_unlock; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1036 | |
Antonio Quartulli | 3fba732 | 2013-10-13 02:50:17 +0200 | [diff] [blame] | 1037 | seq_diff = seqno - orig_node->last_bcast_seqno; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1038 | |
| 1039 | /* check whether the packet is old and the host just restarted. */ |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 1040 | if (batadv_window_protected(bat_priv, seq_diff, |
| 1041 | &orig_node->bcast_seqno_reset)) |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1042 | goto spin_unlock; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1043 | |
| 1044 | /* mark broadcast in flood history, update window position |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1045 | * if required. |
| 1046 | */ |
Sven Eckelmann | 0f5f932 | 2012-05-12 02:09:25 +0200 | [diff] [blame] | 1047 | if (batadv_bit_get_packet(bat_priv, orig_node->bcast_bits, seq_diff, 1)) |
Antonio Quartulli | 3fba732 | 2013-10-13 02:50:17 +0200 | [diff] [blame] | 1048 | orig_node->last_bcast_seqno = seqno; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1049 | |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1050 | spin_unlock_bh(&orig_node->bcast_seqno_lock); |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1051 | |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1052 | /* check whether this has been sent by another originator before */ |
Simon Wunderlich | 004e86f | 2012-10-18 13:47:42 +0200 | [diff] [blame] | 1053 | if (batadv_bla_check_bcast_duplist(bat_priv, skb)) |
Simon Wunderlich | fe2da6f | 2012-01-22 20:00:24 +0100 | [diff] [blame] | 1054 | goto out; |
| 1055 | |
Simon Wunderlich | c54f38c | 2013-07-29 17:56:44 +0200 | [diff] [blame] | 1056 | batadv_skb_set_priority(skb, sizeof(struct batadv_bcast_packet)); |
| 1057 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1058 | /* rebroadcast packet */ |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 1059 | batadv_add_bcast_packet_to_list(bat_priv, skb, 1); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1060 | |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1061 | /* don't hand the broadcast up if it is from an originator |
| 1062 | * from the same backbone. |
| 1063 | */ |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 1064 | if (batadv_bla_is_backbone_gw(skb, orig_node, hdr_size)) |
Simon Wunderlich | 2372138 | 2012-01-22 20:00:19 +0100 | [diff] [blame] | 1065 | goto out; |
| 1066 | |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 1067 | if (batadv_dat_snoop_incoming_arp_request(bat_priv, skb, hdr_size)) |
| 1068 | goto rx_success; |
| 1069 | if (batadv_dat_snoop_incoming_arp_reply(bat_priv, skb, hdr_size)) |
| 1070 | goto rx_success; |
| 1071 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1072 | /* broadcast for me */ |
Antonio Quartulli | 3713517 | 2012-07-05 23:38:30 +0200 | [diff] [blame] | 1073 | batadv_interface_rx(recv_if->soft_iface, skb, recv_if, hdr_size, |
| 1074 | orig_node); |
Antonio Quartulli | c384ea3 | 2011-06-26 03:37:18 +0200 | [diff] [blame] | 1075 | |
| 1076 | rx_success: |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1077 | ret = NET_RX_SUCCESS; |
| 1078 | goto out; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1079 | |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1080 | spin_unlock: |
| 1081 | spin_unlock_bh(&orig_node->bcast_seqno_lock); |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1082 | out: |
| 1083 | if (orig_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1084 | batadv_orig_node_free_ref(orig_node); |
Marek Lindner | f3e0008 | 2011-01-25 21:52:11 +0000 | [diff] [blame] | 1085 | return ret; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 1086 | } |