Module Name: src
Committed By: ozaki-r
Date: Fri Mar 24 03:45:02 UTC 2017
Modified Files:
src/sys/net: route.c rtsock.c
Log Message:
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@)
To generate a diff of this commit:
cvs rdiff -u -r1.193 -r1.194 src/sys/net/route.c
cvs rdiff -u -r1.210 -r1.211 src/sys/net/rtsock.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/net/route.c
diff -u src/sys/net/route.c:1.193 src/sys/net/route.c:1.194
--- src/sys/net/route.c:1.193 Wed Mar 22 07:14:18 2017
+++ src/sys/net/route.c Fri Mar 24 03:45:02 2017
@@ -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 @@ ifa_ifwithroute_psref(int flags, const s
/* 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.
Index: src/sys/net/rtsock.c
diff -u src/sys/net/rtsock.c:1.210 src/sys/net/rtsock.c:1.211
--- src/sys/net/rtsock.c:1.210 Wed Mar 22 07:14:18 2017
+++ src/sys/net/rtsock.c Fri Mar 24 03:45:02 2017
@@ -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 @@ route_output_change(struct rtentry *rt,
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;