commit 2b5481fcdafd0b870d445a9712edf3611689bffc Author: Ryota Ozaki Date: Wed Mar 22 12:24:47 2017 +0900 Check reachable gateway only if a new gateway is specified and different from the original diff --git a/sys/net/rtsock.c b/sys/net/rtsock.c index 1f591bd..4ffe374 100644 --- a/sys/net/rtsock.c +++ b/sys/net/rtsock.c @@ -599,22 +599,29 @@ route_output_change(struct rtentry *rt, struct rt_addrinfo *info, 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; + * 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;