From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Andreas Pape In-Reply-To: <1465557064-24406-1-git-send-email-apape@phoenixcontact.com> References: <1465557064-24406-1-git-send-email-apape@phoenixcontact.com> Message-ID: <1465557064-24406-4-git-send-email-apape@phoenixcontact.com> Date: Fri, 10 Jun 2016 13:11:01 +0200 content-transfer-encoding: quoted-printable content-type: text/plain; charset="utf-8" Subject: [B.A.T.M.A.N.] [PATCH v5 3/6] batman-adv: prevent duplication of ARP replies when DAT is used List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: b.a.t.m.a.n@lists.open-mesh.org If none of the backbone gateways in a bla setup has already knowledge of the mac address searched for in an incoming ARP request from the backbone an address resolution via the DHT of DAT is started. The gateway can send several ARP requests to different DHT nodes and therefore can get several replies. This patch assures that not all of the possible ARP replies are returned to the backbone by checking the local DAT cache of the gateway. If there is an entry in the local cache the gateway has already learned the requested address and there is no need to forward the additional reply to the backbone. Furthermore it is checked if this gateway has claimed the source of the ARP reply and only forwards it to the backbone if it has claimed the source or if there is no claim at all. Signed-off-by: Andreas Pape --- net/batman-adv/distributed-arp-table.c | 32 ++++++++++++++++++++++++++++= ++++ 1 files changed, 32 insertions(+), 0 deletions(-) diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distri= buted-arp-table.c index 998a4b8..e7b054a 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c @@ -1244,6 +1244,7 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batad= v_priv *bat_priv, =09__be32 ip_src, ip_dst; =09u8 *hw_src, *hw_dst; =09bool dropped =3D false; +=09struct batadv_dat_entry *dat_entry =3D NULL; =09unsigned short vid; =09if (!atomic_read(&bat_priv->distributed_arp_table)) @@ -1263,12 +1264,41 @@ bool batadv_dat_snoop_incoming_arp_reply(struct bat= adv_priv *bat_priv, =09hw_dst =3D batadv_arp_hw_dst(skb, hdr_size); =09ip_dst =3D batadv_arp_ip_dst(skb, hdr_size); +=09/* If ip_dst is already in cache and has the right mac address, +=09 * drop this frame if this ARP reply is destined for us because it's +=09 * most probably an ARP reply generated by another node of the DHT. +=09 * We have most probably received already a reply earlier. Delivering +=09 * this frame would lead to doubled receive of an ARP reply. +=09 */ +=09dat_entry =3D batadv_dat_entry_hash_find(bat_priv, ip_src, vid); +=09if ((dat_entry) && (batadv_compare_eth(hw_src, dat_entry->mac_addr))) { +=09=09batadv_dbg(BATADV_DBG_DAT, bat_priv, "Doubled ARP reply removed: ARP= MSG =3D [src: %pM-%pI4 dst: %pM-%pI4]; dat_entry: %pM-%pI4\n", +=09=09=09 hw_src, &ip_src, hw_dst, &ip_dst, +=09=09=09 dat_entry->mac_addr,=09&dat_entry->ip); +=09=09dropped =3D true; +=09=09goto out; +=09} + =09/* Update our internal cache with both the IP addresses the node got =09 * within the ARP reply =09 */ =09batadv_dat_entry_add(bat_priv, ip_src, hw_src, vid); =09batadv_dat_entry_add(bat_priv, ip_dst, hw_dst, vid); +=09/* If BLA is enabled, only forward ARP replies if we have claimed the +=09 * source of the ARP reply or if no one else of the same backbone has +=09 * already claimed that client. This prevents that different gateways +=09 * to the same backbone all forward the ARP reply leading to multiple +=09 * replies in the backbone. +=09 */ +=09if (!batadv_bla_check_claim(bat_priv, hw_src, vid)) { +=09=09batadv_dbg(BATADV_DBG_DAT, bat_priv, +=09=09=09 "Device %pM claimed by another backbone gw. Drop ARP reply.\n", +=09=09=09 hw_src); +=09=09dropped =3D true; +=09=09goto out; +=09} + =09/* if this REPLY is directed to a client of mine, let's deliver the =09 * packet to the interface =09 */ @@ -1281,6 +1311,8 @@ bool batadv_dat_snoop_incoming_arp_reply(struct batad= v_priv *bat_priv, out: =09if (dropped) =09=09kfree_skb(skb); +=09if (dat_entry) +=09=09batadv_dat_entry_put(dat_entry); =09/* if dropped =3D=3D false -> deliver to the interface */ =09return dropped; } -- 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=C3=A4ftsf=C3=BChrer / Executive Board: Roland Bent, Dr. Martin Heubeck ___________________________________________________________________ Diese E-Mail enth=C3=A4lt vertrauliche und/oder rechtlich gesch=C3=BCtzte I= nformationen. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail i= rrt=C3=BCmlich erhalten haben, informieren Sie bitte sofort den Absender un= d vernichten Sie diese Mail. Das unerlaubte Kopieren, jegliche anderweitige= Verwendung sowie die unbefugte Weitergabe dieser Mail ist nicht gestattet. ---------------------------------------------------------------------------= ------------------------- This e-mail may contain confidential and/or privileged information. If you = are not the intended recipient (or have received this e-mail in error) plea= se notify the sender immediately and destroy this e-mail. Any unauthorized = copying, disclosure, distribution or other use of the material or parts the= reof is strictly forbidden. ___________________________________________________________________