Module Name:    src
Committed By:   ozaki-r
Date:           Tue Mar 14 04:25:10 UTC 2017

Modified Files:
        src/sys/net: if.c rtsock.c
        src/sys/netinet6: ip6_input.c nd6_nbr.c

Log Message:
Replace DIAGNOSTIC + panic with KASSERT


To generate a diff of this commit:
cvs rdiff -u -r1.383 -r1.384 src/sys/net/if.c
cvs rdiff -u -r1.203 -r1.204 src/sys/net/rtsock.c
cvs rdiff -u -r1.176 -r1.177 src/sys/netinet6/ip6_input.c
cvs rdiff -u -r1.137 -r1.138 src/sys/netinet6/nd6_nbr.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/net/if.c
diff -u src/sys/net/if.c:1.383 src/sys/net/if.c:1.384
--- src/sys/net/if.c:1.383	Thu Mar  9 09:57:36 2017
+++ src/sys/net/if.c	Tue Mar 14 04:25:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.383 2017/03/09 09:57:36 knakahara Exp $	*/
+/*	$NetBSD: if.c,v 1.384 2017/03/14 04:25:10 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.383 2017/03/09 09:57:36 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.384 2017/03/14 04:25:10 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1371,11 +1371,7 @@ again:
 		if (family == AF_LINK)
 			continue;
 		dp = pffinddomain(family);
-#ifdef DIAGNOSTIC
-		if (dp == NULL)
-			panic("if_detach: no domain for AF %d",
-			    family);
-#endif
+		KASSERTMSG(dp != NULL, "no domain for AF %d", family);
 		/*
 		 * XXX These PURGEIF calls are redundant with the
 		 * purge-all-families calls below, but are left in for

Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.203 src/sys/net/rtsock.c:1.204
--- src/sys/net/rtsock.c:1.203	Tue Mar 14 04:23:15 2017
+++ src/sys/net/rtsock.c	Tue Mar 14 04:25:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: rtsock.c,v 1.203 2017/03/14 04:23:15 ozaki-r Exp $	*/
+/*	$NetBSD: rtsock.c,v 1.204 2017/03/14 04:25:10 ozaki-r Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.203 2017/03/14 04:23:15 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.204 2017/03/14 04:25:10 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1449,10 +1449,7 @@ COMPATNAME(rt_newaddrmsg)(int cmd, struc
 		default:
 			continue;
 		}
-#ifdef DIAGNOSTIC
-		if (m == NULL)
-			panic("%s: called with wrong command", __func__);
-#endif
+		KASSERTMSG(m != NULL, "called with wrong command");
 		COMPATNAME(route_enqueue)(m, sa ? sa->sa_family : 0);
 	}
 #undef cmdpass

Index: src/sys/netinet6/ip6_input.c
diff -u src/sys/netinet6/ip6_input.c:1.176 src/sys/netinet6/ip6_input.c:1.177
--- src/sys/netinet6/ip6_input.c:1.176	Wed Mar  1 08:54:12 2017
+++ src/sys/netinet6/ip6_input.c	Tue Mar 14 04:25:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ip6_input.c,v 1.176 2017/03/01 08:54:12 ozaki-r Exp $	*/
+/*	$NetBSD: ip6_input.c,v 1.177 2017/03/14 04:25:10 ozaki-r Exp $	*/
 /*	$KAME: ip6_input.c,v 1.188 2001/03/29 05:34:31 itojun Exp $	*/
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.176 2017/03/01 08:54:12 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_input.c,v 1.177 2017/03/14 04:25:10 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_gateway.h"
@@ -1322,10 +1322,7 @@ ip6_notify_pmtu(struct in6pcb *in6p, con
 	if (mtu == NULL)
 		return;
 
-#ifdef DIAGNOSTIC
-	if (so == NULL)		/* I believe this is impossible */
-		panic("ip6_notify_pmtu: socket is NULL");
-#endif
+	KASSERT(so != NULL);
 
 	memset(&mtuctl, 0, sizeof(mtuctl));	/* zero-clear for safety */
 	mtuctl.ip6m_mtu = *mtu;

Index: src/sys/netinet6/nd6_nbr.c
diff -u src/sys/netinet6/nd6_nbr.c:1.137 src/sys/netinet6/nd6_nbr.c:1.138
--- src/sys/netinet6/nd6_nbr.c:1.137	Tue Feb 21 03:58:24 2017
+++ src/sys/netinet6/nd6_nbr.c	Tue Mar 14 04:25:10 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: nd6_nbr.c,v 1.137 2017/02/21 03:58:24 ozaki-r Exp $	*/
+/*	$NetBSD: nd6_nbr.c,v 1.138 2017/03/14 04:25:10 ozaki-r Exp $	*/
 /*	$KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $	*/
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.137 2017/02/21 03:58:24 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.138 2017/03/14 04:25:10 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -394,14 +394,9 @@ nd6_ns_output(struct ifnet *ifp, const s
 	/* estimate the size of message */
 	maxlen = sizeof(*ip6) + sizeof(*nd_ns);
 	maxlen += (sizeof(struct nd_opt_hdr) + ifp->if_addrlen + 7) & ~7;
-#ifdef DIAGNOSTIC
-	if (max_linkhdr + maxlen >= MCLBYTES) {
-		printf("nd6_ns_output: max_linkhdr + maxlen >= MCLBYTES "
-		    "(%d + %d > %d)\n", max_linkhdr, maxlen, MCLBYTES);
-		panic("nd6_ns_output: insufficient MCLBYTES");
-		/* NOTREACHED */
-	}
-#endif
+	KASSERTMSG(max_linkhdr + maxlen < MCLBYTES,
+	    "max_linkhdr + maxlen >= MCLBYTES (%d + %d >= %d)",
+	    max_linkhdr, maxlen, MCLBYTES);
 
 	MGETHDR(m, M_DONTWAIT, MT_DATA);
 	if (m && max_linkhdr + maxlen >= MHLEN) {
@@ -910,14 +905,9 @@ nd6_na_output(
 	/* estimate the size of message */
 	maxlen = sizeof(*ip6) + sizeof(*nd_na);
 	maxlen += (sizeof(struct nd_opt_hdr) + ifp->if_addrlen + 7) & ~7;
-#ifdef DIAGNOSTIC
-	if (max_linkhdr + maxlen >= MCLBYTES) {
-		printf("nd6_na_output: max_linkhdr + maxlen >= MCLBYTES "
-		    "(%d + %d > %d)\n", max_linkhdr, maxlen, MCLBYTES);
-		panic("nd6_na_output: insufficient MCLBYTES");
-		/* NOTREACHED */
-	}
-#endif
+	KASSERTMSG(max_linkhdr + maxlen < MCLBYTES,
+	    "max_linkhdr + maxlen >= MCLBYTES (%d + %d >= %d)",
+	    max_linkhdr, maxlen, MCLBYTES);
 
 	MGETHDR(m, M_DONTWAIT, MT_DATA);
 	if (m && max_linkhdr + maxlen >= MHLEN) {

Reply via email to