1/*- 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $KAME: in6_rmx.c,v 1.11 2001/07/26 06:53:16 jinmei Exp $ 30 */ 31 32/*- 33 * Copyright 1994, 1995 Massachusetts Institute of Technology 34 * 35 * Permission to use, copy, modify, and distribute this software and 36 * its documentation for any purpose and without fee is hereby 37 * granted, provided that both the above copyright notice and this 38 * permission notice appear in all copies, that both the above 39 * copyright notice and this permission notice appear in all 40 * supporting documentation, and that the name of M.I.T. not be used 41 * in advertising or publicity pertaining to distribution of the 42 * software without specific, written prior permission. M.I.T. makes 43 * no representations about the suitability of this software for any 44 * purpose. It is provided "as is" without express or implied 45 * warranty. 46 * 47 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 48 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 49 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 50 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 51 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 53 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 54 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 55 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 57 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * SUCH DAMAGE. 59 * 60 */ 61 62/* 63 * This code does two things necessary for the enhanced TCP metrics to 64 * function in a useful manner: 65 * 1) It marks all non-host routes as `cloning', thus ensuring that 66 * every actual reference to such a route actually gets turned 67 * into a reference to a host route to the specific destination 68 * requested. 69 * 2) When such routes lose all their references, it arranges for them 70 * to be deleted in some random collection of circumstances, so that 71 * a large quantity of stale routing data is not kept in kernel memory 72 * indefinitely. See in6_rtqtimo() below for the exact mechanism. 73 */ 74 75#include <sys/cdefs.h>
| 1/*- 2 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of the project nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * $KAME: in6_rmx.c,v 1.11 2001/07/26 06:53:16 jinmei Exp $ 30 */ 31 32/*- 33 * Copyright 1994, 1995 Massachusetts Institute of Technology 34 * 35 * Permission to use, copy, modify, and distribute this software and 36 * its documentation for any purpose and without fee is hereby 37 * granted, provided that both the above copyright notice and this 38 * permission notice appear in all copies, that both the above 39 * copyright notice and this permission notice appear in all 40 * supporting documentation, and that the name of M.I.T. not be used 41 * in advertising or publicity pertaining to distribution of the 42 * software without specific, written prior permission. M.I.T. makes 43 * no representations about the suitability of this software for any 44 * purpose. It is provided "as is" without express or implied 45 * warranty. 46 * 47 * THIS SOFTWARE IS PROVIDED BY M.I.T. ``AS IS''. M.I.T. DISCLAIMS 48 * ALL EXPRESS OR IMPLIED WARRANTIES WITH REGARD TO THIS SOFTWARE, 49 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 50 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT 51 * SHALL M.I.T. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 52 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 53 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 54 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 55 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 56 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 57 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 * SUCH DAMAGE. 59 * 60 */ 61 62/* 63 * This code does two things necessary for the enhanced TCP metrics to 64 * function in a useful manner: 65 * 1) It marks all non-host routes as `cloning', thus ensuring that 66 * every actual reference to such a route actually gets turned 67 * into a reference to a host route to the specific destination 68 * requested. 69 * 2) When such routes lose all their references, it arranges for them 70 * to be deleted in some random collection of circumstances, so that 71 * a large quantity of stale routing data is not kept in kernel memory 72 * indefinitely. See in6_rtqtimo() below for the exact mechanism. 73 */ 74 75#include <sys/cdefs.h>
|
76__FBSDID("$FreeBSD: head/sys/netinet6/in6_rmx.c 186119 2008-12-15 06:10:57Z qingli $");
| 76__FBSDID("$FreeBSD: head/sys/netinet6/in6_rmx.c 186215 2008-12-17 10:03:49Z qingli $");
|
77 78#include <sys/param.h> 79#include <sys/systm.h> 80#include <sys/kernel.h> 81#include <sys/lock.h> 82#include <sys/sysctl.h> 83#include <sys/queue.h> 84#include <sys/socket.h> 85#include <sys/socketvar.h> 86#include <sys/mbuf.h> 87#include <sys/rwlock.h> 88#include <sys/syslog.h> 89#include <sys/callout.h> 90#include <sys/vimage.h> 91 92#include <net/if.h> 93#include <net/route.h> 94#include <net/vnet.h> 95 96#include <netinet/in.h> 97#include <netinet/ip_var.h> 98#include <netinet/in_var.h> 99 100#include <netinet/ip6.h> 101#include <netinet6/ip6_var.h> 102 103#include <netinet/icmp6.h> 104#include <netinet6/nd6.h> 105#include <netinet6/vinet6.h> 106 107#include <netinet/tcp.h> 108#include <netinet/tcp_seq.h> 109#include <netinet/tcp_timer.h> 110#include <netinet/tcp_var.h> 111 112extern int in6_inithead(void **head, int off); 113 114#define RTPRF_OURS RTF_PROTO3 /* set on routes we manage */ 115 116/* 117 * Do what we need to do when inserting a route. 118 */ 119static struct radix_node * 120in6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head, 121 struct radix_node *treenodes) 122{ 123 struct rtentry *rt = (struct rtentry *)treenodes; 124 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)rt_key(rt); 125 struct radix_node *ret; 126 127 RADIX_NODE_HEAD_WLOCK_ASSERT(head); 128 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) 129 rt->rt_flags |= RTF_MULTICAST; 130 131 /* 132 * A little bit of help for both IPv6 output and input: 133 * For local addresses, we make sure that RTF_LOCAL is set, 134 * with the thought that this might one day be used to speed up 135 * ip_input(). 136 * 137 * We also mark routes to multicast addresses as such, because 138 * it's easy to do and might be useful (but this is much more 139 * dubious since it's so easy to inspect the address). (This 140 * is done above.) 141 * 142 * XXX 143 * should elaborate the code. 144 */ 145 if (rt->rt_flags & RTF_HOST) { 146 if (IN6_ARE_ADDR_EQUAL(&satosin6(rt->rt_ifa->ifa_addr) 147 ->sin6_addr, 148 &sin6->sin6_addr)) { 149 rt->rt_flags |= RTF_LOCAL; 150 } 151 } 152 153 if (!rt->rt_rmx.rmx_mtu && rt->rt_ifp) 154 rt->rt_rmx.rmx_mtu = IN6_LINKMTU(rt->rt_ifp); 155 156 ret = rn_addroute(v_arg, n_arg, head, treenodes); 157 if (ret == NULL) { 158 struct rtentry *rt2; 159 /* 160 * We are trying to add a net route, but can't. 161 * The following case should be allowed, so we'll make a 162 * special check for this: 163 * Two IPv6 addresses with the same prefix is assigned 164 * to a single interrface. 165 * # ifconfig if0 inet6 3ffe:0501::1 prefix 64 alias (*1) 166 * # ifconfig if0 inet6 3ffe:0501::2 prefix 64 alias (*2) 167 * In this case, (*1) and (*2) want to add the same 168 * net route entry, 3ffe:0501:: -> if0. 169 * This case should not raise an error. 170 */ 171 rt2 = rtalloc1((struct sockaddr *)sin6, 0, RTF_RNH_LOCKED); 172 if (rt2) { 173 if (((rt2->rt_flags & (RTF_HOST|RTF_GATEWAY)) == 0) 174 && rt2->rt_gateway 175 && rt2->rt_gateway->sa_family == AF_LINK 176 && rt2->rt_ifp == rt->rt_ifp) { 177 ret = rt2->rt_nodes; 178 } 179 RTFREE_LOCKED(rt2); 180 } 181 } 182 return (ret); 183} 184 185/* 186 * This code is the inverse of in6_clsroute: on first reference, if we 187 * were managing the route, stop doing so and set the expiration timer 188 * back off again. 189 */ 190static struct radix_node * 191in6_matroute(void *v_arg, struct radix_node_head *head) 192{ 193 struct radix_node *rn = rn_match(v_arg, head); 194 struct rtentry *rt = (struct rtentry *)rn; 195 196 if (rt && rt->rt_refcnt == 0) { /* this is first reference */ 197 if (rt->rt_flags & RTPRF_OURS) { 198 rt->rt_flags &= ~RTPRF_OURS; 199 rt->rt_rmx.rmx_expire = 0; 200 } 201 } 202 return rn; 203} 204 205SYSCTL_DECL(_net_inet6_ip6); 206 207#ifdef VIMAGE_GLOBALS 208static int rtq_reallyold6; 209static int rtq_minreallyold6; 210static int rtq_toomany6; 211#endif 212 213SYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTEXPIRE, 214 rtexpire, CTLFLAG_RW, rtq_reallyold6 , 0, ""); 215 216SYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMINEXPIRE, 217 rtminexpire, CTLFLAG_RW, rtq_minreallyold6 , 0, ""); 218 219SYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMAXCACHE, 220 rtmaxcache, CTLFLAG_RW, rtq_toomany6 , 0, ""); 221 222
| 77 78#include <sys/param.h> 79#include <sys/systm.h> 80#include <sys/kernel.h> 81#include <sys/lock.h> 82#include <sys/sysctl.h> 83#include <sys/queue.h> 84#include <sys/socket.h> 85#include <sys/socketvar.h> 86#include <sys/mbuf.h> 87#include <sys/rwlock.h> 88#include <sys/syslog.h> 89#include <sys/callout.h> 90#include <sys/vimage.h> 91 92#include <net/if.h> 93#include <net/route.h> 94#include <net/vnet.h> 95 96#include <netinet/in.h> 97#include <netinet/ip_var.h> 98#include <netinet/in_var.h> 99 100#include <netinet/ip6.h> 101#include <netinet6/ip6_var.h> 102 103#include <netinet/icmp6.h> 104#include <netinet6/nd6.h> 105#include <netinet6/vinet6.h> 106 107#include <netinet/tcp.h> 108#include <netinet/tcp_seq.h> 109#include <netinet/tcp_timer.h> 110#include <netinet/tcp_var.h> 111 112extern int in6_inithead(void **head, int off); 113 114#define RTPRF_OURS RTF_PROTO3 /* set on routes we manage */ 115 116/* 117 * Do what we need to do when inserting a route. 118 */ 119static struct radix_node * 120in6_addroute(void *v_arg, void *n_arg, struct radix_node_head *head, 121 struct radix_node *treenodes) 122{ 123 struct rtentry *rt = (struct rtentry *)treenodes; 124 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)rt_key(rt); 125 struct radix_node *ret; 126 127 RADIX_NODE_HEAD_WLOCK_ASSERT(head); 128 if (IN6_IS_ADDR_MULTICAST(&sin6->sin6_addr)) 129 rt->rt_flags |= RTF_MULTICAST; 130 131 /* 132 * A little bit of help for both IPv6 output and input: 133 * For local addresses, we make sure that RTF_LOCAL is set, 134 * with the thought that this might one day be used to speed up 135 * ip_input(). 136 * 137 * We also mark routes to multicast addresses as such, because 138 * it's easy to do and might be useful (but this is much more 139 * dubious since it's so easy to inspect the address). (This 140 * is done above.) 141 * 142 * XXX 143 * should elaborate the code. 144 */ 145 if (rt->rt_flags & RTF_HOST) { 146 if (IN6_ARE_ADDR_EQUAL(&satosin6(rt->rt_ifa->ifa_addr) 147 ->sin6_addr, 148 &sin6->sin6_addr)) { 149 rt->rt_flags |= RTF_LOCAL; 150 } 151 } 152 153 if (!rt->rt_rmx.rmx_mtu && rt->rt_ifp) 154 rt->rt_rmx.rmx_mtu = IN6_LINKMTU(rt->rt_ifp); 155 156 ret = rn_addroute(v_arg, n_arg, head, treenodes); 157 if (ret == NULL) { 158 struct rtentry *rt2; 159 /* 160 * We are trying to add a net route, but can't. 161 * The following case should be allowed, so we'll make a 162 * special check for this: 163 * Two IPv6 addresses with the same prefix is assigned 164 * to a single interrface. 165 * # ifconfig if0 inet6 3ffe:0501::1 prefix 64 alias (*1) 166 * # ifconfig if0 inet6 3ffe:0501::2 prefix 64 alias (*2) 167 * In this case, (*1) and (*2) want to add the same 168 * net route entry, 3ffe:0501:: -> if0. 169 * This case should not raise an error. 170 */ 171 rt2 = rtalloc1((struct sockaddr *)sin6, 0, RTF_RNH_LOCKED); 172 if (rt2) { 173 if (((rt2->rt_flags & (RTF_HOST|RTF_GATEWAY)) == 0) 174 && rt2->rt_gateway 175 && rt2->rt_gateway->sa_family == AF_LINK 176 && rt2->rt_ifp == rt->rt_ifp) { 177 ret = rt2->rt_nodes; 178 } 179 RTFREE_LOCKED(rt2); 180 } 181 } 182 return (ret); 183} 184 185/* 186 * This code is the inverse of in6_clsroute: on first reference, if we 187 * were managing the route, stop doing so and set the expiration timer 188 * back off again. 189 */ 190static struct radix_node * 191in6_matroute(void *v_arg, struct radix_node_head *head) 192{ 193 struct radix_node *rn = rn_match(v_arg, head); 194 struct rtentry *rt = (struct rtentry *)rn; 195 196 if (rt && rt->rt_refcnt == 0) { /* this is first reference */ 197 if (rt->rt_flags & RTPRF_OURS) { 198 rt->rt_flags &= ~RTPRF_OURS; 199 rt->rt_rmx.rmx_expire = 0; 200 } 201 } 202 return rn; 203} 204 205SYSCTL_DECL(_net_inet6_ip6); 206 207#ifdef VIMAGE_GLOBALS 208static int rtq_reallyold6; 209static int rtq_minreallyold6; 210static int rtq_toomany6; 211#endif 212 213SYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTEXPIRE, 214 rtexpire, CTLFLAG_RW, rtq_reallyold6 , 0, ""); 215 216SYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMINEXPIRE, 217 rtminexpire, CTLFLAG_RW, rtq_minreallyold6 , 0, ""); 218 219SYSCTL_V_INT(V_NET, vnet_inet6, _net_inet6_ip6, IPV6CTL_RTMAXCACHE, 220 rtmaxcache, CTLFLAG_RW, rtq_toomany6 , 0, ""); 221 222
|
223/* 224 * On last reference drop, mark the route as belong to us so that it can be 225 * timed out. 226 */ 227static void 228in6_clsroute(struct radix_node *rn, struct radix_node_head *head) 229{ 230 INIT_VNET_INET6(curvnet); 231 struct rtentry *rt = (struct rtentry *)rn;
| |
232
| 223
|
233 RT_LOCK_ASSERT(rt); 234 235 if (!(rt->rt_flags & RTF_UP)) 236 return; /* prophylactic measures */ 237 238 /* 239 * As requested by David Greenman: 240 * If rtq_reallyold6 is 0, just delete the route without 241 * waiting for a timeout cycle to kill it. 242 */ 243 if (V_rtq_reallyold6 != 0) { 244 rt->rt_flags |= RTPRF_OURS; 245 rt->rt_rmx.rmx_expire = time_uptime + V_rtq_reallyold6; 246 } else { 247 rtexpunge(rt); 248 } 249} 250
| |
251struct rtqk_arg { 252 struct radix_node_head *rnh; 253 int mode; 254 int updating; 255 int draining; 256 int killed; 257 int found; 258 time_t nextstop; 259}; 260 261/* 262 * Get rid of old routes. When draining, this deletes everything, even when 263 * the timeout is not expired yet. When updating, this makes sure that 264 * nothing has a timeout longer than the current value of rtq_reallyold6. 265 */ 266static int 267in6_rtqkill(struct radix_node *rn, void *rock) 268{ 269 INIT_VNET_INET6(curvnet); 270 struct rtqk_arg *ap = rock; 271 struct rtentry *rt = (struct rtentry *)rn; 272 int err; 273 274 if (rt->rt_flags & RTPRF_OURS) { 275 ap->found++; 276 277 if (ap->draining || rt->rt_rmx.rmx_expire <= time_uptime) { 278 if (rt->rt_refcnt > 0) 279 panic("rtqkill route really not free"); 280 281 err = rtrequest(RTM_DELETE, 282 (struct sockaddr *)rt_key(rt), 283 rt->rt_gateway, rt_mask(rt), 284 rt->rt_flags|RTF_RNH_LOCKED, 0); 285 if (err) { 286 log(LOG_WARNING, "in6_rtqkill: error %d", err); 287 } else { 288 ap->killed++; 289 } 290 } else { 291 if (ap->updating 292 && (rt->rt_rmx.rmx_expire - time_uptime 293 > V_rtq_reallyold6)) { 294 rt->rt_rmx.rmx_expire = time_uptime 295 + V_rtq_reallyold6; 296 } 297 ap->nextstop = lmin(ap->nextstop, 298 rt->rt_rmx.rmx_expire); 299 } 300 } 301 302 return 0; 303} 304 305#define RTQ_TIMEOUT 60*10 /* run no less than once every ten minutes */ 306#ifdef VIMAGE_GLOBALS 307static int rtq_timeout6; 308static struct callout rtq_timer6; 309#endif 310 311static void 312in6_rtqtimo(void *rock) 313{ 314 CURVNET_SET_QUIET((struct vnet *) rock); 315 INIT_VNET_NET((struct vnet *) rock); 316 INIT_VNET_INET6((struct vnet *) rock); 317 struct radix_node_head *rnh = rock; 318 struct rtqk_arg arg; 319 struct timeval atv; 320 static time_t last_adjusted_timeout = 0; 321 322 arg.found = arg.killed = 0; 323 arg.rnh = rnh; 324 arg.nextstop = time_uptime + V_rtq_timeout6; 325 arg.draining = arg.updating = 0; 326 RADIX_NODE_HEAD_LOCK(rnh); 327 rnh->rnh_walktree(rnh, in6_rtqkill, &arg); 328 RADIX_NODE_HEAD_UNLOCK(rnh); 329 330 /* 331 * Attempt to be somewhat dynamic about this: 332 * If there are ``too many'' routes sitting around taking up space, 333 * then crank down the timeout, and see if we can't make some more 334 * go away. However, we make sure that we will never adjust more 335 * than once in rtq_timeout6 seconds, to keep from cranking down too 336 * hard. 337 */ 338 if ((arg.found - arg.killed > V_rtq_toomany6) 339 && (time_uptime - last_adjusted_timeout >= V_rtq_timeout6) 340 && V_rtq_reallyold6 > V_rtq_minreallyold6) { 341 V_rtq_reallyold6 = 2*V_rtq_reallyold6 / 3; 342 if (V_rtq_reallyold6 < V_rtq_minreallyold6) { 343 V_rtq_reallyold6 = V_rtq_minreallyold6; 344 } 345 346 last_adjusted_timeout = time_uptime; 347#ifdef DIAGNOSTIC 348 log(LOG_DEBUG, "in6_rtqtimo: adjusted rtq_reallyold6 to %d", 349 V_rtq_reallyold6); 350#endif 351 arg.found = arg.killed = 0; 352 arg.updating = 1; 353 RADIX_NODE_HEAD_LOCK(rnh); 354 rnh->rnh_walktree(rnh, in6_rtqkill, &arg); 355 RADIX_NODE_HEAD_UNLOCK(rnh); 356 } 357 358 atv.tv_usec = 0; 359 atv.tv_sec = arg.nextstop - time_uptime; 360 callout_reset(&V_rtq_timer6, tvtohz(&atv), in6_rtqtimo, rock); 361 CURVNET_RESTORE(); 362} 363 364/* 365 * Age old PMTUs. 366 */ 367struct mtuex_arg { 368 struct radix_node_head *rnh; 369 time_t nextstop; 370}; 371#ifdef VIMAGE_GLOBALS 372static struct callout rtq_mtutimer; 373#endif 374 375static int 376in6_mtuexpire(struct radix_node *rn, void *rock) 377{ 378 struct rtentry *rt = (struct rtentry *)rn; 379 struct mtuex_arg *ap = rock; 380 381 /* sanity */ 382 if (!rt) 383 panic("rt == NULL in in6_mtuexpire"); 384 385 if (rt->rt_rmx.rmx_expire && !(rt->rt_flags & RTF_PROBEMTU)) { 386 if (rt->rt_rmx.rmx_expire <= time_uptime) { 387 rt->rt_flags |= RTF_PROBEMTU; 388 } else { 389 ap->nextstop = lmin(ap->nextstop, 390 rt->rt_rmx.rmx_expire); 391 } 392 } 393 394 return 0; 395} 396 397#define MTUTIMO_DEFAULT (60*1) 398 399static void 400in6_mtutimo(void *rock) 401{ 402 CURVNET_SET_QUIET((struct vnet *) rock); 403 INIT_VNET_NET((struct vnet *) rock); 404 INIT_VNET_INET6((struct vnet *) rock); 405 struct radix_node_head *rnh = rock; 406 struct mtuex_arg arg; 407 struct timeval atv; 408 409 arg.rnh = rnh; 410 arg.nextstop = time_uptime + MTUTIMO_DEFAULT; 411 RADIX_NODE_HEAD_LOCK(rnh); 412 rnh->rnh_walktree(rnh, in6_mtuexpire, &arg); 413 RADIX_NODE_HEAD_UNLOCK(rnh); 414 415 atv.tv_usec = 0; 416 atv.tv_sec = arg.nextstop - time_uptime; 417 if (atv.tv_sec < 0) { 418 printf("invalid mtu expiration time on routing table\n"); 419 arg.nextstop = time_uptime + 30; /* last resort */ 420 atv.tv_sec = 30; 421 } 422 callout_reset(&V_rtq_mtutimer, tvtohz(&atv), in6_mtutimo, rock); 423 CURVNET_RESTORE(); 424} 425 426#if 0 427void 428in6_rtqdrain(void) 429{ 430 INIT_VNET_NET(curvnet); 431 struct radix_node_head *rnh = V_rt_tables[AF_INET6]; 432 struct rtqk_arg arg; 433 434 arg.found = arg.killed = 0; 435 arg.rnh = rnh; 436 arg.nextstop = 0; 437 arg.draining = 1; 438 arg.updating = 0; 439 RADIX_NODE_HEAD_LOCK(rnh); 440 rnh->rnh_walktree(rnh, in6_rtqkill, &arg); 441 RADIX_NODE_HEAD_UNLOCK(rnh); 442} 443#endif 444 445/* 446 * Initialize our routing tree. 447 * XXX MRT When off == 0, we are being called from vfs_export.c 448 * so just set up their table and leave. (we know what the correct 449 * value should be so just use that).. FIX AFTER RELENG_7 is MFC'd 450 * see also comments in in_inithead() vfs_export.c and domain.h 451 */ 452int 453in6_inithead(void **head, int off) 454{ 455 INIT_VNET_INET6(curvnet); 456 struct radix_node_head *rnh; 457 458 if (!rn_inithead(head, offsetof(struct sockaddr_in6, sin6_addr) << 3)) 459 return 0; /* See above */ 460 461 if (off == 0) /* See above */ 462 return 1; /* only do the rest for the real thing */ 463 464 V_rtq_reallyold6 = 60*60; /* one hour is ``really old'' */ 465 V_rtq_minreallyold6 = 10; /* never automatically crank down to less */ 466 V_rtq_toomany6 = 128; /* 128 cached routes is ``too many'' */ 467 V_rtq_timeout6 = RTQ_TIMEOUT; 468 469 rnh = *head; 470 rnh->rnh_addaddr = in6_addroute; 471 rnh->rnh_matchaddr = in6_matroute;
| 224struct rtqk_arg { 225 struct radix_node_head *rnh; 226 int mode; 227 int updating; 228 int draining; 229 int killed; 230 int found; 231 time_t nextstop; 232}; 233 234/* 235 * Get rid of old routes. When draining, this deletes everything, even when 236 * the timeout is not expired yet. When updating, this makes sure that 237 * nothing has a timeout longer than the current value of rtq_reallyold6. 238 */ 239static int 240in6_rtqkill(struct radix_node *rn, void *rock) 241{ 242 INIT_VNET_INET6(curvnet); 243 struct rtqk_arg *ap = rock; 244 struct rtentry *rt = (struct rtentry *)rn; 245 int err; 246 247 if (rt->rt_flags & RTPRF_OURS) { 248 ap->found++; 249 250 if (ap->draining || rt->rt_rmx.rmx_expire <= time_uptime) { 251 if (rt->rt_refcnt > 0) 252 panic("rtqkill route really not free"); 253 254 err = rtrequest(RTM_DELETE, 255 (struct sockaddr *)rt_key(rt), 256 rt->rt_gateway, rt_mask(rt), 257 rt->rt_flags|RTF_RNH_LOCKED, 0); 258 if (err) { 259 log(LOG_WARNING, "in6_rtqkill: error %d", err); 260 } else { 261 ap->killed++; 262 } 263 } else { 264 if (ap->updating 265 && (rt->rt_rmx.rmx_expire - time_uptime 266 > V_rtq_reallyold6)) { 267 rt->rt_rmx.rmx_expire = time_uptime 268 + V_rtq_reallyold6; 269 } 270 ap->nextstop = lmin(ap->nextstop, 271 rt->rt_rmx.rmx_expire); 272 } 273 } 274 275 return 0; 276} 277 278#define RTQ_TIMEOUT 60*10 /* run no less than once every ten minutes */ 279#ifdef VIMAGE_GLOBALS 280static int rtq_timeout6; 281static struct callout rtq_timer6; 282#endif 283 284static void 285in6_rtqtimo(void *rock) 286{ 287 CURVNET_SET_QUIET((struct vnet *) rock); 288 INIT_VNET_NET((struct vnet *) rock); 289 INIT_VNET_INET6((struct vnet *) rock); 290 struct radix_node_head *rnh = rock; 291 struct rtqk_arg arg; 292 struct timeval atv; 293 static time_t last_adjusted_timeout = 0; 294 295 arg.found = arg.killed = 0; 296 arg.rnh = rnh; 297 arg.nextstop = time_uptime + V_rtq_timeout6; 298 arg.draining = arg.updating = 0; 299 RADIX_NODE_HEAD_LOCK(rnh); 300 rnh->rnh_walktree(rnh, in6_rtqkill, &arg); 301 RADIX_NODE_HEAD_UNLOCK(rnh); 302 303 /* 304 * Attempt to be somewhat dynamic about this: 305 * If there are ``too many'' routes sitting around taking up space, 306 * then crank down the timeout, and see if we can't make some more 307 * go away. However, we make sure that we will never adjust more 308 * than once in rtq_timeout6 seconds, to keep from cranking down too 309 * hard. 310 */ 311 if ((arg.found - arg.killed > V_rtq_toomany6) 312 && (time_uptime - last_adjusted_timeout >= V_rtq_timeout6) 313 && V_rtq_reallyold6 > V_rtq_minreallyold6) { 314 V_rtq_reallyold6 = 2*V_rtq_reallyold6 / 3; 315 if (V_rtq_reallyold6 < V_rtq_minreallyold6) { 316 V_rtq_reallyold6 = V_rtq_minreallyold6; 317 } 318 319 last_adjusted_timeout = time_uptime; 320#ifdef DIAGNOSTIC 321 log(LOG_DEBUG, "in6_rtqtimo: adjusted rtq_reallyold6 to %d", 322 V_rtq_reallyold6); 323#endif 324 arg.found = arg.killed = 0; 325 arg.updating = 1; 326 RADIX_NODE_HEAD_LOCK(rnh); 327 rnh->rnh_walktree(rnh, in6_rtqkill, &arg); 328 RADIX_NODE_HEAD_UNLOCK(rnh); 329 } 330 331 atv.tv_usec = 0; 332 atv.tv_sec = arg.nextstop - time_uptime; 333 callout_reset(&V_rtq_timer6, tvtohz(&atv), in6_rtqtimo, rock); 334 CURVNET_RESTORE(); 335} 336 337/* 338 * Age old PMTUs. 339 */ 340struct mtuex_arg { 341 struct radix_node_head *rnh; 342 time_t nextstop; 343}; 344#ifdef VIMAGE_GLOBALS 345static struct callout rtq_mtutimer; 346#endif 347 348static int 349in6_mtuexpire(struct radix_node *rn, void *rock) 350{ 351 struct rtentry *rt = (struct rtentry *)rn; 352 struct mtuex_arg *ap = rock; 353 354 /* sanity */ 355 if (!rt) 356 panic("rt == NULL in in6_mtuexpire"); 357 358 if (rt->rt_rmx.rmx_expire && !(rt->rt_flags & RTF_PROBEMTU)) { 359 if (rt->rt_rmx.rmx_expire <= time_uptime) { 360 rt->rt_flags |= RTF_PROBEMTU; 361 } else { 362 ap->nextstop = lmin(ap->nextstop, 363 rt->rt_rmx.rmx_expire); 364 } 365 } 366 367 return 0; 368} 369 370#define MTUTIMO_DEFAULT (60*1) 371 372static void 373in6_mtutimo(void *rock) 374{ 375 CURVNET_SET_QUIET((struct vnet *) rock); 376 INIT_VNET_NET((struct vnet *) rock); 377 INIT_VNET_INET6((struct vnet *) rock); 378 struct radix_node_head *rnh = rock; 379 struct mtuex_arg arg; 380 struct timeval atv; 381 382 arg.rnh = rnh; 383 arg.nextstop = time_uptime + MTUTIMO_DEFAULT; 384 RADIX_NODE_HEAD_LOCK(rnh); 385 rnh->rnh_walktree(rnh, in6_mtuexpire, &arg); 386 RADIX_NODE_HEAD_UNLOCK(rnh); 387 388 atv.tv_usec = 0; 389 atv.tv_sec = arg.nextstop - time_uptime; 390 if (atv.tv_sec < 0) { 391 printf("invalid mtu expiration time on routing table\n"); 392 arg.nextstop = time_uptime + 30; /* last resort */ 393 atv.tv_sec = 30; 394 } 395 callout_reset(&V_rtq_mtutimer, tvtohz(&atv), in6_mtutimo, rock); 396 CURVNET_RESTORE(); 397} 398 399#if 0 400void 401in6_rtqdrain(void) 402{ 403 INIT_VNET_NET(curvnet); 404 struct radix_node_head *rnh = V_rt_tables[AF_INET6]; 405 struct rtqk_arg arg; 406 407 arg.found = arg.killed = 0; 408 arg.rnh = rnh; 409 arg.nextstop = 0; 410 arg.draining = 1; 411 arg.updating = 0; 412 RADIX_NODE_HEAD_LOCK(rnh); 413 rnh->rnh_walktree(rnh, in6_rtqkill, &arg); 414 RADIX_NODE_HEAD_UNLOCK(rnh); 415} 416#endif 417 418/* 419 * Initialize our routing tree. 420 * XXX MRT When off == 0, we are being called from vfs_export.c 421 * so just set up their table and leave. (we know what the correct 422 * value should be so just use that).. FIX AFTER RELENG_7 is MFC'd 423 * see also comments in in_inithead() vfs_export.c and domain.h 424 */ 425int 426in6_inithead(void **head, int off) 427{ 428 INIT_VNET_INET6(curvnet); 429 struct radix_node_head *rnh; 430 431 if (!rn_inithead(head, offsetof(struct sockaddr_in6, sin6_addr) << 3)) 432 return 0; /* See above */ 433 434 if (off == 0) /* See above */ 435 return 1; /* only do the rest for the real thing */ 436 437 V_rtq_reallyold6 = 60*60; /* one hour is ``really old'' */ 438 V_rtq_minreallyold6 = 10; /* never automatically crank down to less */ 439 V_rtq_toomany6 = 128; /* 128 cached routes is ``too many'' */ 440 V_rtq_timeout6 = RTQ_TIMEOUT; 441 442 rnh = *head; 443 rnh->rnh_addaddr = in6_addroute; 444 rnh->rnh_matchaddr = in6_matroute;
|
472 rnh->rnh_close = in6_clsroute;
| |
473 callout_init(&V_rtq_timer6, CALLOUT_MPSAFE); 474 in6_rtqtimo(rnh); /* kick off timeout first time */ 475 callout_init(&V_rtq_mtutimer, CALLOUT_MPSAFE); 476 in6_mtutimo(rnh); /* kick off timeout first time */ 477 return 1; 478}
| 445 callout_init(&V_rtq_timer6, CALLOUT_MPSAFE); 446 in6_rtqtimo(rnh); /* kick off timeout first time */ 447 callout_init(&V_rtq_mtutimer, CALLOUT_MPSAFE); 448 in6_mtutimo(rnh); /* kick off timeout first time */ 449 return 1; 450}
|