in6_rmx.c revision 185751
1139826Simp/*-
253541Sshin * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
353541Sshin * All rights reserved.
453541Sshin *
553541Sshin * Redistribution and use in source and binary forms, with or without
653541Sshin * modification, are permitted provided that the following conditions
753541Sshin * are met:
853541Sshin * 1. Redistributions of source code must retain the above copyright
953541Sshin *    notice, this list of conditions and the following disclaimer.
1053541Sshin * 2. Redistributions in binary form must reproduce the above copyright
1153541Sshin *    notice, this list of conditions and the following disclaimer in the
1253541Sshin *    documentation and/or other materials provided with the distribution.
1353541Sshin * 3. Neither the name of the project nor the names of its contributors
1453541Sshin *    may be used to endorse or promote products derived from this software
1553541Sshin *    without specific prior written permission.
1653541Sshin *
1753541Sshin * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1853541Sshin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1953541Sshin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2053541Sshin * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2153541Sshin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2253541Sshin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2353541Sshin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2453541Sshin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2553541Sshin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2653541Sshin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2753541Sshin * SUCH DAMAGE.
28174510Sobrien *
29174510Sobrien *	$KAME: in6_rmx.c,v 1.11 2001/07/26 06:53:16 jinmei Exp $
3053541Sshin */
3153541Sshin
32139826Simp/*-
3353541Sshin * Copyright 1994, 1995 Massachusetts Institute of Technology
3453541Sshin *
3553541Sshin * Permission to use, copy, modify, and distribute this software and
3653541Sshin * its documentation for any purpose and without fee is hereby
3753541Sshin * granted, provided that both the above copyright notice and this
3853541Sshin * permission notice appear in all copies, that both the above
3953541Sshin * copyright notice and this permission notice appear in all
4053541Sshin * supporting documentation, and that the name of M.I.T. not be used
4153541Sshin * in advertising or publicity pertaining to distribution of the
4253541Sshin * software without specific, written prior permission.  M.I.T. makes
4353541Sshin * no representations about the suitability of this software for any
4453541Sshin * purpose.  It is provided "as is" without express or implied
4553541Sshin * warranty.
4653541Sshin *
4753541Sshin * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''.  M.I.T. DISCLAIMS
4853541Sshin * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE,
4953541Sshin * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
5053541Sshin * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT
5153541Sshin * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
5253541Sshin * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
5353541Sshin * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
5453541Sshin * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
5553541Sshin * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
5653541Sshin * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
5753541Sshin * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
5853541Sshin * SUCH DAMAGE.
5953541Sshin *
6053541Sshin */
6153541Sshin
6253541Sshin/*
6353541Sshin * This code does two things necessary for the enhanced TCP metrics to
6453541Sshin * function in a useful manner:
6553541Sshin *  1) It marks all non-host routes as `cloning', thus ensuring that
6653541Sshin *     every actual reference to such a route actually gets turned
6753541Sshin *     into a reference to a host route to the specific destination
6853541Sshin *     requested.
6953541Sshin *  2) When such routes lose all their references, it arranges for them
7053541Sshin *     to be deleted in some random collection of circumstances, so that
7153541Sshin *     a large quantity of stale routing data is not kept in kernel memory
7253541Sshin *     indefinitely.  See in6_rtqtimo() below for the exact mechanism.
7353541Sshin */
7453541Sshin
75174510Sobrien#include <sys/cdefs.h>
76174510Sobrien__FBSDID("$FreeBSD: head/sys/netinet6/in6_rmx.c 185751 2008-12-08 00:28:21Z imp $");
77174510Sobrien
7853541Sshin#include <sys/param.h>
7953541Sshin#include <sys/systm.h>
8053541Sshin#include <sys/kernel.h>
81185751Simp#include <sys/lock.h>
8253541Sshin#include <sys/sysctl.h>
8353541Sshin#include <sys/queue.h>
8453541Sshin#include <sys/socket.h>
8553541Sshin#include <sys/socketvar.h>
8653541Sshin#include <sys/mbuf.h>
87185747Skmacy#include <sys/rwlock.h>
8853541Sshin#include <sys/syslog.h>
89120727Ssam#include <sys/callout.h>
90181803Sbz#include <sys/vimage.h>
9153541Sshin
9253541Sshin#include <net/if.h>
9353541Sshin#include <net/route.h>
94185571Sbz#include <net/vnet.h>
95185571Sbz
9653541Sshin#include <netinet/in.h>
9753541Sshin#include <netinet/ip_var.h>
9853541Sshin#include <netinet/in_var.h>
9953541Sshin
10062587Sitojun#include <netinet/ip6.h>
10153541Sshin#include <netinet6/ip6_var.h>
10253541Sshin
10362587Sitojun#include <netinet/icmp6.h>
104121283Sume#include <netinet6/nd6.h>
105185571Sbz#include <netinet6/vinet6.h>
10653541Sshin
10753541Sshin#include <netinet/tcp.h>
10853541Sshin#include <netinet/tcp_seq.h>
10953541Sshin#include <netinet/tcp_timer.h>
11053541Sshin#include <netinet/tcp_var.h>
11153541Sshin
112175162Sobrienextern int	in6_inithead(void **head, int off);
11353541Sshin
11462587Sitojun#define RTPRF_OURS		RTF_PROTO3	/* set on routes we manage */
11553541Sshin
11653541Sshin/*
11753541Sshin * Do what we need to do when inserting a route.
11853541Sshin */
11953541Sshinstatic struct radix_node *
12053541Sshinin6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
121171260Sdelphij    struct radix_node *treenodes)
12253541Sshin{
12353541Sshin	struct rtentry *rt = (struct rtentry *)treenodes;
12453541Sshin	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)rt_key(rt);
12553541Sshin	struct radix_node *ret;
12653541Sshin
12753541Sshin	if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
12853541Sshin		rt->rt_flags |= RTF_MULTICAST;
12953541Sshin
13053541Sshin	/*
13153541Sshin	 * A little bit of help for both IPv6 output and input:
13253541Sshin	 *   For local addresses, we make sure that RTF_LOCAL is set,
13353541Sshin	 *   with the thought that this might one day be used to speed up
13453541Sshin	 *   ip_input().
13553541Sshin	 *
13653541Sshin	 * We also mark routes to multicast addresses as such, because
13753541Sshin	 * it's easy to do and might be useful (but this is much more
13853541Sshin	 * dubious since it's so easy to inspect the address).  (This
13953541Sshin	 * is done above.)
14053541Sshin	 *
14153541Sshin	 * XXX
14253541Sshin	 * should elaborate the code.
14353541Sshin	 */
14453541Sshin	if (rt->rt_flags & RTF_HOST) {
14553541Sshin		if (IN6_ARE_ADDR_EQUAL(&satosin6(rt->rt_ifa->ifa_addr)
14653541Sshin					->sin6_addr,
14753541Sshin				       &sin6->sin6_addr)) {
14853541Sshin			rt->rt_flags |= RTF_LOCAL;
14953541Sshin		}
15053541Sshin	}
15153541Sshin
152122922Sandre	if (!rt->rt_rmx.rmx_mtu && rt->rt_ifp)
153121283Sume		rt->rt_rmx.rmx_mtu = IN6_LINKMTU(rt->rt_ifp);
15453541Sshin
15553541Sshin	ret = rn_addroute(v_arg, n_arg, head, treenodes);
15653541Sshin	if (ret == NULL && rt->rt_flags & RTF_HOST) {
15753541Sshin		struct rtentry *rt2;
15853541Sshin		/*
15953541Sshin		 * We are trying to add a host route, but can't.
16053541Sshin		 * Find out if it is because of an
16153541Sshin		 * ARP entry and delete it if so.
16253541Sshin		 */
163122921Sandre		rt2 = rtalloc1((struct sockaddr *)sin6, 0, RTF_CLONING);
16453541Sshin		if (rt2) {
16553541Sshin			if (rt2->rt_flags & RTF_LLINFO &&
16653541Sshin				rt2->rt_flags & RTF_HOST &&
16753541Sshin				rt2->rt_gateway &&
16853541Sshin				rt2->rt_gateway->sa_family == AF_LINK) {
169121770Ssam				rtexpunge(rt2);
170121770Ssam				RTFREE_LOCKED(rt2);
17153541Sshin				ret = rn_addroute(v_arg, n_arg, head,
17253541Sshin					treenodes);
173121770Ssam			} else
174121770Ssam				RTFREE_LOCKED(rt2);
17553541Sshin		}
17653541Sshin	} else if (ret == NULL && rt->rt_flags & RTF_CLONING) {
17753541Sshin		struct rtentry *rt2;
17853541Sshin		/*
17953541Sshin		 * We are trying to add a net route, but can't.
18053541Sshin		 * The following case should be allowed, so we'll make a
18153541Sshin		 * special check for this:
18253541Sshin		 *	Two IPv6 addresses with the same prefix is assigned
18353541Sshin		 *	to a single interrface.
18453541Sshin		 *	# ifconfig if0 inet6 3ffe:0501::1 prefix 64 alias (*1)
18553541Sshin		 *	# ifconfig if0 inet6 3ffe:0501::2 prefix 64 alias (*2)
18653541Sshin		 *	In this case, (*1) and (*2) want to add the same
18753541Sshin		 *	net route entry, 3ffe:0501:: -> if0.
18853541Sshin		 *	This case should not raise an error.
18953541Sshin		 */
190122921Sandre		rt2 = rtalloc1((struct sockaddr *)sin6, 0, RTF_CLONING);
19153541Sshin		if (rt2) {
19253541Sshin			if ((rt2->rt_flags & (RTF_CLONING|RTF_HOST|RTF_GATEWAY))
19353541Sshin					== RTF_CLONING
19453541Sshin			 && rt2->rt_gateway
19553541Sshin			 && rt2->rt_gateway->sa_family == AF_LINK
19653541Sshin			 && rt2->rt_ifp == rt->rt_ifp) {
19753541Sshin				ret = rt2->rt_nodes;
19853541Sshin			}
199120727Ssam			RTFREE_LOCKED(rt2);
20053541Sshin		}
20153541Sshin	}
20253541Sshin	return ret;
20353541Sshin}
20453541Sshin
20553541Sshin/*
20653541Sshin * This code is the inverse of in6_clsroute: on first reference, if we
20753541Sshin * were managing the route, stop doing so and set the expiration timer
20853541Sshin * back off again.
20953541Sshin */
21053541Sshinstatic struct radix_node *
21153541Sshinin6_matroute(void *v_arg, struct radix_node_head *head)
21253541Sshin{
21353541Sshin	struct radix_node *rn = rn_match(v_arg, head);
21453541Sshin	struct rtentry *rt = (struct rtentry *)rn;
21553541Sshin
21653541Sshin	if (rt && rt->rt_refcnt == 0) { /* this is first reference */
21753541Sshin		if (rt->rt_flags & RTPRF_OURS) {
21853541Sshin			rt->rt_flags &= ~RTPRF_OURS;
21953541Sshin			rt->rt_rmx.rmx_expire = 0;
22053541Sshin		}
22153541Sshin	}
22253541Sshin	return rn;
22353541Sshin}
22453541Sshin
22562604SitojunSYSCTL_DECL(_net_inet6_ip6);
22662604Sitojun
227185088Szec#ifdef VIMAGE_GLOBALS
228185088Szecstatic int rtq_reallyold6;
229185088Szecstatic int rtq_minreallyold6;
230185088Szecstatic int rtq_toomany6;
231185088Szec#endif
232185088Szec
233185348SzecSYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTEXPIRE,
234185348Szec    rtexpire, CTLFLAG_RW, rtq_reallyold6 , 0, "");
235120913Sume
236185348SzecSYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMINEXPIRE,
237185348Szec    rtminexpire, CTLFLAG_RW, rtq_minreallyold6 , 0, "");
238120913Sume
239185348SzecSYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMAXCACHE,
240185348Szec    rtmaxcache, CTLFLAG_RW, rtq_toomany6 , 0, "");
24153541Sshin
242120913Sume
24353541Sshin/*
24453541Sshin * On last reference drop, mark the route as belong to us so that it can be
24553541Sshin * timed out.
24653541Sshin */
24753541Sshinstatic void
24853541Sshinin6_clsroute(struct radix_node *rn, struct radix_node_head *head)
24953541Sshin{
250183550Szec	INIT_VNET_INET6(curvnet);
25153541Sshin	struct rtentry *rt = (struct rtentry *)rn;
25253541Sshin
253120727Ssam	RT_LOCK_ASSERT(rt);
254120727Ssam
25553541Sshin	if (!(rt->rt_flags & RTF_UP))
25653541Sshin		return;		/* prophylactic measures */
25753541Sshin
25853541Sshin	if ((rt->rt_flags & (RTF_LLINFO | RTF_HOST)) != RTF_HOST)
25953541Sshin		return;
26053541Sshin
261108250Shsu	if ((rt->rt_flags & (RTF_WASCLONED | RTPRF_OURS)) != RTF_WASCLONED)
26253541Sshin		return;
26353541Sshin
26453541Sshin	/*
26553541Sshin	 * As requested by David Greenman:
266181832Sbz	 * If rtq_reallyold6 is 0, just delete the route without
26753541Sshin	 * waiting for a timeout cycle to kill it.
26853541Sshin	 */
269181832Sbz	if (V_rtq_reallyold6 != 0) {
27053541Sshin		rt->rt_flags |= RTPRF_OURS;
271181832Sbz		rt->rt_rmx.rmx_expire = time_uptime + V_rtq_reallyold6;
27253541Sshin	} else {
273121770Ssam		rtexpunge(rt);
27453541Sshin	}
27553541Sshin}
27653541Sshin
27753541Sshinstruct rtqk_arg {
27853541Sshin	struct radix_node_head *rnh;
27953541Sshin	int mode;
28053541Sshin	int updating;
28153541Sshin	int draining;
28253541Sshin	int killed;
28353541Sshin	int found;
28453541Sshin	time_t nextstop;
28553541Sshin};
28653541Sshin
28753541Sshin/*
28853541Sshin * Get rid of old routes.  When draining, this deletes everything, even when
28953541Sshin * the timeout is not expired yet.  When updating, this makes sure that
290181832Sbz * nothing has a timeout longer than the current value of rtq_reallyold6.
29153541Sshin */
29253541Sshinstatic int
29353541Sshinin6_rtqkill(struct radix_node *rn, void *rock)
29453541Sshin{
295183550Szec	INIT_VNET_INET6(curvnet);
29653541Sshin	struct rtqk_arg *ap = rock;
29753541Sshin	struct rtentry *rt = (struct rtentry *)rn;
29853541Sshin	int err;
29953541Sshin
30053541Sshin	if (rt->rt_flags & RTPRF_OURS) {
30153541Sshin		ap->found++;
30253541Sshin
303150351Sandre		if (ap->draining || rt->rt_rmx.rmx_expire <= time_uptime) {
30453541Sshin			if (rt->rt_refcnt > 0)
30553541Sshin				panic("rtqkill route really not free");
30653541Sshin
30753541Sshin			err = rtrequest(RTM_DELETE,
30853541Sshin					(struct sockaddr *)rt_key(rt),
30953541Sshin					rt->rt_gateway, rt_mask(rt),
31053541Sshin					rt->rt_flags, 0);
31153541Sshin			if (err) {
31253541Sshin				log(LOG_WARNING, "in6_rtqkill: error %d", err);
31353541Sshin			} else {
31453541Sshin				ap->killed++;
31553541Sshin			}
31653541Sshin		} else {
31753541Sshin			if (ap->updating
318150351Sandre			   && (rt->rt_rmx.rmx_expire - time_uptime
319181832Sbz			       > V_rtq_reallyold6)) {
320150351Sandre				rt->rt_rmx.rmx_expire = time_uptime
321181832Sbz					+ V_rtq_reallyold6;
32253541Sshin			}
32353541Sshin			ap->nextstop = lmin(ap->nextstop,
32453541Sshin					    rt->rt_rmx.rmx_expire);
32553541Sshin		}
32653541Sshin	}
32753541Sshin
32853541Sshin	return 0;
32953541Sshin}
33053541Sshin
33153541Sshin#define RTQ_TIMEOUT	60*10	/* run no less than once every ten minutes */
332185088Szec#ifdef VIMAGE_GLOBALS
333185088Szecstatic int rtq_timeout6;
334180088Skanstatic struct callout rtq_timer6;
335185088Szec#endif
33653541Sshin
33753541Sshinstatic void
33853541Sshinin6_rtqtimo(void *rock)
33953541Sshin{
340183550Szec	CURVNET_SET_QUIET((struct vnet *) rock);
341183550Szec	INIT_VNET_NET((struct vnet *) rock);
342183550Szec	INIT_VNET_INET6((struct vnet *) rock);
34353541Sshin	struct radix_node_head *rnh = rock;
34453541Sshin	struct rtqk_arg arg;
34553541Sshin	struct timeval atv;
34653541Sshin	static time_t last_adjusted_timeout = 0;
34753541Sshin
34853541Sshin	arg.found = arg.killed = 0;
34953541Sshin	arg.rnh = rnh;
350181803Sbz	arg.nextstop = time_uptime + V_rtq_timeout6;
35153541Sshin	arg.draining = arg.updating = 0;
352108250Shsu	RADIX_NODE_HEAD_LOCK(rnh);
35353541Sshin	rnh->rnh_walktree(rnh, in6_rtqkill, &arg);
354108250Shsu	RADIX_NODE_HEAD_UNLOCK(rnh);
35553541Sshin
35653541Sshin	/*
35753541Sshin	 * Attempt to be somewhat dynamic about this:
35853541Sshin	 * If there are ``too many'' routes sitting around taking up space,
35953541Sshin	 * then crank down the timeout, and see if we can't make some more
36053541Sshin	 * go away.  However, we make sure that we will never adjust more
361180084Sjulian	 * than once in rtq_timeout6 seconds, to keep from cranking down too
36253541Sshin	 * hard.
36353541Sshin	 */
364181832Sbz	if ((arg.found - arg.killed > V_rtq_toomany6)
365181803Sbz	   && (time_uptime - last_adjusted_timeout >= V_rtq_timeout6)
366181832Sbz	   && V_rtq_reallyold6 > V_rtq_minreallyold6) {
367181832Sbz		V_rtq_reallyold6 = 2*V_rtq_reallyold6 / 3;
368181832Sbz		if (V_rtq_reallyold6 < V_rtq_minreallyold6) {
369181832Sbz			V_rtq_reallyold6 = V_rtq_minreallyold6;
37053541Sshin		}
37153541Sshin
372160123Soleg		last_adjusted_timeout = time_uptime;
37353541Sshin#ifdef DIAGNOSTIC
374181832Sbz		log(LOG_DEBUG, "in6_rtqtimo: adjusted rtq_reallyold6 to %d",
375181832Sbz		    V_rtq_reallyold6);
37653541Sshin#endif
37753541Sshin		arg.found = arg.killed = 0;
37853541Sshin		arg.updating = 1;
379108250Shsu		RADIX_NODE_HEAD_LOCK(rnh);
38053541Sshin		rnh->rnh_walktree(rnh, in6_rtqkill, &arg);
381108250Shsu		RADIX_NODE_HEAD_UNLOCK(rnh);
38253541Sshin	}
38353541Sshin
38453541Sshin	atv.tv_usec = 0;
385160123Soleg	atv.tv_sec = arg.nextstop - time_uptime;
386181803Sbz	callout_reset(&V_rtq_timer6, tvtohz(&atv), in6_rtqtimo, rock);
387183550Szec	CURVNET_RESTORE();
38853541Sshin}
38953541Sshin
39053541Sshin/*
39153541Sshin * Age old PMTUs.
39253541Sshin */
39353541Sshinstruct mtuex_arg {
39453541Sshin	struct radix_node_head *rnh;
39553541Sshin	time_t nextstop;
39653541Sshin};
397185088Szec#ifdef VIMAGE_GLOBALS
398120727Ssamstatic struct callout rtq_mtutimer;
399185088Szec#endif
40053541Sshin
40153541Sshinstatic int
40253541Sshinin6_mtuexpire(struct radix_node *rn, void *rock)
40353541Sshin{
40453541Sshin	struct rtentry *rt = (struct rtentry *)rn;
40553541Sshin	struct mtuex_arg *ap = rock;
40653541Sshin
40753541Sshin	/* sanity */
40853541Sshin	if (!rt)
40953541Sshin		panic("rt == NULL in in6_mtuexpire");
41053541Sshin
41153541Sshin	if (rt->rt_rmx.rmx_expire && !(rt->rt_flags & RTF_PROBEMTU)) {
412150351Sandre		if (rt->rt_rmx.rmx_expire <= time_uptime) {
41353541Sshin			rt->rt_flags |= RTF_PROBEMTU;
41453541Sshin		} else {
41553541Sshin			ap->nextstop = lmin(ap->nextstop,
41653541Sshin					rt->rt_rmx.rmx_expire);
41753541Sshin		}
41853541Sshin	}
41953541Sshin
42053541Sshin	return 0;
42153541Sshin}
42253541Sshin
42353541Sshin#define	MTUTIMO_DEFAULT	(60*1)
42453541Sshin
42553541Sshinstatic void
42653541Sshinin6_mtutimo(void *rock)
42753541Sshin{
428183550Szec	CURVNET_SET_QUIET((struct vnet *) rock);
429183550Szec	INIT_VNET_NET((struct vnet *) rock);
430183550Szec	INIT_VNET_INET6((struct vnet *) rock);
43153541Sshin	struct radix_node_head *rnh = rock;
43253541Sshin	struct mtuex_arg arg;
43353541Sshin	struct timeval atv;
43453541Sshin
43553541Sshin	arg.rnh = rnh;
436160123Soleg	arg.nextstop = time_uptime + MTUTIMO_DEFAULT;
437108250Shsu	RADIX_NODE_HEAD_LOCK(rnh);
43853541Sshin	rnh->rnh_walktree(rnh, in6_mtuexpire, &arg);
439108250Shsu	RADIX_NODE_HEAD_UNLOCK(rnh);
44053541Sshin
44153541Sshin	atv.tv_usec = 0;
442160123Soleg	atv.tv_sec = arg.nextstop - time_uptime;
443136184Ssuz	if (atv.tv_sec < 0) {
44453541Sshin		printf("invalid mtu expiration time on routing table\n");
445160123Soleg		arg.nextstop = time_uptime + 30;	/* last resort */
446160123Soleg		atv.tv_sec = 30;
44753541Sshin	}
448181803Sbz	callout_reset(&V_rtq_mtutimer, tvtohz(&atv), in6_mtutimo, rock);
449183550Szec	CURVNET_RESTORE();
45053541Sshin}
45153541Sshin
45262587Sitojun#if 0
45362587Sitojunvoid
454171259Sdelphijin6_rtqdrain(void)
45562587Sitojun{
456183550Szec	INIT_VNET_NET(curvnet);
457181803Sbz	struct radix_node_head *rnh = V_rt_tables[AF_INET6];
45862587Sitojun	struct rtqk_arg arg;
459120727Ssam
46062587Sitojun	arg.found = arg.killed = 0;
46162587Sitojun	arg.rnh = rnh;
46262587Sitojun	arg.nextstop = 0;
46362587Sitojun	arg.draining = 1;
46462587Sitojun	arg.updating = 0;
465108250Shsu	RADIX_NODE_HEAD_LOCK(rnh);
46662587Sitojun	rnh->rnh_walktree(rnh, in6_rtqkill, &arg);
467108250Shsu	RADIX_NODE_HEAD_UNLOCK(rnh);
46862587Sitojun}
46962587Sitojun#endif
47062587Sitojun
47153541Sshin/*
47253541Sshin * Initialize our routing tree.
473178888Sjulian * XXX MRT When off == 0, we are being called from vfs_export.c
474178888Sjulian * so just set up their table and leave. (we know what the correct
475178888Sjulian * value should be so just use that).. FIX AFTER RELENG_7 is MFC'd
476178888Sjulian * see also comments in in_inithead() vfs_export.c and domain.h
47753541Sshin */
47853541Sshinint
47953541Sshinin6_inithead(void **head, int off)
48053541Sshin{
481183550Szec	INIT_VNET_INET6(curvnet);
48253541Sshin	struct radix_node_head *rnh;
48353541Sshin
484178888Sjulian	if (!rn_inithead(head, offsetof(struct sockaddr_in6, sin6_addr) << 3))
485178888Sjulian		return 0;		/* See above */
48653541Sshin
487178888Sjulian	if (off == 0)		/* See above */
488178888Sjulian		return 1;	/* only do the rest for the real thing */
48953541Sshin
490185088Szec	V_rtq_reallyold6 = 60*60; /* one hour is ``really old'' */
491185088Szec	V_rtq_minreallyold6 = 10; /* never automatically crank down to less */
492185088Szec	V_rtq_toomany6 = 128;	  /* 128 cached routes is ``too many'' */
493185088Szec	V_rtq_timeout6 = RTQ_TIMEOUT;
494185088Szec
49553541Sshin	rnh = *head;
49653541Sshin	rnh->rnh_addaddr = in6_addroute;
49753541Sshin	rnh->rnh_matchaddr = in6_matroute;
49853541Sshin	rnh->rnh_close = in6_clsroute;
499181803Sbz	callout_init(&V_rtq_timer6, CALLOUT_MPSAFE);
50053541Sshin	in6_rtqtimo(rnh);	/* kick off timeout first time */
501181803Sbz	callout_init(&V_rtq_mtutimer, CALLOUT_MPSAFE);
50253541Sshin	in6_mtutimo(rnh);	/* kick off timeout first time */
50353541Sshin	return 1;
50453541Sshin}
505