Source-Changes-HG archive

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

[src/trunk]: src/sys/net Forbit installing a route which its gateway is unrea...



details:   https://anonhg.NetBSD.org/src/rev/9a44b7a737d1
branches:  trunk
changeset: 822530:9a44b7a737d1
user:      ozaki-r <ozaki-r%NetBSD.org@localhost>
date:      Fri Mar 24 03:45:02 2017 +0000

description:
Forbit installing a route which its gateway is unreachable

This change needs a tweak in route_output_change to unbreak route
change commands (e.g., route change -inet6 default -reject).

PR kern/52077 (s-yamaguchi@IIJ and ozaki-r@)

diffstat:

 sys/net/route.c  |  12 ++++++++----
 sys/net/rtsock.c |  27 +++++++++++++++++----------
 2 files changed, 25 insertions(+), 14 deletions(-)

diffs (92 lines):

diff -r 06fb7077bb82 -r 9a44b7a737d1 sys/net/route.c
--- a/sys/net/route.c   Fri Mar 24 01:25:36 2017 +0000
+++ b/sys/net/route.c   Fri Mar 24 03:45:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: route.c,v 1.193 2017/03/22 07:14:18 ozaki-r Exp $      */
+/*     $NetBSD: route.c,v 1.194 2017/03/24 03:45:02 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.193 2017/03/22 07:14:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: route.c,v 1.194 2017/03/24 03:45:02 ozaki-r Exp $");
 
 #include <sys/param.h>
 #ifdef RTFLUSH_DEBUG
@@ -1026,11 +1026,15 @@
 
                /* XXX we cannot call rtalloc1 if holding the rt lock */
                if (RT_LOCKED())
-                       rt = rtalloc1_locked(dst, 0, true);
+                       rt = rtalloc1_locked(gateway, 0, true);
                else
-                       rt = rtalloc1(dst, 0);
+                       rt = rtalloc1(gateway, 0);
                if (rt == NULL)
                        return NULL;
+               if (rt->rt_flags & RTF_GATEWAY) {
+                       rt_unref(rt);
+                       return NULL;
+               }
                /*
                 * Just in case. May not need to do this workaround.
                 * Revisit when working on rtentry MP-ification.
diff -r 06fb7077bb82 -r 9a44b7a737d1 sys/net/rtsock.c
--- a/sys/net/rtsock.c  Fri Mar 24 01:25:36 2017 +0000
+++ b/sys/net/rtsock.c  Fri Mar 24 03:45:02 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rtsock.c,v 1.210 2017/03/22 07:14:18 ozaki-r Exp $     */
+/*     $NetBSD: rtsock.c,v 1.211 2017/03/24 03:45:02 ozaki-r Exp $     */
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.210 2017/03/22 07:14:18 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rtsock.c,v 1.211 2017/03/24 03:45:02 ozaki-r Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -599,22 +599,29 @@
     struct rt_xmsghdr *rtm)
 {
        int error = 0;
-       struct ifnet *ifp, *new_ifp;
-       struct ifaddr *ifa, *new_ifa;
+       struct ifnet *ifp = NULL, *new_ifp;
+       struct ifaddr *ifa = NULL, *new_ifa;
        struct psref psref_ifa, psref_new_ifa, psref_ifp;
+       bool newgw;
 
        /*
         * New gateway could require new ifaddr, ifp;
         * flags may also be different; ifp may be specified
         * by ll sockaddr when protocol address is ambiguous
         */
-       ifp = rt_getifp(info, &psref_ifp);
-       ifa = rt_getifa(info, &psref_ifa);
-       if (ifa == NULL) {
-               error = ENETUNREACH;
-               goto out;
+       newgw = info->rti_info[RTAX_GATEWAY] != NULL &&
+           sockaddr_cmp(info->rti_info[RTAX_GATEWAY], rt->rt_gateway) != 0;
+
+       if (newgw || info->rti_info[RTAX_IFP] != NULL ||
+           info->rti_info[RTAX_IFA] != NULL) {
+               ifp = rt_getifp(info, &psref_ifp);
+               ifa = rt_getifa(info, &psref_ifa);
+               if (ifa == NULL) {
+                       error = ENETUNREACH;
+                       goto out;
+               }
        }
-       if (info->rti_info[RTAX_GATEWAY]) {
+       if (newgw) {
                error = rt_setgate(rt, info->rti_info[RTAX_GATEWAY]);
                if (error != 0)
                        goto out;



Home | Main Index | Thread Index | Old Index