Source-Changes-HG archive

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

[src/trunk]: src/sys/net Tweak ifconf (retry)



details:   https://anonhg.NetBSD.org/src/rev/a8369dbcee74
branches:  trunk
changeset: 804961:a8369dbcee74
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Mon Dec 08 04:55:47 2014 +0000

description:
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.

diffstat:

 sys/net/if.c |  22 ++++++++++++----------
 1 files changed, 12 insertions(+), 10 deletions(-)

diffs (67 lines):

diff -r 276a02bbe96e -r a8369dbcee74 sys/net/if.c
--- a/sys/net/if.c      Mon Dec 08 04:23:03 2014 +0000
+++ b/sys/net/if.c      Mon Dec 08 04:55:47 2014 +0000
@@ -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 @@
        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 @@
                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 @@
                        /* 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 @@
                        }
                }
        }
-       if (ifrp != NULL) {
+       if (docopy) {
                KASSERT(0 <= space && space <= ifc->ifc_len);
                ifc->ifc_len -= space;
        } else {



Home | Main Index | Thread Index | Old Index