Module Name:    src
Committed By:   ozaki-r
Date:           Wed Nov 26 09:53:53 UTC 2014

Modified Files:
        src/sys/compat/common: uipc_syscalls_40.c
        src/sys/compat/linux/common: linux_socket.c
        src/sys/compat/linux32/common: linux32_socket.c
        src/sys/net: if.c

Log Message:
Tweak ifconf variants

The tweaks make the code intention clear and make further changes easy.

No functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/sys/compat/common/uipc_syscalls_40.c
cvs rdiff -u -r1.121 -r1.122 src/sys/compat/linux/common/linux_socket.c
cvs rdiff -u -r1.18 -r1.19 src/sys/compat/linux32/common/linux32_socket.c
cvs rdiff -u -r1.297 -r1.298 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/compat/common/uipc_syscalls_40.c
diff -u src/sys/compat/common/uipc_syscalls_40.c:1.7 src/sys/compat/common/uipc_syscalls_40.c:1.8
--- src/sys/compat/common/uipc_syscalls_40.c:1.7	Wed Jan 19 10:21:16 2011
+++ src/sys/compat/common/uipc_syscalls_40.c	Wed Nov 26 09:53:53 2014
@@ -1,9 +1,9 @@
-/*	$NetBSD: uipc_syscalls_40.c,v 1.7 2011/01/19 10:21:16 tsutsui Exp $	*/
+/*	$NetBSD: uipc_syscalls_40.c,v 1.8 2014/11/26 09:53:53 ozaki-r Exp $	*/
 
 /* written by Pavel Cahyna, 2006. Public domain. */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.7 2011/01/19 10:21:16 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uipc_syscalls_40.c,v 1.8 2014/11/26 09:53:53 ozaki-r Exp $");
 
 /*
  * System call interface to the socket abstraction.
@@ -35,14 +35,16 @@ compat_ifconf(u_long cmd, void *data)
 	struct oifconf *ifc = data;
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
-	struct oifreq ifr, *ifrp;
-	int space, error = 0;
+	struct oifreq ifr, *ifrp = NULL;
+	int space = 0, error = 0;
 	const int sz = (int)sizeof(ifr);
+	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));
@@ -105,7 +107,7 @@ compat_ifconf(u_long cmd, void *data)
 			space -= sz;
 		}
 	}
-	if (ifrp != NULL)
+	if (docopy)
 		ifc->ifc_len -= space;
 	else
 		ifc->ifc_len = -space;

Index: src/sys/compat/linux/common/linux_socket.c
diff -u src/sys/compat/linux/common/linux_socket.c:1.121 src/sys/compat/linux/common/linux_socket.c:1.122
--- src/sys/compat/linux/common/linux_socket.c:1.121	Fri Nov 21 06:03:04 2014
+++ src/sys/compat/linux/common/linux_socket.c	Wed Nov 26 09:53:53 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_socket.c,v 1.121 2014/11/21 06:03:04 ozaki-r Exp $	*/
+/*	$NetBSD: linux_socket.c,v 1.122 2014/11/26 09:53:53 ozaki-r Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 2008 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.121 2014/11/21 06:03:04 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_socket.c,v 1.122 2014/11/26 09:53:53 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -1111,24 +1111,25 @@ linux_getifname(struct lwp *l, register_
 int
 linux_getifconf(struct lwp *l, register_t *retval, void *data)
 {
-	struct linux_ifreq ifr, *ifrp;
+	struct linux_ifreq ifr, *ifrp = NULL;
 	struct linux_ifconf ifc;
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 	struct sockaddr *sa;
 	struct osockaddr *osa;
-	int space, error = 0;
+	int space = 0, error = 0;
 	const int sz = (int)sizeof(ifr);
+	bool docopy;
 
 	error = copyin(data, &ifc, sizeof(ifc));
 	if (error)
 		return error;
 
-	ifrp = ifc.ifc_req;
-	if (ifrp == NULL)
-		space = 0;
-	else
+	docopy = ifc.ifc_req != NULL;
+	if (docopy) {
 		space = ifc.ifc_len;
+		ifrp = ifc.ifc_req;
+	}
 
 	IFNET_FOREACH(ifp) {
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
@@ -1155,7 +1156,7 @@ linux_getifconf(struct lwp *l, register_
 		}
 	}
 
-	if (ifrp != NULL)
+	if (docopy)
 		ifc.ifc_len -= space;
 	else
 		ifc.ifc_len = -space;

Index: src/sys/compat/linux32/common/linux32_socket.c
diff -u src/sys/compat/linux32/common/linux32_socket.c:1.18 src/sys/compat/linux32/common/linux32_socket.c:1.19
--- src/sys/compat/linux32/common/linux32_socket.c:1.18	Sat May 17 21:26:20 2014
+++ src/sys/compat/linux32/common/linux32_socket.c	Wed Nov 26 09:53:53 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_socket.c,v 1.18 2014/05/17 21:26:20 rmind Exp $ */
+/*	$NetBSD: linux32_socket.c,v 1.19 2014/11/26 09:53:53 ozaki-r Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.18 2014/05/17 21:26:20 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_socket.c,v 1.19 2014/11/26 09:53:53 ozaki-r Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -410,24 +410,25 @@ linux32_getifname(struct lwp *l, registe
 int
 linux32_getifconf(struct lwp *l, register_t *retval, void *data)
 {
-	struct linux32_ifreq ifr, *ifrp;
+	struct linux32_ifreq ifr, *ifrp = NULL;
 	struct linux32_ifconf ifc;
 	struct ifnet *ifp;
 	struct ifaddr *ifa;
 	struct sockaddr *sa;
 	struct osockaddr *osa;
-	int space, error = 0;
+	int space = 0, error = 0;
 	const int sz = (int)sizeof(ifr);
+	bool docopy;
 
 	error = copyin(data, &ifc, sizeof(ifc));
 	if (error)
 		return error;
 
-	ifrp = NETBSD32PTR64(ifc.ifc_req);
-	if (ifrp == NULL)
-		space = 0;
-	else
+	docopy = NETBSD32PTR64(ifc.ifc_req) != NULL;
+	if (docopy) {
 		space = ifc.ifc_len;
+		ifrp = NETBSD32PTR64(ifc.ifc_req);
+	}
 
 	IFNET_FOREACH(ifp) {
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
@@ -454,7 +455,7 @@ linux32_getifconf(struct lwp *l, registe
 		}
 	}
 
-	if (ifrp != NULL)
+	if (docopy)
 		ifc.ifc_len -= space;
 	else
 		ifc.ifc_len = -space;

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.297 src/sys/net/if.c:1.298
--- src/sys/net/if.c:1.297	Wed Nov 26 09:38:42 2014
+++ src/sys/net/if.c	Wed Nov 26 09:53:53 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.297 2014/11/26 09:38:42 ozaki-r Exp $	*/
+/*	$NetBSD: if.c,v 1.298 2014/11/26 09:53:53 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.297 2014/11/26 09:38:42 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.298 2014/11/26 09:53:53 ozaki-r Exp $");
 
 #include "opt_inet.h"
 
@@ -2115,13 +2115,12 @@ 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;
 	IFNET_FOREACH(ifp) {
 		(void)strncpy(ifr.ifr_name, ifp->if_xname,
@@ -2131,7 +2130,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;
 			}
@@ -2149,7 +2148,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;
 			}
@@ -2162,7 +2161,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