Commit 122edaa05940c021a55492d8c12f7663ce5168de

Authored by Marek Lindner
Committed by Antonio Quartulli
1 parent 335fbe0f5d

batman-adv: tvlv - convert roaming adv packet to use tvlv unicast packets

Instead of generating roaming specific packets the TVLV unicast API is
used to send roaming information.

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>

Showing 4 changed files with 86 additions and 83 deletions Side-by-side Diff

net/batman-adv/main.c
... ... @@ -414,8 +414,6 @@
414 414 batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet;
415 415 /* vis packet */
416 416 batadv_rx_handler[BATADV_VIS] = batadv_recv_vis_packet;
417   - /* Roaming advertisement */
418   - batadv_rx_handler[BATADV_ROAM_ADV] = batadv_recv_roam_adv;
419 417 /* unicast tvlv packet */
420 418 batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv;
421 419 }
net/batman-adv/packet.h
... ... @@ -31,7 +31,6 @@
31 31 BATADV_BCAST = 0x04,
32 32 BATADV_VIS = 0x05,
33 33 BATADV_UNICAST_FRAG = 0x06,
34   - BATADV_ROAM_ADV = 0x08,
35 34 BATADV_UNICAST_4ADDR = 0x09,
36 35 BATADV_CODED = 0x0a,
37 36 BATADV_UNICAST_TVLV = 0x0b,
38 37  
... ... @@ -127,12 +126,14 @@
127 126 * @BATADV_TVLV_DAT: distributed arp table tvlv
128 127 * @BATADV_TVLV_NC: network coding tvlv
129 128 * @BATADV_TVLV_TT: translation table tvlv
  129 + * @BATADV_TVLV_ROAM: roaming advertisement tvlv
130 130 */
131 131 enum batadv_tvlv_type {
132 132 BATADV_TVLV_GW = 0x01,
133 133 BATADV_TVLV_DAT = 0x02,
134 134 BATADV_TVLV_NC = 0x03,
135 135 BATADV_TVLV_TT = 0x04,
  136 + BATADV_TVLV_ROAM = 0x05,
136 137 };
137 138  
138 139 /* the destination hardware field in the ARP frame is used to
... ... @@ -267,14 +268,6 @@
267 268 uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */
268 269 };
269 270  
270   -struct batadv_roam_adv_packet {
271   - struct batadv_header header;
272   - uint8_t reserved;
273   - uint8_t dst[ETH_ALEN];
274   - uint8_t src[ETH_ALEN];
275   - uint8_t client[ETH_ALEN];
276   -} __packed;
277   -
278 271 /**
279 272 * struct batadv_coded_packet - network coded packet
280 273 * @header: common batman packet header and ttl of first included packet
... ... @@ -371,6 +364,16 @@
371 364 uint8_t flags;
372 365 uint8_t reserved;
373 366 uint8_t addr[ETH_ALEN];
  367 +};
  368 +
  369 +/**
  370 + * struct batadv_tvlv_roam_adv - roaming advertisement
  371 + * @client: mac address of roaming client
  372 + * @reserved: field reserved for future use
  373 + */
  374 +struct batadv_tvlv_roam_adv {
  375 + uint8_t client[ETH_ALEN];
  376 + uint16_t reserved;
374 377 };
375 378  
376 379 #endif /* _NET_BATMAN_ADV_PACKET_H_ */
net/batman-adv/routing.c
... ... @@ -557,48 +557,6 @@
557 557 return 0;
558 558 }
559 559  
560   -int batadv_recv_roam_adv(struct sk_buff *skb, struct batadv_hard_iface *recv_if)
561   -{
562   - struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface);
563   - struct batadv_roam_adv_packet *roam_adv_packet;
564   - struct batadv_orig_node *orig_node;
565   -
566   - if (batadv_check_unicast_packet(bat_priv, skb,
567   - sizeof(*roam_adv_packet)) < 0)
568   - goto out;
569   -
570   - batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX);
571   -
572   - roam_adv_packet = (struct batadv_roam_adv_packet *)skb->data;
573   -
574   - if (!batadv_is_my_mac(bat_priv, roam_adv_packet->dst))
575   - return batadv_route_unicast_packet(skb, recv_if);
576   -
577   - /* check if it is a backbone gateway. we don't accept
578   - * roaming advertisement from it, as it has the same
579   - * entries as we have.
580   - */
581   - if (batadv_bla_is_backbone_gw_orig(bat_priv, roam_adv_packet->src))
582   - goto out;
583   -
584   - orig_node = batadv_orig_hash_find(bat_priv, roam_adv_packet->src);
585   - if (!orig_node)
586   - goto out;
587   -
588   - batadv_dbg(BATADV_DBG_TT, bat_priv,
589   - "Received ROAMING_ADV from %pM (client %pM)\n",
590   - roam_adv_packet->src, roam_adv_packet->client);
591   -
592   - batadv_tt_global_add(bat_priv, orig_node, roam_adv_packet->client,
593   - BATADV_TT_CLIENT_ROAM,
594   - atomic_read(&orig_node->last_ttvn) + 1);
595   -
596   - batadv_orig_node_free_ref(orig_node);
597   -out:
598   - /* returning NET_RX_DROP will make the caller function kfree the skb */
599   - return NET_RX_DROP;
600   -}
601   -
602 560 /* find a suitable router for this originator, and use
603 561 * bonding if possible. increases the found neighbors
604 562 * refcount.
net/batman-adv/translation-table.c
... ... @@ -2189,52 +2189,35 @@
2189 2189 static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client,
2190 2190 struct batadv_orig_node *orig_node)
2191 2191 {
2192   - struct sk_buff *skb = NULL;
2193   - struct batadv_roam_adv_packet *roam_adv_packet;
2194   - int ret = 1;
2195 2192 struct batadv_hard_iface *primary_if;
2196   - size_t len = sizeof(*roam_adv_packet);
  2193 + struct batadv_tvlv_roam_adv tvlv_roam;
2197 2194  
  2195 + primary_if = batadv_primary_if_get_selected(bat_priv);
  2196 + if (!primary_if)
  2197 + goto out;
  2198 +
2198 2199 /* before going on we have to check whether the client has
2199 2200 * already roamed to us too many times
2200 2201 */
2201 2202 if (!batadv_tt_check_roam_count(bat_priv, client))
2202 2203 goto out;
2203 2204  
2204   - skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);
2205   - if (!skb)
2206   - goto out;
2207   -
2208   - skb->priority = TC_PRIO_CONTROL;
2209   - skb_reserve(skb, ETH_HLEN);
2210   -
2211   - roam_adv_packet = (struct batadv_roam_adv_packet *)skb_put(skb, len);
2212   -
2213   - roam_adv_packet->header.packet_type = BATADV_ROAM_ADV;
2214   - roam_adv_packet->header.version = BATADV_COMPAT_VERSION;
2215   - roam_adv_packet->header.ttl = BATADV_TTL;
2216   - roam_adv_packet->reserved = 0;
2217   - primary_if = batadv_primary_if_get_selected(bat_priv);
2218   - if (!primary_if)
2219   - goto out;
2220   - memcpy(roam_adv_packet->src, primary_if->net_dev->dev_addr, ETH_ALEN);
2221   - batadv_hardif_free_ref(primary_if);
2222   - memcpy(roam_adv_packet->dst, orig_node->orig, ETH_ALEN);
2223   - memcpy(roam_adv_packet->client, client, ETH_ALEN);
2224   -
2225 2205 batadv_dbg(BATADV_DBG_TT, bat_priv,
2226 2206 "Sending ROAMING_ADV to %pM (client %pM)\n",
2227 2207 orig_node->orig, client);
2228 2208  
2229 2209 batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX);
2230 2210  
2231   - if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP)
2232   - ret = 0;
  2211 + memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client));
  2212 + tvlv_roam.reserved = 0;
2233 2213  
  2214 + batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr,
  2215 + orig_node->orig, BATADV_TVLV_ROAM, 1,
  2216 + &tvlv_roam, sizeof(tvlv_roam));
  2217 +
2234 2218 out:
2235   - if (ret && skb)
2236   - kfree_skb(skb);
2237   - return;
  2219 + if (primary_if)
  2220 + batadv_hardif_free_ref(primary_if);
2238 2221 }
2239 2222  
2240 2223 static void batadv_tt_purge(struct work_struct *work)
... ... @@ -2668,6 +2651,63 @@
2668 2651 }
2669 2652  
2670 2653 /**
  2654 + * batadv_roam_tvlv_unicast_handler_v1 - process incoming tt roam tvlv container
  2655 + * @bat_priv: the bat priv with all the soft interface information
  2656 + * @src: mac address of tt tvlv sender
  2657 + * @dst: mac address of tt tvlv recipient
  2658 + * @tvlv_value: tvlv buffer containing the tt data
  2659 + * @tvlv_value_len: tvlv buffer length
  2660 + *
  2661 + * Returns NET_RX_DROP if the tt roam tvlv is to be re-routed, NET_RX_SUCCESS
  2662 + * otherwise.
  2663 + */
  2664 +static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv,
  2665 + uint8_t *src, uint8_t *dst,
  2666 + void *tvlv_value,
  2667 + uint16_t tvlv_value_len)
  2668 +{
  2669 + struct batadv_tvlv_roam_adv *roaming_adv;
  2670 + struct batadv_orig_node *orig_node = NULL;
  2671 +
  2672 + /* If this node is not the intended recipient of the
  2673 + * roaming advertisement the packet is forwarded
  2674 + * (the tvlv API will re-route the packet).
  2675 + */
  2676 + if (!batadv_is_my_mac(bat_priv, dst))
  2677 + return NET_RX_DROP;
  2678 +
  2679 + /* check if it is a backbone gateway. we don't accept
  2680 + * roaming advertisement from it, as it has the same
  2681 + * entries as we have.
  2682 + */
  2683 + if (batadv_bla_is_backbone_gw_orig(bat_priv, src))
  2684 + goto out;
  2685 +
  2686 + if (tvlv_value_len < sizeof(*roaming_adv))
  2687 + goto out;
  2688 +
  2689 + orig_node = batadv_orig_hash_find(bat_priv, src);
  2690 + if (!orig_node)
  2691 + goto out;
  2692 +
  2693 + batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX);
  2694 + roaming_adv = (struct batadv_tvlv_roam_adv *)tvlv_value;
  2695 +
  2696 + batadv_dbg(BATADV_DBG_TT, bat_priv,
  2697 + "Received ROAMING_ADV from %pM (client %pM)\n",
  2698 + src, roaming_adv->client);
  2699 +
  2700 + batadv_tt_global_add(bat_priv, orig_node, roaming_adv->client,
  2701 + BATADV_TT_CLIENT_ROAM,
  2702 + atomic_read(&orig_node->last_ttvn) + 1);
  2703 +
  2704 +out:
  2705 + if (orig_node)
  2706 + batadv_orig_node_free_ref(orig_node);
  2707 + return NET_RX_SUCCESS;
  2708 +}
  2709 +
  2710 +/**
2671 2711 * batadv_tt_init - initialise the translation table internals
2672 2712 * @bat_priv: the bat priv with all the soft interface information
2673 2713 *
... ... @@ -2688,6 +2728,10 @@
2688 2728 batadv_tvlv_handler_register(bat_priv, batadv_tt_tvlv_ogm_handler_v1,
2689 2729 batadv_tt_tvlv_unicast_handler_v1,
2690 2730 BATADV_TVLV_TT, 1, BATADV_NO_FLAGS);
  2731 +
  2732 + batadv_tvlv_handler_register(bat_priv, NULL,
  2733 + batadv_roam_tvlv_unicast_handler_v1,
  2734 + BATADV_TVLV_ROAM, 1, BATADV_NO_FLAGS);
2691 2735  
2692 2736 INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge);
2693 2737 queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work,