Deleted Added
full compact
nd6.c (196481) nd6.c (197138)
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.c,v 1.144 2001/05/24 07:44:00 itojun 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.c,v 1.144 2001/05/24 07:44:00 itojun Exp $
30 */
31
32#include <sys/cdefs.h>
33__FBSDID("$FreeBSD: head/sys/netinet6/nd6.c 196481 2009-08-23 20:40:19Z rwatson $");
33__FBSDID("$FreeBSD: head/sys/netinet6/nd6.c 197138 2009-09-12 22:08:20Z 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/callout.h>
41#include <sys/malloc.h>

--- 23 unchanged lines hidden (view full) ---

65#include <net/if_llatbl.h>
66#define L3_ADDR_SIN6(le) ((struct sockaddr_in6 *) L3_ADDR(le))
67#include <netinet/if_ether.h>
68#include <netinet6/in6_var.h>
69#include <netinet/ip6.h>
70#include <netinet6/ip6_var.h>
71#include <netinet6/scope6_var.h>
72#include <netinet6/nd6.h>
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/callout.h>
41#include <sys/malloc.h>

--- 23 unchanged lines hidden (view full) ---

65#include <net/if_llatbl.h>
66#define L3_ADDR_SIN6(le) ((struct sockaddr_in6 *) L3_ADDR(le))
67#include <netinet/if_ether.h>
68#include <netinet6/in6_var.h>
69#include <netinet/ip6.h>
70#include <netinet6/ip6_var.h>
71#include <netinet6/scope6_var.h>
72#include <netinet6/nd6.h>
73#include <netinet6/in6_ifattach.h>
73#include <netinet/icmp6.h>
74
75#include <sys/limits.h>
76
77#include <security/mac/mac_framework.h>
78
79#define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */
80#define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */

--- 126 unchanged lines hidden (view full) ---

207 bzero(nd, sizeof(*nd));
208
209 nd->initialized = 1;
210
211 nd->chlim = IPV6_DEFHLIM;
212 nd->basereachable = REACHABLE_TIME;
213 nd->reachable = ND_COMPUTE_RTIME(nd->basereachable);
214 nd->retrans = RETRANS_TIMER;
74#include <netinet/icmp6.h>
75
76#include <sys/limits.h>
77
78#include <security/mac/mac_framework.h>
79
80#define ND6_SLOWTIMER_INTERVAL (60 * 60) /* 1 hour */
81#define ND6_RECALC_REACHTM_INTERVAL (60 * 120) /* 2 hours */

--- 126 unchanged lines hidden (view full) ---

208 bzero(nd, sizeof(*nd));
209
210 nd->initialized = 1;
211
212 nd->chlim = IPV6_DEFHLIM;
213 nd->basereachable = REACHABLE_TIME;
214 nd->reachable = ND_COMPUTE_RTIME(nd->basereachable);
215 nd->retrans = RETRANS_TIMER;
215 /*
216 * Note that the default value of ip6_accept_rtadv is 0, which means
217 * we won't accept RAs by default even if we set ND6_IFF_ACCEPT_RTADV
218 * here.
219 */
220 nd->flags = (ND6_IFF_PERFORMNUD | ND6_IFF_ACCEPT_RTADV);
221
216
217 nd->flags = ND6_IFF_PERFORMNUD;
218
219 /* A loopback interface always has ND6_IFF_AUTO_LINKLOCAL. */
220 if (V_ip6_auto_linklocal || (ifp->if_flags & IFF_LOOPBACK))
221 nd->flags |= ND6_IFF_AUTO_LINKLOCAL;
222
223 /* A loopback interface does not need to accept RTADV. */
224 if (V_ip6_accept_rtadv && !(ifp->if_flags & IFF_LOOPBACK))
225 nd->flags |= ND6_IFF_ACCEPT_RTADV;
226
222 /* XXX: we cannot call nd6_setmtu since ifp is not fully initialized */
223 nd6_setmtu0(ifp, nd);
224
225 return nd;
226}
227
228void
229nd6_ifdetach(struct nd_ifinfo *nd)

--- 608 unchanged lines hidden (view full) ---

838 prelist_remove(pr);
839 }
840 }
841
842 /* cancel default outgoing interface setting */
843 if (V_nd6_defifindex == ifp->if_index)
844 nd6_setdefaultiface(0);
845
227 /* XXX: we cannot call nd6_setmtu since ifp is not fully initialized */
228 nd6_setmtu0(ifp, nd);
229
230 return nd;
231}
232
233void
234nd6_ifdetach(struct nd_ifinfo *nd)

--- 608 unchanged lines hidden (view full) ---

843 prelist_remove(pr);
844 }
845 }
846
847 /* cancel default outgoing interface setting */
848 if (V_nd6_defifindex == ifp->if_index)
849 nd6_setdefaultiface(0);
850
846 if (!V_ip6_forwarding && V_ip6_accept_rtadv) { /* XXX: too restrictive? */
847 /* refresh default router list
848 *
849 *
850 */
851 if (!V_ip6_forwarding && ND_IFINFO(ifp)->flags & ND6_IFF_ACCEPT_RTADV) {
852 /* Refresh default router list. */
851 defrouter_select();
853 defrouter_select();
852
853 }
854
855 /* XXXXX
856 * We do not nuke the neighbor cache entries here any more
857 * because the neighbor cache is kept in if_afdata[AF_INET6].
858 * nd6_purge() is invoked by in6_ifdetach() which is called
859 * from if_detach() where everything gets purged. So let
860 * in6_domifdetach() do the actual L2 table purging work.

--- 430 unchanged lines hidden (view full) ---

1291 ND_COMPUTE_RTIME(ND.basereachable);
1292 }
1293 if (ND.retrans != 0)
1294 ND_IFINFO(ifp)->retrans = ND.retrans;
1295 if (ND.chlim != 0)
1296 ND_IFINFO(ifp)->chlim = ND.chlim;
1297 /* FALLTHROUGH */
1298 case SIOCSIFINFO_FLAGS:
854 }
855
856 /* XXXXX
857 * We do not nuke the neighbor cache entries here any more
858 * because the neighbor cache is kept in if_afdata[AF_INET6].
859 * nd6_purge() is invoked by in6_ifdetach() which is called
860 * from if_detach() where everything gets purged. So let
861 * in6_domifdetach() do the actual L2 table purging work.

--- 430 unchanged lines hidden (view full) ---

1292 ND_COMPUTE_RTIME(ND.basereachable);
1293 }
1294 if (ND.retrans != 0)
1295 ND_IFINFO(ifp)->retrans = ND.retrans;
1296 if (ND.chlim != 0)
1297 ND_IFINFO(ifp)->chlim = ND.chlim;
1298 /* FALLTHROUGH */
1299 case SIOCSIFINFO_FLAGS:
1300 {
1301 struct ifaddr *ifa;
1302 struct in6_ifaddr *ia;
1303
1304 if ((ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED) &&
1305 !(ND.flags & ND6_IFF_IFDISABLED)) {
1306 /* ifdisabled 1->0 transision */
1307
1308 /*
1309 * If the interface is marked as ND6_IFF_IFDISABLED and
1310 * has an link-local address with IN6_IFF_DUPLICATED,
1311 * do not clear ND6_IFF_IFDISABLED.
1312 * See RFC 4862, Section 5.4.5.
1313 */
1314 int duplicated_linklocal = 0;
1315
1316 IF_ADDR_LOCK(ifp);
1317 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1318 if (ifa->ifa_addr->sa_family != AF_INET6)
1319 continue;
1320 ia = (struct in6_ifaddr *)ifa;
1321 if ((ia->ia6_flags & IN6_IFF_DUPLICATED) &&
1322 IN6_IS_ADDR_LINKLOCAL(&ia->ia_addr.sin6_addr)) {
1323 duplicated_linklocal = 1;
1324 break;
1325 }
1326 }
1327 IF_ADDR_UNLOCK(ifp);
1328
1329 if (duplicated_linklocal) {
1330 ND.flags |= ND6_IFF_IFDISABLED;
1331 log(LOG_ERR, "Cannot enable an interface"
1332 " with a link-local address marked"
1333 " duplicate.\n");
1334 } else {
1335 ND_IFINFO(ifp)->flags &= ~ND6_IFF_IFDISABLED;
1336 in6_if_up(ifp);
1337 }
1338 } else if (!(ND_IFINFO(ifp)->flags & ND6_IFF_IFDISABLED) &&
1339 (ND.flags & ND6_IFF_IFDISABLED)) {
1340 /* ifdisabled 0->1 transision */
1341 /* Mark all IPv6 address as tentative. */
1342
1343 ND_IFINFO(ifp)->flags |= ND6_IFF_IFDISABLED;
1344 IF_ADDR_LOCK(ifp);
1345 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1346 if (ifa->ifa_addr->sa_family != AF_INET6)
1347 continue;
1348 ia = (struct in6_ifaddr *)ifa;
1349 ia->ia6_flags |= IN6_IFF_TENTATIVE;
1350 }
1351 IF_ADDR_UNLOCK(ifp);
1352 }
1353
1354 if (!(ND_IFINFO(ifp)->flags & ND6_IFF_AUTO_LINKLOCAL) &&
1355 (ND.flags & ND6_IFF_AUTO_LINKLOCAL)) {
1356 /* auto_linklocal 0->1 transision */
1357
1358 /* If no link-local address on ifp, configure */
1359 ND_IFINFO(ifp)->flags |= ND6_IFF_AUTO_LINKLOCAL;
1360 in6_ifattach(ifp, NULL);
1361 }
1362 }
1299 ND_IFINFO(ifp)->flags = ND.flags;
1300 break;
1301#undef ND
1302 case SIOCSNDFLUSH_IN6: /* XXX: the ioctl name is confusing... */
1303 /* sync kernel routing table with the default router list */
1304 defrouter_reset();
1305 defrouter_select();
1306 break;

--- 321 unchanged lines hidden (view full) ---

1628 * address option, defrouter_select() is called twice, since
1629 * defrtrlist_update called the function as well. However, I believe
1630 * we can compromise the overhead, since it only happens the first
1631 * time.
1632 * XXX: although defrouter_select() should not have a bad effect
1633 * for those are not autoconfigured hosts, we explicitly avoid such
1634 * cases for safety.
1635 */
1363 ND_IFINFO(ifp)->flags = ND.flags;
1364 break;
1365#undef ND
1366 case SIOCSNDFLUSH_IN6: /* XXX: the ioctl name is confusing... */
1367 /* sync kernel routing table with the default router list */
1368 defrouter_reset();
1369 defrouter_select();
1370 break;

--- 321 unchanged lines hidden (view full) ---

1692 * address option, defrouter_select() is called twice, since
1693 * defrtrlist_update called the function as well. However, I believe
1694 * we can compromise the overhead, since it only happens the first
1695 * time.
1696 * XXX: although defrouter_select() should not have a bad effect
1697 * for those are not autoconfigured hosts, we explicitly avoid such
1698 * cases for safety.
1699 */
1636 if (do_update && router && !V_ip6_forwarding && V_ip6_accept_rtadv) {
1700 if (do_update && router && !V_ip6_forwarding &&
1701 ND_IFINFO(ifp)->flags & ND6_IFF_ACCEPT_RTADV) {
1637 /*
1638 * guaranteed recursion
1639 */
1640 defrouter_select();
1641 }
1642
1643 return (ln);
1644done:

--- 581 unchanged lines hidden ---
1702 /*
1703 * guaranteed recursion
1704 */
1705 defrouter_select();
1706 }
1707
1708 return (ln);
1709done:

--- 581 unchanged lines hidden ---