aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/translation-table.c
diff options
context:
space:
mode:
authorMarek Lindner <lindner_marek@yahoo.de>2013-04-23 09:40:03 -0400
committerAntonio Quartulli <antonio@meshcoding.com>2013-10-09 15:22:30 -0400
commit122edaa05940c021a55492d8c12f7663ce5168de (patch)
tree535cbdaa3d8e699e37657a1590c3f1bb19dd526c /net/batman-adv/translation-table.c
parent335fbe0f5d2501b7dd815806aef6fd9bad784eb1 (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/translation-table.c')
-rw-r--r--net/batman-adv/translation-table.c104
1 files changed, 74 insertions, 30 deletions
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:
2189static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, 2189static 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
2234out: 2218out:
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
2240static void batadv_tt_purge(struct work_struct *work) 2223static 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 */
2664static 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
2704out:
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));