nd6_rtr.c (252141) | nd6_rtr.c (253970) |
---|---|
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 --- 16 unchanged lines hidden (view full) --- 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: nd6_rtr.c,v 1.111 2001/04/27 01:37:15 jinmei Exp $ 30 */ 31 32#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 --- 16 unchanged lines hidden (view full) --- 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: nd6_rtr.c,v 1.111 2001/04/27 01:37:15 jinmei Exp $ 30 */ 31 32#include <sys/cdefs.h> |
33__FBSDID("$FreeBSD: head/sys/netinet6/nd6_rtr.c 252141 2013-06-24 05:01:13Z qingli $"); | 33__FBSDID("$FreeBSD: head/sys/netinet6/nd6_rtr.c 253970 2013-08-05 20:13:02Z hrs $"); |
34 35#include "opt_inet.h" 36#include "opt_inet6.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/malloc.h> 41#include <sys/mbuf.h> --- 235 unchanged lines hidden (view full) --- 277 * (ip6.forwarding == 1 && ip6.rfc6204w3 != 1). 278 */ 279 if (ndi->flags & ND6_IFF_NO_RADR) 280 dr0.rtlifetime = 0; 281 else if (V_ip6_forwarding && !V_ip6_rfc6204w3) 282 dr0.rtlifetime = 0; 283 else 284 dr0.rtlifetime = ntohs(nd_ra->nd_ra_router_lifetime); | 34 35#include "opt_inet.h" 36#include "opt_inet6.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/malloc.h> 41#include <sys/mbuf.h> --- 235 unchanged lines hidden (view full) --- 277 * (ip6.forwarding == 1 && ip6.rfc6204w3 != 1). 278 */ 279 if (ndi->flags & ND6_IFF_NO_RADR) 280 dr0.rtlifetime = 0; 281 else if (V_ip6_forwarding && !V_ip6_rfc6204w3) 282 dr0.rtlifetime = 0; 283 else 284 dr0.rtlifetime = ntohs(nd_ra->nd_ra_router_lifetime); |
285 dr0.expire = time_second + dr0.rtlifetime; | 285 dr0.expire = time_uptime + dr0.rtlifetime; |
286 dr0.ifp = ifp; 287 /* unspecified or not? (RFC 2461 6.3.4) */ 288 if (advreachable) { 289 advreachable = ntohl(advreachable); 290 if (advreachable <= MAX_REACHABLE_TIME && 291 ndi->basereachable != advreachable) { 292 ndi->basereachable = advreachable; 293 ndi->reachable = ND_COMPUTE_RTIME(ndi->basereachable); --- 575 unchanged lines hidden (view full) --- 869 new->ndpr_plen = pr->ndpr_plen; 870 new->ndpr_vltime = pr->ndpr_vltime; 871 new->ndpr_pltime = pr->ndpr_pltime; 872 new->ndpr_flags = pr->ndpr_flags; 873 if ((error = in6_init_prefix_ltimes(new)) != 0) { 874 free(new, M_IP6NDP); 875 return(error); 876 } | 286 dr0.ifp = ifp; 287 /* unspecified or not? (RFC 2461 6.3.4) */ 288 if (advreachable) { 289 advreachable = ntohl(advreachable); 290 if (advreachable <= MAX_REACHABLE_TIME && 291 ndi->basereachable != advreachable) { 292 ndi->basereachable = advreachable; 293 ndi->reachable = ND_COMPUTE_RTIME(ndi->basereachable); --- 575 unchanged lines hidden (view full) --- 869 new->ndpr_plen = pr->ndpr_plen; 870 new->ndpr_vltime = pr->ndpr_vltime; 871 new->ndpr_pltime = pr->ndpr_pltime; 872 new->ndpr_flags = pr->ndpr_flags; 873 if ((error = in6_init_prefix_ltimes(new)) != 0) { 874 free(new, M_IP6NDP); 875 return(error); 876 } |
877 new->ndpr_lastupdate = time_second; | 877 new->ndpr_lastupdate = time_uptime; |
878 if (newp != NULL) 879 *newp = new; 880 881 /* initialization */ 882 LIST_INIT(&new->ndpr_advrtrs); 883 in6_prefixlen2mask(&new->ndpr_mask, new->ndpr_plen); 884 /* make prefix in the canonical form */ 885 for (i = 0; i < 4; i++) --- 107 unchanged lines hidden (view full) --- 993 if (new->ndpr_raf_onlink == 1) 994 pr->ndpr_raf_onlink = 1; 995 if (new->ndpr_raf_auto == 1) 996 pr->ndpr_raf_auto = 1; 997 if (new->ndpr_raf_onlink) { 998 pr->ndpr_vltime = new->ndpr_vltime; 999 pr->ndpr_pltime = new->ndpr_pltime; 1000 (void)in6_init_prefix_ltimes(pr); /* XXX error case? */ | 878 if (newp != NULL) 879 *newp = new; 880 881 /* initialization */ 882 LIST_INIT(&new->ndpr_advrtrs); 883 in6_prefixlen2mask(&new->ndpr_mask, new->ndpr_plen); 884 /* make prefix in the canonical form */ 885 for (i = 0; i < 4; i++) --- 107 unchanged lines hidden (view full) --- 993 if (new->ndpr_raf_onlink == 1) 994 pr->ndpr_raf_onlink = 1; 995 if (new->ndpr_raf_auto == 1) 996 pr->ndpr_raf_auto = 1; 997 if (new->ndpr_raf_onlink) { 998 pr->ndpr_vltime = new->ndpr_vltime; 999 pr->ndpr_pltime = new->ndpr_pltime; 1000 (void)in6_init_prefix_ltimes(pr); /* XXX error case? */ |
1001 pr->ndpr_lastupdate = time_second; | 1001 pr->ndpr_lastupdate = time_uptime; |
1002 } 1003 1004 if (new->ndpr_raf_onlink && 1005 (pr->ndpr_stateflags & NDPRF_ONLINK) == 0) { 1006 int e; 1007 1008 if ((e = nd6_prefix_onlink(pr)) != 0) { 1009 nd6log((LOG_ERR, --- 121 unchanged lines hidden (view full) --- 1131 * variable name 1132 * - remove the dead code in the "two-hour" rule 1133 */ 1134#define TWOHOUR (120*60) 1135 lt6_tmp = ifa6->ia6_lifetime; 1136 1137 if (lt6_tmp.ia6t_vltime == ND6_INFINITE_LIFETIME) 1138 remaininglifetime = ND6_INFINITE_LIFETIME; | 1002 } 1003 1004 if (new->ndpr_raf_onlink && 1005 (pr->ndpr_stateflags & NDPRF_ONLINK) == 0) { 1006 int e; 1007 1008 if ((e = nd6_prefix_onlink(pr)) != 0) { 1009 nd6log((LOG_ERR, --- 121 unchanged lines hidden (view full) --- 1131 * variable name 1132 * - remove the dead code in the "two-hour" rule 1133 */ 1134#define TWOHOUR (120*60) 1135 lt6_tmp = ifa6->ia6_lifetime; 1136 1137 if (lt6_tmp.ia6t_vltime == ND6_INFINITE_LIFETIME) 1138 remaininglifetime = ND6_INFINITE_LIFETIME; |
1139 else if (time_second - ifa6->ia6_updatetime > | 1139 else if (time_uptime - ifa6->ia6_updatetime > |
1140 lt6_tmp.ia6t_vltime) { 1141 /* 1142 * The case of "invalid" address. We should usually 1143 * not see this case. 1144 */ 1145 remaininglifetime = 0; 1146 } else 1147 remaininglifetime = lt6_tmp.ia6t_vltime - | 1140 lt6_tmp.ia6t_vltime) { 1141 /* 1142 * The case of "invalid" address. We should usually 1143 * not see this case. 1144 */ 1145 remaininglifetime = 0; 1146 } else 1147 remaininglifetime = lt6_tmp.ia6t_vltime - |
1148 (time_second - ifa6->ia6_updatetime); | 1148 (time_uptime - ifa6->ia6_updatetime); |
1149 1150 /* when not updating, keep the current stored lifetime. */ 1151 lt6_tmp.ia6t_vltime = remaininglifetime; 1152 1153 if (TWOHOUR < new->ndpr_vltime || 1154 remaininglifetime < new->ndpr_vltime) { 1155 lt6_tmp.ia6t_vltime = new->ndpr_vltime; 1156 } else if (remaininglifetime <= TWOHOUR) { --- 19 unchanged lines hidden (view full) --- 1176 * draft-ietf-ipv6-privacy-addrs-v2-01.txt 3.3 (1); 1177 * we only update the lifetimes when they are in the maximum 1178 * intervals. 1179 */ 1180 if ((ifa6->ia6_flags & IN6_IFF_TEMPORARY) != 0) { 1181 u_int32_t maxvltime, maxpltime; 1182 1183 if (V_ip6_temp_valid_lifetime > | 1149 1150 /* when not updating, keep the current stored lifetime. */ 1151 lt6_tmp.ia6t_vltime = remaininglifetime; 1152 1153 if (TWOHOUR < new->ndpr_vltime || 1154 remaininglifetime < new->ndpr_vltime) { 1155 lt6_tmp.ia6t_vltime = new->ndpr_vltime; 1156 } else if (remaininglifetime <= TWOHOUR) { --- 19 unchanged lines hidden (view full) --- 1176 * draft-ietf-ipv6-privacy-addrs-v2-01.txt 3.3 (1); 1177 * we only update the lifetimes when they are in the maximum 1178 * intervals. 1179 */ 1180 if ((ifa6->ia6_flags & IN6_IFF_TEMPORARY) != 0) { 1181 u_int32_t maxvltime, maxpltime; 1182 1183 if (V_ip6_temp_valid_lifetime > |
1184 (u_int32_t)((time_second - ifa6->ia6_createtime) + | 1184 (u_int32_t)((time_uptime - ifa6->ia6_createtime) + |
1185 V_ip6_desync_factor)) { 1186 maxvltime = V_ip6_temp_valid_lifetime - | 1185 V_ip6_desync_factor)) { 1186 maxvltime = V_ip6_temp_valid_lifetime - |
1187 (time_second - ifa6->ia6_createtime) - | 1187 (time_uptime - ifa6->ia6_createtime) - |
1188 V_ip6_desync_factor; 1189 } else 1190 maxvltime = 0; 1191 if (V_ip6_temp_preferred_lifetime > | 1188 V_ip6_desync_factor; 1189 } else 1190 maxvltime = 0; 1191 if (V_ip6_temp_preferred_lifetime > |
1192 (u_int32_t)((time_second - ifa6->ia6_createtime) + | 1192 (u_int32_t)((time_uptime - ifa6->ia6_createtime) + |
1193 V_ip6_desync_factor)) { 1194 maxpltime = V_ip6_temp_preferred_lifetime - | 1193 V_ip6_desync_factor)) { 1194 maxpltime = V_ip6_temp_preferred_lifetime - |
1195 (time_second - ifa6->ia6_createtime) - | 1195 (time_uptime - ifa6->ia6_createtime) - |
1196 V_ip6_desync_factor; 1197 } else 1198 maxpltime = 0; 1199 1200 if (lt6_tmp.ia6t_vltime == ND6_INFINITE_LIFETIME || 1201 lt6_tmp.ia6t_vltime > maxvltime) { 1202 lt6_tmp.ia6t_vltime = maxvltime; 1203 } 1204 if (lt6_tmp.ia6t_pltime == ND6_INFINITE_LIFETIME || 1205 lt6_tmp.ia6t_pltime > maxpltime) { 1206 lt6_tmp.ia6t_pltime = maxpltime; 1207 } 1208 } 1209 ifa6->ia6_lifetime = lt6_tmp; | 1196 V_ip6_desync_factor; 1197 } else 1198 maxpltime = 0; 1199 1200 if (lt6_tmp.ia6t_vltime == ND6_INFINITE_LIFETIME || 1201 lt6_tmp.ia6t_vltime > maxvltime) { 1202 lt6_tmp.ia6t_vltime = maxvltime; 1203 } 1204 if (lt6_tmp.ia6t_pltime == ND6_INFINITE_LIFETIME || 1205 lt6_tmp.ia6t_pltime > maxpltime) { 1206 lt6_tmp.ia6t_pltime = maxpltime; 1207 } 1208 } 1209 ifa6->ia6_lifetime = lt6_tmp; |
1210 ifa6->ia6_updatetime = time_second; | 1210 ifa6->ia6_updatetime = time_uptime; |
1211 } 1212 IF_ADDR_RUNLOCK(ifp); 1213 if (ia6_match == NULL && new->ndpr_vltime) { 1214 int ifidlen; 1215 1216 /* 1217 * 5.5.3 (d) (continued) 1218 * No address matched and the valid lifetime is non-zero. --- 764 unchanged lines hidden (view full) --- 1983 * public address or TEMP_VALID_LIFETIME. 1984 * The Preferred Lifetime is the lower of the Preferred Lifetime 1985 * of the public address or TEMP_PREFERRED_LIFETIME - 1986 * DESYNC_FACTOR. 1987 */ 1988 if (ia0->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME) { 1989 vltime0 = IFA6_IS_INVALID(ia0) ? 0 : 1990 (ia0->ia6_lifetime.ia6t_vltime - | 1211 } 1212 IF_ADDR_RUNLOCK(ifp); 1213 if (ia6_match == NULL && new->ndpr_vltime) { 1214 int ifidlen; 1215 1216 /* 1217 * 5.5.3 (d) (continued) 1218 * No address matched and the valid lifetime is non-zero. --- 764 unchanged lines hidden (view full) --- 1983 * public address or TEMP_VALID_LIFETIME. 1984 * The Preferred Lifetime is the lower of the Preferred Lifetime 1985 * of the public address or TEMP_PREFERRED_LIFETIME - 1986 * DESYNC_FACTOR. 1987 */ 1988 if (ia0->ia6_lifetime.ia6t_vltime != ND6_INFINITE_LIFETIME) { 1989 vltime0 = IFA6_IS_INVALID(ia0) ? 0 : 1990 (ia0->ia6_lifetime.ia6t_vltime - |
1991 (time_second - ia0->ia6_updatetime)); | 1991 (time_uptime - ia0->ia6_updatetime)); |
1992 if (vltime0 > V_ip6_temp_valid_lifetime) 1993 vltime0 = V_ip6_temp_valid_lifetime; 1994 } else 1995 vltime0 = V_ip6_temp_valid_lifetime; 1996 if (ia0->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME) { 1997 pltime0 = IFA6_IS_DEPRECATED(ia0) ? 0 : 1998 (ia0->ia6_lifetime.ia6t_pltime - | 1992 if (vltime0 > V_ip6_temp_valid_lifetime) 1993 vltime0 = V_ip6_temp_valid_lifetime; 1994 } else 1995 vltime0 = V_ip6_temp_valid_lifetime; 1996 if (ia0->ia6_lifetime.ia6t_pltime != ND6_INFINITE_LIFETIME) { 1997 pltime0 = IFA6_IS_DEPRECATED(ia0) ? 0 : 1998 (ia0->ia6_lifetime.ia6t_pltime - |
1999 (time_second - ia0->ia6_updatetime)); | 1999 (time_uptime - ia0->ia6_updatetime)); |
2000 if (pltime0 > V_ip6_temp_preferred_lifetime - V_ip6_desync_factor){ 2001 pltime0 = V_ip6_temp_preferred_lifetime - 2002 V_ip6_desync_factor; 2003 } 2004 } else 2005 pltime0 = V_ip6_temp_preferred_lifetime - V_ip6_desync_factor; 2006 ifra.ifra_lifetime.ia6t_vltime = vltime0; 2007 ifra.ifra_lifetime.ia6t_pltime = pltime0; --- 41 unchanged lines hidden (view full) --- 2049} 2050 2051static int 2052in6_init_prefix_ltimes(struct nd_prefix *ndpr) 2053{ 2054 if (ndpr->ndpr_pltime == ND6_INFINITE_LIFETIME) 2055 ndpr->ndpr_preferred = 0; 2056 else | 2000 if (pltime0 > V_ip6_temp_preferred_lifetime - V_ip6_desync_factor){ 2001 pltime0 = V_ip6_temp_preferred_lifetime - 2002 V_ip6_desync_factor; 2003 } 2004 } else 2005 pltime0 = V_ip6_temp_preferred_lifetime - V_ip6_desync_factor; 2006 ifra.ifra_lifetime.ia6t_vltime = vltime0; 2007 ifra.ifra_lifetime.ia6t_pltime = pltime0; --- 41 unchanged lines hidden (view full) --- 2049} 2050 2051static int 2052in6_init_prefix_ltimes(struct nd_prefix *ndpr) 2053{ 2054 if (ndpr->ndpr_pltime == ND6_INFINITE_LIFETIME) 2055 ndpr->ndpr_preferred = 0; 2056 else |
2057 ndpr->ndpr_preferred = time_second + ndpr->ndpr_pltime; | 2057 ndpr->ndpr_preferred = time_uptime + ndpr->ndpr_pltime; |
2058 if (ndpr->ndpr_vltime == ND6_INFINITE_LIFETIME) 2059 ndpr->ndpr_expire = 0; 2060 else | 2058 if (ndpr->ndpr_vltime == ND6_INFINITE_LIFETIME) 2059 ndpr->ndpr_expire = 0; 2060 else |
2061 ndpr->ndpr_expire = time_second + ndpr->ndpr_vltime; | 2061 ndpr->ndpr_expire = time_uptime + ndpr->ndpr_vltime; |
2062 2063 return 0; 2064} 2065 2066static void 2067in6_init_address_ltimes(struct nd_prefix *new, struct in6_addrlifetime *lt6) 2068{ 2069 /* init ia6t_expire */ 2070 if (lt6->ia6t_vltime == ND6_INFINITE_LIFETIME) 2071 lt6->ia6t_expire = 0; 2072 else { | 2062 2063 return 0; 2064} 2065 2066static void 2067in6_init_address_ltimes(struct nd_prefix *new, struct in6_addrlifetime *lt6) 2068{ 2069 /* init ia6t_expire */ 2070 if (lt6->ia6t_vltime == ND6_INFINITE_LIFETIME) 2071 lt6->ia6t_expire = 0; 2072 else { |
2073 lt6->ia6t_expire = time_second; | 2073 lt6->ia6t_expire = time_uptime; |
2074 lt6->ia6t_expire += lt6->ia6t_vltime; 2075 } 2076 2077 /* init ia6t_preferred */ 2078 if (lt6->ia6t_pltime == ND6_INFINITE_LIFETIME) 2079 lt6->ia6t_preferred = 0; 2080 else { | 2074 lt6->ia6t_expire += lt6->ia6t_vltime; 2075 } 2076 2077 /* init ia6t_preferred */ 2078 if (lt6->ia6t_pltime == ND6_INFINITE_LIFETIME) 2079 lt6->ia6t_preferred = 0; 2080 else { |
2081 lt6->ia6t_preferred = time_second; | 2081 lt6->ia6t_preferred = time_uptime; |
2082 lt6->ia6t_preferred += lt6->ia6t_pltime; 2083 } 2084} 2085 2086/* 2087 * Delete all the routing table entries that use the specified gateway. 2088 * XXX: this function causes search through all entries of routing table, so 2089 * it shouldn't be called when acting as a router. --- 84 unchanged lines hidden --- | 2082 lt6->ia6t_preferred += lt6->ia6t_pltime; 2083 } 2084} 2085 2086/* 2087 * Delete all the routing table entries that use the specified gateway. 2088 * XXX: this function causes search through all entries of routing table, so 2089 * it shouldn't be called when acting as a router. --- 84 unchanged lines hidden --- |