Antonio Quartulli | 0b87393 | 2013-01-04 03:05:31 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2007-2013 B.A.T.M.A.N. contributors: |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [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 |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 | * 02110-1301, USA |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "main.h" |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 21 | #include "translation-table.h" |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 22 | #include "originator.h" |
| 23 | #include "routing.h" |
| 24 | #include "gateway_common.h" |
| 25 | #include "gateway_client.h" |
| 26 | #include "hard-interface.h" |
| 27 | #include "send.h" |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 28 | #include "bat_algo.h" |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 29 | #include "network-coding.h" |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 30 | |
Antonio Quartulli | 791c2a2 | 2013-08-17 12:44:44 +0200 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * batadv_dup_status - duplicate status |
| 34 | * @BATADV_NO_DUP: the packet is a duplicate |
| 35 | * @BATADV_ORIG_DUP: OGM is a duplicate in the originator (but not for the |
| 36 | * neighbor) |
| 37 | * @BATADV_NEIGH_DUP: OGM is a duplicate for the neighbor |
| 38 | * @BATADV_PROTECTED: originator is currently protected (after reboot) |
| 39 | */ |
| 40 | enum batadv_dup_status { |
| 41 | BATADV_NO_DUP = 0, |
| 42 | BATADV_ORIG_DUP, |
| 43 | BATADV_NEIGH_DUP, |
| 44 | BATADV_PROTECTED, |
| 45 | }; |
| 46 | |
Antonio Quartulli | 24a5dee | 2013-04-08 09:38:12 +0200 | [diff] [blame] | 47 | /** |
| 48 | * batadv_ring_buffer_set - update the ring buffer with the given value |
| 49 | * @lq_recv: pointer to the ring buffer |
| 50 | * @lq_index: index to store the value at |
| 51 | * @value: value to store in the ring buffer |
| 52 | */ |
| 53 | static void batadv_ring_buffer_set(uint8_t lq_recv[], uint8_t *lq_index, |
| 54 | uint8_t value) |
| 55 | { |
| 56 | lq_recv[*lq_index] = value; |
| 57 | *lq_index = (*lq_index + 1) % BATADV_TQ_GLOBAL_WINDOW_SIZE; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * batadv_ring_buffer_set - compute the average of all non-zero values stored |
| 62 | * in the given ring buffer |
| 63 | * @lq_recv: pointer to the ring buffer |
| 64 | * |
| 65 | * Returns computed average value. |
| 66 | */ |
| 67 | static uint8_t batadv_ring_buffer_avg(const uint8_t lq_recv[]) |
| 68 | { |
| 69 | const uint8_t *ptr; |
| 70 | uint16_t count = 0, i = 0, sum = 0; |
| 71 | |
| 72 | ptr = lq_recv; |
| 73 | |
| 74 | while (i < BATADV_TQ_GLOBAL_WINDOW_SIZE) { |
| 75 | if (*ptr != 0) { |
| 76 | count++; |
| 77 | sum += *ptr; |
| 78 | } |
| 79 | |
| 80 | i++; |
| 81 | ptr++; |
| 82 | } |
| 83 | |
| 84 | if (count == 0) |
| 85 | return 0; |
| 86 | |
| 87 | return (uint8_t)(sum / count); |
| 88 | } |
David S. Miller | d98cae64e | 2013-06-19 16:49:39 -0700 | [diff] [blame] | 89 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 90 | /** |
| 91 | * batadv_iv_ogm_orig_get - retrieve or create (if does not exist) an originator |
| 92 | * @bat_priv: the bat priv with all the soft interface information |
| 93 | * @addr: mac address of the originator |
| 94 | * |
| 95 | * Returns the originator object corresponding to the passed mac address or NULL |
| 96 | * on failure. |
| 97 | * If the object does not exists it is created an initialised. |
| 98 | */ |
| 99 | static struct batadv_orig_node * |
| 100 | batadv_iv_ogm_orig_get(struct batadv_priv *bat_priv, const uint8_t *addr) |
| 101 | { |
| 102 | struct batadv_orig_node *orig_node; |
| 103 | int size, hash_added; |
| 104 | |
| 105 | orig_node = batadv_orig_hash_find(bat_priv, addr); |
| 106 | if (orig_node) |
| 107 | return orig_node; |
| 108 | |
| 109 | orig_node = batadv_orig_node_new(bat_priv, addr); |
| 110 | if (!orig_node) |
| 111 | return NULL; |
| 112 | |
| 113 | spin_lock_init(&orig_node->bat_iv.ogm_cnt_lock); |
| 114 | |
| 115 | size = bat_priv->num_ifaces * sizeof(unsigned long) * BATADV_NUM_WORDS; |
| 116 | orig_node->bat_iv.bcast_own = kzalloc(size, GFP_ATOMIC); |
| 117 | if (!orig_node->bat_iv.bcast_own) |
| 118 | goto free_orig_node; |
| 119 | |
| 120 | size = bat_priv->num_ifaces * sizeof(uint8_t); |
| 121 | orig_node->bat_iv.bcast_own_sum = kzalloc(size, GFP_ATOMIC); |
| 122 | if (!orig_node->bat_iv.bcast_own_sum) |
| 123 | goto free_bcast_own; |
| 124 | |
| 125 | hash_added = batadv_hash_add(bat_priv->orig_hash, batadv_compare_orig, |
| 126 | batadv_choose_orig, orig_node, |
| 127 | &orig_node->hash_entry); |
| 128 | if (hash_added != 0) |
| 129 | goto free_bcast_own; |
| 130 | |
| 131 | return orig_node; |
| 132 | |
| 133 | free_bcast_own: |
| 134 | kfree(orig_node->bat_iv.bcast_own); |
| 135 | free_orig_node: |
| 136 | batadv_orig_node_free_ref(orig_node); |
| 137 | |
| 138 | return NULL; |
| 139 | } |
| 140 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 141 | static struct batadv_neigh_node * |
| 142 | batadv_iv_ogm_neigh_new(struct batadv_hard_iface *hard_iface, |
| 143 | const uint8_t *neigh_addr, |
| 144 | struct batadv_orig_node *orig_node, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 145 | struct batadv_orig_node *orig_neigh) |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 146 | { |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 147 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 148 | struct batadv_neigh_node *neigh_node; |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 149 | |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 150 | neigh_node = batadv_neigh_node_new(hard_iface, neigh_addr, orig_node); |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 151 | if (!neigh_node) |
| 152 | goto out; |
| 153 | |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 154 | spin_lock_init(&neigh_node->bat_iv.lq_update_lock); |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 155 | |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 156 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
| 157 | "Creating new neighbor %pM for orig_node %pM on interface %s\n", |
| 158 | neigh_addr, orig_node->orig, hard_iface->net_dev->name); |
Marek Lindner | 7ae8b28 | 2012-03-01 15:35:21 +0800 | [diff] [blame] | 159 | |
| 160 | spin_lock_bh(&orig_node->neigh_list_lock); |
| 161 | hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); |
| 162 | spin_unlock_bh(&orig_node->neigh_list_lock); |
| 163 | |
| 164 | out: |
| 165 | return neigh_node; |
| 166 | } |
| 167 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 168 | static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface) |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 169 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 170 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 171 | unsigned char *ogm_buff; |
Marek Lindner | d7d32ec | 2012-02-07 17:20:46 +0800 | [diff] [blame] | 172 | uint32_t random_seqno; |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 173 | int res = -ENOMEM; |
Marek Lindner | d7d32ec | 2012-02-07 17:20:46 +0800 | [diff] [blame] | 174 | |
| 175 | /* randomize initial seqno to avoid collision */ |
| 176 | get_random_bytes(&random_seqno, sizeof(random_seqno)); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 177 | atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno); |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 178 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 179 | hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN; |
| 180 | ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC); |
| 181 | if (!ogm_buff) |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 182 | goto out; |
| 183 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 184 | hard_iface->bat_iv.ogm_buff = ogm_buff; |
| 185 | |
| 186 | batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 187 | batadv_ogm_packet->header.packet_type = BATADV_IV_OGM; |
| 188 | batadv_ogm_packet->header.version = BATADV_COMPAT_VERSION; |
| 189 | batadv_ogm_packet->header.ttl = 2; |
| 190 | batadv_ogm_packet->flags = BATADV_NO_FLAGS; |
Marek Lindner | 414254e | 2013-04-23 21:39:58 +0800 | [diff] [blame] | 191 | batadv_ogm_packet->reserved = 0; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 192 | batadv_ogm_packet->tq = BATADV_TQ_MAX_VALUE; |
Marek Lindner | 77af757 | 2012-02-07 17:20:48 +0800 | [diff] [blame] | 193 | |
| 194 | res = 0; |
| 195 | |
| 196 | out: |
| 197 | return res; |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 198 | } |
| 199 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 200 | static void batadv_iv_ogm_iface_disable(struct batadv_hard_iface *hard_iface) |
Marek Lindner | 00a5007 | 2012-02-07 17:20:47 +0800 | [diff] [blame] | 201 | { |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 202 | kfree(hard_iface->bat_iv.ogm_buff); |
| 203 | hard_iface->bat_iv.ogm_buff = NULL; |
Marek Lindner | 00a5007 | 2012-02-07 17:20:47 +0800 | [diff] [blame] | 204 | } |
| 205 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 206 | static void batadv_iv_ogm_iface_update_mac(struct batadv_hard_iface *hard_iface) |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 207 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 208 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 209 | unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 210 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 211 | batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 212 | memcpy(batadv_ogm_packet->orig, |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 213 | hard_iface->net_dev->dev_addr, ETH_ALEN); |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 214 | memcpy(batadv_ogm_packet->prev_sender, |
Marek Lindner | d0b9fd8 | 2011-07-30 12:33:33 +0200 | [diff] [blame] | 215 | hard_iface->net_dev->dev_addr, ETH_ALEN); |
| 216 | } |
| 217 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 218 | static void |
| 219 | batadv_iv_ogm_primary_iface_set(struct batadv_hard_iface *hard_iface) |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 220 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 221 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 222 | unsigned char *ogm_buff = hard_iface->bat_iv.ogm_buff; |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 223 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 224 | batadv_ogm_packet = (struct batadv_ogm_packet *)ogm_buff; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 225 | batadv_ogm_packet->flags = BATADV_PRIMARIES_FIRST_HOP; |
| 226 | batadv_ogm_packet->header.ttl = BATADV_TTL; |
Marek Lindner | c322939 | 2012-03-11 06:17:50 +0800 | [diff] [blame] | 227 | } |
| 228 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 229 | /* when do we schedule our own ogm to be sent */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 230 | static unsigned long |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 231 | batadv_iv_ogm_emit_send_time(const struct batadv_priv *bat_priv) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 232 | { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 233 | unsigned int msecs; |
| 234 | |
| 235 | msecs = atomic_read(&bat_priv->orig_interval) - BATADV_JITTER; |
Akinobu Mita | e76e432 | 2012-12-24 11:14:07 +0900 | [diff] [blame] | 236 | msecs += prandom_u32() % (2 * BATADV_JITTER); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 237 | |
| 238 | return jiffies + msecs_to_jiffies(msecs); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | /* when do we schedule a ogm packet to be sent */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 242 | static unsigned long batadv_iv_ogm_fwd_send_time(void) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 243 | { |
Akinobu Mita | e76e432 | 2012-12-24 11:14:07 +0900 | [diff] [blame] | 244 | return jiffies + msecs_to_jiffies(prandom_u32() % (BATADV_JITTER / 2)); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | /* apply hop penalty for a normal link */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 248 | static uint8_t batadv_hop_penalty(uint8_t tq, |
| 249 | const struct batadv_priv *bat_priv) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 250 | { |
| 251 | int hop_penalty = atomic_read(&bat_priv->hop_penalty); |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 252 | int new_tq; |
| 253 | |
| 254 | new_tq = tq * (BATADV_TQ_MAX_VALUE - hop_penalty); |
| 255 | new_tq /= BATADV_TQ_MAX_VALUE; |
| 256 | |
| 257 | return new_tq; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 258 | } |
| 259 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 260 | /* is there another aggregated packet here? */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 261 | static int batadv_iv_ogm_aggr_packet(int buff_pos, int packet_len, |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 262 | __be16 tvlv_len) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 263 | { |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 264 | int next_buff_pos = 0; |
| 265 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 266 | next_buff_pos += buff_pos + BATADV_OGM_HLEN; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 267 | next_buff_pos += ntohs(tvlv_len); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 268 | |
| 269 | return (next_buff_pos <= packet_len) && |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 270 | (next_buff_pos <= BATADV_MAX_AGGREGATION_BYTES); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 271 | } |
| 272 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 273 | /* send a batman ogm to a given interface */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 274 | static void batadv_iv_ogm_send_to_if(struct batadv_forw_packet *forw_packet, |
| 275 | struct batadv_hard_iface *hard_iface) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 276 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 277 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 278 | char *fwd_str; |
| 279 | uint8_t packet_num; |
| 280 | int16_t buff_pos; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 281 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 282 | struct sk_buff *skb; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 283 | uint8_t *packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 284 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 285 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 286 | return; |
| 287 | |
| 288 | packet_num = 0; |
| 289 | buff_pos = 0; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 290 | packet_pos = forw_packet->skb->data; |
| 291 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 292 | |
| 293 | /* adjust all flags and log packets */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 294 | while (batadv_iv_ogm_aggr_packet(buff_pos, forw_packet->packet_len, |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 295 | batadv_ogm_packet->tvlv_len)) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 296 | /* we might have aggregated direct link packets with an |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 297 | * ordinary base packet |
| 298 | */ |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 299 | if (forw_packet->direct_link_flags & BIT(packet_num) && |
| 300 | forw_packet->if_incoming == hard_iface) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 301 | batadv_ogm_packet->flags |= BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 302 | else |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 303 | batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 304 | |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 305 | if (packet_num > 0 || !forw_packet->own) |
| 306 | fwd_str = "Forwarding"; |
| 307 | else |
| 308 | fwd_str = "Sending own"; |
| 309 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 310 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 311 | "%s %spacket (originator %pM, seqno %u, TQ %d, TTL %d, IDF %s) on interface %s [%pM]\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 312 | fwd_str, (packet_num > 0 ? "aggregated " : ""), |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 313 | batadv_ogm_packet->orig, |
| 314 | ntohl(batadv_ogm_packet->seqno), |
| 315 | batadv_ogm_packet->tq, batadv_ogm_packet->header.ttl, |
| 316 | (batadv_ogm_packet->flags & BATADV_DIRECTLINK ? |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 317 | "on" : "off"), |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 318 | hard_iface->net_dev->name, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 319 | hard_iface->net_dev->dev_addr); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 320 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 321 | buff_pos += BATADV_OGM_HLEN; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 322 | buff_pos += ntohs(batadv_ogm_packet->tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 323 | packet_num++; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 324 | packet_pos = forw_packet->skb->data + buff_pos; |
| 325 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 326 | } |
| 327 | |
| 328 | /* create clone because function is called more than once */ |
| 329 | skb = skb_clone(forw_packet->skb, GFP_ATOMIC); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 330 | if (skb) { |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 331 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_TX); |
| 332 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_TX_BYTES, |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 333 | skb->len + ETH_HLEN); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 334 | batadv_send_skb_packet(skb, hard_iface, batadv_broadcast_addr); |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 335 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | /* send a batman ogm packet */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 339 | static void batadv_iv_ogm_emit(struct batadv_forw_packet *forw_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 340 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 341 | struct batadv_hard_iface *hard_iface; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 342 | struct net_device *soft_iface; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 343 | struct batadv_priv *bat_priv; |
| 344 | struct batadv_hard_iface *primary_if = NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 345 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 346 | unsigned char directlink; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 347 | uint8_t *packet_pos; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 348 | |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 349 | packet_pos = forw_packet->skb->data; |
| 350 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 351 | directlink = (batadv_ogm_packet->flags & BATADV_DIRECTLINK ? 1 : 0); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 352 | |
| 353 | if (!forw_packet->if_incoming) { |
Sven Eckelmann | 86ceb36 | 2012-03-07 09:07:45 +0100 | [diff] [blame] | 354 | pr_err("Error - can't forward packet: incoming iface not specified\n"); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 355 | goto out; |
| 356 | } |
| 357 | |
| 358 | soft_iface = forw_packet->if_incoming->soft_iface; |
| 359 | bat_priv = netdev_priv(soft_iface); |
| 360 | |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 361 | if (forw_packet->if_incoming->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 362 | goto out; |
| 363 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 364 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 365 | if (!primary_if) |
| 366 | goto out; |
| 367 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 368 | /* multihomed peer assumed |
| 369 | * non-primary OGMs are only broadcasted on their interface |
| 370 | */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 371 | if ((directlink && (batadv_ogm_packet->header.ttl == 1)) || |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 372 | (forw_packet->own && (forw_packet->if_incoming != primary_if))) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 373 | /* FIXME: what about aggregated packets ? */ |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 374 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 375 | "%s packet (originator %pM, seqno %u, TTL %d) on interface %s [%pM]\n", |
| 376 | (forw_packet->own ? "Sending own" : "Forwarding"), |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 377 | batadv_ogm_packet->orig, |
| 378 | ntohl(batadv_ogm_packet->seqno), |
| 379 | batadv_ogm_packet->header.ttl, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 380 | forw_packet->if_incoming->net_dev->name, |
| 381 | forw_packet->if_incoming->net_dev->dev_addr); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 382 | |
| 383 | /* skb is only used once and than forw_packet is free'd */ |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 384 | batadv_send_skb_packet(forw_packet->skb, |
| 385 | forw_packet->if_incoming, |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 386 | batadv_broadcast_addr); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 387 | forw_packet->skb = NULL; |
| 388 | |
| 389 | goto out; |
| 390 | } |
| 391 | |
| 392 | /* broadcast on every interface */ |
| 393 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 394 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 395 | if (hard_iface->soft_iface != soft_iface) |
| 396 | continue; |
| 397 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 398 | batadv_iv_ogm_send_to_if(forw_packet, hard_iface); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 399 | } |
| 400 | rcu_read_unlock(); |
| 401 | |
| 402 | out: |
| 403 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 404 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /* return true if new_packet can be aggregated with forw_packet */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 408 | static bool |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 409 | batadv_iv_ogm_can_aggregate(const struct batadv_ogm_packet *new_bat_ogm_packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 410 | struct batadv_priv *bat_priv, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 411 | int packet_len, unsigned long send_time, |
| 412 | bool directlink, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 413 | const struct batadv_hard_iface *if_incoming, |
| 414 | const struct batadv_forw_packet *forw_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 415 | { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 416 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 417 | int aggregated_bytes = forw_packet->packet_len + packet_len; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 418 | struct batadv_hard_iface *primary_if = NULL; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 419 | bool res = false; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 420 | unsigned long aggregation_end_time; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 421 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 422 | batadv_ogm_packet = (struct batadv_ogm_packet *)forw_packet->skb->data; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 423 | aggregation_end_time = send_time; |
| 424 | aggregation_end_time += msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 425 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 426 | /* we can aggregate the current packet to this aggregated packet |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 427 | * if: |
| 428 | * |
| 429 | * - the send time is within our MAX_AGGREGATION_MS time |
| 430 | * - the resulting packet wont be bigger than |
| 431 | * MAX_AGGREGATION_BYTES |
| 432 | */ |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 433 | if (time_before(send_time, forw_packet->send_time) && |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 434 | time_after_eq(aggregation_end_time, forw_packet->send_time) && |
| 435 | (aggregated_bytes <= BATADV_MAX_AGGREGATION_BYTES)) { |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 436 | /* check aggregation compatibility |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 437 | * -> direct link packets are broadcasted on |
| 438 | * their interface only |
| 439 | * -> aggregate packet if the current packet is |
| 440 | * a "global" packet as well as the base |
| 441 | * packet |
| 442 | */ |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 443 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 444 | if (!primary_if) |
| 445 | goto out; |
| 446 | |
| 447 | /* packets without direct link flag and high TTL |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 448 | * are flooded through the net |
| 449 | */ |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 450 | if ((!directlink) && |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 451 | (!(batadv_ogm_packet->flags & BATADV_DIRECTLINK)) && |
| 452 | (batadv_ogm_packet->header.ttl != 1) && |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 453 | |
| 454 | /* own packets originating non-primary |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 455 | * interfaces leave only that interface |
| 456 | */ |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 457 | ((!forw_packet->own) || |
| 458 | (forw_packet->if_incoming == primary_if))) { |
| 459 | res = true; |
| 460 | goto out; |
| 461 | } |
| 462 | |
| 463 | /* if the incoming packet is sent via this one |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 464 | * interface only - we still can aggregate |
| 465 | */ |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 466 | if ((directlink) && |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 467 | (new_bat_ogm_packet->header.ttl == 1) && |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 468 | (forw_packet->if_incoming == if_incoming) && |
| 469 | |
| 470 | /* packets from direct neighbors or |
| 471 | * own secondary interface packets |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 472 | * (= secondary interface packets in general) |
| 473 | */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 474 | (batadv_ogm_packet->flags & BATADV_DIRECTLINK || |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 475 | (forw_packet->own && |
| 476 | forw_packet->if_incoming != primary_if))) { |
| 477 | res = true; |
| 478 | goto out; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | out: |
| 483 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 484 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 485 | return res; |
| 486 | } |
| 487 | |
| 488 | /* create a new aggregated packet and add this packet to it */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 489 | static void batadv_iv_ogm_aggregate_new(const unsigned char *packet_buff, |
| 490 | int packet_len, unsigned long send_time, |
| 491 | bool direct_link, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 492 | struct batadv_hard_iface *if_incoming, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 493 | int own_packet) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 494 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 495 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 496 | struct batadv_forw_packet *forw_packet_aggr; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 497 | unsigned char *skb_buff; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 498 | unsigned int skb_size; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 499 | |
| 500 | if (!atomic_inc_not_zero(&if_incoming->refcount)) |
| 501 | return; |
| 502 | |
| 503 | /* own packet should always be scheduled */ |
| 504 | if (!own_packet) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 505 | if (!batadv_atomic_dec_not_zero(&bat_priv->batman_queue_left)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 506 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 507 | "batman packet queue full\n"); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 508 | goto out; |
| 509 | } |
| 510 | } |
| 511 | |
| 512 | forw_packet_aggr = kmalloc(sizeof(*forw_packet_aggr), GFP_ATOMIC); |
| 513 | if (!forw_packet_aggr) { |
| 514 | if (!own_packet) |
| 515 | atomic_inc(&bat_priv->batman_queue_left); |
| 516 | goto out; |
| 517 | } |
| 518 | |
| 519 | if ((atomic_read(&bat_priv->aggregated_ogms)) && |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 520 | (packet_len < BATADV_MAX_AGGREGATION_BYTES)) |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 521 | skb_size = BATADV_MAX_AGGREGATION_BYTES; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 522 | else |
Sven Eckelmann | 5b24657 | 2012-11-04 17:11:45 +0100 | [diff] [blame] | 523 | skb_size = packet_len; |
| 524 | |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 525 | skb_size += ETH_HLEN; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 526 | |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 527 | forw_packet_aggr->skb = netdev_alloc_skb_ip_align(NULL, skb_size); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 528 | if (!forw_packet_aggr->skb) { |
| 529 | if (!own_packet) |
| 530 | atomic_inc(&bat_priv->batman_queue_left); |
| 531 | kfree(forw_packet_aggr); |
| 532 | goto out; |
| 533 | } |
Simon Wunderlich | c54f38c | 2013-07-29 17:56:44 +0200 | [diff] [blame] | 534 | forw_packet_aggr->skb->priority = TC_PRIO_CONTROL; |
Antonio Quartulli | 41ab6c4 | 2013-04-02 22:28:44 +0200 | [diff] [blame] | 535 | skb_reserve(forw_packet_aggr->skb, ETH_HLEN); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 536 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 537 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); |
| 538 | forw_packet_aggr->packet_len = packet_len; |
| 539 | memcpy(skb_buff, packet_buff, packet_len); |
| 540 | |
| 541 | forw_packet_aggr->own = own_packet; |
| 542 | forw_packet_aggr->if_incoming = if_incoming; |
| 543 | forw_packet_aggr->num_packets = 0; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 544 | forw_packet_aggr->direct_link_flags = BATADV_NO_FLAGS; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 545 | forw_packet_aggr->send_time = send_time; |
| 546 | |
| 547 | /* save packet direct link flag status */ |
| 548 | if (direct_link) |
| 549 | forw_packet_aggr->direct_link_flags |= 1; |
| 550 | |
| 551 | /* add new packet to packet list */ |
| 552 | spin_lock_bh(&bat_priv->forw_bat_list_lock); |
| 553 | hlist_add_head(&forw_packet_aggr->list, &bat_priv->forw_bat_list); |
| 554 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 555 | |
| 556 | /* start timer for this packet */ |
| 557 | INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, |
Sven Eckelmann | 9455e34 | 2012-05-12 02:09:37 +0200 | [diff] [blame] | 558 | batadv_send_outstanding_bat_ogm_packet); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 559 | queue_delayed_work(batadv_event_workqueue, |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 560 | &forw_packet_aggr->delayed_work, |
| 561 | send_time - jiffies); |
| 562 | |
| 563 | return; |
| 564 | out: |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 565 | batadv_hardif_free_ref(if_incoming); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | /* aggregate a new packet into the existing ogm packet */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 569 | static void batadv_iv_ogm_aggregate(struct batadv_forw_packet *forw_packet_aggr, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 570 | const unsigned char *packet_buff, |
| 571 | int packet_len, bool direct_link) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 572 | { |
| 573 | unsigned char *skb_buff; |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 574 | unsigned long new_direct_link_flag; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 575 | |
| 576 | skb_buff = skb_put(forw_packet_aggr->skb, packet_len); |
| 577 | memcpy(skb_buff, packet_buff, packet_len); |
| 578 | forw_packet_aggr->packet_len += packet_len; |
| 579 | forw_packet_aggr->num_packets++; |
| 580 | |
| 581 | /* save packet direct link flag status */ |
Sven Eckelmann | 8de47de | 2012-07-08 16:32:09 +0200 | [diff] [blame] | 582 | if (direct_link) { |
| 583 | new_direct_link_flag = BIT(forw_packet_aggr->num_packets); |
| 584 | forw_packet_aggr->direct_link_flags |= new_direct_link_flag; |
| 585 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 586 | } |
| 587 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 588 | static void batadv_iv_ogm_queue_add(struct batadv_priv *bat_priv, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 589 | unsigned char *packet_buff, |
| 590 | int packet_len, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 591 | struct batadv_hard_iface *if_incoming, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 592 | int own_packet, unsigned long send_time) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 593 | { |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 594 | /* _aggr -> pointer to the packet we want to aggregate with |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 595 | * _pos -> pointer to the position in the queue |
| 596 | */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 597 | struct batadv_forw_packet *forw_packet_aggr = NULL; |
| 598 | struct batadv_forw_packet *forw_packet_pos = NULL; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 599 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 600 | bool direct_link; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 601 | unsigned long max_aggregation_jiffies; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 602 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 603 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff; |
| 604 | direct_link = batadv_ogm_packet->flags & BATADV_DIRECTLINK ? 1 : 0; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 605 | max_aggregation_jiffies = msecs_to_jiffies(BATADV_MAX_AGGREGATION_MS); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 606 | |
| 607 | /* find position for the packet in the forward queue */ |
| 608 | spin_lock_bh(&bat_priv->forw_bat_list_lock); |
| 609 | /* own packets are not to be aggregated */ |
| 610 | if ((atomic_read(&bat_priv->aggregated_ogms)) && (!own_packet)) { |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 611 | hlist_for_each_entry(forw_packet_pos, |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 612 | &bat_priv->forw_bat_list, list) { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 613 | if (batadv_iv_ogm_can_aggregate(batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 614 | bat_priv, packet_len, |
| 615 | send_time, direct_link, |
| 616 | if_incoming, |
| 617 | forw_packet_pos)) { |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 618 | forw_packet_aggr = forw_packet_pos; |
| 619 | break; |
| 620 | } |
| 621 | } |
| 622 | } |
| 623 | |
| 624 | /* nothing to aggregate with - either aggregation disabled or no |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 625 | * suitable aggregation packet found |
| 626 | */ |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 627 | if (!forw_packet_aggr) { |
| 628 | /* the following section can run without the lock */ |
| 629 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 630 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 631 | /* if we could not aggregate this packet with one of the others |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 632 | * we hold it back for a while, so that it might be aggregated |
| 633 | * later on |
| 634 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 635 | if (!own_packet && atomic_read(&bat_priv->aggregated_ogms)) |
| 636 | send_time += max_aggregation_jiffies; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 637 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 638 | batadv_iv_ogm_aggregate_new(packet_buff, packet_len, |
| 639 | send_time, direct_link, |
| 640 | if_incoming, own_packet); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 641 | } else { |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 642 | batadv_iv_ogm_aggregate(forw_packet_aggr, packet_buff, |
| 643 | packet_len, direct_link); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 644 | spin_unlock_bh(&bat_priv->forw_bat_list_lock); |
| 645 | } |
| 646 | } |
| 647 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 648 | static void batadv_iv_ogm_forward(struct batadv_orig_node *orig_node, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 649 | const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 650 | struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 651 | bool is_single_hop_neigh, |
| 652 | bool is_from_best_next_hop, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 653 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 654 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 655 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 656 | uint16_t tvlv_len; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 657 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 658 | if (batadv_ogm_packet->header.ttl <= 1) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 659 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, "ttl exceeded\n"); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 660 | return; |
| 661 | } |
| 662 | |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 663 | if (!is_from_best_next_hop) { |
| 664 | /* Mark the forwarded packet when it is not coming from our |
| 665 | * best next hop. We still need to forward the packet for our |
| 666 | * neighbor link quality detection to work in case the packet |
| 667 | * originated from a single hop neighbor. Otherwise we can |
| 668 | * simply drop the ogm. |
| 669 | */ |
| 670 | if (is_single_hop_neigh) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 671 | batadv_ogm_packet->flags |= BATADV_NOT_BEST_NEXT_HOP; |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 672 | else |
| 673 | return; |
| 674 | } |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 675 | |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 676 | tvlv_len = ntohs(batadv_ogm_packet->tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 677 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 678 | batadv_ogm_packet->header.ttl--; |
| 679 | memcpy(batadv_ogm_packet->prev_sender, ethhdr->h_source, ETH_ALEN); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 680 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 681 | /* apply hop penalty */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 682 | batadv_ogm_packet->tq = batadv_hop_penalty(batadv_ogm_packet->tq, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 683 | bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 684 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 685 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 686 | "Forwarding packet: tq: %i, ttl: %i\n", |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 687 | batadv_ogm_packet->tq, batadv_ogm_packet->header.ttl); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 688 | |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 689 | /* switch of primaries first hop flag when forwarding */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 690 | batadv_ogm_packet->flags &= ~BATADV_PRIMARIES_FIRST_HOP; |
Marek Lindner | 75cd33f | 2012-03-01 15:35:16 +0800 | [diff] [blame] | 691 | if (is_single_hop_neigh) |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 692 | batadv_ogm_packet->flags |= BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 693 | else |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 694 | batadv_ogm_packet->flags &= ~BATADV_DIRECTLINK; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 695 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 696 | batadv_iv_ogm_queue_add(bat_priv, (unsigned char *)batadv_ogm_packet, |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 697 | BATADV_OGM_HLEN + tvlv_len, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 698 | if_incoming, 0, batadv_iv_ogm_fwd_send_time()); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 699 | } |
| 700 | |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 701 | /** |
| 702 | * batadv_iv_ogm_slide_own_bcast_window - bitshift own OGM broadcast windows for |
| 703 | * the given interface |
| 704 | * @hard_iface: the interface for which the windows have to be shifted |
| 705 | */ |
| 706 | static void |
| 707 | batadv_iv_ogm_slide_own_bcast_window(struct batadv_hard_iface *hard_iface) |
| 708 | { |
| 709 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
| 710 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 711 | struct hlist_head *head; |
| 712 | struct batadv_orig_node *orig_node; |
| 713 | unsigned long *word; |
| 714 | uint32_t i; |
| 715 | size_t word_index; |
| 716 | uint8_t *w; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 717 | int if_num; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 718 | |
| 719 | for (i = 0; i < hash->size; i++) { |
| 720 | head = &hash->table[i]; |
| 721 | |
| 722 | rcu_read_lock(); |
| 723 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 724 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 725 | word_index = hard_iface->if_num * BATADV_NUM_WORDS; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 726 | word = &(orig_node->bat_iv.bcast_own[word_index]); |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 727 | |
| 728 | batadv_bit_get_packet(bat_priv, word, 1, 0); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 729 | if_num = hard_iface->if_num; |
| 730 | w = &orig_node->bat_iv.bcast_own_sum[if_num]; |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 731 | *w = bitmap_weight(word, BATADV_TQ_LOCAL_WINDOW_SIZE); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 732 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 733 | } |
| 734 | rcu_read_unlock(); |
| 735 | } |
| 736 | } |
| 737 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 738 | static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface) |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 739 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 740 | struct batadv_priv *bat_priv = netdev_priv(hard_iface->soft_iface); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 741 | unsigned char **ogm_buff = &hard_iface->bat_iv.ogm_buff; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 742 | struct batadv_ogm_packet *batadv_ogm_packet; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 743 | struct batadv_hard_iface *primary_if; |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 744 | int *ogm_buff_len = &hard_iface->bat_iv.ogm_buff_len; |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 745 | uint32_t seqno; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 746 | uint16_t tvlv_len = 0; |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 747 | |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 748 | primary_if = batadv_primary_if_get_selected(bat_priv); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 749 | |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 750 | if (hard_iface == primary_if) { |
| 751 | /* tt changes have to be committed before the tvlv data is |
| 752 | * appended as it may alter the tt tvlv container |
| 753 | */ |
| 754 | batadv_tt_local_commit_changes(bat_priv); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 755 | tvlv_len = batadv_tvlv_container_ogm_append(bat_priv, ogm_buff, |
| 756 | ogm_buff_len, |
| 757 | BATADV_OGM_HLEN); |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 758 | } |
Marek Lindner | be9aa4c | 2012-05-07 04:22:05 +0800 | [diff] [blame] | 759 | |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 760 | batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff); |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 761 | batadv_ogm_packet->tvlv_len = htons(tvlv_len); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 762 | |
| 763 | /* change sequence number to network order */ |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 764 | seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno); |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 765 | batadv_ogm_packet->seqno = htonl(seqno); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 766 | atomic_inc(&hard_iface->bat_iv.ogm_seqno); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 767 | |
Antonio Quartulli | d989661 | 2013-04-17 17:44:43 +0200 | [diff] [blame] | 768 | batadv_iv_ogm_slide_own_bcast_window(hard_iface); |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 769 | batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff, |
| 770 | hard_iface->bat_iv.ogm_buff_len, hard_iface, 1, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 771 | batadv_iv_ogm_emit_send_time(bat_priv)); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 772 | |
| 773 | if (primary_if) |
Sven Eckelmann | e5d8925 | 2012-05-12 13:48:54 +0200 | [diff] [blame] | 774 | batadv_hardif_free_ref(primary_if); |
Marek Lindner | b9dacc5 | 2011-08-03 09:09:30 +0200 | [diff] [blame] | 775 | } |
| 776 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 777 | static void |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 778 | batadv_iv_ogm_orig_update(struct batadv_priv *bat_priv, |
| 779 | struct batadv_orig_node *orig_node, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 780 | const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 781 | const struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 782 | struct batadv_hard_iface *if_incoming, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 783 | const unsigned char *tt_buff, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 784 | enum batadv_dup_status dup_status) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 785 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 786 | struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node = NULL; |
| 787 | struct batadv_neigh_node *router = NULL; |
| 788 | struct batadv_orig_node *orig_node_tmp; |
Linus LĂĽssing | 7caf69f | 2012-09-18 03:01:08 +0200 | [diff] [blame] | 789 | int if_num; |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 790 | uint8_t sum_orig, sum_neigh; |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 791 | uint8_t *neigh_addr; |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 792 | uint8_t tq_avg; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 793 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 794 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 795 | "update_originator(): Searching and updating originator entry of received packet\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 796 | |
| 797 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 798 | hlist_for_each_entry_rcu(tmp_neigh_node, |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 799 | &orig_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 800 | neigh_addr = tmp_neigh_node->addr; |
| 801 | if (batadv_compare_eth(neigh_addr, ethhdr->h_source) && |
| 802 | tmp_neigh_node->if_incoming == if_incoming && |
| 803 | atomic_inc_not_zero(&tmp_neigh_node->refcount)) { |
Antonio Quartulli | 38dc40e | 2013-03-30 17:22:00 +0100 | [diff] [blame] | 804 | if (WARN(neigh_node, "too many matching neigh_nodes")) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 805 | batadv_neigh_node_free_ref(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 806 | neigh_node = tmp_neigh_node; |
| 807 | continue; |
| 808 | } |
| 809 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 810 | if (dup_status != BATADV_NO_DUP) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 811 | continue; |
| 812 | |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 813 | spin_lock_bh(&tmp_neigh_node->bat_iv.lq_update_lock); |
| 814 | batadv_ring_buffer_set(tmp_neigh_node->bat_iv.tq_recv, |
| 815 | &tmp_neigh_node->bat_iv.tq_index, 0); |
| 816 | tq_avg = batadv_ring_buffer_avg(tmp_neigh_node->bat_iv.tq_recv); |
| 817 | tmp_neigh_node->bat_iv.tq_avg = tq_avg; |
| 818 | spin_unlock_bh(&tmp_neigh_node->bat_iv.lq_update_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 819 | } |
| 820 | |
| 821 | if (!neigh_node) { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 822 | struct batadv_orig_node *orig_tmp; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 823 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 824 | orig_tmp = batadv_iv_ogm_orig_get(bat_priv, ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 825 | if (!orig_tmp) |
| 826 | goto unlock; |
| 827 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 828 | neigh_node = batadv_iv_ogm_neigh_new(if_incoming, |
| 829 | ethhdr->h_source, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 830 | orig_node, orig_tmp); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 831 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 832 | batadv_orig_node_free_ref(orig_tmp); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 833 | if (!neigh_node) |
| 834 | goto unlock; |
| 835 | } else |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 836 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 837 | "Updating existing last-hop neighbor of originator\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 838 | |
| 839 | rcu_read_unlock(); |
| 840 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 841 | neigh_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 842 | |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 843 | spin_lock_bh(&neigh_node->bat_iv.lq_update_lock); |
| 844 | batadv_ring_buffer_set(neigh_node->bat_iv.tq_recv, |
| 845 | &neigh_node->bat_iv.tq_index, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 846 | batadv_ogm_packet->tq); |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 847 | tq_avg = batadv_ring_buffer_avg(neigh_node->bat_iv.tq_recv); |
| 848 | neigh_node->bat_iv.tq_avg = tq_avg; |
| 849 | spin_unlock_bh(&neigh_node->bat_iv.lq_update_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 850 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 851 | if (dup_status == BATADV_NO_DUP) { |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 852 | orig_node->last_ttl = batadv_ogm_packet->header.ttl; |
| 853 | neigh_node->last_ttl = batadv_ogm_packet->header.ttl; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 854 | } |
| 855 | |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 856 | batadv_bonding_candidate_add(orig_node, neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 857 | |
| 858 | /* if this neighbor already is our next hop there is nothing |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 859 | * to change |
| 860 | */ |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 861 | router = batadv_orig_node_get_router(orig_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 862 | if (router == neigh_node) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 863 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 864 | |
| 865 | /* if this neighbor does not offer a better TQ we won't consider it */ |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 866 | if (router && (router->bat_iv.tq_avg > neigh_node->bat_iv.tq_avg)) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 867 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 868 | |
| 869 | /* if the TQ is the same and the link not more symmetric we |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 870 | * won't consider it either |
| 871 | */ |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 872 | if (router && (neigh_node->bat_iv.tq_avg == router->bat_iv.tq_avg)) { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 873 | orig_node_tmp = router->orig_node; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 874 | spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Linus LĂĽssing | 7caf69f | 2012-09-18 03:01:08 +0200 | [diff] [blame] | 875 | if_num = router->if_incoming->if_num; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 876 | sum_orig = orig_node_tmp->bat_iv.bcast_own_sum[if_num]; |
| 877 | spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 878 | |
| 879 | orig_node_tmp = neigh_node->orig_node; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 880 | spin_lock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Linus LĂĽssing | 7caf69f | 2012-09-18 03:01:08 +0200 | [diff] [blame] | 881 | if_num = neigh_node->if_incoming->if_num; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 882 | sum_neigh = orig_node_tmp->bat_iv.bcast_own_sum[if_num]; |
| 883 | spin_unlock_bh(&orig_node_tmp->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 884 | |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 885 | if (sum_orig >= sum_neigh) |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 886 | goto out; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 887 | } |
| 888 | |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 889 | batadv_update_route(bat_priv, orig_node, neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 890 | goto out; |
| 891 | |
| 892 | unlock: |
| 893 | rcu_read_unlock(); |
| 894 | out: |
| 895 | if (neigh_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 896 | batadv_neigh_node_free_ref(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 897 | if (router) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 898 | batadv_neigh_node_free_ref(router); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 899 | } |
| 900 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 901 | static int batadv_iv_ogm_calc_tq(struct batadv_orig_node *orig_node, |
| 902 | struct batadv_orig_node *orig_neigh_node, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 903 | struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 904 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 905 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 906 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 907 | struct batadv_neigh_node *neigh_node = NULL, *tmp_neigh_node; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 908 | uint8_t total_count; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 909 | uint8_t orig_eq_count, neigh_rq_count, neigh_rq_inv, tq_own; |
| 910 | unsigned int neigh_rq_inv_cube, neigh_rq_max_cube; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 911 | int tq_asym_penalty, inv_asym_penalty, if_num, ret = 0; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 912 | unsigned int combined_tq; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 913 | |
| 914 | /* find corresponding one hop neighbor */ |
| 915 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 916 | hlist_for_each_entry_rcu(tmp_neigh_node, |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 917 | &orig_neigh_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 918 | if (!batadv_compare_eth(tmp_neigh_node->addr, |
| 919 | orig_neigh_node->orig)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 920 | continue; |
| 921 | |
| 922 | if (tmp_neigh_node->if_incoming != if_incoming) |
| 923 | continue; |
| 924 | |
| 925 | if (!atomic_inc_not_zero(&tmp_neigh_node->refcount)) |
| 926 | continue; |
| 927 | |
| 928 | neigh_node = tmp_neigh_node; |
| 929 | break; |
| 930 | } |
| 931 | rcu_read_unlock(); |
| 932 | |
| 933 | if (!neigh_node) |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 934 | neigh_node = batadv_iv_ogm_neigh_new(if_incoming, |
| 935 | orig_neigh_node->orig, |
| 936 | orig_neigh_node, |
Antonio Quartulli | 863dd7a | 2013-03-25 13:49:46 +0100 | [diff] [blame] | 937 | orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 938 | |
| 939 | if (!neigh_node) |
| 940 | goto out; |
| 941 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 942 | /* if orig_node is direct neighbor update neigh_node last_seen */ |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 943 | if (orig_node == orig_neigh_node) |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 944 | neigh_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 945 | |
Marek Lindner | d7b2a97 | 2012-03-01 15:35:19 +0800 | [diff] [blame] | 946 | orig_node->last_seen = jiffies; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 947 | |
| 948 | /* find packet count of corresponding one hop neighbor */ |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 949 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
| 950 | if_num = if_incoming->if_num; |
| 951 | orig_eq_count = orig_neigh_node->bat_iv.bcast_own_sum[if_num]; |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 952 | neigh_rq_count = neigh_node->bat_iv.real_packet_count; |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 953 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 954 | |
| 955 | /* pay attention to not get a value bigger than 100 % */ |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 956 | if (orig_eq_count > neigh_rq_count) |
| 957 | total_count = neigh_rq_count; |
| 958 | else |
| 959 | total_count = orig_eq_count; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 960 | |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 961 | /* if we have too few packets (too less data) we set tq_own to zero |
| 962 | * if we receive too few packets it is not considered bidirectional |
| 963 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 964 | if (total_count < BATADV_TQ_LOCAL_BIDRECT_SEND_MINIMUM || |
| 965 | neigh_rq_count < BATADV_TQ_LOCAL_BIDRECT_RECV_MINIMUM) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 966 | tq_own = 0; |
| 967 | else |
| 968 | /* neigh_node->real_packet_count is never zero as we |
| 969 | * only purge old information when getting new |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 970 | * information |
| 971 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 972 | tq_own = (BATADV_TQ_MAX_VALUE * total_count) / neigh_rq_count; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 973 | |
Sven Eckelmann | 21a1236 | 2012-03-07 09:07:46 +0100 | [diff] [blame] | 974 | /* 1 - ((1-x) ** 3), normalized to TQ_MAX_VALUE this does |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 975 | * affect the nearly-symmetric links only a little, but |
| 976 | * punishes asymmetric links more. This will give a value |
| 977 | * between 0 and TQ_MAX_VALUE |
| 978 | */ |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 979 | neigh_rq_inv = BATADV_TQ_LOCAL_WINDOW_SIZE - neigh_rq_count; |
| 980 | neigh_rq_inv_cube = neigh_rq_inv * neigh_rq_inv * neigh_rq_inv; |
| 981 | neigh_rq_max_cube = BATADV_TQ_LOCAL_WINDOW_SIZE * |
| 982 | BATADV_TQ_LOCAL_WINDOW_SIZE * |
| 983 | BATADV_TQ_LOCAL_WINDOW_SIZE; |
| 984 | inv_asym_penalty = BATADV_TQ_MAX_VALUE * neigh_rq_inv_cube; |
| 985 | inv_asym_penalty /= neigh_rq_max_cube; |
| 986 | tq_asym_penalty = BATADV_TQ_MAX_VALUE - inv_asym_penalty; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 987 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 988 | combined_tq = batadv_ogm_packet->tq * tq_own * tq_asym_penalty; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 989 | combined_tq /= BATADV_TQ_MAX_VALUE * BATADV_TQ_MAX_VALUE; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 990 | batadv_ogm_packet->tq = combined_tq; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 991 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 992 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 993 | "bidirectional: orig = %-15pM neigh = %-15pM => own_bcast = %2i, real recv = %2i, local tq: %3i, asym_penalty: %3i, total tq: %3i\n", |
| 994 | orig_node->orig, orig_neigh_node->orig, total_count, |
| 995 | neigh_rq_count, tq_own, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 996 | tq_asym_penalty, batadv_ogm_packet->tq); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 997 | |
| 998 | /* if link has the minimum required transmission quality |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 999 | * consider it bidirectional |
| 1000 | */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1001 | if (batadv_ogm_packet->tq >= BATADV_TQ_TOTAL_BIDRECT_LIMIT) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1002 | ret = 1; |
| 1003 | |
| 1004 | out: |
| 1005 | if (neigh_node) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1006 | batadv_neigh_node_free_ref(neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1007 | return ret; |
| 1008 | } |
| 1009 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1010 | /** |
| 1011 | * batadv_iv_ogm_update_seqnos - process a batman packet for all interfaces, |
| 1012 | * adjust the sequence number and find out whether it is a duplicate |
| 1013 | * @ethhdr: ethernet header of the packet |
| 1014 | * @batadv_ogm_packet: OGM packet to be considered |
| 1015 | * @if_incoming: interface on which the OGM packet was received |
| 1016 | * |
| 1017 | * Returns duplicate status as enum batadv_dup_status |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1018 | */ |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1019 | static enum batadv_dup_status |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1020 | batadv_iv_ogm_update_seqnos(const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1021 | const struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1022 | const struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1023 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1024 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 1025 | struct batadv_orig_node *orig_node; |
| 1026 | struct batadv_neigh_node *tmp_neigh_node; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1027 | int is_dup; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1028 | int32_t seq_diff; |
| 1029 | int need_update = 0; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1030 | int set_mark; |
| 1031 | enum batadv_dup_status ret = BATADV_NO_DUP; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1032 | uint32_t seqno = ntohl(batadv_ogm_packet->seqno); |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1033 | uint8_t *neigh_addr; |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1034 | uint8_t packet_count; |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1035 | unsigned long *bitmap; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1036 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1037 | orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1038 | if (!orig_node) |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1039 | return BATADV_NO_DUP; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1040 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1041 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Al Viro | e0f5211 | 2012-04-22 07:46:29 +0100 | [diff] [blame] | 1042 | seq_diff = seqno - orig_node->last_real_seqno; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1043 | |
| 1044 | /* signalize caller that the packet is to be dropped. */ |
Antonio Quartulli | 1e5cc26 | 2012-02-26 15:39:42 +0100 | [diff] [blame] | 1045 | if (!hlist_empty(&orig_node->neigh_list) && |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 1046 | batadv_window_protected(bat_priv, seq_diff, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1047 | &orig_node->batman_seqno_reset)) { |
| 1048 | ret = BATADV_PROTECTED; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1049 | goto out; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1050 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1051 | |
| 1052 | rcu_read_lock(); |
Sasha Levin | b67bfe0 | 2013-02-27 17:06:00 -0800 | [diff] [blame] | 1053 | hlist_for_each_entry_rcu(tmp_neigh_node, |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1054 | &orig_node->neigh_list, list) { |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1055 | neigh_addr = tmp_neigh_node->addr; |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1056 | is_dup = batadv_test_bit(tmp_neigh_node->bat_iv.real_bits, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1057 | orig_node->last_real_seqno, |
| 1058 | seqno); |
| 1059 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1060 | if (batadv_compare_eth(neigh_addr, ethhdr->h_source) && |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1061 | tmp_neigh_node->if_incoming == if_incoming) { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1062 | set_mark = 1; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1063 | if (is_dup) |
| 1064 | ret = BATADV_NEIGH_DUP; |
| 1065 | } else { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1066 | set_mark = 0; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1067 | if (is_dup && (ret != BATADV_NEIGH_DUP)) |
| 1068 | ret = BATADV_ORIG_DUP; |
| 1069 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1070 | |
| 1071 | /* if the window moved, set the update flag. */ |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1072 | bitmap = tmp_neigh_node->bat_iv.real_bits; |
| 1073 | need_update |= batadv_bit_get_packet(bat_priv, bitmap, |
Sven Eckelmann | 0f5f9322 | 2012-05-12 02:09:25 +0200 | [diff] [blame] | 1074 | seq_diff, set_mark); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1075 | |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1076 | packet_count = bitmap_weight(tmp_neigh_node->bat_iv.real_bits, |
Sven Eckelmann | bbb1f90 | 2012-07-08 17:13:15 +0200 | [diff] [blame] | 1077 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1078 | tmp_neigh_node->bat_iv.real_packet_count = packet_count; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1079 | } |
| 1080 | rcu_read_unlock(); |
| 1081 | |
| 1082 | if (need_update) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1083 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1084 | "updating last_seqno: old %u, new %u\n", |
| 1085 | orig_node->last_real_seqno, seqno); |
Al Viro | e0f5211 | 2012-04-22 07:46:29 +0100 | [diff] [blame] | 1086 | orig_node->last_real_seqno = seqno; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1087 | } |
| 1088 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1089 | out: |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1090 | spin_unlock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1091 | batadv_orig_node_free_ref(orig_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1092 | return ret; |
| 1093 | } |
| 1094 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1095 | static void batadv_iv_ogm_process(const struct ethhdr *ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1096 | struct batadv_ogm_packet *batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1097 | const unsigned char *tt_buff, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1098 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1099 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1100 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
| 1101 | struct batadv_hard_iface *hard_iface; |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1102 | struct batadv_orig_node *orig_neigh_node, *orig_node, *orig_node_tmp; |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1103 | struct batadv_neigh_node *router = NULL, *router_router = NULL; |
| 1104 | struct batadv_neigh_node *orig_neigh_router = NULL; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1105 | int has_directlink_flag; |
| 1106 | int is_my_addr = 0, is_my_orig = 0, is_my_oldorig = 0; |
Antonio Quartulli | 281581d | 2013-03-25 22:27:00 +0100 | [diff] [blame] | 1107 | int is_bidirect; |
Marek Lindner | 75cd33f | 2012-03-01 15:35:16 +0800 | [diff] [blame] | 1108 | bool is_single_hop_neigh = false; |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 1109 | bool is_from_best_next_hop = false; |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1110 | int sameseq, similar_ttl; |
| 1111 | enum batadv_dup_status dup_status; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1112 | uint32_t if_incoming_seqno; |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1113 | uint8_t *prev_sender; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1114 | |
| 1115 | /* Silently drop when the batman packet is actually not a |
| 1116 | * correct packet. |
| 1117 | * |
| 1118 | * This might happen if a packet is padded (e.g. Ethernet has a |
| 1119 | * minimum frame length of 64 byte) and the aggregation interprets |
| 1120 | * it as an additional length. |
| 1121 | * |
| 1122 | * TODO: A more sane solution would be to have a bit in the |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1123 | * batadv_ogm_packet to detect whether the packet is the last |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1124 | * packet in an aggregation. Here we expect that the padding |
| 1125 | * is always zero (or not 0x01) |
| 1126 | */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1127 | if (batadv_ogm_packet->header.packet_type != BATADV_IV_OGM) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1128 | return; |
| 1129 | |
| 1130 | /* could be changed by schedule_own_packet() */ |
Marek Lindner | 1451151 | 2012-08-02 17:20:26 +0200 | [diff] [blame] | 1131 | if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1132 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1133 | if (batadv_ogm_packet->flags & BATADV_DIRECTLINK) |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1134 | has_directlink_flag = 1; |
| 1135 | else |
| 1136 | has_directlink_flag = 0; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1137 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1138 | if (batadv_compare_eth(ethhdr->h_source, batadv_ogm_packet->orig)) |
Marek Lindner | 75cd33f | 2012-03-01 15:35:16 +0800 | [diff] [blame] | 1139 | is_single_hop_neigh = true; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1140 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1141 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1142 | "Received BATMAN packet via NB: %pM, IF: %s [%pM] (from OG: %pM, via prev OG: %pM, seqno %u, tq %d, TTL %d, V %d, IDF %d)\n", |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1143 | ethhdr->h_source, if_incoming->net_dev->name, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1144 | if_incoming->net_dev->dev_addr, batadv_ogm_packet->orig, |
| 1145 | batadv_ogm_packet->prev_sender, |
Marek Lindner | e1bf0c1 | 2013-04-23 21:40:01 +0800 | [diff] [blame] | 1146 | ntohl(batadv_ogm_packet->seqno), batadv_ogm_packet->tq, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1147 | batadv_ogm_packet->header.ttl, |
| 1148 | batadv_ogm_packet->header.version, has_directlink_flag); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1149 | |
| 1150 | rcu_read_lock(); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 1151 | list_for_each_entry_rcu(hard_iface, &batadv_hardif_list, list) { |
Sven Eckelmann | e9a4f29 | 2012-06-03 22:19:19 +0200 | [diff] [blame] | 1152 | if (hard_iface->if_status != BATADV_IF_ACTIVE) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1153 | continue; |
| 1154 | |
| 1155 | if (hard_iface->soft_iface != if_incoming->soft_iface) |
| 1156 | continue; |
| 1157 | |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1158 | if (batadv_compare_eth(ethhdr->h_source, |
| 1159 | hard_iface->net_dev->dev_addr)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1160 | is_my_addr = 1; |
| 1161 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1162 | if (batadv_compare_eth(batadv_ogm_packet->orig, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1163 | hard_iface->net_dev->dev_addr)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1164 | is_my_orig = 1; |
| 1165 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1166 | if (batadv_compare_eth(batadv_ogm_packet->prev_sender, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1167 | hard_iface->net_dev->dev_addr)) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1168 | is_my_oldorig = 1; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1169 | } |
| 1170 | rcu_read_unlock(); |
| 1171 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1172 | if (is_my_addr) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1173 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1174 | "Drop packet: received my own broadcast (sender: %pM)\n", |
| 1175 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1176 | return; |
| 1177 | } |
| 1178 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1179 | if (is_my_orig) { |
| 1180 | unsigned long *word; |
| 1181 | int offset; |
Sven Eckelmann | 9b4a115 | 2012-05-12 13:48:53 +0200 | [diff] [blame] | 1182 | int32_t bit_pos; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1183 | int16_t if_num; |
| 1184 | uint8_t *weight; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1185 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1186 | orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, |
| 1187 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1188 | if (!orig_neigh_node) |
| 1189 | return; |
| 1190 | |
| 1191 | /* neighbor has to indicate direct link and it has to |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1192 | * come via the corresponding interface |
| 1193 | * save packet seqno for bidirectional check |
| 1194 | */ |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1195 | if (has_directlink_flag && |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1196 | batadv_compare_eth(if_incoming->net_dev->dev_addr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1197 | batadv_ogm_packet->orig)) { |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1198 | if_num = if_incoming->if_num; |
| 1199 | offset = if_num * BATADV_NUM_WORDS; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1200 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1201 | spin_lock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock); |
| 1202 | word = &(orig_neigh_node->bat_iv.bcast_own[offset]); |
Sven Eckelmann | 9b4a115 | 2012-05-12 13:48:53 +0200 | [diff] [blame] | 1203 | bit_pos = if_incoming_seqno - 2; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1204 | bit_pos -= ntohl(batadv_ogm_packet->seqno); |
Sven Eckelmann | 9b4a115 | 2012-05-12 13:48:53 +0200 | [diff] [blame] | 1205 | batadv_set_bit(word, bit_pos); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1206 | weight = &orig_neigh_node->bat_iv.bcast_own_sum[if_num]; |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 1207 | *weight = bitmap_weight(word, |
| 1208 | BATADV_TQ_LOCAL_WINDOW_SIZE); |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1209 | spin_unlock_bh(&orig_neigh_node->bat_iv.ogm_cnt_lock); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1210 | } |
| 1211 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1212 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1213 | "Drop packet: originator packet from myself (via neighbor)\n"); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1214 | batadv_orig_node_free_ref(orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1215 | return; |
| 1216 | } |
| 1217 | |
| 1218 | if (is_my_oldorig) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1219 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1220 | "Drop packet: ignoring all rebroadcast echos (sender: %pM)\n", |
| 1221 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1222 | return; |
| 1223 | } |
| 1224 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1225 | if (batadv_ogm_packet->flags & BATADV_NOT_BEST_NEXT_HOP) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1226 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1227 | "Drop packet: ignoring all packets not forwarded from the best next hop (sender: %pM)\n", |
| 1228 | ethhdr->h_source); |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 1229 | return; |
| 1230 | } |
| 1231 | |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1232 | orig_node = batadv_iv_ogm_orig_get(bat_priv, batadv_ogm_packet->orig); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1233 | if (!orig_node) |
| 1234 | return; |
| 1235 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1236 | dup_status = batadv_iv_ogm_update_seqnos(ethhdr, batadv_ogm_packet, |
| 1237 | if_incoming); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1238 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1239 | if (dup_status == BATADV_PROTECTED) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1240 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1241 | "Drop packet: packet within seqno protection time (sender: %pM)\n", |
| 1242 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1243 | goto out; |
| 1244 | } |
| 1245 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1246 | if (batadv_ogm_packet->tq == 0) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1247 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1248 | "Drop packet: originator packet with tq equal 0\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1249 | goto out; |
| 1250 | } |
| 1251 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1252 | router = batadv_orig_node_get_router(orig_node); |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1253 | if (router) { |
| 1254 | orig_node_tmp = router->orig_node; |
| 1255 | router_router = batadv_orig_node_get_router(orig_node_tmp); |
| 1256 | } |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1257 | |
Antonio Quartulli | 0538f759 | 2013-09-02 12:15:01 +0200 | [diff] [blame] | 1258 | if ((router && router->bat_iv.tq_avg != 0) && |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1259 | (batadv_compare_eth(router->addr, ethhdr->h_source))) |
Marek Lindner | 13b2541 | 2012-03-11 06:17:53 +0800 | [diff] [blame] | 1260 | is_from_best_next_hop = true; |
| 1261 | |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1262 | prev_sender = batadv_ogm_packet->prev_sender; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1263 | /* avoid temporary routing loops */ |
| 1264 | if (router && router_router && |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1265 | (batadv_compare_eth(router->addr, prev_sender)) && |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1266 | !(batadv_compare_eth(batadv_ogm_packet->orig, prev_sender)) && |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1267 | (batadv_compare_eth(router->addr, router_router->addr))) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1268 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1269 | "Drop packet: ignoring all rebroadcast packets that may make me loop (sender: %pM)\n", |
| 1270 | ethhdr->h_source); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1271 | goto out; |
| 1272 | } |
| 1273 | |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 1274 | batadv_tvlv_ogm_receive(bat_priv, batadv_ogm_packet, orig_node); |
| 1275 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1276 | /* if sender is a direct neighbor the sender mac equals |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1277 | * originator mac |
| 1278 | */ |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 1279 | if (is_single_hop_neigh) |
| 1280 | orig_neigh_node = orig_node; |
| 1281 | else |
Antonio Quartulli | bbad0a5 | 2013-09-02 12:15:02 +0200 | [diff] [blame] | 1282 | orig_neigh_node = batadv_iv_ogm_orig_get(bat_priv, |
| 1283 | ethhdr->h_source); |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 1284 | |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1285 | if (!orig_neigh_node) |
| 1286 | goto out; |
| 1287 | |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 1288 | /* Update nc_nodes of the originator */ |
| 1289 | batadv_nc_update_nc_node(bat_priv, orig_node, orig_neigh_node, |
| 1290 | batadv_ogm_packet, is_single_hop_neigh); |
| 1291 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1292 | orig_neigh_router = batadv_orig_node_get_router(orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1293 | |
| 1294 | /* drop packet if sender is not a direct neighbor and if we |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1295 | * don't route towards it |
| 1296 | */ |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1297 | if (!is_single_hop_neigh && (!orig_neigh_router)) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1298 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1299 | "Drop packet: OGM via unknown neighbor!\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1300 | goto out_neigh; |
| 1301 | } |
| 1302 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1303 | is_bidirect = batadv_iv_ogm_calc_tq(orig_node, orig_neigh_node, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1304 | batadv_ogm_packet, if_incoming); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1305 | |
Sven Eckelmann | 30d3c51 | 2012-05-12 02:09:36 +0200 | [diff] [blame] | 1306 | batadv_bonding_save_primary(orig_node, orig_neigh_node, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1307 | batadv_ogm_packet); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1308 | |
| 1309 | /* update ranking if it is not a duplicate or has the same |
Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1310 | * seqno and similar ttl as the non-duplicate |
| 1311 | */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1312 | sameseq = orig_node->last_real_seqno == ntohl(batadv_ogm_packet->seqno); |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1313 | similar_ttl = orig_node->last_ttl - 3 <= batadv_ogm_packet->header.ttl; |
| 1314 | if (is_bidirect && ((dup_status == BATADV_NO_DUP) || |
| 1315 | (sameseq && similar_ttl))) |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1316 | batadv_iv_ogm_orig_update(bat_priv, orig_node, ethhdr, |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1317 | batadv_ogm_packet, if_incoming, |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1318 | tt_buff, dup_status); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1319 | |
| 1320 | /* is single hop (direct) neighbor */ |
| 1321 | if (is_single_hop_neigh) { |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1322 | /* mark direct link on incoming interface */ |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1323 | batadv_iv_ogm_forward(orig_node, ethhdr, batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1324 | is_single_hop_neigh, |
| 1325 | is_from_best_next_hop, if_incoming); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1326 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1327 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1328 | "Forwarding packet: rebroadcast neighbor packet with direct link flag\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1329 | goto out_neigh; |
| 1330 | } |
| 1331 | |
| 1332 | /* multihop originator */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1333 | if (!is_bidirect) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1334 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1335 | "Drop packet: not received via bidirectional link\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1336 | goto out_neigh; |
| 1337 | } |
| 1338 | |
Simon Wunderlich | 7c24bbb | 2013-05-23 13:07:42 +0200 | [diff] [blame] | 1339 | if (dup_status == BATADV_NEIGH_DUP) { |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1340 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1341 | "Drop packet: duplicate packet received\n"); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1342 | goto out_neigh; |
| 1343 | } |
| 1344 | |
Sven Eckelmann | 39c75a5 | 2012-06-03 22:19:22 +0200 | [diff] [blame] | 1345 | batadv_dbg(BATADV_DBG_BATMAN, bat_priv, |
Sven Eckelmann | 1eda58b | 2012-05-12 13:48:58 +0200 | [diff] [blame] | 1346 | "Forwarding packet: rebroadcast originator packet\n"); |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1347 | batadv_iv_ogm_forward(orig_node, ethhdr, batadv_ogm_packet, |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1348 | is_single_hop_neigh, is_from_best_next_hop, |
| 1349 | if_incoming); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1350 | |
| 1351 | out_neigh: |
| 1352 | if ((orig_neigh_node) && (!is_single_hop_neigh)) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1353 | batadv_orig_node_free_ref(orig_neigh_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1354 | out: |
| 1355 | if (router) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1356 | batadv_neigh_node_free_ref(router); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1357 | if (router_router) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1358 | batadv_neigh_node_free_ref(router_router); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1359 | if (orig_neigh_router) |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1360 | batadv_neigh_node_free_ref(orig_neigh_router); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1361 | |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 1362 | batadv_orig_node_free_ref(orig_node); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1363 | } |
| 1364 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1365 | static int batadv_iv_ogm_receive(struct sk_buff *skb, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1366 | struct batadv_hard_iface *if_incoming) |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1367 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1368 | struct batadv_priv *bat_priv = netdev_priv(if_incoming->soft_iface); |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1369 | struct batadv_ogm_packet *batadv_ogm_packet; |
Marek Lindner | 8780dad | 2011-12-05 04:01:51 +0800 | [diff] [blame] | 1370 | struct ethhdr *ethhdr; |
| 1371 | int buff_pos = 0, packet_len; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 1372 | unsigned char *tvlv_buff, *packet_buff; |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 1373 | uint8_t *packet_pos; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 1374 | bool ret; |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1375 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 1376 | ret = batadv_check_management_packet(skb, if_incoming, BATADV_OGM_HLEN); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1377 | if (!ret) |
| 1378 | return NET_RX_DROP; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1379 | |
Marek Lindner | edbf12b | 2012-03-11 06:17:49 +0800 | [diff] [blame] | 1380 | /* did we receive a B.A.T.M.A.N. IV OGM packet on an interface |
| 1381 | * that does not have B.A.T.M.A.N. IV enabled ? |
| 1382 | */ |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1383 | if (bat_priv->bat_algo_ops->bat_ogm_emit != batadv_iv_ogm_emit) |
Marek Lindner | edbf12b | 2012-03-11 06:17:49 +0800 | [diff] [blame] | 1384 | return NET_RX_DROP; |
| 1385 | |
Sven Eckelmann | d69909d | 2012-06-03 22:19:20 +0200 | [diff] [blame] | 1386 | batadv_inc_counter(bat_priv, BATADV_CNT_MGMT_RX); |
| 1387 | batadv_add_counter(bat_priv, BATADV_CNT_MGMT_RX_BYTES, |
Martin Hundebøll | f821486 | 2012-04-20 17:02:45 +0200 | [diff] [blame] | 1388 | skb->len + ETH_HLEN); |
| 1389 | |
Marek Lindner | 8780dad | 2011-12-05 04:01:51 +0800 | [diff] [blame] | 1390 | packet_len = skb_headlen(skb); |
Antonio Quartulli | 7ed4be9 | 2013-04-08 15:08:18 +0200 | [diff] [blame] | 1391 | ethhdr = eth_hdr(skb); |
Marek Lindner | 8780dad | 2011-12-05 04:01:51 +0800 | [diff] [blame] | 1392 | packet_buff = skb->data; |
Sven Eckelmann | 9641269 | 2012-06-05 22:31:30 +0200 | [diff] [blame] | 1393 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1394 | |
| 1395 | /* unpack the aggregated packets and process them one by one */ |
Marek Lindner | b47506d | 2013-03-04 10:39:49 +0800 | [diff] [blame] | 1396 | while (batadv_iv_ogm_aggr_packet(buff_pos, packet_len, |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 1397 | batadv_ogm_packet->tvlv_len)) { |
| 1398 | tvlv_buff = packet_buff + buff_pos + BATADV_OGM_HLEN; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1399 | |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 1400 | batadv_iv_ogm_process(ethhdr, batadv_ogm_packet, |
| 1401 | tvlv_buff, if_incoming); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1402 | |
Sven Eckelmann | 7e071c7 | 2012-06-03 22:19:13 +0200 | [diff] [blame] | 1403 | buff_pos += BATADV_OGM_HLEN; |
Marek Lindner | ef26157 | 2013-04-23 21:39:57 +0800 | [diff] [blame] | 1404 | buff_pos += ntohs(batadv_ogm_packet->tvlv_len); |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1405 | |
Sven Eckelmann | c67893d | 2012-07-08 18:33:51 +0200 | [diff] [blame] | 1406 | packet_pos = packet_buff + buff_pos; |
| 1407 | batadv_ogm_packet = (struct batadv_ogm_packet *)packet_pos; |
Marek Lindner | b47506d | 2013-03-04 10:39:49 +0800 | [diff] [blame] | 1408 | } |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1409 | |
| 1410 | kfree_skb(skb); |
| 1411 | return NET_RX_SUCCESS; |
Marek Lindner | fc95727 | 2011-07-30 12:04:12 +0200 | [diff] [blame] | 1412 | } |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 1413 | |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame^] | 1414 | /** |
| 1415 | * batadv_iv_ogm_orig_print - print the originator table |
| 1416 | * @bat_priv: the bat priv with all the soft interface information |
| 1417 | * @seq: debugfs table seq_file struct |
| 1418 | */ |
| 1419 | static void batadv_iv_ogm_orig_print(struct batadv_priv *bat_priv, |
| 1420 | struct seq_file *seq) |
| 1421 | { |
| 1422 | struct batadv_neigh_node *neigh_node, *neigh_node_tmp; |
| 1423 | struct batadv_hashtable *hash = bat_priv->orig_hash; |
| 1424 | int last_seen_msecs, last_seen_secs; |
| 1425 | struct batadv_orig_node *orig_node; |
| 1426 | unsigned long last_seen_jiffies; |
| 1427 | struct hlist_head *head; |
| 1428 | int batman_count = 0; |
| 1429 | uint32_t i; |
| 1430 | |
| 1431 | seq_printf(seq, " %-15s %s (%s/%i) %17s [%10s]: %20s ...\n", |
| 1432 | "Originator", "last-seen", "#", BATADV_TQ_MAX_VALUE, |
| 1433 | "Nexthop", "outgoingIF", "Potential nexthops"); |
| 1434 | |
| 1435 | for (i = 0; i < hash->size; i++) { |
| 1436 | head = &hash->table[i]; |
| 1437 | |
| 1438 | rcu_read_lock(); |
| 1439 | hlist_for_each_entry_rcu(orig_node, head, hash_entry) { |
| 1440 | neigh_node = batadv_orig_node_get_router(orig_node); |
| 1441 | if (!neigh_node) |
| 1442 | continue; |
| 1443 | |
| 1444 | if (neigh_node->bat_iv.tq_avg == 0) |
| 1445 | goto next; |
| 1446 | |
| 1447 | last_seen_jiffies = jiffies - orig_node->last_seen; |
| 1448 | last_seen_msecs = jiffies_to_msecs(last_seen_jiffies); |
| 1449 | last_seen_secs = last_seen_msecs / 1000; |
| 1450 | last_seen_msecs = last_seen_msecs % 1000; |
| 1451 | |
| 1452 | seq_printf(seq, "%pM %4i.%03is (%3i) %pM [%10s]:", |
| 1453 | orig_node->orig, last_seen_secs, |
| 1454 | last_seen_msecs, neigh_node->bat_iv.tq_avg, |
| 1455 | neigh_node->addr, |
| 1456 | neigh_node->if_incoming->net_dev->name); |
| 1457 | |
| 1458 | hlist_for_each_entry_rcu(neigh_node_tmp, |
| 1459 | &orig_node->neigh_list, list) { |
| 1460 | seq_printf(seq, " %pM (%3i)", |
| 1461 | neigh_node_tmp->addr, |
| 1462 | neigh_node_tmp->bat_iv.tq_avg); |
| 1463 | } |
| 1464 | |
| 1465 | seq_puts(seq, "\n"); |
| 1466 | batman_count++; |
| 1467 | |
| 1468 | next: |
| 1469 | batadv_neigh_node_free_ref(neigh_node); |
| 1470 | } |
| 1471 | rcu_read_unlock(); |
| 1472 | } |
| 1473 | |
| 1474 | if (batman_count == 0) |
| 1475 | seq_puts(seq, "No batman nodes in range ...\n"); |
| 1476 | } |
| 1477 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 1478 | static struct batadv_algo_ops batadv_batman_iv __read_mostly = { |
Marek Lindner | 519d349 | 2012-04-18 17:15:57 +0800 | [diff] [blame] | 1479 | .name = "BATMAN_IV", |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1480 | .bat_iface_enable = batadv_iv_ogm_iface_enable, |
| 1481 | .bat_iface_disable = batadv_iv_ogm_iface_disable, |
| 1482 | .bat_iface_update_mac = batadv_iv_ogm_iface_update_mac, |
| 1483 | .bat_primary_iface_set = batadv_iv_ogm_primary_iface_set, |
| 1484 | .bat_ogm_schedule = batadv_iv_ogm_schedule, |
| 1485 | .bat_ogm_emit = batadv_iv_ogm_emit, |
Antonio Quartulli | 737a2a22 | 2013-09-02 12:15:03 +0200 | [diff] [blame^] | 1486 | .bat_orig_print = batadv_iv_ogm_orig_print, |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 1487 | }; |
| 1488 | |
Sven Eckelmann | 81c524f | 2012-05-12 02:09:22 +0200 | [diff] [blame] | 1489 | int __init batadv_iv_init(void) |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 1490 | { |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1491 | int ret; |
| 1492 | |
| 1493 | /* batman originator packet */ |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1494 | ret = batadv_recv_handler_register(BATADV_IV_OGM, |
| 1495 | batadv_iv_ogm_receive); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1496 | if (ret < 0) |
| 1497 | goto out; |
| 1498 | |
Sven Eckelmann | fe8bc39 | 2012-05-12 18:33:51 +0200 | [diff] [blame] | 1499 | ret = batadv_algo_register(&batadv_batman_iv); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1500 | if (ret < 0) |
| 1501 | goto handler_unregister; |
| 1502 | |
| 1503 | goto out; |
| 1504 | |
| 1505 | handler_unregister: |
Sven Eckelmann | acd34af | 2012-06-03 22:19:21 +0200 | [diff] [blame] | 1506 | batadv_recv_handler_unregister(BATADV_IV_OGM); |
Marek Lindner | c3e2931 | 2012-03-04 16:56:25 +0800 | [diff] [blame] | 1507 | out: |
| 1508 | return ret; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 1509 | } |