From patchwork Fri May 6 08:58:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andreas Pape X-Patchwork-Id: 16093 X-Patchwork-Delegate: mareklindner@neomailbox.ch Return-Path: X-Original-To: patchwork@open-mesh.org Delivered-To: patchwork@open-mesh.org Received: from open-mesh.org (localhost [IPv6:::1]) by open-mesh.org (Postfix) with ESMTP id 7284D82703; Fri, 6 May 2016 11:08:48 +0200 (CEST) Authentication-Results: open-mesh.org; dmarc=none header.from=phoenixcontact.com Received-SPF: None (no SPF record) identity=mailfrom; client-ip=62.157.123.121; helo=mail2.phoenixcontact.com; envelope-from=apape@phoenixcontact.com; receiver=b.a.t.m.a.n@lists.open-mesh.org Authentication-Results: open-mesh.org; dmarc=none header.from=phoenixcontact.com Received: from mail2.phoenixcontact.com (mail2.phoenixcontact.com [62.157.123.121]) by open-mesh.org (Postfix) with ESMTPS id 0137682703 for ; Fri, 6 May 2016 11:08:46 +0200 (CEST) Received: from localhost.localdomain ([149.208.237.127]) by de-nice01.de.phoenixcontact.com with ESMTP id 2016050610584170-87320 ; Fri, 6 May 2016 10:58:41 +0200 From: Andreas Pape To: b.a.t.m.a.n@lists.open-mesh.org X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1462525107-19750-1-git-send-email-apape@phoenixcontact.com> References: <1462525107-19750-1-git-send-email-apape@phoenixcontact.com> X-MIMETrack: Itemize by SMTP Server on DE-NICE01/Hub/SRV/DE/Phoenix Contact at 06.05.2016 10:58:41, Serialize by ntm_grab.EXE on nemex02/spoke/SRV/DE/Phoenix Contact at 06.05.2016 10:58:34, Serialize complete at 06.05.2016 10:58:34, Itemize by ntm_grab.EXE on nemex02/spoke/SRV/DE/Phoenix Contact at 06.05.2016 10:58:34, Serialize by Router on nemex02/spoke/SRV/DE/Phoenix Contact at 06.05.2016 11:08:38, Serialize complete at 06.05.2016 11:08:38 X-TNEFEvaluated: 1 Message-ID: <1462525107-19750-2-git-send-email-apape@phoenixcontact.com> Date: Fri, 6 May 2016 10:58:22 +0200 content-transfer-encoding: quoted-printable content-type: text/plain; charset="utf-8" Subject: [B.A.T.M.A.N.] [PATCHv3 1/6] batman-adv: prevent multiple ARP replies sent by gateways if dat enbled X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking Errors-To: b.a.t.m.a.n-bounces@lists.open-mesh.org Sender: "B.A.T.M.A.N" If dat is enabled it must be made sure that only the backbone gw which has claimed the remote destination for the ARP request answers the ARP request directly if the MAC address is known due to the local dat table. This prevents multiple ARP replies in a common backbone if more than one gateway already knows the remote mac searched for in the ARP request. Signed-off-by: Andreas Pape --- net/batman-adv/bridge_loop_avoidance.c | 49 ++++++++++++++++++++++++++++++++ net/batman-adv/bridge_loop_avoidance.h | 11 +++++++ net/batman-adv/distributed-arp-table.c | 15 ++++++++++ 3 files changed, 75 insertions(+), 0 deletions(-) -- 1.7.0.4 .................................................................. PHOENIX CONTACT ELECTRONICS GmbH Sitz der Gesellschaft / registered office of the company: 31812 Bad Pyrmont USt-Id-Nr.: DE811742156 Amtsgericht Hannover HRB 100528 / district court Hannover HRB 100528 Geschäftsführer / Executive Board: Roland Bent, Dr. Martin Heubeck diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c index 748a9ea..2f46ce9 100644 --- a/net/batman-adv/bridge_loop_avoidance.c +++ b/net/batman-adv/bridge_loop_avoidance.c @@ -2045,3 +2045,52 @@ out: batadv_hardif_put(primary_if); return 0; } + +#ifdef CONFIG_BATMAN_ADV_DAT +/** + * batadv_bla_handle_local_claim - check if address is claimed + * + * @bat_priv: the bat priv with all the soft interface information + * @addr: mac address of which the claim status is checked + * @vid: the VLAN ID + * + * addr is checked if this address is claimed by the local device itself. + * + * Return: true if bla is disabled or the mac is claimed by the device, + * false if the device addr is already claimed by another gateway + */ +bool batadv_bla_handle_local_claim(struct batadv_priv *bat_priv, + u8 *addr, unsigned short vid) +{ + struct batadv_bla_claim search_claim; + struct batadv_bla_claim *claim = NULL; + struct batadv_hard_iface *primary_if = NULL; + bool ret = true; + + if (!atomic_read(&bat_priv->bridge_loop_avoidance)) + return ret; + + primary_if = batadv_primary_if_get_selected(bat_priv); + if (!primary_if) + return ret; + + /* First look if the mac address is claimed */ + ether_addr_copy(search_claim.addr, addr); + search_claim.vid = vid; + + claim = batadv_claim_hash_find(bat_priv, &search_claim); + + /* If there is a claim and we are not owner of the claim, + * return false. + */ + if (claim) { + if (!batadv_compare_eth(claim->backbone_gw->orig, + primary_if->net_dev->dev_addr)) + ret = false; + batadv_claim_put(claim); + } + + batadv_hardif_put(primary_if); + return ret; +} +#endif diff --git a/net/batman-adv/bridge_loop_avoidance.h b/net/batman-adv/bridge_loop_avoidance.h index 0f01dae..cc07be9 100644 --- a/net/batman-adv/bridge_loop_avoidance.h +++ b/net/batman-adv/bridge_loop_avoidance.h @@ -47,6 +47,10 @@ void batadv_bla_update_orig_address(struct batadv_priv *bat_priv, void batadv_bla_status_update(struct net_device *net_dev); int batadv_bla_init(struct batadv_priv *bat_priv); void batadv_bla_free(struct batadv_priv *bat_priv); +#ifdef CONFIG_BATMAN_ADV_DAT +bool batadv_bla_handle_local_claim(struct batadv_priv *bat_priv, u8 *addr, + unsigned short vid); +#endif #define BATADV_BLA_CRC_INIT 0 #else /* ifdef CONFIG_BATMAN_ADV_BLA */ @@ -112,6 +116,13 @@ static inline void batadv_bla_free(struct batadv_priv *bat_priv) { } +static inline +bool batadv_bla_handle_local_claim(struct batadv_priv *bat_priv, u8 *addr, + unsigned short vid) +{ + return true; +} + #endif /* ifdef CONFIG_BATMAN_ADV_BLA */ #endif /* ifndef _NET_BATMAN_ADV_BLA_H_ */ diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index 278800a..c11f035 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@ -48,6 +48,7 @@ #include "originator.h" #include "send.h" #include "translation-table.h" +#include "bridge_loop_avoidance.h" static void batadv_dat_purge(struct work_struct *work); @@ -1003,6 +1004,20 @@ bool batadv_dat_snoop_outgoing_arp_request(struct batadv_priv *bat_priv, goto out; } + /* If BLA is enabled, only send ARP replies if we have claimed + * the destination for the ARP request or if no one else of + * the backbone gws belonging to our backbone has claimed the + * destination. + */ + if (!batadv_bla_handle_local_claim(bat_priv, + dat_entry->mac_addr, vid)) { + batadv_dbg(BATADV_DBG_DAT, bat_priv, + "Device %pM claimed by another backbone gw. Don't send ARP reply!", + dat_entry->mac_addr); + ret = true; + goto out; + } + skb_new = arp_create(ARPOP_REPLY, ETH_P_ARP, ip_src, bat_priv->soft_iface, ip_dst, hw_src, dat_entry->mac_addr, hw_src);