Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/netinet Use if_get_bylla() instead of just looking at th...



details:   https://anonhg.NetBSD.org/src/rev/0379c9394b01
branches:  trunk
changeset: 825042:0379c9394b01
user:      roy <roy%NetBSD.org@localhost>
date:      Tue Jun 27 12:21:54 2017 +0000

description:
Use if_get_bylla() instead of just looking at the lla of the interface
the address belongs to.
This allows any ARP message we receieved from another interface to
be correctly dropped.

While here, move the protocol length check higher up the food chain.

diffstat:

 sys/netinet/if_arp.c |  23 ++++++++++++-----------
 1 files changed, 12 insertions(+), 11 deletions(-)

diffs (58 lines):

diff -r 416185023542 -r 0379c9394b01 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Tue Jun 27 12:17:27 2017 +0000
+++ b/sys/netinet/if_arp.c      Tue Jun 27 12:21:54 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.252 2017/06/21 09:05:31 ozaki-r Exp $     */
+/*     $NetBSD: if_arp.c,v 1.253 2017/06/27 12:21:54 roy Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.252 2017/06/21 09:05:31 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.253 2017/06/27 12:21:54 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -1025,6 +1025,16 @@
        ah = mtod(m, struct arphdr *);
        op = ntohs(ah->ar_op);
 
+       if (ah->ar_pln != sizeof(struct in_addr))
+               goto out;
+
+       ifp = if_get_bylla(ar_sha(ah), ah->ar_hln, &psref);
+       if (ifp) {
+               if_put(ifp, &psref);
+               ARP_STATINC(ARP_STAT_RCVLOCALSHA);
+               goto out;       /* it's from me, ignore it. */
+       }
+
        rcvif = ifp = m_get_rcvif_psref(m, &psref);
        if (__predict_false(rcvif == NULL))
                goto drop;
@@ -1046,9 +1056,6 @@
                break;
        }
 
-       if (ah->ar_pln != sizeof(struct in_addr))
-               goto drop;
-
        memcpy(&isaddr, ar_spa(ah), sizeof(isaddr));
        memcpy(&itaddr, ar_tpa(ah), sizeof(itaddr));
 
@@ -1135,12 +1142,6 @@
        myaddr = ia->ia_addr.sin_addr;
 
        /* XXX checks for bridge case? */
-       if (!memcmp(ar_sha(ah), CLLADDR(ifp->if_sadl), ifp->if_addrlen)) {
-               ARP_STATINC(ARP_STAT_RCVLOCALSHA);
-               goto out;       /* it's from me, ignore it. */
-       }
-
-       /* XXX checks for bridge case? */
        if (!memcmp(ar_sha(ah), ifp->if_broadcastaddr, ifp->if_addrlen)) {
                ARP_STATINC(ARP_STAT_RCVBCASTSHA);
                log(LOG_ERR,



Home | Main Index | Thread Index | Old Index