diff options
author | Marek Lindner <lindner_marek@yahoo.de> | 2013-04-23 09:40:03 -0400 |
---|---|---|
committer | Antonio Quartulli <antonio@meshcoding.com> | 2013-10-09 15:22:30 -0400 |
commit | 122edaa05940c021a55492d8c12f7663ce5168de (patch) | |
tree | 535cbdaa3d8e699e37657a1590c3f1bb19dd526c /net/batman-adv | |
parent | 335fbe0f5d2501b7dd815806aef6fd9bad784eb1 (diff) |
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>
Diffstat (limited to 'net/batman-adv')
-rw-r--r-- | net/batman-adv/main.c | 2 | ||||
-rw-r--r-- | net/batman-adv/packet.h | 21 | ||||
-rw-r--r-- | net/batman-adv/routing.c | 42 | ||||
-rw-r--r-- | net/batman-adv/translation-table.c | 104 |
4 files changed, 86 insertions, 83 deletions
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c index 39d9b44fba44..fc55acbacacf 100644 --- a/net/batman-adv/main.c +++ b/net/batman-adv/main.c | |||
@@ -414,8 +414,6 @@ static void batadv_recv_handler_init(void) | |||
414 | batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet; | 414 | batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet; |
415 | /* vis packet */ | 415 | /* vis packet */ |
416 | batadv_rx_handler[BATADV_VIS] = batadv_recv_vis_packet; | 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 | /* unicast tvlv packet */ | 417 | /* unicast tvlv packet */ |
420 | batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv; | 418 | batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv; |
421 | } | 419 | } |
diff --git a/net/batman-adv/packet.h b/net/batman-adv/packet.h index a602efc76750..5c08d261e69a 100644 --- a/net/batman-adv/packet.h +++ b/net/batman-adv/packet.h | |||
@@ -31,7 +31,6 @@ enum batadv_packettype { | |||
31 | BATADV_BCAST = 0x04, | 31 | BATADV_BCAST = 0x04, |
32 | BATADV_VIS = 0x05, | 32 | BATADV_VIS = 0x05, |
33 | BATADV_UNICAST_FRAG = 0x06, | 33 | BATADV_UNICAST_FRAG = 0x06, |
34 | BATADV_ROAM_ADV = 0x08, | ||
35 | BATADV_UNICAST_4ADDR = 0x09, | 34 | BATADV_UNICAST_4ADDR = 0x09, |
36 | BATADV_CODED = 0x0a, | 35 | BATADV_CODED = 0x0a, |
37 | BATADV_UNICAST_TVLV = 0x0b, | 36 | BATADV_UNICAST_TVLV = 0x0b, |
@@ -127,12 +126,14 @@ enum batadv_bla_claimframe { | |||
127 | * @BATADV_TVLV_DAT: distributed arp table tvlv | 126 | * @BATADV_TVLV_DAT: distributed arp table tvlv |
128 | * @BATADV_TVLV_NC: network coding tvlv | 127 | * @BATADV_TVLV_NC: network coding tvlv |
129 | * @BATADV_TVLV_TT: translation table tvlv | 128 | * @BATADV_TVLV_TT: translation table tvlv |
129 | * @BATADV_TVLV_ROAM: roaming advertisement tvlv | ||
130 | */ | 130 | */ |
131 | enum batadv_tvlv_type { | 131 | enum batadv_tvlv_type { |
132 | BATADV_TVLV_GW = 0x01, | 132 | BATADV_TVLV_GW = 0x01, |
133 | BATADV_TVLV_DAT = 0x02, | 133 | BATADV_TVLV_DAT = 0x02, |
134 | BATADV_TVLV_NC = 0x03, | 134 | BATADV_TVLV_NC = 0x03, |
135 | BATADV_TVLV_TT = 0x04, | 135 | BATADV_TVLV_TT = 0x04, |
136 | BATADV_TVLV_ROAM = 0x05, | ||
136 | }; | 137 | }; |
137 | 138 | ||
138 | /* the destination hardware field in the ARP frame is used to | 139 | /* the destination hardware field in the ARP frame is used to |
@@ -267,14 +268,6 @@ struct batadv_vis_packet { | |||
267 | uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */ | 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 | * struct batadv_coded_packet - network coded packet | 272 | * struct batadv_coded_packet - network coded packet |
280 | * @header: common batman packet header and ttl of first included packet | 273 | * @header: common batman packet header and ttl of first included packet |
@@ -373,4 +366,14 @@ struct batadv_tvlv_tt_change { | |||
373 | uint8_t addr[ETH_ALEN]; | 366 | uint8_t addr[ETH_ALEN]; |
374 | }; | 367 | }; |
375 | 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; | ||
377 | }; | ||
378 | |||
376 | #endif /* _NET_BATMAN_ADV_PACKET_H_ */ | 379 | #endif /* _NET_BATMAN_ADV_PACKET_H_ */ |
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index d12858110f91..a5bf8fffdcea 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -557,48 +557,6 @@ static int batadv_check_unicast_packet(struct batadv_priv *bat_priv, | |||
557 | return 0; | 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 | /* find a suitable router for this originator, and use | 560 | /* find a suitable router for this originator, and use |
603 | * bonding if possible. increases the found neighbors | 561 | * bonding if possible. increases the found neighbors |
604 | * refcount. | 562 | * refcount. |
diff --git a/net/batman-adv/translation-table.c b/net/batman-adv/translation-table.c index 22fce8a4793e..1149f8610762 100644 --- a/net/batman-adv/translation-table.c +++ b/net/batman-adv/translation-table.c | |||
@@ -2189,11 +2189,12 @@ unlock: | |||
2189 | static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, | 2189 | static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, |
2190 | struct batadv_orig_node *orig_node) | 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 | struct batadv_hard_iface *primary_if; | 2192 | struct batadv_hard_iface *primary_if; |
2196 | size_t len = sizeof(*roam_adv_packet); | 2193 | struct batadv_tvlv_roam_adv tvlv_roam; |
2194 | |||
2195 | primary_if = batadv_primary_if_get_selected(bat_priv); | ||
2196 | if (!primary_if) | ||
2197 | goto out; | ||
2197 | 2198 | ||
2198 | /* before going on we have to check whether the client has | 2199 | /* before going on we have to check whether the client has |
2199 | * already roamed to us too many times | 2200 | * already roamed to us too many times |
@@ -2201,40 +2202,22 @@ static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, | |||
2201 | if (!batadv_tt_check_roam_count(bat_priv, client)) | 2202 | if (!batadv_tt_check_roam_count(bat_priv, client)) |
2202 | goto out; | 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 | batadv_dbg(BATADV_DBG_TT, bat_priv, | 2205 | batadv_dbg(BATADV_DBG_TT, bat_priv, |
2226 | "Sending ROAMING_ADV to %pM (client %pM)\n", | 2206 | "Sending ROAMING_ADV to %pM (client %pM)\n", |
2227 | orig_node->orig, client); | 2207 | orig_node->orig, client); |
2228 | 2208 | ||
2229 | batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX); | 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) | 2211 | memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client)); |
2232 | ret = 0; | 2212 | tvlv_roam.reserved = 0; |
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)); | ||
2233 | 2217 | ||
2234 | out: | 2218 | out: |
2235 | if (ret && skb) | 2219 | if (primary_if) |
2236 | kfree_skb(skb); | 2220 | batadv_hardif_free_ref(primary_if); |
2237 | return; | ||
2238 | } | 2221 | } |
2239 | 2222 | ||
2240 | static void batadv_tt_purge(struct work_struct *work) | 2223 | static void batadv_tt_purge(struct work_struct *work) |
@@ -2668,6 +2651,63 @@ static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv, | |||
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 | * batadv_tt_init - initialise the translation table internals | 2711 | * batadv_tt_init - initialise the translation table internals |
2672 | * @bat_priv: the bat priv with all the soft interface information | 2712 | * @bat_priv: the bat priv with all the soft interface information |
2673 | * | 2713 | * |
@@ -2689,6 +2729,10 @@ int batadv_tt_init(struct batadv_priv *bat_priv) | |||
2689 | batadv_tt_tvlv_unicast_handler_v1, | 2729 | batadv_tt_tvlv_unicast_handler_v1, |
2690 | BATADV_TVLV_TT, 1, BATADV_NO_FLAGS); | 2730 | BATADV_TVLV_TT, 1, BATADV_NO_FLAGS); |
2691 | 2731 | ||
2732 | batadv_tvlv_handler_register(bat_priv, NULL, | ||
2733 | batadv_roam_tvlv_unicast_handler_v1, | ||
2734 | BATADV_TVLV_ROAM, 1, BATADV_NO_FLAGS); | ||
2735 | |||
2692 | INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge); | 2736 | INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge); |
2693 | queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work, | 2737 | queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work, |
2694 | msecs_to_jiffies(BATADV_TT_WORK_PERIOD)); | 2738 | msecs_to_jiffies(BATADV_TT_WORK_PERIOD)); |