Module Name:    src
Committed By:   ozaki-r
Date:           Mon Dec  8 04:55:47 UTC 2014

Modified Files:
        src/sys/net: if.c

Log Message:
Tweak ifconf (retry)

The tweak makes the code intention clear and further changes easy.

No functional change.

The first trial broke SIOCGIFCONF (PR 49437). So as not to repeat the mistake,
t_ifconf was added. It should warn if something goes wrong on ifconf.


To generate a diff of this commit:
cvs rdiff -u -r1.303 -r1.304 src/sys/net/if.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.303 src/sys/net/if.c:1.304
--- src/sys/net/if.c:1.303	Tue Dec  2 04:43:35 2014
+++ src/sys/net/if.c	Mon Dec  8 04:55:47 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.303 2014/12/02 04:43:35 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.304 2014/12/08 04:55:47 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.303 2014/12/02 04:43:35 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.304 2014/12/08 04:55:47 ozaki-r Exp $");
 
 #include "opt_inet.h"
 
@@ -2119,14 +2119,16 @@ ifconf(u_long cmd, void *data)
 	struct ifconf *ifc = (struct ifconf *)data;
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
-	struct ifreq ifr, *ifrp;
-	int space, error = 0;
+	struct ifreq ifr, *ifrp = NULL;
+	int space = 0, error = 0;
 	const int sz = (int)sizeof(struct ifreq);
+	const bool docopy = ifc->ifc_req != NULL;
 
-	if ((ifrp = ifc->ifc_req) == NULL)
-		space = 0;
-	else
+	if (docopy) {
 		space = ifc->ifc_len;
+		ifrp = ifc->ifc_req;
+	}
+
 	IFNET_FOREACH(ifp) {
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
 		    sizeof(ifr.ifr_name));
@@ -2135,7 +2137,7 @@ ifconf(u_long cmd, void *data)
 		if (IFADDR_EMPTY(ifp)) {
 			/* Interface with no addresses - send zero sockaddr. */
 			memset(&ifr.ifr_addr, 0, sizeof(ifr.ifr_addr));
-			if (ifrp == NULL) {
+			if (!docopy) {
 				space += sz;
 				continue;
 			}
@@ -2153,7 +2155,7 @@ ifconf(u_long cmd, void *data)
 			/* all sockaddrs must fit in sockaddr_storage */
 			KASSERT(sa->sa_len <= sizeof(ifr.ifr_ifru));
 
-			if (ifrp == NULL) {
+			if (!docopy) {
 				space += sz;
 				continue;
 			}
@@ -2166,7 +2168,7 @@ ifconf(u_long cmd, void *data)
 			}
 		}
 	}
-	if (ifrp != NULL) {
+	if (docopy) {
 		KASSERT(0 <= space && space <= ifc->ifc_len);
 		ifc->ifc_len -= space;
 	} else {

Reply via email to