Source-Changes-HG archive

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

[src/trunk]: src/sys Tweak ifconf variants



details:   https://anonhg.NetBSD.org/src/rev/6682bfe6ffd4
branches:  trunk
changeset: 334011:6682bfe6ffd4
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Nov 26 09:53:53 2014 +0000

description:
Tweak ifconf variants

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

No functional change.

diffstat:

 sys/compat/common/uipc_syscalls_40.c       |  18 ++++++++++--------
 sys/compat/linux/common/linux_socket.c     |  19 ++++++++++---------
 sys/compat/linux32/common/linux32_socket.c |  19 ++++++++++---------
 sys/net/if.c                               |  19 +++++++++----------
 4 files changed, 39 insertions(+), 36 deletions(-)

diffs (227 lines):

diff -r ad84f6eeeb59 -r 6682bfe6ffd4 sys/compat/common/uipc_syscalls_40.c
--- a/sys/compat/common/uipc_syscalls_40.c      Wed Nov 26 09:38:42 2014 +0000
+++ b/sys/compat/common/uipc_syscalls_40.c      Wed Nov 26 09:53:53 2014 +0000
@@ -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 @@
        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 @@
                        space -= sz;
                }
        }
-       if (ifrp != NULL)
+       if (docopy)
                ifc->ifc_len -= space;
        else
                ifc->ifc_len = -space;
diff -r ad84f6eeeb59 -r 6682bfe6ffd4 sys/compat/linux/common/linux_socket.c
--- a/sys/compat/linux/common/linux_socket.c    Wed Nov 26 09:38:42 2014 +0000
+++ b/sys/compat/linux/common/linux_socket.c    Wed Nov 26 09:53:53 2014 +0000
@@ -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 @@
 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 @@
                }
        }
 
-       if (ifrp != NULL)
+       if (docopy)
                ifc.ifc_len -= space;
        else
                ifc.ifc_len = -space;
diff -r ad84f6eeeb59 -r 6682bfe6ffd4 sys/compat/linux32/common/linux32_socket.c
--- a/sys/compat/linux32/common/linux32_socket.c        Wed Nov 26 09:38:42 2014 +0000
+++ b/sys/compat/linux32/common/linux32_socket.c        Wed Nov 26 09:53:53 2014 +0000
@@ -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 @@
 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 @@
                }
        }
 
-       if (ifrp != NULL)
+       if (docopy)
                ifc.ifc_len -= space;
        else
                ifc.ifc_len = -space;
diff -r ad84f6eeeb59 -r 6682bfe6ffd4 sys/net/if.c
--- a/sys/net/if.c      Wed Nov 26 09:38:42 2014 +0000
+++ b/sys/net/if.c      Wed Nov 26 09:53:53 2014 +0000
@@ -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 @@
        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 @@
                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 @@
                        /* 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 @@
                        }
                }
        }
-       if (ifrp != NULL) {
+       if (docopy) {
                KASSERT(0 <= space && space <= ifc->ifc_len);
                ifc->ifc_len -= space;
        } else {



Home | Main Index | Thread Index | Old Index