Source-Changes-HG archive

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

[src/trunk]: src/sys Get rid of unnecessary NULL checks for rt_ifa and ifa_ifp



details:   https://anonhg.NetBSD.org/src/rev/c5979ade1829
branches:  trunk
changeset: 461008:c5979ade1829
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Wed Nov 13 02:51:22 2019 +0000

description:
Get rid of unnecessary NULL checks for rt_ifa and ifa_ifp

They are always non-NULL nowadays.

diffstat:

 sys/net/if.c              |  10 +++++-----
 sys/net/route.c           |  35 ++++++++++++++++-------------------
 sys/netinet/ip_input.c    |   7 +++----
 sys/netinet/sctp_output.c |   8 +++-----
 sys/netinet6/frag6.c      |   6 +++---
 sys/netinet6/in6_src.c    |   7 +++----
 sys/netinet6/ip6_output.c |   6 +++---
 sys/netinet6/nd6_nbr.c    |  16 +++++++---------
 8 files changed, 43 insertions(+), 52 deletions(-)

diffs (truncated from 320 to 300 lines):

diff -r 09384a754ee1 -r c5979ade1829 sys/net/if.c
--- a/sys/net/if.c      Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/net/if.c      Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if.c,v 1.463 2019/10/06 15:11:17 uwe Exp $     */
+/*     $NetBSD: if.c,v 1.464 2019/11/13 02:51:22 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.463 2019/10/06 15:11:17 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.464 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -2197,10 +2197,10 @@
        struct ifnet *ifp;
        struct psref psref;
 
-       if (cmd != RTM_ADD || (ifa = rt->rt_ifa) == NULL ||
-           (ifp = ifa->ifa_ifp) == NULL || (dst = rt_getkey(rt)) == NULL ||
-           ISSET(info->rti_flags, RTF_DONTCHANGEIFA))
+       if (cmd != RTM_ADD || ISSET(info->rti_flags, RTF_DONTCHANGEIFA))
                return;
+       ifp = rt->rt_ifa->ifa_ifp;
+       dst = rt_getkey(rt);
        if ((ifa = ifaof_ifpforaddr_psref(dst, ifp, &psref)) != NULL) {
                rt_replace_ifa(rt, ifa);
                if (ifa->ifa_rtrequest && ifa->ifa_rtrequest != link_rtrequest)
diff -r 09384a754ee1 -r c5979ade1829 sys/net/route.c
--- a/sys/net/route.c   Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/net/route.c   Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $    */
+/*     $NetBSD: route.c,v 1.226 2019/11/13 02:51:22 ozaki-r Exp $      */
 
 /*-
  * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.225 2019/10/03 03:10:02 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.226 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #include <sys/param.h>
 #ifdef RTFLUSH_DEBUG
@@ -355,9 +355,8 @@
 {
        struct ifaddr *ifa;
 
-       if ((ifa = rt->rt_ifa) == NULL)
-               return ifa;
-       else if (ifa->ifa_getifa == NULL)
+       ifa = rt->rt_ifa;
+       if (ifa->ifa_getifa == NULL)
                return ifa;
 #if 0
        else if (ifa->ifa_seqno != NULL && *ifa->ifa_seqno == rt->rt_ifa_seqno)
@@ -412,8 +411,7 @@
        if (rt->rt_ifa == ifa)
                return;
 
-       if (rt->rt_ifa &&
-           rt->rt_ifa != ifa &&
+       if (rt->rt_ifa != ifa &&
            rt->rt_ifa->ifa_flags & IFA_ROUTE &&
            rt_ifa_connected(rt, rt->rt_ifa))
        {
@@ -1194,18 +1192,17 @@
                if ((rt = rt_deladdr(rtbl, dst, netmask)) == NULL)
                        senderr(ESRCH);
                rt->rt_flags &= ~RTF_UP;
-               if ((ifa = rt->rt_ifa)) {
-                       if (ifa->ifa_flags & IFA_ROUTE &&
-                           rt_ifa_connected(rt, ifa)) {
-                               RT_DPRINTF("rt->_rt_key = %p, ifa = %p, "
-                                   "deleted IFA_ROUTE\n",
-                                   (void *)rt->_rt_key, (void *)ifa);
-                               ifa->ifa_flags &= ~IFA_ROUTE;
-                       }
-                       if (ifa->ifa_rtrequest)
-                               ifa->ifa_rtrequest(RTM_DELETE, rt, info);
-                       ifa = NULL;
+               ifa = rt->rt_ifa;
+               if (ifa->ifa_flags & IFA_ROUTE &&
+                   rt_ifa_connected(rt, ifa)) {
+                       RT_DPRINTF("rt->_rt_key = %p, ifa = %p, "
+                           "deleted IFA_ROUTE\n",
+                           (void *)rt->_rt_key, (void *)ifa);
+                       ifa->ifa_flags &= ~IFA_ROUTE;
                }
+               if (ifa->ifa_rtrequest)
+                       ifa->ifa_rtrequest(RTM_DELETE, rt, info);
+               ifa = NULL;
                rttrash++;
                if (ret_nrt) {
                        *ret_nrt = rt;
@@ -1519,7 +1516,7 @@
                rt->rt_flags = (info->rti_flags & ~PRESERVED_RTF) |
                    (rt->rt_flags & PRESERVED_RTF);
        }
-       if (rt->rt_ifa && rt->rt_ifa->ifa_rtrequest)
+       if (rt->rt_ifa->ifa_rtrequest)
                rt->rt_ifa->ifa_rtrequest(RTM_ADD, rt, info);
 #if defined(INET) || defined(INET6)
        if (ifp_changed && rt_mask(rt) != NULL)
diff -r 09384a754ee1 -r c5979ade1829 sys/netinet/ip_input.c
--- a/sys/netinet/ip_input.c    Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/netinet/ip_input.c    Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip_input.c,v 1.392 2019/09/19 05:31:50 ozaki-r Exp $   */
+/*     $NetBSD: ip_input.c,v 1.393 2019/11/13 02:51:22 ozaki-r Exp $   */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -91,7 +91,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.392 2019/09/19 05:31:50 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip_input.c,v 1.393 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1400,8 +1400,7 @@
            (rt->rt_flags & (RTF_DYNAMIC|RTF_MODIFIED)) == 0 &&
            !in_nullhost(satocsin(rt_getkey(rt))->sin_addr) &&
            ipsendredirects && !srcrt) {
-               if (rt->rt_ifa &&
-                   (ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_subnetmask) ==
+               if ((ip->ip_src.s_addr & ifatoia(rt->rt_ifa)->ia_subnetmask) ==
                    ifatoia(rt->rt_ifa)->ia_subnet) {
                        if (rt->rt_flags & RTF_GATEWAY)
                                dest = satosin(rt->rt_gateway)->sin_addr.s_addr;
diff -r 09384a754ee1 -r c5979ade1829 sys/netinet/sctp_output.c
--- a/sys/netinet/sctp_output.c Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/netinet/sctp_output.c Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sctp_output.c,v 1.18 2018/12/22 14:28:57 maxv Exp $ */
+/*     $NetBSD: sctp_output.c,v 1.19 2019/11/13 02:51:22 ozaki-r Exp $ */
 /*     $KAME: sctp_output.c,v 1.48 2005/06/16 18:29:24 jinmei Exp $    */
 
 /*
@@ -30,7 +30,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.18 2018/12/22 14:28:57 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sctp_output.c,v 1.19 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_ipsec.h"
@@ -2507,9 +2507,7 @@
                             int local_scope,
                             int site_scope)
 {
-       if ((loopback_scope == 0) &&
-           (ifa->ifa_ifp) &&
-           (ifa->ifa_ifp->if_type == IFT_LOOP)) {
+       if ((loopback_scope == 0) && (ifa->ifa_ifp->if_type == IFT_LOOP)) {
                /* skip loopback if not in scope *
                 */
                return (0);
diff -r 09384a754ee1 -r c5979ade1829 sys/netinet6/frag6.c
--- a/sys/netinet6/frag6.c      Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/netinet6/frag6.c      Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: frag6.c,v 1.74 2018/05/15 19:16:38 maxv Exp $  */
+/*     $NetBSD: frag6.c,v 1.75 2019/11/13 02:51:22 ozaki-r Exp $       */
 /*     $KAME: frag6.c,v 1.40 2002/05/27 21:40:31 itojun Exp $  */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.74 2018/05/15 19:16:38 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: frag6.c,v 1.75 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_net_mpsafe.h"
@@ -181,7 +181,7 @@
        dstifp = NULL;
        /* find the destination interface of the packet. */
        sockaddr_in6_init(&u.dst6, &ip6->ip6_dst, 0, 0, 0);
-       if ((rt = rtcache_lookup(&ro, &u.dst)) != NULL && rt->rt_ifa != NULL)
+       if ((rt = rtcache_lookup(&ro, &u.dst)) != NULL)
                dstifp = ((struct in6_ifaddr *)rt->rt_ifa)->ia_ifp;
 
        /* jumbo payload can't contain a fragment header */
diff -r 09384a754ee1 -r c5979ade1829 sys/netinet6/in6_src.c
--- a/sys/netinet6/in6_src.c    Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/netinet6/in6_src.c    Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: in6_src.c,v 1.85 2018/05/01 07:21:39 maxv Exp $        */
+/*     $NetBSD: in6_src.c,v 1.86 2019/11/13 02:51:22 ozaki-r Exp $     */
 /*     $KAME: in6_src.c,v 1.159 2005/10/19 01:40:32 t-momose Exp $     */
 
 /*
@@ -66,7 +66,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.85 2018/05/01 07:21:39 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: in6_src.c,v 1.86 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -780,8 +780,7 @@
         * destination address (which should probably be one of our own
         * addresses.)
         */
-       if (rt->rt_ifa && rt->rt_ifa->ifa_ifp &&
-           rt->rt_ifa->ifa_ifp != *retifp &&
+       if (rt->rt_ifa->ifa_ifp != *retifp &&
            !if_is_deactivated(rt->rt_ifa->ifa_ifp)) {
                if_put(*retifp, psref);
                *retifp = rt->rt_ifa->ifa_ifp;
diff -r 09384a754ee1 -r c5979ade1829 sys/netinet6/ip6_output.c
--- a/sys/netinet6/ip6_output.c Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/netinet6/ip6_output.c Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ip6_output.c,v 1.221 2019/11/01 04:23:21 knakahara Exp $       */
+/*     $NetBSD: ip6_output.c,v 1.222 2019/11/13 02:51:22 ozaki-r Exp $ */
 /*     $KAME: ip6_output.c,v 1.172 2001/03/25 09:55:56 itojun Exp $    */
 
 /*
@@ -62,7 +62,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.221 2019/11/01 04:23:21 knakahara Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ip6_output.c,v 1.222 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -550,7 +550,7 @@
         * destination addresses.  We should use ia_ifp to support the
         * case of sending packets to an address of our own.
         */
-       if (ia != NULL && ia->ia_ifp) {
+       if (ia != NULL) {
                origifp = ia->ia_ifp;
                if (if_is_deactivated(origifp))
                        goto bad;
diff -r 09384a754ee1 -r c5979ade1829 sys/netinet6/nd6_nbr.c
--- a/sys/netinet6/nd6_nbr.c    Wed Nov 13 01:31:47 2019 +0000
+++ b/sys/netinet6/nd6_nbr.c    Wed Nov 13 02:51:22 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: nd6_nbr.c,v 1.174 2019/09/25 09:52:32 ozaki-r Exp $    */
+/*     $NetBSD: nd6_nbr.c,v 1.175 2019/11/13 02:51:22 ozaki-r Exp $    */
 /*     $KAME: nd6_nbr.c,v 1.61 2001/02/10 16:06:14 jinmei Exp $        */
 
 /*
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.174 2019/09/25 09:52:32 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nd6_nbr.c,v 1.175 2019/11/13 02:51:22 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1179,8 +1179,7 @@
                        *found_nonce = true;
                        log(LOG_DEBUG,
                            "%s: detected a looped back NS message for %s\n",
-                           ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???",
-                           IN6_PRINT(ip6buf, myaddr6));
+                           if_name(ifa->ifa_ifp), IN6_PRINT(ip6buf, myaddr6));
                        dp->dad_ns_lcount++;
                        continue;
                }
@@ -1256,7 +1255,7 @@
                        "nd6_dad_start: called with non-tentative address "
                        "%s(%s)\n",
                        IN6_PRINT(ip6buf, &ia->ia_addr.sin6_addr),
-                       ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
+                       if_name(ifa->ifa_ifp));
                return;
        }
        if (ia->ia6_flags & IN6_IFF_ANYCAST || !ip6_dad_enabled()) {
@@ -1264,7 +1263,6 @@
                rt_addrmsg(RTM_NEWADDR, ifa);
                return;
        }
-       KASSERT(ifa->ifa_ifp != NULL);
        if (!(ifa->ifa_ifp->if_flags & IFF_UP))
                return;
 
@@ -1284,7 +1282,7 @@
                log(LOG_ERR, "nd6_dad_start: memory allocation failed for "
                        "%s(%s)\n",
                        IN6_PRINT(ip6buf, &ia->ia_addr.sin6_addr),
-                       ifa->ifa_ifp ? if_name(ifa->ifa_ifp) : "???");
+                       if_name(ifa->ifa_ifp));



Home | Main Index | Thread Index | Old Index