summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbrian <brian@openbsd.org>2001-08-20 00:48:14 +0000
committerbrian <brian@openbsd.org>2001-08-20 00:48:14 +0000
commit77d4eadc1b9ff5391e25f60b5840eda971330861 (patch)
treedd390dcebc4df62acb5645f69ea2c3c7160642dd
parentThe end of old timeouts is near... (diff)
downloadwireguard-openbsd-77d4eadc1b9ff5391e25f60b5840eda971330861.tar.xz
wireguard-openbsd-77d4eadc1b9ff5391e25f60b5840eda971330861.zip
When attempting to change the default route under FreeBSD, don't write
the gateway and mask to the routing socket, otherwise the update fails. The code here was broken for FreeBSD when IPv6 support was added, but worked for OpenBSD. OpenBSD expects the gateway and mask to be supplied and fails the update otherwise.
-rw-r--r--usr.sbin/ppp/ppp/route.c35
1 files changed, 27 insertions, 8 deletions
diff --git a/usr.sbin/ppp/ppp/route.c b/usr.sbin/ppp/ppp/route.c
index 91bacd901f1..82041771559 100644
--- a/usr.sbin/ppp/ppp/route.c
+++ b/usr.sbin/ppp/ppp/route.c
@@ -25,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $OpenBSD: route.c,v 1.15 2001/08/19 23:22:18 brian Exp $
+ * $OpenBSD: route.c,v 1.16 2001/08/20 00:48:14 brian Exp $
*/
#include <sys/param.h>
@@ -838,7 +838,7 @@ rt_Update(struct bundle *bundle, const struct sockaddr *dst,
memset(&rtmes, '\0', sizeof rtmes);
rtmes.m_rtm.rtm_version = RTM_VERSION;
rtmes.m_rtm.rtm_type = RTM_CHANGE;
- rtmes.m_rtm.rtm_addrs = RTA_GATEWAY;
+ rtmes.m_rtm.rtm_addrs = 0;
rtmes.m_rtm.rtm_seq = ++bundle->routing_seq;
rtmes.m_rtm.rtm_pid = getpid();
rtmes.m_rtm.rtm_flags = RTF_UP | RTF_GATEWAY | RTF_STATIC;
@@ -862,12 +862,31 @@ rt_Update(struct bundle *bundle, const struct sockaddr *dst,
memcpy(p, dst, dst->sa_len);
p += dst->sa_len;
}
- memcpy(p, gw, gw->sa_len);
- p += gw->sa_len;
- if (mask) {
- rtmes.m_rtm.rtm_addrs |= RTA_NETMASK;
- memcpy(p, mask, mask->sa_len);
- p += mask->sa_len;
+
+#ifdef __FreeBSD__
+ /*
+ * In order to update the default route under FreeBSD, only the destination
+ * address should be specified. If the (empty) mask or the gateway
+ * address are used, the update fails...
+ * Conversely, if the gateway and mask are omitted under OpenBSD, the
+ * update will fail.
+ */
+ if (dst)
+ ncprange_setsa(&ncpdst, dst, mask);
+ else
+ ncprange_init(&ncpdst);
+
+ if (!ncprange_isdefault(&ncpdst))
+#endif
+ {
+ rtmes.m_rtm.rtm_addrs |= RTA_GATEWAY;
+ memcpy(p, gw, gw->sa_len);
+ p += gw->sa_len;
+ if (mask) {
+ rtmes.m_rtm.rtm_addrs |= RTA_NETMASK;
+ memcpy(p, mask, mask->sa_len);
+ p += mask->sa_len;
+ }
}
rtmes.m_rtm.rtm_msglen = p - (char *)&rtmes;