Module Name:    src
Committed By:   christos
Date:           Sat Jul  8 22:56:15 UTC 2017

Modified Files:
        src/sys/netinet: ip_input.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.357 -r1.358 src/sys/netinet/ip_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/netinet/ip_input.c
diff -u src/sys/netinet/ip_input.c:1.357 src/sys/netinet/ip_input.c:1.358
--- src/sys/netinet/ip_input.c:1.357	Thu Jul  6 13:12:34 2017
+++ src/sys/netinet/ip_input.c	Sat Jul  8 18:56:15 2017
@@ -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 @@ ip_savecontrol(struct inpcb *inp, struct
     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 @@ ip_savecontrol(struct inpcb *inp, struct
 		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 @@ ip_savecontrol(struct inpcb *inp, struct
 		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);
 }
 

Reply via email to