Deleted Added
full compact
in6.c (238222) in6.c (238945)
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

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

56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)in.c 8.2 (Berkeley) 11/15/93
61 */
62
63#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

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

56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)in.c 8.2 (Berkeley) 11/15/93
61 */
62
63#include <sys/cdefs.h>
64__FBSDID("$FreeBSD: head/sys/netinet6/in6.c 238222 2012-07-08 08:49:37Z bz $");
64__FBSDID("$FreeBSD: head/sys/netinet6/in6.c 238945 2012-07-31 11:31:12Z glebius $");
65
66#include "opt_compat.h"
67#include "opt_inet.h"
68#include "opt_inet6.h"
69
70#include <sys/param.h>
71#include <sys/errno.h>
72#include <sys/jail.h>

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

252 return (-1);
253 }
254
255 return x * 8 + y;
256}
257
258#ifdef COMPAT_FREEBSD32
259struct in6_ndifreq32 {
65
66#include "opt_compat.h"
67#include "opt_inet.h"
68#include "opt_inet6.h"
69
70#include <sys/param.h>
71#include <sys/errno.h>
72#include <sys/jail.h>

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

252 return (-1);
253 }
254
255 return x * 8 + y;
256}
257
258#ifdef COMPAT_FREEBSD32
259struct in6_ndifreq32 {
260 char ifname[IFNAMSIZ];
261 uint32_t ifindex;
260 char ifname[IFNAMSIZ];
261 uint32_t ifindex;
262};
262};
263#define SIOCGDEFIFACE32_IN6 _IOWR('i', 86, struct in6_ndifreq32)
263#define SIOCGDEFIFACE32_IN6 _IOWR('i', 86, struct in6_ndifreq32)
264#endif
265
266int
267in6_control(struct socket *so, u_long cmd, caddr_t data,
268 struct ifnet *ifp, struct thread *td)
269{
270 struct in6_ifreq *ifr = (struct in6_ifreq *)data;
271 struct in6_ifaddr *ia = NULL;

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

480 */
481 if (ifra->ifra_addr.sin6_family != AF_INET6 ||
482 ifra->ifra_addr.sin6_len != sizeof(struct sockaddr_in6)) {
483 error = EAFNOSUPPORT;
484 goto out;
485 }
486
487 if (td != NULL) {
264#endif
265
266int
267in6_control(struct socket *so, u_long cmd, caddr_t data,
268 struct ifnet *ifp, struct thread *td)
269{
270 struct in6_ifreq *ifr = (struct in6_ifreq *)data;
271 struct in6_ifaddr *ia = NULL;

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

480 */
481 if (ifra->ifra_addr.sin6_family != AF_INET6 ||
482 ifra->ifra_addr.sin6_len != sizeof(struct sockaddr_in6)) {
483 error = EAFNOSUPPORT;
484 goto out;
485 }
486
487 if (td != NULL) {
488 error = priv_check(td, (cmd == SIOCDIFADDR_IN6) ?
488 error = priv_check(td, (cmd == SIOCDIFADDR_IN6) ?
489 PRIV_NET_DELIFADDR : PRIV_NET_ADDIFADDR);
490 if (error)
491 goto out;
492 }
493 break;
494
495 case SIOCGIFADDR_IN6:
496 /* This interface is basically deprecated. use SIOCGIFCONF. */

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

1360 /*
1361 * As for the mltaddr above, proactively prepare the sin6 to avoid
1362 * rtentry un- and re-locking.
1363 */
1364 if (ifa0 != NULL) {
1365 bzero(&sin6, sizeof(sin6));
1366 sin6.sin6_len = sizeof(sin6);
1367 sin6.sin6_family = AF_INET6;
489 PRIV_NET_DELIFADDR : PRIV_NET_ADDIFADDR);
490 if (error)
491 goto out;
492 }
493 break;
494
495 case SIOCGIFADDR_IN6:
496 /* This interface is basically deprecated. use SIOCGIFCONF. */

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

1360 /*
1361 * As for the mltaddr above, proactively prepare the sin6 to avoid
1362 * rtentry un- and re-locking.
1363 */
1364 if (ifa0 != NULL) {
1365 bzero(&sin6, sizeof(sin6));
1366 sin6.sin6_len = sizeof(sin6);
1367 sin6.sin6_family = AF_INET6;
1368 memcpy(&sin6.sin6_addr, &satosin6(ifa0->ifa_addr)->sin6_addr,
1368 memcpy(&sin6.sin6_addr, &satosin6(ifa0->ifa_addr)->sin6_addr,
1369 sizeof(sin6.sin6_addr));
1370 error = in6_setscope(&sin6.sin6_addr, ifa0->ifa_ifp, NULL);
1371 if (error != 0)
1372 return (error);
1373 }
1374
1375 rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB);
1376 if (rt != NULL && rt->rt_gateway != NULL &&
1369 sizeof(sin6.sin6_addr));
1370 error = in6_setscope(&sin6.sin6_addr, ifa0->ifa_ifp, NULL);
1371 if (error != 0)
1372 return (error);
1373 }
1374
1375 rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB);
1376 if (rt != NULL && rt->rt_gateway != NULL &&
1377 (memcmp(&satosin6(rt->rt_gateway)->sin6_addr,
1377 (memcmp(&satosin6(rt->rt_gateway)->sin6_addr,
1378 &ia->ia_addr.sin6_addr,
1379 sizeof(ia->ia_addr.sin6_addr)) == 0)) {
1378 &ia->ia_addr.sin6_addr,
1379 sizeof(ia->ia_addr.sin6_addr)) == 0)) {
1380 /*
1380 /*
1381 * If no more IPv6 address exists on this interface then
1382 * remove the multicast address route.
1383 */
1384 if (ifa0 == NULL) {
1381 * If no more IPv6 address exists on this interface then
1382 * remove the multicast address route.
1383 */
1384 if (ifa0 == NULL) {
1385 memcpy(&mltaddr.sin6_addr, &satosin6(rt_key(rt))->sin6_addr,
1386 sizeof(mltaddr.sin6_addr));
1385 memcpy(&mltaddr.sin6_addr,
1386 &satosin6(rt_key(rt))->sin6_addr,
1387 sizeof(mltaddr.sin6_addr));
1387 RTFREE_LOCKED(rt);
1388 error = in6_rtrequest(RTM_DELETE,
1389 (struct sockaddr *)&mltaddr,
1390 (struct sockaddr *)&ia->ia_addr,
1391 (struct sockaddr *)&mltmask, RTF_UP,
1392 (struct rtentry **)0, RT_DEFAULT_FIB);
1393 if (error)
1394 log(LOG_INFO, "%s: link-local all-nodes "

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

1410 * Remove the node-local all-nodes address.
1411 */
1412 mltaddr.sin6_addr = in6addr_nodelocal_allnodes;
1413 if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0)
1414 return (error);
1415
1416 rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB);
1417 if (rt != NULL && rt->rt_gateway != NULL &&
1388 RTFREE_LOCKED(rt);
1389 error = in6_rtrequest(RTM_DELETE,
1390 (struct sockaddr *)&mltaddr,
1391 (struct sockaddr *)&ia->ia_addr,
1392 (struct sockaddr *)&mltmask, RTF_UP,
1393 (struct rtentry **)0, RT_DEFAULT_FIB);
1394 if (error)
1395 log(LOG_INFO, "%s: link-local all-nodes "

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

1411 * Remove the node-local all-nodes address.
1412 */
1413 mltaddr.sin6_addr = in6addr_nodelocal_allnodes;
1414 if ((error = in6_setscope(&mltaddr.sin6_addr, ifp, NULL)) != 0)
1415 return (error);
1416
1417 rt = in6_rtalloc1((struct sockaddr *)&mltaddr, 0, 0UL, RT_DEFAULT_FIB);
1418 if (rt != NULL && rt->rt_gateway != NULL &&
1418 (memcmp(&satosin6(rt->rt_gateway)->sin6_addr,
1419 (memcmp(&satosin6(rt->rt_gateway)->sin6_addr,
1419 &ia->ia_addr.sin6_addr,
1420 sizeof(ia->ia_addr.sin6_addr)) == 0)) {
1420 &ia->ia_addr.sin6_addr,
1421 sizeof(ia->ia_addr.sin6_addr)) == 0)) {
1421 /*
1422 /*
1422 * If no more IPv6 address exists on this interface then
1423 * remove the multicast address route.
1424 */
1425 if (ifa0 == NULL) {
1423 * If no more IPv6 address exists on this interface then
1424 * remove the multicast address route.
1425 */
1426 if (ifa0 == NULL) {
1426 memcpy(&mltaddr.sin6_addr, &satosin6(rt_key(rt))->sin6_addr,
1427 sizeof(mltaddr.sin6_addr));
1427 memcpy(&mltaddr.sin6_addr,
1428 &satosin6(rt_key(rt))->sin6_addr,
1429 sizeof(mltaddr.sin6_addr));
1428
1429 RTFREE_LOCKED(rt);
1430 error = in6_rtrequest(RTM_DELETE,
1431 (struct sockaddr *)&mltaddr,
1432 (struct sockaddr *)&ia->ia_addr,
1433 (struct sockaddr *)&mltmask, RTF_UP,
1434 (struct rtentry **)0, RT_DEFAULT_FIB);
1435 if (error)

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

1466 * find another IPv6 address as the gateway for the
1467 * link-local and node-local all-nodes multicast
1468 * address routes
1469 */
1470 IF_ADDR_RLOCK(ifp);
1471 TAILQ_FOREACH(ifa0, &ifp->if_addrhead, ifa_link) {
1472 if ((ifa0->ifa_addr->sa_family != AF_INET6) ||
1473 memcmp(&satosin6(ifa0->ifa_addr)->sin6_addr,
1430
1431 RTFREE_LOCKED(rt);
1432 error = in6_rtrequest(RTM_DELETE,
1433 (struct sockaddr *)&mltaddr,
1434 (struct sockaddr *)&ia->ia_addr,
1435 (struct sockaddr *)&mltmask, RTF_UP,
1436 (struct rtentry **)0, RT_DEFAULT_FIB);
1437 if (error)

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

1468 * find another IPv6 address as the gateway for the
1469 * link-local and node-local all-nodes multicast
1470 * address routes
1471 */
1472 IF_ADDR_RLOCK(ifp);
1473 TAILQ_FOREACH(ifa0, &ifp->if_addrhead, ifa_link) {
1474 if ((ifa0->ifa_addr->sa_family != AF_INET6) ||
1475 memcmp(&satosin6(ifa0->ifa_addr)->sin6_addr,
1474 &ia->ia_addr.sin6_addr,
1475 sizeof(struct in6_addr)) == 0)
1476 &ia->ia_addr.sin6_addr, sizeof(struct in6_addr)) == 0)
1476 continue;
1477 else
1478 break;
1479 }
1480 if (ifa0 != NULL)
1481 ifa_ref(ifa0);
1482 IF_ADDR_RUNLOCK(ifp);
1483
1484 /*
1485 * Remove the loopback route to the interface address.
1477 continue;
1478 else
1479 break;
1480 }
1481 if (ifa0 != NULL)
1482 ifa_ref(ifa0);
1483 IF_ADDR_RUNLOCK(ifp);
1484
1485 /*
1486 * Remove the loopback route to the interface address.
1486 * The check for the current setting of "nd6_useloopback"
1487 * The check for the current setting of "nd6_useloopback"
1487 * is not needed.
1488 */
1489 if (ia->ia_flags & IFA_RTSELF) {
1490 error = ifa_del_loopback_route((struct ifaddr *)ia,
1488 * is not needed.
1489 */
1490 if (ia->ia_flags & IFA_RTSELF) {
1491 error = ifa_del_loopback_route((struct ifaddr *)ia,
1491 (struct sockaddr *)&ia->ia_addr);
1492 (struct sockaddr *)&ia->ia_addr);
1492 if (error == 0)
1493 ia->ia_flags &= ~IFA_RTSELF;
1494 }
1495
1496 /* stop DAD processing */
1497 nd6_dad_stop(ifa);
1498
1499 /* Remove local address entry from lltable. */

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

1885 ia->ia_ifa.ifa_metric = ifp->if_metric;
1886
1887 /* we could do in(6)_socktrim here, but just omit it at this moment. */
1888
1889 /*
1890 * Special case:
1891 * If a new destination address is specified for a point-to-point
1892 * interface, install a route to the destination as an interface
1493 if (error == 0)
1494 ia->ia_flags &= ~IFA_RTSELF;
1495 }
1496
1497 /* stop DAD processing */
1498 nd6_dad_stop(ifa);
1499
1500 /* Remove local address entry from lltable. */

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

1886 ia->ia_ifa.ifa_metric = ifp->if_metric;
1887
1888 /* we could do in(6)_socktrim here, but just omit it at this moment. */
1889
1890 /*
1891 * Special case:
1892 * If a new destination address is specified for a point-to-point
1893 * interface, install a route to the destination as an interface
1893 * direct route.
1894 * direct route.
1894 * XXX: the logic below rejects assigning multiple addresses on a p2p
1895 * interface that share the same destination.
1896 */
1897 plen = in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL); /* XXX */
1898 if (!(ia->ia_flags & IFA_ROUTE) && plen == 128 &&
1899 ia->ia_dstaddr.sin6_family == AF_INET6) {
1900 int rtflags = RTF_UP | RTF_HOST;
1901 error = rtinit(&ia->ia_ifa, RTM_ADD, ia->ia_flags | rtflags);

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

1909 ia->ia_flags |= IFA_RTSELF;
1910 }
1911
1912 /*
1913 * add a loopback route to self
1914 */
1915 if (!(ia->ia_flags & IFA_RTSELF) && V_nd6_useloopback) {
1916 error = ifa_add_loopback_route((struct ifaddr *)ia,
1895 * XXX: the logic below rejects assigning multiple addresses on a p2p
1896 * interface that share the same destination.
1897 */
1898 plen = in6_mask2len(&ia->ia_prefixmask.sin6_addr, NULL); /* XXX */
1899 if (!(ia->ia_flags & IFA_ROUTE) && plen == 128 &&
1900 ia->ia_dstaddr.sin6_family == AF_INET6) {
1901 int rtflags = RTF_UP | RTF_HOST;
1902 error = rtinit(&ia->ia_ifa, RTM_ADD, ia->ia_flags | rtflags);

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

1910 ia->ia_flags |= IFA_RTSELF;
1911 }
1912
1913 /*
1914 * add a loopback route to self
1915 */
1916 if (!(ia->ia_flags & IFA_RTSELF) && V_nd6_useloopback) {
1917 error = ifa_add_loopback_route((struct ifaddr *)ia,
1917 (struct sockaddr *)&ia->ia_addr);
1918 (struct sockaddr *)&ia->ia_addr);
1918 if (error == 0)
1919 ia->ia_flags |= IFA_RTSELF;
1920 }
1921
1922 /* Add local address to lltable, if necessary (ex. on p2p link). */
1923 if (newhost)
1924 in6_ifaddloop(&(ia->ia_ifa));
1925

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

1936 struct ifaddr *ifa;
1937
1938 IF_ADDR_RLOCK(ifp);
1939 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1940 if (ifa->ifa_addr->sa_family != AF_INET6)
1941 continue;
1942 if (IN6_IS_ADDR_LINKLOCAL(IFA_IN6(ifa))) {
1943 if ((((struct in6_ifaddr *)ifa)->ia6_flags &
1919 if (error == 0)
1920 ia->ia_flags |= IFA_RTSELF;
1921 }
1922
1923 /* Add local address to lltable, if necessary (ex. on p2p link). */
1924 if (newhost)
1925 in6_ifaddloop(&(ia->ia_ifa));
1926

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

1937 struct ifaddr *ifa;
1938
1939 IF_ADDR_RLOCK(ifp);
1940 TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) {
1941 if (ifa->ifa_addr->sa_family != AF_INET6)
1942 continue;
1943 if (IN6_IS_ADDR_LINKLOCAL(IFA_IN6(ifa))) {
1944 if ((((struct in6_ifaddr *)ifa)->ia6_flags &
1944 ignoreflags) != 0)
1945 ignoreflags) != 0)
1945 continue;
1946 ifa_ref(ifa);
1947 break;
1948 }
1949 }
1950 IF_ADDR_RUNLOCK(ifp);
1951
1952 return ((struct in6_ifaddr *)ifa);

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

2103int
2104in6_is_addr_deprecated(struct sockaddr_in6 *sa6)
2105{
2106 struct in6_ifaddr *ia;
2107
2108 IN6_IFADDR_RLOCK();
2109 TAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) {
2110 if (IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr,
1946 continue;
1947 ifa_ref(ifa);
1948 break;
1949 }
1950 }
1951 IF_ADDR_RUNLOCK(ifp);
1952
1953 return ((struct in6_ifaddr *)ifa);

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

2104int
2105in6_is_addr_deprecated(struct sockaddr_in6 *sa6)
2106{
2107 struct in6_ifaddr *ia;
2108
2109 IN6_IFADDR_RLOCK();
2110 TAILQ_FOREACH(ia, &V_in6_ifaddrhead, ia_link) {
2111 if (IN6_ARE_ADDR_EQUAL(&ia->ia_addr.sin6_addr,
2111 &sa6->sin6_addr) &&
2112 &sa6->sin6_addr) &&
2112 (ia->ia6_flags & IN6_IFF_DEPRECATED) != 0) {
2113 IN6_IFADDR_RUNLOCK();
2114 return (1); /* true */
2115 }
2116
2117 /* XXX: do we still have to go thru the rest of the list? */
2118 }
2119 IN6_IFADDR_RUNLOCK();

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

2374 /* this function can be called during ifnet initialization */
2375 if (!ifp->if_afdata[AF_INET6])
2376 continue;
2377 if ((ifp->if_flags & IFF_LOOPBACK) == 0 &&
2378 IN6_LINKMTU(ifp) > maxmtu)
2379 maxmtu = IN6_LINKMTU(ifp);
2380 }
2381 IFNET_RUNLOCK_NOSLEEP();
2113 (ia->ia6_flags & IN6_IFF_DEPRECATED) != 0) {
2114 IN6_IFADDR_RUNLOCK();
2115 return (1); /* true */
2116 }
2117
2118 /* XXX: do we still have to go thru the rest of the list? */
2119 }
2120 IN6_IFADDR_RUNLOCK();

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

2375 /* this function can be called during ifnet initialization */
2376 if (!ifp->if_afdata[AF_INET6])
2377 continue;
2378 if ((ifp->if_flags & IFF_LOOPBACK) == 0 &&
2379 IN6_LINKMTU(ifp) > maxmtu)
2380 maxmtu = IN6_LINKMTU(ifp);
2381 }
2382 IFNET_RUNLOCK_NOSLEEP();
2382 if (maxmtu) /* update only when maxmtu is positive */
2383 if (maxmtu) /* update only when maxmtu is positive */
2383 V_in6_maxmtu = maxmtu;
2384}
2385
2386/*
2387 * Provide the length of interface identifiers to be used for the link attached
2388 * to the given interface. The length should be defined in "IPv6 over
2389 * xxx-link" document. Note that address architecture might also define
2390 * the length for a particular set of address prefixes, regardless of the

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

2464 free(lle, M_LLTABLE);
2465}
2466
2467static struct llentry *
2468in6_lltable_new(const struct sockaddr *l3addr, u_int flags)
2469{
2470 struct in6_llentry *lle;
2471
2384 V_in6_maxmtu = maxmtu;
2385}
2386
2387/*
2388 * Provide the length of interface identifiers to be used for the link attached
2389 * to the given interface. The length should be defined in "IPv6 over
2390 * xxx-link" document. Note that address architecture might also define
2391 * the length for a particular set of address prefixes, regardless of the

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

2465 free(lle, M_LLTABLE);
2466}
2467
2468static struct llentry *
2469in6_lltable_new(const struct sockaddr *l3addr, u_int flags)
2470{
2471 struct in6_llentry *lle;
2472
2472 lle = malloc(sizeof(struct in6_llentry), M_LLTABLE,
2473 M_DONTWAIT | M_ZERO);
2473 lle = malloc(sizeof(struct in6_llentry), M_LLTABLE, M_NOWAIT | M_ZERO);
2474 if (lle == NULL) /* NB: caller generates msg */
2475 return NULL;
2476
2477 lle->l3_addr6 = *(const struct sockaddr_in6 *)l3addr;
2478 lle->base.lle_refcnt = 1;
2479 lle->base.lle_free = in6_lltable_free;
2480 LLE_LOCK_INIT(&lle->base);
2481 callout_init_rw(&lle->base.ln_timer_ch, &lle->base.lle_lock,
2482 CALLOUT_RETURNUNLOCKED);
2483
2474 if (lle == NULL) /* NB: caller generates msg */
2475 return NULL;
2476
2477 lle->l3_addr6 = *(const struct sockaddr_in6 *)l3addr;
2478 lle->base.lle_refcnt = 1;
2479 lle->base.lle_free = in6_lltable_free;
2480 LLE_LOCK_INIT(&lle->base);
2481 callout_init_rw(&lle->base.ln_timer_ch, &lle->base.lle_lock,
2482 CALLOUT_RETURNUNLOCKED);
2483
2484 return &lle->base;
2484 return (&lle->base);
2485}
2486
2487static void
2485}
2486
2487static void
2488in6_lltable_prefix_free(struct lltable *llt,
2489 const struct sockaddr *prefix,
2490 const struct sockaddr *mask,
2491 u_int flags)
2488in6_lltable_prefix_free(struct lltable *llt, const struct sockaddr *prefix,
2489 const struct sockaddr *mask, u_int flags)
2492{
2493 const struct sockaddr_in6 *pfx = (const struct sockaddr_in6 *)prefix;
2494 const struct sockaddr_in6 *msk = (const struct sockaddr_in6 *)mask;
2495 struct llentry *lle, *next;
2490{
2491 const struct sockaddr_in6 *pfx = (const struct sockaddr_in6 *)prefix;
2492 const struct sockaddr_in6 *msk = (const struct sockaddr_in6 *)mask;
2493 struct llentry *lle, *next;
2496 register int i;
2494 int i;
2497
2498 /*
2495
2496 /*
2499 * (flags & LLE_STATIC) means deleting all entries
2500 * including static ND6 entries
2497 * (flags & LLE_STATIC) means deleting all entries
2498 * including static ND6 entries.
2501 */
2499 */
2502 for (i=0; i < LLTBL_HASHTBL_SIZE; i++) {
2500 for (i = 0; i < LLTBL_HASHTBL_SIZE; i++) {
2503 LIST_FOREACH_SAFE(lle, &llt->lle_head[i], lle_next, next) {
2504 if (IN6_ARE_MASKED_ADDR_EQUAL(
2501 LIST_FOREACH_SAFE(lle, &llt->lle_head[i], lle_next, next) {
2502 if (IN6_ARE_MASKED_ADDR_EQUAL(
2505 &((struct sockaddr_in6 *)L3_ADDR(lle))->sin6_addr,
2506 &pfx->sin6_addr,
2503 &((struct sockaddr_in6 *)L3_ADDR(lle))->sin6_addr,
2504 &pfx->sin6_addr,
2507 &msk->sin6_addr) &&
2508 ((flags & LLE_STATIC) || !(lle->la_flags & LLE_STATIC))) {
2509 int canceled;
2510
2511 canceled = callout_drain(&lle->la_timer);
2512 LLE_WLOCK(lle);
2513 if (canceled)
2514 LLE_REMREF(lle);
2515 llentry_free(lle);
2516 }
2517 }
2518 }
2519}
2520
2521static int
2505 &msk->sin6_addr) &&
2506 ((flags & LLE_STATIC) || !(lle->la_flags & LLE_STATIC))) {
2507 int canceled;
2508
2509 canceled = callout_drain(&lle->la_timer);
2510 LLE_WLOCK(lle);
2511 if (canceled)
2512 LLE_REMREF(lle);
2513 llentry_free(lle);
2514 }
2515 }
2516 }
2517}
2518
2519static int
2522in6_lltable_rtcheck(struct ifnet *ifp,
2523 u_int flags,
2520in6_lltable_rtcheck(struct ifnet *ifp,
2521 u_int flags,
2524 const struct sockaddr *l3addr)
2525{
2526 struct rtentry *rt;
2527 char ip6buf[INET6_ADDRSTRLEN];
2528
2529 KASSERT(l3addr->sa_family == AF_INET6,
2530 ("sin_family %d", l3addr->sa_family));
2531
2532 /* Our local addresses are always only installed on the default FIB. */
2533 /* XXX rtalloc1 should take a const param */
2534 rt = in6_rtalloc1(__DECONST(struct sockaddr *, l3addr), 0, 0,
2535 RT_DEFAULT_FIB);
2536 if (rt == NULL || (rt->rt_flags & RTF_GATEWAY) || rt->rt_ifp != ifp) {
2537 struct ifaddr *ifa;
2522 const struct sockaddr *l3addr)
2523{
2524 struct rtentry *rt;
2525 char ip6buf[INET6_ADDRSTRLEN];
2526
2527 KASSERT(l3addr->sa_family == AF_INET6,
2528 ("sin_family %d", l3addr->sa_family));
2529
2530 /* Our local addresses are always only installed on the default FIB. */
2531 /* XXX rtalloc1 should take a const param */
2532 rt = in6_rtalloc1(__DECONST(struct sockaddr *, l3addr), 0, 0,
2533 RT_DEFAULT_FIB);
2534 if (rt == NULL || (rt->rt_flags & RTF_GATEWAY) || rt->rt_ifp != ifp) {
2535 struct ifaddr *ifa;
2538 /*
2539 * Create an ND6 cache for an IPv6 neighbor
2536 /*
2537 * Create an ND6 cache for an IPv6 neighbor
2540 * that is not covered by our own prefix.
2541 */
2542 /* XXX ifaof_ifpforaddr should take a const param */
2543 ifa = ifaof_ifpforaddr(__DECONST(struct sockaddr *, l3addr), ifp);
2544 if (ifa != NULL) {
2545 ifa_free(ifa);
2546 if (rt != NULL)
2547 RTFREE_LOCKED(rt);

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

2572 ("sin_family %d", l3addr->sa_family));
2573
2574 hashkey = sin6->sin6_addr.s6_addr32[3];
2575 lleh = &llt->lle_head[LLATBL_HASH(hashkey, LLTBL_HASHMASK)];
2576 LIST_FOREACH(lle, lleh, lle_next) {
2577 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)L3_ADDR(lle);
2578 if (lle->la_flags & LLE_DELETED)
2579 continue;
2538 * that is not covered by our own prefix.
2539 */
2540 /* XXX ifaof_ifpforaddr should take a const param */
2541 ifa = ifaof_ifpforaddr(__DECONST(struct sockaddr *, l3addr), ifp);
2542 if (ifa != NULL) {
2543 ifa_free(ifa);
2544 if (rt != NULL)
2545 RTFREE_LOCKED(rt);

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

2570 ("sin_family %d", l3addr->sa_family));
2571
2572 hashkey = sin6->sin6_addr.s6_addr32[3];
2573 lleh = &llt->lle_head[LLATBL_HASH(hashkey, LLTBL_HASHMASK)];
2574 LIST_FOREACH(lle, lleh, lle_next) {
2575 struct sockaddr_in6 *sa6 = (struct sockaddr_in6 *)L3_ADDR(lle);
2576 if (lle->la_flags & LLE_DELETED)
2577 continue;
2580 if (bcmp(&sa6->sin6_addr, &sin6->sin6_addr,
2581 sizeof(struct in6_addr)) == 0)
2578 if (bcmp(&sa6->sin6_addr, &sin6->sin6_addr,
2579 sizeof(struct in6_addr)) == 0)
2582 break;
2583 }
2584
2585 if (lle == NULL) {
2586 if (!(flags & LLE_CREATE))
2587 return (NULL);
2588 /*
2589 * A route that covers the given address must have

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

2796
2797/* Convert sockaddr_in into sockaddr_in6 in v4 mapped addr format. */
2798void
2799in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam)
2800{
2801 struct sockaddr_in *sin_p;
2802 struct sockaddr_in6 *sin6_p;
2803
2580 break;
2581 }
2582
2583 if (lle == NULL) {
2584 if (!(flags & LLE_CREATE))
2585 return (NULL);
2586 /*
2587 * A route that covers the given address must have

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

2794
2795/* Convert sockaddr_in into sockaddr_in6 in v4 mapped addr format. */
2796void
2797in6_sin_2_v4mapsin6_in_sock(struct sockaddr **nam)
2798{
2799 struct sockaddr_in *sin_p;
2800 struct sockaddr_in6 *sin6_p;
2801
2804 sin6_p = malloc(sizeof *sin6_p, M_SONAME,
2805 M_WAITOK);
2802 sin6_p = malloc(sizeof *sin6_p, M_SONAME, M_WAITOK);
2806 sin_p = (struct sockaddr_in *)*nam;
2807 in6_sin_2_v4mapsin6(sin_p, sin6_p);
2808 free(*nam, M_SONAME);
2809 *nam = (struct sockaddr *)sin6_p;
2810}
2803 sin_p = (struct sockaddr_in *)*nam;
2804 in6_sin_2_v4mapsin6(sin_p, sin6_p);
2805 free(*nam, M_SONAME);
2806 *nam = (struct sockaddr *)sin6_p;
2807}