Hi, It is possible to create a gateway route pointing to another gateway route by changing the gateway.
# route add 1/8 127.0.0.1 # route add 2/8 127.0.0.1 1/8 127.0.0.1 UGS 0 0 32768 8 lo0 2/8 127.0.0.1 UGS 0 0 32768 8 lo0 # route change 2/8 1.0.0.1 route: writing to routing socket: Network is unreachable change net 2/8: gateway 1.0.0.1: Network is unreachable 1/8 127.0.0.1 UGS 1 2 32768 8 lo0 2/8 1.0.0.1 UGS 0 0 32768 8 lo0 Despite the error message when doing so, the route has actually changed. The gateway is modified by rt_setgate(), the error is created by rt_getifa(). So these operations should be done the other way around. ok? bluhm Index: net/rtsock.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/net/rtsock.c,v retrieving revision 1.172 diff -u -p -u -p -r1.172 rtsock.c --- net/rtsock.c 22 Oct 2015 15:37:47 -0000 1.172 +++ net/rtsock.c 22 Oct 2015 21:05:51 -0000 @@ -744,6 +744,13 @@ report: info.rti_info[RTAX_GATEWAY]->sa_len)) { newgate = 1; } + /* check reachable gateway before changing the route */ + if (newgate || info.rti_info[RTAX_IFP] != NULL || + info.rti_info[RTAX_IFA] != NULL) { + if ((error = rt_getifa(&info, tableid)) != 0) + goto flush; + ifa = info.rti_ifa; + } if (info.rti_info[RTAX_GATEWAY] != NULL && (error = rt_setgate(rt, info.rti_info[RTAX_GATEWAY], tableid))) @@ -753,12 +760,6 @@ report: * flags may also be different; ifp may be specified * by ll sockaddr when protocol address is ambiguous */ - if (newgate || info.rti_info[RTAX_IFP] != NULL || - info.rti_info[RTAX_IFA] != NULL) { - if ((error = rt_getifa(&info, tableid)) != 0) - goto flush; - ifa = info.rti_ifa; - } if (ifa) { if (rt->rt_ifa != ifa) { if (rt->rt_ifa->ifa_rtrequest)