Source-Changes-HG archive

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

[src/trunk]: src/sys/netinet Reorder the controls to the ones that need an in...



details:   https://anonhg.NetBSD.org/src/rev/f8d4c3feca24
branches:  trunk
changeset: 825320:f8d4c3feca24
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Jul 08 22:56:15 2017 +0000

description:
Reorder the controls to the ones that need an interface and the ones that
don't; process the ones that don't first. Add a DIAGNOSTIC if there is no
interface; really this should be a KASSERT/panic because it is a bug if the
interface is not set at this point.

diffstat:

 sys/netinet/ip_input.c |  33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)

diffs (69 lines):

diff -r 726d2c86a888 -r f8d4c3feca24 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c    Sat Jul 08 19:25:37 2017 +0000
+++ b/sys/netinet/ip_input.c    Sat Jul 08 22:56:15 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_input.c,v 1.357 2017/07/06 17:12:34 christos Exp $  */
+/*     $NetBSD: ip_input.c,v 1.358 2017/07/08 22:56:15 christos Exp $  */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.357 2017/07/06 17:12:34 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.358 2017/07/08 22:56:15 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1515,13 +1515,7 @@
     struct mbuf *m)
 {
        struct socket *so = inp->inp_socket;
-       ifnet_t *ifp;
        int inpflags = inp->inp_flags;
-       struct psref psref;
-
-       ifp = m_get_rcvif_psref(m, &psref);
-       if (__predict_false(ifp == NULL))
-               return; /* XXX should report error? */
 
        if (SOOPT_TIMESTAMP(so->so_options))
                mp = sbsavetimestamp(so->so_options, m, mp);
@@ -1532,6 +1526,23 @@
                if (*mp)
                        mp = &(*mp)->m_next;
        }
+
+       if (inpflags & INP_RECVTTL) {
+               *mp = sbcreatecontrol(&ip->ip_ttl,
+                   sizeof(uint8_t), IP_RECVTTL, IPPROTO_IP);
+               if (*mp)
+                       mp = &(*mp)->m_next;
+       }
+
+       struct psref psref;
+       ifnet_t *ifp = m_get_rcvif_psref(m, &psref);
+       if (__predict_false(ifp == NULL)) {
+#ifdef DIAGNOSTIC
+               printf("%s: missing receive interface\n", __func__);
+#endif
+               return; /* XXX should report error? */
+       }
+
        if (inpflags & INP_RECVPKTINFO) {
                struct in_pktinfo ipi;
                ipi.ipi_addr = ip->ip_src;
@@ -1559,12 +1570,6 @@
                if (*mp)
                        mp = &(*mp)->m_next;
        }
-       if (inpflags & INP_RECVTTL) {
-               *mp = sbcreatecontrol(&ip->ip_ttl,
-                   sizeof(uint8_t), IP_RECVTTL, IPPROTO_IP);
-               if (*mp)
-                       mp = &(*mp)->m_next;
-       }
        m_put_rcvif_psref(ifp, &psref);
 }
 



Home | Main Index | Thread Index | Old Index