Source-Changes-HG archive

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

[src/trunk]: src/sys if_arp: Just KASSERT that arphrd is aligned



details:   https://anonhg.NetBSD.org/src/rev/71ac38279cc7
branches:  trunk
changeset: 959454:71ac38279cc7
user:      roy <roy%NetBSD.org@localhost>
date:      Sun Feb 14 19:47:16 2021 +0000

description:
if_arp: Just KASSERT that arphrd is aligned

While here improve readability of checking ARP IEEE1394 matches interface.

diffstat:

 sys/net/if_arp.h     |  10 +---------
 sys/netinet/if_arp.c |  47 ++++++++++++++++++++++-------------------------
 2 files changed, 23 insertions(+), 34 deletions(-)

diffs (124 lines):

diff -r fbdca81cd35f -r 71ac38279cc7 sys/net/if_arp.h
--- a/sys/net/if_arp.h  Sun Feb 14 19:35:37 2021 +0000
+++ b/sys/net/if_arp.h  Sun Feb 14 19:47:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.h,v 1.38 2021/02/13 07:57:09 roy Exp $  */
+/*     $NetBSD: if_arp.h,v 1.39 2021/02/14 19:47:16 roy Exp $  */
 
 /*
  * Copyright (c) 1986, 1993
@@ -72,14 +72,6 @@
        uint8_t  ar_tpa[];      /* target protocol address */
 #endif
 };
-#ifdef __NO_STRICT_ALIGNMENT
-#define        ARP_HDR_ALIGNED_P(ah)   1
-#else
-#define        ARP_HDR_ALIGNED_P(ah)   ((((vaddr_t) (ah)) & 3) == 0)
-#endif
-#ifdef __CTASSERT
-__CTASSERT(sizeof(struct arphdr) == 8);
-#endif
 
 static __inline uint8_t *
 ar_data(struct arphdr *ap)
diff -r fbdca81cd35f -r 71ac38279cc7 sys/netinet/if_arp.c
--- a/sys/netinet/if_arp.c      Sun Feb 14 19:35:37 2021 +0000
+++ b/sys/netinet/if_arp.c      Sun Feb 14 19:47:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_arp.c,v 1.300 2021/02/13 13:00:16 roy Exp $ */
+/*     $NetBSD: if_arp.c,v 1.301 2021/02/14 19:47:17 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.300 2021/02/13 13:00:16 roy Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_arp.c,v 1.301 2021/02/14 19:47:17 roy Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ddb.h"
@@ -133,6 +133,12 @@
  */
 #define ETHERTYPE_IPTRAILERS ETHERTYPE_TRAIL
 
+#ifdef __NO_STRICT_ALIGNMENT
+#define        ARP_HDR_ALIGNED_P(ar)   1
+#else
+#define        ARP_HDR_ALIGNED_P(ar)   ((((vaddr_t) (ar)) & 1) == 0)
+#endif
+
 /* timers */
 static int arp_reachable = REACHABLE_TIME;
 static int arp_retrans = RETRANS_TIMER;
@@ -684,10 +690,11 @@
        struct arphdr *ar;
        int s;
        int arplen;
+       struct ifnet *rcvif;
+       bool badhrd;
 
        SOFTNET_KERNEL_LOCK_UNLESS_NET_MPSAFE();
        for (;;) {
-               struct ifnet *rcvif;
 
                IFQ_LOCK(&arpintrq);
                IF_DEQUEUE(&arpintrq, m);
@@ -700,15 +707,12 @@
                MCLAIM(m, &arpdomain.dom_mowner);
                ARP_STATINC(ARP_STAT_RCVTOTAL);
 
-               /* Enforce alignment */
-               if (ARP_HDR_ALIGNED_P(mtod(m, void *)) == 0) {
-                       if ((m = m_copyup(m, sizeof(*ar), 0)) == NULL)
-                               goto badlen;
-               } else if (__predict_false(m->m_len < sizeof(*ar))) {
+               if (__predict_false(m->m_len < sizeof(*ar))) {
                        if ((m = m_pullup(m, sizeof(*ar))) == NULL)
                                goto badlen;
                }
                ar = mtod(m, struct arphdr *);
+               KASSERT(ARP_HDR_ALIGNED_P(ar));
 
                rcvif = m_get_rcvif(m, &s);
                if (__predict_false(rcvif == NULL)) {
@@ -720,27 +724,20 @@
                 * We don't want non-IEEE1394 ARP packets on IEEE1394
                 * interfaces, and vice versa. Our life depends on that.
                 */
-               switch (rcvif->if_type) {
-               case IFT_IEEE1394:
-                       if (ntohs(ar->ar_hrd) != ARPHRD_IEEE1394) {
-                               m_put_rcvif(rcvif, &s);
-                               ARP_STATINC(ARP_STAT_RCVBADPROTO);
-                               goto free;
-                       }
-                       break;
-               default:
-                       if (ntohs(ar->ar_hrd) == ARPHRD_IEEE1394) {
-                               m_put_rcvif(rcvif, &s);
-                               ARP_STATINC(ARP_STAT_RCVBADPROTO);
-                               goto free;
-                       }
-                       break;
-               }
+               if (ntohs(ar->ar_hrd) == ARPHRD_IEEE1394)
+                       badhrd = rcvif->if_type != IFT_IEEE1394;
+               else
+                       badhrd = rcvif->if_type == IFT_IEEE1394;
 
                m_put_rcvif(rcvif, &s);
 
+               if (badhrd) {
+                       ARP_STATINC(ARP_STAT_RCVBADPROTO);
+                       goto free;
+               }
+
                arplen = sizeof(*ar) + 2 * ar->ar_hln + 2 * ar->ar_pln;
-               if (m->m_len < arplen) {
+               if (__predict_false(m->m_len < arplen)) {
                        if ((m = m_pullup(m, arplen)) == NULL)
                                goto badlen;
                        ar = mtod(m, struct arphdr *);



Home | Main Index | Thread Index | Old Index