From patchwork Tue Apr 23 13:39:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 2902 Return-Path: Received: from nm25-vm3.bullet.mail.ird.yahoo.com (nm25-vm3.bullet.mail.ird.yahoo.com [212.82.109.204]) by open-mesh.org (Postfix) with SMTP id 69404602071 for ; Tue, 23 Apr 2013 15:40:18 +0200 (CEST) Received: from [77.238.189.231] by nm25.bullet.mail.ird.yahoo.com with NNFMP; 23 Apr 2013 13:40:18 -0000 Received: from [217.146.188.79] by tm12.bullet.mail.ird.yahoo.com with NNFMP; 23 Apr 2013 13:40:18 -0000 Received: from [127.0.0.1] by smtp103.mail.ird.yahoo.com with NNFMP; 23 Apr 2013 13:40:18 -0000 X-Yahoo-Newman-Id: 170992.18081.bm@smtp103.mail.ird.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: lzq7a4YVM1mKVSFpthpTRtk7X.OeY4MDDLIPupySgUEbGta T.MYf69KdeWG1v3XRTlSbGYyhrZoae4VSoO0cxFsWW4st6Iz1upjTcDfvhMY qPGNy1bBCdpTBrGBYfgB.D3Gft40aU0sfSek0PEluSW5vGtv_DrtcvDkCwVr NRDAwIKRClPiTP4zZRkr601pkIkaXF3QL5ASGPaUfSsQr.XhK3mc_mQCuBVV qnKDHibf2LsifTIJu0LcwlTj1XqUW.BIQTSoKeTabcjwcPsk.UiY5Z9taqrM Khw6vlQ2w2Cnqhdpq6PrHOKOWRTK.hRW9kE_vgPzFwSZlR78Grvpvn_lHQnW ppUiXxWYmlFWoFmg4jXfy8o1OlgFJVODRDKMjYEc0bNVMoGTEff88IkJJMQ_ XGkiq3yL_4enw1TcDRoh6_7nl8pA3UZ12fceTgphUzFxsry4Qgof6cU.PcDI rZreuOxIfBCai1ypklfyqpkLNt1fppBCc9V4ik_P6Z92pzHSFVQVjZLxfzlk IzA-- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- X-Rocket-Received: from localhost (lindner_marek@79.205.244.113 with plain) by smtp103.mail.ird.yahoo.com with SMTP; 23 Apr 2013 06:40:18 -0700 PDT From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Tue, 23 Apr 2013 21:39:59 +0800 Message-Id: <1366724403-29629-4-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 3/7] batman-adv: tvlv - add distributed arp table container 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:18 -0000 Create DAT container to announce DAT capabilities (if enabled). Signed-off-by: Marek Lindner --- distributed-arp-table.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++ distributed-arp-table.h | 5 ++++ packet.h | 2 ++ sysfs.c | 3 ++- types.h | 10 ++++++++ 5 files changed, 83 insertions(+), 1 deletion(-) diff --git a/distributed-arp-table.c b/distributed-arp-table.c index 3a3e1d8..3a4b577 100644 --- a/distributed-arp-table.c +++ b/distributed-arp-table.c @@ -419,6 +419,10 @@ static bool batadv_is_orig_node_eligible(struct batadv_dat_candidate *res, bool ret = false; int j; + /* check if orig node candidate is running DAT */ + if (!(candidate->capabilities & BATADV_ORIG_CAPA_HAS_DAT)) + goto out; + /* Check if this node has already been selected... */ for (j = 0; j < select; j++) if (res[j].orig_node == candidate) @@ -626,6 +630,59 @@ out: } /** + * batadv_dat_tvlv_container_update - update the dat tvlv container after dat + * setting change + * @bat_priv: the bat priv with all the soft interface information + */ +static void batadv_dat_tvlv_container_update(struct batadv_priv *bat_priv) +{ + char dat_mode; + + dat_mode = atomic_read(&bat_priv->distributed_arp_table); + + switch (dat_mode) { + case 0: + batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_DAT, 1); + break; + case 1: + batadv_tvlv_container_register(bat_priv, BATADV_TVLV_DAT, 1, + NULL, 0); + break; + } +} + +/** + * batadv_dat_status_update - update the dat tvlv container after dat + * setting change + * @net_dev: the soft interface net device + */ +void batadv_dat_status_update(struct net_device *net_dev) +{ + struct batadv_priv *bat_priv = netdev_priv(net_dev); + batadv_dat_tvlv_container_update(bat_priv); +} + +/** + * batadv_gw_tvlv_ogm_handler_v1 - process incoming dat tvlv container + * @bat_priv: the bat priv with all the soft interface information + * @orig: the orig_node of the ogm + * @flags: flags indicating the tvlv state (see batadv_tvlv_handler_flags) + * @tvlv_value: tvlv buffer containing the gateway data + * @tvlv_value_len: tvlv buffer length + */ +static void batadv_dat_tvlv_ogm_handler_v1(struct batadv_priv *bat_priv, + struct batadv_orig_node *orig, + uint8_t flags, + void *tvlv_value, + uint16_t tvlv_value_len) +{ + if (flags & BATADV_TVLV_HANDLER_OGM_CIFNOTFND) + orig->capabilities &= ~BATADV_ORIG_CAPA_HAS_DAT; + else + orig->capabilities |= BATADV_ORIG_CAPA_HAS_DAT; +} + +/** * batadv_dat_hash_free - free the local DAT hash table * @bat_priv: the bat priv with all the soft interface information */ @@ -657,6 +714,10 @@ int batadv_dat_init(struct batadv_priv *bat_priv) batadv_dat_start_timer(bat_priv); + batadv_tvlv_handler_register(bat_priv, batadv_dat_tvlv_ogm_handler_v1, + NULL, BATADV_TVLV_DAT, 1, + BATADV_TVLV_HANDLER_OGM_CIFNOTFND); + batadv_dat_tvlv_container_update(bat_priv); return 0; } @@ -666,6 +727,9 @@ int batadv_dat_init(struct batadv_priv *bat_priv) */ void batadv_dat_free(struct batadv_priv *bat_priv) { + batadv_tvlv_container_unregister(bat_priv, BATADV_TVLV_DAT, 1); + batadv_tvlv_handler_unregister(bat_priv, BATADV_TVLV_DAT, 1); + cancel_delayed_work_sync(&bat_priv->dat.work); batadv_dat_hash_free(bat_priv); diff --git a/distributed-arp-table.h b/distributed-arp-table.h index 125c8c6..60d853b 100644 --- a/distributed-arp-table.h +++ b/distributed-arp-table.h @@ -29,6 +29,7 @@ #define BATADV_DAT_ADDR_MAX ((batadv_dat_addr_t)~(batadv_dat_addr_t)0) +void batadv_dat_status_update(struct net_device *net_dev); bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, struct sk_buff *skb); bool batadv_dat_snoop_incoming_arp_request(struct batadv_priv *bat_priv, @@ -98,6 +99,10 @@ static inline void batadv_dat_inc_counter(struct batadv_priv *bat_priv, #else +static inline void batadv_dat_status_update(struct net_device *net_dev) +{ +} + static inline bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, struct sk_buff *skb) diff --git a/packet.h b/packet.h index a7c5475..5a293da 100644 --- a/packet.h +++ b/packet.h @@ -121,9 +121,11 @@ enum batadv_bla_claimframe { /** * enum batadv_tvlv_type - tvlv type definitions * @BATADV_TVLV_GW: gateway tvlv + * @BATADV_TVLV_DAT: distributed arp table tvlv */ enum batadv_tvlv_type { BATADV_TVLV_GW = 0x01, + BATADV_TVLV_DAT = 0x02, }; /* the destination hardware field in the ARP frame is used to diff --git a/sysfs.c b/sysfs.c index 35c7649..a8e0459 100644 --- a/sysfs.c +++ b/sysfs.c @@ -421,7 +421,8 @@ BATADV_ATTR_SIF_BOOL(bonding, S_IRUGO | S_IWUSR, NULL); BATADV_ATTR_SIF_BOOL(bridge_loop_avoidance, S_IRUGO | S_IWUSR, NULL); #endif #ifdef CONFIG_BATMAN_ADV_DAT -BATADV_ATTR_SIF_BOOL(distributed_arp_table, S_IRUGO | S_IWUSR, NULL); +BATADV_ATTR_SIF_BOOL(distributed_arp_table, S_IRUGO | S_IWUSR, + batadv_dat_status_update); #endif BATADV_ATTR_SIF_BOOL(fragmentation, S_IRUGO | S_IWUSR, batadv_update_min_mtu); BATADV_ATTR_SIF_BOOL(ap_isolation, S_IRUGO | S_IWUSR, NULL); diff --git a/types.h b/types.h index d51c260..d499204 100644 --- a/types.h +++ b/types.h @@ -100,6 +100,7 @@ struct batadv_hard_iface { * @bcast_seqno_reset: time when the broadcast seqno window was reset * @batman_seqno_reset: time when the batman seqno window was reset * @flags: for now only VIS_SERVER flag + * @capabilities: announced capabilities of this originator * @last_ttvn: last seen translation table version number * @tt_crc: CRC of the translation table * @tt_buff: last tt changeset this node received from the orig node @@ -147,6 +148,7 @@ struct batadv_orig_node { unsigned long bcast_seqno_reset; unsigned long batman_seqno_reset; uint8_t flags; + uint8_t capabilities; atomic_t last_ttvn; uint16_t tt_crc; unsigned char *tt_buff; @@ -184,6 +186,14 @@ struct batadv_orig_node { }; /** + * enum batadv_orig_capabilities - orig node capabilities + * @BATADV_ORIG_CAPA_HAS_DAT: orig node has distributed arp table enabled + */ +enum batadv_orig_capabilities { + BATADV_ORIG_CAPA_HAS_DAT = BIT(1), +}; + +/** * struct batadv_gw_node - structure for orig nodes announcing gw capabilities * @list: list node for batadv_priv_gw::list * @orig_node: pointer to corresponding orig node