diff options
author | brian <brian@FreeBSD.org> | 2001-08-16 02:01:05 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 2001-08-16 02:01:05 +0000 |
commit | 9311b9a0c6a95eb3d50f008413e9402f009fc9c2 (patch) | |
tree | 335ec6fcb40828e986dc81fcd542ae2daf394fae /usr.sbin | |
parent | 435f044654f35938fd5c9737d37e646786365f27 (diff) | |
download | FreeBSD-src-9311b9a0c6a95eb3d50f008413e9402f009fc9c2.zip FreeBSD-src-9311b9a0c6a95eb3d50f008413e9402f009fc9c2.tar.gz |
Specify the gateway address when updating the MTU and send/recv pipe
sizes on a route.
IMHO this shouldn't be necessary (the destination & mask/prefixlen
should be enough), but without it, the default route update under
OpenBSD will fail.
Thanks to: Russell T Hunt <alaric@MIT.EDU>
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ppp/ipcp.c | 13 | ||||
-rw-r--r-- | usr.sbin/ppp/ipv6cp.c | 16 | ||||
-rw-r--r-- | usr.sbin/ppp/ncpaddr.c | 6 | ||||
-rw-r--r-- | usr.sbin/ppp/ncpaddr.h | 1 | ||||
-rw-r--r-- | usr.sbin/ppp/route.c | 61 | ||||
-rw-r--r-- | usr.sbin/ppp/route.h | 3 |
6 files changed, 69 insertions, 31 deletions
diff --git a/usr.sbin/ppp/ipcp.c b/usr.sbin/ppp/ipcp.c index 8decdb1..37c7e93 100644 --- a/usr.sbin/ppp/ipcp.c +++ b/usr.sbin/ppp/ipcp.c @@ -659,8 +659,14 @@ ipcp_SetIPaddress(struct ipcp *ipcp, struct in_addr myaddr, { struct bundle *bundle = ipcp->fsm.bundle; struct ncpaddr myncpaddr, hisncpaddr; - struct ncprange myrange, dst; + struct ncprange myrange; struct in_addr mask; + struct sockaddr_storage ssdst, ssgw, ssmask; + struct sockaddr *sadst, *sagw, *samask; + + sadst = (struct sockaddr *)&ssdst; + sagw = (struct sockaddr *)&ssgw; + samask = (struct sockaddr *)&ssmask; ncpaddr_setip4(&hisncpaddr, hisaddr); ncpaddr_setip4(&myncpaddr, myaddr); @@ -681,8 +687,9 @@ ipcp_SetIPaddress(struct ipcp *ipcp, struct in_addr myaddr, IFACE_CLEAR_ALIASES|IFACE_SYSTEM); if (bundle->ncp.cfg.sendpipe > 0 || bundle->ncp.cfg.recvpipe > 0) { - ncprange_sethost(&dst, &hisncpaddr); - rt_Update(bundle, &dst); + ncprange_getsa(&myrange, &ssgw, &ssmask); + ncpaddr_getsa(&hisncpaddr, &ssdst); + rt_Update(bundle, sadst, sagw, samask); } if (Enabled(bundle, OPT_SROUTES)) diff --git a/usr.sbin/ppp/ipv6cp.c b/usr.sbin/ppp/ipv6cp.c index eb76465..6ec1485 100644 --- a/usr.sbin/ppp/ipv6cp.c +++ b/usr.sbin/ppp/ipv6cp.c @@ -115,7 +115,13 @@ ipcp_SetIPv6address(struct ipv6cp *ipv6cp, u_int32_t mytok, u_int32_t histok) { struct bundle *bundle = ipv6cp->fsm.bundle; struct in6_addr myaddr, hisaddr; - struct ncprange myrange, dst; + struct ncprange myrange; + struct sockaddr_storage ssdst, ssgw, ssmask; + struct sockaddr *sadst, *sagw, *samask; + + sadst = (struct sockaddr *)&ssdst; + sagw = (struct sockaddr *)&ssgw; + samask = (struct sockaddr *)&ssmask; memset(&myaddr, '\0', sizeof myaddr); memset(&hisaddr, '\0', sizeof hisaddr); @@ -141,8 +147,12 @@ ipcp_SetIPv6address(struct ipv6cp *ipv6cp, u_int32_t mytok, u_int32_t histok) IFACE_CLEAR_ALIASES|IFACE_SYSTEM); if (bundle->ncp.cfg.sendpipe > 0 || bundle->ncp.cfg.recvpipe > 0) { - ncprange_sethost(&dst, &ipv6cp->hisaddr); - rt_Update(bundle, &dst); + ncprange_getsa(&myrange, &ssgw, &ssmask); + if (ncpaddr_isset(&ipv6cp->hisaddr)) + ncpaddr_getsa(&ipv6cp->hisaddr, &ssdst); + else + sadst = NULL; + rt_Update(bundle, sadst, sagw, samask); } if (Enabled(bundle, OPT_SROUTES)) diff --git a/usr.sbin/ppp/ncpaddr.c b/usr.sbin/ppp/ncpaddr.c index e0f4512..62b5e7f 100644 --- a/usr.sbin/ppp/ncpaddr.c +++ b/usr.sbin/ppp/ncpaddr.c @@ -185,6 +185,12 @@ ncpaddr_init(struct ncpaddr *addr) } int +ncpaddr_isset(const struct ncpaddr *addr) +{ + return addr->ncpaddr_family != AF_UNSPEC; +} + +int ncpaddr_isdefault(const struct ncpaddr *addr) { switch (addr->ncpaddr_family) { diff --git a/usr.sbin/ppp/ncpaddr.h b/usr.sbin/ppp/ncpaddr.h index 98ca582..2b3c546 100644 --- a/usr.sbin/ppp/ncpaddr.h +++ b/usr.sbin/ppp/ncpaddr.h @@ -59,6 +59,7 @@ struct ncpaddr { struct ncp; extern void ncpaddr_init(struct ncpaddr *); +extern int ncpaddr_isset(const struct ncpaddr *); extern int ncpaddr_isdefault(const struct ncpaddr *); extern int ncpaddr_equal(const struct ncpaddr *, const struct ncpaddr *); extern void ncpaddr_copy(struct ncpaddr *, const struct ncpaddr *); diff --git a/usr.sbin/ppp/route.c b/usr.sbin/ppp/route.c index a3bab0f..b29bce2 100644 --- a/usr.sbin/ppp/route.c +++ b/usr.sbin/ppp/route.c @@ -504,17 +504,19 @@ route_UpdateMTU(struct bundle *bundle) for (cp = sp; cp < ep; cp += rtm->rtm_msglen) { rtm = (struct rt_msghdr *)cp; route_ParseHdr(rtm, sa); - if (sa[RTAX_DST] && sa[RTAX_DST]->sa_family == AF_INET && - sa[RTAX_GATEWAY] && /* sa[RTAX_NETMASK] && */ - rtm->rtm_index == bundle->iface->index && - (sa[RTAX_GATEWAY]->sa_family == AF_INET || - sa[RTAX_GATEWAY]->sa_family == AF_LINK)) { - log_Printf(LogTCPIP, "route_UpdateMTU: Netif: %d (%s), dst %s, mtu %d\n", - rtm->rtm_index, Index2Nam(rtm->rtm_index), - inet_ntoa(((struct sockaddr_in *)sa[RTAX_DST])->sin_addr), - bundle->iface->mtu); - ncprange_setsa(&dst, sa[RTAX_DST], sa[RTAX_NETMASK]); - rt_Update(bundle, &dst); + if (sa[RTAX_DST] && (sa[RTAX_DST]->sa_family == AF_INET || +#ifndef NOINET6 + sa[RTAX_DST]->sa_family == AF_INET6 +#endif + ) && + sa[RTAX_GATEWAY] && rtm->rtm_index == bundle->iface->index) { + if (log_IsKept(LogTCPIP)) { + ncprange_setsa(&dst, sa[RTAX_DST], sa[RTAX_NETMASK]); + log_Printf(LogTCPIP, "route_UpdateMTU: Netif: %d (%s), dst %s," + " mtu %d\n", rtm->rtm_index, Index2Nam(rtm->rtm_index), + ncprange_ntoa(&dst), bundle->iface->mtu); + } + rt_Update(bundle, sa[RTAX_DST], sa[RTAX_GATEWAY], sa[RTAX_NETMASK]); } } @@ -819,11 +821,13 @@ failed: } void -rt_Update(struct bundle *bundle, const struct ncprange *dst) +rt_Update(struct bundle *bundle, const struct sockaddr *dst, + const struct sockaddr *gw, const struct sockaddr *mask) { + struct ncprange ncpdst; struct rtmsg rtmes; + char *p; int s, wb; - struct sockaddr_storage sadst, samask; s = ID0socket(PF_ROUTE, SOCK_RAW, 0); if (s < 0) { @@ -834,7 +838,7 @@ rt_Update(struct bundle *bundle, const struct ncprange *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_DST; + rtmes.m_rtm.rtm_addrs = RTA_GATEWAY; 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; @@ -851,27 +855,36 @@ rt_Update(struct bundle *bundle, const struct ncprange *dst) rtmes.m_rtm.rtm_rmx.rmx_mtu = bundle->iface->mtu; rtmes.m_rtm.rtm_inits |= RTV_MTU; + p = rtmes.m_space; - ncprange_getsa(dst, &sadst, &samask); + if (dst) { + rtmes.m_rtm.rtm_addrs |= RTA_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; + } - memcpy(rtmes.m_space, &sadst, sadst.ss_len); - memcpy(rtmes.m_space + sadst.ss_len, &samask, samask.ss_len); - rtmes.m_rtm.rtm_msglen = rtmes.m_space - (char *)&rtmes; - rtmes.m_rtm.rtm_msglen+= sadst.ss_len + samask.ss_len; + rtmes.m_rtm.rtm_msglen = p - (char *)&rtmes; wb = ID0write(s, &rtmes, rtmes.m_rtm.rtm_msglen); if (wb < 0) { + ncprange_setsa(&ncpdst, dst, mask); + log_Printf(LogTCPIP, "rt_Update failure:\n"); - log_Printf(LogTCPIP, "rt_Update: Dst = %s\n", ncprange_ntoa(dst)); + log_Printf(LogTCPIP, "rt_Update: Dst = %s\n", ncprange_ntoa(&ncpdst)); if (rtmes.m_rtm.rtm_errno == 0) log_Printf(LogWARN, "%s: Change route failed: errno: %s\n", - ncprange_ntoa(dst), strerror(errno)); + ncprange_ntoa(&ncpdst), strerror(errno)); else log_Printf(LogWARN, "%s: Change route failed: %s\n", - ncprange_ntoa(dst), strerror(rtmes.m_rtm.rtm_errno)); + ncprange_ntoa(&ncpdst), strerror(rtmes.m_rtm.rtm_errno)); } - log_Printf(LogDEBUG, "wrote %d: cmd = Change, dst = %s\n", - wb, ncprange_ntoa(dst)); close(s); } diff --git a/usr.sbin/ppp/route.h b/usr.sbin/ppp/route.h index f2ebd0e..edf6604 100644 --- a/usr.sbin/ppp/route.h +++ b/usr.sbin/ppp/route.h @@ -69,4 +69,5 @@ extern void route_ShowSticky(struct prompt *, struct sticky_route *, extern void route_ParseHdr(struct rt_msghdr *, struct sockaddr *[RTAX_MAX]); extern int rt_Set(struct bundle *, int, const struct ncprange *, const struct ncpaddr *, int, int); -extern void rt_Update(struct bundle *, const struct ncprange *); +extern void rt_Update(struct bundle *, const struct sockaddr *, + const struct sockaddr *, const struct sockaddr *); |