10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51534Spwernau * Common Development and Distribution License (the "License").
61534Spwernau * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*12016SGirish.Moodalbail@Sun.COM * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #include "defs.h"
270Sstevel@tonic-gate #include "tables.h"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <time.h>
303284Sapersson #include <assert.h>
310Sstevel@tonic-gate
320Sstevel@tonic-gate struct phyint *phyints = NULL;
333284Sapersson int num_of_phyints = 0;
340Sstevel@tonic-gate
350Sstevel@tonic-gate static void phyint_print(struct phyint *pi);
360Sstevel@tonic-gate static void phyint_insert(struct phyint *pi);
370Sstevel@tonic-gate
380Sstevel@tonic-gate static boolean_t tmptoken_isvalid(struct in6_addr *token);
390Sstevel@tonic-gate
400Sstevel@tonic-gate static void prefix_print(struct prefix *pr);
410Sstevel@tonic-gate static void prefix_insert(struct phyint *pi, struct prefix *pr);
420Sstevel@tonic-gate static char *prefix_print_state(int state, char *buf, int buflen);
430Sstevel@tonic-gate static void prefix_set(struct in6_addr *prefix, struct in6_addr addr,
440Sstevel@tonic-gate int bits);
450Sstevel@tonic-gate
460Sstevel@tonic-gate static void adv_prefix_print(struct adv_prefix *adv_pr);
470Sstevel@tonic-gate static void adv_prefix_insert(struct phyint *pi, struct adv_prefix *adv_pr);
480Sstevel@tonic-gate static void adv_prefix_delete(struct adv_prefix *adv_pr);
490Sstevel@tonic-gate
500Sstevel@tonic-gate static void router_print(struct router *dr);
510Sstevel@tonic-gate static void router_insert(struct phyint *pi, struct router *dr);
520Sstevel@tonic-gate static void router_delete(struct router *dr);
530Sstevel@tonic-gate static void router_add_k(struct router *dr);
540Sstevel@tonic-gate static void router_delete_k(struct router *dr);
550Sstevel@tonic-gate
560Sstevel@tonic-gate static int rtmseq; /* rtm_seq sequence number */
570Sstevel@tonic-gate
580Sstevel@tonic-gate /* 1 week in ms */
590Sstevel@tonic-gate #define NDP_PREFIX_DEFAULT_LIFETIME (7*24*60*60*1000)
600Sstevel@tonic-gate struct phyint *
phyint_lookup(char * name)610Sstevel@tonic-gate phyint_lookup(char *name)
620Sstevel@tonic-gate {
630Sstevel@tonic-gate struct phyint *pi;
640Sstevel@tonic-gate
650Sstevel@tonic-gate if (debug & D_PHYINT)
660Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_lookup(%s)\n", name);
670Sstevel@tonic-gate
680Sstevel@tonic-gate for (pi = phyints; pi != NULL; pi = pi->pi_next) {
690Sstevel@tonic-gate if (strcmp(pi->pi_name, name) == 0)
700Sstevel@tonic-gate break;
710Sstevel@tonic-gate }
720Sstevel@tonic-gate return (pi);
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate struct phyint *
phyint_lookup_on_index(uint_t ifindex)760Sstevel@tonic-gate phyint_lookup_on_index(uint_t ifindex)
770Sstevel@tonic-gate {
780Sstevel@tonic-gate struct phyint *pi;
790Sstevel@tonic-gate
800Sstevel@tonic-gate if (debug & D_PHYINT)
810Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_lookup_on_index(%d)\n", ifindex);
820Sstevel@tonic-gate
830Sstevel@tonic-gate for (pi = phyints; pi != NULL; pi = pi->pi_next) {
840Sstevel@tonic-gate if (pi->pi_index == ifindex)
850Sstevel@tonic-gate break;
860Sstevel@tonic-gate }
870Sstevel@tonic-gate return (pi);
880Sstevel@tonic-gate }
890Sstevel@tonic-gate
900Sstevel@tonic-gate struct phyint *
phyint_create(char * name)910Sstevel@tonic-gate phyint_create(char *name)
920Sstevel@tonic-gate {
930Sstevel@tonic-gate struct phyint *pi;
940Sstevel@tonic-gate int i;
950Sstevel@tonic-gate
960Sstevel@tonic-gate if (debug & D_PHYINT)
970Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_create(%s)\n", name);
980Sstevel@tonic-gate
990Sstevel@tonic-gate pi = (struct phyint *)calloc(sizeof (struct phyint), 1);
1000Sstevel@tonic-gate if (pi == NULL) {
1010Sstevel@tonic-gate logmsg(LOG_ERR, "phyint_create: out of memory\n");
1020Sstevel@tonic-gate return (NULL);
1030Sstevel@tonic-gate }
1040Sstevel@tonic-gate (void) strncpy(pi->pi_name, name, sizeof (pi->pi_name));
1050Sstevel@tonic-gate pi->pi_name[sizeof (pi->pi_name) - 1] = '\0';
1060Sstevel@tonic-gate
1070Sstevel@tonic-gate /*
1080Sstevel@tonic-gate * Copy the defaults from the defaults array.
1090Sstevel@tonic-gate * Do not copy the cf_notdefault fields since these have not
1100Sstevel@tonic-gate * been explicitly set for the phyint.
1110Sstevel@tonic-gate */
1120Sstevel@tonic-gate for (i = 0; i < I_IFSIZE; i++)
1130Sstevel@tonic-gate pi->pi_config[i].cf_value = ifdefaults[i].cf_value;
1140Sstevel@tonic-gate
1150Sstevel@tonic-gate /*
1160Sstevel@tonic-gate * TmpDesyncFactor is used to desynchronize temporary token
1170Sstevel@tonic-gate * generation among systems; the actual preferred lifetime value
1180Sstevel@tonic-gate * of a temporary address will be (TmpPreferredLifetime -
1190Sstevel@tonic-gate * TmpDesyncFactor). It's a random value, with a user-configurable
1200Sstevel@tonic-gate * maximum value. The value is constant throughout the lifetime
1210Sstevel@tonic-gate * of the in.ndpd process, but can change if the daemon is restarted,
1220Sstevel@tonic-gate * per RFC3041.
1230Sstevel@tonic-gate */
1240Sstevel@tonic-gate if (pi->pi_TmpMaxDesyncFactor != 0) {
1250Sstevel@tonic-gate time_t seed = time(NULL);
1260Sstevel@tonic-gate srand((uint_t)seed);
1270Sstevel@tonic-gate pi->pi_TmpDesyncFactor = rand() % pi->pi_TmpMaxDesyncFactor;
1280Sstevel@tonic-gate /* we actually want [1,max], not [0,(max-1)] */
1290Sstevel@tonic-gate pi->pi_TmpDesyncFactor++;
1300Sstevel@tonic-gate }
1310Sstevel@tonic-gate pi->pi_TmpRegenCountdown = TIMER_INFINITY;
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate pi->pi_sock = -1;
134*12016SGirish.Moodalbail@Sun.COM pi->pi_stateless = pi->pi_StatelessAddrConf;
135*12016SGirish.Moodalbail@Sun.COM pi->pi_stateful = pi->pi_StatefulAddrConf;
136*12016SGirish.Moodalbail@Sun.COM pi->pi_autoconf = _B_TRUE;
137*12016SGirish.Moodalbail@Sun.COM pi->pi_default_token = _B_TRUE;
1380Sstevel@tonic-gate if (phyint_init_from_k(pi) == -1) {
1390Sstevel@tonic-gate free(pi);
1400Sstevel@tonic-gate return (NULL);
1410Sstevel@tonic-gate }
1420Sstevel@tonic-gate phyint_insert(pi);
1430Sstevel@tonic-gate if (pi->pi_sock != -1) {
1440Sstevel@tonic-gate if (poll_add(pi->pi_sock) == -1) {
1450Sstevel@tonic-gate phyint_delete(pi);
1460Sstevel@tonic-gate return (NULL);
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate return (pi);
1500Sstevel@tonic-gate }
1510Sstevel@tonic-gate
1520Sstevel@tonic-gate /* Insert in linked list */
1530Sstevel@tonic-gate static void
phyint_insert(struct phyint * pi)1540Sstevel@tonic-gate phyint_insert(struct phyint *pi)
1550Sstevel@tonic-gate {
1560Sstevel@tonic-gate /* Insert in list */
1570Sstevel@tonic-gate pi->pi_next = phyints;
1580Sstevel@tonic-gate pi->pi_prev = NULL;
1590Sstevel@tonic-gate if (phyints)
1600Sstevel@tonic-gate phyints->pi_prev = pi;
1610Sstevel@tonic-gate phyints = pi;
1623284Sapersson num_of_phyints++;
1630Sstevel@tonic-gate }
1640Sstevel@tonic-gate
1650Sstevel@tonic-gate /*
1660Sstevel@tonic-gate * Initialize both the phyint data structure and the pi_sock for
1670Sstevel@tonic-gate * sending and receving on the interface.
1680Sstevel@tonic-gate * Extract information from the kernel (if present) and set pi_kernel_state.
1690Sstevel@tonic-gate */
1700Sstevel@tonic-gate int
phyint_init_from_k(struct phyint * pi)1710Sstevel@tonic-gate phyint_init_from_k(struct phyint *pi)
1720Sstevel@tonic-gate {
1730Sstevel@tonic-gate struct ipv6_mreq v6mcastr;
1740Sstevel@tonic-gate struct lifreq lifr;
1750Sstevel@tonic-gate int fd;
1768485SPeter.Memishian@Sun.COM int save_errno;
1770Sstevel@tonic-gate boolean_t newsock;
1780Sstevel@tonic-gate uint_t ttl;
1790Sstevel@tonic-gate struct sockaddr_in6 *sin6;
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate if (debug & D_PHYINT)
1820Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_init_from_k(%s)\n", pi->pi_name);
1830Sstevel@tonic-gate
1840Sstevel@tonic-gate start_over:
1850Sstevel@tonic-gate
1860Sstevel@tonic-gate if (pi->pi_sock < 0) {
1870Sstevel@tonic-gate pi->pi_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6);
1880Sstevel@tonic-gate if (pi->pi_sock < 0) {
1890Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: socket");
1900Sstevel@tonic-gate return (-1);
1910Sstevel@tonic-gate }
1920Sstevel@tonic-gate newsock = _B_TRUE;
1930Sstevel@tonic-gate } else {
1940Sstevel@tonic-gate newsock = _B_FALSE;
1950Sstevel@tonic-gate }
1960Sstevel@tonic-gate fd = pi->pi_sock;
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pi->pi_name, sizeof (lifr.lifr_name));
1990Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
2000Sstevel@tonic-gate if (ioctl(fd, SIOCGLIFINDEX, (char *)&lifr) < 0) {
2010Sstevel@tonic-gate if (errno == ENXIO) {
2020Sstevel@tonic-gate if (newsock) {
2030Sstevel@tonic-gate (void) close(pi->pi_sock);
2040Sstevel@tonic-gate pi->pi_sock = -1;
2050Sstevel@tonic-gate }
2060Sstevel@tonic-gate if (debug & D_PHYINT) {
2070Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_init_from_k(%s): "
2080Sstevel@tonic-gate "not exist\n", pi->pi_name);
2090Sstevel@tonic-gate }
2100Sstevel@tonic-gate return (0);
2110Sstevel@tonic-gate }
2120Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: SIOCGLIFINDEX");
2130Sstevel@tonic-gate goto error;
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate
2160Sstevel@tonic-gate if (!newsock && (pi->pi_index != lifr.lifr_index)) {
2170Sstevel@tonic-gate /*
2180Sstevel@tonic-gate * Interface has been re-plumbed, lets open a new socket.
2190Sstevel@tonic-gate * This situation can occur if plumb/unplumb are happening
2200Sstevel@tonic-gate * quite frequently.
2210Sstevel@tonic-gate */
2220Sstevel@tonic-gate
2230Sstevel@tonic-gate phyint_cleanup(pi);
2240Sstevel@tonic-gate goto start_over;
2250Sstevel@tonic-gate }
2260Sstevel@tonic-gate
2270Sstevel@tonic-gate pi->pi_index = lifr.lifr_index;
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate if (ioctl(fd, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
2300Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: ioctl (get flags)");
2310Sstevel@tonic-gate goto error;
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate pi->pi_flags = lifr.lifr_flags;
2340Sstevel@tonic-gate
2350Sstevel@tonic-gate /*
2362546Scarlsonj * If the link local interface is not up yet or it's IFF_UP and the
2372546Scarlsonj * IFF_NOLOCAL flag is set, then ignore the interface.
2380Sstevel@tonic-gate */
2390Sstevel@tonic-gate if (!(pi->pi_flags & IFF_UP) || (pi->pi_flags & IFF_NOLOCAL)) {
2400Sstevel@tonic-gate if (newsock) {
2410Sstevel@tonic-gate (void) close(pi->pi_sock);
2420Sstevel@tonic-gate pi->pi_sock = -1;
2430Sstevel@tonic-gate }
244*12016SGirish.Moodalbail@Sun.COM
2450Sstevel@tonic-gate if (debug & D_PHYINT) {
2460Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_init_from_k(%s): "
2472546Scarlsonj "IFF_NOLOCAL or not IFF_UP\n", pi->pi_name);
2480Sstevel@tonic-gate }
2490Sstevel@tonic-gate return (0);
2500Sstevel@tonic-gate }
2510Sstevel@tonic-gate pi->pi_kernel_state |= PI_PRESENT;
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate if (ioctl(fd, SIOCGLIFMTU, (caddr_t)&lifr) < 0) {
2540Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: ioctl (get mtu)");
2550Sstevel@tonic-gate goto error;
2560Sstevel@tonic-gate }
2570Sstevel@tonic-gate pi->pi_mtu = lifr.lifr_mtu;
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate if (ioctl(fd, SIOCGLIFADDR, (char *)&lifr) < 0) {
2600Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: SIOCGLIFADDR");
2610Sstevel@tonic-gate goto error;
2620Sstevel@tonic-gate }
2630Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
2640Sstevel@tonic-gate pi->pi_ifaddr = sin6->sin6_addr;
2650Sstevel@tonic-gate
266*12016SGirish.Moodalbail@Sun.COM if (pi->pi_autoconf && pi->pi_default_token) {
267*12016SGirish.Moodalbail@Sun.COM if (ioctl(fd, SIOCGLIFTOKEN, (char *)&lifr) < 0) {
268*12016SGirish.Moodalbail@Sun.COM logperror_pi(pi, "phyint_init_from_k: SIOCGLIFTOKEN");
269*12016SGirish.Moodalbail@Sun.COM goto error;
270*12016SGirish.Moodalbail@Sun.COM }
271*12016SGirish.Moodalbail@Sun.COM /* Ignore interface if the token is all zeros */
272*12016SGirish.Moodalbail@Sun.COM sin6 = (struct sockaddr_in6 *)&lifr.lifr_token;
273*12016SGirish.Moodalbail@Sun.COM if (IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr)) {
274*12016SGirish.Moodalbail@Sun.COM logmsg(LOG_ERR, "ignoring interface %s: zero token\n",
275*12016SGirish.Moodalbail@Sun.COM pi->pi_name);
276*12016SGirish.Moodalbail@Sun.COM goto error;
277*12016SGirish.Moodalbail@Sun.COM }
278*12016SGirish.Moodalbail@Sun.COM pi->pi_token = sin6->sin6_addr;
279*12016SGirish.Moodalbail@Sun.COM pi->pi_token_length = lifr.lifr_addrlen;
2800Sstevel@tonic-gate }
2810Sstevel@tonic-gate
2820Sstevel@tonic-gate /*
2830Sstevel@tonic-gate * Guess a remote token for POINTOPOINT by looking at
2840Sstevel@tonic-gate * the link-local destination address.
2850Sstevel@tonic-gate */
2860Sstevel@tonic-gate if (pi->pi_flags & IFF_POINTOPOINT) {
2870Sstevel@tonic-gate if (ioctl(fd, SIOCGLIFDSTADDR, (char *)&lifr) < 0) {
2880Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: SIOCGLIFDSTADDR");
2890Sstevel@tonic-gate goto error;
2900Sstevel@tonic-gate }
2910Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
2920Sstevel@tonic-gate if (sin6->sin6_family != AF_INET6 ||
2930Sstevel@tonic-gate IN6_IS_ADDR_UNSPECIFIED(&sin6->sin6_addr) ||
2940Sstevel@tonic-gate !IN6_IS_ADDR_LINKLOCAL(&sin6->sin6_addr)) {
2950Sstevel@tonic-gate pi->pi_dst_token = in6addr_any;
2960Sstevel@tonic-gate } else {
2970Sstevel@tonic-gate pi->pi_dst_token = sin6->sin6_addr;
2980Sstevel@tonic-gate /* Clear link-local prefix (first 10 bits) */
2990Sstevel@tonic-gate pi->pi_dst_token.s6_addr[0] = 0;
3000Sstevel@tonic-gate pi->pi_dst_token.s6_addr[1] &= 0x3f;
3010Sstevel@tonic-gate }
3020Sstevel@tonic-gate } else {
3030Sstevel@tonic-gate pi->pi_dst_token = in6addr_any;
3040Sstevel@tonic-gate }
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate if (newsock) {
3070Sstevel@tonic-gate icmp6_filter_t filter;
3080Sstevel@tonic-gate int on = 1;
3090Sstevel@tonic-gate
3100Sstevel@tonic-gate /* Set default values */
3110Sstevel@tonic-gate pi->pi_LinkMTU = pi->pi_mtu;
3120Sstevel@tonic-gate pi->pi_CurHopLimit = 0;
3130Sstevel@tonic-gate pi->pi_BaseReachableTime = ND_REACHABLE_TIME;
3140Sstevel@tonic-gate phyint_reach_random(pi, _B_FALSE);
3150Sstevel@tonic-gate pi->pi_RetransTimer = ND_RETRANS_TIMER;
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate /* Setup socket for transmission and reception */
3180Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_IPV6,
3190Sstevel@tonic-gate IPV6_BOUND_IF, (char *)&pi->pi_index,
3200Sstevel@tonic-gate sizeof (pi->pi_index)) < 0) {
3210Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: setsockopt "
3220Sstevel@tonic-gate "IPV6_BOUND_IF");
3230Sstevel@tonic-gate goto error;
3240Sstevel@tonic-gate }
3250Sstevel@tonic-gate
3260Sstevel@tonic-gate ttl = IPV6_MAX_HOPS;
3270Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_IPV6, IPV6_UNICAST_HOPS,
3280Sstevel@tonic-gate (char *)&ttl, sizeof (ttl)) < 0) {
3290Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: setsockopt "
3300Sstevel@tonic-gate "IPV6_UNICAST_HOPS");
3310Sstevel@tonic-gate goto error;
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS,
3350Sstevel@tonic-gate (char *)&ttl, sizeof (ttl)) < 0) {
3360Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: setsockopt "
3370Sstevel@tonic-gate "IPV6_MULTICAST_HOPS");
3380Sstevel@tonic-gate goto error;
3390Sstevel@tonic-gate }
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate v6mcastr.ipv6mr_multiaddr = all_nodes_mcast;
3420Sstevel@tonic-gate v6mcastr.ipv6mr_interface = pi->pi_index;
3430Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
3440Sstevel@tonic-gate (char *)&v6mcastr, sizeof (v6mcastr)) < 0) {
3458485SPeter.Memishian@Sun.COM /*
3468485SPeter.Memishian@Sun.COM * One benign reason IPV6_JOIN_GROUP could fail is
3478485SPeter.Memishian@Sun.COM * when `pi' has been placed into an IPMP group and we
3488485SPeter.Memishian@Sun.COM * haven't yet processed the routing socket message
3498485SPeter.Memishian@Sun.COM * informing us of its disappearance. As such, if
3508485SPeter.Memishian@Sun.COM * it's now in a group, don't print an error.
3518485SPeter.Memishian@Sun.COM */
3528485SPeter.Memishian@Sun.COM save_errno = errno;
3538485SPeter.Memishian@Sun.COM (void) strlcpy(lifr.lifr_name, pi->pi_name, LIFNAMSIZ);
3548485SPeter.Memishian@Sun.COM if (ioctl(fd, SIOCGLIFGROUPNAME, &lifr) == -1 ||
3558485SPeter.Memishian@Sun.COM lifr.lifr_groupname[0] == '\0') {
3568485SPeter.Memishian@Sun.COM errno = save_errno;
3578485SPeter.Memishian@Sun.COM logperror_pi(pi, "phyint_init_from_k: "
3588485SPeter.Memishian@Sun.COM "setsockopt IPV6_JOIN_GROUP");
3598485SPeter.Memishian@Sun.COM }
3600Sstevel@tonic-gate goto error;
3610Sstevel@tonic-gate }
3620Sstevel@tonic-gate pi->pi_state |= PI_JOINED_ALLNODES;
3630Sstevel@tonic-gate pi->pi_kernel_state |= PI_JOINED_ALLNODES;
3640Sstevel@tonic-gate
3650Sstevel@tonic-gate /*
3660Sstevel@tonic-gate * Filter out so that we only receive router advertisements and
3670Sstevel@tonic-gate * router solicitations.
3680Sstevel@tonic-gate */
3690Sstevel@tonic-gate ICMP6_FILTER_SETBLOCKALL(&filter);
3700Sstevel@tonic-gate ICMP6_FILTER_SETPASS(ND_ROUTER_SOLICIT, &filter);
3710Sstevel@tonic-gate ICMP6_FILTER_SETPASS(ND_ROUTER_ADVERT, &filter);
3720Sstevel@tonic-gate
3730Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_ICMPV6, ICMP6_FILTER,
3740Sstevel@tonic-gate (char *)&filter, sizeof (filter)) < 0) {
3750Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: setsockopt "
3760Sstevel@tonic-gate "ICMP6_FILTER");
3770Sstevel@tonic-gate goto error;
3780Sstevel@tonic-gate }
3790Sstevel@tonic-gate
3800Sstevel@tonic-gate /* Enable receipt of ancillary data */
3810Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVHOPLIMIT,
3820Sstevel@tonic-gate (char *)&on, sizeof (on)) < 0) {
3830Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: setsockopt "
3840Sstevel@tonic-gate "IPV6_RECVHOPLIMIT");
3850Sstevel@tonic-gate goto error;
3860Sstevel@tonic-gate }
3870Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_IPV6, IPV6_RECVRTHDR,
3880Sstevel@tonic-gate (char *)&on, sizeof (on)) < 0) {
3890Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: setsockopt "
3900Sstevel@tonic-gate "IPV6_RECVRTHDR");
3910Sstevel@tonic-gate goto error;
3920Sstevel@tonic-gate }
3930Sstevel@tonic-gate }
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate if (pi->pi_AdvSendAdvertisements &&
3960Sstevel@tonic-gate !(pi->pi_kernel_state & PI_JOINED_ALLROUTERS)) {
3970Sstevel@tonic-gate v6mcastr.ipv6mr_multiaddr = all_routers_mcast;
3980Sstevel@tonic-gate v6mcastr.ipv6mr_interface = pi->pi_index;
3990Sstevel@tonic-gate if (setsockopt(fd, IPPROTO_IPV6, IPV6_JOIN_GROUP,
4000Sstevel@tonic-gate (char *)&v6mcastr, sizeof (v6mcastr)) < 0) {
4018485SPeter.Memishian@Sun.COM /*
4028485SPeter.Memishian@Sun.COM * See IPV6_JOIN_GROUP comment above.
4038485SPeter.Memishian@Sun.COM */
4048485SPeter.Memishian@Sun.COM save_errno = errno;
4058485SPeter.Memishian@Sun.COM (void) strlcpy(lifr.lifr_name, pi->pi_name, LIFNAMSIZ);
4068485SPeter.Memishian@Sun.COM if (ioctl(fd, SIOCGLIFGROUPNAME, &lifr) == -1 ||
4078485SPeter.Memishian@Sun.COM lifr.lifr_groupname[0] == '\0') {
4088485SPeter.Memishian@Sun.COM errno = save_errno;
4098485SPeter.Memishian@Sun.COM logperror_pi(pi, "phyint_init_from_k: "
4108485SPeter.Memishian@Sun.COM "setsockopt IPV6_JOIN_GROUP");
4118485SPeter.Memishian@Sun.COM }
4120Sstevel@tonic-gate goto error;
4130Sstevel@tonic-gate }
4140Sstevel@tonic-gate pi->pi_state |= PI_JOINED_ALLROUTERS;
4150Sstevel@tonic-gate pi->pi_kernel_state |= PI_JOINED_ALLROUTERS;
4160Sstevel@tonic-gate }
4170Sstevel@tonic-gate /*
4180Sstevel@tonic-gate * If not already set, set the IFF_ROUTER interface flag based on
4190Sstevel@tonic-gate * AdvSendAdvertisements. Note that this will also enable IPv6
4200Sstevel@tonic-gate * forwarding on the interface. We don't clear IFF_ROUTER if we're
4210Sstevel@tonic-gate * not advertising on an interface, because we could still be
4220Sstevel@tonic-gate * forwarding on those interfaces.
4230Sstevel@tonic-gate */
4240Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pi->pi_name, sizeof (lifr.lifr_name));
4250Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
4260Sstevel@tonic-gate if (ioctl(fd, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
4270Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: SIOCGLIFFLAGS");
4280Sstevel@tonic-gate goto error;
4290Sstevel@tonic-gate }
4300Sstevel@tonic-gate if (!(lifr.lifr_flags & IFF_ROUTER) && pi->pi_AdvSendAdvertisements) {
4310Sstevel@tonic-gate lifr.lifr_flags |= IFF_ROUTER;
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate if (ioctl(fd, SIOCSLIFFLAGS, (char *)&lifr) < 0) {
4340Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: SIOCSLIFFLAGS");
4350Sstevel@tonic-gate goto error;
4360Sstevel@tonic-gate }
4370Sstevel@tonic-gate pi->pi_flags = lifr.lifr_flags;
4380Sstevel@tonic-gate }
4390Sstevel@tonic-gate
4400Sstevel@tonic-gate /* Set linkinfo parameters */
4410Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pi->pi_name, sizeof (lifr.lifr_name));
4420Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
4430Sstevel@tonic-gate lifr.lifr_ifinfo.lir_maxhops = pi->pi_CurHopLimit;
4440Sstevel@tonic-gate lifr.lifr_ifinfo.lir_reachtime = pi->pi_ReachableTime;
4450Sstevel@tonic-gate lifr.lifr_ifinfo.lir_reachretrans = pi->pi_RetransTimer;
4461534Spwernau /* Setting maxmtu to 0 means that we're leaving the MTU alone */
4471534Spwernau lifr.lifr_ifinfo.lir_maxmtu = 0;
4480Sstevel@tonic-gate if (ioctl(fd, SIOCSLIFLNKINFO, (char *)&lifr) < 0) {
4490Sstevel@tonic-gate logperror_pi(pi, "phyint_init_from_k: SIOCSLIFLNKINFO");
4500Sstevel@tonic-gate goto error;
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate if (debug & D_PHYINT) {
4530Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_init_from_k(%s): done\n",
4540Sstevel@tonic-gate pi->pi_name);
4550Sstevel@tonic-gate }
4560Sstevel@tonic-gate return (0);
4570Sstevel@tonic-gate
4580Sstevel@tonic-gate error:
4590Sstevel@tonic-gate /* Pretend the interface does not exist in the kernel */
4600Sstevel@tonic-gate pi->pi_kernel_state &= ~PI_PRESENT;
4610Sstevel@tonic-gate if (newsock) {
4620Sstevel@tonic-gate (void) close(pi->pi_sock);
4630Sstevel@tonic-gate pi->pi_sock = -1;
4640Sstevel@tonic-gate }
4650Sstevel@tonic-gate return (-1);
4660Sstevel@tonic-gate }
4670Sstevel@tonic-gate
4680Sstevel@tonic-gate /*
4690Sstevel@tonic-gate * Delete (unlink and free).
4700Sstevel@tonic-gate * Handles delete of things that have not yet been inserted in the list.
4710Sstevel@tonic-gate */
4720Sstevel@tonic-gate void
phyint_delete(struct phyint * pi)4730Sstevel@tonic-gate phyint_delete(struct phyint *pi)
4740Sstevel@tonic-gate {
4750Sstevel@tonic-gate if (debug & D_PHYINT)
4760Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_delete(%s)\n", pi->pi_name);
4770Sstevel@tonic-gate
4783284Sapersson assert(num_of_phyints > 0);
4793284Sapersson
4800Sstevel@tonic-gate while (pi->pi_router_list)
4810Sstevel@tonic-gate router_delete(pi->pi_router_list);
482*12016SGirish.Moodalbail@Sun.COM while (pi->pi_prefix_list) {
483*12016SGirish.Moodalbail@Sun.COM prefix_update_ipadm_addrobj(pi->pi_prefix_list, _B_FALSE);
4840Sstevel@tonic-gate prefix_delete(pi->pi_prefix_list);
485*12016SGirish.Moodalbail@Sun.COM }
4860Sstevel@tonic-gate while (pi->pi_adv_prefix_list)
4870Sstevel@tonic-gate adv_prefix_delete(pi->pi_adv_prefix_list);
4880Sstevel@tonic-gate
4890Sstevel@tonic-gate if (pi->pi_sock != -1) {
4900Sstevel@tonic-gate (void) poll_remove(pi->pi_sock);
4910Sstevel@tonic-gate if (close(pi->pi_sock) < 0) {
4920Sstevel@tonic-gate logperror_pi(pi, "phyint_delete: close");
4930Sstevel@tonic-gate }
4940Sstevel@tonic-gate pi->pi_sock = -1;
4950Sstevel@tonic-gate }
4960Sstevel@tonic-gate
4970Sstevel@tonic-gate if (pi->pi_prev == NULL) {
4980Sstevel@tonic-gate if (phyints == pi)
4990Sstevel@tonic-gate phyints = pi->pi_next;
5000Sstevel@tonic-gate } else {
5010Sstevel@tonic-gate pi->pi_prev->pi_next = pi->pi_next;
5020Sstevel@tonic-gate }
5030Sstevel@tonic-gate if (pi->pi_next != NULL)
5040Sstevel@tonic-gate pi->pi_next->pi_prev = pi->pi_prev;
5050Sstevel@tonic-gate pi->pi_next = pi->pi_prev = NULL;
5060Sstevel@tonic-gate free(pi);
5073284Sapersson num_of_phyints--;
5080Sstevel@tonic-gate }
5090Sstevel@tonic-gate
5100Sstevel@tonic-gate /*
5116067Smeem * Called with the number of milliseconds elapsed since the last call.
5120Sstevel@tonic-gate * Determines if any timeout event has occurred and
5130Sstevel@tonic-gate * returns the number of milliseconds until the next timeout event
5146067Smeem * for the phyint itself (excluding prefixes and routers).
5150Sstevel@tonic-gate * Returns TIMER_INFINITY for "never".
5160Sstevel@tonic-gate */
5170Sstevel@tonic-gate uint_t
phyint_timer(struct phyint * pi,uint_t elapsed)5180Sstevel@tonic-gate phyint_timer(struct phyint *pi, uint_t elapsed)
5190Sstevel@tonic-gate {
5200Sstevel@tonic-gate uint_t next = TIMER_INFINITY;
5210Sstevel@tonic-gate
5220Sstevel@tonic-gate if (pi->pi_AdvSendAdvertisements) {
5230Sstevel@tonic-gate if (pi->pi_adv_state != NO_ADV) {
5240Sstevel@tonic-gate int old_state = pi->pi_adv_state;
5250Sstevel@tonic-gate
5260Sstevel@tonic-gate if (debug & (D_STATE|D_PHYINT)) {
5270Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_timer ADV(%s) "
5280Sstevel@tonic-gate "state %d\n", pi->pi_name, (int)old_state);
5290Sstevel@tonic-gate }
5300Sstevel@tonic-gate next = advertise_event(pi, ADV_TIMER, elapsed);
5310Sstevel@tonic-gate if (debug & D_STATE) {
5320Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_timer ADV(%s) "
5330Sstevel@tonic-gate "state %d -> %d\n",
5340Sstevel@tonic-gate pi->pi_name, (int)old_state,
5350Sstevel@tonic-gate (int)pi->pi_adv_state);
5360Sstevel@tonic-gate }
5370Sstevel@tonic-gate }
5380Sstevel@tonic-gate } else {
5390Sstevel@tonic-gate if (pi->pi_sol_state != NO_SOLICIT) {
5400Sstevel@tonic-gate int old_state = pi->pi_sol_state;
5410Sstevel@tonic-gate
5420Sstevel@tonic-gate if (debug & (D_STATE|D_PHYINT)) {
5430Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_timer SOL(%s) "
5440Sstevel@tonic-gate "state %d\n", pi->pi_name, (int)old_state);
5450Sstevel@tonic-gate }
5460Sstevel@tonic-gate next = solicit_event(pi, SOL_TIMER, elapsed);
5470Sstevel@tonic-gate if (debug & D_STATE) {
5480Sstevel@tonic-gate logmsg(LOG_DEBUG, "phyint_timer SOL(%s) "
5490Sstevel@tonic-gate "state %d -> %d\n",
5500Sstevel@tonic-gate pi->pi_name, (int)old_state,
5510Sstevel@tonic-gate (int)pi->pi_sol_state);
5520Sstevel@tonic-gate }
5530Sstevel@tonic-gate }
5540Sstevel@tonic-gate }
5550Sstevel@tonic-gate
5560Sstevel@tonic-gate /*
5570Sstevel@tonic-gate * If the phyint has been unplumbed, we don't want to call
5580Sstevel@tonic-gate * phyint_reach_random. We will be in the NO_ADV or NO_SOLICIT state.
5590Sstevel@tonic-gate */
5600Sstevel@tonic-gate if ((pi->pi_AdvSendAdvertisements && (pi->pi_adv_state != NO_ADV)) ||
5610Sstevel@tonic-gate (!pi->pi_AdvSendAdvertisements &&
5620Sstevel@tonic-gate (pi->pi_sol_state != NO_SOLICIT))) {
5630Sstevel@tonic-gate pi->pi_reach_time_since_random += elapsed;
5640Sstevel@tonic-gate if (pi->pi_reach_time_since_random >= MAX_REACH_RANDOM_INTERVAL)
5650Sstevel@tonic-gate phyint_reach_random(pi, _B_TRUE);
5660Sstevel@tonic-gate }
5670Sstevel@tonic-gate
5680Sstevel@tonic-gate return (next);
5690Sstevel@tonic-gate }
5700Sstevel@tonic-gate
5710Sstevel@tonic-gate static void
phyint_print(struct phyint * pi)5720Sstevel@tonic-gate phyint_print(struct phyint *pi)
5730Sstevel@tonic-gate {
5740Sstevel@tonic-gate struct prefix *pr;
5750Sstevel@tonic-gate struct adv_prefix *adv_pr;
5760Sstevel@tonic-gate struct router *dr;
5770Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
5780Sstevel@tonic-gate
5790Sstevel@tonic-gate logmsg(LOG_DEBUG, "Phyint %s index %d state %x, kernel %x, "
5801577Sseb "num routers %d\n",
5811577Sseb pi->pi_name, pi->pi_index, pi->pi_state, pi->pi_kernel_state,
5820Sstevel@tonic-gate pi->pi_num_k_routers);
5838485SPeter.Memishian@Sun.COM logmsg(LOG_DEBUG, "\taddress: %s flags %llx\n",
5840Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pi->pi_ifaddr,
5850Sstevel@tonic-gate abuf, sizeof (abuf)), pi->pi_flags);
5868485SPeter.Memishian@Sun.COM logmsg(LOG_DEBUG, "\tsock %d mtu %d\n", pi->pi_sock, pi->pi_mtu);
5878485SPeter.Memishian@Sun.COM logmsg(LOG_DEBUG, "\ttoken: len %d %s\n", pi->pi_token_length,
5880Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pi->pi_token,
5890Sstevel@tonic-gate abuf, sizeof (abuf)));
5900Sstevel@tonic-gate if (pi->pi_TmpAddrsEnabled) {
5910Sstevel@tonic-gate logmsg(LOG_DEBUG, "\ttmp_token: %s\n",
5920Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pi->pi_tmp_token,
5936067Smeem abuf, sizeof (abuf)));
5940Sstevel@tonic-gate logmsg(LOG_DEBUG, "\ttmp config: pref %d valid %d "
5950Sstevel@tonic-gate "maxdesync %d desync %d regen %d\n",
5960Sstevel@tonic-gate pi->pi_TmpPreferredLifetime, pi->pi_TmpValidLifetime,
5970Sstevel@tonic-gate pi->pi_TmpMaxDesyncFactor, pi->pi_TmpDesyncFactor,
5980Sstevel@tonic-gate pi->pi_TmpRegenAdvance);
5990Sstevel@tonic-gate }
6000Sstevel@tonic-gate if (pi->pi_flags & IFF_POINTOPOINT) {
6010Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tdst_token: %s\n",
6020Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pi->pi_dst_token,
6036067Smeem abuf, sizeof (abuf)));
6040Sstevel@tonic-gate }
6050Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tLinkMTU %d CurHopLimit %d "
6060Sstevel@tonic-gate "BaseReachableTime %d\n\tReachableTime %d RetransTimer %d\n",
6070Sstevel@tonic-gate pi->pi_LinkMTU, pi->pi_CurHopLimit, pi->pi_BaseReachableTime,
6080Sstevel@tonic-gate pi->pi_ReachableTime, pi->pi_RetransTimer);
6090Sstevel@tonic-gate if (!pi->pi_AdvSendAdvertisements) {
6100Sstevel@tonic-gate /* Solicit state */
6110Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tSOLICIT: time_left %d state %d count %d\n",
6120Sstevel@tonic-gate pi->pi_sol_time_left, pi->pi_sol_state, pi->pi_sol_count);
6130Sstevel@tonic-gate } else {
6140Sstevel@tonic-gate /* Advertise state */
6150Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tADVERT: time_left %d state %d count %d "
6160Sstevel@tonic-gate "since last %d\n",
6170Sstevel@tonic-gate pi->pi_adv_time_left, pi->pi_adv_state, pi->pi_adv_count,
6180Sstevel@tonic-gate pi->pi_adv_time_since_sent);
6190Sstevel@tonic-gate print_iflist(pi->pi_config);
6200Sstevel@tonic-gate }
6210Sstevel@tonic-gate for (pr = pi->pi_prefix_list; pr != NULL; pr = pr->pr_next)
6220Sstevel@tonic-gate prefix_print(pr);
6230Sstevel@tonic-gate
6240Sstevel@tonic-gate for (adv_pr = pi->pi_adv_prefix_list; adv_pr != NULL;
6250Sstevel@tonic-gate adv_pr = adv_pr->adv_pr_next) {
6260Sstevel@tonic-gate adv_prefix_print(adv_pr);
6270Sstevel@tonic-gate }
6280Sstevel@tonic-gate
6290Sstevel@tonic-gate for (dr = pi->pi_router_list; dr != NULL; dr = dr->dr_next)
6300Sstevel@tonic-gate router_print(dr);
6310Sstevel@tonic-gate
6320Sstevel@tonic-gate logmsg(LOG_DEBUG, "\n");
6330Sstevel@tonic-gate }
6340Sstevel@tonic-gate
6358485SPeter.Memishian@Sun.COM
6368485SPeter.Memishian@Sun.COM /*
6378485SPeter.Memishian@Sun.COM * Store the LLA for the phyint `pi' `lifrp'. Returns 0 on success, or
6388485SPeter.Memishian@Sun.COM * -1 on failure.
6398485SPeter.Memishian@Sun.COM *
6408485SPeter.Memishian@Sun.COM * Note that we do not cache the hardware address since there's no reliable
6418485SPeter.Memishian@Sun.COM * mechanism to determine when it's become stale.
6428485SPeter.Memishian@Sun.COM */
6438485SPeter.Memishian@Sun.COM int
phyint_get_lla(struct phyint * pi,struct lifreq * lifrp)6448485SPeter.Memishian@Sun.COM phyint_get_lla(struct phyint *pi, struct lifreq *lifrp)
6458485SPeter.Memishian@Sun.COM {
6468485SPeter.Memishian@Sun.COM struct sockaddr_in6 *sin6;
6478485SPeter.Memishian@Sun.COM
6488485SPeter.Memishian@Sun.COM /* If this phyint doesn't have a link-layer address, bail */
6498485SPeter.Memishian@Sun.COM if (!(pi->pi_flags & IFF_MULTICAST) ||
6508485SPeter.Memishian@Sun.COM (pi->pi_flags & IFF_POINTOPOINT)) {
6518485SPeter.Memishian@Sun.COM return (-1);
6528485SPeter.Memishian@Sun.COM }
6538485SPeter.Memishian@Sun.COM
6548485SPeter.Memishian@Sun.COM (void) strlcpy(lifrp->lifr_name, pi->pi_name, LIFNAMSIZ);
6558485SPeter.Memishian@Sun.COM sin6 = (struct sockaddr_in6 *)&(lifrp->lifr_nd.lnr_addr);
6568485SPeter.Memishian@Sun.COM sin6->sin6_family = AF_INET6;
6578485SPeter.Memishian@Sun.COM sin6->sin6_addr = pi->pi_ifaddr;
6588485SPeter.Memishian@Sun.COM if (ioctl(pi->pi_sock, SIOCLIFGETND, lifrp) < 0) {
6598485SPeter.Memishian@Sun.COM /*
6608485SPeter.Memishian@Sun.COM * For IPMP interfaces, don't report ESRCH errors since that
6618485SPeter.Memishian@Sun.COM * merely indicates that there are no active interfaces in the
6628485SPeter.Memishian@Sun.COM * IPMP group (and thus there's no working hardware address),
6638485SPeter.Memishian@Sun.COM * and the packet will thus never make it out anyway.
6648485SPeter.Memishian@Sun.COM */
6658485SPeter.Memishian@Sun.COM if (!(pi->pi_flags & IFF_IPMP) || errno != ESRCH)
6668485SPeter.Memishian@Sun.COM logperror_pi(pi, "phyint_get_lla: SIOCLIFGETND");
6678485SPeter.Memishian@Sun.COM return (-1);
6688485SPeter.Memishian@Sun.COM }
6698485SPeter.Memishian@Sun.COM return (0);
6708485SPeter.Memishian@Sun.COM }
6718485SPeter.Memishian@Sun.COM
6720Sstevel@tonic-gate /*
6730Sstevel@tonic-gate * Randomize pi->pi_ReachableTime.
6740Sstevel@tonic-gate * Done periodically when there are no RAs and at a maximum frequency when
6750Sstevel@tonic-gate * RA's arrive.
6760Sstevel@tonic-gate * Assumes that caller has determined that it is time to generate
6770Sstevel@tonic-gate * a new random ReachableTime.
6780Sstevel@tonic-gate */
6790Sstevel@tonic-gate void
phyint_reach_random(struct phyint * pi,boolean_t set_needed)6800Sstevel@tonic-gate phyint_reach_random(struct phyint *pi, boolean_t set_needed)
6810Sstevel@tonic-gate {
6828485SPeter.Memishian@Sun.COM struct lifreq lifr;
6838485SPeter.Memishian@Sun.COM
6840Sstevel@tonic-gate pi->pi_ReachableTime = GET_RANDOM(
6850Sstevel@tonic-gate (int)(ND_MIN_RANDOM_FACTOR * pi->pi_BaseReachableTime),
6860Sstevel@tonic-gate (int)(ND_MAX_RANDOM_FACTOR * pi->pi_BaseReachableTime));
6870Sstevel@tonic-gate if (set_needed) {
6888485SPeter.Memishian@Sun.COM bzero(&lifr, sizeof (lifr));
6898485SPeter.Memishian@Sun.COM (void) strlcpy(lifr.lifr_name, pi->pi_name, LIFNAMSIZ);
6900Sstevel@tonic-gate lifr.lifr_ifinfo.lir_reachtime = pi->pi_ReachableTime;
6910Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFLNKINFO, (char *)&lifr) < 0) {
6920Sstevel@tonic-gate logperror_pi(pi,
6930Sstevel@tonic-gate "phyint_reach_random: SIOCSLIFLNKINFO");
6940Sstevel@tonic-gate return;
6950Sstevel@tonic-gate }
6960Sstevel@tonic-gate }
6970Sstevel@tonic-gate pi->pi_reach_time_since_random = 0;
6980Sstevel@tonic-gate }
6990Sstevel@tonic-gate
7000Sstevel@tonic-gate /*
7010Sstevel@tonic-gate * Validate a temporary token against a list of known bad values.
7020Sstevel@tonic-gate * Currently assumes that token is 8 bytes long! Current known
7030Sstevel@tonic-gate * bad values include 0, reserved anycast tokens (RFC 2526), tokens
7040Sstevel@tonic-gate * used by ISATAP (draft-ietf-ngtrans-isatap-N), any token already
7050Sstevel@tonic-gate * assigned to this interface, or any token for which the global
7060Sstevel@tonic-gate * bit is set.
7070Sstevel@tonic-gate *
7080Sstevel@tonic-gate * Called by tmptoken_create().
7090Sstevel@tonic-gate *
7100Sstevel@tonic-gate * Return _B_TRUE if token is valid (no match), _B_FALSE if not.
7110Sstevel@tonic-gate */
7120Sstevel@tonic-gate static boolean_t
tmptoken_isvalid(struct in6_addr * token)7130Sstevel@tonic-gate tmptoken_isvalid(struct in6_addr *token)
7140Sstevel@tonic-gate {
7150Sstevel@tonic-gate struct phyint *pi;
7160Sstevel@tonic-gate struct in6_addr mask;
7170Sstevel@tonic-gate struct in6_addr isatap = { 0, 0, 0, 0, 0, 0, 0, 0, \
7180Sstevel@tonic-gate 0, 0, 0x5e, 0xfe, 0, 0, 0, 0 };
7190Sstevel@tonic-gate struct in6_addr anycast = { 0, 0, 0, 0, \
7200Sstevel@tonic-gate 0, 0, 0, 0, \
7210Sstevel@tonic-gate 0xfd, 0xff, 0xff, 0xff, \
7220Sstevel@tonic-gate 0xff, 0xff, 0xff, 0x80 };
7230Sstevel@tonic-gate
7240Sstevel@tonic-gate if (IN6_IS_ADDR_UNSPECIFIED(token))
7250Sstevel@tonic-gate return (_B_FALSE);
7260Sstevel@tonic-gate
7270Sstevel@tonic-gate if (token->s6_addr[8] & 0x2)
7280Sstevel@tonic-gate return (_B_FALSE);
7290Sstevel@tonic-gate
7300Sstevel@tonic-gate (void) memcpy(&mask, token, sizeof (mask));
7310Sstevel@tonic-gate mask._S6_un._S6_u32[3] = 0;
7320Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&isatap, token))
7330Sstevel@tonic-gate return (_B_FALSE);
7340Sstevel@tonic-gate
7350Sstevel@tonic-gate mask._S6_un._S6_u32[3] = token->_S6_un._S6_u32[3] & 0xffffff80;
7360Sstevel@tonic-gate if (IN6_ARE_ADDR_EQUAL(&anycast, token))
7370Sstevel@tonic-gate return (_B_FALSE);
7380Sstevel@tonic-gate
7390Sstevel@tonic-gate for (pi = phyints; pi != NULL; pi = pi->pi_next) {
7400Sstevel@tonic-gate if (((pi->pi_token_length == TMP_TOKEN_BITS) &&
7410Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&pi->pi_token, token)) ||
7420Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&pi->pi_tmp_token, token))
7430Sstevel@tonic-gate return (_B_FALSE);
7440Sstevel@tonic-gate }
7450Sstevel@tonic-gate
7460Sstevel@tonic-gate /* none of our tests failed, must be a good one! */
7470Sstevel@tonic-gate return (_B_TRUE);
7480Sstevel@tonic-gate }
7490Sstevel@tonic-gate
7500Sstevel@tonic-gate /*
7510Sstevel@tonic-gate * Generate a temporary token and set up its timer
7520Sstevel@tonic-gate *
7530Sstevel@tonic-gate * Called from incoming_prefix_addrconf_process() (when token is first
7540Sstevel@tonic-gate * needed) and from tmptoken_timer() (when current token expires).
7550Sstevel@tonic-gate *
7560Sstevel@tonic-gate * Returns _B_TRUE if a token was successfully generated, _B_FALSE if not.
7570Sstevel@tonic-gate */
7580Sstevel@tonic-gate boolean_t
tmptoken_create(struct phyint * pi)7590Sstevel@tonic-gate tmptoken_create(struct phyint *pi)
7600Sstevel@tonic-gate {
7610Sstevel@tonic-gate int fd, i = 0, max_tries = 15;
7620Sstevel@tonic-gate struct in6_addr token;
7630Sstevel@tonic-gate uint32_t *tokenp = &(token._S6_un._S6_u32[2]);
7640Sstevel@tonic-gate char buf[INET6_ADDRSTRLEN];
7650Sstevel@tonic-gate
7660Sstevel@tonic-gate if ((fd = open("/dev/urandom", O_RDONLY)) == -1) {
7670Sstevel@tonic-gate perror("open /dev/urandom");
7680Sstevel@tonic-gate goto no_token;
7690Sstevel@tonic-gate }
7700Sstevel@tonic-gate
7710Sstevel@tonic-gate bzero((char *)&token, sizeof (token));
7720Sstevel@tonic-gate do {
7730Sstevel@tonic-gate if (read(fd, (void *)tokenp, TMP_TOKEN_BYTES) == -1) {
7740Sstevel@tonic-gate perror("read /dev/urandom");
7750Sstevel@tonic-gate (void) close(fd);
7760Sstevel@tonic-gate goto no_token;
7770Sstevel@tonic-gate }
7780Sstevel@tonic-gate
7790Sstevel@tonic-gate /*
7800Sstevel@tonic-gate * Assume EUI-64 formatting, and thus 64-bit
7810Sstevel@tonic-gate * token len; need to clear global bit.
7820Sstevel@tonic-gate */
7830Sstevel@tonic-gate token.s6_addr[8] &= 0xfd;
7840Sstevel@tonic-gate
7850Sstevel@tonic-gate i++;
7860Sstevel@tonic-gate
7870Sstevel@tonic-gate } while (!tmptoken_isvalid(&token) && i < max_tries);
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate (void) close(fd);
7900Sstevel@tonic-gate
7910Sstevel@tonic-gate if (i == max_tries) {
7920Sstevel@tonic-gate no_token:
7930Sstevel@tonic-gate logmsg(LOG_WARNING, "tmptoken_create(%s): failed to create "
7940Sstevel@tonic-gate "token; disabling temporary addresses on %s\n",
7950Sstevel@tonic-gate pi->pi_name, pi->pi_name);
7960Sstevel@tonic-gate pi->pi_TmpAddrsEnabled = 0;
7970Sstevel@tonic-gate return (_B_FALSE);
7980Sstevel@tonic-gate }
7990Sstevel@tonic-gate
8000Sstevel@tonic-gate pi->pi_tmp_token = token;
8010Sstevel@tonic-gate
8020Sstevel@tonic-gate if (debug & D_TMP)
8030Sstevel@tonic-gate logmsg(LOG_DEBUG, "tmptoken_create(%s): created temporary "
8040Sstevel@tonic-gate "token %s\n", pi->pi_name,
8050Sstevel@tonic-gate inet_ntop(AF_INET6, &pi->pi_tmp_token, buf, sizeof (buf)));
8060Sstevel@tonic-gate
8070Sstevel@tonic-gate pi->pi_TmpRegenCountdown = (pi->pi_TmpPreferredLifetime -
8080Sstevel@tonic-gate pi->pi_TmpDesyncFactor - pi->pi_TmpRegenAdvance) * MILLISEC;
8090Sstevel@tonic-gate if (pi->pi_TmpRegenCountdown != 0)
8100Sstevel@tonic-gate timer_schedule(pi->pi_TmpRegenCountdown);
8110Sstevel@tonic-gate
8120Sstevel@tonic-gate return (_B_TRUE);
8130Sstevel@tonic-gate }
8140Sstevel@tonic-gate
8150Sstevel@tonic-gate /*
8160Sstevel@tonic-gate * Delete a temporary token. This is outside the normal timeout process,
8170Sstevel@tonic-gate * so mark any existing addresses based on this token DEPRECATED and set
8180Sstevel@tonic-gate * their preferred lifetime to 0. Don't tamper with valid lifetime, that
8190Sstevel@tonic-gate * will be used to eventually remove the address. Also reset the current
8200Sstevel@tonic-gate * pi_tmp_token value to 0.
8210Sstevel@tonic-gate *
8220Sstevel@tonic-gate * Called from incoming_prefix_addrconf_process() if DAD fails on a temp
8230Sstevel@tonic-gate * addr.
8240Sstevel@tonic-gate */
8250Sstevel@tonic-gate void
tmptoken_delete(struct phyint * pi)8260Sstevel@tonic-gate tmptoken_delete(struct phyint *pi)
8270Sstevel@tonic-gate {
8280Sstevel@tonic-gate struct prefix *pr;
8290Sstevel@tonic-gate
8300Sstevel@tonic-gate for (pr = pi->pi_prefix_list; pr != NULL; pr = pr->pr_next) {
8310Sstevel@tonic-gate if (!(pr->pr_flags & IFF_TEMPORARY) ||
8320Sstevel@tonic-gate (pr->pr_flags & IFF_DEPRECATED) ||
8330Sstevel@tonic-gate (!token_equal(pr->pr_address, pi->pi_tmp_token,
8340Sstevel@tonic-gate TMP_TOKEN_BITS))) {
8350Sstevel@tonic-gate continue;
8360Sstevel@tonic-gate }
8370Sstevel@tonic-gate pr->pr_PreferredLifetime = 0;
8380Sstevel@tonic-gate pr->pr_state |= PR_DEPRECATED;
8390Sstevel@tonic-gate prefix_update_k(pr);
8400Sstevel@tonic-gate }
8410Sstevel@tonic-gate
8420Sstevel@tonic-gate (void) memset(&pi->pi_tmp_token, 0, sizeof (pi->pi_tmp_token));
8430Sstevel@tonic-gate }
8440Sstevel@tonic-gate
8450Sstevel@tonic-gate /*
8460Sstevel@tonic-gate * Called from run_timeouts() with the number of milliseconds elapsed
8470Sstevel@tonic-gate * since the last call. Determines if any timeout event has occurred
8480Sstevel@tonic-gate * and returns the number of milliseconds until the next timeout event
8490Sstevel@tonic-gate * for the tmp token. Returns TIMER_INFINITY for "never".
8500Sstevel@tonic-gate */
8510Sstevel@tonic-gate uint_t
tmptoken_timer(struct phyint * pi,uint_t elapsed)8520Sstevel@tonic-gate tmptoken_timer(struct phyint *pi, uint_t elapsed)
8530Sstevel@tonic-gate {
8540Sstevel@tonic-gate struct nd_opt_prefix_info opt;
8550Sstevel@tonic-gate struct sockaddr_in6 sin6;
8560Sstevel@tonic-gate struct prefix *pr, *newpr;
8570Sstevel@tonic-gate
8580Sstevel@tonic-gate if (debug & D_TMP) {
8590Sstevel@tonic-gate logmsg(LOG_DEBUG, "tmptoken_timer(%s, %d) regencountdown %d\n",
8600Sstevel@tonic-gate pi->pi_name, (int)elapsed, pi->pi_TmpRegenCountdown);
8610Sstevel@tonic-gate }
8620Sstevel@tonic-gate if (!pi->pi_TmpAddrsEnabled ||
8630Sstevel@tonic-gate (pi->pi_TmpRegenCountdown == TIMER_INFINITY))
8640Sstevel@tonic-gate return (TIMER_INFINITY);
8650Sstevel@tonic-gate
8660Sstevel@tonic-gate if (pi->pi_TmpRegenCountdown > elapsed) {
8670Sstevel@tonic-gate pi->pi_TmpRegenCountdown -= elapsed;
8680Sstevel@tonic-gate return (pi->pi_TmpRegenCountdown);
8690Sstevel@tonic-gate }
8700Sstevel@tonic-gate
8710Sstevel@tonic-gate /*
8720Sstevel@tonic-gate * Tmp token timer has expired. Start by generating a new token.
8730Sstevel@tonic-gate * If we can't get a new token, tmp addrs are disabled on this
8740Sstevel@tonic-gate * interface, so there's no need to continue, or to set a timer.
8750Sstevel@tonic-gate */
8760Sstevel@tonic-gate if (!tmptoken_create(pi))
8770Sstevel@tonic-gate return (TIMER_INFINITY);
8780Sstevel@tonic-gate
8790Sstevel@tonic-gate /*
8800Sstevel@tonic-gate * Now that we have a new token, walk the list of prefixes to
8810Sstevel@tonic-gate * find which ones need a corresponding tmp addr generated.
8820Sstevel@tonic-gate */
8830Sstevel@tonic-gate for (pr = pi->pi_prefix_list; pr != NULL; pr = pr->pr_next) {
8840Sstevel@tonic-gate
8850Sstevel@tonic-gate if (!(pr->pr_state & PR_AUTO) || pr->pr_state & PR_STATIC ||
8860Sstevel@tonic-gate pr->pr_state & PR_DEPRECATED ||
8870Sstevel@tonic-gate pr->pr_flags & IFF_TEMPORARY)
8880Sstevel@tonic-gate continue;
8890Sstevel@tonic-gate
8900Sstevel@tonic-gate newpr = prefix_create(pi, pr->pr_prefix, pr->pr_prefix_len,
8910Sstevel@tonic-gate IFF_TEMPORARY);
8920Sstevel@tonic-gate if (newpr == NULL) {
8930Sstevel@tonic-gate char pbuf[INET6_ADDRSTRLEN];
8940Sstevel@tonic-gate char tbuf[INET6_ADDRSTRLEN];
8950Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &pr->pr_prefix, pbuf,
8960Sstevel@tonic-gate sizeof (pbuf));
8970Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &pi->pi_tmp_token, tbuf,
8980Sstevel@tonic-gate sizeof (tbuf));
8990Sstevel@tonic-gate logmsg(LOG_ERR, "can't create new tmp addr "
9000Sstevel@tonic-gate "(%s, %s, %s)\n", pi->pi_name, pbuf, tbuf);
9010Sstevel@tonic-gate continue;
9020Sstevel@tonic-gate }
9030Sstevel@tonic-gate
9040Sstevel@tonic-gate /*
9050Sstevel@tonic-gate * We want to use incoming_prefix_*_process() functions to
9060Sstevel@tonic-gate * set up the new tmp addr, so cobble together a prefix
9070Sstevel@tonic-gate * info option struct based on the existing prefix to pass
9080Sstevel@tonic-gate * in. The lifetimes will be based on the current time
9090Sstevel@tonic-gate * remaining.
9100Sstevel@tonic-gate *
9110Sstevel@tonic-gate * The "from" param is only used for messages; pass in
9120Sstevel@tonic-gate * ::0 for that.
9130Sstevel@tonic-gate */
9140Sstevel@tonic-gate opt.nd_opt_pi_type = ND_OPT_PREFIX_INFORMATION;
9150Sstevel@tonic-gate opt.nd_opt_pi_len = sizeof (opt) / 8;
9160Sstevel@tonic-gate opt.nd_opt_pi_prefix_len = pr->pr_prefix_len;
9170Sstevel@tonic-gate opt.nd_opt_pi_flags_reserved = ND_OPT_PI_FLAG_AUTO;
9180Sstevel@tonic-gate opt.nd_opt_pi_valid_time =
9190Sstevel@tonic-gate htonl(pr->pr_ValidLifetime / 1000);
9200Sstevel@tonic-gate opt.nd_opt_pi_preferred_time =
9210Sstevel@tonic-gate htonl(pr->pr_PreferredLifetime / 1000);
9220Sstevel@tonic-gate if (pr->pr_state & PR_ONLINK)
9230Sstevel@tonic-gate opt.nd_opt_pi_flags_reserved &= ND_OPT_PI_FLAG_ONLINK;
9240Sstevel@tonic-gate opt.nd_opt_pi_prefix = pr->pr_prefix;
9250Sstevel@tonic-gate
9260Sstevel@tonic-gate (void) memset(&sin6, 0, sizeof (sin6));
9270Sstevel@tonic-gate
9280Sstevel@tonic-gate if (!incoming_prefix_addrconf_process(pi, newpr,
9290Sstevel@tonic-gate (uchar_t *)&opt, &sin6, _B_FALSE, _B_TRUE)) {
9300Sstevel@tonic-gate char pbuf[INET6_ADDRSTRLEN];
9310Sstevel@tonic-gate char tbuf[INET6_ADDRSTRLEN];
9320Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &pr->pr_prefix, pbuf,
9330Sstevel@tonic-gate sizeof (pbuf));
9340Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &pi->pi_tmp_token, tbuf,
9350Sstevel@tonic-gate sizeof (tbuf));
9360Sstevel@tonic-gate logmsg(LOG_ERR, "can't create new tmp addr "
9370Sstevel@tonic-gate "(%s, %s, %s)\n", pi->pi_name, pbuf, tbuf);
9380Sstevel@tonic-gate continue;
9390Sstevel@tonic-gate }
9400Sstevel@tonic-gate
9410Sstevel@tonic-gate if (pr->pr_state & PR_ONLINK) {
9420Sstevel@tonic-gate incoming_prefix_onlink_process(newpr, (uchar_t *)&opt);
9430Sstevel@tonic-gate }
9440Sstevel@tonic-gate }
9450Sstevel@tonic-gate
9460Sstevel@tonic-gate /*
9470Sstevel@tonic-gate * appropriate timers were scheduled when
9480Sstevel@tonic-gate * the token and addresses were created.
9490Sstevel@tonic-gate */
9500Sstevel@tonic-gate return (TIMER_INFINITY);
9510Sstevel@tonic-gate }
9520Sstevel@tonic-gate
9530Sstevel@tonic-gate /*
9540Sstevel@tonic-gate * tlen specifies the token length in bits. Compares the lower
9550Sstevel@tonic-gate * tlen bits of the two addresses provided and returns _B_TRUE if
9560Sstevel@tonic-gate * they match, _B_FALSE if not. Also returns _B_FALSE for invalid
9570Sstevel@tonic-gate * values of tlen.
9580Sstevel@tonic-gate */
9590Sstevel@tonic-gate boolean_t
token_equal(struct in6_addr t1,struct in6_addr t2,int tlen)9600Sstevel@tonic-gate token_equal(struct in6_addr t1, struct in6_addr t2, int tlen)
9610Sstevel@tonic-gate {
9620Sstevel@tonic-gate uchar_t mask;
9630Sstevel@tonic-gate int j, abytes, tbytes, tbits;
9640Sstevel@tonic-gate
9650Sstevel@tonic-gate if (tlen < 0 || tlen > IPV6_ABITS)
9660Sstevel@tonic-gate return (_B_FALSE);
9670Sstevel@tonic-gate
9680Sstevel@tonic-gate abytes = IPV6_ABITS >> 3;
9690Sstevel@tonic-gate tbytes = tlen >> 3;
9700Sstevel@tonic-gate tbits = tlen & 7;
9710Sstevel@tonic-gate
9720Sstevel@tonic-gate for (j = abytes - 1; j >= abytes - tbytes; j--)
9730Sstevel@tonic-gate if (t1.s6_addr[j] != t2.s6_addr[j])
9740Sstevel@tonic-gate return (_B_FALSE);
9750Sstevel@tonic-gate
9760Sstevel@tonic-gate if (tbits == 0)
9770Sstevel@tonic-gate return (_B_TRUE);
9780Sstevel@tonic-gate
9790Sstevel@tonic-gate /* We only care about the tbits rightmost bits */
9800Sstevel@tonic-gate mask = 0xff >> (8 - tbits);
9810Sstevel@tonic-gate if ((t1.s6_addr[j] & mask) != (t2.s6_addr[j] & mask))
9820Sstevel@tonic-gate return (_B_FALSE);
9830Sstevel@tonic-gate
9840Sstevel@tonic-gate return (_B_TRUE);
9850Sstevel@tonic-gate }
9860Sstevel@tonic-gate
9870Sstevel@tonic-gate /*
9880Sstevel@tonic-gate * Lookup prefix structure that matches the prefix and prefix length.
9890Sstevel@tonic-gate * Assumes that the bits after prefixlen might not be zero.
9900Sstevel@tonic-gate */
9910Sstevel@tonic-gate static struct prefix *
prefix_lookup(struct phyint * pi,struct in6_addr prefix,int prefixlen)9920Sstevel@tonic-gate prefix_lookup(struct phyint *pi, struct in6_addr prefix, int prefixlen)
9930Sstevel@tonic-gate {
9940Sstevel@tonic-gate struct prefix *pr;
9950Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
9960Sstevel@tonic-gate
9970Sstevel@tonic-gate if (debug & D_PREFIX) {
9980Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_lookup(%s, %s/%u)\n", pi->pi_name,
9990Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&prefix,
10000Sstevel@tonic-gate abuf, sizeof (abuf)), prefixlen);
10010Sstevel@tonic-gate }
10020Sstevel@tonic-gate
10030Sstevel@tonic-gate for (pr = pi->pi_prefix_list; pr != NULL; pr = pr->pr_next) {
10040Sstevel@tonic-gate if (pr->pr_prefix_len == prefixlen &&
10050Sstevel@tonic-gate prefix_equal(prefix, pr->pr_prefix, prefixlen))
10060Sstevel@tonic-gate return (pr);
10070Sstevel@tonic-gate }
10080Sstevel@tonic-gate return (NULL);
10090Sstevel@tonic-gate }
10100Sstevel@tonic-gate
10110Sstevel@tonic-gate /*
10120Sstevel@tonic-gate * Compare two prefixes that have the same prefix length.
10130Sstevel@tonic-gate * Fails if the prefix length is unreasonable.
10140Sstevel@tonic-gate */
10150Sstevel@tonic-gate boolean_t
prefix_equal(struct in6_addr p1,struct in6_addr p2,int plen)10160Sstevel@tonic-gate prefix_equal(struct in6_addr p1, struct in6_addr p2, int plen)
10170Sstevel@tonic-gate {
10180Sstevel@tonic-gate uchar_t mask;
10190Sstevel@tonic-gate int j, pbytes, pbits;
10200Sstevel@tonic-gate
10210Sstevel@tonic-gate if (plen < 0 || plen > IPV6_ABITS)
10220Sstevel@tonic-gate return (_B_FALSE);
10230Sstevel@tonic-gate
10240Sstevel@tonic-gate pbytes = plen >> 3;
10250Sstevel@tonic-gate pbits = plen & 7;
10260Sstevel@tonic-gate
10270Sstevel@tonic-gate for (j = 0; j < pbytes; j++)
10280Sstevel@tonic-gate if (p1.s6_addr[j] != p2.s6_addr[j])
10290Sstevel@tonic-gate return (_B_FALSE);
10300Sstevel@tonic-gate
10310Sstevel@tonic-gate if (pbits == 0)
10320Sstevel@tonic-gate return (_B_TRUE);
10330Sstevel@tonic-gate
10340Sstevel@tonic-gate /* Make the N leftmost bits one */
10350Sstevel@tonic-gate mask = 0xff << (8 - pbits);
10360Sstevel@tonic-gate if ((p1.s6_addr[j] & mask) != (p2.s6_addr[j] & mask))
10370Sstevel@tonic-gate return (_B_FALSE);
10380Sstevel@tonic-gate
10390Sstevel@tonic-gate return (_B_TRUE);
10400Sstevel@tonic-gate }
10410Sstevel@tonic-gate
10420Sstevel@tonic-gate /*
10430Sstevel@tonic-gate * Set a prefix from an address and a prefix length.
10440Sstevel@tonic-gate * Force all the bits after the prefix length to be zero.
10450Sstevel@tonic-gate */
10460Sstevel@tonic-gate void
prefix_set(struct in6_addr * prefix,struct in6_addr addr,int prefix_len)10470Sstevel@tonic-gate prefix_set(struct in6_addr *prefix, struct in6_addr addr, int prefix_len)
10480Sstevel@tonic-gate {
10490Sstevel@tonic-gate uchar_t mask;
10500Sstevel@tonic-gate int j;
10510Sstevel@tonic-gate
10520Sstevel@tonic-gate if (prefix_len < 0 || prefix_len > IPV6_ABITS)
10530Sstevel@tonic-gate return;
10540Sstevel@tonic-gate
10550Sstevel@tonic-gate bzero((char *)prefix, sizeof (*prefix));
10560Sstevel@tonic-gate
10570Sstevel@tonic-gate for (j = 0; prefix_len > 8; prefix_len -= 8, j++)
10580Sstevel@tonic-gate prefix->s6_addr[j] = addr.s6_addr[j];
10590Sstevel@tonic-gate
10600Sstevel@tonic-gate /* Make the N leftmost bits one */
10610Sstevel@tonic-gate mask = 0xff << (8 - prefix_len);
10620Sstevel@tonic-gate prefix->s6_addr[j] = addr.s6_addr[j] & mask;
10630Sstevel@tonic-gate }
10640Sstevel@tonic-gate
10650Sstevel@tonic-gate /*
10660Sstevel@tonic-gate * Lookup a prefix based on the kernel's interface name.
10670Sstevel@tonic-gate */
10680Sstevel@tonic-gate struct prefix *
prefix_lookup_name(struct phyint * pi,char * name)10690Sstevel@tonic-gate prefix_lookup_name(struct phyint *pi, char *name)
10700Sstevel@tonic-gate {
10710Sstevel@tonic-gate struct prefix *pr;
10720Sstevel@tonic-gate
10730Sstevel@tonic-gate if (debug & D_PREFIX) {
10740Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_lookup_name(%s, %s)\n",
10750Sstevel@tonic-gate pi->pi_name, name);
10760Sstevel@tonic-gate }
10770Sstevel@tonic-gate if (name[0] == '\0')
10780Sstevel@tonic-gate return (NULL);
10790Sstevel@tonic-gate
10800Sstevel@tonic-gate for (pr = pi->pi_prefix_list; pr != NULL; pr = pr->pr_next) {
10810Sstevel@tonic-gate if (strcmp(name, pr->pr_name) == 0)
10820Sstevel@tonic-gate return (pr);
10830Sstevel@tonic-gate }
10840Sstevel@tonic-gate return (NULL);
10850Sstevel@tonic-gate }
10860Sstevel@tonic-gate
10870Sstevel@tonic-gate /*
10880Sstevel@tonic-gate * Search the phyints list to make sure that this new prefix does
10890Sstevel@tonic-gate * not already exist in any other physical interfaces that have
10900Sstevel@tonic-gate * the same address as this one
10910Sstevel@tonic-gate */
10920Sstevel@tonic-gate struct prefix *
prefix_lookup_addr_match(struct prefix * pr)10930Sstevel@tonic-gate prefix_lookup_addr_match(struct prefix *pr)
10940Sstevel@tonic-gate {
10950Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
10960Sstevel@tonic-gate struct phyint *pi;
10970Sstevel@tonic-gate struct prefix *otherpr = NULL;
10980Sstevel@tonic-gate struct in6_addr prefix;
10990Sstevel@tonic-gate int prefixlen;
11000Sstevel@tonic-gate
11010Sstevel@tonic-gate if (debug & D_PREFIX) {
11020Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_lookup_addr_match(%s/%u)\n",
11030Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_address,
11040Sstevel@tonic-gate abuf, sizeof (abuf)), pr->pr_prefix_len);
11050Sstevel@tonic-gate }
11060Sstevel@tonic-gate prefix = pr->pr_prefix;
11070Sstevel@tonic-gate prefixlen = pr->pr_prefix_len;
11080Sstevel@tonic-gate for (pi = phyints; pi != NULL; pi = pi->pi_next) {
11090Sstevel@tonic-gate otherpr = prefix_lookup(pi, prefix, prefixlen);
11100Sstevel@tonic-gate if (otherpr == pr)
11110Sstevel@tonic-gate continue;
11120Sstevel@tonic-gate if (otherpr != NULL && (otherpr->pr_state & PR_AUTO) &&
11130Sstevel@tonic-gate IN6_ARE_ADDR_EQUAL(&pr->pr_address,
11140Sstevel@tonic-gate &otherpr->pr_address))
11150Sstevel@tonic-gate return (otherpr);
11160Sstevel@tonic-gate }
11170Sstevel@tonic-gate return (NULL);
11180Sstevel@tonic-gate }
11190Sstevel@tonic-gate
11200Sstevel@tonic-gate /*
11210Sstevel@tonic-gate * Initialize a new prefix without setting lifetimes etc.
11220Sstevel@tonic-gate */
11230Sstevel@tonic-gate struct prefix *
prefix_create(struct phyint * pi,struct in6_addr prefix,int prefixlen,uint64_t flags)11240Sstevel@tonic-gate prefix_create(struct phyint *pi, struct in6_addr prefix, int prefixlen,
11250Sstevel@tonic-gate uint64_t flags)
11260Sstevel@tonic-gate {
11270Sstevel@tonic-gate struct prefix *pr;
11280Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
11290Sstevel@tonic-gate
11300Sstevel@tonic-gate if (debug & D_PREFIX) {
11310Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_create(%s, %s/%u, 0x%llx)\n",
11320Sstevel@tonic-gate pi->pi_name, inet_ntop(AF_INET6, (void *)&prefix,
11330Sstevel@tonic-gate abuf, sizeof (abuf)), prefixlen, flags);
11340Sstevel@tonic-gate }
11350Sstevel@tonic-gate pr = (struct prefix *)calloc(sizeof (struct prefix), 1);
11360Sstevel@tonic-gate if (pr == NULL) {
11370Sstevel@tonic-gate logmsg(LOG_ERR, "prefix_create: out of memory\n");
11380Sstevel@tonic-gate return (NULL);
11390Sstevel@tonic-gate }
11400Sstevel@tonic-gate /*
11410Sstevel@tonic-gate * The prefix might have non-zero bits after the prefix len bits.
11420Sstevel@tonic-gate * Force them to be zero.
11430Sstevel@tonic-gate */
11440Sstevel@tonic-gate prefix_set(&pr->pr_prefix, prefix, prefixlen);
11450Sstevel@tonic-gate pr->pr_prefix_len = prefixlen;
11460Sstevel@tonic-gate pr->pr_PreferredLifetime = PREFIX_INFINITY;
11470Sstevel@tonic-gate pr->pr_ValidLifetime = PREFIX_INFINITY;
11480Sstevel@tonic-gate pr->pr_OnLinkLifetime = PREFIX_INFINITY;
11490Sstevel@tonic-gate pr->pr_kernel_state = 0;
11500Sstevel@tonic-gate pr->pr_flags |= flags;
11510Sstevel@tonic-gate prefix_insert(pi, pr);
11520Sstevel@tonic-gate return (pr);
11530Sstevel@tonic-gate }
11540Sstevel@tonic-gate
11550Sstevel@tonic-gate /*
11560Sstevel@tonic-gate * Create a new named prefix. Caller should use prefix_init_from_k
11570Sstevel@tonic-gate * to initialize the content.
11580Sstevel@tonic-gate */
11590Sstevel@tonic-gate struct prefix *
prefix_create_name(struct phyint * pi,char * name)11600Sstevel@tonic-gate prefix_create_name(struct phyint *pi, char *name)
11610Sstevel@tonic-gate {
11620Sstevel@tonic-gate struct prefix *pr;
11630Sstevel@tonic-gate
11640Sstevel@tonic-gate if (debug & D_PREFIX) {
11650Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_create_name(%s, %s)\n",
11660Sstevel@tonic-gate pi->pi_name, name);
11670Sstevel@tonic-gate }
11680Sstevel@tonic-gate pr = (struct prefix *)calloc(sizeof (struct prefix), 1);
11690Sstevel@tonic-gate if (pr == NULL) {
11700Sstevel@tonic-gate logmsg(LOG_ERR, "prefix_create_name: out of memory\n");
11710Sstevel@tonic-gate return (NULL);
11720Sstevel@tonic-gate }
11730Sstevel@tonic-gate (void) strncpy(pr->pr_name, name, sizeof (pr->pr_name));
11740Sstevel@tonic-gate pr->pr_name[sizeof (pr->pr_name) - 1] = '\0';
11750Sstevel@tonic-gate prefix_insert(pi, pr);
11760Sstevel@tonic-gate return (pr);
11770Sstevel@tonic-gate }
11780Sstevel@tonic-gate
11790Sstevel@tonic-gate /* Insert in linked list */
11800Sstevel@tonic-gate static void
prefix_insert(struct phyint * pi,struct prefix * pr)11810Sstevel@tonic-gate prefix_insert(struct phyint *pi, struct prefix *pr)
11820Sstevel@tonic-gate {
11830Sstevel@tonic-gate pr->pr_next = pi->pi_prefix_list;
11840Sstevel@tonic-gate pr->pr_prev = NULL;
11850Sstevel@tonic-gate if (pi->pi_prefix_list != NULL)
11860Sstevel@tonic-gate pi->pi_prefix_list->pr_prev = pr;
11870Sstevel@tonic-gate pi->pi_prefix_list = pr;
11880Sstevel@tonic-gate pr->pr_physical = pi;
11890Sstevel@tonic-gate }
11900Sstevel@tonic-gate
11910Sstevel@tonic-gate /*
11920Sstevel@tonic-gate * Initialize the prefix from the content of the kernel.
11930Sstevel@tonic-gate * If IFF_ADDRCONF is set we treat it as PR_AUTO (i.e. an addrconf
11943431Scarlsonj * prefix). However, we cannot derive the lifetime from
11953431Scarlsonj * the kernel, thus it is set to 1 week.
11960Sstevel@tonic-gate * Ignore the prefix if the interface is not IFF_UP.
11973431Scarlsonj * If it's from DHCPv6, then we set the netmask.
11980Sstevel@tonic-gate */
11990Sstevel@tonic-gate int
prefix_init_from_k(struct prefix * pr)12000Sstevel@tonic-gate prefix_init_from_k(struct prefix *pr)
12010Sstevel@tonic-gate {
12020Sstevel@tonic-gate struct lifreq lifr;
12030Sstevel@tonic-gate struct sockaddr_in6 *sin6;
12040Sstevel@tonic-gate int sock = pr->pr_physical->pi_sock;
12050Sstevel@tonic-gate
12060Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pr->pr_name, sizeof (lifr.lifr_name));
12070Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
12080Sstevel@tonic-gate if (ioctl(sock, SIOCGLIFADDR, (char *)&lifr) < 0) {
12090Sstevel@tonic-gate logperror_pr(pr, "prefix_init_from_k: ioctl (get addr)");
12100Sstevel@tonic-gate goto error;
12110Sstevel@tonic-gate }
12120Sstevel@tonic-gate if (lifr.lifr_addr.ss_family != AF_INET6) {
12130Sstevel@tonic-gate logmsg(LOG_ERR, "ignoring interface %s: not AF_INET6\n",
12140Sstevel@tonic-gate pr->pr_name);
12150Sstevel@tonic-gate goto error;
12160Sstevel@tonic-gate }
12170Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
12180Sstevel@tonic-gate pr->pr_address = sin6->sin6_addr;
12190Sstevel@tonic-gate
12200Sstevel@tonic-gate if (ioctl(sock, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
12210Sstevel@tonic-gate logperror_pr(pr, "prefix_init_from_k: ioctl (get flags)");
12220Sstevel@tonic-gate goto error;
12230Sstevel@tonic-gate }
12240Sstevel@tonic-gate pr->pr_flags = lifr.lifr_flags;
12250Sstevel@tonic-gate
12260Sstevel@tonic-gate /*
12273431Scarlsonj * If this is a DHCPv6 interface, then we control the netmask.
12280Sstevel@tonic-gate */
12293431Scarlsonj if (lifr.lifr_flags & IFF_DHCPRUNNING) {
12303431Scarlsonj struct phyint *pi = pr->pr_physical;
12313431Scarlsonj struct prefix *pr2;
12323431Scarlsonj
12333431Scarlsonj pr->pr_prefix_len = IPV6_ABITS;
12343431Scarlsonj if (!(lifr.lifr_flags & IFF_UP) ||
12353431Scarlsonj IN6_IS_ADDR_UNSPECIFIED(&pr->pr_address) ||
12363431Scarlsonj IN6_IS_ADDR_LINKLOCAL(&pr->pr_address)) {
12373431Scarlsonj if (debug & D_DHCP)
12383431Scarlsonj logmsg(LOG_DEBUG, "prefix_init_from_k: "
12393431Scarlsonj "ignoring DHCP %s not ready\n",
12403431Scarlsonj pr->pr_name);
12413431Scarlsonj return (0);
12423431Scarlsonj }
12430Sstevel@tonic-gate
12443431Scarlsonj for (pr2 = pi->pi_prefix_list; pr2 != NULL;
12453431Scarlsonj pr2 = pr2->pr_next) {
12463431Scarlsonj /*
12473431Scarlsonj * Examine any non-static (autoconfigured) prefixes as
12483431Scarlsonj * well as existing DHCP-controlled prefixes for valid
12493431Scarlsonj * prefix length information.
12503431Scarlsonj */
12513431Scarlsonj if (pr2->pr_prefix_len != IPV6_ABITS &&
12523431Scarlsonj (!(pr2->pr_state & PR_STATIC) ||
12533431Scarlsonj (pr2->pr_flags & IFF_DHCPRUNNING)) &&
12543431Scarlsonj prefix_equal(pr->pr_prefix, pr2->pr_prefix,
12553431Scarlsonj pr2->pr_prefix_len)) {
12563431Scarlsonj pr->pr_prefix_len = pr2->pr_prefix_len;
12573431Scarlsonj break;
12583431Scarlsonj }
12593431Scarlsonj }
12603431Scarlsonj if (pr2 == NULL) {
12613431Scarlsonj if (debug & D_DHCP)
12623431Scarlsonj logmsg(LOG_DEBUG, "prefix_init_from_k: no "
12633431Scarlsonj "saved mask for DHCP %s; need to "
12643431Scarlsonj "resolicit\n", pr->pr_name);
12653431Scarlsonj (void) check_to_solicit(pi, RESTART_INIT_SOLICIT);
12663431Scarlsonj } else {
12673431Scarlsonj if (debug & D_DHCP)
12683431Scarlsonj logmsg(LOG_DEBUG, "prefix_init_from_k: using "
12693431Scarlsonj "%s mask for DHCP %s\n",
12703431Scarlsonj pr2->pr_name[0] == '\0' ? "saved" :
12713431Scarlsonj pr2->pr_name, pr->pr_name);
12723431Scarlsonj prefix_update_dhcp(pr);
12733431Scarlsonj }
1274*12016SGirish.Moodalbail@Sun.COM /*
1275*12016SGirish.Moodalbail@Sun.COM * If this interface was created using ipadm, store the
1276*12016SGirish.Moodalbail@Sun.COM * addrobj for the DHCPv6 interface in ipmgmtd daemon's
1277*12016SGirish.Moodalbail@Sun.COM * in-memory aobjmap.
1278*12016SGirish.Moodalbail@Sun.COM */
1279*12016SGirish.Moodalbail@Sun.COM prefix_update_ipadm_addrobj(pr, _B_TRUE);
12803431Scarlsonj } else {
12813431Scarlsonj if (ioctl(sock, SIOCGLIFSUBNET, (char *)&lifr) < 0) {
12823431Scarlsonj logperror_pr(pr,
12833431Scarlsonj "prefix_init_from_k: ioctl (get subnet)");
12843431Scarlsonj goto error;
12853431Scarlsonj }
12863431Scarlsonj if (lifr.lifr_subnet.ss_family != AF_INET6) {
12873431Scarlsonj logmsg(LOG_ERR,
12883431Scarlsonj "ignoring interface %s: not AF_INET6\n",
12893431Scarlsonj pr->pr_name);
12903431Scarlsonj goto error;
12913431Scarlsonj }
12923431Scarlsonj /*
12933431Scarlsonj * Guard against the prefix having non-zero bits after the
12943431Scarlsonj * prefix len bits.
12953431Scarlsonj */
12963431Scarlsonj sin6 = (struct sockaddr_in6 *)&lifr.lifr_subnet;
12973431Scarlsonj pr->pr_prefix_len = lifr.lifr_addrlen;
12983431Scarlsonj prefix_set(&pr->pr_prefix, sin6->sin6_addr, pr->pr_prefix_len);
12990Sstevel@tonic-gate
13003431Scarlsonj if (pr->pr_prefix_len != IPV6_ABITS &&
13013431Scarlsonj (pr->pr_flags & IFF_UP) &&
13023431Scarlsonj IN6_ARE_ADDR_EQUAL(&pr->pr_address, &pr->pr_prefix)) {
13033431Scarlsonj char abuf[INET6_ADDRSTRLEN];
13043431Scarlsonj
13056067Smeem logmsg(LOG_ERR, "ignoring interface %s: it appears to "
13063431Scarlsonj "be configured with an invalid interface id "
13073431Scarlsonj "(%s/%u)\n",
13083431Scarlsonj pr->pr_name,
13093431Scarlsonj inet_ntop(AF_INET6, (void *)&pr->pr_address,
13103431Scarlsonj abuf, sizeof (abuf)), pr->pr_prefix_len);
13113431Scarlsonj goto error;
13123431Scarlsonj }
13130Sstevel@tonic-gate }
13140Sstevel@tonic-gate pr->pr_kernel_state = 0;
13150Sstevel@tonic-gate if (pr->pr_prefix_len != IPV6_ABITS)
13160Sstevel@tonic-gate pr->pr_kernel_state |= PR_ONLINK;
13173431Scarlsonj if (!(pr->pr_flags & (IFF_NOLOCAL | IFF_DHCPRUNNING)))
13180Sstevel@tonic-gate pr->pr_kernel_state |= PR_AUTO;
13190Sstevel@tonic-gate if ((pr->pr_flags & IFF_DEPRECATED) && (pr->pr_kernel_state & PR_AUTO))
13200Sstevel@tonic-gate pr->pr_kernel_state |= PR_DEPRECATED;
13210Sstevel@tonic-gate if (!(pr->pr_flags & IFF_ADDRCONF)) {
13220Sstevel@tonic-gate /* Prevent ndpd from stepping on this prefix */
13230Sstevel@tonic-gate pr->pr_kernel_state |= PR_STATIC;
13240Sstevel@tonic-gate }
13250Sstevel@tonic-gate pr->pr_state = pr->pr_kernel_state;
13260Sstevel@tonic-gate /* Adjust pr_prefix_len based if PR_AUTO is set */
13270Sstevel@tonic-gate if (pr->pr_state & PR_AUTO) {
13280Sstevel@tonic-gate pr->pr_prefix_len =
13290Sstevel@tonic-gate IPV6_ABITS - pr->pr_physical->pi_token_length;
13300Sstevel@tonic-gate prefix_set(&pr->pr_prefix, pr->pr_prefix, pr->pr_prefix_len);
13310Sstevel@tonic-gate }
13320Sstevel@tonic-gate
13330Sstevel@tonic-gate /* Can't extract lifetimes from the kernel - use 1 week */
13340Sstevel@tonic-gate pr->pr_ValidLifetime = NDP_PREFIX_DEFAULT_LIFETIME;
13350Sstevel@tonic-gate pr->pr_PreferredLifetime = NDP_PREFIX_DEFAULT_LIFETIME;
13360Sstevel@tonic-gate pr->pr_OnLinkLifetime = NDP_PREFIX_DEFAULT_LIFETIME;
13370Sstevel@tonic-gate
13380Sstevel@tonic-gate /*
13390Sstevel@tonic-gate * If this is a temp addr, the creation time needs to be set.
13400Sstevel@tonic-gate * Though it won't be entirely accurate, the current time is
13410Sstevel@tonic-gate * an okay approximation.
13420Sstevel@tonic-gate */
13430Sstevel@tonic-gate if (pr->pr_flags & IFF_TEMPORARY)
13440Sstevel@tonic-gate pr->pr_CreateTime = getcurrenttime() / MILLISEC;
13450Sstevel@tonic-gate
13460Sstevel@tonic-gate if (pr->pr_kernel_state == 0)
13470Sstevel@tonic-gate pr->pr_name[0] = '\0';
13480Sstevel@tonic-gate return (0);
13490Sstevel@tonic-gate
13500Sstevel@tonic-gate error:
13510Sstevel@tonic-gate /* Pretend that the prefix does not exist in the kernel */
13520Sstevel@tonic-gate pr->pr_kernel_state = 0;
13530Sstevel@tonic-gate pr->pr_name[0] = '\0';
13540Sstevel@tonic-gate return (-1);
13550Sstevel@tonic-gate }
13560Sstevel@tonic-gate
13570Sstevel@tonic-gate /*
13580Sstevel@tonic-gate * Delete (unlink and free) and remove from kernel if the prefix
13590Sstevel@tonic-gate * was added by in.ndpd (i.e. PR_STATIC is not set).
13600Sstevel@tonic-gate * Handles delete of things that have not yet been inserted in the list
13610Sstevel@tonic-gate * i.e. pr_physical is NULL.
1362*12016SGirish.Moodalbail@Sun.COM * Removes the ipadm addrobj created for the prefix.
13630Sstevel@tonic-gate */
13640Sstevel@tonic-gate void
prefix_delete(struct prefix * pr)13650Sstevel@tonic-gate prefix_delete(struct prefix *pr)
13660Sstevel@tonic-gate {
13670Sstevel@tonic-gate struct phyint *pi;
13680Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
13690Sstevel@tonic-gate
13700Sstevel@tonic-gate if (debug & D_PREFIX) {
13710Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_delete(%s, %s, %s/%u)\n",
13720Sstevel@tonic-gate pr->pr_physical->pi_name, pr->pr_name,
13730Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_prefix,
13740Sstevel@tonic-gate abuf, sizeof (abuf)), pr->pr_prefix_len);
13750Sstevel@tonic-gate }
1376*12016SGirish.Moodalbail@Sun.COM pi = pr->pr_physical;
1377*12016SGirish.Moodalbail@Sun.COM
13780Sstevel@tonic-gate /* Remove non-static prefixes from the kernel. */
13790Sstevel@tonic-gate pr->pr_state &= PR_STATIC;
13800Sstevel@tonic-gate if (pr->pr_kernel_state != pr->pr_state)
13810Sstevel@tonic-gate prefix_update_k(pr);
13820Sstevel@tonic-gate
13830Sstevel@tonic-gate if (pr->pr_prev == NULL) {
13840Sstevel@tonic-gate if (pi != NULL)
13850Sstevel@tonic-gate pi->pi_prefix_list = pr->pr_next;
13860Sstevel@tonic-gate } else {
13870Sstevel@tonic-gate pr->pr_prev->pr_next = pr->pr_next;
13880Sstevel@tonic-gate }
13890Sstevel@tonic-gate if (pr->pr_next != NULL)
13900Sstevel@tonic-gate pr->pr_next->pr_prev = pr->pr_prev;
13910Sstevel@tonic-gate pr->pr_next = pr->pr_prev = NULL;
1392*12016SGirish.Moodalbail@Sun.COM
13930Sstevel@tonic-gate free(pr);
13940Sstevel@tonic-gate }
13950Sstevel@tonic-gate
13960Sstevel@tonic-gate /*
13970Sstevel@tonic-gate * Toggle one or more IFF_ flags for a prefix. Turn on 'onflags' and
13980Sstevel@tonic-gate * turn off 'offflags'.
13990Sstevel@tonic-gate */
14000Sstevel@tonic-gate static int
prefix_modify_flags(struct prefix * pr,uint64_t onflags,uint64_t offflags)14010Sstevel@tonic-gate prefix_modify_flags(struct prefix *pr, uint64_t onflags, uint64_t offflags)
14020Sstevel@tonic-gate {
14030Sstevel@tonic-gate struct lifreq lifr;
14040Sstevel@tonic-gate struct phyint *pi = pr->pr_physical;
14050Sstevel@tonic-gate uint64_t old_flags;
14060Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
14070Sstevel@tonic-gate
14080Sstevel@tonic-gate if (debug & D_PREFIX) {
14090Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_modify_flags(%s, %s, %s/%u) "
14100Sstevel@tonic-gate "flags %llx on %llx off %llx\n",
14110Sstevel@tonic-gate pr->pr_physical->pi_name,
14120Sstevel@tonic-gate pr->pr_name,
14130Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_prefix,
14140Sstevel@tonic-gate abuf, sizeof (abuf)), pr->pr_prefix_len,
14150Sstevel@tonic-gate pr->pr_flags, onflags, offflags);
14160Sstevel@tonic-gate }
14170Sstevel@tonic-gate /* Assumes that only the PR_STATIC link-local matches the pi_name */
14180Sstevel@tonic-gate if (!(pr->pr_state & PR_STATIC) &&
14190Sstevel@tonic-gate strcmp(pr->pr_name, pi->pi_name) == 0) {
14200Sstevel@tonic-gate logmsg(LOG_ERR, "prefix_modify_flags(%s, on %llx, off %llx): "
14210Sstevel@tonic-gate "name matches interface name\n",
14220Sstevel@tonic-gate pi->pi_name, onflags, offflags);
14230Sstevel@tonic-gate return (-1);
14240Sstevel@tonic-gate }
14250Sstevel@tonic-gate
14260Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pr->pr_name, sizeof (lifr.lifr_name));
14270Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
14280Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
14298485SPeter.Memishian@Sun.COM if (errno != ENXIO) {
14308485SPeter.Memishian@Sun.COM logperror_pr(pr, "prefix_modify_flags: SIOCGLIFFLAGS");
14318485SPeter.Memishian@Sun.COM logmsg(LOG_ERR, "prefix_modify_flags(%s, %s) old 0x%llx"
14328485SPeter.Memishian@Sun.COM " on 0x%llx off 0x%llx\n", pr->pr_physical->pi_name,
14338485SPeter.Memishian@Sun.COM pr->pr_name, pr->pr_flags, onflags, offflags);
14348485SPeter.Memishian@Sun.COM }
14350Sstevel@tonic-gate return (-1);
14360Sstevel@tonic-gate }
14370Sstevel@tonic-gate old_flags = lifr.lifr_flags;
14380Sstevel@tonic-gate lifr.lifr_flags |= onflags;
14390Sstevel@tonic-gate lifr.lifr_flags &= ~offflags;
14400Sstevel@tonic-gate pr->pr_flags = lifr.lifr_flags;
14410Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFFLAGS, (char *)&lifr) < 0) {
14428485SPeter.Memishian@Sun.COM if (errno != ENXIO) {
14438485SPeter.Memishian@Sun.COM logperror_pr(pr, "prefix_modify_flags: SIOCSLIFFLAGS");
14448485SPeter.Memishian@Sun.COM logmsg(LOG_ERR, "prefix_modify_flags(%s, %s) old 0x%llx"
14458485SPeter.Memishian@Sun.COM " new 0x%llx on 0x%llx off 0x%llx\n",
14468485SPeter.Memishian@Sun.COM pr->pr_physical->pi_name, pr->pr_name,
14478485SPeter.Memishian@Sun.COM old_flags, lifr.lifr_flags, onflags, offflags);
14488485SPeter.Memishian@Sun.COM }
14490Sstevel@tonic-gate return (-1);
14500Sstevel@tonic-gate }
14510Sstevel@tonic-gate return (0);
14520Sstevel@tonic-gate }
14530Sstevel@tonic-gate
14540Sstevel@tonic-gate /*
14553431Scarlsonj * Update the subnet mask for this interface under DHCPv6 control.
14563431Scarlsonj */
14573431Scarlsonj void
prefix_update_dhcp(struct prefix * pr)14583431Scarlsonj prefix_update_dhcp(struct prefix *pr)
14593431Scarlsonj {
14603431Scarlsonj struct lifreq lifr;
14613431Scarlsonj
14623431Scarlsonj (void) memset(&lifr, 0, sizeof (lifr));
14633431Scarlsonj (void) strlcpy(lifr.lifr_name, pr->pr_name, sizeof (lifr.lifr_name));
14643431Scarlsonj lifr.lifr_addr.ss_family = AF_INET6;
14653431Scarlsonj prefix_set(&((struct sockaddr_in6 *)&lifr.lifr_addr)->sin6_addr,
14663431Scarlsonj pr->pr_address, pr->pr_prefix_len);
14673431Scarlsonj lifr.lifr_addrlen = pr->pr_prefix_len;
14683431Scarlsonj /*
14693431Scarlsonj * Ignore ENXIO, as the dhcpagent process is responsible for plumbing
14703431Scarlsonj * and unplumbing these.
14713431Scarlsonj */
14723431Scarlsonj if (ioctl(pr->pr_physical->pi_sock, SIOCSLIFSUBNET, (char *)&lifr) ==
14733431Scarlsonj -1 && errno != ENXIO)
14743431Scarlsonj logperror_pr(pr, "prefix_update_dhcp: ioctl (set subnet)");
14753431Scarlsonj }
14763431Scarlsonj
14773431Scarlsonj /*
14780Sstevel@tonic-gate * Make the kernel state match what is in the prefix structure.
14790Sstevel@tonic-gate * This includes creating the prefix (allocating a new interface name)
14800Sstevel@tonic-gate * as well as setting the local address and on-link subnet prefix
14810Sstevel@tonic-gate * and controlling the IFF_ADDRCONF and IFF_DEPRECATED flags.
14820Sstevel@tonic-gate */
14830Sstevel@tonic-gate void
prefix_update_k(struct prefix * pr)14840Sstevel@tonic-gate prefix_update_k(struct prefix *pr)
14850Sstevel@tonic-gate {
14860Sstevel@tonic-gate struct lifreq lifr;
14870Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
14880Sstevel@tonic-gate char buf1[PREFIX_STATESTRLEN], buf2[PREFIX_STATESTRLEN];
14890Sstevel@tonic-gate struct phyint *pi = pr->pr_physical;
14900Sstevel@tonic-gate struct sockaddr_in6 *sin6;
14910Sstevel@tonic-gate
14920Sstevel@tonic-gate if (debug & D_PREFIX) {
14930Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k(%s, %s, %s/%u) "
14940Sstevel@tonic-gate "from %s to %s\n", pr->pr_physical->pi_name, pr->pr_name,
14950Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_prefix,
14960Sstevel@tonic-gate abuf, sizeof (abuf)), pr->pr_prefix_len,
14970Sstevel@tonic-gate prefix_print_state(pr->pr_kernel_state, buf1,
14980Sstevel@tonic-gate sizeof (buf1)),
14990Sstevel@tonic-gate prefix_print_state(pr->pr_state, buf2, sizeof (buf2)));
15000Sstevel@tonic-gate }
15010Sstevel@tonic-gate
15020Sstevel@tonic-gate if (pr->pr_kernel_state == pr->pr_state)
15030Sstevel@tonic-gate return; /* No changes */
15040Sstevel@tonic-gate
15050Sstevel@tonic-gate /* Skip static prefixes */
15060Sstevel@tonic-gate if (pr->pr_state & PR_STATIC)
15070Sstevel@tonic-gate return;
15080Sstevel@tonic-gate
15090Sstevel@tonic-gate if (pr->pr_kernel_state == 0) {
15100Sstevel@tonic-gate uint64_t onflags;
15110Sstevel@tonic-gate /*
15120Sstevel@tonic-gate * Create a new logical interface name and store in pr_name.
15130Sstevel@tonic-gate * Set IFF_ADDRCONF. Do not set an address (yet).
15140Sstevel@tonic-gate */
15150Sstevel@tonic-gate if (pr->pr_name[0] != '\0') {
15160Sstevel@tonic-gate /* Name already set! */
15170Sstevel@tonic-gate logmsg(LOG_ERR, "prefix_update_k(%s, %s, %s/%u) "
15180Sstevel@tonic-gate "from %s to %s name is already allocated\n",
15190Sstevel@tonic-gate pr->pr_physical->pi_name, pr->pr_name,
15200Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_prefix,
15210Sstevel@tonic-gate abuf, sizeof (abuf)), pr->pr_prefix_len,
15220Sstevel@tonic-gate prefix_print_state(pr->pr_kernel_state, buf1,
15230Sstevel@tonic-gate sizeof (buf1)),
15240Sstevel@tonic-gate prefix_print_state(pr->pr_state, buf2,
15250Sstevel@tonic-gate sizeof (buf2)));
15260Sstevel@tonic-gate return;
15270Sstevel@tonic-gate }
15280Sstevel@tonic-gate
15290Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pi->pi_name,
15300Sstevel@tonic-gate sizeof (lifr.lifr_name));
15310Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
15320Sstevel@tonic-gate lifr.lifr_addr.ss_family = AF_UNSPEC;
15330Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCLIFADDIF, (char *)&lifr) < 0) {
15340Sstevel@tonic-gate logperror_pr(pr, "prefix_update_k: SIOCLIFADDIF");
15350Sstevel@tonic-gate return;
15360Sstevel@tonic-gate }
15370Sstevel@tonic-gate (void) strncpy(pr->pr_name, lifr.lifr_name,
15380Sstevel@tonic-gate sizeof (pr->pr_name));
15390Sstevel@tonic-gate pr->pr_name[sizeof (pr->pr_name) - 1] = '\0';
15400Sstevel@tonic-gate if (debug & D_PREFIX) {
15410Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k: new name %s\n",
15420Sstevel@tonic-gate pr->pr_name);
15430Sstevel@tonic-gate }
15440Sstevel@tonic-gate /*
15450Sstevel@tonic-gate * The IFF_TEMPORARY flag might have already been set; if
15460Sstevel@tonic-gate * so, it needs to be or'd into the flags we're turning on.
15470Sstevel@tonic-gate * But be careful, we might be re-creating a manually
15480Sstevel@tonic-gate * removed interface, in which case we don't want to try
15490Sstevel@tonic-gate * to set *all* the flags we might have in our copy of the
15500Sstevel@tonic-gate * flags yet.
15510Sstevel@tonic-gate */
15520Sstevel@tonic-gate onflags = IFF_ADDRCONF;
15530Sstevel@tonic-gate if (pr->pr_flags & IFF_TEMPORARY)
15540Sstevel@tonic-gate onflags |= IFF_TEMPORARY;
15550Sstevel@tonic-gate if (prefix_modify_flags(pr, onflags, 0) == -1)
15560Sstevel@tonic-gate return;
15570Sstevel@tonic-gate }
15580Sstevel@tonic-gate if ((pr->pr_state & (PR_ONLINK|PR_AUTO)) == 0) {
15590Sstevel@tonic-gate /* Remove the interface */
15600Sstevel@tonic-gate if (prefix_modify_flags(pr, 0, IFF_UP|IFF_DEPRECATED) == -1)
15610Sstevel@tonic-gate return;
15620Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pr->pr_name,
15630Sstevel@tonic-gate sizeof (lifr.lifr_name));
15640Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
15650Sstevel@tonic-gate
15660Sstevel@tonic-gate if (debug & D_PREFIX) {
15670Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k: remove name %s\n",
15680Sstevel@tonic-gate pr->pr_name);
15690Sstevel@tonic-gate }
15700Sstevel@tonic-gate
15710Sstevel@tonic-gate /*
15720Sstevel@tonic-gate * Assumes that only the PR_STATIC link-local matches
15730Sstevel@tonic-gate * the pi_name
15740Sstevel@tonic-gate */
15750Sstevel@tonic-gate if (!(pr->pr_state & PR_STATIC) &&
15760Sstevel@tonic-gate strcmp(pr->pr_name, pi->pi_name) == 0) {
15770Sstevel@tonic-gate logmsg(LOG_ERR, "prefix_update_k(%s): "
15780Sstevel@tonic-gate "name matches if\n", pi->pi_name);
15790Sstevel@tonic-gate return;
15800Sstevel@tonic-gate }
15810Sstevel@tonic-gate
15820Sstevel@tonic-gate /* Remove logical interface based on pr_name */
15830Sstevel@tonic-gate lifr.lifr_addr.ss_family = AF_UNSPEC;
15848485SPeter.Memishian@Sun.COM if (ioctl(pi->pi_sock, SIOCLIFREMOVEIF, (char *)&lifr) < 0 &&
15858485SPeter.Memishian@Sun.COM errno != ENXIO) {
15860Sstevel@tonic-gate logperror_pr(pr, "prefix_update_k: SIOCLIFREMOVEIF");
15870Sstevel@tonic-gate }
15880Sstevel@tonic-gate pr->pr_kernel_state = 0;
15890Sstevel@tonic-gate pr->pr_name[0] = '\0';
15900Sstevel@tonic-gate return;
15910Sstevel@tonic-gate }
15920Sstevel@tonic-gate if ((pr->pr_state & PR_AUTO) && !(pr->pr_kernel_state & PR_AUTO)) {
15930Sstevel@tonic-gate /*
15940Sstevel@tonic-gate * Set local address and set the prefix length to 128.
15950Sstevel@tonic-gate * Turn off IFF_NOLOCAL in case it was set.
15960Sstevel@tonic-gate * Turn on IFF_UP.
15970Sstevel@tonic-gate */
15980Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pr->pr_name,
15990Sstevel@tonic-gate sizeof (lifr.lifr_name));
16000Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
16010Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
16020Sstevel@tonic-gate bzero(sin6, sizeof (struct sockaddr_in6));
16030Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
16040Sstevel@tonic-gate sin6->sin6_addr = pr->pr_address;
16050Sstevel@tonic-gate if (debug & D_PREFIX) {
16060Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k(%s) set addr %s "
16070Sstevel@tonic-gate "for PR_AUTO on\n",
16080Sstevel@tonic-gate pr->pr_name,
16090Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_address,
16106067Smeem abuf, sizeof (abuf)));
16110Sstevel@tonic-gate }
16120Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFADDR, (char *)&lifr) < 0) {
16130Sstevel@tonic-gate logperror_pr(pr, "prefix_update_k: SIOCSLIFADDR");
16140Sstevel@tonic-gate return;
16150Sstevel@tonic-gate }
1616*12016SGirish.Moodalbail@Sun.COM /*
1617*12016SGirish.Moodalbail@Sun.COM * If this interface was created using ipadm, store the
1618*12016SGirish.Moodalbail@Sun.COM * addrobj for the prefix in ipmgmtd daemon's aobjmap.
1619*12016SGirish.Moodalbail@Sun.COM */
1620*12016SGirish.Moodalbail@Sun.COM prefix_update_ipadm_addrobj(pr, _B_TRUE);
16210Sstevel@tonic-gate if (pr->pr_state & PR_ONLINK) {
16220Sstevel@tonic-gate sin6->sin6_addr = pr->pr_prefix;
16230Sstevel@tonic-gate lifr.lifr_addrlen = pr->pr_prefix_len;
16240Sstevel@tonic-gate } else {
16250Sstevel@tonic-gate sin6->sin6_addr = pr->pr_address;
16260Sstevel@tonic-gate lifr.lifr_addrlen = IPV6_ABITS;
16270Sstevel@tonic-gate }
16280Sstevel@tonic-gate if (debug & D_PREFIX) {
16290Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k(%s) set subnet "
16300Sstevel@tonic-gate "%s/%u for PR_AUTO on\n", pr->pr_name,
16310Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&sin6->sin6_addr,
16326067Smeem abuf, sizeof (abuf)), lifr.lifr_addrlen);
16330Sstevel@tonic-gate }
16340Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFSUBNET, (char *)&lifr) < 0) {
16350Sstevel@tonic-gate logperror_pr(pr, "prefix_update_k: SIOCSLIFSUBNET");
16360Sstevel@tonic-gate return;
16370Sstevel@tonic-gate }
16380Sstevel@tonic-gate /*
16390Sstevel@tonic-gate * For ptp interfaces, create a destination based on
16400Sstevel@tonic-gate * prefix and prefix len together with the remote token
16410Sstevel@tonic-gate * extracted from the remote pt-pt address. This is used by
16420Sstevel@tonic-gate * ip to choose a proper source for outgoing packets.
16430Sstevel@tonic-gate */
16440Sstevel@tonic-gate if (pi->pi_flags & IFF_POINTOPOINT) {
16450Sstevel@tonic-gate int i;
16460Sstevel@tonic-gate
16470Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
16480Sstevel@tonic-gate bzero(sin6, sizeof (struct sockaddr_in6));
16490Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
16500Sstevel@tonic-gate sin6->sin6_addr = pr->pr_prefix;
16510Sstevel@tonic-gate for (i = 0; i < 16; i++) {
16520Sstevel@tonic-gate sin6->sin6_addr.s6_addr[i] |=
16530Sstevel@tonic-gate pi->pi_dst_token.s6_addr[i];
16540Sstevel@tonic-gate }
16550Sstevel@tonic-gate if (debug & D_PREFIX) {
16560Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k(%s) "
16570Sstevel@tonic-gate "set dstaddr %s for PR_AUTO on\n",
16580Sstevel@tonic-gate pr->pr_name, inet_ntop(AF_INET6,
16590Sstevel@tonic-gate (void *)&sin6->sin6_addr,
16600Sstevel@tonic-gate abuf, sizeof (abuf)));
16610Sstevel@tonic-gate }
16620Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFDSTADDR,
16630Sstevel@tonic-gate (char *)&lifr) < 0) {
16640Sstevel@tonic-gate logperror_pr(pr,
16650Sstevel@tonic-gate "prefix_update_k: SIOCSLIFDSTADDR");
16660Sstevel@tonic-gate return;
16670Sstevel@tonic-gate }
16680Sstevel@tonic-gate }
16690Sstevel@tonic-gate if (prefix_modify_flags(pr, IFF_UP, IFF_NOLOCAL) == -1)
16700Sstevel@tonic-gate return;
16710Sstevel@tonic-gate pr->pr_kernel_state |= PR_AUTO;
16720Sstevel@tonic-gate if (pr->pr_state & PR_ONLINK)
16730Sstevel@tonic-gate pr->pr_kernel_state |= PR_ONLINK;
16740Sstevel@tonic-gate else
16750Sstevel@tonic-gate pr->pr_kernel_state &= ~PR_ONLINK;
16760Sstevel@tonic-gate }
16770Sstevel@tonic-gate if (!(pr->pr_state & PR_AUTO) && (pr->pr_kernel_state & PR_AUTO)) {
16780Sstevel@tonic-gate /* Turn on IFF_NOLOCAL and set the local address to all zero */
16790Sstevel@tonic-gate if (prefix_modify_flags(pr, IFF_NOLOCAL, 0) == -1)
16800Sstevel@tonic-gate return;
16810Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pr->pr_name,
16820Sstevel@tonic-gate sizeof (lifr.lifr_name));
16830Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
16840Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
16850Sstevel@tonic-gate bzero(sin6, sizeof (struct sockaddr_in6));
16860Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
16870Sstevel@tonic-gate if (debug & D_PREFIX) {
16880Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k(%s) set addr %s "
16890Sstevel@tonic-gate "for PR_AUTO off\n", pr->pr_name,
16900Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&sin6->sin6_addr,
16916067Smeem abuf, sizeof (abuf)));
16920Sstevel@tonic-gate }
16930Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFADDR, (char *)&lifr) < 0) {
16940Sstevel@tonic-gate logperror_pr(pr, "prefix_update_k: SIOCSLIFADDR");
16950Sstevel@tonic-gate return;
16960Sstevel@tonic-gate }
16970Sstevel@tonic-gate pr->pr_kernel_state &= ~PR_AUTO;
16980Sstevel@tonic-gate }
16990Sstevel@tonic-gate if ((pr->pr_state & PR_DEPRECATED) &&
17000Sstevel@tonic-gate !(pr->pr_kernel_state & PR_DEPRECATED) &&
17010Sstevel@tonic-gate (pr->pr_kernel_state & PR_AUTO)) {
17020Sstevel@tonic-gate /* Only applies if PR_AUTO */
17030Sstevel@tonic-gate if (prefix_modify_flags(pr, IFF_DEPRECATED, 0) == -1)
17040Sstevel@tonic-gate return;
17050Sstevel@tonic-gate pr->pr_kernel_state |= PR_DEPRECATED;
17060Sstevel@tonic-gate }
17070Sstevel@tonic-gate if (!(pr->pr_state & PR_DEPRECATED) &&
17080Sstevel@tonic-gate (pr->pr_kernel_state & PR_DEPRECATED)) {
17090Sstevel@tonic-gate if (prefix_modify_flags(pr, 0, IFF_DEPRECATED) == -1)
17100Sstevel@tonic-gate return;
17110Sstevel@tonic-gate pr->pr_kernel_state &= ~PR_DEPRECATED;
17120Sstevel@tonic-gate }
17130Sstevel@tonic-gate if ((pr->pr_state & PR_ONLINK) && !(pr->pr_kernel_state & PR_ONLINK)) {
17140Sstevel@tonic-gate /* Set the subnet and set IFF_UP */
17150Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pr->pr_name,
17160Sstevel@tonic-gate sizeof (lifr.lifr_name));
17170Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
17180Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
17190Sstevel@tonic-gate bzero(sin6, sizeof (struct sockaddr_in6));
17200Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
17210Sstevel@tonic-gate sin6->sin6_addr = pr->pr_prefix;
17220Sstevel@tonic-gate lifr.lifr_addrlen = pr->pr_prefix_len;
17230Sstevel@tonic-gate if (debug & D_PREFIX) {
17240Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k(%s) set subnet "
17250Sstevel@tonic-gate "%s/%d for PR_ONLINK on\n", pr->pr_name,
17260Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&sin6->sin6_addr,
17276067Smeem abuf, sizeof (abuf)), lifr.lifr_addrlen);
17280Sstevel@tonic-gate }
17290Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFSUBNET, (char *)&lifr) < 0) {
17300Sstevel@tonic-gate logperror_pr(pr, "prefix_update_k: SIOCSLIFSUBNET");
17310Sstevel@tonic-gate return;
17320Sstevel@tonic-gate }
17333322Scarlsonj /*
17343322Scarlsonj * If we've previously marked the interface "up" while
17353322Scarlsonj * processing the PR_AUTO flag -- via incoming_prefix_addrconf
17363322Scarlsonj * -- then there's no need to set it "up" again. We're done;
17373322Scarlsonj * just set PR_ONLINK to indicate that we've set the subnet.
17383322Scarlsonj */
17393322Scarlsonj if (!(pr->pr_state & PR_AUTO) &&
17403322Scarlsonj prefix_modify_flags(pr, IFF_UP | IFF_NOLOCAL, 0) == -1)
17410Sstevel@tonic-gate return;
17420Sstevel@tonic-gate pr->pr_kernel_state |= PR_ONLINK;
17430Sstevel@tonic-gate }
17440Sstevel@tonic-gate if (!(pr->pr_state & PR_ONLINK) && (pr->pr_kernel_state & PR_ONLINK)) {
17450Sstevel@tonic-gate /* Set the prefixlen to 128 */
17460Sstevel@tonic-gate (void) strncpy(lifr.lifr_name, pr->pr_name,
17470Sstevel@tonic-gate sizeof (lifr.lifr_name));
17480Sstevel@tonic-gate lifr.lifr_name[sizeof (lifr.lifr_name) - 1] = '\0';
17490Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
17500Sstevel@tonic-gate bzero(sin6, sizeof (struct sockaddr_in6));
17510Sstevel@tonic-gate sin6->sin6_family = AF_INET6;
17520Sstevel@tonic-gate sin6->sin6_addr = pr->pr_address;
17530Sstevel@tonic-gate lifr.lifr_addrlen = IPV6_ABITS;
17540Sstevel@tonic-gate if (debug & D_PREFIX) {
17550Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_update_k(%s) set subnet "
17560Sstevel@tonic-gate "%s/%d for PR_ONLINK off\n", pr->pr_name,
17570Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&sin6->sin6_addr,
17586067Smeem abuf, sizeof (abuf)), lifr.lifr_addrlen);
17590Sstevel@tonic-gate }
17600Sstevel@tonic-gate if (ioctl(pi->pi_sock, SIOCSLIFSUBNET, (char *)&lifr) < 0) {
17610Sstevel@tonic-gate logperror_pr(pr, "prefix_update_k: SIOCSLIFSUBNET");
17620Sstevel@tonic-gate return;
17630Sstevel@tonic-gate }
17640Sstevel@tonic-gate pr->pr_kernel_state &= ~PR_ONLINK;
17650Sstevel@tonic-gate }
17660Sstevel@tonic-gate }
17670Sstevel@tonic-gate
17680Sstevel@tonic-gate /*
17690Sstevel@tonic-gate * Called with the number of millseconds elapsed since the last call.
17700Sstevel@tonic-gate * Determines if any timeout event has occurred and
17710Sstevel@tonic-gate * returns the number of milliseconds until the next timeout event.
17720Sstevel@tonic-gate * Returns TIMER_INFINITY for "never".
17730Sstevel@tonic-gate */
17740Sstevel@tonic-gate uint_t
prefix_timer(struct prefix * pr,uint_t elapsed)17750Sstevel@tonic-gate prefix_timer(struct prefix *pr, uint_t elapsed)
17760Sstevel@tonic-gate {
17770Sstevel@tonic-gate uint_t next = TIMER_INFINITY;
17780Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
17790Sstevel@tonic-gate
17800Sstevel@tonic-gate if (debug & (D_PREFIX|D_TMP)) {
17810Sstevel@tonic-gate logmsg(LOG_DEBUG, "prefix_timer(%s, %s/%u, %d) "
17820Sstevel@tonic-gate "valid %d pref %d onlink %d\n",
17830Sstevel@tonic-gate pr->pr_name,
17840Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_prefix,
17850Sstevel@tonic-gate abuf, sizeof (abuf)), pr->pr_prefix_len,
17860Sstevel@tonic-gate elapsed, pr->pr_ValidLifetime, pr->pr_PreferredLifetime,
17870Sstevel@tonic-gate pr->pr_OnLinkLifetime);
17880Sstevel@tonic-gate }
17890Sstevel@tonic-gate
17900Sstevel@tonic-gate /* Exclude static prefixes */
17910Sstevel@tonic-gate if (pr->pr_state & PR_STATIC)
17920Sstevel@tonic-gate return (next);
17930Sstevel@tonic-gate
17940Sstevel@tonic-gate if (pr->pr_AutonomousFlag &&
17950Sstevel@tonic-gate (pr->pr_PreferredLifetime != PREFIX_INFINITY)) {
17960Sstevel@tonic-gate if (pr->pr_PreferredLifetime <= elapsed) {
17970Sstevel@tonic-gate pr->pr_PreferredLifetime = 0;
17980Sstevel@tonic-gate } else {
17990Sstevel@tonic-gate pr->pr_PreferredLifetime -= elapsed;
18000Sstevel@tonic-gate if (pr->pr_PreferredLifetime < next)
18010Sstevel@tonic-gate next = pr->pr_PreferredLifetime;
18020Sstevel@tonic-gate }
18030Sstevel@tonic-gate }
18040Sstevel@tonic-gate if (pr->pr_AutonomousFlag &&
18050Sstevel@tonic-gate (pr->pr_ValidLifetime != PREFIX_INFINITY)) {
18060Sstevel@tonic-gate if (pr->pr_ValidLifetime <= elapsed) {
18070Sstevel@tonic-gate pr->pr_ValidLifetime = 0;
18080Sstevel@tonic-gate } else {
18090Sstevel@tonic-gate pr->pr_ValidLifetime -= elapsed;
18100Sstevel@tonic-gate if (pr->pr_ValidLifetime < next)
18110Sstevel@tonic-gate next = pr->pr_ValidLifetime;
18120Sstevel@tonic-gate }
18130Sstevel@tonic-gate }
18140Sstevel@tonic-gate if (pr->pr_OnLinkFlag &&
18150Sstevel@tonic-gate (pr->pr_OnLinkLifetime != PREFIX_INFINITY)) {
18160Sstevel@tonic-gate if (pr->pr_OnLinkLifetime <= elapsed) {
18170Sstevel@tonic-gate pr->pr_OnLinkLifetime = 0;
18180Sstevel@tonic-gate } else {
18190Sstevel@tonic-gate pr->pr_OnLinkLifetime -= elapsed;
18200Sstevel@tonic-gate if (pr->pr_OnLinkLifetime < next)
18210Sstevel@tonic-gate next = pr->pr_OnLinkLifetime;
18220Sstevel@tonic-gate }
18230Sstevel@tonic-gate }
18240Sstevel@tonic-gate if (pr->pr_AutonomousFlag && pr->pr_ValidLifetime == 0)
18250Sstevel@tonic-gate pr->pr_state &= ~(PR_AUTO|PR_DEPRECATED);
18260Sstevel@tonic-gate if (pr->pr_AutonomousFlag && pr->pr_PreferredLifetime == 0 &&
18270Sstevel@tonic-gate (pr->pr_state & PR_AUTO)) {
18280Sstevel@tonic-gate pr->pr_state |= PR_DEPRECATED;
18290Sstevel@tonic-gate if (debug & D_TMP)
18300Sstevel@tonic-gate logmsg(LOG_WARNING, "prefix_timer: deprecated "
18310Sstevel@tonic-gate "prefix(%s)\n", pr->pr_name);
18320Sstevel@tonic-gate }
18330Sstevel@tonic-gate if (pr->pr_OnLinkFlag && pr->pr_OnLinkLifetime == 0)
18340Sstevel@tonic-gate pr->pr_state &= ~PR_ONLINK;
18350Sstevel@tonic-gate
18360Sstevel@tonic-gate if (pr->pr_state != pr->pr_kernel_state) {
18370Sstevel@tonic-gate /* Might cause prefix to be deleted! */
18380Sstevel@tonic-gate
18390Sstevel@tonic-gate /* Log a message when an addrconf prefix goes away */
18400Sstevel@tonic-gate if ((pr->pr_kernel_state & PR_AUTO) &&
18410Sstevel@tonic-gate !(pr->pr_state & PR_AUTO)) {
18420Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
18430Sstevel@tonic-gate
18440Sstevel@tonic-gate logmsg(LOG_WARNING,
18450Sstevel@tonic-gate "Address removed due to timeout %s\n",
18460Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_address,
18470Sstevel@tonic-gate abuf, sizeof (abuf)));
18480Sstevel@tonic-gate }
18490Sstevel@tonic-gate prefix_update_k(pr);
18500Sstevel@tonic-gate }
18510Sstevel@tonic-gate
18520Sstevel@tonic-gate return (next);
18530Sstevel@tonic-gate }
18540Sstevel@tonic-gate
18550Sstevel@tonic-gate static char *
prefix_print_state(int state,char * buf,int buflen)18560Sstevel@tonic-gate prefix_print_state(int state, char *buf, int buflen)
18570Sstevel@tonic-gate {
18580Sstevel@tonic-gate char *cp;
18590Sstevel@tonic-gate int cplen = buflen;
18600Sstevel@tonic-gate
18610Sstevel@tonic-gate cp = buf;
18620Sstevel@tonic-gate cp[0] = '\0';
18630Sstevel@tonic-gate
18640Sstevel@tonic-gate if (state & PR_ONLINK) {
18650Sstevel@tonic-gate if (strlcat(cp, "ONLINK ", cplen) >= cplen)
18660Sstevel@tonic-gate return (buf);
18670Sstevel@tonic-gate cp += strlen(cp);
18680Sstevel@tonic-gate cplen = buflen - (cp - buf);
18690Sstevel@tonic-gate }
18700Sstevel@tonic-gate if (state & PR_AUTO) {
18710Sstevel@tonic-gate if (strlcat(cp, "AUTO ", cplen) >= cplen)
18720Sstevel@tonic-gate return (buf);
18730Sstevel@tonic-gate cp += strlen(cp);
18740Sstevel@tonic-gate cplen = buflen - (cp - buf);
18750Sstevel@tonic-gate }
18760Sstevel@tonic-gate if (state & PR_DEPRECATED) {
18770Sstevel@tonic-gate if (strlcat(cp, "DEPRECATED ", cplen) >= cplen)
18780Sstevel@tonic-gate return (buf);
18790Sstevel@tonic-gate cp += strlen(cp);
18800Sstevel@tonic-gate cplen = buflen - (cp - buf);
18810Sstevel@tonic-gate }
18820Sstevel@tonic-gate if (state & PR_STATIC) {
18830Sstevel@tonic-gate if (strlcat(cp, "STATIC ", cplen) >= cplen)
18840Sstevel@tonic-gate return (buf);
18850Sstevel@tonic-gate cp += strlen(cp);
18860Sstevel@tonic-gate cplen = buflen - (cp - buf);
18870Sstevel@tonic-gate }
18880Sstevel@tonic-gate return (buf);
18890Sstevel@tonic-gate }
18900Sstevel@tonic-gate
18910Sstevel@tonic-gate static void
prefix_print(struct prefix * pr)18920Sstevel@tonic-gate prefix_print(struct prefix *pr)
18930Sstevel@tonic-gate {
18940Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
18950Sstevel@tonic-gate char buf1[PREFIX_STATESTRLEN], buf2[PREFIX_STATESTRLEN];
18960Sstevel@tonic-gate
18970Sstevel@tonic-gate logmsg(LOG_DEBUG, "Prefix name: %s prefix %s/%u state %s "
18980Sstevel@tonic-gate "kernel_state %s\n", pr->pr_name,
18990Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_prefix, abuf, sizeof (abuf)),
19000Sstevel@tonic-gate pr->pr_prefix_len,
19010Sstevel@tonic-gate prefix_print_state(pr->pr_state, buf2, sizeof (buf2)),
19020Sstevel@tonic-gate prefix_print_state(pr->pr_kernel_state, buf1, sizeof (buf1)));
19030Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tAddress: %s flags %llx in_use %d\n",
19040Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&pr->pr_address, abuf, sizeof (abuf)),
19050Sstevel@tonic-gate pr->pr_flags, pr->pr_in_use);
19060Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tValidLifetime %u PreferredLifetime %u "
19070Sstevel@tonic-gate "OnLinkLifetime %u\n", pr->pr_ValidLifetime,
19080Sstevel@tonic-gate pr->pr_PreferredLifetime, pr->pr_OnLinkLifetime);
19090Sstevel@tonic-gate logmsg(LOG_DEBUG, "\tOnLink %d Auto %d\n",
19100Sstevel@tonic-gate pr->pr_OnLinkFlag, pr->pr_AutonomousFlag);
19110Sstevel@tonic-gate logmsg(LOG_DEBUG, "\n");
19120Sstevel@tonic-gate }
19130Sstevel@tonic-gate
19140Sstevel@tonic-gate /*
19150Sstevel@tonic-gate * Lookup advertisement prefix structure that matches the prefix and
19160Sstevel@tonic-gate * prefix length.
19170Sstevel@tonic-gate * Assumes that the bits after prefixlen might not be zero.
19180Sstevel@tonic-gate */
19190Sstevel@tonic-gate struct adv_prefix *
adv_prefix_lookup(struct phyint * pi,struct in6_addr prefix,int prefixlen)19200Sstevel@tonic-gate adv_prefix_lookup(struct phyint *pi, struct in6_addr prefix, int prefixlen)
19210Sstevel@tonic-gate {
19220Sstevel@tonic-gate struct adv_prefix *adv_pr;
19230Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
19240Sstevel@tonic-gate
19250Sstevel@tonic-gate if (debug & D_PREFIX) {
19260Sstevel@tonic-gate logmsg(LOG_DEBUG, "adv_prefix_lookup(%s, %s/%u)\n",
19270Sstevel@tonic-gate pi->pi_name, inet_ntop(AF_INET6, (void *)&prefix,
19280Sstevel@tonic-gate abuf, sizeof (abuf)), prefixlen);
19290Sstevel@tonic-gate }
19300Sstevel@tonic-gate
19310Sstevel@tonic-gate for (adv_pr = pi->pi_adv_prefix_list; adv_pr != NULL;
19320Sstevel@tonic-gate adv_pr = adv_pr->adv_pr_next) {
19330Sstevel@tonic-gate if (adv_pr->adv_pr_prefix_len == prefixlen &&
19340Sstevel@tonic-gate prefix_equal(prefix, adv_pr->adv_pr_prefix, prefixlen))
19350Sstevel@tonic-gate return (adv_pr);
19360Sstevel@tonic-gate }
19370Sstevel@tonic-gate return (NULL);
19380Sstevel@tonic-gate }
19390Sstevel@tonic-gate
19400Sstevel@tonic-gate /*
19410Sstevel@tonic-gate * Initialize a new advertisement prefix.
19420Sstevel@tonic-gate */
19430Sstevel@tonic-gate struct adv_prefix *
adv_prefix_create(struct phyint * pi,struct in6_addr prefix,int prefixlen)19440Sstevel@tonic-gate adv_prefix_create(struct phyint *pi, struct in6_addr prefix, int prefixlen)
19450Sstevel@tonic-gate {
19460Sstevel@tonic-gate struct adv_prefix *adv_pr;
19470Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
19480Sstevel@tonic-gate
19490Sstevel@tonic-gate if (debug & D_PREFIX) {
19500Sstevel@tonic-gate logmsg(LOG_DEBUG, "adv_prefix_create(%s, %s/%u)\n",
19510Sstevel@tonic-gate pi->pi_name, inet_ntop(AF_INET6, (void *)&prefix,
19520Sstevel@tonic-gate abuf, sizeof (abuf)), prefixlen);
19530Sstevel@tonic-gate }
19540Sstevel@tonic-gate adv_pr = (struct adv_prefix *)calloc(sizeof (struct adv_prefix), 1);
19550Sstevel@tonic-gate if (adv_pr == NULL) {
19560Sstevel@tonic-gate logmsg(LOG_ERR, "adv_prefix_create: calloc\n");
19570Sstevel@tonic-gate return (NULL);
19580Sstevel@tonic-gate }
19590Sstevel@tonic-gate /*
19600Sstevel@tonic-gate * The prefix might have non-zero bits after the prefix len bits.
19610Sstevel@tonic-gate * Force them to be zero.
19620Sstevel@tonic-gate */
19630Sstevel@tonic-gate prefix_set(&adv_pr->adv_pr_prefix, prefix, prefixlen);
19640Sstevel@tonic-gate adv_pr->adv_pr_prefix_len = prefixlen;
19650Sstevel@tonic-gate adv_prefix_insert(pi, adv_pr);
19660Sstevel@tonic-gate return (adv_pr);
19670Sstevel@tonic-gate }
19680Sstevel@tonic-gate
19690Sstevel@tonic-gate /* Insert in linked list */
19700Sstevel@tonic-gate static void
adv_prefix_insert(struct phyint * pi,struct adv_prefix * adv_pr)19710Sstevel@tonic-gate adv_prefix_insert(struct phyint *pi, struct adv_prefix *adv_pr)
19720Sstevel@tonic-gate {
19730Sstevel@tonic-gate adv_pr->adv_pr_next = pi->pi_adv_prefix_list;
19740Sstevel@tonic-gate adv_pr->adv_pr_prev = NULL;
19750Sstevel@tonic-gate if (pi->pi_adv_prefix_list != NULL)
19760Sstevel@tonic-gate pi->pi_adv_prefix_list->adv_pr_prev = adv_pr;
19770Sstevel@tonic-gate pi->pi_adv_prefix_list = adv_pr;
19780Sstevel@tonic-gate adv_pr->adv_pr_physical = pi;
19790Sstevel@tonic-gate }
19800Sstevel@tonic-gate
19810Sstevel@tonic-gate /*
19820Sstevel@tonic-gate * Delete (unlink and free) from our tables. There should be
19830Sstevel@tonic-gate * a corresponding "struct prefix *" which will clean up the kernel
19840Sstevel@tonic-gate * if necessary. adv_prefix is just used for sending out advertisements.
19850Sstevel@tonic-gate */
19860Sstevel@tonic-gate static void
adv_prefix_delete(struct adv_prefix * adv_pr)19870Sstevel@tonic-gate adv_prefix_delete(struct adv_prefix *adv_pr)
19880Sstevel@tonic-gate {
19890Sstevel@tonic-gate struct phyint *pi;
19900Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
19910Sstevel@tonic-gate
19920Sstevel@tonic-gate if (debug & D_PREFIX) {
19930Sstevel@tonic-gate logmsg(LOG_DEBUG, "adv_prefix_delete(%s, %s/%u)\n",
19940Sstevel@tonic-gate adv_pr->adv_pr_physical->pi_name,
19950Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&adv_pr->adv_pr_prefix,
19960Sstevel@tonic-gate abuf, sizeof (abuf)), adv_pr->adv_pr_prefix_len);
19970Sstevel@tonic-gate }
19980Sstevel@tonic-gate pi = adv_pr->adv_pr_physical;
19990Sstevel@tonic-gate
20000Sstevel@tonic-gate if (adv_pr->adv_pr_prev == NULL) {
20010Sstevel@tonic-gate if (pi != NULL)
20020Sstevel@tonic-gate pi->pi_adv_prefix_list = adv_pr->adv_pr_next;
20030Sstevel@tonic-gate } else {
20040Sstevel@tonic-gate adv_pr->adv_pr_prev->adv_pr_next = adv_pr->adv_pr_next;
20050Sstevel@tonic-gate }
20060Sstevel@tonic-gate if (adv_pr->adv_pr_next != NULL)
20070Sstevel@tonic-gate adv_pr->adv_pr_next->adv_pr_prev = adv_pr->adv_pr_prev;
20080Sstevel@tonic-gate adv_pr->adv_pr_next = adv_pr->adv_pr_prev = NULL;
20090Sstevel@tonic-gate free(adv_pr);
20100Sstevel@tonic-gate }
20110Sstevel@tonic-gate
20120Sstevel@tonic-gate /*
20130Sstevel@tonic-gate * Called with the number of millseconds elapsed since the last call.
20140Sstevel@tonic-gate * Determines if any timeout event has occurred and
20150Sstevel@tonic-gate * returns the number of milliseconds until the next timeout event.
20160Sstevel@tonic-gate * Returns TIMER_INFINITY for "never".
20170Sstevel@tonic-gate */
20180Sstevel@tonic-gate uint_t
adv_prefix_timer(struct adv_prefix * adv_pr,uint_t elapsed)20190Sstevel@tonic-gate adv_prefix_timer(struct adv_prefix *adv_pr, uint_t elapsed)
20200Sstevel@tonic-gate {
20210Sstevel@tonic-gate int seconds_elapsed = (elapsed + 500) / 1000; /* Rounded */
20220Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
20230Sstevel@tonic-gate
20240Sstevel@tonic-gate if (debug & D_PREFIX) {
20250Sstevel@tonic-gate logmsg(LOG_DEBUG, "adv_prefix_timer(%s, %s/%u, %d)\n",
20260Sstevel@tonic-gate adv_pr->adv_pr_physical->pi_name,
20270Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&adv_pr->adv_pr_prefix,
20280Sstevel@tonic-gate abuf, sizeof (abuf)), adv_pr->adv_pr_prefix_len,
20290Sstevel@tonic-gate elapsed);
20300Sstevel@tonic-gate }
20310Sstevel@tonic-gate
20320Sstevel@tonic-gate /* Decrement Expire time left for real-time lifetimes */
20330Sstevel@tonic-gate if (adv_pr->adv_pr_AdvValidRealTime) {
20340Sstevel@tonic-gate if (adv_pr->adv_pr_AdvValidExpiration > seconds_elapsed)
20350Sstevel@tonic-gate adv_pr->adv_pr_AdvValidExpiration -= seconds_elapsed;
20360Sstevel@tonic-gate else
20370Sstevel@tonic-gate adv_pr->adv_pr_AdvValidExpiration = 0;
20380Sstevel@tonic-gate }
20390Sstevel@tonic-gate if (adv_pr->adv_pr_AdvPreferredRealTime) {
20400Sstevel@tonic-gate if (adv_pr->adv_pr_AdvPreferredExpiration > seconds_elapsed) {
20410Sstevel@tonic-gate adv_pr->adv_pr_AdvPreferredExpiration -=
20420Sstevel@tonic-gate seconds_elapsed;
20430Sstevel@tonic-gate } else {
20440Sstevel@tonic-gate adv_pr->adv_pr_AdvPreferredExpiration = 0;
20450Sstevel@tonic-gate }
20460Sstevel@tonic-gate }
20470Sstevel@tonic-gate return (TIMER_INFINITY);
20480Sstevel@tonic-gate }
20490Sstevel@tonic-gate
20500Sstevel@tonic-gate static void
adv_prefix_print(struct adv_prefix * adv_pr)20510Sstevel@tonic-gate adv_prefix_print(struct adv_prefix *adv_pr)
20520Sstevel@tonic-gate {
20530Sstevel@tonic-gate print_prefixlist(adv_pr->adv_pr_config);
20540Sstevel@tonic-gate }
20550Sstevel@tonic-gate
20560Sstevel@tonic-gate /* Lookup router on its link-local IPv6 address */
20570Sstevel@tonic-gate struct router *
router_lookup(struct phyint * pi,struct in6_addr addr)20580Sstevel@tonic-gate router_lookup(struct phyint *pi, struct in6_addr addr)
20590Sstevel@tonic-gate {
20600Sstevel@tonic-gate struct router *dr;
20610Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
20620Sstevel@tonic-gate
20630Sstevel@tonic-gate if (debug & D_ROUTER) {
20640Sstevel@tonic-gate logmsg(LOG_DEBUG, "router_lookup(%s, %s)\n", pi->pi_name,
20650Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&addr,
20660Sstevel@tonic-gate abuf, sizeof (abuf)));
20670Sstevel@tonic-gate }
20680Sstevel@tonic-gate
20690Sstevel@tonic-gate for (dr = pi->pi_router_list; dr != NULL; dr = dr->dr_next) {
20700Sstevel@tonic-gate if (bcmp((char *)&addr, (char *)&dr->dr_address,
20710Sstevel@tonic-gate sizeof (addr)) == 0)
20720Sstevel@tonic-gate return (dr);
20730Sstevel@tonic-gate }
20740Sstevel@tonic-gate return (NULL);
20750Sstevel@tonic-gate }
20760Sstevel@tonic-gate
20770Sstevel@tonic-gate /*
20780Sstevel@tonic-gate * Create a default router entry.
20790Sstevel@tonic-gate * The lifetime parameter is in seconds.
20800Sstevel@tonic-gate */
20810Sstevel@tonic-gate struct router *
router_create(struct phyint * pi,struct in6_addr addr,uint_t lifetime)20820Sstevel@tonic-gate router_create(struct phyint *pi, struct in6_addr addr, uint_t lifetime)
20830Sstevel@tonic-gate {
20840Sstevel@tonic-gate struct router *dr;
20850Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
20860Sstevel@tonic-gate
20870Sstevel@tonic-gate if (debug & D_ROUTER) {
20880Sstevel@tonic-gate logmsg(LOG_DEBUG, "router_create(%s, %s, %u)\n", pi->pi_name,
20890Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&addr,
20900Sstevel@tonic-gate abuf, sizeof (abuf)), lifetime);
20910Sstevel@tonic-gate }
20920Sstevel@tonic-gate
20930Sstevel@tonic-gate dr = (struct router *)calloc(sizeof (struct router), 1);
20940Sstevel@tonic-gate if (dr == NULL) {
20950Sstevel@tonic-gate logmsg(LOG_ERR, "router_create: out of memory\n");
20960Sstevel@tonic-gate return (NULL);
20970Sstevel@tonic-gate }
20980Sstevel@tonic-gate dr->dr_address = addr;
20990Sstevel@tonic-gate dr->dr_lifetime = lifetime;
21000Sstevel@tonic-gate router_insert(pi, dr);
21011577Sseb if (dr->dr_lifetime != 0)
21020Sstevel@tonic-gate router_add_k(dr);
21030Sstevel@tonic-gate return (dr);
21040Sstevel@tonic-gate }
21050Sstevel@tonic-gate
21060Sstevel@tonic-gate /* Insert in linked list */
21070Sstevel@tonic-gate static void
router_insert(struct phyint * pi,struct router * dr)21080Sstevel@tonic-gate router_insert(struct phyint *pi, struct router *dr)
21090Sstevel@tonic-gate {
21100Sstevel@tonic-gate dr->dr_next = pi->pi_router_list;
21110Sstevel@tonic-gate dr->dr_prev = NULL;
21120Sstevel@tonic-gate if (pi->pi_router_list != NULL)
21130Sstevel@tonic-gate pi->pi_router_list->dr_prev = dr;
21140Sstevel@tonic-gate pi->pi_router_list = dr;
21150Sstevel@tonic-gate dr->dr_physical = pi;
21160Sstevel@tonic-gate }
21170Sstevel@tonic-gate
21180Sstevel@tonic-gate /*
21190Sstevel@tonic-gate * Delete (unlink and free).
21200Sstevel@tonic-gate * Handles delete of things that have not yet been inserted in the list
21210Sstevel@tonic-gate * i.e. dr_physical is NULL.
21220Sstevel@tonic-gate */
21230Sstevel@tonic-gate static void
router_delete(struct router * dr)21240Sstevel@tonic-gate router_delete(struct router *dr)
21250Sstevel@tonic-gate {
21260Sstevel@tonic-gate struct phyint *pi;
21270Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
21280Sstevel@tonic-gate
21290Sstevel@tonic-gate if (debug & D_ROUTER) {
21300Sstevel@tonic-gate logmsg(LOG_DEBUG, "router_delete(%s, %s, %u)\n",
21310Sstevel@tonic-gate dr->dr_physical->pi_name,
21320Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&dr->dr_address,
21330Sstevel@tonic-gate abuf, sizeof (abuf)), dr->dr_lifetime);
21340Sstevel@tonic-gate }
21350Sstevel@tonic-gate pi = dr->dr_physical;
21361577Sseb if (dr->dr_inkernel && (pi->pi_kernel_state & PI_PRESENT))
21371577Sseb router_delete_k(dr);
21380Sstevel@tonic-gate
21390Sstevel@tonic-gate if (dr->dr_prev == NULL) {
21400Sstevel@tonic-gate if (pi != NULL)
21410Sstevel@tonic-gate pi->pi_router_list = dr->dr_next;
21420Sstevel@tonic-gate } else {
21430Sstevel@tonic-gate dr->dr_prev->dr_next = dr->dr_next;
21440Sstevel@tonic-gate }
21450Sstevel@tonic-gate if (dr->dr_next != NULL)
21460Sstevel@tonic-gate dr->dr_next->dr_prev = dr->dr_prev;
21470Sstevel@tonic-gate dr->dr_next = dr->dr_prev = NULL;
21480Sstevel@tonic-gate free(dr);
21490Sstevel@tonic-gate }
21500Sstevel@tonic-gate
21510Sstevel@tonic-gate /*
21520Sstevel@tonic-gate * Update the kernel to match dr_lifetime
21530Sstevel@tonic-gate */
21540Sstevel@tonic-gate void
router_update_k(struct router * dr)21550Sstevel@tonic-gate router_update_k(struct router *dr)
21560Sstevel@tonic-gate {
21570Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
21580Sstevel@tonic-gate
21590Sstevel@tonic-gate if (debug & D_ROUTER) {
21600Sstevel@tonic-gate logmsg(LOG_DEBUG, "router_update_k(%s, %s, %u)\n",
21610Sstevel@tonic-gate dr->dr_physical->pi_name,
21620Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&dr->dr_address,
21630Sstevel@tonic-gate abuf, sizeof (abuf)), dr->dr_lifetime);
21640Sstevel@tonic-gate }
21650Sstevel@tonic-gate
21660Sstevel@tonic-gate if (dr->dr_lifetime == 0 && dr->dr_inkernel) {
21670Sstevel@tonic-gate /* Log a message when last router goes away */
21680Sstevel@tonic-gate if (dr->dr_physical->pi_num_k_routers == 1) {
21690Sstevel@tonic-gate logmsg(LOG_WARNING,
21700Sstevel@tonic-gate "Last default router (%s) removed on %s\n",
21710Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&dr->dr_address,
21720Sstevel@tonic-gate abuf, sizeof (abuf)), dr->dr_physical->pi_name);
21730Sstevel@tonic-gate }
21740Sstevel@tonic-gate router_delete(dr);
21751577Sseb } else if (dr->dr_lifetime != 0 && !dr->dr_inkernel)
21760Sstevel@tonic-gate router_add_k(dr);
21770Sstevel@tonic-gate }
21780Sstevel@tonic-gate
21790Sstevel@tonic-gate /*
21800Sstevel@tonic-gate * Called with the number of millseconds elapsed since the last call.
21810Sstevel@tonic-gate * Determines if any timeout event has occurred and
21820Sstevel@tonic-gate * returns the number of milliseconds until the next timeout event.
21830Sstevel@tonic-gate * Returns TIMER_INFINITY for "never".
21840Sstevel@tonic-gate */
21850Sstevel@tonic-gate uint_t
router_timer(struct router * dr,uint_t elapsed)21860Sstevel@tonic-gate router_timer(struct router *dr, uint_t elapsed)
21870Sstevel@tonic-gate {
21880Sstevel@tonic-gate uint_t next = TIMER_INFINITY;
21890Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
21900Sstevel@tonic-gate
21910Sstevel@tonic-gate if (debug & D_ROUTER) {
21920Sstevel@tonic-gate logmsg(LOG_DEBUG, "router_timer(%s, %s, %u, %d)\n",
21930Sstevel@tonic-gate dr->dr_physical->pi_name,
21940Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&dr->dr_address,
21950Sstevel@tonic-gate abuf, sizeof (abuf)), dr->dr_lifetime, elapsed);
21960Sstevel@tonic-gate }
21970Sstevel@tonic-gate if (dr->dr_lifetime <= elapsed) {
21980Sstevel@tonic-gate dr->dr_lifetime = 0;
21990Sstevel@tonic-gate } else {
22000Sstevel@tonic-gate dr->dr_lifetime -= elapsed;
22010Sstevel@tonic-gate if (dr->dr_lifetime < next)
22020Sstevel@tonic-gate next = dr->dr_lifetime;
22030Sstevel@tonic-gate }
22040Sstevel@tonic-gate
22050Sstevel@tonic-gate if (dr->dr_lifetime == 0) {
22060Sstevel@tonic-gate /* Log a message when last router goes away */
22070Sstevel@tonic-gate if (dr->dr_physical->pi_num_k_routers == 1) {
22080Sstevel@tonic-gate logmsg(LOG_WARNING,
22090Sstevel@tonic-gate "Last default router (%s) timed out on %s\n",
22100Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&dr->dr_address,
22110Sstevel@tonic-gate abuf, sizeof (abuf)), dr->dr_physical->pi_name);
22120Sstevel@tonic-gate }
22130Sstevel@tonic-gate router_delete(dr);
22140Sstevel@tonic-gate }
22150Sstevel@tonic-gate return (next);
22160Sstevel@tonic-gate }
22170Sstevel@tonic-gate
22180Sstevel@tonic-gate /*
22190Sstevel@tonic-gate * Add a default route to the kernel (unless the lifetime is zero)
22200Sstevel@tonic-gate * Handles onlink default routes.
22210Sstevel@tonic-gate */
22220Sstevel@tonic-gate static void
router_add_k(struct router * dr)22230Sstevel@tonic-gate router_add_k(struct router *dr)
22240Sstevel@tonic-gate {
22250Sstevel@tonic-gate struct phyint *pi = dr->dr_physical;
22260Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
22270Sstevel@tonic-gate int rlen;
22280Sstevel@tonic-gate
22290Sstevel@tonic-gate if (debug & D_ROUTER) {
22300Sstevel@tonic-gate logmsg(LOG_DEBUG, "router_add_k(%s, %s, %u)\n",
22310Sstevel@tonic-gate dr->dr_physical->pi_name,
22320Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&dr->dr_address,
22330Sstevel@tonic-gate abuf, sizeof (abuf)), dr->dr_lifetime);
22340Sstevel@tonic-gate }
22350Sstevel@tonic-gate
22360Sstevel@tonic-gate rta_gateway->sin6_addr = dr->dr_address;
22370Sstevel@tonic-gate
22380Sstevel@tonic-gate rta_ifp->sdl_index = if_nametoindex(pi->pi_name);
22390Sstevel@tonic-gate if (rta_ifp->sdl_index == 0) {
22400Sstevel@tonic-gate logperror_pi(pi, "router_add_k: if_nametoindex");
22410Sstevel@tonic-gate return;
22420Sstevel@tonic-gate }
22430Sstevel@tonic-gate
22441577Sseb rt_msg->rtm_flags = RTF_GATEWAY;
22450Sstevel@tonic-gate rt_msg->rtm_type = RTM_ADD;
22460Sstevel@tonic-gate rt_msg->rtm_seq = ++rtmseq;
22470Sstevel@tonic-gate rlen = write(rtsock, rt_msg, rt_msg->rtm_msglen);
22480Sstevel@tonic-gate if (rlen < 0) {
22490Sstevel@tonic-gate if (errno != EEXIST) {
22500Sstevel@tonic-gate logperror_pi(pi, "router_add_k: RTM_ADD");
22510Sstevel@tonic-gate return;
22520Sstevel@tonic-gate }
22530Sstevel@tonic-gate } else if (rlen < rt_msg->rtm_msglen) {
22540Sstevel@tonic-gate logmsg(LOG_ERR, "router_add_k: write to routing socket got "
22550Sstevel@tonic-gate "only %d for rlen (interface %s)\n", rlen, pi->pi_name);
22560Sstevel@tonic-gate return;
22570Sstevel@tonic-gate }
22580Sstevel@tonic-gate dr->dr_inkernel = _B_TRUE;
22591577Sseb pi->pi_num_k_routers++;
22600Sstevel@tonic-gate }
22610Sstevel@tonic-gate
22620Sstevel@tonic-gate /*
22630Sstevel@tonic-gate * Delete a route from the kernel.
22640Sstevel@tonic-gate * Handles onlink default routes.
22650Sstevel@tonic-gate */
22660Sstevel@tonic-gate static void
router_delete_k(struct router * dr)22670Sstevel@tonic-gate router_delete_k(struct router *dr)
22680Sstevel@tonic-gate {
22690Sstevel@tonic-gate struct phyint *pi = dr->dr_physical;
22700Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
22710Sstevel@tonic-gate int rlen;
22720Sstevel@tonic-gate
22730Sstevel@tonic-gate if (debug & D_ROUTER) {
22740Sstevel@tonic-gate logmsg(LOG_DEBUG, "router_delete_k(%s, %s, %u)\n",
22750Sstevel@tonic-gate dr->dr_physical->pi_name,
22760Sstevel@tonic-gate inet_ntop(AF_INET6, (void *)&dr->dr_address,
22770Sstevel@tonic-gate abuf, sizeof (abuf)), dr->dr_lifetime);
22780Sstevel@tonic-gate }
22790Sstevel@tonic-gate
22800Sstevel@tonic-gate rta_gateway->sin6_addr = dr->dr_address;
22810Sstevel@tonic-gate
22820Sstevel@tonic-gate rta_ifp->sdl_index = if_nametoindex(pi->pi_name);
22830Sstevel@tonic-gate if (rta_ifp->sdl_index == 0) {
22840Sstevel@tonic-gate logperror_pi(pi, "router_delete_k: if_nametoindex");
22850Sstevel@tonic-gate return;
22860Sstevel@tonic-gate }
22870Sstevel@tonic-gate
22881577Sseb rt_msg->rtm_flags = RTF_GATEWAY;
22890Sstevel@tonic-gate rt_msg->rtm_type = RTM_DELETE;
22900Sstevel@tonic-gate rt_msg->rtm_seq = ++rtmseq;
22910Sstevel@tonic-gate rlen = write(rtsock, rt_msg, rt_msg->rtm_msglen);
22920Sstevel@tonic-gate if (rlen < 0) {
22930Sstevel@tonic-gate if (errno != ESRCH) {
22940Sstevel@tonic-gate logperror_pi(pi, "router_delete_k: RTM_DELETE");
22950Sstevel@tonic-gate }
22960Sstevel@tonic-gate } else if (rlen < rt_msg->rtm_msglen) {
22970Sstevel@tonic-gate logmsg(LOG_ERR, "router_delete_k: write to routing socket got "
22980Sstevel@tonic-gate "only %d for rlen (interface %s)\n", rlen, pi->pi_name);
22990Sstevel@tonic-gate }
23000Sstevel@tonic-gate dr->dr_inkernel = _B_FALSE;
23011577Sseb pi->pi_num_k_routers--;
23020Sstevel@tonic-gate }
23030Sstevel@tonic-gate
23040Sstevel@tonic-gate static void
router_print(struct router * dr)23050Sstevel@tonic-gate router_print(struct router *dr)
23060Sstevel@tonic-gate {
23070Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN];
23080Sstevel@tonic-gate
23091577Sseb logmsg(LOG_DEBUG, "Router %s on %s inkernel %d lifetime %u\n",
23101577Sseb inet_ntop(AF_INET6, (void *)&dr->dr_address, abuf, sizeof (abuf)),
23111577Sseb dr->dr_physical->pi_name, dr->dr_inkernel, dr->dr_lifetime);
23120Sstevel@tonic-gate }
23130Sstevel@tonic-gate
23140Sstevel@tonic-gate void
phyint_print_all(void)23150Sstevel@tonic-gate phyint_print_all(void)
23160Sstevel@tonic-gate {
23170Sstevel@tonic-gate struct phyint *pi;
23180Sstevel@tonic-gate
23190Sstevel@tonic-gate for (pi = phyints; pi != NULL; pi = pi->pi_next) {
23200Sstevel@tonic-gate phyint_print(pi);
23210Sstevel@tonic-gate }
23220Sstevel@tonic-gate }
23230Sstevel@tonic-gate
23240Sstevel@tonic-gate void
phyint_cleanup(struct phyint * pi)23258485SPeter.Memishian@Sun.COM phyint_cleanup(struct phyint *pi)
23260Sstevel@tonic-gate {
23270Sstevel@tonic-gate pi->pi_state = 0;
23280Sstevel@tonic-gate pi->pi_kernel_state = 0;
23290Sstevel@tonic-gate
23300Sstevel@tonic-gate if (pi->pi_AdvSendAdvertisements) {
23310Sstevel@tonic-gate check_to_advertise(pi, ADV_OFF);
23320Sstevel@tonic-gate } else {
23330Sstevel@tonic-gate check_to_solicit(pi, SOLICIT_OFF);
23340Sstevel@tonic-gate }
23350Sstevel@tonic-gate
23360Sstevel@tonic-gate while (pi->pi_router_list)
23370Sstevel@tonic-gate router_delete(pi->pi_router_list);
23380Sstevel@tonic-gate (void) poll_remove(pi->pi_sock);
23390Sstevel@tonic-gate (void) close(pi->pi_sock);
23400Sstevel@tonic-gate pi->pi_sock = -1;
2341*12016SGirish.Moodalbail@Sun.COM pi->pi_stateless = pi->pi_StatelessAddrConf;
2342*12016SGirish.Moodalbail@Sun.COM pi->pi_stateful = pi->pi_StatefulAddrConf;
2343*12016SGirish.Moodalbail@Sun.COM pi->pi_ipadm_aobjname[0] = '\0';
23440Sstevel@tonic-gate }
2345*12016SGirish.Moodalbail@Sun.COM
2346*12016SGirish.Moodalbail@Sun.COM /*
2347*12016SGirish.Moodalbail@Sun.COM * Sets/removes the ipadm address object name for the given prefix.
2348*12016SGirish.Moodalbail@Sun.COM */
2349*12016SGirish.Moodalbail@Sun.COM void
prefix_update_ipadm_addrobj(struct prefix * pr,boolean_t add)2350*12016SGirish.Moodalbail@Sun.COM prefix_update_ipadm_addrobj(struct prefix *pr, boolean_t add)
2351*12016SGirish.Moodalbail@Sun.COM {
2352*12016SGirish.Moodalbail@Sun.COM struct phyint *pi = pr->pr_physical;
2353*12016SGirish.Moodalbail@Sun.COM int lnum = 0;
2354*12016SGirish.Moodalbail@Sun.COM char *cp;
2355*12016SGirish.Moodalbail@Sun.COM ipadm_handle_t iph;
2356*12016SGirish.Moodalbail@Sun.COM ipadm_status_t status;
2357*12016SGirish.Moodalbail@Sun.COM
2358*12016SGirish.Moodalbail@Sun.COM /*
2359*12016SGirish.Moodalbail@Sun.COM * If ipadm was used to autoconfigure this interface,
2360*12016SGirish.Moodalbail@Sun.COM * pi_ipadm_aobjname will contain the address object name
2361*12016SGirish.Moodalbail@Sun.COM * that is used to identify the addresses. Use the same
2362*12016SGirish.Moodalbail@Sun.COM * address object name for this prefix.
2363*12016SGirish.Moodalbail@Sun.COM */
2364*12016SGirish.Moodalbail@Sun.COM if (pi->pi_ipadm_aobjname[0] == '\0' ||
2365*12016SGirish.Moodalbail@Sun.COM pr->pr_name[0] == '\0' || IN6_IS_ADDR_LINKLOCAL(&pr->pr_address) ||
2366*12016SGirish.Moodalbail@Sun.COM (!(pr->pr_flags & IFF_ADDRCONF) &&
2367*12016SGirish.Moodalbail@Sun.COM !(pr->pr_flags & IFF_DHCPRUNNING))) {
2368*12016SGirish.Moodalbail@Sun.COM return;
2369*12016SGirish.Moodalbail@Sun.COM }
2370*12016SGirish.Moodalbail@Sun.COM if ((status = ipadm_open(&iph, 0)) != IPADM_SUCCESS) {
2371*12016SGirish.Moodalbail@Sun.COM logmsg(LOG_ERR, "Could not open handle to libipadm: %s\n",
2372*12016SGirish.Moodalbail@Sun.COM ipadm_status2str(status));
2373*12016SGirish.Moodalbail@Sun.COM return;
2374*12016SGirish.Moodalbail@Sun.COM }
2375*12016SGirish.Moodalbail@Sun.COM cp = strrchr(pr->pr_name, ':');
2376*12016SGirish.Moodalbail@Sun.COM if (cp != NULL)
2377*12016SGirish.Moodalbail@Sun.COM lnum = atoi(++cp);
2378*12016SGirish.Moodalbail@Sun.COM if (add) {
2379*12016SGirish.Moodalbail@Sun.COM status = ipadm_add_aobjname(iph, pi->pi_name, AF_INET6,
2380*12016SGirish.Moodalbail@Sun.COM pi->pi_ipadm_aobjname, IPADM_ADDR_IPV6_ADDRCONF, lnum);
2381*12016SGirish.Moodalbail@Sun.COM } else {
2382*12016SGirish.Moodalbail@Sun.COM status = ipadm_delete_aobjname(iph, pi->pi_name, AF_INET6,
2383*12016SGirish.Moodalbail@Sun.COM pi->pi_ipadm_aobjname, IPADM_ADDR_IPV6_ADDRCONF, lnum);
2384*12016SGirish.Moodalbail@Sun.COM }
2385*12016SGirish.Moodalbail@Sun.COM /* Ignore the error if the ipmgmtd daemon is not running */
2386*12016SGirish.Moodalbail@Sun.COM if (status != IPADM_SUCCESS && status != IPADM_IPC_ERROR) {
2387*12016SGirish.Moodalbail@Sun.COM logmsg(LOG_ERR, "ipadm error in %s '%s' : %s\n",
2388*12016SGirish.Moodalbail@Sun.COM (add ? "adding" : "deleting"), pi->pi_ipadm_aobjname,
2389*12016SGirish.Moodalbail@Sun.COM ipadm_status2str(status));
2390*12016SGirish.Moodalbail@Sun.COM }
2391*12016SGirish.Moodalbail@Sun.COM ipadm_close(iph);
2392*12016SGirish.Moodalbail@Sun.COM }
2393