- need_trigger/idx should be u_int, not ssize_t.
- realloc pedant. - set sin6_scope_id before sending (link-local/multicast) packets - removed an incorrect comment - don't age non-gateway host routes. - not remove global addresses on loopback interface from routing table by route aging. Obtained from: KAME
This commit is contained in:
parent
f768a332f8
commit
cd8ce96d58
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=122677
@ -1,5 +1,5 @@
|
|||||||
/* $FreeBSD$ */
|
/* $FreeBSD$ */
|
||||||
/* $KAME: route6d.c,v 1.64 2001/05/08 04:36:37 itojun Exp $ */
|
/* $KAME: route6d.c,v 1.104 2003/10/31 00:30:20 itojun Exp $ */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
* Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
|
||||||
@ -31,7 +31,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef lint
|
#ifndef lint
|
||||||
static char _rcsid[] = "$KAME: route6d.c,v 1.64 2001/05/08 04:36:37 itojun Exp $";
|
static char _rcsid[] = "$KAME: route6d.c,v 1.104 2003/10/31 00:30:20 itojun Exp $";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -62,13 +62,9 @@ static char _rcsid[] = "$KAME: route6d.c,v 1.64 2001/05/08 04:36:37 itojun Exp $
|
|||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
#include <net/if.h>
|
#include <net/if.h>
|
||||||
#if defined(__FreeBSD__) && __FreeBSD__ >= 3
|
|
||||||
#include <net/if_var.h>
|
#include <net/if_var.h>
|
||||||
#endif /* __FreeBSD__ >= 3 */
|
|
||||||
#define KERNEL 1
|
|
||||||
#define _KERNEL 1
|
#define _KERNEL 1
|
||||||
#include <net/route.h>
|
#include <net/route.h>
|
||||||
#undef KERNEL
|
|
||||||
#undef _KERNEL
|
#undef _KERNEL
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <netinet/in_var.h>
|
#include <netinet/in_var.h>
|
||||||
@ -390,11 +386,6 @@ main(argc, argv)
|
|||||||
fatal("No loopback found");
|
fatal("No loopback found");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
#ifdef __FreeBSD__
|
|
||||||
sranddev();
|
|
||||||
#else
|
|
||||||
srand((unsigned)(time(NULL)^(pid<<16)));
|
|
||||||
#endif
|
|
||||||
for (ifcp = ifc; ifcp; ifcp = ifcp->ifc_next)
|
for (ifcp = ifc; ifcp; ifcp = ifcp->ifc_next)
|
||||||
ifrt(ifcp, 0);
|
ifrt(ifcp, 0);
|
||||||
filterconfig();
|
filterconfig();
|
||||||
@ -402,11 +393,13 @@ main(argc, argv)
|
|||||||
if (dflag)
|
if (dflag)
|
||||||
ifrtdump(0);
|
ifrtdump(0);
|
||||||
|
|
||||||
|
#if 1
|
||||||
pid = getpid();
|
pid = getpid();
|
||||||
if ((pidfile = fopen(ROUTE6D_PID, "w")) != NULL) {
|
if ((pidfile = fopen(ROUTE6D_PID, "w")) != NULL) {
|
||||||
fprintf(pidfile, "%d\n", pid);
|
fprintf(pidfile, "%d\n", pid);
|
||||||
fclose(pidfile);
|
fclose(pidfile);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if ((ripbuf = (struct rip6 *)malloc(RIP6_MAXMTU)) == NULL) {
|
if ((ripbuf = (struct rip6 *)malloc(RIP6_MAXMTU)) == NULL) {
|
||||||
fatal("malloc");
|
fatal("malloc");
|
||||||
@ -1016,11 +1009,6 @@ sendpacket(sin6, len)
|
|||||||
struct sockaddr_in6 *sin6;
|
struct sockaddr_in6 *sin6;
|
||||||
int len;
|
int len;
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* MSG_DONTROUTE should not be specified when it responds with a
|
|
||||||
* RIP6_REQUEST message. SO_DONTROUTE has been specified to
|
|
||||||
* other sockets.
|
|
||||||
*/
|
|
||||||
struct msghdr m;
|
struct msghdr m;
|
||||||
struct cmsghdr *cm;
|
struct cmsghdr *cm;
|
||||||
struct iovec iov[2];
|
struct iovec iov[2];
|
||||||
@ -1035,8 +1023,10 @@ sendpacket(sin6, len)
|
|||||||
|
|
||||||
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
|
if (IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr) ||
|
||||||
IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
|
IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) {
|
||||||
|
/* XXX: do not mix the interface index and link index */
|
||||||
idx = IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr);
|
idx = IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr);
|
||||||
SET_IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr, 0);
|
SET_IN6_LINKLOCAL_IFINDEX(sin6->sin6_addr, 0);
|
||||||
|
sin6->sin6_scope_id = idx;
|
||||||
} else
|
} else
|
||||||
idx = 0;
|
idx = 0;
|
||||||
|
|
||||||
@ -1084,7 +1074,8 @@ riprecv()
|
|||||||
struct rip6 *rp;
|
struct rip6 *rp;
|
||||||
struct netinfo6 *np, *nq;
|
struct netinfo6 *np, *nq;
|
||||||
struct riprt *rrt;
|
struct riprt *rrt;
|
||||||
int len, nn, need_trigger, idx;
|
ssize_t len, nn;
|
||||||
|
unsigned int need_trigger, idx;
|
||||||
char buf[4 * RIP6_MAXMTU];
|
char buf[4 * RIP6_MAXMTU];
|
||||||
time_t t;
|
time_t t;
|
||||||
struct msghdr m;
|
struct msghdr m;
|
||||||
@ -1510,6 +1501,8 @@ ifconfig1(name, sa, ifcp, s)
|
|||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
|
||||||
sin6 = (const struct sockaddr_in6 *)sa;
|
sin6 = (const struct sockaddr_in6 *)sa;
|
||||||
|
if (IN6_IS_ADDR_SITELOCAL(&sin6->sin6_addr) && !lflag)
|
||||||
|
return;
|
||||||
ifr.ifr_addr = *sin6;
|
ifr.ifr_addr = *sin6;
|
||||||
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
strncpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
|
||||||
if (ioctl(s, SIOCGIFNETMASK_IN6, (char *)&ifr) < 0) {
|
if (ioctl(s, SIOCGIFNETMASK_IN6, (char *)&ifr) < 0) {
|
||||||
@ -2030,8 +2023,11 @@ ifrt(ifcp, again)
|
|||||||
time_t t_lifetime;
|
time_t t_lifetime;
|
||||||
int need_trigger = 0;
|
int need_trigger = 0;
|
||||||
|
|
||||||
|
#if 0
|
||||||
if (ifcp->ifc_flags & IFF_LOOPBACK)
|
if (ifcp->ifc_flags & IFF_LOOPBACK)
|
||||||
return 0; /* ignore loopback */
|
return 0; /* ignore loopback */
|
||||||
|
#endif
|
||||||
|
|
||||||
if (ifcp->ifc_flags & IFF_POINTOPOINT) {
|
if (ifcp->ifc_flags & IFF_POINTOPOINT) {
|
||||||
ifrt_p2p(ifcp, again);
|
ifrt_p2p(ifcp, again);
|
||||||
return 0;
|
return 0;
|
||||||
@ -2050,6 +2046,13 @@ ifrt(ifcp, again)
|
|||||||
#if 0
|
#if 0
|
||||||
trace(1, "route: %s: skip unspec interface address\n",
|
trace(1, "route: %s: skip unspec interface address\n",
|
||||||
ifcp->ifc_name);
|
ifcp->ifc_name);
|
||||||
|
#endif
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (IN6_IS_ADDR_LOOPBACK(&ifa->ifa_addr)) {
|
||||||
|
#if 0
|
||||||
|
trace(1, "route: %s: skip loopback address\n",
|
||||||
|
ifcp->ifc_name);
|
||||||
#endif
|
#endif
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -2064,7 +2067,10 @@ ifrt(ifcp, again)
|
|||||||
rrt->rrt_info.rip6_tag = htons(routetag & 0xffff);
|
rrt->rrt_info.rip6_tag = htons(routetag & 0xffff);
|
||||||
rrt->rrt_info.rip6_metric = 1 + ifcp->ifc_metric;
|
rrt->rrt_info.rip6_metric = 1 + ifcp->ifc_metric;
|
||||||
rrt->rrt_info.rip6_plen = ifa->ifa_plen;
|
rrt->rrt_info.rip6_plen = ifa->ifa_plen;
|
||||||
rrt->rrt_flags = RTF_CLONING;
|
if (ifa->ifa_plen == 128)
|
||||||
|
rrt->rrt_flags = RTF_HOST;
|
||||||
|
else
|
||||||
|
rrt->rrt_flags = RTF_CLONING;
|
||||||
rrt->rrt_rflags |= RRTF_CHANGED;
|
rrt->rrt_rflags |= RRTF_CHANGED;
|
||||||
applyplen(&rrt->rrt_info.rip6_dest, ifa->ifa_plen);
|
applyplen(&rrt->rrt_info.rip6_dest, ifa->ifa_plen);
|
||||||
memset(&rrt->rrt_gw, 0, sizeof(struct in6_addr));
|
memset(&rrt->rrt_gw, 0, sizeof(struct in6_addr));
|
||||||
@ -2326,12 +2332,10 @@ getifmtu(ifindex)
|
|||||||
}
|
}
|
||||||
ifm = (struct if_msghdr *)buf;
|
ifm = (struct if_msghdr *)buf;
|
||||||
mtu = ifm->ifm_data.ifi_mtu;
|
mtu = ifm->ifm_data.ifi_mtu;
|
||||||
#ifdef __FreeBSD__
|
|
||||||
if (ifindex != ifm->ifm_index) {
|
if (ifindex != ifm->ifm_index) {
|
||||||
fatal("ifindex does not match with ifm_index");
|
fatal("ifindex does not match with ifm_index");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return mtu;
|
return mtu;
|
||||||
}
|
}
|
||||||
@ -2614,6 +2618,8 @@ rt_entry(rtm, again)
|
|||||||
rrt->rrt_t = time(NULL);
|
rrt->rrt_t = time(NULL);
|
||||||
if (aflag == 0 && (rtm->rtm_flags & RTF_STATIC))
|
if (aflag == 0 && (rtm->rtm_flags & RTF_STATIC))
|
||||||
rrt->rrt_t = 0; /* Don't age static routes */
|
rrt->rrt_t = 0; /* Don't age static routes */
|
||||||
|
if ((rtm->rtm_flags & (RTF_HOST|RTF_GATEWAY)) == RTF_HOST)
|
||||||
|
rrt->rrt_t = 0; /* Don't age non-gateway host routes */
|
||||||
np->rip6_tag = 0;
|
np->rip6_tag = 0;
|
||||||
np->rip6_metric = rtm->rtm_rmx.rmx_hopcount;
|
np->rip6_metric = rtm->rtm_rmx.rmx_hopcount;
|
||||||
if (np->rip6_metric < 1)
|
if (np->rip6_metric < 1)
|
||||||
@ -2672,11 +2678,8 @@ rt_entry(rtm, again)
|
|||||||
|
|
||||||
/* Check gateway */
|
/* Check gateway */
|
||||||
if (!IN6_IS_ADDR_LINKLOCAL(&rrt->rrt_gw) &&
|
if (!IN6_IS_ADDR_LINKLOCAL(&rrt->rrt_gw) &&
|
||||||
!IN6_IS_ADDR_LOOPBACK(&rrt->rrt_gw)
|
!IN6_IS_ADDR_LOOPBACK(&rrt->rrt_gw) &&
|
||||||
#ifdef __FreeBSD__
|
(rrt->rrt_flags & RTF_LOCAL) == 0) {
|
||||||
&& (rrt->rrt_flags & RTF_LOCAL) == 0
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
trace(0, "***** Gateway %s is not a link-local address.\n",
|
trace(0, "***** Gateway %s is not a link-local address.\n",
|
||||||
inet6_n2p(&rrt->rrt_gw));
|
inet6_n2p(&rrt->rrt_gw));
|
||||||
trace(0, "***** dest(%s) if(%s) -- Not optimized.\n",
|
trace(0, "***** dest(%s) if(%s) -- Not optimized.\n",
|
||||||
@ -3525,7 +3528,7 @@ setindex2ifc(idx, ifcp)
|
|||||||
int idx;
|
int idx;
|
||||||
struct ifc *ifcp;
|
struct ifc *ifcp;
|
||||||
{
|
{
|
||||||
int n;
|
int n, nsize;
|
||||||
struct ifc **p;
|
struct ifc **p;
|
||||||
|
|
||||||
if (!index2ifc) {
|
if (!index2ifc) {
|
||||||
@ -3539,17 +3542,18 @@ setindex2ifc(idx, ifcp)
|
|||||||
memset(index2ifc, 0, sizeof(*index2ifc) * nindex2ifc);
|
memset(index2ifc, 0, sizeof(*index2ifc) * nindex2ifc);
|
||||||
}
|
}
|
||||||
n = nindex2ifc;
|
n = nindex2ifc;
|
||||||
while (nindex2ifc <= idx)
|
for (nsize = nindex2ifc; nsize <= idx; nsize *= 2)
|
||||||
nindex2ifc *= 2;
|
;
|
||||||
if (n != nindex2ifc) {
|
if (n != nsize) {
|
||||||
p = (struct ifc **)realloc(index2ifc,
|
p = (struct ifc **)realloc(index2ifc,
|
||||||
sizeof(*index2ifc) * nindex2ifc);
|
sizeof(*index2ifc) * nsize);
|
||||||
if (p == NULL) {
|
if (p == NULL) {
|
||||||
fatal("realloc");
|
fatal("realloc");
|
||||||
/*NOTREACHED*/
|
/*NOTREACHED*/
|
||||||
}
|
}
|
||||||
memset(p + n, 0, sizeof(*index2ifc) * (nindex2ifc - n));
|
memset(p + n, 0, sizeof(*index2ifc) * (nindex2ifc - n));
|
||||||
index2ifc = p;
|
index2ifc = p;
|
||||||
|
nindex2ifc = nsize;
|
||||||
}
|
}
|
||||||
index2ifc[idx] = ifcp;
|
index2ifc[idx] = ifcp;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user