From patchwork Tue Apr 23 13:40:03 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 2917 Return-Path: Received: from nm7-vm0.bullet.mail.ird.yahoo.com (nm7-vm0.bullet.mail.ird.yahoo.com [77.238.189.222]) by open-mesh.org (Postfix) with SMTP id D99C060209C for ; Tue, 23 Apr 2013 15:40:31 +0200 (CEST) Received: from [77.238.189.49] by nm7.bullet.mail.ird.yahoo.com with NNFMP; 23 Apr 2013 13:40:31 -0000 Received: from [217.146.188.163] by tm2.bullet.mail.ird.yahoo.com with NNFMP; 23 Apr 2013 13:40:31 -0000 Received: from [127.0.0.1] by smtp131.mail.ird.yahoo.com with NNFMP; 23 Apr 2013 13:40:31 -0000 X-Yahoo-Newman-Id: 432818.8159.bm@smtp131.mail.ird.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 8iJaLY4VM1lEYv9z2ENmc42.L8vB8psLgi9Sk21i8j58.na h0lbHVXDRyIS2jmJYJp.bYr6sJVXnQNNRlVoDDg5IrtDiDATZj6E5X_IevKI YZOxf5qWd4zMtc.Sq4UUJnEZVCHvKlo1zkEioFRRVTQfrfYcYwgUFCbBffNh 39z3Axjo8l9w52RpzO3QO8RRzJT_og7uvsxeL5qjqgHPIrc7l_2DrwRI5woU HfOd_35c4N3uoq2LkYlP2v6vXTvafH749nG9tzFkeUx769VVUQjHnYHK6sKe RFfSdmVKY8CYEZD1eq11BbMI70jrhsunowPMginbq6hixKGOgfMrz.VRdFaE VGIKvN3DNj6lJQKC56YRkqu_OAbh4v9DKhNPJ1osRbaHgODrKFEn3EtdeyBF Xll2FyX6.D6fqwrRD0tzB17aU_6QdJhPQYo9H.LR08fp8Cpf9rVx0vi4- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- X-Rocket-Received: from localhost (lindner_marek@79.205.244.113 with plain) by smtp131.mail.ird.yahoo.com with SMTP; 23 Apr 2013 06:40:31 -0700 PDT From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Tue, 23 Apr 2013 21:40:03 +0800 Message-Id: <1366724403-29629-8-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1366724403-29629-1-git-send-email-lindner_marek@yahoo.de> References: <1366724403-29629-1-git-send-email-lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCHv2 7/7] batman-adv: tvlv - convert roaming adv packet to use tvlv unicast packets X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 23 Apr 2013 13:40:32 -0000 Instead of generating roaming specific packets the TVLV unicast API is used to send roaming information. Signed-off-by: Marek Lindner --- main.c | 2 - packet.h | 19 +++++----- routing.c | 42 --------------------- translation-table.c | 102 ++++++++++++++++++++++++++++++++++++--------------- 4 files changed, 83 insertions(+), 82 deletions(-) diff --git a/main.c b/main.c index 4529a44..f257a5b 100644 --- a/main.c +++ b/main.c @@ -349,8 +349,6 @@ static void batadv_recv_handler_init(void) batadv_rx_handler[BATADV_BCAST] = batadv_recv_bcast_packet; /* vis packet */ batadv_rx_handler[BATADV_VIS] = batadv_recv_vis_packet; - /* Roaming advertisement */ - batadv_rx_handler[BATADV_ROAM_ADV] = batadv_recv_roam_adv; /* unicast tvlv packet */ batadv_rx_handler[BATADV_UNICAST_TVLV] = batadv_recv_unicast_tvlv; } diff --git a/packet.h b/packet.h index 4675dc4..c4653a5 100644 --- a/packet.h +++ b/packet.h @@ -31,7 +31,6 @@ enum batadv_packettype { BATADV_BCAST = 0x04, BATADV_VIS = 0x05, BATADV_UNICAST_FRAG = 0x06, - BATADV_ROAM_ADV = 0x08, BATADV_UNICAST_4ADDR = 0x09, BATADV_CODED = 0x0a, BATADV_UNICAST_TVLV = 0x0b, @@ -127,12 +126,14 @@ enum batadv_bla_claimframe { * @BATADV_TVLV_DAT: distributed arp table tvlv * @BATADV_TVLV_NC: network coding tvlv * @BATADV_TVLV_TT: translation table tvlv + * @BATADV_TVLV_ROAM: roaming advertisement tvlv */ enum batadv_tvlv_type { BATADV_TVLV_GW = 0x01, BATADV_TVLV_DAT = 0x02, BATADV_TVLV_NC = 0x03, BATADV_TVLV_TT = 0x04, + BATADV_TVLV_ROAM = 0x05, }; /* the destination hardware field in the ARP frame is used to @@ -267,14 +268,6 @@ struct batadv_vis_packet { uint8_t sender_orig[ETH_ALEN]; /* who sent or forwarded this packet */ }; -struct batadv_roam_adv_packet { - struct batadv_header header; - uint8_t reserved; - uint8_t dst[ETH_ALEN]; - uint8_t src[ETH_ALEN]; - uint8_t client[ETH_ALEN]; -} __packed; - /** * struct batadv_coded_packet - network coded packet * @header: common batman packet header and ttl of first included packet @@ -399,4 +392,12 @@ struct batadv_tvlv_tt_change { uint8_t addr[ETH_ALEN]; }; +/** + * struct batadv_tvlv_roam_adv - roaming advertisement + * @client: mac address of roaming client + */ +struct batadv_tvlv_roam_adv { + uint8_t client[ETH_ALEN]; +}; + #endif /* _NET_BATMAN_ADV_PACKET_H_ */ diff --git a/routing.c b/routing.c index 968a0e9..e5671f5 100644 --- a/routing.c +++ b/routing.c @@ -557,48 +557,6 @@ static int batadv_check_unicast_packet(struct batadv_priv *bat_priv, return 0; } -int batadv_recv_roam_adv(struct sk_buff *skb, struct batadv_hard_iface *recv_if) -{ - struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); - struct batadv_roam_adv_packet *roam_adv_packet; - struct batadv_orig_node *orig_node; - - if (batadv_check_unicast_packet(bat_priv, skb, - sizeof(*roam_adv_packet)) < 0) - goto out; - - batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX); - - roam_adv_packet = (struct batadv_roam_adv_packet *)skb->data; - - if (!batadv_is_my_mac(bat_priv, roam_adv_packet->dst)) - return batadv_route_unicast_packet(skb, recv_if); - - /* check if it is a backbone gateway. we don't accept - * roaming advertisement from it, as it has the same - * entries as we have. - */ - if (batadv_bla_is_backbone_gw_orig(bat_priv, roam_adv_packet->src)) - goto out; - - orig_node = batadv_orig_hash_find(bat_priv, roam_adv_packet->src); - if (!orig_node) - goto out; - - batadv_dbg(BATADV_DBG_TT, bat_priv, - "Received ROAMING_ADV from %pM (client %pM)\n", - roam_adv_packet->src, roam_adv_packet->client); - - batadv_tt_global_add(bat_priv, orig_node, roam_adv_packet->client, - BATADV_TT_CLIENT_ROAM, - atomic_read(&orig_node->last_ttvn) + 1); - - batadv_orig_node_free_ref(orig_node); -out: - /* returning NET_RX_DROP will make the caller function kfree the skb */ - return NET_RX_DROP; -} - /* find a suitable router for this originator, and use * bonding if possible. increases the found neighbors * refcount. diff --git a/translation-table.c b/translation-table.c index 062e4c9..e153414 100644 --- a/translation-table.c +++ b/translation-table.c @@ -2189,11 +2189,12 @@ unlock: static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, struct batadv_orig_node *orig_node) { - struct sk_buff *skb = NULL; - struct batadv_roam_adv_packet *roam_adv_packet; - int ret = 1; struct batadv_hard_iface *primary_if; - size_t len = sizeof(*roam_adv_packet); + struct batadv_tvlv_roam_adv tvlv_roam; + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if) + goto out; /* before going on we have to check whether the client has * already roamed to us too many times @@ -2201,39 +2202,21 @@ static void batadv_send_roam_adv(struct batadv_priv *bat_priv, uint8_t *client, if (!batadv_tt_check_roam_count(bat_priv, client)) goto out; - skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN); - if (!skb) - goto out; - - skb_reserve(skb, ETH_HLEN); - - roam_adv_packet = (struct batadv_roam_adv_packet *)skb_put(skb, len); - - roam_adv_packet->header.packet_type = BATADV_ROAM_ADV; - roam_adv_packet->header.version = BATADV_COMPAT_VERSION; - roam_adv_packet->header.ttl = BATADV_TTL; - roam_adv_packet->reserved = 0; - primary_if = batadv_primary_if_get_selected(bat_priv); - if (!primary_if) - goto out; - memcpy(roam_adv_packet->src, primary_if->net_dev->dev_addr, ETH_ALEN); - batadv_hardif_free_ref(primary_if); - memcpy(roam_adv_packet->dst, orig_node->orig, ETH_ALEN); - memcpy(roam_adv_packet->client, client, ETH_ALEN); - batadv_dbg(BATADV_DBG_TT, bat_priv, "Sending ROAMING_ADV to %pM (client %pM)\n", orig_node->orig, client); batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_TX); - if (batadv_send_skb_to_orig(skb, orig_node, NULL) != NET_XMIT_DROP) - ret = 0; + memcpy(tvlv_roam.client, client, sizeof(tvlv_roam.client)); + + batadv_tvlv_unicast_send(bat_priv, primary_if->net_dev->dev_addr, + orig_node->orig, BATADV_TVLV_ROAM, 1, + &tvlv_roam, sizeof(tvlv_roam)); out: - if (ret && skb) - kfree_skb(skb); - return; + if (primary_if) + batadv_hardif_free_ref(primary_if); } static void batadv_tt_purge(struct work_struct *work) @@ -2667,6 +2650,63 @@ static int batadv_tt_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv, } /** + * batadv_roam_tvlv_unicast_handler_v1 - process incoming tt roam tvlv container + * @bat_priv: the bat priv with all the soft interface information + * @src: mac address of tt tvlv sender + * @dst: mac address of tt tvlv recipient + * @tvlv_value: tvlv buffer containing the tt data + * @tvlv_value_len: tvlv buffer length + * + * Returns NET_RX_DROP if the tt roam tvlv is to be re-routed, NET_RX_SUCCESS + * otherwise. + */ +static int batadv_roam_tvlv_unicast_handler_v1(struct batadv_priv *bat_priv, + uint8_t *src, uint8_t *dst, + void *tvlv_value, + uint16_t tvlv_value_len) +{ + struct batadv_tvlv_roam_adv *roaming_adv; + struct batadv_orig_node *orig_node = NULL; + + /* If this node is not the intended recipient of the + * roaming advertisement the packet is forwarded + * (the tvlv API will re-route the packet). + */ + if (!batadv_is_my_mac(bat_priv, dst)) + return NET_RX_DROP; + + /* check if it is a backbone gateway. we don't accept + * roaming advertisement from it, as it has the same + * entries as we have. + */ + if (batadv_bla_is_backbone_gw_orig(bat_priv, src)) + goto out; + + if (tvlv_value_len < sizeof(*roaming_adv)) + goto out; + + orig_node = batadv_orig_hash_find(bat_priv, src); + if (!orig_node) + goto out; + + batadv_inc_counter(bat_priv, BATADV_CNT_TT_ROAM_ADV_RX); + roaming_adv = (struct batadv_tvlv_roam_adv *)tvlv_value; + + batadv_dbg(BATADV_DBG_TT, bat_priv, + "Received ROAMING_ADV from %pM (client %pM)\n", + src, roaming_adv->client); + + batadv_tt_global_add(bat_priv, orig_node, roaming_adv->client, + BATADV_TT_CLIENT_ROAM, + atomic_read(&orig_node->last_ttvn) + 1); + +out: + if (orig_node) + batadv_orig_node_free_ref(orig_node); + return NET_RX_SUCCESS; +} + +/** * batadv_tt_init - initialise the translation table internals * @bat_priv: the bat priv with all the soft interface information * @@ -2688,6 +2728,10 @@ int batadv_tt_init(struct batadv_priv *bat_priv) batadv_tt_tvlv_unicast_handler_v1, BATADV_TVLV_TT, 1, BATADV_NO_FLAGS); + batadv_tvlv_handler_register(bat_priv, NULL, + batadv_roam_tvlv_unicast_handler_v1, + BATADV_TVLV_ROAM, 1, BATADV_NO_FLAGS); + INIT_DELAYED_WORK(&bat_priv->tt.work, batadv_tt_purge); queue_delayed_work(batadv_event_workqueue, &bat_priv->tt.work, msecs_to_jiffies(BATADV_TT_WORK_PERIOD));