Source-Changes-HG archive

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

[src/trunk]: src/sys/net Simplify ifunit, if_get and if_get_byindex by reusin...



details:   https://anonhg.NetBSD.org/src/rev/1a93a90c0345
branches:  trunk
changeset: 822359:1a93a90c0345
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Thu Mar 16 09:40:48 2017 +0000

description:
Simplify ifunit, if_get and if_get_byindex by reusing other functions

Inspired by kre@'s comment

diffstat:

 sys/net/if.c |  34 ++++++++--------------------------
 1 files changed, 8 insertions(+), 26 deletions(-)

diffs (76 lines):

diff -r 2bce230b9de2 -r 1a93a90c0345 sys/net/if.c
--- a/sys/net/if.c      Thu Mar 16 08:11:47 2017 +0000
+++ b/sys/net/if.c      Thu Mar 16 09:40:48 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.386 2017/03/16 08:11:47 ozaki-r Exp $ */
+/*     $NetBSD: if.c,v 1.387 2017/03/16 09:40:48 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.386 2017/03/16 08:11:47 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.387 2017/03/16 09:40:48 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2545,14 +2545,8 @@
        /*
         * If the number took all of the name, then it's a valid ifindex.
         */
-       if (i == IFNAMSIZ || (cp != name && *cp == '\0')) {
-               if (unit >= if_indexlim)
-                       return NULL;
-               ifp = ifindex2ifnet[unit];
-               if (ifp == NULL || if_is_deactivated(ifp))
-                       return NULL;
-               return ifp;
-       }
+       if (i == IFNAMSIZ || (cp != name && *cp == '\0'))
+               return if_byindex(unit);
 
        ifp = NULL;
        s = pserialize_read_enter();
@@ -2591,18 +2585,8 @@
        /*
         * If the number took all of the name, then it's a valid ifindex.
         */
-       if (i == IFNAMSIZ || (cp != name && *cp == '\0')) {
-               if (unit >= if_indexlim)
-                       return NULL;
-               s = pserialize_read_enter();
-               ifp = ifindex2ifnet[unit];
-               if (ifp == NULL || if_is_deactivated(ifp))
-                       ifp = NULL;
-               if (ifp != NULL)
-                       psref_acquire(psref, &ifp->if_psref, ifnet_psref_class);
-               pserialize_read_exit(s);
-               return ifp;
-       }
+       if (i == IFNAMSIZ || (cp != name && *cp == '\0'))
+               return if_get_byindex(unit, psref);
 
        ifp = NULL;
        s = pserialize_read_enter();
@@ -2639,7 +2623,7 @@
 {
        ifnet_t *ifp;
 
-       ifp = (idx < if_indexlim) ? ifindex2ifnet[idx] : NULL;
+       ifp = (__predict_true(idx < if_indexlim)) ? ifindex2ifnet[idx] : NULL;
        if (ifp != NULL && if_is_deactivated(ifp))
                ifp = NULL;
        return ifp;
@@ -2657,9 +2641,7 @@
        int s;
 
        s = pserialize_read_enter();
-       ifp = (__predict_true(idx < if_indexlim)) ? ifindex2ifnet[idx] : NULL;
-       if (ifp != NULL && if_is_deactivated(ifp))
-               ifp = NULL;
+       ifp = if_byindex(idx);
        if (__predict_true(ifp != NULL))
                psref_acquire(psref, &ifp->if_psref, ifnet_psref_class);
        pserialize_read_exit(s);



Home | Main Index | Thread Index | Old Index