in6_rmx.c revision 185747
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 185747 2008-12-07 21:15:43Z kmacy $");
77174510Sobrien
7853541Sshin#include <sys/param.h>
7953541Sshin#include <sys/systm.h>
8053541Sshin#include <sys/kernel.h>
8153541Sshin#include <sys/sysctl.h>
8253541Sshin#include <sys/queue.h>
8353541Sshin#include <sys/socket.h>
8453541Sshin#include <sys/socketvar.h>
8553541Sshin#include <sys/mbuf.h>
86185747Skmacy#include <sys/rwlock.h>
8753541Sshin#include <sys/syslog.h>
88120727Ssam#include <sys/callout.h>
89181803Sbz#include <sys/vimage.h>
9053541Sshin
9153541Sshin#include <net/if.h>
9253541Sshin#include <net/route.h>
93185571Sbz#include <net/vnet.h>
94185571Sbz
9553541Sshin#include <netinet/in.h>
9653541Sshin#include <netinet/ip_var.h>
9753541Sshin#include <netinet/in_var.h>
9853541Sshin
9962587Sitojun#include <netinet/ip6.h>
10053541Sshin#include <netinet6/ip6_var.h>
10153541Sshin
10262587Sitojun#include <netinet/icmp6.h>
103121283Sume#include <netinet6/nd6.h>
104185571Sbz#include <netinet6/vinet6.h>
10553541Sshin
10653541Sshin#include <netinet/tcp.h>
10753541Sshin#include <netinet/tcp_seq.h>
10853541Sshin#include <netinet/tcp_timer.h>
10953541Sshin#include <netinet/tcp_var.h>
11053541Sshin
111175162Sobrienextern int	in6_inithead(void **head, int off);
11253541Sshin
11362587Sitojun#define RTPRF_OURS		RTF_PROTO3	/* set on routes we manage */
11453541Sshin
11553541Sshin/*
11653541Sshin * Do what we need to do when inserting a route.
11753541Sshin */
11853541Sshinstatic struct radix_node *
11953541Sshinin6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head,
120171260Sdelphij    struct radix_node *treenodes)
12153541Sshin{
12253541Sshin	struct rtentry *rt = (struct rtentry *)treenodes;
12353541Sshin	struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)rt_key(rt);
12453541Sshin	struct radix_node *ret;
12553541Sshin
12653541Sshin	if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr))
12753541Sshin		rt->rt_flags |= RTF_MULTICAST;
12853541Sshin
12953541Sshin	/*
13053541Sshin	 * A little bit of help for both IPv6 output and input:
13153541Sshin	 *   For local addresses, we make sure that RTF_LOCAL is set,
13253541Sshin	 *   with the thought that this might one day be used to speed up
13353541Sshin	 *   ip_input().
13453541Sshin	 *
13553541Sshin	 * We also mark routes to multicast addresses as such, because
13653541Sshin	 * it's easy to do and might be useful (but this is much more
13753541Sshin	 * dubious since it's so easy to inspect the address).  (This
13853541Sshin	 * is done above.)
13953541Sshin	 *
14053541Sshin	 * XXX
14153541Sshin	 * should elaborate the code.
14253541Sshin	 */
14353541Sshin	if (rt->rt_flags & RTF_HOST) {
14453541Sshin		if (IN6_ARE_ADDR_EQUAL(&satosin6(rt->rt_ifa->ifa_addr)
14553541Sshin					->sin6_addr,
14653541Sshin				       &sin6->sin6_addr)) {
14753541Sshin			rt->rt_flags |= RTF_LOCAL;
14853541Sshin		}
14953541Sshin	}
15053541Sshin
151122922Sandre	if (!rt->rt_rmx.rmx_mtu && rt->rt_ifp)
152121283Sume		rt->rt_rmx.rmx_mtu = IN6_LINKMTU(rt->rt_ifp);
15353541Sshin
15453541Sshin	ret = rn_addroute(v_arg, n_arg, head, treenodes);
15553541Sshin	if (ret == NULL && rt->rt_flags & RTF_HOST) {
15653541Sshin		struct rtentry *rt2;
15753541Sshin		/*
15853541Sshin		 * We are trying to add a host route, but can't.
15953541Sshin		 * Find out if it is because of an
16053541Sshin		 * ARP entry and delete it if so.
16153541Sshin		 */
162122921Sandre		rt2 = rtalloc1((struct sockaddr *)sin6, 0, RTF_CLONING);
16353541Sshin		if (rt2) {
16453541Sshin			if (rt2->rt_flags & RTF_LLINFO &&
16553541Sshin				rt2->rt_flags & RTF_HOST &&
16653541Sshin				rt2->rt_gateway &&
16753541Sshin				rt2->rt_gateway->sa_family == AF_LINK) {
168121770Ssam				rtexpunge(rt2);
169121770Ssam				RTFREE_LOCKED(rt2);
17053541Sshin				ret = rn_addroute(v_arg, n_arg, head,
17153541Sshin					treenodes);
172121770Ssam			} else
173121770Ssam				RTFREE_LOCKED(rt2);
17453541Sshin		}
17553541Sshin	} else if (ret == NULL && rt->rt_flags & RTF_CLONING) {
17653541Sshin		struct rtentry *rt2;
17753541Sshin		/*
17853541Sshin		 * We are trying to add a net route, but can't.
17953541Sshin		 * The following case should be allowed, so we'll make a
18053541Sshin		 * special check for this:
18153541Sshin		 *	Two IPv6 addresses with the same prefix is assigned
18253541Sshin		 *	to a single interrface.
18353541Sshin		 *	# ifconfig if0 inet6 3ffe:0501::1 prefix 64 alias (*1)
18453541Sshin		 *	# ifconfig if0 inet6 3ffe:0501::2 prefix 64 alias (*2)
18553541Sshin		 *	In this case, (*1) and (*2) want to add the same
18653541Sshin		 *	net route entry, 3ffe:0501:: -> if0.
18753541Sshin		 *	This case should not raise an error.
18853541Sshin		 */
189122921Sandre		rt2 = rtalloc1((struct sockaddr *)sin6, 0, RTF_CLONING);
19053541Sshin		if (rt2) {
19153541Sshin			if ((rt2->rt_flags & (RTF_CLONING|RTF_HOST|RTF_GATEWAY))
19253541Sshin					== RTF_CLONING
19353541Sshin			 && rt2->rt_gateway
19453541Sshin			 && rt2->rt_gateway->sa_family == AF_LINK
19553541Sshin			 && rt2->rt_ifp == rt->rt_ifp) {
19653541Sshin				ret = rt2->rt_nodes;
19753541Sshin			}
198120727Ssam			RTFREE_LOCKED(rt2);
19953541Sshin		}
20053541Sshin	}
20153541Sshin	return ret;
20253541Sshin}
20353541Sshin
20453541Sshin/*
20553541Sshin * This code is the inverse of in6_clsroute: on first reference, if we
20653541Sshin * were managing the route, stop doing so and set the expiration timer
20753541Sshin * back off again.
20853541Sshin */
20953541Sshinstatic struct radix_node *
21053541Sshinin6_matroute(void *v_arg, struct radix_node_head *head)
21153541Sshin{
21253541Sshin	struct radix_node *rn = rn_match(v_arg, head);
21353541Sshin	struct rtentry *rt = (struct rtentry *)rn;
21453541Sshin
21553541Sshin	if (rt && rt->rt_refcnt == 0) { /* this is first reference */
21653541Sshin		if (rt->rt_flags & RTPRF_OURS) {
21753541Sshin			rt->rt_flags &= ~RTPRF_OURS;
21853541Sshin			rt->rt_rmx.rmx_expire = 0;
21953541Sshin		}
22053541Sshin	}
22153541Sshin	return rn;
22253541Sshin}
22353541Sshin
22462604SitojunSYSCTL_DECL(_net_inet6_ip6);
22562604Sitojun
226185088Szec#ifdef VIMAGE_GLOBALS
227185088Szecstatic int rtq_reallyold6;
228185088Szecstatic int rtq_minreallyold6;
229185088Szecstatic int rtq_toomany6;
230185088Szec#endif
231185088Szec
232185348SzecSYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTEXPIRE,
233185348Szec    rtexpire, CTLFLAG_RW, rtq_reallyold6 , 0, "");
234120913Sume
235185348SzecSYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMINEXPIRE,
236185348Szec    rtminexpire, CTLFLAG_RW, rtq_minreallyold6 , 0, "");
237120913Sume
238185348SzecSYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMAXCACHE,
239185348Szec    rtmaxcache, CTLFLAG_RW, rtq_toomany6 , 0, "");
24053541Sshin
241120913Sume
24253541Sshin/*
24353541Sshin * On last reference drop, mark the route as belong to us so that it can be
24453541Sshin * timed out.
24553541Sshin */
24653541Sshinstatic void
24753541Sshinin6_clsroute(struct radix_node *rn, struct radix_node_head *head)
24853541Sshin{
249183550Szec	INIT_VNET_INET6(curvnet);
25053541Sshin	struct rtentry *rt = (struct rtentry *)rn;
25153541Sshin
252120727Ssam	RT_LOCK_ASSERT(rt);
253120727Ssam
25453541Sshin	if (!(rt->rt_flags & RTF_UP))
25553541Sshin		return;		/* prophylactic measures */
25653541Sshin
25753541Sshin	if ((rt->rt_flags & (RTF_LLINFO | RTF_HOST)) != RTF_HOST)
25853541Sshin		return;
25953541Sshin
260108250Shsu	if ((rt->rt_flags & (RTF_WASCLONED | RTPRF_OURS)) != RTF_WASCLONED)
26153541Sshin		return;
26253541Sshin
26353541Sshin	/*
26453541Sshin	 * As requested by David Greenman:
265181832Sbz	 * If rtq_reallyold6 is 0, just delete the route without
26653541Sshin	 * waiting for a timeout cycle to kill it.
26753541Sshin	 */
268181832Sbz	if (V_rtq_reallyold6 != 0) {
26953541Sshin		rt->rt_flags |= RTPRF_OURS;
270181832Sbz		rt->rt_rmx.rmx_expire = time_uptime + V_rtq_reallyold6;
27153541Sshin	} else {
272121770Ssam		rtexpunge(rt);
27353541Sshin	}
27453541Sshin}
27553541Sshin
27653541Sshinstruct rtqk_arg {
27753541Sshin	struct radix_node_head *rnh;
27853541Sshin	int mode;
27953541Sshin	int updating;
28053541Sshin	int draining;
28153541Sshin	int killed;
28253541Sshin	int found;
28353541Sshin	time_t nextstop;
28453541Sshin};
28553541Sshin
28653541Sshin/*
28753541Sshin * Get rid of old routes.  When draining, this deletes everything, even when
28853541Sshin * the timeout is not expired yet.  When updating, this makes sure that
289181832Sbz * nothing has a timeout longer than the current value of rtq_reallyold6.
29053541Sshin */
29153541Sshinstatic int
29253541Sshinin6_rtqkill(struct radix_node *rn, void *rock)
29353541Sshin{
294183550Szec	INIT_VNET_INET6(curvnet);
29553541Sshin	struct rtqk_arg *ap = rock;
29653541Sshin	struct rtentry *rt = (struct rtentry *)rn;
29753541Sshin	int err;
29853541Sshin
29953541Sshin	if (rt->rt_flags & RTPRF_OURS) {
30053541Sshin		ap->found++;
30153541Sshin
302150351Sandre		if (ap->draining || rt->rt_rmx.rmx_expire <= time_uptime) {
30353541Sshin			if (rt->rt_refcnt > 0)
30453541Sshin				panic("rtqkill route really not free");
30553541Sshin
30653541Sshin			err = rtrequest(RTM_DELETE,
30753541Sshin					(struct sockaddr *)rt_key(rt),
30853541Sshin					rt->rt_gateway, rt_mask(rt),
30953541Sshin					rt->rt_flags, 0);
31053541Sshin			if (err) {
31153541Sshin				log(LOG_WARNING, "in6_rtqkill: error %d", err);
31253541Sshin			} else {
31353541Sshin				ap->killed++;
31453541Sshin			}
31553541Sshin		} else {
31653541Sshin			if (ap->updating
317150351Sandre			   && (rt->rt_rmx.rmx_expire - time_uptime
318181832Sbz			       > V_rtq_reallyold6)) {
319150351Sandre				rt->rt_rmx.rmx_expire = time_uptime
320181832Sbz					+ V_rtq_reallyold6;
32153541Sshin			}
32253541Sshin			ap->nextstop = lmin(ap->nextstop,
32353541Sshin					    rt->rt_rmx.rmx_expire);
32453541Sshin		}
32553541Sshin	}
32653541Sshin
32753541Sshin	return 0;
32853541Sshin}
32953541Sshin
33053541Sshin#define RTQ_TIMEOUT	60*10	/* run no less than once every ten minutes */
331185088Szec#ifdef VIMAGE_GLOBALS
332185088Szecstatic int rtq_timeout6;
333180088Skanstatic struct callout rtq_timer6;
334185088Szec#endif
33553541Sshin
33653541Sshinstatic void
33753541Sshinin6_rtqtimo(void *rock)
33853541Sshin{
339183550Szec	CURVNET_SET_QUIET((struct vnet *) rock);
340183550Szec	INIT_VNET_NET((struct vnet *) rock);
341183550Szec	INIT_VNET_INET6((struct vnet *) rock);
34253541Sshin	struct radix_node_head *rnh = rock;
34353541Sshin	struct rtqk_arg arg;
34453541Sshin	struct timeval atv;
34553541Sshin	static time_t last_adjusted_timeout = 0;
34653541Sshin
34753541Sshin	arg.found = arg.killed = 0;
34853541Sshin	arg.rnh = rnh;
349181803Sbz	arg.nextstop = time_uptime + V_rtq_timeout6;
35053541Sshin	arg.draining = arg.updating = 0;
351108250Shsu	RADIX_NODE_HEAD_LOCK(rnh);
35253541Sshin	rnh->rnh_walktree(rnh, in6_rtqkill, &arg);
353108250Shsu	RADIX_NODE_HEAD_UNLOCK(rnh);
35453541Sshin
35553541Sshin	/*
35653541Sshin	 * Attempt to be somewhat dynamic about this:
35753541Sshin	 * If there are ``too many'' routes sitting around taking up space,
35853541Sshin	 * then crank down the timeout, and see if we can't make some more
35953541Sshin	 * go away.  However, we make sure that we will never adjust more
360180084Sjulian	 * than once in rtq_timeout6 seconds, to keep from cranking down too
36153541Sshin	 * hard.
36253541Sshin	 */
363181832Sbz	if ((arg.found - arg.killed > V_rtq_toomany6)
364181803Sbz	   && (time_uptime - last_adjusted_timeout >= V_rtq_timeout6)
365181832Sbz	   && V_rtq_reallyold6 > V_rtq_minreallyold6) {
366181832Sbz		V_rtq_reallyold6 = 2*V_rtq_reallyold6 / 3;
367181832Sbz		if (V_rtq_reallyold6 < V_rtq_minreallyold6) {
368181832Sbz			V_rtq_reallyold6 = V_rtq_minreallyold6;
36953541Sshin		}
37053541Sshin
371160123Soleg		last_adjusted_timeout = time_uptime;
37253541Sshin#ifdef DIAGNOSTIC
373181832Sbz		log(LOG_DEBUG, "in6_rtqtimo: adjusted rtq_reallyold6 to %d",
374181832Sbz		    V_rtq_reallyold6);
37553541Sshin#endif
37653541Sshin		arg.found = arg.killed = 0;
37753541Sshin		arg.updating = 1;
378108250Shsu		RADIX_NODE_HEAD_LOCK(rnh);
37953541Sshin		rnh->rnh_walktree(rnh, in6_rtqkill, &arg);
380108250Shsu		RADIX_NODE_HEAD_UNLOCK(rnh);
38153541Sshin	}
38253541Sshin
38353541Sshin	atv.tv_usec = 0;
384160123Soleg	atv.tv_sec = arg.nextstop - time_uptime;
385181803Sbz	callout_reset(&V_rtq_timer6, tvtohz(&atv), in6_rtqtimo, rock);
386183550Szec	CURVNET_RESTORE();
38753541Sshin}
38853541Sshin
38953541Sshin/*
39053541Sshin * Age old PMTUs.
39153541Sshin */
39253541Sshinstruct mtuex_arg {
39353541Sshin	struct radix_node_head *rnh;
39453541Sshin	time_t nextstop;
39553541Sshin};
396185088Szec#ifdef VIMAGE_GLOBALS
397120727Ssamstatic struct callout rtq_mtutimer;
398185088Szec#endif
39953541Sshin
40053541Sshinstatic int
40153541Sshinin6_mtuexpire(struct radix_node *rn, void *rock)
40253541Sshin{
40353541Sshin	struct rtentry *rt = (struct rtentry *)rn;
40453541Sshin	struct mtuex_arg *ap = rock;
40553541Sshin
40653541Sshin	/* sanity */
40753541Sshin	if (!rt)
40853541Sshin		panic("rt == NULL in in6_mtuexpire");
40953541Sshin
41053541Sshin	if (rt->rt_rmx.rmx_expire && !(rt->rt_flags & RTF_PROBEMTU)) {
411150351Sandre		if (rt->rt_rmx.rmx_expire <= time_uptime) {
41253541Sshin			rt->rt_flags |= RTF_PROBEMTU;
41353541Sshin		} else {
41453541Sshin			ap->nextstop = lmin(ap->nextstop,
41553541Sshin					rt->rt_rmx.rmx_expire);
41653541Sshin		}
41753541Sshin	}
41853541Sshin
41953541Sshin	return 0;
42053541Sshin}
42153541Sshin
42253541Sshin#define	MTUTIMO_DEFAULT	(60*1)
42353541Sshin
42453541Sshinstatic void
42553541Sshinin6_mtutimo(void *rock)
42653541Sshin{
427183550Szec	CURVNET_SET_QUIET((struct vnet *) rock);
428183550Szec	INIT_VNET_NET((struct vnet *) rock);
429183550Szec	INIT_VNET_INET6((struct vnet *) rock);
43053541Sshin	struct radix_node_head *rnh = rock;
43153541Sshin	struct mtuex_arg arg;
43253541Sshin	struct timeval atv;
43353541Sshin
43453541Sshin	arg.rnh = rnh;
435160123Soleg	arg.nextstop = time_uptime + MTUTIMO_DEFAULT;
436108250Shsu	RADIX_NODE_HEAD_LOCK(rnh);
43753541Sshin	rnh->rnh_walktree(rnh, in6_mtuexpire, &arg);
438108250Shsu	RADIX_NODE_HEAD_UNLOCK(rnh);
43953541Sshin
44053541Sshin	atv.tv_usec = 0;
441160123Soleg	atv.tv_sec = arg.nextstop - time_uptime;
442136184Ssuz	if (atv.tv_sec < 0) {
44353541Sshin		printf("invalid mtu expiration time on routing table\n");
444160123Soleg		arg.nextstop = time_uptime + 30;	/* last resort */
445160123Soleg		atv.tv_sec = 30;
44653541Sshin	}
447181803Sbz	callout_reset(&V_rtq_mtutimer, tvtohz(&atv), in6_mtutimo, rock);
448183550Szec	CURVNET_RESTORE();
44953541Sshin}
45053541Sshin
45162587Sitojun#if 0
45262587Sitojunvoid
453171259Sdelphijin6_rtqdrain(void)
45462587Sitojun{
455183550Szec	INIT_VNET_NET(curvnet);
456181803Sbz	struct radix_node_head *rnh = V_rt_tables[AF_INET6];
45762587Sitojun	struct rtqk_arg arg;
458120727Ssam
45962587Sitojun	arg.found = arg.killed = 0;
46062587Sitojun	arg.rnh = rnh;
46162587Sitojun	arg.nextstop = 0;
46262587Sitojun	arg.draining = 1;
46362587Sitojun	arg.updating = 0;
464108250Shsu	RADIX_NODE_HEAD_LOCK(rnh);
46562587Sitojun	rnh->rnh_walktree(rnh, in6_rtqkill, &arg);
466108250Shsu	RADIX_NODE_HEAD_UNLOCK(rnh);
46762587Sitojun}
46862587Sitojun#endif
46962587Sitojun
47053541Sshin/*
47153541Sshin * Initialize our routing tree.
472178888Sjulian * XXX MRT When off == 0, we are being called from vfs_export.c
473178888Sjulian * so just set up their table and leave. (we know what the correct
474178888Sjulian * value should be so just use that).. FIX AFTER RELENG_7 is MFC'd
475178888Sjulian * see also comments in in_inithead() vfs_export.c and domain.h
47653541Sshin */
47753541Sshinint
47853541Sshinin6_inithead(void **head, int off)
47953541Sshin{
480183550Szec	INIT_VNET_INET6(curvnet);
48153541Sshin	struct radix_node_head *rnh;
48253541Sshin
483178888Sjulian	if (!rn_inithead(head, offsetof(struct sockaddr_in6, sin6_addr) << 3))
484178888Sjulian		return 0;		/* See above */
48553541Sshin
486178888Sjulian	if (off == 0)		/* See above */
487178888Sjulian		return 1;	/* only do the rest for the real thing */
48853541Sshin
489185088Szec	V_rtq_reallyold6 = 60*60; /* one hour is ``really old'' */
490185088Szec	V_rtq_minreallyold6 = 10; /* never automatically crank down to less */
491185088Szec	V_rtq_toomany6 = 128;	  /* 128 cached routes is ``too many'' */
492185088Szec	V_rtq_timeout6 = RTQ_TIMEOUT;
493185088Szec
49453541Sshin	rnh = *head;
49553541Sshin	rnh->rnh_addaddr = in6_addroute;
49653541Sshin	rnh->rnh_matchaddr = in6_matroute;
49753541Sshin	rnh->rnh_close = in6_clsroute;
498181803Sbz	callout_init(&V_rtq_timer6, CALLOUT_MPSAFE);
49953541Sshin	in6_rtqtimo(rnh);	/* kick off timeout first time */
500181803Sbz	callout_init(&V_rtq_mtutimer, CALLOUT_MPSAFE);
50153541Sshin	in6_mtutimo(rnh);	/* kick off timeout first time */
50253541Sshin	return 1;
50353541Sshin}
504