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 52074Smeem * Common Development and Distribution License (the "License"). 62074Smeem * 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 /* 228485SPeter.Memishian@Sun.COM * Copyright 2009 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 "mpd_defs.h" 270Sstevel@tonic-gate #include "mpd_tables.h" 280Sstevel@tonic-gate 290Sstevel@tonic-gate int debug = 0; /* Debug flag */ 300Sstevel@tonic-gate static int pollfd_num = 0; /* Num. of poll descriptors */ 310Sstevel@tonic-gate static struct pollfd *pollfds = NULL; /* Array of poll descriptors */ 320Sstevel@tonic-gate /* All times below in ms */ 330Sstevel@tonic-gate int user_failure_detection_time; /* user specified failure detection */ 340Sstevel@tonic-gate /* time (fdt) */ 350Sstevel@tonic-gate int user_probe_interval; /* derived from user specified fdt */ 360Sstevel@tonic-gate 37*8865SJonathan.Anderson@Sun.COM /* 38*8865SJonathan.Anderson@Sun.COM * Structure to store mib2 information returned by the kernel. 39*8865SJonathan.Anderson@Sun.COM * This is used to process routing table information. 40*8865SJonathan.Anderson@Sun.COM */ 41*8865SJonathan.Anderson@Sun.COM typedef struct mib_item_s { 42*8865SJonathan.Anderson@Sun.COM struct mib_item_s *mi_next; 43*8865SJonathan.Anderson@Sun.COM struct opthdr mi_opthdr; 44*8865SJonathan.Anderson@Sun.COM void *mi_valp; 45*8865SJonathan.Anderson@Sun.COM } mib_item_t; 46*8865SJonathan.Anderson@Sun.COM 470Sstevel@tonic-gate static int rtsock_v4; /* AF_INET routing socket */ 480Sstevel@tonic-gate static int rtsock_v6; /* AF_INET6 routing socket */ 490Sstevel@tonic-gate int ifsock_v4 = -1; /* IPv4 socket for ioctls */ 500Sstevel@tonic-gate int ifsock_v6 = -1; /* IPv6 socket for ioctls */ 510Sstevel@tonic-gate static int lsock_v4; /* Listen socket to detect mpathd */ 520Sstevel@tonic-gate static int lsock_v6; /* Listen socket to detect mpathd */ 530Sstevel@tonic-gate static int mibfd = -1; /* fd to get mib info */ 540Sstevel@tonic-gate static boolean_t force_mcast = _B_FALSE; /* Only for test purposes */ 550Sstevel@tonic-gate 560Sstevel@tonic-gate static uint_t last_initifs_time; /* Time when initifs was last run */ 570Sstevel@tonic-gate static char **argv0; /* Saved for re-exec on SIGHUP */ 580Sstevel@tonic-gate boolean_t handle_link_notifications = _B_TRUE; 59*8865SJonathan.Anderson@Sun.COM static int ipRouteEntrySize; /* Size of IPv4 route entry */ 60*8865SJonathan.Anderson@Sun.COM static int ipv6RouteEntrySize; /* Size of IPv6 route entry */ 610Sstevel@tonic-gate 620Sstevel@tonic-gate static void initlog(void); 630Sstevel@tonic-gate static void run_timeouts(void); 640Sstevel@tonic-gate static void initifs(void); 650Sstevel@tonic-gate static void check_if_removed(struct phyint_instance *pii); 660Sstevel@tonic-gate static void select_test_ifs(void); 67*8865SJonathan.Anderson@Sun.COM static void update_router_list(mib_item_t *item); 68*8865SJonathan.Anderson@Sun.COM static void mib_get_constants(mib_item_t *item); 69*8865SJonathan.Anderson@Sun.COM static int mibwalk(void (*proc)(mib_item_t *)); 700Sstevel@tonic-gate static void ire_process_v4(mib2_ipRouteEntry_t *buf, size_t len); 710Sstevel@tonic-gate static void ire_process_v6(mib2_ipv6RouteEntry_t *buf, size_t len); 720Sstevel@tonic-gate static void router_add_common(int af, char *ifname, 730Sstevel@tonic-gate struct in6_addr nexthop); 740Sstevel@tonic-gate static void init_router_targets(); 750Sstevel@tonic-gate static void cleanup(void); 760Sstevel@tonic-gate static int setup_listener(int af); 770Sstevel@tonic-gate static void check_config(void); 784770Smeem static void check_testconfig(void); 792496Smeem static void check_addr_unique(struct phyint_instance *, 802496Smeem struct sockaddr_storage *); 810Sstevel@tonic-gate static void init_host_targets(void); 820Sstevel@tonic-gate static void dup_host_targets(struct phyint_instance *desired_pii); 830Sstevel@tonic-gate static void loopback_cmd(int sock, int family); 840Sstevel@tonic-gate static boolean_t daemonize(void); 850Sstevel@tonic-gate static int closefunc(void *, int); 860Sstevel@tonic-gate static unsigned int process_cmd(int newfd, union mi_commands *mpi); 870Sstevel@tonic-gate static unsigned int process_query(int fd, mi_query_t *miq); 888485SPeter.Memishian@Sun.COM static unsigned int send_addrinfo(int fd, ipmp_addrinfo_t *adinfop); 890Sstevel@tonic-gate static unsigned int send_groupinfo(int fd, ipmp_groupinfo_t *grinfop); 900Sstevel@tonic-gate static unsigned int send_grouplist(int fd, ipmp_grouplist_t *grlistp); 910Sstevel@tonic-gate static unsigned int send_ifinfo(int fd, ipmp_ifinfo_t *ifinfop); 920Sstevel@tonic-gate static unsigned int send_result(int fd, unsigned int error, int syserror); 930Sstevel@tonic-gate 948485SPeter.Memishian@Sun.COM addrlist_t *localaddrs; 952250Srk129064 960Sstevel@tonic-gate /* 970Sstevel@tonic-gate * Return the current time in milliseconds (from an arbitrary reference) 980Sstevel@tonic-gate * truncated to fit into an int. Truncation is ok since we are interested 990Sstevel@tonic-gate * only in differences and not the absolute values. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate uint_t 1020Sstevel@tonic-gate getcurrenttime(void) 1030Sstevel@tonic-gate { 1040Sstevel@tonic-gate uint_t cur_time; /* In ms */ 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate /* 1070Sstevel@tonic-gate * Use of a non-user-adjustable source of time is 1080Sstevel@tonic-gate * required. However millisecond precision is sufficient. 1090Sstevel@tonic-gate * divide by 10^6 1100Sstevel@tonic-gate */ 1110Sstevel@tonic-gate cur_time = (uint_t)(gethrtime() / 1000000LL); 1120Sstevel@tonic-gate return (cur_time); 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 1154770Smeem uint64_t 1164770Smeem getcurrentsec(void) 1174770Smeem { 1184770Smeem return (gethrtime() / NANOSEC); 1194770Smeem } 1204770Smeem 1210Sstevel@tonic-gate /* 1220Sstevel@tonic-gate * Add fd to the set being polled. Returns 0 if ok; -1 if failed. 1230Sstevel@tonic-gate */ 1240Sstevel@tonic-gate int 1250Sstevel@tonic-gate poll_add(int fd) 1260Sstevel@tonic-gate { 1270Sstevel@tonic-gate int i; 1280Sstevel@tonic-gate int new_num; 1290Sstevel@tonic-gate struct pollfd *newfds; 1300Sstevel@tonic-gate retry: 1310Sstevel@tonic-gate /* Check if already present */ 1320Sstevel@tonic-gate for (i = 0; i < pollfd_num; i++) { 1330Sstevel@tonic-gate if (pollfds[i].fd == fd) 1340Sstevel@tonic-gate return (0); 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate /* Check for empty spot already present */ 1370Sstevel@tonic-gate for (i = 0; i < pollfd_num; i++) { 1380Sstevel@tonic-gate if (pollfds[i].fd == -1) { 1390Sstevel@tonic-gate pollfds[i].fd = fd; 1400Sstevel@tonic-gate return (0); 1410Sstevel@tonic-gate } 1420Sstevel@tonic-gate } 1430Sstevel@tonic-gate 1440Sstevel@tonic-gate /* Allocate space for 32 more fds and initialize to -1 */ 1450Sstevel@tonic-gate new_num = pollfd_num + 32; 1460Sstevel@tonic-gate newfds = realloc(pollfds, new_num * sizeof (struct pollfd)); 1470Sstevel@tonic-gate if (newfds == NULL) { 1480Sstevel@tonic-gate logperror("poll_add: realloc"); 1490Sstevel@tonic-gate return (-1); 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate for (i = pollfd_num; i < new_num; i++) { 1520Sstevel@tonic-gate newfds[i].fd = -1; 1530Sstevel@tonic-gate newfds[i].events = POLLIN; 1540Sstevel@tonic-gate } 1550Sstevel@tonic-gate pollfd_num = new_num; 1560Sstevel@tonic-gate pollfds = newfds; 1570Sstevel@tonic-gate goto retry; 1580Sstevel@tonic-gate } 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate /* 1610Sstevel@tonic-gate * Remove fd from the set being polled. Returns 0 if ok; -1 if failed. 1620Sstevel@tonic-gate */ 1638485SPeter.Memishian@Sun.COM int 1640Sstevel@tonic-gate poll_remove(int fd) 1650Sstevel@tonic-gate { 1660Sstevel@tonic-gate int i; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate /* Check if already present */ 1690Sstevel@tonic-gate for (i = 0; i < pollfd_num; i++) { 1700Sstevel@tonic-gate if (pollfds[i].fd == fd) { 1710Sstevel@tonic-gate pollfds[i].fd = -1; 1720Sstevel@tonic-gate return (0); 1730Sstevel@tonic-gate } 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate return (-1); 1760Sstevel@tonic-gate } 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate /* 1790Sstevel@tonic-gate * Extract information about the phyint instance. If the phyint instance still 1800Sstevel@tonic-gate * exists in the kernel then set pii_in_use, else clear it. check_if_removed() 1810Sstevel@tonic-gate * will use it to detect phyint instances that don't exist any longer and 1820Sstevel@tonic-gate * remove them, from our database of phyint instances. 1830Sstevel@tonic-gate * Return value: 1840Sstevel@tonic-gate * returns true if the phyint instance exists in the kernel, 1850Sstevel@tonic-gate * returns false otherwise 1860Sstevel@tonic-gate */ 1870Sstevel@tonic-gate static boolean_t 1880Sstevel@tonic-gate pii_process(int af, char *name, struct phyint_instance **pii_p) 1890Sstevel@tonic-gate { 1900Sstevel@tonic-gate int err; 1910Sstevel@tonic-gate struct phyint_instance *pii; 1920Sstevel@tonic-gate struct phyint_instance *pii_other; 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate if (debug & D_PHYINT) 1950Sstevel@tonic-gate logdebug("pii_process(%s %s)\n", AF_STR(af), name); 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate pii = phyint_inst_lookup(af, name); 1980Sstevel@tonic-gate if (pii == NULL) { 1990Sstevel@tonic-gate /* 2000Sstevel@tonic-gate * Phyint instance does not exist in our tables, 2010Sstevel@tonic-gate * create new phyint instance 2020Sstevel@tonic-gate */ 2030Sstevel@tonic-gate pii = phyint_inst_init_from_k(af, name); 2040Sstevel@tonic-gate } else { 2050Sstevel@tonic-gate /* Phyint exists in our tables */ 2060Sstevel@tonic-gate err = phyint_inst_update_from_k(pii); 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate switch (err) { 2090Sstevel@tonic-gate case PI_IOCTL_ERROR: 2100Sstevel@tonic-gate /* Some ioctl error. don't change anything */ 2110Sstevel@tonic-gate pii->pii_in_use = 1; 2120Sstevel@tonic-gate break; 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate case PI_GROUP_CHANGED: 2150Sstevel@tonic-gate case PI_IFINDEX_CHANGED: 2160Sstevel@tonic-gate /* 2178485SPeter.Memishian@Sun.COM * Interface index or group membership has changed. 2188485SPeter.Memishian@Sun.COM * Delete the old state and recreate based on the new 2198485SPeter.Memishian@Sun.COM * state (it may no longer be in a group). 2200Sstevel@tonic-gate */ 2210Sstevel@tonic-gate pii_other = phyint_inst_other(pii); 2220Sstevel@tonic-gate if (pii_other != NULL) 2230Sstevel@tonic-gate phyint_inst_delete(pii_other); 2240Sstevel@tonic-gate phyint_inst_delete(pii); 2250Sstevel@tonic-gate pii = phyint_inst_init_from_k(af, name); 2260Sstevel@tonic-gate break; 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate case PI_DELETED: 2290Sstevel@tonic-gate /* Phyint instance has disappeared from kernel */ 2300Sstevel@tonic-gate pii->pii_in_use = 0; 2310Sstevel@tonic-gate break; 2320Sstevel@tonic-gate 2330Sstevel@tonic-gate case PI_OK: 2340Sstevel@tonic-gate /* Phyint instance exists and is fine */ 2350Sstevel@tonic-gate pii->pii_in_use = 1; 2360Sstevel@tonic-gate break; 2370Sstevel@tonic-gate 2380Sstevel@tonic-gate default: 2390Sstevel@tonic-gate /* Unknown status */ 2400Sstevel@tonic-gate logerr("pii_process: Unknown status %d\n", err); 2410Sstevel@tonic-gate break; 2420Sstevel@tonic-gate } 2430Sstevel@tonic-gate } 2440Sstevel@tonic-gate 2450Sstevel@tonic-gate *pii_p = pii; 2460Sstevel@tonic-gate if (pii != NULL) 2470Sstevel@tonic-gate return (pii->pii_in_use ? _B_TRUE : _B_FALSE); 2480Sstevel@tonic-gate else 2490Sstevel@tonic-gate return (_B_FALSE); 2500Sstevel@tonic-gate } 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate /* 2530Sstevel@tonic-gate * Scan all interfaces to detect changes as well as new and deleted interfaces 2540Sstevel@tonic-gate */ 2550Sstevel@tonic-gate static void 2560Sstevel@tonic-gate initifs() 2570Sstevel@tonic-gate { 2588485SPeter.Memishian@Sun.COM int i, nlifr; 2590Sstevel@tonic-gate int af; 2600Sstevel@tonic-gate char *cp; 2610Sstevel@tonic-gate char *buf; 2628485SPeter.Memishian@Sun.COM int sockfd; 2638485SPeter.Memishian@Sun.COM uint64_t flags; 2640Sstevel@tonic-gate struct lifnum lifn; 2650Sstevel@tonic-gate struct lifconf lifc; 2668485SPeter.Memishian@Sun.COM struct lifreq lifreq; 2670Sstevel@tonic-gate struct lifreq *lifr; 2680Sstevel@tonic-gate struct logint *li; 2690Sstevel@tonic-gate struct phyint_instance *pii; 2700Sstevel@tonic-gate struct phyint_instance *next_pii; 2718485SPeter.Memishian@Sun.COM struct phyint_group *pg, *next_pg; 2728485SPeter.Memishian@Sun.COM char pi_name[LIFNAMSIZ + 1]; 2730Sstevel@tonic-gate 2740Sstevel@tonic-gate if (debug & D_PHYINT) 2750Sstevel@tonic-gate logdebug("initifs: Scanning interfaces\n"); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate last_initifs_time = getcurrenttime(); 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate /* 2808485SPeter.Memishian@Sun.COM * Free the existing local address list; we'll build a new list below. 2812250Srk129064 */ 2828485SPeter.Memishian@Sun.COM addrlist_free(&localaddrs); 2832250Srk129064 2842250Srk129064 /* 2850Sstevel@tonic-gate * Mark the interfaces so that we can find phyints and logints 2860Sstevel@tonic-gate * which have disappeared from the kernel. pii_process() and 2870Sstevel@tonic-gate * logint_init_from_k() will set {pii,li}_in_use when they find 2880Sstevel@tonic-gate * the interface in the kernel. Also, clear dupaddr bit on probe 2890Sstevel@tonic-gate * logint. check_addr_unique() will set the dupaddr bit on the 2900Sstevel@tonic-gate * probe logint, if the testaddress is not unique. 2910Sstevel@tonic-gate */ 2920Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; pii = pii->pii_next) { 2930Sstevel@tonic-gate pii->pii_in_use = 0; 2940Sstevel@tonic-gate for (li = pii->pii_logint; li != NULL; li = li->li_next) { 2950Sstevel@tonic-gate li->li_in_use = 0; 2960Sstevel@tonic-gate if (pii->pii_probe_logint == li) 2970Sstevel@tonic-gate li->li_dupaddr = 0; 2980Sstevel@tonic-gate } 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate 3018485SPeter.Memishian@Sun.COM /* 3028485SPeter.Memishian@Sun.COM * As above, mark groups so that we can detect IPMP interfaces which 3038485SPeter.Memishian@Sun.COM * have been removed from the kernel. Also, delete the group address 3048485SPeter.Memishian@Sun.COM * list since we'll iteratively recreate it below. 3058485SPeter.Memishian@Sun.COM */ 3068485SPeter.Memishian@Sun.COM for (pg = phyint_groups; pg != NULL; pg = pg->pg_next) { 3078485SPeter.Memishian@Sun.COM pg->pg_in_use = _B_FALSE; 3088485SPeter.Memishian@Sun.COM addrlist_free(&pg->pg_addrs); 3098485SPeter.Memishian@Sun.COM } 3108485SPeter.Memishian@Sun.COM 3110Sstevel@tonic-gate lifn.lifn_family = AF_UNSPEC; 3128485SPeter.Memishian@Sun.COM lifn.lifn_flags = LIFC_ALLZONES | LIFC_UNDER_IPMP; 3138485SPeter.Memishian@Sun.COM again: 3140Sstevel@tonic-gate if (ioctl(ifsock_v4, SIOCGLIFNUM, (char *)&lifn) < 0) { 3158485SPeter.Memishian@Sun.COM logperror("initifs: ioctl (get interface count)"); 3160Sstevel@tonic-gate return; 3170Sstevel@tonic-gate } 3188485SPeter.Memishian@Sun.COM /* 3198485SPeter.Memishian@Sun.COM * Pad the interface count to detect when additional interfaces have 3208485SPeter.Memishian@Sun.COM * been configured between SIOCGLIFNUM and SIOCGLIFCONF. 3218485SPeter.Memishian@Sun.COM */ 3228485SPeter.Memishian@Sun.COM lifn.lifn_count += 4; 3238485SPeter.Memishian@Sun.COM 3248485SPeter.Memishian@Sun.COM if ((buf = calloc(lifn.lifn_count, sizeof (struct lifreq))) == NULL) { 3250Sstevel@tonic-gate logperror("initifs: calloc"); 3260Sstevel@tonic-gate return; 3270Sstevel@tonic-gate } 3280Sstevel@tonic-gate 3290Sstevel@tonic-gate lifc.lifc_family = AF_UNSPEC; 3308485SPeter.Memishian@Sun.COM lifc.lifc_flags = LIFC_ALLZONES | LIFC_UNDER_IPMP; 3318485SPeter.Memishian@Sun.COM lifc.lifc_len = lifn.lifn_count * sizeof (struct lifreq); 3320Sstevel@tonic-gate lifc.lifc_buf = buf; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate if (ioctl(ifsock_v4, SIOCGLIFCONF, (char *)&lifc) < 0) { 3358485SPeter.Memishian@Sun.COM logperror("initifs: ioctl (get interface configuration)"); 3360Sstevel@tonic-gate free(buf); 3370Sstevel@tonic-gate return; 3380Sstevel@tonic-gate } 3390Sstevel@tonic-gate 3408485SPeter.Memishian@Sun.COM /* 3418485SPeter.Memishian@Sun.COM * If every lifr_req slot is taken, then additional interfaces must 3428485SPeter.Memishian@Sun.COM * have been plumbed between the SIOCGLIFNUM and the SIOCGLIFCONF. 3438485SPeter.Memishian@Sun.COM * Recalculate to make sure we didn't miss any interfaces. 3448485SPeter.Memishian@Sun.COM */ 3458485SPeter.Memishian@Sun.COM nlifr = lifc.lifc_len / sizeof (struct lifreq); 3468485SPeter.Memishian@Sun.COM if (nlifr >= lifn.lifn_count) { 3478485SPeter.Memishian@Sun.COM free(buf); 3488485SPeter.Memishian@Sun.COM goto again; 3498485SPeter.Memishian@Sun.COM } 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate /* 3528485SPeter.Memishian@Sun.COM * Walk through the lifreqs returned by SIOGGLIFCONF, and refresh the 3538485SPeter.Memishian@Sun.COM * global list of addresses, phyint groups, phyints, and logints. 3540Sstevel@tonic-gate */ 3558485SPeter.Memishian@Sun.COM for (lifr = lifc.lifc_req, i = 0; i < nlifr; i++, lifr++) { 3560Sstevel@tonic-gate af = lifr->lifr_addr.ss_family; 3572250Srk129064 sockfd = (af == AF_INET) ? ifsock_v4 : ifsock_v6; 3588485SPeter.Memishian@Sun.COM (void) strlcpy(lifreq.lifr_name, lifr->lifr_name, LIFNAMSIZ); 3592250Srk129064 3602250Srk129064 if (ioctl(sockfd, SIOCGLIFFLAGS, &lifreq) == -1) { 3612250Srk129064 if (errno != ENXIO) 3622250Srk129064 logperror("initifs: ioctl (SIOCGLIFFLAGS)"); 3632250Srk129064 continue; 3642250Srk129064 } 3658485SPeter.Memishian@Sun.COM flags = lifreq.lifr_flags; 3662250Srk129064 3672250Srk129064 /* 3688485SPeter.Memishian@Sun.COM * If the address is IFF_UP, add it to the local address list. 3698485SPeter.Memishian@Sun.COM * (We ignore addresses that aren't IFF_UP since another node 3708485SPeter.Memishian@Sun.COM * might legitimately have that address IFF_UP.) 3712250Srk129064 */ 3728485SPeter.Memishian@Sun.COM if (flags & IFF_UP) { 3738485SPeter.Memishian@Sun.COM (void) addrlist_add(&localaddrs, lifr->lifr_name, flags, 3748485SPeter.Memishian@Sun.COM &lifr->lifr_addr); 3752250Srk129064 } 3762250Srk129064 3772250Srk129064 /* 3788485SPeter.Memishian@Sun.COM * If this address is on an IPMP meta-interface, update our 3798485SPeter.Memishian@Sun.COM * phyint_group information (either by recording that group 3808485SPeter.Memishian@Sun.COM * still exists or creating a new group), and track what 3818485SPeter.Memishian@Sun.COM * group the address is part of. 3828485SPeter.Memishian@Sun.COM */ 3838485SPeter.Memishian@Sun.COM if (flags & IFF_IPMP) { 3848485SPeter.Memishian@Sun.COM if (ioctl(sockfd, SIOCGLIFGROUPNAME, &lifreq) == -1) { 3858485SPeter.Memishian@Sun.COM if (errno != ENXIO) 3868485SPeter.Memishian@Sun.COM logperror("initifs: ioctl " 3878485SPeter.Memishian@Sun.COM "(SIOCGLIFGROUPNAME)"); 3888485SPeter.Memishian@Sun.COM continue; 3898485SPeter.Memishian@Sun.COM } 3908485SPeter.Memishian@Sun.COM 3918485SPeter.Memishian@Sun.COM pg = phyint_group_lookup(lifreq.lifr_groupname); 3928485SPeter.Memishian@Sun.COM if (pg == NULL) { 3938485SPeter.Memishian@Sun.COM pg = phyint_group_create(lifreq.lifr_groupname); 3948485SPeter.Memishian@Sun.COM if (pg == NULL) { 3958485SPeter.Memishian@Sun.COM logerr("initifs: cannot create group " 3968485SPeter.Memishian@Sun.COM "%s\n", lifreq.lifr_groupname); 3978485SPeter.Memishian@Sun.COM continue; 3988485SPeter.Memishian@Sun.COM } 3998485SPeter.Memishian@Sun.COM phyint_group_insert(pg); 4008485SPeter.Memishian@Sun.COM } 4018485SPeter.Memishian@Sun.COM pg->pg_in_use = _B_TRUE; 4028485SPeter.Memishian@Sun.COM 4038485SPeter.Memishian@Sun.COM /* 4048485SPeter.Memishian@Sun.COM * Add this to the group's list of data addresses. 4058485SPeter.Memishian@Sun.COM */ 4068485SPeter.Memishian@Sun.COM if (!addrlist_add(&pg->pg_addrs, lifr->lifr_name, flags, 4078485SPeter.Memishian@Sun.COM &lifr->lifr_addr)) { 4088485SPeter.Memishian@Sun.COM logerr("initifs: insufficient memory to track " 4098485SPeter.Memishian@Sun.COM "data address information for %s\n", 4108485SPeter.Memishian@Sun.COM lifr->lifr_name); 4118485SPeter.Memishian@Sun.COM } 4128485SPeter.Memishian@Sun.COM continue; 4138485SPeter.Memishian@Sun.COM } 4148485SPeter.Memishian@Sun.COM 4158485SPeter.Memishian@Sun.COM /* 4168485SPeter.Memishian@Sun.COM * This isn't an address on an IPMP meta-interface, so it's 4178485SPeter.Memishian@Sun.COM * either on an underlying interface or not related to any 4188485SPeter.Memishian@Sun.COM * group. Update our phyint and logint information (via 4198485SPeter.Memishian@Sun.COM * pii_process() and logint_init_from_k()) -- but first, 4208485SPeter.Memishian@Sun.COM * convert the logint name to a phyint name so we can call 4218485SPeter.Memishian@Sun.COM * pii_process(). 4220Sstevel@tonic-gate */ 4232250Srk129064 (void) strlcpy(pi_name, lifr->lifr_name, sizeof (pi_name)); 4240Sstevel@tonic-gate if ((cp = strchr(pi_name, IF_SEPARATOR)) != NULL) 4250Sstevel@tonic-gate *cp = '\0'; 4260Sstevel@tonic-gate 4278485SPeter.Memishian@Sun.COM if (pii_process(af, pi_name, &pii)) { 4280Sstevel@tonic-gate /* The phyint is fine. So process the logint */ 4290Sstevel@tonic-gate logint_init_from_k(pii, lifr->lifr_name); 4302496Smeem check_addr_unique(pii, &lifr->lifr_addr); 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate free(buf); 4340Sstevel@tonic-gate 4350Sstevel@tonic-gate /* 4368485SPeter.Memishian@Sun.COM * Scan for groups, phyints and logints that have disappeared from the 4370Sstevel@tonic-gate * kernel, and delete them. 4380Sstevel@tonic-gate */ 4394770Smeem for (pii = phyint_instances; pii != NULL; pii = next_pii) { 4400Sstevel@tonic-gate next_pii = pii->pii_next; 4410Sstevel@tonic-gate check_if_removed(pii); 4420Sstevel@tonic-gate } 4430Sstevel@tonic-gate 4448485SPeter.Memishian@Sun.COM for (pg = phyint_groups; pg != NULL; pg = next_pg) { 4458485SPeter.Memishian@Sun.COM next_pg = pg->pg_next; 4468485SPeter.Memishian@Sun.COM if (!pg->pg_in_use) { 4478485SPeter.Memishian@Sun.COM phyint_group_delete(pg); 4488485SPeter.Memishian@Sun.COM continue; 4498485SPeter.Memishian@Sun.COM } 4508485SPeter.Memishian@Sun.COM /* 4518485SPeter.Memishian@Sun.COM * Refresh the group's state. This is necessary since the 4528485SPeter.Memishian@Sun.COM * group's state is defined by the set of usable interfaces in 4538485SPeter.Memishian@Sun.COM * the group, and an interface is considered unusable if all 4548485SPeter.Memishian@Sun.COM * of its addresses are down. When an address goes down/up, 4558485SPeter.Memishian@Sun.COM * the RTM_DELADDR/RTM_NEWADDR brings us through here. 4568485SPeter.Memishian@Sun.COM */ 4578485SPeter.Memishian@Sun.COM phyint_group_refresh_state(pg); 4588485SPeter.Memishian@Sun.COM } 4598485SPeter.Memishian@Sun.COM 4600Sstevel@tonic-gate /* 4610Sstevel@tonic-gate * Select a test address for sending probes on each phyint instance 4620Sstevel@tonic-gate */ 4630Sstevel@tonic-gate select_test_ifs(); 4640Sstevel@tonic-gate 4650Sstevel@tonic-gate /* 4668485SPeter.Memishian@Sun.COM * Handle link up/down notifications. 4670Sstevel@tonic-gate */ 4680Sstevel@tonic-gate process_link_state_changes(); 4690Sstevel@tonic-gate } 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate /* 4722496Smeem * Check that a given test address is unique across all of the interfaces in a 4732496Smeem * group. (e.g., IPv6 link-locals may not be inherently unique, and binding 4742496Smeem * to such an (IFF_NOFAILOVER) address can produce unexpected results.) 4754770Smeem * Any issues will be reported by check_testconfig(). 4760Sstevel@tonic-gate */ 4770Sstevel@tonic-gate static void 4782496Smeem check_addr_unique(struct phyint_instance *ourpii, struct sockaddr_storage *ss) 4790Sstevel@tonic-gate { 4802496Smeem struct phyint *pi; 4812496Smeem struct phyint_group *pg; 4822496Smeem struct in6_addr addr; 4830Sstevel@tonic-gate struct phyint_instance *pii; 4840Sstevel@tonic-gate struct sockaddr_in *sin; 4852496Smeem 4862496Smeem if (ss->ss_family == AF_INET) { 4872496Smeem sin = (struct sockaddr_in *)ss; 4880Sstevel@tonic-gate IN6_INADDR_TO_V4MAPPED(&sin->sin_addr, &addr); 4890Sstevel@tonic-gate } else { 4902496Smeem assert(ss->ss_family == AF_INET6); 4912496Smeem addr = ((struct sockaddr_in6 *)ss)->sin6_addr; 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate /* 4952496Smeem * For anonymous groups, every interface is assumed to be on its own 4962496Smeem * link, so there is no chance of overlapping addresses. 4970Sstevel@tonic-gate */ 4982496Smeem pg = ourpii->pii_phyint->pi_group; 4992496Smeem if (pg == phyint_anongroup) 5002496Smeem return; 5012496Smeem 5022496Smeem /* 5032496Smeem * Walk the list of phyint instances in the group and check for test 5042496Smeem * addresses matching ours. Of course, we skip ourself. 5052496Smeem */ 5062496Smeem for (pi = pg->pg_phyint; pi != NULL; pi = pi->pi_pgnext) { 5072496Smeem pii = PHYINT_INSTANCE(pi, ss->ss_family); 5082496Smeem if (pii == NULL || pii == ourpii || 5092496Smeem pii->pii_probe_logint == NULL) 5100Sstevel@tonic-gate continue; 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate /* 5134770Smeem * If this test address is not unique, set the dupaddr bit. 5140Sstevel@tonic-gate */ 5154770Smeem if (IN6_ARE_ADDR_EQUAL(&addr, &pii->pii_probe_logint->li_addr)) 5164770Smeem pii->pii_probe_logint->li_dupaddr = 1; 5170Sstevel@tonic-gate } 5180Sstevel@tonic-gate } 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate /* 5210Sstevel@tonic-gate * Stop probing an interface. Called when an interface is offlined. 5220Sstevel@tonic-gate * The probe socket is closed on each interface instance, and the 5230Sstevel@tonic-gate * interface state set to PI_OFFLINE. 5240Sstevel@tonic-gate */ 5258485SPeter.Memishian@Sun.COM void 5260Sstevel@tonic-gate stop_probing(struct phyint *pi) 5270Sstevel@tonic-gate { 5280Sstevel@tonic-gate struct phyint_instance *pii; 5290Sstevel@tonic-gate 5300Sstevel@tonic-gate pii = pi->pi_v4; 5310Sstevel@tonic-gate if (pii != NULL) { 5320Sstevel@tonic-gate if (pii->pii_probe_sock != -1) 5330Sstevel@tonic-gate close_probe_socket(pii, _B_TRUE); 5340Sstevel@tonic-gate pii->pii_probe_logint = NULL; 5350Sstevel@tonic-gate } 5360Sstevel@tonic-gate 5370Sstevel@tonic-gate pii = pi->pi_v6; 5380Sstevel@tonic-gate if (pii != NULL) { 5390Sstevel@tonic-gate if (pii->pii_probe_sock != -1) 5400Sstevel@tonic-gate close_probe_socket(pii, _B_TRUE); 5410Sstevel@tonic-gate pii->pii_probe_logint = NULL; 5420Sstevel@tonic-gate } 5430Sstevel@tonic-gate 5440Sstevel@tonic-gate phyint_chstate(pi, PI_OFFLINE); 5450Sstevel@tonic-gate } 5460Sstevel@tonic-gate 5472074Smeem enum { BAD_TESTFLAGS, OK_TESTFLAGS, BEST_TESTFLAGS }; 5482074Smeem 5490Sstevel@tonic-gate /* 5502074Smeem * Rate the provided test flags. By definition, IFF_NOFAILOVER must be set. 5512074Smeem * IFF_UP must also be set so that the associated address can be used as a 5522074Smeem * source address. Further, we must be able to exchange packets with local 5532074Smeem * destinations, so IFF_NOXMIT and IFF_NOLOCAL must be clear. For historical 5542074Smeem * reasons, we have a proclivity for IFF_DEPRECATED IPv4 test addresses. 5552074Smeem */ 5562074Smeem static int 5572074Smeem rate_testflags(uint64_t flags) 5582074Smeem { 5592074Smeem if ((flags & (IFF_NOFAILOVER | IFF_UP)) != (IFF_NOFAILOVER | IFF_UP)) 5602074Smeem return (BAD_TESTFLAGS); 5612074Smeem 5622074Smeem if ((flags & (IFF_NOXMIT | IFF_NOLOCAL)) != 0) 5632074Smeem return (BAD_TESTFLAGS); 5642074Smeem 5652074Smeem if ((flags & (IFF_IPV6 | IFF_DEPRECATED)) == IFF_DEPRECATED) 5662074Smeem return (BEST_TESTFLAGS); 5672074Smeem 5682074Smeem if ((flags & (IFF_IPV6 | IFF_DEPRECATED)) == IFF_IPV6) 5692074Smeem return (BEST_TESTFLAGS); 5702074Smeem 5712074Smeem return (OK_TESTFLAGS); 5722074Smeem } 5732074Smeem 5742074Smeem /* 5752074Smeem * Attempt to select a test address for each phyint instance. 5762074Smeem * Call phyint_inst_sockinit() to complete the initializations. 5770Sstevel@tonic-gate */ 5780Sstevel@tonic-gate static void 5790Sstevel@tonic-gate select_test_ifs(void) 5800Sstevel@tonic-gate { 5810Sstevel@tonic-gate struct phyint *pi; 5820Sstevel@tonic-gate struct phyint_instance *pii; 5830Sstevel@tonic-gate struct phyint_instance *next_pii; 5842074Smeem struct logint *li; 5852074Smeem struct logint *probe_logint; 5862074Smeem boolean_t target_scan_reqd = _B_FALSE; 5872074Smeem int rating; 5880Sstevel@tonic-gate 5890Sstevel@tonic-gate if (debug & D_PHYINT) 5900Sstevel@tonic-gate logdebug("select_test_ifs\n"); 5910Sstevel@tonic-gate 5920Sstevel@tonic-gate /* 5930Sstevel@tonic-gate * For each phyint instance, do the test address selection 5940Sstevel@tonic-gate */ 5950Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; pii = next_pii) { 5960Sstevel@tonic-gate next_pii = pii->pii_next; 5972074Smeem probe_logint = NULL; 5982074Smeem 5990Sstevel@tonic-gate /* 6008485SPeter.Memishian@Sun.COM * An interface that is offline should not be probed. 6018485SPeter.Memishian@Sun.COM * IFF_OFFLINE interfaces should always be PI_OFFLINE 6020Sstevel@tonic-gate * unless some other entity has set the offline flag. 6030Sstevel@tonic-gate */ 6040Sstevel@tonic-gate if (pii->pii_phyint->pi_flags & IFF_OFFLINE) { 6050Sstevel@tonic-gate if (pii->pii_phyint->pi_state != PI_OFFLINE) { 6060Sstevel@tonic-gate logerr("shouldn't be probing offline" 6074770Smeem " interface %s (state is: %u)." 6084770Smeem " Stopping probes.\n", 6094770Smeem pii->pii_phyint->pi_name, 6104770Smeem pii->pii_phyint->pi_state); 6110Sstevel@tonic-gate stop_probing(pii->pii_phyint); 6120Sstevel@tonic-gate } 6130Sstevel@tonic-gate continue; 6148485SPeter.Memishian@Sun.COM } else { 6158485SPeter.Memishian@Sun.COM /* 6168485SPeter.Memishian@Sun.COM * If something cleared IFF_OFFLINE (e.g., by accident 6178485SPeter.Memishian@Sun.COM * because the SIOCGLIFFLAGS/SIOCSLIFFLAGS sequence is 6188485SPeter.Memishian@Sun.COM * inherently racy), the phyint may still be offline. 6198485SPeter.Memishian@Sun.COM * Just ignore it. 6208485SPeter.Memishian@Sun.COM */ 6218485SPeter.Memishian@Sun.COM if (pii->pii_phyint->pi_state == PI_OFFLINE) 6228485SPeter.Memishian@Sun.COM continue; 6230Sstevel@tonic-gate } 6240Sstevel@tonic-gate 6252074Smeem li = pii->pii_probe_logint; 6262074Smeem if (li != NULL) { 6270Sstevel@tonic-gate /* 6282074Smeem * We've already got a test address; only proceed 6292074Smeem * if it's suboptimal. 6300Sstevel@tonic-gate */ 6312074Smeem if (rate_testflags(li->li_flags) == BEST_TESTFLAGS) 6322074Smeem continue; 6330Sstevel@tonic-gate } 6340Sstevel@tonic-gate 6350Sstevel@tonic-gate /* 6360Sstevel@tonic-gate * Walk the logints of this phyint instance, and select 6370Sstevel@tonic-gate * the best available test address 6380Sstevel@tonic-gate */ 6390Sstevel@tonic-gate for (li = pii->pii_logint; li != NULL; li = li->li_next) { 6400Sstevel@tonic-gate /* 6412496Smeem * Skip 0.0.0.0 addresses, as those are never 6422496Smeem * actually usable. 6432496Smeem */ 6442496Smeem if (pii->pii_af == AF_INET && 6452496Smeem IN6_IS_ADDR_V4MAPPED_ANY(&li->li_addr)) 6462496Smeem continue; 6472496Smeem 6482496Smeem /* 6490Sstevel@tonic-gate * Skip any IPv6 logints that are not link-local, 6500Sstevel@tonic-gate * since we should always have a link-local address 6510Sstevel@tonic-gate * anyway and in6_data() expects link-local replies. 6520Sstevel@tonic-gate */ 6530Sstevel@tonic-gate if (pii->pii_af == AF_INET6 && 6540Sstevel@tonic-gate !IN6_IS_ADDR_LINKLOCAL(&li->li_addr)) 6550Sstevel@tonic-gate continue; 6560Sstevel@tonic-gate 6572074Smeem /* 6582074Smeem * Rate the testflags. If we've found an optimal 6592074Smeem * match, then break out; otherwise, record the most 6602074Smeem * recent OK one. 6612074Smeem */ 6622074Smeem rating = rate_testflags(li->li_flags); 6632074Smeem if (rating == BAD_TESTFLAGS) 6642074Smeem continue; 6652074Smeem 6662074Smeem probe_logint = li; 6672074Smeem if (rating == BEST_TESTFLAGS) 6682074Smeem break; 6690Sstevel@tonic-gate } 6700Sstevel@tonic-gate 6710Sstevel@tonic-gate /* 6722074Smeem * If the probe logint has changed, ditch the old one. 6730Sstevel@tonic-gate */ 6742074Smeem if (pii->pii_probe_logint != NULL && 6752074Smeem pii->pii_probe_logint != probe_logint) { 6760Sstevel@tonic-gate if (pii->pii_probe_sock != -1) 6770Sstevel@tonic-gate close_probe_socket(pii, _B_TRUE); 6780Sstevel@tonic-gate pii->pii_probe_logint = NULL; 6790Sstevel@tonic-gate } 6800Sstevel@tonic-gate 6812074Smeem if (probe_logint == NULL) { 6820Sstevel@tonic-gate /* 6834770Smeem * We don't have a test address; zero out the probe 6844770Smeem * stats array since it is no longer relevant. 6854770Smeem * Optimize by checking if it is already zeroed out. 6860Sstevel@tonic-gate */ 6870Sstevel@tonic-gate int pr_ndx; 6880Sstevel@tonic-gate 6890Sstevel@tonic-gate pr_ndx = PROBE_INDEX_PREV(pii->pii_probe_next); 6900Sstevel@tonic-gate if (pii->pii_probes[pr_ndx].pr_status != PR_UNUSED) { 6910Sstevel@tonic-gate clear_pii_probe_stats(pii); 6920Sstevel@tonic-gate reset_crtt_all(pii->pii_phyint); 6930Sstevel@tonic-gate } 6940Sstevel@tonic-gate continue; 6952074Smeem } else if (probe_logint == pii->pii_probe_logint) { 6960Sstevel@tonic-gate /* 6970Sstevel@tonic-gate * If we didn't find any new test addr, go to the 6980Sstevel@tonic-gate * next phyint. 6990Sstevel@tonic-gate */ 7000Sstevel@tonic-gate continue; 7010Sstevel@tonic-gate } 7020Sstevel@tonic-gate 7030Sstevel@tonic-gate /* 7040Sstevel@tonic-gate * The phyint is either being assigned a new testaddr 7050Sstevel@tonic-gate * or is being assigned a testaddr for the 1st time. 7060Sstevel@tonic-gate * Need to initialize the phyint socket 7070Sstevel@tonic-gate */ 7082074Smeem pii->pii_probe_logint = probe_logint; 7090Sstevel@tonic-gate if (!phyint_inst_sockinit(pii)) { 7100Sstevel@tonic-gate if (debug & D_PHYINT) { 7110Sstevel@tonic-gate logdebug("select_test_ifs: " 7120Sstevel@tonic-gate "phyint_sockinit failed\n"); 7130Sstevel@tonic-gate } 7140Sstevel@tonic-gate phyint_inst_delete(pii); 7150Sstevel@tonic-gate continue; 7160Sstevel@tonic-gate } 7170Sstevel@tonic-gate 7180Sstevel@tonic-gate /* 7190Sstevel@tonic-gate * This phyint instance is now enabled for probes; this 7200Sstevel@tonic-gate * impacts our state machine in two ways: 7210Sstevel@tonic-gate * 7220Sstevel@tonic-gate * 1. If we're probe *capable* as well (i.e., we have 7230Sstevel@tonic-gate * probe targets) and the interface is in PI_NOTARGETS, 7240Sstevel@tonic-gate * then transition to PI_RUNNING. 7250Sstevel@tonic-gate * 7260Sstevel@tonic-gate * 2. If we're not probe capable, and the other phyint 7270Sstevel@tonic-gate * instance is also not probe capable, and we were in 7280Sstevel@tonic-gate * PI_RUNNING, then transition to PI_NOTARGETS. 7290Sstevel@tonic-gate * 7300Sstevel@tonic-gate * Also see the state diagram in mpd_probe.c. 7310Sstevel@tonic-gate */ 7320Sstevel@tonic-gate if (PROBE_CAPABLE(pii)) { 7330Sstevel@tonic-gate if (pii->pii_phyint->pi_state == PI_NOTARGETS) 7340Sstevel@tonic-gate phyint_chstate(pii->pii_phyint, PI_RUNNING); 7350Sstevel@tonic-gate } else if (!PROBE_CAPABLE(phyint_inst_other(pii))) { 7360Sstevel@tonic-gate if (pii->pii_phyint->pi_state == PI_RUNNING) 7370Sstevel@tonic-gate phyint_chstate(pii->pii_phyint, PI_NOTARGETS); 7380Sstevel@tonic-gate } 7390Sstevel@tonic-gate 7400Sstevel@tonic-gate /* 7410Sstevel@tonic-gate * If no targets are currently known for this phyint 7420Sstevel@tonic-gate * we need to call init_router_targets. Since 7430Sstevel@tonic-gate * init_router_targets() initializes the list of targets 7440Sstevel@tonic-gate * for all phyints it is done below the loop. 7450Sstevel@tonic-gate */ 7460Sstevel@tonic-gate if (pii->pii_targets == NULL) 7470Sstevel@tonic-gate target_scan_reqd = _B_TRUE; 7480Sstevel@tonic-gate 7490Sstevel@tonic-gate /* 7500Sstevel@tonic-gate * Start the probe timer for this instance. 7510Sstevel@tonic-gate */ 7522496Smeem if (!pii->pii_basetime_inited && PROBE_ENABLED(pii)) { 7530Sstevel@tonic-gate start_timer(pii); 7540Sstevel@tonic-gate pii->pii_basetime_inited = 1; 7550Sstevel@tonic-gate } 7560Sstevel@tonic-gate } 7570Sstevel@tonic-gate 7580Sstevel@tonic-gate /* 7598485SPeter.Memishian@Sun.COM * Scan the interface list for any interfaces that are PI_FAILED or 7608485SPeter.Memishian@Sun.COM * PI_NOTARGETS but no longer enabled to send probes, and call 7618485SPeter.Memishian@Sun.COM * phyint_check_for_repair() to see if the link state indicates that 7628485SPeter.Memishian@Sun.COM * the interface should be repaired. Also see the state diagram in 7630Sstevel@tonic-gate * mpd_probe.c. 7640Sstevel@tonic-gate */ 7650Sstevel@tonic-gate for (pi = phyints; pi != NULL; pi = pi->pi_next) { 7668485SPeter.Memishian@Sun.COM if ((!PROBE_ENABLED(pi->pi_v4) && !PROBE_ENABLED(pi->pi_v6)) && 7678485SPeter.Memishian@Sun.COM (pi->pi_state == PI_FAILED || 7688485SPeter.Memishian@Sun.COM pi->pi_state == PI_NOTARGETS)) { 7690Sstevel@tonic-gate phyint_check_for_repair(pi); 7700Sstevel@tonic-gate } 7710Sstevel@tonic-gate } 7720Sstevel@tonic-gate 7734770Smeem check_testconfig(); 7744770Smeem 7750Sstevel@tonic-gate /* 7760Sstevel@tonic-gate * Try to populate the target list. init_router_targets populates 7770Sstevel@tonic-gate * the target list from the routing table. If our target list is 7780Sstevel@tonic-gate * still empty, init_host_targets adds host targets based on the 7790Sstevel@tonic-gate * host target list of other phyints in the group. 7800Sstevel@tonic-gate */ 7810Sstevel@tonic-gate if (target_scan_reqd) { 7820Sstevel@tonic-gate init_router_targets(); 7830Sstevel@tonic-gate init_host_targets(); 7840Sstevel@tonic-gate } 7850Sstevel@tonic-gate } 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate /* 7886578Smeem * Check test address configuration, and log notices/errors if appropriate. 7896578Smeem * Note that this function only logs pre-existing conditions (e.g., that 7906578Smeem * probe-based failure detection is disabled). 7914770Smeem */ 7924770Smeem static void 7934770Smeem check_testconfig(void) 7944770Smeem { 7954770Smeem struct phyint *pi; 7964770Smeem struct logint *li; 7974770Smeem char abuf[INET6_ADDRSTRLEN]; 7986578Smeem int pri; 7994770Smeem 8004770Smeem for (pi = phyints; pi != NULL; pi = pi->pi_next) { 8014770Smeem if (pi->pi_flags & IFF_OFFLINE) 8024770Smeem continue; 8034770Smeem 8044770Smeem if (PROBE_ENABLED(pi->pi_v4) || PROBE_ENABLED(pi->pi_v6)) { 8054770Smeem if (pi->pi_taddrmsg_printed || 8064770Smeem pi->pi_duptaddrmsg_printed) { 8076578Smeem if (pi->pi_duptaddrmsg_printed) 8086578Smeem pri = LOG_ERR; 8096578Smeem else 8106578Smeem pri = LOG_INFO; 8116578Smeem logmsg(pri, "Test address now configured on " 8124770Smeem "interface %s; enabling probe-based " 8134770Smeem "failure detection on it\n", pi->pi_name); 8144770Smeem pi->pi_taddrmsg_printed = 0; 8154770Smeem pi->pi_duptaddrmsg_printed = 0; 8164770Smeem } 8174770Smeem continue; 8184770Smeem } 8194770Smeem 8204770Smeem li = NULL; 8214770Smeem if (pi->pi_v4 != NULL && pi->pi_v4->pii_probe_logint != NULL && 8224770Smeem pi->pi_v4->pii_probe_logint->li_dupaddr) 8234770Smeem li = pi->pi_v4->pii_probe_logint; 8244770Smeem 8254770Smeem if (pi->pi_v6 != NULL && pi->pi_v6->pii_probe_logint != NULL && 8264770Smeem pi->pi_v6->pii_probe_logint->li_dupaddr) 8274770Smeem li = pi->pi_v6->pii_probe_logint; 8284770Smeem 8298485SPeter.Memishian@Sun.COM if (li != NULL && li->li_dupaddr) { 8308485SPeter.Memishian@Sun.COM if (pi->pi_duptaddrmsg_printed) 8318485SPeter.Memishian@Sun.COM continue; 8328485SPeter.Memishian@Sun.COM logerr("Test address %s is not unique in group; " 8338485SPeter.Memishian@Sun.COM "disabling probe-based failure detection on %s\n", 8348485SPeter.Memishian@Sun.COM pr_addr(li->li_phyint_inst->pii_af, 8358485SPeter.Memishian@Sun.COM li->li_addr, abuf, sizeof (abuf)), pi->pi_name); 8368485SPeter.Memishian@Sun.COM pi->pi_duptaddrmsg_printed = 1; 8374770Smeem continue; 8384770Smeem } 8394770Smeem 8404770Smeem if (getcurrentsec() < pi->pi_taddrthresh) 8414770Smeem continue; 8424770Smeem 8434770Smeem if (!pi->pi_taddrmsg_printed) { 8446578Smeem logtrace("No test address configured on interface %s; " 8454770Smeem "disabling probe-based failure detection on it\n", 8464770Smeem pi->pi_name); 8474770Smeem pi->pi_taddrmsg_printed = 1; 8484770Smeem } 8494770Smeem } 8504770Smeem } 8514770Smeem 8524770Smeem /* 8530Sstevel@tonic-gate * Check phyint group configuration, to detect any inconsistencies, 8540Sstevel@tonic-gate * and log an error message. This is called from runtimeouts every 8550Sstevel@tonic-gate * 20 secs. But the error message is displayed once. If the 8560Sstevel@tonic-gate * consistency is resolved by the admin, a recovery message is displayed 8570Sstevel@tonic-gate * once. 8580Sstevel@tonic-gate */ 8590Sstevel@tonic-gate static void 8600Sstevel@tonic-gate check_config(void) 8610Sstevel@tonic-gate { 8620Sstevel@tonic-gate struct phyint_group *pg; 8630Sstevel@tonic-gate struct phyint *pi; 8640Sstevel@tonic-gate boolean_t v4_in_group; 8650Sstevel@tonic-gate boolean_t v6_in_group; 8660Sstevel@tonic-gate 8670Sstevel@tonic-gate /* 8688485SPeter.Memishian@Sun.COM * All phyints of a group must be homogeneous to ensure that they can 8698485SPeter.Memishian@Sun.COM * take over for one another. If any phyint in a group has IPv4 8708485SPeter.Memishian@Sun.COM * plumbed, check that all phyints have IPv4 plumbed. Do a similar 8718485SPeter.Memishian@Sun.COM * check for IPv6. 8720Sstevel@tonic-gate */ 8730Sstevel@tonic-gate for (pg = phyint_groups; pg != NULL; pg = pg->pg_next) { 8740Sstevel@tonic-gate if (pg == phyint_anongroup) 8750Sstevel@tonic-gate continue; 8760Sstevel@tonic-gate 8770Sstevel@tonic-gate v4_in_group = _B_FALSE; 8780Sstevel@tonic-gate v6_in_group = _B_FALSE; 8790Sstevel@tonic-gate /* 8800Sstevel@tonic-gate * 1st pass. Determine if at least 1 phyint in the group 8810Sstevel@tonic-gate * has IPv4 plumbed and if so set v4_in_group to true. 8820Sstevel@tonic-gate * Repeat similarly for IPv6. 8830Sstevel@tonic-gate */ 8840Sstevel@tonic-gate for (pi = pg->pg_phyint; pi != NULL; pi = pi->pi_pgnext) { 8850Sstevel@tonic-gate if (pi->pi_v4 != NULL) 8860Sstevel@tonic-gate v4_in_group = _B_TRUE; 8870Sstevel@tonic-gate if (pi->pi_v6 != NULL) 8880Sstevel@tonic-gate v6_in_group = _B_TRUE; 8890Sstevel@tonic-gate } 8900Sstevel@tonic-gate 8910Sstevel@tonic-gate /* 8920Sstevel@tonic-gate * 2nd pass. If v4_in_group is true, check that phyint 8930Sstevel@tonic-gate * has IPv4 plumbed. Repeat similarly for IPv6. Print 8940Sstevel@tonic-gate * out a message the 1st time only. 8950Sstevel@tonic-gate */ 8960Sstevel@tonic-gate for (pi = pg->pg_phyint; pi != NULL; pi = pi->pi_pgnext) { 8970Sstevel@tonic-gate if (pi->pi_flags & IFF_OFFLINE) 8980Sstevel@tonic-gate continue; 8990Sstevel@tonic-gate 9000Sstevel@tonic-gate if (v4_in_group == _B_TRUE && pi->pi_v4 == NULL) { 9010Sstevel@tonic-gate if (!pi->pi_cfgmsg_printed) { 9028485SPeter.Memishian@Sun.COM logerr("IP interface %s in group %s is" 9038485SPeter.Memishian@Sun.COM " not plumbed for IPv4, affecting" 9048485SPeter.Memishian@Sun.COM " IPv4 connectivity\n", 9050Sstevel@tonic-gate pi->pi_name, 9060Sstevel@tonic-gate pi->pi_group->pg_name); 9070Sstevel@tonic-gate pi->pi_cfgmsg_printed = 1; 9080Sstevel@tonic-gate } 9090Sstevel@tonic-gate } else if (v6_in_group == _B_TRUE && 9100Sstevel@tonic-gate pi->pi_v6 == NULL) { 9110Sstevel@tonic-gate if (!pi->pi_cfgmsg_printed) { 9128485SPeter.Memishian@Sun.COM logerr("IP interface %s in group %s is" 9138485SPeter.Memishian@Sun.COM " not plumbed for IPv6, affecting" 9148485SPeter.Memishian@Sun.COM " IPv6 connectivity\n", 9150Sstevel@tonic-gate pi->pi_name, 9160Sstevel@tonic-gate pi->pi_group->pg_name); 9170Sstevel@tonic-gate pi->pi_cfgmsg_printed = 1; 9180Sstevel@tonic-gate } 9190Sstevel@tonic-gate } else { 9200Sstevel@tonic-gate /* 9210Sstevel@tonic-gate * The phyint matches the group configuration, 9220Sstevel@tonic-gate * if we have reached this point. If it was 9230Sstevel@tonic-gate * improperly configured earlier, log an 9240Sstevel@tonic-gate * error recovery message 9250Sstevel@tonic-gate */ 9260Sstevel@tonic-gate if (pi->pi_cfgmsg_printed) { 9278485SPeter.Memishian@Sun.COM logerr("IP interface %s is now" 9288485SPeter.Memishian@Sun.COM " consistent with group %s " 9298485SPeter.Memishian@Sun.COM " and connectivity is restored\n", 9308485SPeter.Memishian@Sun.COM pi->pi_name, pi->pi_group->pg_name); 9310Sstevel@tonic-gate pi->pi_cfgmsg_printed = 0; 9320Sstevel@tonic-gate } 9330Sstevel@tonic-gate } 9340Sstevel@tonic-gate 9350Sstevel@tonic-gate } 9360Sstevel@tonic-gate } 9370Sstevel@tonic-gate } 9380Sstevel@tonic-gate 9390Sstevel@tonic-gate /* 9400Sstevel@tonic-gate * Timer mechanism using relative time (in milliseconds) from the 9410Sstevel@tonic-gate * previous timer event. Timers exceeding TIMER_INFINITY milliseconds 9420Sstevel@tonic-gate * will fire after TIMER_INFINITY milliseconds. 9430Sstevel@tonic-gate * Unsigned arithmetic note: We assume a 32-bit circular sequence space for 9440Sstevel@tonic-gate * time values. Hence 2 consecutive timer events cannot be spaced farther 9450Sstevel@tonic-gate * than 0x7fffffff. We call this TIMER_INFINITY, and it is the maximum value 9460Sstevel@tonic-gate * that can be passed for the delay parameter of timer_schedule() 9470Sstevel@tonic-gate */ 9480Sstevel@tonic-gate static uint_t timer_next; /* Currently scheduled timeout */ 9490Sstevel@tonic-gate static boolean_t timer_active = _B_FALSE; /* SIGALRM has not yet occurred */ 9500Sstevel@tonic-gate 9510Sstevel@tonic-gate static void 9520Sstevel@tonic-gate timer_init(void) 9530Sstevel@tonic-gate { 9540Sstevel@tonic-gate timer_next = getcurrenttime() + TIMER_INFINITY; 9550Sstevel@tonic-gate /* 9560Sstevel@tonic-gate * The call to run_timeouts() will get the timer started 9570Sstevel@tonic-gate * Since there are no phyints at this point, the timer will 9580Sstevel@tonic-gate * be set for IF_SCAN_INTERVAL ms. 9590Sstevel@tonic-gate */ 9600Sstevel@tonic-gate run_timeouts(); 9610Sstevel@tonic-gate } 9620Sstevel@tonic-gate 9630Sstevel@tonic-gate /* 9640Sstevel@tonic-gate * Make sure the next SIGALRM occurs delay milliseconds from the current 9650Sstevel@tonic-gate * time if not earlier. We are interested only in time differences. 9660Sstevel@tonic-gate */ 9670Sstevel@tonic-gate void 9680Sstevel@tonic-gate timer_schedule(uint_t delay) 9690Sstevel@tonic-gate { 9700Sstevel@tonic-gate uint_t now; 9710Sstevel@tonic-gate struct itimerval itimerval; 9720Sstevel@tonic-gate 9730Sstevel@tonic-gate if (debug & D_TIMER) 9740Sstevel@tonic-gate logdebug("timer_schedule(%u)\n", delay); 9750Sstevel@tonic-gate 9760Sstevel@tonic-gate assert(delay <= TIMER_INFINITY); 9770Sstevel@tonic-gate 9780Sstevel@tonic-gate now = getcurrenttime(); 9790Sstevel@tonic-gate if (delay == 0) { 9800Sstevel@tonic-gate /* Minimum allowed delay */ 9810Sstevel@tonic-gate delay = 1; 9820Sstevel@tonic-gate } 9830Sstevel@tonic-gate /* Will this timer occur before the currently scheduled SIGALRM? */ 9840Sstevel@tonic-gate if (timer_active && TIME_GE(now + delay, timer_next)) { 9850Sstevel@tonic-gate if (debug & D_TIMER) { 9860Sstevel@tonic-gate logdebug("timer_schedule(%u) - no action: " 9870Sstevel@tonic-gate "now %u next %u\n", delay, now, timer_next); 9880Sstevel@tonic-gate } 9890Sstevel@tonic-gate return; 9900Sstevel@tonic-gate } 9910Sstevel@tonic-gate timer_next = now + delay; 9920Sstevel@tonic-gate 9930Sstevel@tonic-gate itimerval.it_value.tv_sec = delay / 1000; 9940Sstevel@tonic-gate itimerval.it_value.tv_usec = (delay % 1000) * 1000; 9950Sstevel@tonic-gate itimerval.it_interval.tv_sec = 0; 9960Sstevel@tonic-gate itimerval.it_interval.tv_usec = 0; 9970Sstevel@tonic-gate if (debug & D_TIMER) { 9980Sstevel@tonic-gate logdebug("timer_schedule(%u): sec %ld usec %ld\n", 9990Sstevel@tonic-gate delay, itimerval.it_value.tv_sec, 10000Sstevel@tonic-gate itimerval.it_value.tv_usec); 10010Sstevel@tonic-gate } 10020Sstevel@tonic-gate timer_active = _B_TRUE; 10030Sstevel@tonic-gate if (setitimer(ITIMER_REAL, &itimerval, NULL) < 0) { 10040Sstevel@tonic-gate logperror("timer_schedule: setitimer"); 10050Sstevel@tonic-gate exit(2); 10060Sstevel@tonic-gate } 10070Sstevel@tonic-gate } 10080Sstevel@tonic-gate 10090Sstevel@tonic-gate /* 10100Sstevel@tonic-gate * Timer has fired. Determine when the next timer event will occur by asking 10110Sstevel@tonic-gate * all the timer routines. Should not be called from a timer routine. 10120Sstevel@tonic-gate */ 10130Sstevel@tonic-gate static void 10140Sstevel@tonic-gate run_timeouts(void) 10150Sstevel@tonic-gate { 10160Sstevel@tonic-gate uint_t next; 10170Sstevel@tonic-gate uint_t next_event_time; 10180Sstevel@tonic-gate struct phyint_instance *pii; 10190Sstevel@tonic-gate struct phyint_instance *next_pii; 10200Sstevel@tonic-gate static boolean_t timeout_running; 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate /* assert that recursive timeouts don't happen. */ 10230Sstevel@tonic-gate assert(!timeout_running); 10240Sstevel@tonic-gate 10250Sstevel@tonic-gate timeout_running = _B_TRUE; 10260Sstevel@tonic-gate 10270Sstevel@tonic-gate if (debug & D_TIMER) 10280Sstevel@tonic-gate logdebug("run_timeouts()\n"); 10290Sstevel@tonic-gate 10304770Smeem if ((getcurrenttime() - last_initifs_time) > IF_SCAN_INTERVAL) { 10314770Smeem initifs(); 10324770Smeem check_config(); 10334770Smeem } 10344770Smeem 10350Sstevel@tonic-gate next = TIMER_INFINITY; 10360Sstevel@tonic-gate 10370Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; pii = next_pii) { 10380Sstevel@tonic-gate next_pii = pii->pii_next; 10390Sstevel@tonic-gate next_event_time = phyint_inst_timer(pii); 10400Sstevel@tonic-gate if (next_event_time != TIMER_INFINITY && next_event_time < next) 10410Sstevel@tonic-gate next = next_event_time; 10420Sstevel@tonic-gate 10430Sstevel@tonic-gate if (debug & D_TIMER) { 10440Sstevel@tonic-gate logdebug("run_timeouts(%s %s): next scheduled for" 10450Sstevel@tonic-gate " this phyint inst %u, next scheduled global" 10460Sstevel@tonic-gate " %u ms\n", 10470Sstevel@tonic-gate AF_STR(pii->pii_af), pii->pii_phyint->pi_name, 10480Sstevel@tonic-gate next_event_time, next); 10490Sstevel@tonic-gate } 10500Sstevel@tonic-gate } 10510Sstevel@tonic-gate 10520Sstevel@tonic-gate /* 10530Sstevel@tonic-gate * Make sure initifs() is called at least once every 10540Sstevel@tonic-gate * IF_SCAN_INTERVAL, to make sure that we are in sync 10550Sstevel@tonic-gate * with the kernel, in case we have missed any routing 10560Sstevel@tonic-gate * socket messages. 10570Sstevel@tonic-gate */ 10580Sstevel@tonic-gate if (next > IF_SCAN_INTERVAL) 10590Sstevel@tonic-gate next = IF_SCAN_INTERVAL; 10600Sstevel@tonic-gate 10610Sstevel@tonic-gate if (debug & D_TIMER) 10620Sstevel@tonic-gate logdebug("run_timeouts: %u ms\n", next); 10630Sstevel@tonic-gate 10640Sstevel@tonic-gate timer_schedule(next); 10650Sstevel@tonic-gate timeout_running = _B_FALSE; 10660Sstevel@tonic-gate } 10670Sstevel@tonic-gate 10680Sstevel@tonic-gate static int eventpipe_read = -1; /* Used for synchronous signal delivery */ 10690Sstevel@tonic-gate static int eventpipe_write = -1; 10708485SPeter.Memishian@Sun.COM boolean_t cleanup_started = _B_FALSE; /* true if we're going away */ 10718485SPeter.Memishian@Sun.COM 10720Sstevel@tonic-gate /* 10730Sstevel@tonic-gate * Ensure that signals are processed synchronously with the rest of 10740Sstevel@tonic-gate * the code by just writing a one character signal number on the pipe. 10750Sstevel@tonic-gate * The poll loop will pick this up and process the signal event. 10760Sstevel@tonic-gate */ 10770Sstevel@tonic-gate static void 10780Sstevel@tonic-gate sig_handler(int signo) 10790Sstevel@tonic-gate { 10800Sstevel@tonic-gate uchar_t buf = (uchar_t)signo; 10810Sstevel@tonic-gate 10820Sstevel@tonic-gate /* 10830Sstevel@tonic-gate * Don't write to pipe if cleanup has already begun. cleanup() 10840Sstevel@tonic-gate * might have closed the pipe already 10850Sstevel@tonic-gate */ 10860Sstevel@tonic-gate if (cleanup_started) 10870Sstevel@tonic-gate return; 10880Sstevel@tonic-gate 10890Sstevel@tonic-gate if (eventpipe_write == -1) { 10900Sstevel@tonic-gate logerr("sig_handler: no pipe found\n"); 10910Sstevel@tonic-gate return; 10920Sstevel@tonic-gate } 10930Sstevel@tonic-gate if (write(eventpipe_write, &buf, sizeof (buf)) < 0) 10940Sstevel@tonic-gate logperror("sig_handler: write"); 10950Sstevel@tonic-gate } 10960Sstevel@tonic-gate 10970Sstevel@tonic-gate extern struct probes_missed probes_missed; 10980Sstevel@tonic-gate 10990Sstevel@tonic-gate /* 11000Sstevel@tonic-gate * Pick up a signal "byte" from the pipe and process it. 11010Sstevel@tonic-gate */ 11020Sstevel@tonic-gate static void 11030Sstevel@tonic-gate in_signal(int fd) 11040Sstevel@tonic-gate { 11050Sstevel@tonic-gate uchar_t buf; 11060Sstevel@tonic-gate uint64_t sent, acked, lost, unacked, unknown; 11070Sstevel@tonic-gate struct phyint_instance *pii; 11080Sstevel@tonic-gate int pr_ndx; 11090Sstevel@tonic-gate 11100Sstevel@tonic-gate switch (read(fd, &buf, sizeof (buf))) { 11110Sstevel@tonic-gate case -1: 11120Sstevel@tonic-gate logperror("in_signal: read"); 11130Sstevel@tonic-gate exit(1); 11140Sstevel@tonic-gate /* NOTREACHED */ 11150Sstevel@tonic-gate case 1: 11160Sstevel@tonic-gate break; 11170Sstevel@tonic-gate case 0: 11180Sstevel@tonic-gate logerr("in_signal: read end of file\n"); 11190Sstevel@tonic-gate exit(1); 11200Sstevel@tonic-gate /* NOTREACHED */ 11210Sstevel@tonic-gate default: 11220Sstevel@tonic-gate logerr("in_signal: read > 1\n"); 11230Sstevel@tonic-gate exit(1); 11240Sstevel@tonic-gate } 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate if (debug & D_TIMER) 11270Sstevel@tonic-gate logdebug("in_signal() got %d\n", buf); 11280Sstevel@tonic-gate 11290Sstevel@tonic-gate switch (buf) { 11300Sstevel@tonic-gate case SIGALRM: 11310Sstevel@tonic-gate if (debug & D_TIMER) { 11320Sstevel@tonic-gate uint_t now = getcurrenttime(); 11330Sstevel@tonic-gate 11340Sstevel@tonic-gate logdebug("in_signal(SIGALRM) delta %u\n", 11350Sstevel@tonic-gate now - timer_next); 11360Sstevel@tonic-gate } 11370Sstevel@tonic-gate timer_active = _B_FALSE; 11380Sstevel@tonic-gate run_timeouts(); 11390Sstevel@tonic-gate break; 11400Sstevel@tonic-gate case SIGUSR1: 11410Sstevel@tonic-gate logdebug("Printing configuration:\n"); 11420Sstevel@tonic-gate /* Print out the internal tables */ 11430Sstevel@tonic-gate phyint_inst_print_all(); 11440Sstevel@tonic-gate 11450Sstevel@tonic-gate /* 11460Sstevel@tonic-gate * Print out the accumulated statistics about missed 11470Sstevel@tonic-gate * probes (happens due to scheduling delay). 11480Sstevel@tonic-gate */ 11490Sstevel@tonic-gate logerr("Missed sending total of %d probes spread over" 11500Sstevel@tonic-gate " %d occurrences\n", probes_missed.pm_nprobes, 11510Sstevel@tonic-gate probes_missed.pm_ntimes); 11520Sstevel@tonic-gate 11530Sstevel@tonic-gate /* 11540Sstevel@tonic-gate * Print out the accumulated statistics about probes 11550Sstevel@tonic-gate * that were sent. 11560Sstevel@tonic-gate */ 11570Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; 11580Sstevel@tonic-gate pii = pii->pii_next) { 11590Sstevel@tonic-gate unacked = 0; 11600Sstevel@tonic-gate acked = pii->pii_cum_stats.acked; 11610Sstevel@tonic-gate lost = pii->pii_cum_stats.lost; 11620Sstevel@tonic-gate sent = pii->pii_cum_stats.sent; 11630Sstevel@tonic-gate unknown = pii->pii_cum_stats.unknown; 11640Sstevel@tonic-gate for (pr_ndx = 0; pr_ndx < PROBE_STATS_COUNT; pr_ndx++) { 11650Sstevel@tonic-gate switch (pii->pii_probes[pr_ndx].pr_status) { 11660Sstevel@tonic-gate case PR_ACKED: 11670Sstevel@tonic-gate acked++; 11680Sstevel@tonic-gate break; 11690Sstevel@tonic-gate case PR_LOST: 11700Sstevel@tonic-gate lost++; 11710Sstevel@tonic-gate break; 11720Sstevel@tonic-gate case PR_UNACKED: 11730Sstevel@tonic-gate unacked++; 11740Sstevel@tonic-gate break; 11750Sstevel@tonic-gate } 11760Sstevel@tonic-gate } 11770Sstevel@tonic-gate logerr("\nProbe stats on (%s %s)\n" 11780Sstevel@tonic-gate "Number of probes sent %lld\n" 11790Sstevel@tonic-gate "Number of probe acks received %lld\n" 11800Sstevel@tonic-gate "Number of probes/acks lost %lld\n" 11818485SPeter.Memishian@Sun.COM "Number of valid unacknowledged probes %lld\n" 11820Sstevel@tonic-gate "Number of ambiguous probe acks received %lld\n", 11830Sstevel@tonic-gate AF_STR(pii->pii_af), pii->pii_name, 11840Sstevel@tonic-gate sent, acked, lost, unacked, unknown); 11850Sstevel@tonic-gate } 11860Sstevel@tonic-gate break; 11870Sstevel@tonic-gate case SIGHUP: 11880Sstevel@tonic-gate logerr("SIGHUP: restart and reread config file\n"); 11890Sstevel@tonic-gate cleanup(); 11900Sstevel@tonic-gate (void) execv(argv0[0], argv0); 11910Sstevel@tonic-gate _exit(0177); 11920Sstevel@tonic-gate /* NOTREACHED */ 11930Sstevel@tonic-gate case SIGINT: 11940Sstevel@tonic-gate case SIGTERM: 11950Sstevel@tonic-gate case SIGQUIT: 11960Sstevel@tonic-gate cleanup(); 11970Sstevel@tonic-gate exit(0); 11980Sstevel@tonic-gate /* NOTREACHED */ 11990Sstevel@tonic-gate default: 12000Sstevel@tonic-gate logerr("in_signal: unknown signal: %d\n", buf); 12010Sstevel@tonic-gate } 12020Sstevel@tonic-gate } 12030Sstevel@tonic-gate 12040Sstevel@tonic-gate static void 12050Sstevel@tonic-gate cleanup(void) 12060Sstevel@tonic-gate { 12070Sstevel@tonic-gate struct phyint_instance *pii; 12080Sstevel@tonic-gate struct phyint_instance *next_pii; 12090Sstevel@tonic-gate 12100Sstevel@tonic-gate /* 12110Sstevel@tonic-gate * Make sure that we don't write to eventpipe in 12120Sstevel@tonic-gate * sig_handler() if any signal notably SIGALRM, 12130Sstevel@tonic-gate * occurs after we close the eventpipe descriptor below 12140Sstevel@tonic-gate */ 12150Sstevel@tonic-gate cleanup_started = _B_TRUE; 12160Sstevel@tonic-gate 12170Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; pii = next_pii) { 12180Sstevel@tonic-gate next_pii = pii->pii_next; 12190Sstevel@tonic-gate phyint_inst_delete(pii); 12200Sstevel@tonic-gate } 12210Sstevel@tonic-gate 12220Sstevel@tonic-gate (void) close(ifsock_v4); 12230Sstevel@tonic-gate (void) close(ifsock_v6); 12240Sstevel@tonic-gate (void) close(rtsock_v4); 12250Sstevel@tonic-gate (void) close(rtsock_v6); 12260Sstevel@tonic-gate (void) close(lsock_v4); 12270Sstevel@tonic-gate (void) close(lsock_v6); 12280Sstevel@tonic-gate (void) close(0); 12290Sstevel@tonic-gate (void) close(1); 12300Sstevel@tonic-gate (void) close(2); 12310Sstevel@tonic-gate (void) close(mibfd); 12320Sstevel@tonic-gate (void) close(eventpipe_read); 12330Sstevel@tonic-gate (void) close(eventpipe_write); 12340Sstevel@tonic-gate } 12350Sstevel@tonic-gate 12360Sstevel@tonic-gate /* 12370Sstevel@tonic-gate * Create pipe for signal delivery and set up signal handlers. 12380Sstevel@tonic-gate */ 12390Sstevel@tonic-gate static void 12400Sstevel@tonic-gate setup_eventpipe(void) 12410Sstevel@tonic-gate { 12420Sstevel@tonic-gate int fds[2]; 12430Sstevel@tonic-gate struct sigaction act; 12440Sstevel@tonic-gate 12450Sstevel@tonic-gate if ((pipe(fds)) < 0) { 12460Sstevel@tonic-gate logperror("setup_eventpipe: pipe"); 12470Sstevel@tonic-gate exit(1); 12480Sstevel@tonic-gate } 12490Sstevel@tonic-gate eventpipe_read = fds[0]; 12500Sstevel@tonic-gate eventpipe_write = fds[1]; 12510Sstevel@tonic-gate if (poll_add(eventpipe_read) == -1) { 12520Sstevel@tonic-gate exit(1); 12530Sstevel@tonic-gate } 12540Sstevel@tonic-gate 12550Sstevel@tonic-gate act.sa_handler = sig_handler; 12560Sstevel@tonic-gate act.sa_flags = SA_RESTART; 12570Sstevel@tonic-gate (void) sigaction(SIGALRM, &act, NULL); 12580Sstevel@tonic-gate 12590Sstevel@tonic-gate (void) sigset(SIGHUP, sig_handler); 12600Sstevel@tonic-gate (void) sigset(SIGUSR1, sig_handler); 12610Sstevel@tonic-gate (void) sigset(SIGTERM, sig_handler); 12620Sstevel@tonic-gate (void) sigset(SIGINT, sig_handler); 12630Sstevel@tonic-gate (void) sigset(SIGQUIT, sig_handler); 12640Sstevel@tonic-gate } 12650Sstevel@tonic-gate 12660Sstevel@tonic-gate /* 12670Sstevel@tonic-gate * Create a routing socket for receiving RTM_IFINFO messages. 12680Sstevel@tonic-gate */ 12690Sstevel@tonic-gate static int 12700Sstevel@tonic-gate setup_rtsock(int af) 12710Sstevel@tonic-gate { 12720Sstevel@tonic-gate int s; 12730Sstevel@tonic-gate int flags; 12748485SPeter.Memishian@Sun.COM int aware = RTAW_UNDER_IPMP; 12750Sstevel@tonic-gate 12760Sstevel@tonic-gate s = socket(PF_ROUTE, SOCK_RAW, af); 12770Sstevel@tonic-gate if (s == -1) { 12780Sstevel@tonic-gate logperror("setup_rtsock: socket PF_ROUTE"); 12790Sstevel@tonic-gate exit(1); 12800Sstevel@tonic-gate } 12818485SPeter.Memishian@Sun.COM 12828485SPeter.Memishian@Sun.COM if (setsockopt(s, SOL_ROUTE, RT_AWARE, &aware, sizeof (aware)) == -1) { 12838485SPeter.Memishian@Sun.COM logperror("setup_rtsock: setsockopt RT_AWARE"); 12848485SPeter.Memishian@Sun.COM (void) close(s); 12858485SPeter.Memishian@Sun.COM exit(1); 12868485SPeter.Memishian@Sun.COM } 12878485SPeter.Memishian@Sun.COM 12880Sstevel@tonic-gate if ((flags = fcntl(s, F_GETFL, 0)) < 0) { 12890Sstevel@tonic-gate logperror("setup_rtsock: fcntl F_GETFL"); 12900Sstevel@tonic-gate (void) close(s); 12910Sstevel@tonic-gate exit(1); 12920Sstevel@tonic-gate } 12930Sstevel@tonic-gate if ((fcntl(s, F_SETFL, flags | O_NONBLOCK)) < 0) { 12940Sstevel@tonic-gate logperror("setup_rtsock: fcntl F_SETFL"); 12950Sstevel@tonic-gate (void) close(s); 12960Sstevel@tonic-gate exit(1); 12970Sstevel@tonic-gate } 12980Sstevel@tonic-gate if (poll_add(s) == -1) { 12990Sstevel@tonic-gate (void) close(s); 13000Sstevel@tonic-gate exit(1); 13010Sstevel@tonic-gate } 13020Sstevel@tonic-gate return (s); 13030Sstevel@tonic-gate } 13040Sstevel@tonic-gate 13050Sstevel@tonic-gate /* 13060Sstevel@tonic-gate * Process an RTM_IFINFO message received on a routing socket. 13070Sstevel@tonic-gate * The return value indicates whether a full interface scan is required. 13088485SPeter.Memishian@Sun.COM * Link up/down notifications are reflected in the IFF_RUNNING flag. 13090Sstevel@tonic-gate * If just the state of the IFF_RUNNING interface flag has changed, a 13100Sstevel@tonic-gate * a full interface scan isn't required. 13110Sstevel@tonic-gate */ 13120Sstevel@tonic-gate static boolean_t 13130Sstevel@tonic-gate process_rtm_ifinfo(if_msghdr_t *ifm, int type) 13140Sstevel@tonic-gate { 13150Sstevel@tonic-gate struct sockaddr_dl *sdl; 13160Sstevel@tonic-gate struct phyint *pi; 13170Sstevel@tonic-gate uint64_t old_flags; 13180Sstevel@tonic-gate struct phyint_instance *pii; 13190Sstevel@tonic-gate 13200Sstevel@tonic-gate assert(ifm->ifm_type == RTM_IFINFO && ifm->ifm_addrs == RTA_IFP); 13210Sstevel@tonic-gate 13220Sstevel@tonic-gate /* 13230Sstevel@tonic-gate * Although the sockaddr_dl structure is directly after the 13240Sstevel@tonic-gate * if_msghdr_t structure. At the time of writing, the size of the 13250Sstevel@tonic-gate * if_msghdr_t structure is different on 32 and 64 bit kernels, due 13260Sstevel@tonic-gate * to the presence of a timeval structure, which contains longs, 13270Sstevel@tonic-gate * in the if_data structure. Anyway, we know where the message ends, 13280Sstevel@tonic-gate * so we work backwards to get the start of the sockaddr_dl structure. 13290Sstevel@tonic-gate */ 13300Sstevel@tonic-gate /*LINTED*/ 13310Sstevel@tonic-gate sdl = (struct sockaddr_dl *)((char *)ifm + ifm->ifm_msglen - 13324770Smeem sizeof (struct sockaddr_dl)); 13330Sstevel@tonic-gate 13340Sstevel@tonic-gate assert(sdl->sdl_family == AF_LINK); 13350Sstevel@tonic-gate 13360Sstevel@tonic-gate /* 13370Sstevel@tonic-gate * The interface name is in sdl_data. 13380Sstevel@tonic-gate * RTM_IFINFO messages are only generated for logical interface 13390Sstevel@tonic-gate * zero, so there is no colon and logical interface number to 13400Sstevel@tonic-gate * strip from the name. The name is not null terminated, but 13410Sstevel@tonic-gate * there should be enough space in sdl_data to add the null. 13420Sstevel@tonic-gate */ 13430Sstevel@tonic-gate if (sdl->sdl_nlen >= sizeof (sdl->sdl_data)) { 13440Sstevel@tonic-gate if (debug & D_LINKNOTE) 13454770Smeem logdebug("process_rtm_ifinfo: phyint name too long\n"); 13460Sstevel@tonic-gate return (_B_TRUE); 13470Sstevel@tonic-gate } 13480Sstevel@tonic-gate sdl->sdl_data[sdl->sdl_nlen] = 0; 13490Sstevel@tonic-gate 13500Sstevel@tonic-gate pi = phyint_lookup(sdl->sdl_data); 13510Sstevel@tonic-gate if (pi == NULL) { 13520Sstevel@tonic-gate if (debug & D_LINKNOTE) 13530Sstevel@tonic-gate logdebug("process_rtm_ifinfo: phyint lookup failed" 13544770Smeem " for %s\n", sdl->sdl_data); 13550Sstevel@tonic-gate return (_B_TRUE); 13560Sstevel@tonic-gate } 13570Sstevel@tonic-gate 13580Sstevel@tonic-gate /* 13590Sstevel@tonic-gate * We want to try and avoid doing a full interface scan for 13608485SPeter.Memishian@Sun.COM * link state notifications from the datalink layer, as indicated 13610Sstevel@tonic-gate * by the state of the IFF_RUNNING flag. If just the 13620Sstevel@tonic-gate * IFF_RUNNING flag has changed state, the link state changes 13630Sstevel@tonic-gate * are processed without a full scan. 13640Sstevel@tonic-gate * If there is both an IPv4 and IPv6 instance associated with 13650Sstevel@tonic-gate * the physical interface, we will get an RTM_IFINFO message 13660Sstevel@tonic-gate * for each instance. If we just maintained a single copy of 13670Sstevel@tonic-gate * the physical interface flags, it would appear that no flags 13680Sstevel@tonic-gate * had changed when the second message is processed, leading us 13690Sstevel@tonic-gate * to believe that the message wasn't generated by a flags change, 13700Sstevel@tonic-gate * and that a full interface scan is required. 13710Sstevel@tonic-gate * To get around this problem, two additional copies of the flags 13720Sstevel@tonic-gate * are kept, one copy for each instance. These are only used in 13730Sstevel@tonic-gate * this routine. At any one time, all three copies of the flags 13740Sstevel@tonic-gate * should be identical except for the IFF_RUNNING flag. The 13750Sstevel@tonic-gate * copy of the flags in the "phyint" structure is always up to 13760Sstevel@tonic-gate * date. 13770Sstevel@tonic-gate */ 13780Sstevel@tonic-gate pii = (type == AF_INET) ? pi->pi_v4 : pi->pi_v6; 13790Sstevel@tonic-gate if (pii == NULL) { 13800Sstevel@tonic-gate if (debug & D_LINKNOTE) 13810Sstevel@tonic-gate logdebug("process_rtm_ifinfo: no instance of address " 13820Sstevel@tonic-gate "family %s for %s\n", AF_STR(type), pi->pi_name); 13830Sstevel@tonic-gate return (_B_TRUE); 13840Sstevel@tonic-gate } 13850Sstevel@tonic-gate 13860Sstevel@tonic-gate old_flags = pii->pii_flags; 13870Sstevel@tonic-gate pii->pii_flags = PHYINT_FLAGS(ifm->ifm_flags); 13880Sstevel@tonic-gate pi->pi_flags = pii->pii_flags; 13890Sstevel@tonic-gate 13900Sstevel@tonic-gate if (debug & D_LINKNOTE) { 13910Sstevel@tonic-gate logdebug("process_rtm_ifinfo: %s address family: %s, " 13920Sstevel@tonic-gate "old flags: %llx, new flags: %llx\n", pi->pi_name, 13930Sstevel@tonic-gate AF_STR(type), old_flags, pi->pi_flags); 13940Sstevel@tonic-gate } 13950Sstevel@tonic-gate 13960Sstevel@tonic-gate /* 13970Sstevel@tonic-gate * If IFF_STANDBY has changed, indicate that the interface has changed 13980Sstevel@tonic-gate * types. 13990Sstevel@tonic-gate */ 14000Sstevel@tonic-gate if ((old_flags ^ pii->pii_flags) & IFF_STANDBY) 14018485SPeter.Memishian@Sun.COM phyint_changed(pi); 14020Sstevel@tonic-gate 14030Sstevel@tonic-gate /* Has just the IFF_RUNNING flag changed state ? */ 14040Sstevel@tonic-gate if ((old_flags ^ pii->pii_flags) != IFF_RUNNING) { 14050Sstevel@tonic-gate struct phyint_instance *pii_other; 14060Sstevel@tonic-gate /* 14070Sstevel@tonic-gate * It wasn't just a link state change. Update 14080Sstevel@tonic-gate * the other instance's copy of the flags. 14090Sstevel@tonic-gate */ 14100Sstevel@tonic-gate pii_other = phyint_inst_other(pii); 14110Sstevel@tonic-gate if (pii_other != NULL) 14120Sstevel@tonic-gate pii_other->pii_flags = pii->pii_flags; 14130Sstevel@tonic-gate return (_B_TRUE); 14140Sstevel@tonic-gate } 14150Sstevel@tonic-gate 14160Sstevel@tonic-gate return (_B_FALSE); 14170Sstevel@tonic-gate } 14180Sstevel@tonic-gate 14190Sstevel@tonic-gate /* 14200Sstevel@tonic-gate * Retrieve as many routing socket messages as possible, and try to 14210Sstevel@tonic-gate * empty the routing sockets. Initiate full scan of targets or interfaces 14220Sstevel@tonic-gate * as needed. 14230Sstevel@tonic-gate * We listen on separate IPv4 an IPv6 sockets so that we can accurately 14240Sstevel@tonic-gate * detect changes in certain flags (see "process_rtm_ifinfo()" above). 14250Sstevel@tonic-gate */ 14260Sstevel@tonic-gate static void 14270Sstevel@tonic-gate process_rtsock(int rtsock_v4, int rtsock_v6) 14280Sstevel@tonic-gate { 14290Sstevel@tonic-gate int nbytes; 14300Sstevel@tonic-gate int64_t msg[2048 / 8]; 14310Sstevel@tonic-gate struct rt_msghdr *rtm; 14320Sstevel@tonic-gate boolean_t need_if_scan = _B_FALSE; 14330Sstevel@tonic-gate boolean_t need_rt_scan = _B_FALSE; 14340Sstevel@tonic-gate boolean_t rtm_ifinfo_seen = _B_FALSE; 14350Sstevel@tonic-gate int type; 14360Sstevel@tonic-gate 14370Sstevel@tonic-gate /* Read as many messages as possible and try to empty the sockets */ 14380Sstevel@tonic-gate for (type = AF_INET; ; type = AF_INET6) { 14390Sstevel@tonic-gate for (;;) { 14400Sstevel@tonic-gate nbytes = read((type == AF_INET) ? rtsock_v4 : 14414770Smeem rtsock_v6, msg, sizeof (msg)); 14420Sstevel@tonic-gate if (nbytes <= 0) { 14430Sstevel@tonic-gate /* No more messages */ 14440Sstevel@tonic-gate break; 14450Sstevel@tonic-gate } 14460Sstevel@tonic-gate rtm = (struct rt_msghdr *)msg; 14470Sstevel@tonic-gate if (rtm->rtm_version != RTM_VERSION) { 14480Sstevel@tonic-gate logerr("process_rtsock: version %d " 14490Sstevel@tonic-gate "not understood\n", rtm->rtm_version); 14500Sstevel@tonic-gate break; 14510Sstevel@tonic-gate } 14520Sstevel@tonic-gate 14530Sstevel@tonic-gate if (debug & D_PHYINT) { 14540Sstevel@tonic-gate logdebug("process_rtsock: message %d\n", 14550Sstevel@tonic-gate rtm->rtm_type); 14560Sstevel@tonic-gate } 14570Sstevel@tonic-gate 14580Sstevel@tonic-gate switch (rtm->rtm_type) { 14590Sstevel@tonic-gate case RTM_NEWADDR: 14600Sstevel@tonic-gate case RTM_DELADDR: 14610Sstevel@tonic-gate /* 14620Sstevel@tonic-gate * Some logical interface has changed, 14630Sstevel@tonic-gate * have to scan everything to determine 14640Sstevel@tonic-gate * what actually changed. 14650Sstevel@tonic-gate */ 14660Sstevel@tonic-gate need_if_scan = _B_TRUE; 14670Sstevel@tonic-gate break; 14680Sstevel@tonic-gate 14690Sstevel@tonic-gate case RTM_IFINFO: 14700Sstevel@tonic-gate rtm_ifinfo_seen = _B_TRUE; 14714770Smeem need_if_scan |= process_rtm_ifinfo( 14724770Smeem (if_msghdr_t *)rtm, type); 14730Sstevel@tonic-gate break; 14740Sstevel@tonic-gate 14750Sstevel@tonic-gate case RTM_ADD: 14760Sstevel@tonic-gate case RTM_DELETE: 14770Sstevel@tonic-gate case RTM_CHANGE: 14780Sstevel@tonic-gate case RTM_OLDADD: 14790Sstevel@tonic-gate case RTM_OLDDEL: 14800Sstevel@tonic-gate need_rt_scan = _B_TRUE; 14810Sstevel@tonic-gate break; 14820Sstevel@tonic-gate 14830Sstevel@tonic-gate default: 14840Sstevel@tonic-gate /* Not interesting */ 14850Sstevel@tonic-gate break; 14860Sstevel@tonic-gate } 14870Sstevel@tonic-gate } 14880Sstevel@tonic-gate if (type == AF_INET6) 14890Sstevel@tonic-gate break; 14900Sstevel@tonic-gate } 14910Sstevel@tonic-gate 14920Sstevel@tonic-gate if (need_if_scan) { 14930Sstevel@tonic-gate if (debug & D_LINKNOTE && rtm_ifinfo_seen) 14940Sstevel@tonic-gate logdebug("process_rtsock: synchronizing with kernel\n"); 14950Sstevel@tonic-gate initifs(); 14960Sstevel@tonic-gate } else if (rtm_ifinfo_seen) { 14970Sstevel@tonic-gate if (debug & D_LINKNOTE) 14980Sstevel@tonic-gate logdebug("process_rtsock: " 14990Sstevel@tonic-gate "link up/down notification(s) seen\n"); 15000Sstevel@tonic-gate process_link_state_changes(); 15010Sstevel@tonic-gate } 15020Sstevel@tonic-gate 15030Sstevel@tonic-gate if (need_rt_scan) 15040Sstevel@tonic-gate init_router_targets(); 15050Sstevel@tonic-gate } 15060Sstevel@tonic-gate 15070Sstevel@tonic-gate /* 15080Sstevel@tonic-gate * Look if the phyint instance or one of its logints have been removed from 15090Sstevel@tonic-gate * the kernel and take appropriate action. 15100Sstevel@tonic-gate * Uses {pii,li}_in_use. 15110Sstevel@tonic-gate */ 15120Sstevel@tonic-gate static void 15130Sstevel@tonic-gate check_if_removed(struct phyint_instance *pii) 15140Sstevel@tonic-gate { 15150Sstevel@tonic-gate struct logint *li; 15160Sstevel@tonic-gate struct logint *next_li; 15170Sstevel@tonic-gate 15180Sstevel@tonic-gate /* Detect phyints that have been removed from the kernel. */ 15190Sstevel@tonic-gate if (!pii->pii_in_use) { 15200Sstevel@tonic-gate logtrace("%s %s has been removed from kernel\n", 15210Sstevel@tonic-gate AF_STR(pii->pii_af), pii->pii_phyint->pi_name); 15220Sstevel@tonic-gate phyint_inst_delete(pii); 15230Sstevel@tonic-gate } else { 15240Sstevel@tonic-gate /* Detect logints that have been removed. */ 15250Sstevel@tonic-gate for (li = pii->pii_logint; li != NULL; li = next_li) { 15260Sstevel@tonic-gate next_li = li->li_next; 15270Sstevel@tonic-gate if (!li->li_in_use) { 15280Sstevel@tonic-gate logint_delete(li); 15290Sstevel@tonic-gate } 15300Sstevel@tonic-gate } 15310Sstevel@tonic-gate } 15320Sstevel@tonic-gate } 15330Sstevel@tonic-gate 15340Sstevel@tonic-gate /* 1535*8865SJonathan.Anderson@Sun.COM * Parse the supplied mib2 information to extract the routing information 1536*8865SJonathan.Anderson@Sun.COM * table. Process the routing table to get the list of known onlink routers 1537*8865SJonathan.Anderson@Sun.COM * and update our database. These onlink routers will serve as probe 1538*8865SJonathan.Anderson@Sun.COM * targets. 15390Sstevel@tonic-gate */ 1540*8865SJonathan.Anderson@Sun.COM static void 1541*8865SJonathan.Anderson@Sun.COM update_router_list(mib_item_t *item) 15420Sstevel@tonic-gate { 1543*8865SJonathan.Anderson@Sun.COM for (; item != NULL; item = item->mi_next) { 1544*8865SJonathan.Anderson@Sun.COM if (item->mi_opthdr.name == 0) 15450Sstevel@tonic-gate continue; 1546*8865SJonathan.Anderson@Sun.COM if (item->mi_opthdr.level == MIB2_IP && 1547*8865SJonathan.Anderson@Sun.COM item->mi_opthdr.name == MIB2_IP_ROUTE) { 1548*8865SJonathan.Anderson@Sun.COM ire_process_v4((mib2_ipRouteEntry_t *)item->mi_valp, 1549*8865SJonathan.Anderson@Sun.COM item->mi_opthdr.len); 1550*8865SJonathan.Anderson@Sun.COM } else if (item->mi_opthdr.level == MIB2_IP6 && 1551*8865SJonathan.Anderson@Sun.COM item->mi_opthdr.name == MIB2_IP6_ROUTE) { 1552*8865SJonathan.Anderson@Sun.COM ire_process_v6((mib2_ipv6RouteEntry_t *)item->mi_valp, 1553*8865SJonathan.Anderson@Sun.COM item->mi_opthdr.len); 15540Sstevel@tonic-gate } 15550Sstevel@tonic-gate } 15560Sstevel@tonic-gate } 15570Sstevel@tonic-gate 15588485SPeter.Memishian@Sun.COM 15590Sstevel@tonic-gate /* 15608485SPeter.Memishian@Sun.COM * Convert octet `octp' to a phyint name and store in `ifname' 15618485SPeter.Memishian@Sun.COM */ 15628485SPeter.Memishian@Sun.COM static void 15638485SPeter.Memishian@Sun.COM oct2ifname(const Octet_t *octp, char *ifname, size_t ifsize) 15648485SPeter.Memishian@Sun.COM { 15658485SPeter.Memishian@Sun.COM char *cp; 15668485SPeter.Memishian@Sun.COM size_t len = MIN(octp->o_length, ifsize - 1); 15678485SPeter.Memishian@Sun.COM 15688485SPeter.Memishian@Sun.COM (void) strncpy(ifname, octp->o_bytes, len); 15698485SPeter.Memishian@Sun.COM ifname[len] = '\0'; 15708485SPeter.Memishian@Sun.COM 15718485SPeter.Memishian@Sun.COM if ((cp = strchr(ifname, IF_SEPARATOR)) != NULL) 15728485SPeter.Memishian@Sun.COM *cp = '\0'; 15738485SPeter.Memishian@Sun.COM } 15748485SPeter.Memishian@Sun.COM 15758485SPeter.Memishian@Sun.COM /* 15768485SPeter.Memishian@Sun.COM * Examine the IPv4 routing table `buf' for possible targets. For each 15778485SPeter.Memishian@Sun.COM * possible target, if it's on the same subnet an interface route, pass 15788485SPeter.Memishian@Sun.COM * it to router_add_common() for further consideration. 15790Sstevel@tonic-gate */ 15800Sstevel@tonic-gate static void 15810Sstevel@tonic-gate ire_process_v4(mib2_ipRouteEntry_t *buf, size_t len) 15820Sstevel@tonic-gate { 15838485SPeter.Memishian@Sun.COM char ifname[LIFNAMSIZ]; 15848485SPeter.Memishian@Sun.COM mib2_ipRouteEntry_t *rp, *rp1, *endp; 15858485SPeter.Memishian@Sun.COM struct in_addr nexthop_v4; 15868485SPeter.Memishian@Sun.COM struct in6_addr nexthop; 15870Sstevel@tonic-gate 1588*8865SJonathan.Anderson@Sun.COM if (debug & D_TARGET) 1589*8865SJonathan.Anderson@Sun.COM logdebug("ire_process_v4(len %d)\n", len); 1590*8865SJonathan.Anderson@Sun.COM 15910Sstevel@tonic-gate if (len == 0) 15920Sstevel@tonic-gate return; 1593*8865SJonathan.Anderson@Sun.COM 1594*8865SJonathan.Anderson@Sun.COM assert((len % ipRouteEntrySize) == 0); 1595*8865SJonathan.Anderson@Sun.COM endp = buf + (len / ipRouteEntrySize); 15960Sstevel@tonic-gate 15970Sstevel@tonic-gate /* 15988485SPeter.Memishian@Sun.COM * Scan the routing table entries for any IRE_OFFSUBNET entries, and 15998485SPeter.Memishian@Sun.COM * cross-reference them with the interface routes to determine if 16008485SPeter.Memishian@Sun.COM * they're possible probe targets. 16010Sstevel@tonic-gate */ 16020Sstevel@tonic-gate for (rp = buf; rp < endp; rp++) { 16030Sstevel@tonic-gate if (!(rp->ipRouteInfo.re_ire_type & IRE_OFFSUBNET)) 16040Sstevel@tonic-gate continue; 16050Sstevel@tonic-gate 16068485SPeter.Memishian@Sun.COM /* Get the nexthop address. */ 16070Sstevel@tonic-gate nexthop_v4.s_addr = rp->ipRouteNextHop; 16080Sstevel@tonic-gate 16090Sstevel@tonic-gate /* 16108485SPeter.Memishian@Sun.COM * Rescan the routing table looking for interface routes that 16118485SPeter.Memishian@Sun.COM * are on the same subnet, and try to add them. If they're 16128485SPeter.Memishian@Sun.COM * not relevant (e.g., the interface route isn't part of an 16138485SPeter.Memishian@Sun.COM * IPMP group, router_add_common() will discard). 16140Sstevel@tonic-gate */ 16150Sstevel@tonic-gate for (rp1 = buf; rp1 < endp; rp1++) { 16168485SPeter.Memishian@Sun.COM if (!(rp1->ipRouteInfo.re_ire_type & IRE_INTERFACE) || 16178485SPeter.Memishian@Sun.COM rp1->ipRouteIfIndex.o_length == 0) 16180Sstevel@tonic-gate continue; 16198485SPeter.Memishian@Sun.COM 16208485SPeter.Memishian@Sun.COM if ((rp1->ipRouteDest & rp1->ipRouteMask) != 16218485SPeter.Memishian@Sun.COM (nexthop_v4.s_addr & rp1->ipRouteMask)) 16228485SPeter.Memishian@Sun.COM continue; 16238485SPeter.Memishian@Sun.COM 16248485SPeter.Memishian@Sun.COM oct2ifname(&rp1->ipRouteIfIndex, ifname, LIFNAMSIZ); 16258485SPeter.Memishian@Sun.COM IN6_INADDR_TO_V4MAPPED(&nexthop_v4, &nexthop); 16268485SPeter.Memishian@Sun.COM router_add_common(AF_INET, ifname, nexthop); 16270Sstevel@tonic-gate } 16280Sstevel@tonic-gate } 16290Sstevel@tonic-gate } 16300Sstevel@tonic-gate 16310Sstevel@tonic-gate void 16320Sstevel@tonic-gate router_add_common(int af, char *ifname, struct in6_addr nexthop) 16330Sstevel@tonic-gate { 16340Sstevel@tonic-gate struct phyint_instance *pii; 16350Sstevel@tonic-gate struct phyint *pi; 16360Sstevel@tonic-gate 16370Sstevel@tonic-gate if (debug & D_TARGET) 16380Sstevel@tonic-gate logdebug("router_add_common(%s %s)\n", AF_STR(af), ifname); 16390Sstevel@tonic-gate 16400Sstevel@tonic-gate /* 16410Sstevel@tonic-gate * Retrieve the phyint instance; bail if it's not known to us yet. 16420Sstevel@tonic-gate */ 16430Sstevel@tonic-gate pii = phyint_inst_lookup(af, ifname); 16440Sstevel@tonic-gate if (pii == NULL) 16450Sstevel@tonic-gate return; 16460Sstevel@tonic-gate 16470Sstevel@tonic-gate /* 16480Sstevel@tonic-gate * Don't use our own addresses as targets. 16490Sstevel@tonic-gate */ 16502250Srk129064 if (own_address(nexthop)) 16510Sstevel@tonic-gate return; 16520Sstevel@tonic-gate 16530Sstevel@tonic-gate /* 16540Sstevel@tonic-gate * If the phyint is part a named group, then add the address to all 16550Sstevel@tonic-gate * members of the group; note that this is suboptimal in the IPv4 case 16560Sstevel@tonic-gate * as it has already been added to all matching interfaces in 16570Sstevel@tonic-gate * ire_process_v4(). Otherwise, add the address only to the phyint 16580Sstevel@tonic-gate * itself, since other phyints in the anongroup may not be on the same 16590Sstevel@tonic-gate * subnet. 16600Sstevel@tonic-gate */ 16610Sstevel@tonic-gate pi = pii->pii_phyint; 16620Sstevel@tonic-gate if (pi->pi_group == phyint_anongroup) { 16630Sstevel@tonic-gate target_add(pii, nexthop, _B_TRUE); 16640Sstevel@tonic-gate } else { 16650Sstevel@tonic-gate pi = pi->pi_group->pg_phyint; 16660Sstevel@tonic-gate for (; pi != NULL; pi = pi->pi_pgnext) 16670Sstevel@tonic-gate target_add(PHYINT_INSTANCE(pi, af), nexthop, _B_TRUE); 16680Sstevel@tonic-gate } 16690Sstevel@tonic-gate } 16700Sstevel@tonic-gate 16710Sstevel@tonic-gate /* 16728485SPeter.Memishian@Sun.COM * Examine the IPv6 routing table `buf' for possible link-local targets, and 16738485SPeter.Memishian@Sun.COM * pass any contenders to router_add_common() for further consideration. 16740Sstevel@tonic-gate */ 16750Sstevel@tonic-gate static void 16760Sstevel@tonic-gate ire_process_v6(mib2_ipv6RouteEntry_t *buf, size_t len) 16770Sstevel@tonic-gate { 16788485SPeter.Memishian@Sun.COM struct lifreq lifr; 16798485SPeter.Memishian@Sun.COM char ifname[LIFNAMSIZ]; 16808485SPeter.Memishian@Sun.COM char grname[LIFGRNAMSIZ]; 16818485SPeter.Memishian@Sun.COM mib2_ipv6RouteEntry_t *rp, *rp1, *endp; 16828485SPeter.Memishian@Sun.COM struct in6_addr nexthop_v6; 16830Sstevel@tonic-gate 16840Sstevel@tonic-gate if (debug & D_TARGET) 16850Sstevel@tonic-gate logdebug("ire_process_v6(len %d)\n", len); 16860Sstevel@tonic-gate 16870Sstevel@tonic-gate if (len == 0) 16880Sstevel@tonic-gate return; 16890Sstevel@tonic-gate 1690*8865SJonathan.Anderson@Sun.COM assert((len % ipv6RouteEntrySize) == 0); 1691*8865SJonathan.Anderson@Sun.COM endp = buf + (len / ipv6RouteEntrySize); 16920Sstevel@tonic-gate 16930Sstevel@tonic-gate /* 16948485SPeter.Memishian@Sun.COM * Scan the routing table entries for any IRE_OFFSUBNET entries, and 16958485SPeter.Memishian@Sun.COM * cross-reference them with the interface routes to determine if 16968485SPeter.Memishian@Sun.COM * they're possible probe targets. 16970Sstevel@tonic-gate */ 16980Sstevel@tonic-gate for (rp = buf; rp < endp; rp++) { 16998485SPeter.Memishian@Sun.COM if (!(rp->ipv6RouteInfo.re_ire_type & IRE_OFFSUBNET) || 17008485SPeter.Memishian@Sun.COM !IN6_IS_ADDR_LINKLOCAL(&rp->ipv6RouteNextHop)) 17010Sstevel@tonic-gate continue; 17020Sstevel@tonic-gate 17038485SPeter.Memishian@Sun.COM /* Get the nexthop address. */ 17048485SPeter.Memishian@Sun.COM nexthop_v6 = rp->ipv6RouteNextHop; 17058485SPeter.Memishian@Sun.COM 17060Sstevel@tonic-gate /* 17078485SPeter.Memishian@Sun.COM * The interface name should always exist for link-locals; 17088485SPeter.Memishian@Sun.COM * we use it to map this entry to an IPMP group name. 17090Sstevel@tonic-gate */ 17108485SPeter.Memishian@Sun.COM if (rp->ipv6RouteIfIndex.o_length == 0) 17118485SPeter.Memishian@Sun.COM continue; 17128485SPeter.Memishian@Sun.COM 17138485SPeter.Memishian@Sun.COM oct2ifname(&rp->ipv6RouteIfIndex, lifr.lifr_name, LIFNAMSIZ); 17148485SPeter.Memishian@Sun.COM if (ioctl(ifsock_v6, SIOCGLIFGROUPNAME, &lifr) == -1 || 17158485SPeter.Memishian@Sun.COM strlcpy(grname, lifr.lifr_groupname, LIFGRNAMSIZ) == 0) { 17168485SPeter.Memishian@Sun.COM continue; 17178485SPeter.Memishian@Sun.COM } 17188485SPeter.Memishian@Sun.COM 17198485SPeter.Memishian@Sun.COM /* 17208485SPeter.Memishian@Sun.COM * Rescan the list of routes for interface routes, and add the 17218485SPeter.Memishian@Sun.COM * above target to any interfaces in the same IPMP group. 17228485SPeter.Memishian@Sun.COM */ 17238485SPeter.Memishian@Sun.COM for (rp1 = buf; rp1 < endp; rp1++) { 17248485SPeter.Memishian@Sun.COM if (!(rp1->ipv6RouteInfo.re_ire_type & IRE_INTERFACE) || 17258485SPeter.Memishian@Sun.COM rp1->ipv6RouteIfIndex.o_length == 0) { 17268485SPeter.Memishian@Sun.COM continue; 17278485SPeter.Memishian@Sun.COM } 17288485SPeter.Memishian@Sun.COM oct2ifname(&rp1->ipv6RouteIfIndex, ifname, LIFNAMSIZ); 17298485SPeter.Memishian@Sun.COM (void) strlcpy(lifr.lifr_name, ifname, LIFNAMSIZ); 17308485SPeter.Memishian@Sun.COM 17318485SPeter.Memishian@Sun.COM if (ioctl(ifsock_v6, SIOCGLIFGROUPNAME, &lifr) != -1 && 17328485SPeter.Memishian@Sun.COM strcmp(lifr.lifr_groupname, grname) == 0) { 17338485SPeter.Memishian@Sun.COM router_add_common(AF_INET6, ifname, nexthop_v6); 17348485SPeter.Memishian@Sun.COM } 17350Sstevel@tonic-gate } 17360Sstevel@tonic-gate } 17370Sstevel@tonic-gate } 17380Sstevel@tonic-gate 17390Sstevel@tonic-gate /* 17400Sstevel@tonic-gate * Build a list of target routers, by scanning the routing tables. 17410Sstevel@tonic-gate * It is assumed that interface routes exist, to reach the routers. 17420Sstevel@tonic-gate */ 17430Sstevel@tonic-gate static void 17440Sstevel@tonic-gate init_router_targets(void) 17450Sstevel@tonic-gate { 17460Sstevel@tonic-gate struct target *tg; 17470Sstevel@tonic-gate struct target *next_tg; 17480Sstevel@tonic-gate struct phyint_instance *pii; 17490Sstevel@tonic-gate struct phyint *pi; 17500Sstevel@tonic-gate 17510Sstevel@tonic-gate if (force_mcast) 17520Sstevel@tonic-gate return; 17530Sstevel@tonic-gate 17540Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; pii = pii->pii_next) { 17550Sstevel@tonic-gate pi = pii->pii_phyint; 17560Sstevel@tonic-gate /* 17578485SPeter.Memishian@Sun.COM * Set tg_in_use to false only for router targets. 17580Sstevel@tonic-gate */ 17598485SPeter.Memishian@Sun.COM if (!pii->pii_targets_are_routers) 17600Sstevel@tonic-gate continue; 17610Sstevel@tonic-gate 17620Sstevel@tonic-gate for (tg = pii->pii_targets; tg != NULL; tg = tg->tg_next) 17630Sstevel@tonic-gate tg->tg_in_use = 0; 17640Sstevel@tonic-gate } 17650Sstevel@tonic-gate 1766*8865SJonathan.Anderson@Sun.COM if (mibwalk(update_router_list) == -1) 1767*8865SJonathan.Anderson@Sun.COM exit(1); 17680Sstevel@tonic-gate 17690Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; pii = pii->pii_next) { 17708485SPeter.Memishian@Sun.COM pi = pii->pii_phyint; 17718485SPeter.Memishian@Sun.COM if (!pii->pii_targets_are_routers) 17720Sstevel@tonic-gate continue; 17730Sstevel@tonic-gate 17740Sstevel@tonic-gate for (tg = pii->pii_targets; tg != NULL; tg = next_tg) { 17750Sstevel@tonic-gate next_tg = tg->tg_next; 17768485SPeter.Memishian@Sun.COM /* 17778485SPeter.Memishian@Sun.COM * If the group has failed, it's likely the route was 17788485SPeter.Memishian@Sun.COM * removed by an application affected by that failure. 17798485SPeter.Memishian@Sun.COM * In that case, we keep the target so that we can 17808485SPeter.Memishian@Sun.COM * reliably repair, at which point we'll refresh the 17818485SPeter.Memishian@Sun.COM * target list again. 17828485SPeter.Memishian@Sun.COM */ 17838485SPeter.Memishian@Sun.COM if (!tg->tg_in_use && !GROUP_FAILED(pi->pi_group)) 17840Sstevel@tonic-gate target_delete(tg); 17850Sstevel@tonic-gate } 17860Sstevel@tonic-gate } 17870Sstevel@tonic-gate } 17880Sstevel@tonic-gate 17890Sstevel@tonic-gate /* 17900Sstevel@tonic-gate * Attempt to assign host targets to any interfaces that do not currently 17910Sstevel@tonic-gate * have probe targets by sharing targets with other interfaces in the group. 17920Sstevel@tonic-gate */ 17930Sstevel@tonic-gate static void 17940Sstevel@tonic-gate init_host_targets(void) 17950Sstevel@tonic-gate { 17960Sstevel@tonic-gate struct phyint_instance *pii; 17970Sstevel@tonic-gate struct phyint_group *pg; 17980Sstevel@tonic-gate 17990Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; pii = pii->pii_next) { 18000Sstevel@tonic-gate pg = pii->pii_phyint->pi_group; 18010Sstevel@tonic-gate if (pg != phyint_anongroup && pii->pii_targets == NULL) 18020Sstevel@tonic-gate dup_host_targets(pii); 18030Sstevel@tonic-gate } 18040Sstevel@tonic-gate } 18050Sstevel@tonic-gate 18060Sstevel@tonic-gate /* 18070Sstevel@tonic-gate * Duplicate host targets from other phyints of the group to 18080Sstevel@tonic-gate * the phyint instance 'desired_pii'. 18090Sstevel@tonic-gate */ 18100Sstevel@tonic-gate static void 18110Sstevel@tonic-gate dup_host_targets(struct phyint_instance *desired_pii) 18120Sstevel@tonic-gate { 18130Sstevel@tonic-gate int af; 18140Sstevel@tonic-gate struct phyint *pi; 18150Sstevel@tonic-gate struct phyint_instance *pii; 18160Sstevel@tonic-gate struct target *tg; 18170Sstevel@tonic-gate 18180Sstevel@tonic-gate assert(desired_pii->pii_phyint->pi_group != phyint_anongroup); 18190Sstevel@tonic-gate 18200Sstevel@tonic-gate af = desired_pii->pii_af; 18210Sstevel@tonic-gate 18220Sstevel@tonic-gate /* 18230Sstevel@tonic-gate * For every phyint in the same group as desired_pii, check if 18240Sstevel@tonic-gate * it has any host targets. If so add them to desired_pii. 18250Sstevel@tonic-gate */ 18260Sstevel@tonic-gate for (pi = desired_pii->pii_phyint; pi != NULL; pi = pi->pi_pgnext) { 18270Sstevel@tonic-gate pii = PHYINT_INSTANCE(pi, af); 18280Sstevel@tonic-gate /* 18290Sstevel@tonic-gate * We know that we don't have targets on this phyint instance 18300Sstevel@tonic-gate * since we have been called. But we still check for 18310Sstevel@tonic-gate * pii_targets_are_routers because another phyint instance 18320Sstevel@tonic-gate * could have router targets, since IFF_NOFAILOVER addresses 18330Sstevel@tonic-gate * on different phyint instances may belong to different 18340Sstevel@tonic-gate * subnets. 18350Sstevel@tonic-gate */ 18360Sstevel@tonic-gate if ((pii == NULL) || (pii == desired_pii) || 18370Sstevel@tonic-gate pii->pii_targets_are_routers) 18380Sstevel@tonic-gate continue; 18390Sstevel@tonic-gate for (tg = pii->pii_targets; tg != NULL; tg = tg->tg_next) { 18400Sstevel@tonic-gate target_create(desired_pii, tg->tg_address, _B_FALSE); 18410Sstevel@tonic-gate } 18420Sstevel@tonic-gate } 18430Sstevel@tonic-gate } 18440Sstevel@tonic-gate 18450Sstevel@tonic-gate static void 18460Sstevel@tonic-gate usage(char *cmd) 18470Sstevel@tonic-gate { 18480Sstevel@tonic-gate (void) fprintf(stderr, "usage: %s\n", cmd); 18490Sstevel@tonic-gate } 18500Sstevel@tonic-gate 18510Sstevel@tonic-gate 18520Sstevel@tonic-gate #define MPATHD_DEFAULT_FILE "/etc/default/mpathd" 18530Sstevel@tonic-gate 18540Sstevel@tonic-gate /* Get an option from the /etc/default/mpathd file */ 18550Sstevel@tonic-gate static char * 18560Sstevel@tonic-gate getdefault(char *name) 18570Sstevel@tonic-gate { 18580Sstevel@tonic-gate char namebuf[BUFSIZ]; 18590Sstevel@tonic-gate char *value = NULL; 18600Sstevel@tonic-gate 18610Sstevel@tonic-gate if (defopen(MPATHD_DEFAULT_FILE) == 0) { 18620Sstevel@tonic-gate char *cp; 18630Sstevel@tonic-gate int flags; 18640Sstevel@tonic-gate 18650Sstevel@tonic-gate /* 18660Sstevel@tonic-gate * ignore case 18670Sstevel@tonic-gate */ 18680Sstevel@tonic-gate flags = defcntl(DC_GETFLAGS, 0); 18690Sstevel@tonic-gate TURNOFF(flags, DC_CASE); 18700Sstevel@tonic-gate (void) defcntl(DC_SETFLAGS, flags); 18710Sstevel@tonic-gate 18720Sstevel@tonic-gate /* Add "=" to the name */ 18730Sstevel@tonic-gate (void) strncpy(namebuf, name, sizeof (namebuf) - 2); 18740Sstevel@tonic-gate (void) strncat(namebuf, "=", 2); 18750Sstevel@tonic-gate 18760Sstevel@tonic-gate if ((cp = defread(namebuf)) != NULL) 18770Sstevel@tonic-gate value = strdup(cp); 18780Sstevel@tonic-gate 18790Sstevel@tonic-gate /* close */ 18800Sstevel@tonic-gate (void) defopen((char *)NULL); 18810Sstevel@tonic-gate } 18820Sstevel@tonic-gate return (value); 18830Sstevel@tonic-gate } 18840Sstevel@tonic-gate 18850Sstevel@tonic-gate 18860Sstevel@tonic-gate /* 18870Sstevel@tonic-gate * Command line options below 18880Sstevel@tonic-gate */ 18890Sstevel@tonic-gate boolean_t failback_enabled = _B_TRUE; /* failback enabled/disabled */ 18908485SPeter.Memishian@Sun.COM boolean_t track_all_phyints = _B_FALSE; /* track all IP interfaces */ 18910Sstevel@tonic-gate static boolean_t adopt = _B_FALSE; 18920Sstevel@tonic-gate static boolean_t foreground = _B_FALSE; 18930Sstevel@tonic-gate 18940Sstevel@tonic-gate int 18950Sstevel@tonic-gate main(int argc, char *argv[]) 18960Sstevel@tonic-gate { 18970Sstevel@tonic-gate int i; 18980Sstevel@tonic-gate int c; 18998485SPeter.Memishian@Sun.COM struct phyint *pi; 19000Sstevel@tonic-gate struct phyint_instance *pii; 19010Sstevel@tonic-gate char *value; 19020Sstevel@tonic-gate 19030Sstevel@tonic-gate argv0 = argv; /* Saved for re-exec on SIGHUP */ 19040Sstevel@tonic-gate srandom(gethostid()); /* Initialize the random number generator */ 19050Sstevel@tonic-gate 19060Sstevel@tonic-gate /* 19070Sstevel@tonic-gate * NOTE: The messages output by in.mpathd are not suitable for 19080Sstevel@tonic-gate * translation, so we do not call textdomain(). 19090Sstevel@tonic-gate */ 19100Sstevel@tonic-gate (void) setlocale(LC_ALL, ""); 19110Sstevel@tonic-gate 19120Sstevel@tonic-gate /* 19130Sstevel@tonic-gate * Get the user specified value of 'failure detection time' 19140Sstevel@tonic-gate * from /etc/default/mpathd 19150Sstevel@tonic-gate */ 19160Sstevel@tonic-gate value = getdefault("FAILURE_DETECTION_TIME"); 19170Sstevel@tonic-gate if (value != NULL) { 19180Sstevel@tonic-gate user_failure_detection_time = 19190Sstevel@tonic-gate (int)strtol((char *)value, NULL, 0); 19200Sstevel@tonic-gate 19210Sstevel@tonic-gate if (user_failure_detection_time <= 0) { 19220Sstevel@tonic-gate user_failure_detection_time = FAILURE_DETECTION_TIME; 19230Sstevel@tonic-gate logerr("Invalid failure detection time %s, assuming " 19248485SPeter.Memishian@Sun.COM "default of %d ms\n", value, 19258485SPeter.Memishian@Sun.COM user_failure_detection_time); 19260Sstevel@tonic-gate 19270Sstevel@tonic-gate } else if (user_failure_detection_time < 19280Sstevel@tonic-gate MIN_FAILURE_DETECTION_TIME) { 19290Sstevel@tonic-gate user_failure_detection_time = 19300Sstevel@tonic-gate MIN_FAILURE_DETECTION_TIME; 19310Sstevel@tonic-gate logerr("Too small failure detection time of %s, " 19328485SPeter.Memishian@Sun.COM "assuming minimum of %d ms\n", value, 19330Sstevel@tonic-gate user_failure_detection_time); 19340Sstevel@tonic-gate } 19350Sstevel@tonic-gate free(value); 19360Sstevel@tonic-gate } else { 19370Sstevel@tonic-gate /* User has not specified the parameter, Use default value */ 19380Sstevel@tonic-gate user_failure_detection_time = FAILURE_DETECTION_TIME; 19390Sstevel@tonic-gate } 19400Sstevel@tonic-gate 19410Sstevel@tonic-gate /* 19420Sstevel@tonic-gate * This gives the frequency at which probes will be sent. 19430Sstevel@tonic-gate * When fdt ms elapses, we should be able to determine 19440Sstevel@tonic-gate * whether 5 consecutive probes have failed or not. 19450Sstevel@tonic-gate * 1 probe will be sent in every user_probe_interval ms, 19460Sstevel@tonic-gate * randomly anytime in the (0.5 - 1.0) 2nd half of every 19470Sstevel@tonic-gate * user_probe_interval. Thus when we send out probe 'n' we 19480Sstevel@tonic-gate * can be sure that probe 'n - 2' is lost, if we have not 19490Sstevel@tonic-gate * got the ack. (since the probe interval is > crtt). But 19500Sstevel@tonic-gate * probe 'n - 1' may be a valid unacked probe, since the 19510Sstevel@tonic-gate * time between 2 successive probes could be as small as 19520Sstevel@tonic-gate * 0.5 * user_probe_interval. Hence the NUM_PROBE_FAILS + 2 19530Sstevel@tonic-gate */ 19540Sstevel@tonic-gate user_probe_interval = user_failure_detection_time / 19550Sstevel@tonic-gate (NUM_PROBE_FAILS + 2); 19560Sstevel@tonic-gate 19570Sstevel@tonic-gate /* 19580Sstevel@tonic-gate * Get the user specified value of failback_enabled from 19590Sstevel@tonic-gate * /etc/default/mpathd 19600Sstevel@tonic-gate */ 19610Sstevel@tonic-gate value = getdefault("FAILBACK"); 19620Sstevel@tonic-gate if (value != NULL) { 19638485SPeter.Memishian@Sun.COM if (strcasecmp(value, "yes") == 0) 19640Sstevel@tonic-gate failback_enabled = _B_TRUE; 19658485SPeter.Memishian@Sun.COM else if (strcasecmp(value, "no") == 0) 19660Sstevel@tonic-gate failback_enabled = _B_FALSE; 19670Sstevel@tonic-gate else 19680Sstevel@tonic-gate logerr("Invalid value for FAILBACK %s\n", value); 19690Sstevel@tonic-gate free(value); 19700Sstevel@tonic-gate } else { 19710Sstevel@tonic-gate failback_enabled = _B_TRUE; 19720Sstevel@tonic-gate } 19730Sstevel@tonic-gate 19740Sstevel@tonic-gate /* 19750Sstevel@tonic-gate * Get the user specified value of track_all_phyints from 19760Sstevel@tonic-gate * /etc/default/mpathd. The sense is reversed in 19770Sstevel@tonic-gate * TRACK_INTERFACES_ONLY_WITH_GROUPS. 19780Sstevel@tonic-gate */ 19790Sstevel@tonic-gate value = getdefault("TRACK_INTERFACES_ONLY_WITH_GROUPS"); 19800Sstevel@tonic-gate if (value != NULL) { 19818485SPeter.Memishian@Sun.COM if (strcasecmp(value, "yes") == 0) 19820Sstevel@tonic-gate track_all_phyints = _B_FALSE; 19838485SPeter.Memishian@Sun.COM else if (strcasecmp(value, "no") == 0) 19840Sstevel@tonic-gate track_all_phyints = _B_TRUE; 19850Sstevel@tonic-gate else 19860Sstevel@tonic-gate logerr("Invalid value for " 19870Sstevel@tonic-gate "TRACK_INTERFACES_ONLY_WITH_GROUPS %s\n", value); 19880Sstevel@tonic-gate free(value); 19890Sstevel@tonic-gate } else { 19900Sstevel@tonic-gate track_all_phyints = _B_FALSE; 19910Sstevel@tonic-gate } 19920Sstevel@tonic-gate 19930Sstevel@tonic-gate while ((c = getopt(argc, argv, "adD:ml")) != EOF) { 19940Sstevel@tonic-gate switch (c) { 19950Sstevel@tonic-gate case 'a': 19960Sstevel@tonic-gate adopt = _B_TRUE; 19970Sstevel@tonic-gate break; 19980Sstevel@tonic-gate case 'm': 19990Sstevel@tonic-gate force_mcast = _B_TRUE; 20000Sstevel@tonic-gate break; 20010Sstevel@tonic-gate case 'd': 20020Sstevel@tonic-gate debug = D_ALL; 20030Sstevel@tonic-gate foreground = _B_TRUE; 20040Sstevel@tonic-gate break; 20050Sstevel@tonic-gate case 'D': 20060Sstevel@tonic-gate i = (int)strtol(optarg, NULL, 0); 20070Sstevel@tonic-gate if (i == 0) { 20080Sstevel@tonic-gate (void) fprintf(stderr, "Bad debug flags: %s\n", 20090Sstevel@tonic-gate optarg); 20100Sstevel@tonic-gate exit(1); 20110Sstevel@tonic-gate } 20120Sstevel@tonic-gate debug |= i; 20130Sstevel@tonic-gate foreground = _B_TRUE; 20140Sstevel@tonic-gate break; 20150Sstevel@tonic-gate case 'l': 20160Sstevel@tonic-gate /* 20170Sstevel@tonic-gate * Turn off link state notification handling. 20180Sstevel@tonic-gate * Undocumented command line flag, for debugging 20190Sstevel@tonic-gate * purposes. 20200Sstevel@tonic-gate */ 20210Sstevel@tonic-gate handle_link_notifications = _B_FALSE; 20220Sstevel@tonic-gate break; 20230Sstevel@tonic-gate default: 20240Sstevel@tonic-gate usage(argv[0]); 20250Sstevel@tonic-gate exit(1); 20260Sstevel@tonic-gate } 20270Sstevel@tonic-gate } 20280Sstevel@tonic-gate 20290Sstevel@tonic-gate /* 20300Sstevel@tonic-gate * The sockets for the loopback command interface should be listening 20310Sstevel@tonic-gate * before we fork and exit in daemonize(). This way, whoever started us 20320Sstevel@tonic-gate * can use the loopback interface as soon as they get a zero exit 20330Sstevel@tonic-gate * status. 20340Sstevel@tonic-gate */ 20350Sstevel@tonic-gate lsock_v4 = setup_listener(AF_INET); 20360Sstevel@tonic-gate lsock_v6 = setup_listener(AF_INET6); 20370Sstevel@tonic-gate 20380Sstevel@tonic-gate if (lsock_v4 < 0 && lsock_v6 < 0) { 20390Sstevel@tonic-gate logerr("main: setup_listener failed for both IPv4 and IPv6\n"); 20400Sstevel@tonic-gate exit(1); 20410Sstevel@tonic-gate } 20420Sstevel@tonic-gate 20430Sstevel@tonic-gate if (!foreground) { 20440Sstevel@tonic-gate if (!daemonize()) { 20450Sstevel@tonic-gate logerr("cannot daemonize\n"); 20460Sstevel@tonic-gate exit(EXIT_FAILURE); 20470Sstevel@tonic-gate } 20480Sstevel@tonic-gate initlog(); 20490Sstevel@tonic-gate } 20500Sstevel@tonic-gate 20510Sstevel@tonic-gate /* 20520Sstevel@tonic-gate * Initializations: 20530Sstevel@tonic-gate * 1. Create ifsock* sockets. These are used for performing SIOC* 20540Sstevel@tonic-gate * ioctls. We have 2 sockets 1 each for IPv4 and IPv6. 20550Sstevel@tonic-gate * 2. Initialize a pipe for handling/recording signal events. 20560Sstevel@tonic-gate * 3. Create the routing sockets, used for listening 20570Sstevel@tonic-gate * to routing / interface changes. 20580Sstevel@tonic-gate * 4. phyint_init() - Initialize physical interface state 20590Sstevel@tonic-gate * (in mpd_tables.c). Must be done before creating interfaces, 20600Sstevel@tonic-gate * which timer_init() does indirectly. 2061*8865SJonathan.Anderson@Sun.COM * 5. Query kernel for route entry sizes (v4 and v6). 2062*8865SJonathan.Anderson@Sun.COM * 6. timer_init() - Initialize timer related stuff 2063*8865SJonathan.Anderson@Sun.COM * 7. initifs() - Initialize our database of all known interfaces 2064*8865SJonathan.Anderson@Sun.COM * 8. init_router_targets() - Initialize our database of all known 20650Sstevel@tonic-gate * router targets. 20660Sstevel@tonic-gate */ 20670Sstevel@tonic-gate ifsock_v4 = socket(AF_INET, SOCK_DGRAM, 0); 20680Sstevel@tonic-gate if (ifsock_v4 < 0) { 20690Sstevel@tonic-gate logperror("main: IPv4 socket open"); 20700Sstevel@tonic-gate exit(1); 20710Sstevel@tonic-gate } 20720Sstevel@tonic-gate 20730Sstevel@tonic-gate ifsock_v6 = socket(AF_INET6, SOCK_DGRAM, 0); 20740Sstevel@tonic-gate if (ifsock_v6 < 0) { 20750Sstevel@tonic-gate logperror("main: IPv6 socket open"); 20760Sstevel@tonic-gate exit(1); 20770Sstevel@tonic-gate } 20780Sstevel@tonic-gate 20790Sstevel@tonic-gate setup_eventpipe(); 20800Sstevel@tonic-gate 20810Sstevel@tonic-gate rtsock_v4 = setup_rtsock(AF_INET); 20820Sstevel@tonic-gate rtsock_v6 = setup_rtsock(AF_INET6); 20830Sstevel@tonic-gate 20840Sstevel@tonic-gate if (phyint_init() == -1) { 20850Sstevel@tonic-gate logerr("cannot initialize physical interface structures"); 20860Sstevel@tonic-gate exit(1); 20870Sstevel@tonic-gate } 20880Sstevel@tonic-gate 2089*8865SJonathan.Anderson@Sun.COM if (mibwalk(mib_get_constants) == -1) 2090*8865SJonathan.Anderson@Sun.COM exit(1); 2091*8865SJonathan.Anderson@Sun.COM 20920Sstevel@tonic-gate timer_init(); 20930Sstevel@tonic-gate 20940Sstevel@tonic-gate initifs(); 20950Sstevel@tonic-gate 20960Sstevel@tonic-gate /* 20970Sstevel@tonic-gate * If we're operating in "adopt" mode and no interfaces need to be 20980Sstevel@tonic-gate * tracked, shut down (ifconfig(1M) will restart us on demand if 20990Sstevel@tonic-gate * interfaces are subsequently put into multipathing groups). 21000Sstevel@tonic-gate */ 21010Sstevel@tonic-gate if (adopt && phyint_instances == NULL) 21020Sstevel@tonic-gate exit(0); 21030Sstevel@tonic-gate 21040Sstevel@tonic-gate /* 21050Sstevel@tonic-gate * Main body. Keep listening for activity on any of the sockets 21060Sstevel@tonic-gate * that we are monitoring and take appropriate action as necessary. 21070Sstevel@tonic-gate * signals are also handled synchronously. 21080Sstevel@tonic-gate */ 21090Sstevel@tonic-gate for (;;) { 21100Sstevel@tonic-gate if (poll(pollfds, pollfd_num, -1) < 0) { 21110Sstevel@tonic-gate if (errno == EINTR) 21120Sstevel@tonic-gate continue; 21130Sstevel@tonic-gate logperror("main: poll"); 21140Sstevel@tonic-gate exit(1); 21150Sstevel@tonic-gate } 21160Sstevel@tonic-gate for (i = 0; i < pollfd_num; i++) { 21170Sstevel@tonic-gate if ((pollfds[i].fd == -1) || 21180Sstevel@tonic-gate !(pollfds[i].revents & POLLIN)) 21190Sstevel@tonic-gate continue; 21200Sstevel@tonic-gate if (pollfds[i].fd == eventpipe_read) { 21210Sstevel@tonic-gate in_signal(eventpipe_read); 21220Sstevel@tonic-gate break; 21230Sstevel@tonic-gate } 21240Sstevel@tonic-gate if (pollfds[i].fd == rtsock_v4 || 21252496Smeem pollfds[i].fd == rtsock_v6) { 21260Sstevel@tonic-gate process_rtsock(rtsock_v4, rtsock_v6); 21270Sstevel@tonic-gate break; 21280Sstevel@tonic-gate } 21298485SPeter.Memishian@Sun.COM 21300Sstevel@tonic-gate for (pii = phyint_instances; pii != NULL; 21310Sstevel@tonic-gate pii = pii->pii_next) { 21320Sstevel@tonic-gate if (pollfds[i].fd == pii->pii_probe_sock) { 21330Sstevel@tonic-gate if (pii->pii_af == AF_INET) 21340Sstevel@tonic-gate in_data(pii); 21350Sstevel@tonic-gate else 21360Sstevel@tonic-gate in6_data(pii); 21370Sstevel@tonic-gate break; 21380Sstevel@tonic-gate } 21390Sstevel@tonic-gate } 21408485SPeter.Memishian@Sun.COM 21418485SPeter.Memishian@Sun.COM for (pi = phyints; pi != NULL; pi = pi->pi_next) { 21428485SPeter.Memishian@Sun.COM if (pi->pi_notes != 0 && 21438485SPeter.Memishian@Sun.COM pollfds[i].fd == dlpi_fd(pi->pi_dh)) { 21448485SPeter.Memishian@Sun.COM (void) dlpi_recv(pi->pi_dh, NULL, NULL, 21458485SPeter.Memishian@Sun.COM NULL, NULL, 0, NULL); 21468485SPeter.Memishian@Sun.COM break; 21478485SPeter.Memishian@Sun.COM } 21488485SPeter.Memishian@Sun.COM } 21498485SPeter.Memishian@Sun.COM 21500Sstevel@tonic-gate if (pollfds[i].fd == lsock_v4) 21510Sstevel@tonic-gate loopback_cmd(lsock_v4, AF_INET); 21520Sstevel@tonic-gate else if (pollfds[i].fd == lsock_v6) 21530Sstevel@tonic-gate loopback_cmd(lsock_v6, AF_INET6); 21540Sstevel@tonic-gate } 21550Sstevel@tonic-gate } 21560Sstevel@tonic-gate /* NOTREACHED */ 21570Sstevel@tonic-gate return (EXIT_SUCCESS); 21580Sstevel@tonic-gate } 21590Sstevel@tonic-gate 21600Sstevel@tonic-gate static int 21610Sstevel@tonic-gate setup_listener(int af) 21620Sstevel@tonic-gate { 21630Sstevel@tonic-gate int sock; 21640Sstevel@tonic-gate int on; 21650Sstevel@tonic-gate int len; 21660Sstevel@tonic-gate int ret; 21670Sstevel@tonic-gate struct sockaddr_storage laddr; 21680Sstevel@tonic-gate struct sockaddr_in *sin; 21690Sstevel@tonic-gate struct sockaddr_in6 *sin6; 21700Sstevel@tonic-gate struct in6_addr loopback_addr = IN6ADDR_LOOPBACK_INIT; 21710Sstevel@tonic-gate 21720Sstevel@tonic-gate assert(af == AF_INET || af == AF_INET6); 21730Sstevel@tonic-gate 21740Sstevel@tonic-gate sock = socket(af, SOCK_STREAM, 0); 21750Sstevel@tonic-gate if (sock < 0) { 21760Sstevel@tonic-gate logperror("setup_listener: socket"); 21770Sstevel@tonic-gate exit(1); 21780Sstevel@tonic-gate } 21790Sstevel@tonic-gate 21800Sstevel@tonic-gate on = 1; 21810Sstevel@tonic-gate if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (char *)&on, 21820Sstevel@tonic-gate sizeof (on)) < 0) { 21830Sstevel@tonic-gate logperror("setup_listener: setsockopt (SO_REUSEADDR)"); 21840Sstevel@tonic-gate exit(1); 21850Sstevel@tonic-gate } 21860Sstevel@tonic-gate 21870Sstevel@tonic-gate bzero(&laddr, sizeof (laddr)); 21880Sstevel@tonic-gate laddr.ss_family = af; 21890Sstevel@tonic-gate 21900Sstevel@tonic-gate if (af == AF_INET) { 21910Sstevel@tonic-gate sin = (struct sockaddr_in *)&laddr; 21920Sstevel@tonic-gate sin->sin_port = htons(MPATHD_PORT); 21930Sstevel@tonic-gate sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK); 21940Sstevel@tonic-gate len = sizeof (struct sockaddr_in); 21950Sstevel@tonic-gate } else { 21960Sstevel@tonic-gate sin6 = (struct sockaddr_in6 *)&laddr; 21970Sstevel@tonic-gate sin6->sin6_port = htons(MPATHD_PORT); 21980Sstevel@tonic-gate sin6->sin6_addr = loopback_addr; 21990Sstevel@tonic-gate len = sizeof (struct sockaddr_in6); 22000Sstevel@tonic-gate } 22010Sstevel@tonic-gate 22020Sstevel@tonic-gate ret = bind(sock, (struct sockaddr *)&laddr, len); 22030Sstevel@tonic-gate if (ret < 0) { 22040Sstevel@tonic-gate if (errno == EADDRINUSE) { 22050Sstevel@tonic-gate /* 22060Sstevel@tonic-gate * Another instance of mpathd may be already active. 22070Sstevel@tonic-gate */ 22080Sstevel@tonic-gate logerr("main: is another instance of in.mpathd " 22090Sstevel@tonic-gate "already active?\n"); 22100Sstevel@tonic-gate exit(1); 22110Sstevel@tonic-gate } else { 22120Sstevel@tonic-gate (void) close(sock); 22130Sstevel@tonic-gate return (-1); 22140Sstevel@tonic-gate } 22150Sstevel@tonic-gate } 22160Sstevel@tonic-gate if (listen(sock, 30) < 0) { 22170Sstevel@tonic-gate logperror("main: listen"); 22180Sstevel@tonic-gate exit(1); 22190Sstevel@tonic-gate } 22200Sstevel@tonic-gate if (poll_add(sock) == -1) { 22210Sstevel@tonic-gate (void) close(sock); 22220Sstevel@tonic-gate exit(1); 22230Sstevel@tonic-gate } 22240Sstevel@tonic-gate 22250Sstevel@tonic-gate return (sock); 22260Sstevel@tonic-gate } 22270Sstevel@tonic-gate 22280Sstevel@tonic-gate /* 22290Sstevel@tonic-gate * Table of commands and their expected size; used by loopback_cmd(). 22300Sstevel@tonic-gate */ 22310Sstevel@tonic-gate static struct { 22320Sstevel@tonic-gate const char *name; 22330Sstevel@tonic-gate unsigned int size; 22340Sstevel@tonic-gate } commands[] = { 22350Sstevel@tonic-gate { "MI_PING", sizeof (uint32_t) }, 22360Sstevel@tonic-gate { "MI_OFFLINE", sizeof (mi_offline_t) }, 22370Sstevel@tonic-gate { "MI_UNDO_OFFLINE", sizeof (mi_undo_offline_t) }, 22380Sstevel@tonic-gate { "MI_QUERY", sizeof (mi_query_t) } 22390Sstevel@tonic-gate }; 22400Sstevel@tonic-gate 22410Sstevel@tonic-gate /* 22428485SPeter.Memishian@Sun.COM * Commands received over the loopback interface come here (via libipmp). 22430Sstevel@tonic-gate */ 22440Sstevel@tonic-gate static void 22450Sstevel@tonic-gate loopback_cmd(int sock, int family) 22460Sstevel@tonic-gate { 22470Sstevel@tonic-gate int newfd; 22480Sstevel@tonic-gate ssize_t len; 22498485SPeter.Memishian@Sun.COM boolean_t is_priv = _B_FALSE; 22500Sstevel@tonic-gate struct sockaddr_storage peer; 22510Sstevel@tonic-gate struct sockaddr_in *peer_sin; 22520Sstevel@tonic-gate struct sockaddr_in6 *peer_sin6; 22530Sstevel@tonic-gate socklen_t peerlen; 22540Sstevel@tonic-gate union mi_commands mpi; 22550Sstevel@tonic-gate char abuf[INET6_ADDRSTRLEN]; 22560Sstevel@tonic-gate uint_t cmd; 22570Sstevel@tonic-gate int retval; 22580Sstevel@tonic-gate 22590Sstevel@tonic-gate peerlen = sizeof (peer); 22600Sstevel@tonic-gate newfd = accept(sock, (struct sockaddr *)&peer, &peerlen); 22610Sstevel@tonic-gate if (newfd < 0) { 22620Sstevel@tonic-gate logperror("loopback_cmd: accept"); 22630Sstevel@tonic-gate return; 22640Sstevel@tonic-gate } 22650Sstevel@tonic-gate 22660Sstevel@tonic-gate switch (family) { 22670Sstevel@tonic-gate case AF_INET: 22680Sstevel@tonic-gate /* 22690Sstevel@tonic-gate * Validate the address and port to make sure that 22700Sstevel@tonic-gate * non privileged processes don't connect and start 22710Sstevel@tonic-gate * talking to us. 22720Sstevel@tonic-gate */ 22730Sstevel@tonic-gate if (peerlen != sizeof (struct sockaddr_in)) { 22740Sstevel@tonic-gate logerr("loopback_cmd: AF_INET peerlen %d\n", peerlen); 22750Sstevel@tonic-gate (void) close(newfd); 22760Sstevel@tonic-gate return; 22770Sstevel@tonic-gate } 22780Sstevel@tonic-gate peer_sin = (struct sockaddr_in *)&peer; 22798485SPeter.Memishian@Sun.COM is_priv = ntohs(peer_sin->sin_port) < IPPORT_RESERVED; 22808485SPeter.Memishian@Sun.COM (void) inet_ntop(AF_INET, &peer_sin->sin_addr.s_addr, 22818485SPeter.Memishian@Sun.COM abuf, sizeof (abuf)); 22828485SPeter.Memishian@Sun.COM 22838485SPeter.Memishian@Sun.COM if (ntohl(peer_sin->sin_addr.s_addr) != INADDR_LOOPBACK) { 22840Sstevel@tonic-gate logerr("Attempt to connect from addr %s port %d\n", 22850Sstevel@tonic-gate abuf, ntohs(peer_sin->sin_port)); 22860Sstevel@tonic-gate (void) close(newfd); 22870Sstevel@tonic-gate return; 22880Sstevel@tonic-gate } 22890Sstevel@tonic-gate break; 22900Sstevel@tonic-gate 22910Sstevel@tonic-gate case AF_INET6: 22920Sstevel@tonic-gate if (peerlen != sizeof (struct sockaddr_in6)) { 22930Sstevel@tonic-gate logerr("loopback_cmd: AF_INET6 peerlen %d\n", peerlen); 22940Sstevel@tonic-gate (void) close(newfd); 22950Sstevel@tonic-gate return; 22960Sstevel@tonic-gate } 22970Sstevel@tonic-gate /* 22980Sstevel@tonic-gate * Validate the address and port to make sure that 22990Sstevel@tonic-gate * non privileged processes don't connect and start 23000Sstevel@tonic-gate * talking to us. 23010Sstevel@tonic-gate */ 23020Sstevel@tonic-gate peer_sin6 = (struct sockaddr_in6 *)&peer; 23038485SPeter.Memishian@Sun.COM is_priv = ntohs(peer_sin6->sin6_port) < IPPORT_RESERVED; 23048485SPeter.Memishian@Sun.COM (void) inet_ntop(AF_INET6, &peer_sin6->sin6_addr, abuf, 23058485SPeter.Memishian@Sun.COM sizeof (abuf)); 23068485SPeter.Memishian@Sun.COM if (!IN6_IS_ADDR_LOOPBACK(&peer_sin6->sin6_addr)) { 23070Sstevel@tonic-gate logerr("Attempt to connect from addr %s port %d\n", 23080Sstevel@tonic-gate abuf, ntohs(peer_sin6->sin6_port)); 23090Sstevel@tonic-gate (void) close(newfd); 23100Sstevel@tonic-gate return; 23110Sstevel@tonic-gate } 23120Sstevel@tonic-gate 23130Sstevel@tonic-gate default: 23140Sstevel@tonic-gate logdebug("loopback_cmd: family %d\n", family); 23150Sstevel@tonic-gate (void) close(newfd); 23160Sstevel@tonic-gate return; 23170Sstevel@tonic-gate } 23180Sstevel@tonic-gate 23190Sstevel@tonic-gate /* 23200Sstevel@tonic-gate * The sizeof the 'mpi' buffer corresponds to the maximum size of 23210Sstevel@tonic-gate * all supported commands 23220Sstevel@tonic-gate */ 23230Sstevel@tonic-gate len = read(newfd, &mpi, sizeof (mpi)); 23240Sstevel@tonic-gate 23250Sstevel@tonic-gate /* 23260Sstevel@tonic-gate * In theory, we can receive any sized message for a stream socket, 23270Sstevel@tonic-gate * but we don't expect that to happen for a small message over a 23280Sstevel@tonic-gate * loopback connection. 23290Sstevel@tonic-gate */ 23300Sstevel@tonic-gate if (len < sizeof (uint32_t)) { 23310Sstevel@tonic-gate logerr("loopback_cmd: bad command format or read returns " 23320Sstevel@tonic-gate "partial data %d\n", len); 23338485SPeter.Memishian@Sun.COM (void) close(newfd); 23348485SPeter.Memishian@Sun.COM return; 23350Sstevel@tonic-gate } 23360Sstevel@tonic-gate 23370Sstevel@tonic-gate cmd = mpi.mi_command; 23380Sstevel@tonic-gate if (cmd >= MI_NCMD) { 23390Sstevel@tonic-gate logerr("loopback_cmd: unknown command id `%d'\n", cmd); 23400Sstevel@tonic-gate (void) close(newfd); 23410Sstevel@tonic-gate return; 23420Sstevel@tonic-gate } 23430Sstevel@tonic-gate 23448485SPeter.Memishian@Sun.COM /* 23458485SPeter.Memishian@Sun.COM * Only MI_PING and MI_QUERY can come from unprivileged sources. 23468485SPeter.Memishian@Sun.COM */ 23478485SPeter.Memishian@Sun.COM if (!is_priv && (cmd != MI_QUERY && cmd != MI_PING)) { 23488485SPeter.Memishian@Sun.COM logerr("Unprivileged request from %s for privileged " 23498485SPeter.Memishian@Sun.COM "command %s\n", abuf, commands[cmd].name); 23508485SPeter.Memishian@Sun.COM (void) close(newfd); 23518485SPeter.Memishian@Sun.COM return; 23528485SPeter.Memishian@Sun.COM } 23538485SPeter.Memishian@Sun.COM 23540Sstevel@tonic-gate if (len < commands[cmd].size) { 23550Sstevel@tonic-gate logerr("loopback_cmd: short %s command (expected %d, got %d)\n", 23560Sstevel@tonic-gate commands[cmd].name, commands[cmd].size, len); 23570Sstevel@tonic-gate (void) close(newfd); 23580Sstevel@tonic-gate return; 23590Sstevel@tonic-gate } 23600Sstevel@tonic-gate 23610Sstevel@tonic-gate retval = process_cmd(newfd, &mpi); 23620Sstevel@tonic-gate if (retval != IPMP_SUCCESS) { 23630Sstevel@tonic-gate logerr("failed processing %s: %s\n", commands[cmd].name, 23640Sstevel@tonic-gate ipmp_errmsg(retval)); 23650Sstevel@tonic-gate } 23660Sstevel@tonic-gate (void) close(newfd); 23670Sstevel@tonic-gate } 23680Sstevel@tonic-gate 23690Sstevel@tonic-gate /* 23708485SPeter.Memishian@Sun.COM * Process the commands received via libipmp. 23710Sstevel@tonic-gate */ 23720Sstevel@tonic-gate static unsigned int 23730Sstevel@tonic-gate process_cmd(int newfd, union mi_commands *mpi) 23740Sstevel@tonic-gate { 23750Sstevel@tonic-gate struct phyint *pi; 23760Sstevel@tonic-gate struct mi_offline *mio; 23770Sstevel@tonic-gate struct mi_undo_offline *miu; 23788485SPeter.Memishian@Sun.COM unsigned int retval; 23798485SPeter.Memishian@Sun.COM 23808485SPeter.Memishian@Sun.COM switch (mpi->mi_command) { 23818485SPeter.Memishian@Sun.COM case MI_PING: 23828485SPeter.Memishian@Sun.COM return (send_result(newfd, IPMP_SUCCESS, 0)); 23838485SPeter.Memishian@Sun.COM 23840Sstevel@tonic-gate case MI_OFFLINE: 23850Sstevel@tonic-gate mio = &mpi->mi_ocmd; 23868485SPeter.Memishian@Sun.COM 23870Sstevel@tonic-gate pi = phyint_lookup(mio->mio_ifname); 23880Sstevel@tonic-gate if (pi == NULL) 23898485SPeter.Memishian@Sun.COM return (send_result(newfd, IPMP_EUNKIF, 0)); 23908485SPeter.Memishian@Sun.COM 23918485SPeter.Memishian@Sun.COM retval = phyint_offline(pi, mio->mio_min_redundancy); 23928485SPeter.Memishian@Sun.COM if (retval == IPMP_FAILURE) 23930Sstevel@tonic-gate return (send_result(newfd, IPMP_FAILURE, errno)); 23948485SPeter.Memishian@Sun.COM 23958485SPeter.Memishian@Sun.COM return (send_result(newfd, retval, 0)); 23960Sstevel@tonic-gate 23970Sstevel@tonic-gate case MI_UNDO_OFFLINE: 23980Sstevel@tonic-gate miu = &mpi->mi_ucmd; 23998485SPeter.Memishian@Sun.COM 24000Sstevel@tonic-gate pi = phyint_lookup(miu->miu_ifname); 24018485SPeter.Memishian@Sun.COM if (pi == NULL) 24028485SPeter.Memishian@Sun.COM return (send_result(newfd, IPMP_EUNKIF, 0)); 24038485SPeter.Memishian@Sun.COM 24048485SPeter.Memishian@Sun.COM retval = phyint_undo_offline(pi); 24058485SPeter.Memishian@Sun.COM if (retval == IPMP_FAILURE) 24060Sstevel@tonic-gate return (send_result(newfd, IPMP_FAILURE, errno)); 24070Sstevel@tonic-gate 24088485SPeter.Memishian@Sun.COM return (send_result(newfd, retval, 0)); 24090Sstevel@tonic-gate 24100Sstevel@tonic-gate case MI_QUERY: 24110Sstevel@tonic-gate return (process_query(newfd, &mpi->mi_qcmd)); 24120Sstevel@tonic-gate 24130Sstevel@tonic-gate default: 24140Sstevel@tonic-gate break; 24150Sstevel@tonic-gate } 24160Sstevel@tonic-gate 24170Sstevel@tonic-gate return (send_result(newfd, IPMP_EPROTO, 0)); 24180Sstevel@tonic-gate } 24190Sstevel@tonic-gate 24200Sstevel@tonic-gate /* 24210Sstevel@tonic-gate * Process the query request pointed to by `miq' and send a reply on file 24220Sstevel@tonic-gate * descriptor `fd'. Returns an IPMP error code. 24230Sstevel@tonic-gate */ 24240Sstevel@tonic-gate static unsigned int 24250Sstevel@tonic-gate process_query(int fd, mi_query_t *miq) 24260Sstevel@tonic-gate { 24278485SPeter.Memishian@Sun.COM ipmp_addrinfo_t *adinfop; 24288485SPeter.Memishian@Sun.COM ipmp_addrinfolist_t *adlp; 24290Sstevel@tonic-gate ipmp_groupinfo_t *grinfop; 24300Sstevel@tonic-gate ipmp_groupinfolist_t *grlp; 24310Sstevel@tonic-gate ipmp_grouplist_t *grlistp; 24320Sstevel@tonic-gate ipmp_ifinfo_t *ifinfop; 24330Sstevel@tonic-gate ipmp_ifinfolist_t *iflp; 24340Sstevel@tonic-gate ipmp_snap_t *snap; 24350Sstevel@tonic-gate unsigned int retval; 24360Sstevel@tonic-gate 24370Sstevel@tonic-gate switch (miq->miq_inforeq) { 24388485SPeter.Memishian@Sun.COM case IPMP_ADDRINFO: 24398485SPeter.Memishian@Sun.COM retval = getgraddrinfo(miq->miq_grname, &miq->miq_addr, 24408485SPeter.Memishian@Sun.COM &adinfop); 24418485SPeter.Memishian@Sun.COM if (retval != IPMP_SUCCESS) 24428485SPeter.Memishian@Sun.COM return (send_result(fd, retval, errno)); 24438485SPeter.Memishian@Sun.COM 24448485SPeter.Memishian@Sun.COM retval = send_result(fd, IPMP_SUCCESS, 0); 24458485SPeter.Memishian@Sun.COM if (retval == IPMP_SUCCESS) 24468485SPeter.Memishian@Sun.COM retval = send_addrinfo(fd, adinfop); 24478485SPeter.Memishian@Sun.COM 24488485SPeter.Memishian@Sun.COM ipmp_freeaddrinfo(adinfop); 24498485SPeter.Memishian@Sun.COM return (retval); 24508485SPeter.Memishian@Sun.COM 24510Sstevel@tonic-gate case IPMP_GROUPLIST: 24520Sstevel@tonic-gate retval = getgrouplist(&grlistp); 24530Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 24540Sstevel@tonic-gate return (send_result(fd, retval, errno)); 24550Sstevel@tonic-gate 24560Sstevel@tonic-gate retval = send_result(fd, IPMP_SUCCESS, 0); 24570Sstevel@tonic-gate if (retval == IPMP_SUCCESS) 24580Sstevel@tonic-gate retval = send_grouplist(fd, grlistp); 24590Sstevel@tonic-gate 24600Sstevel@tonic-gate ipmp_freegrouplist(grlistp); 24610Sstevel@tonic-gate return (retval); 24620Sstevel@tonic-gate 24630Sstevel@tonic-gate case IPMP_GROUPINFO: 24640Sstevel@tonic-gate miq->miq_grname[LIFGRNAMSIZ - 1] = '\0'; 24658485SPeter.Memishian@Sun.COM retval = getgroupinfo(miq->miq_grname, &grinfop); 24660Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 24670Sstevel@tonic-gate return (send_result(fd, retval, errno)); 24680Sstevel@tonic-gate 24690Sstevel@tonic-gate retval = send_result(fd, IPMP_SUCCESS, 0); 24700Sstevel@tonic-gate if (retval == IPMP_SUCCESS) 24710Sstevel@tonic-gate retval = send_groupinfo(fd, grinfop); 24720Sstevel@tonic-gate 24730Sstevel@tonic-gate ipmp_freegroupinfo(grinfop); 24740Sstevel@tonic-gate return (retval); 24750Sstevel@tonic-gate 24760Sstevel@tonic-gate case IPMP_IFINFO: 24770Sstevel@tonic-gate miq->miq_ifname[LIFNAMSIZ - 1] = '\0'; 24780Sstevel@tonic-gate retval = getifinfo(miq->miq_ifname, &ifinfop); 24790Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 24800Sstevel@tonic-gate return (send_result(fd, retval, errno)); 24810Sstevel@tonic-gate 24820Sstevel@tonic-gate retval = send_result(fd, IPMP_SUCCESS, 0); 24830Sstevel@tonic-gate if (retval == IPMP_SUCCESS) 24840Sstevel@tonic-gate retval = send_ifinfo(fd, ifinfop); 24850Sstevel@tonic-gate 24860Sstevel@tonic-gate ipmp_freeifinfo(ifinfop); 24870Sstevel@tonic-gate return (retval); 24880Sstevel@tonic-gate 24890Sstevel@tonic-gate case IPMP_SNAP: 24908485SPeter.Memishian@Sun.COM /* 24918485SPeter.Memishian@Sun.COM * Before taking the snapshot, sync with the kernel. 24928485SPeter.Memishian@Sun.COM */ 24938485SPeter.Memishian@Sun.COM initifs(); 24948485SPeter.Memishian@Sun.COM 24950Sstevel@tonic-gate retval = getsnap(&snap); 24960Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 24970Sstevel@tonic-gate return (send_result(fd, retval, errno)); 24980Sstevel@tonic-gate 24990Sstevel@tonic-gate retval = send_result(fd, IPMP_SUCCESS, 0); 25000Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 25010Sstevel@tonic-gate goto out; 25020Sstevel@tonic-gate 25030Sstevel@tonic-gate retval = ipmp_writetlv(fd, IPMP_SNAP, sizeof (*snap), snap); 25040Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 25050Sstevel@tonic-gate goto out; 25060Sstevel@tonic-gate 25070Sstevel@tonic-gate retval = send_grouplist(fd, snap->sn_grlistp); 25080Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 25090Sstevel@tonic-gate goto out; 25100Sstevel@tonic-gate 25110Sstevel@tonic-gate iflp = snap->sn_ifinfolistp; 25120Sstevel@tonic-gate for (; iflp != NULL; iflp = iflp->ifl_next) { 25130Sstevel@tonic-gate retval = send_ifinfo(fd, iflp->ifl_ifinfop); 25140Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 25150Sstevel@tonic-gate goto out; 25160Sstevel@tonic-gate } 25170Sstevel@tonic-gate 25180Sstevel@tonic-gate grlp = snap->sn_grinfolistp; 25190Sstevel@tonic-gate for (; grlp != NULL; grlp = grlp->grl_next) { 25200Sstevel@tonic-gate retval = send_groupinfo(fd, grlp->grl_grinfop); 25210Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 25220Sstevel@tonic-gate goto out; 25230Sstevel@tonic-gate } 25248485SPeter.Memishian@Sun.COM 25258485SPeter.Memishian@Sun.COM adlp = snap->sn_adinfolistp; 25268485SPeter.Memishian@Sun.COM for (; adlp != NULL; adlp = adlp->adl_next) { 25278485SPeter.Memishian@Sun.COM retval = send_addrinfo(fd, adlp->adl_adinfop); 25288485SPeter.Memishian@Sun.COM if (retval != IPMP_SUCCESS) 25298485SPeter.Memishian@Sun.COM goto out; 25308485SPeter.Memishian@Sun.COM } 25310Sstevel@tonic-gate out: 25320Sstevel@tonic-gate ipmp_snap_free(snap); 25330Sstevel@tonic-gate return (retval); 25340Sstevel@tonic-gate 25350Sstevel@tonic-gate default: 25360Sstevel@tonic-gate break; 25370Sstevel@tonic-gate 25380Sstevel@tonic-gate } 25390Sstevel@tonic-gate return (send_result(fd, IPMP_EPROTO, 0)); 25400Sstevel@tonic-gate } 25410Sstevel@tonic-gate 25420Sstevel@tonic-gate /* 25430Sstevel@tonic-gate * Send the group information pointed to by `grinfop' on file descriptor `fd'. 25440Sstevel@tonic-gate * Returns an IPMP error code. 25450Sstevel@tonic-gate */ 25460Sstevel@tonic-gate static unsigned int 25470Sstevel@tonic-gate send_groupinfo(int fd, ipmp_groupinfo_t *grinfop) 25480Sstevel@tonic-gate { 25490Sstevel@tonic-gate ipmp_iflist_t *iflistp = grinfop->gr_iflistp; 25508485SPeter.Memishian@Sun.COM ipmp_addrlist_t *adlistp = grinfop->gr_adlistp; 25510Sstevel@tonic-gate unsigned int retval; 25520Sstevel@tonic-gate 25530Sstevel@tonic-gate retval = ipmp_writetlv(fd, IPMP_GROUPINFO, sizeof (*grinfop), grinfop); 25540Sstevel@tonic-gate if (retval != IPMP_SUCCESS) 25550Sstevel@tonic-gate return (retval); 25560Sstevel@tonic-gate 25578485SPeter.Memishian@Sun.COM retval = ipmp_writetlv(fd, IPMP_IFLIST, 25588485SPeter.Memishian@Sun.COM IPMP_IFLIST_SIZE(iflistp->il_nif), iflistp); 25598485SPeter.Memishian@Sun.COM if (retval != IPMP_SUCCESS) 25608485SPeter.Memishian@Sun.COM return (retval); 25618485SPeter.Memishian@Sun.COM 25628485SPeter.Memishian@Sun.COM return (ipmp_writetlv(fd, IPMP_ADDRLIST, 25638485SPeter.Memishian@Sun.COM IPMP_ADDRLIST_SIZE(adlistp->al_naddr), adlistp)); 25640Sstevel@tonic-gate } 25650Sstevel@tonic-gate 25660Sstevel@tonic-gate /* 25670Sstevel@tonic-gate * Send the interface information pointed to by `ifinfop' on file descriptor 25680Sstevel@tonic-gate * `fd'. Returns an IPMP error code. 25690Sstevel@tonic-gate */ 25700Sstevel@tonic-gate static unsigned int 25710Sstevel@tonic-gate send_ifinfo(int fd, ipmp_ifinfo_t *ifinfop) 25720Sstevel@tonic-gate { 25738485SPeter.Memishian@Sun.COM ipmp_addrlist_t *adlist4p = ifinfop->if_targinfo4.it_targlistp; 25748485SPeter.Memishian@Sun.COM ipmp_addrlist_t *adlist6p = ifinfop->if_targinfo6.it_targlistp; 25758485SPeter.Memishian@Sun.COM unsigned int retval; 25768485SPeter.Memishian@Sun.COM 25778485SPeter.Memishian@Sun.COM retval = ipmp_writetlv(fd, IPMP_IFINFO, sizeof (*ifinfop), ifinfop); 25788485SPeter.Memishian@Sun.COM if (retval != IPMP_SUCCESS) 25798485SPeter.Memishian@Sun.COM return (retval); 25808485SPeter.Memishian@Sun.COM 25818485SPeter.Memishian@Sun.COM retval = ipmp_writetlv(fd, IPMP_ADDRLIST, 25828485SPeter.Memishian@Sun.COM IPMP_ADDRLIST_SIZE(adlist4p->al_naddr), adlist4p); 25838485SPeter.Memishian@Sun.COM if (retval != IPMP_SUCCESS) 25848485SPeter.Memishian@Sun.COM return (retval); 25858485SPeter.Memishian@Sun.COM 25868485SPeter.Memishian@Sun.COM return (ipmp_writetlv(fd, IPMP_ADDRLIST, 25878485SPeter.Memishian@Sun.COM IPMP_ADDRLIST_SIZE(adlist6p->al_naddr), adlist6p)); 25888485SPeter.Memishian@Sun.COM } 25898485SPeter.Memishian@Sun.COM 25908485SPeter.Memishian@Sun.COM /* 25918485SPeter.Memishian@Sun.COM * Send the address information pointed to by `adinfop' on file descriptor 25928485SPeter.Memishian@Sun.COM * `fd'. Returns an IPMP error code. 25938485SPeter.Memishian@Sun.COM */ 25948485SPeter.Memishian@Sun.COM static unsigned int 25958485SPeter.Memishian@Sun.COM send_addrinfo(int fd, ipmp_addrinfo_t *adinfop) 25968485SPeter.Memishian@Sun.COM { 25978485SPeter.Memishian@Sun.COM return (ipmp_writetlv(fd, IPMP_ADDRINFO, sizeof (*adinfop), adinfop)); 25980Sstevel@tonic-gate } 25990Sstevel@tonic-gate 26000Sstevel@tonic-gate /* 26010Sstevel@tonic-gate * Send the group list pointed to by `grlistp' on file descriptor `fd'. 26020Sstevel@tonic-gate * Returns an IPMP error code. 26030Sstevel@tonic-gate */ 26040Sstevel@tonic-gate static unsigned int 26050Sstevel@tonic-gate send_grouplist(int fd, ipmp_grouplist_t *grlistp) 26060Sstevel@tonic-gate { 26070Sstevel@tonic-gate return (ipmp_writetlv(fd, IPMP_GROUPLIST, 26080Sstevel@tonic-gate IPMP_GROUPLIST_SIZE(grlistp->gl_ngroup), grlistp)); 26090Sstevel@tonic-gate } 26100Sstevel@tonic-gate 26110Sstevel@tonic-gate /* 26120Sstevel@tonic-gate * Initialize an mi_result_t structure using `error' and `syserror' and 26130Sstevel@tonic-gate * send it on file descriptor `fd'. Returns an IPMP error code. 26140Sstevel@tonic-gate */ 26150Sstevel@tonic-gate static unsigned int 26160Sstevel@tonic-gate send_result(int fd, unsigned int error, int syserror) 26170Sstevel@tonic-gate { 26180Sstevel@tonic-gate mi_result_t me; 26190Sstevel@tonic-gate 26200Sstevel@tonic-gate me.me_mpathd_error = error; 26210Sstevel@tonic-gate if (error == IPMP_FAILURE) 26220Sstevel@tonic-gate me.me_sys_error = syserror; 26230Sstevel@tonic-gate else 26240Sstevel@tonic-gate me.me_sys_error = 0; 26250Sstevel@tonic-gate 26260Sstevel@tonic-gate return (ipmp_write(fd, &me, sizeof (me))); 26270Sstevel@tonic-gate } 26280Sstevel@tonic-gate 26290Sstevel@tonic-gate /* 26300Sstevel@tonic-gate * Daemonize the process. 26310Sstevel@tonic-gate */ 26320Sstevel@tonic-gate static boolean_t 26330Sstevel@tonic-gate daemonize(void) 26340Sstevel@tonic-gate { 26350Sstevel@tonic-gate switch (fork()) { 26360Sstevel@tonic-gate case -1: 26370Sstevel@tonic-gate return (_B_FALSE); 26380Sstevel@tonic-gate 26390Sstevel@tonic-gate case 0: 26400Sstevel@tonic-gate /* 26410Sstevel@tonic-gate * Lose our controlling terminal, and become both a session 26420Sstevel@tonic-gate * leader and a process group leader. 26430Sstevel@tonic-gate */ 26440Sstevel@tonic-gate if (setsid() == -1) 26450Sstevel@tonic-gate return (_B_FALSE); 26460Sstevel@tonic-gate 26470Sstevel@tonic-gate /* 26480Sstevel@tonic-gate * Under POSIX, a session leader can accidentally (through 26490Sstevel@tonic-gate * open(2)) acquire a controlling terminal if it does not 26500Sstevel@tonic-gate * have one. Just to be safe, fork() again so we are not a 26510Sstevel@tonic-gate * session leader. 26520Sstevel@tonic-gate */ 26530Sstevel@tonic-gate switch (fork()) { 26540Sstevel@tonic-gate case -1: 26550Sstevel@tonic-gate return (_B_FALSE); 26560Sstevel@tonic-gate 26570Sstevel@tonic-gate case 0: 26580Sstevel@tonic-gate (void) chdir("/"); 26590Sstevel@tonic-gate (void) umask(022); 26600Sstevel@tonic-gate (void) fdwalk(closefunc, NULL); 26610Sstevel@tonic-gate break; 26620Sstevel@tonic-gate 26630Sstevel@tonic-gate default: 26640Sstevel@tonic-gate _exit(EXIT_SUCCESS); 26650Sstevel@tonic-gate } 26660Sstevel@tonic-gate break; 26670Sstevel@tonic-gate 26680Sstevel@tonic-gate default: 26690Sstevel@tonic-gate _exit(EXIT_SUCCESS); 26700Sstevel@tonic-gate } 26710Sstevel@tonic-gate 26720Sstevel@tonic-gate return (_B_TRUE); 26730Sstevel@tonic-gate } 26740Sstevel@tonic-gate 26750Sstevel@tonic-gate /* 26760Sstevel@tonic-gate * The parent has created some fds before forking on purpose, keep them open. 26770Sstevel@tonic-gate */ 26780Sstevel@tonic-gate static int 26790Sstevel@tonic-gate closefunc(void *not_used, int fd) 26800Sstevel@tonic-gate /* ARGSUSED */ 26810Sstevel@tonic-gate { 26820Sstevel@tonic-gate if (fd != lsock_v4 && fd != lsock_v6) 26830Sstevel@tonic-gate (void) close(fd); 26840Sstevel@tonic-gate return (0); 26850Sstevel@tonic-gate } 26860Sstevel@tonic-gate 26870Sstevel@tonic-gate /* LOGGER */ 26880Sstevel@tonic-gate 26890Sstevel@tonic-gate #include <syslog.h> 26900Sstevel@tonic-gate 26910Sstevel@tonic-gate /* 26920Sstevel@tonic-gate * Logging routines. All routines log to syslog, unless the daemon is 26930Sstevel@tonic-gate * running in the foreground, in which case the logging goes to stderr. 26940Sstevel@tonic-gate * 26950Sstevel@tonic-gate * The following routines are available: 26960Sstevel@tonic-gate * 26970Sstevel@tonic-gate * logdebug(): A printf-like function for outputting debug messages 26980Sstevel@tonic-gate * (messages at LOG_DEBUG) that are only of use to developers. 26990Sstevel@tonic-gate * 27000Sstevel@tonic-gate * logtrace(): A printf-like function for outputting tracing messages 27010Sstevel@tonic-gate * (messages at LOG_INFO) from the daemon. This is typically used 27020Sstevel@tonic-gate * to log the receipt of interesting network-related conditions. 27030Sstevel@tonic-gate * 27040Sstevel@tonic-gate * logerr(): A printf-like function for outputting error messages 27050Sstevel@tonic-gate * (messages at LOG_ERR) from the daemon. 27060Sstevel@tonic-gate * 27070Sstevel@tonic-gate * logperror*(): A set of functions used to output error messages 27080Sstevel@tonic-gate * (messages at LOG_ERR); these automatically append strerror(errno) 27090Sstevel@tonic-gate * and a newline to the message passed to them. 27100Sstevel@tonic-gate * 27110Sstevel@tonic-gate * NOTE: since the logging functions write to syslog, the messages passed 27120Sstevel@tonic-gate * to them are not eligible for localization. Thus, gettext() must 27130Sstevel@tonic-gate * *not* be used. 27140Sstevel@tonic-gate */ 27150Sstevel@tonic-gate 27160Sstevel@tonic-gate static int logging = 0; 27170Sstevel@tonic-gate 27180Sstevel@tonic-gate static void 27190Sstevel@tonic-gate initlog(void) 27200Sstevel@tonic-gate { 27210Sstevel@tonic-gate logging++; 27226578Smeem openlog("in.mpathd", LOG_PID, LOG_DAEMON); 27230Sstevel@tonic-gate } 27240Sstevel@tonic-gate 27256578Smeem /* PRINTFLIKE2 */ 27260Sstevel@tonic-gate void 27276578Smeem logmsg(int pri, const char *fmt, ...) 27280Sstevel@tonic-gate { 27290Sstevel@tonic-gate va_list ap; 27300Sstevel@tonic-gate 27310Sstevel@tonic-gate va_start(ap, fmt); 27320Sstevel@tonic-gate 27330Sstevel@tonic-gate if (logging) 27346578Smeem vsyslog(pri, fmt, ap); 27350Sstevel@tonic-gate else 27360Sstevel@tonic-gate (void) vfprintf(stderr, fmt, ap); 27370Sstevel@tonic-gate va_end(ap); 27380Sstevel@tonic-gate } 27390Sstevel@tonic-gate 27400Sstevel@tonic-gate /* PRINTFLIKE1 */ 27410Sstevel@tonic-gate void 27426578Smeem logperror(const char *str) 27430Sstevel@tonic-gate { 27440Sstevel@tonic-gate if (logging) 27450Sstevel@tonic-gate syslog(LOG_ERR, "%s: %m\n", str); 27460Sstevel@tonic-gate else 27470Sstevel@tonic-gate (void) fprintf(stderr, "%s: %s\n", str, strerror(errno)); 27480Sstevel@tonic-gate } 27490Sstevel@tonic-gate 27500Sstevel@tonic-gate void 27516578Smeem logperror_pii(struct phyint_instance *pii, const char *str) 27520Sstevel@tonic-gate { 27530Sstevel@tonic-gate if (logging) { 27540Sstevel@tonic-gate syslog(LOG_ERR, "%s (%s %s): %m\n", 27550Sstevel@tonic-gate str, AF_STR(pii->pii_af), pii->pii_phyint->pi_name); 27560Sstevel@tonic-gate } else { 27570Sstevel@tonic-gate (void) fprintf(stderr, "%s (%s %s): %s\n", 27580Sstevel@tonic-gate str, AF_STR(pii->pii_af), pii->pii_phyint->pi_name, 27590Sstevel@tonic-gate strerror(errno)); 27600Sstevel@tonic-gate } 27610Sstevel@tonic-gate } 27620Sstevel@tonic-gate 27630Sstevel@tonic-gate void 27646578Smeem logperror_li(struct logint *li, const char *str) 27650Sstevel@tonic-gate { 27660Sstevel@tonic-gate struct phyint_instance *pii = li->li_phyint_inst; 27670Sstevel@tonic-gate 27680Sstevel@tonic-gate if (logging) { 27690Sstevel@tonic-gate syslog(LOG_ERR, "%s (%s %s): %m\n", 27700Sstevel@tonic-gate str, AF_STR(pii->pii_af), li->li_name); 27710Sstevel@tonic-gate } else { 27720Sstevel@tonic-gate (void) fprintf(stderr, "%s (%s %s): %s\n", 27730Sstevel@tonic-gate str, AF_STR(pii->pii_af), li->li_name, 27740Sstevel@tonic-gate strerror(errno)); 27750Sstevel@tonic-gate } 27760Sstevel@tonic-gate } 27770Sstevel@tonic-gate 27780Sstevel@tonic-gate void 27790Sstevel@tonic-gate close_probe_socket(struct phyint_instance *pii, boolean_t polled) 27800Sstevel@tonic-gate { 27810Sstevel@tonic-gate if (polled) 27820Sstevel@tonic-gate (void) poll_remove(pii->pii_probe_sock); 27830Sstevel@tonic-gate (void) close(pii->pii_probe_sock); 27840Sstevel@tonic-gate pii->pii_probe_sock = -1; 27850Sstevel@tonic-gate pii->pii_basetime_inited = 0; 27860Sstevel@tonic-gate } 27878485SPeter.Memishian@Sun.COM 27888485SPeter.Memishian@Sun.COM boolean_t 27898485SPeter.Memishian@Sun.COM addrlist_add(addrlist_t **addrsp, const char *name, uint64_t flags, 27908485SPeter.Memishian@Sun.COM struct sockaddr_storage *ssp) 27918485SPeter.Memishian@Sun.COM { 27928485SPeter.Memishian@Sun.COM addrlist_t *addrp; 27938485SPeter.Memishian@Sun.COM 27948485SPeter.Memishian@Sun.COM if ((addrp = malloc(sizeof (addrlist_t))) == NULL) 27958485SPeter.Memishian@Sun.COM return (_B_FALSE); 27968485SPeter.Memishian@Sun.COM 27978485SPeter.Memishian@Sun.COM (void) strlcpy(addrp->al_name, name, LIFNAMSIZ); 27988485SPeter.Memishian@Sun.COM addrp->al_flags = flags; 27998485SPeter.Memishian@Sun.COM addrp->al_addr = *ssp; 28008485SPeter.Memishian@Sun.COM addrp->al_next = *addrsp; 28018485SPeter.Memishian@Sun.COM *addrsp = addrp; 28028485SPeter.Memishian@Sun.COM return (_B_TRUE); 28038485SPeter.Memishian@Sun.COM } 28048485SPeter.Memishian@Sun.COM 28058485SPeter.Memishian@Sun.COM void 28068485SPeter.Memishian@Sun.COM addrlist_free(addrlist_t **addrsp) 28078485SPeter.Memishian@Sun.COM { 28088485SPeter.Memishian@Sun.COM addrlist_t *addrp, *next_addrp; 28098485SPeter.Memishian@Sun.COM 28108485SPeter.Memishian@Sun.COM for (addrp = *addrsp; addrp != NULL; addrp = next_addrp) { 28118485SPeter.Memishian@Sun.COM next_addrp = addrp->al_next; 28128485SPeter.Memishian@Sun.COM free(addrp); 28138485SPeter.Memishian@Sun.COM } 28148485SPeter.Memishian@Sun.COM *addrsp = NULL; 28158485SPeter.Memishian@Sun.COM } 2816*8865SJonathan.Anderson@Sun.COM 2817*8865SJonathan.Anderson@Sun.COM /* 2818*8865SJonathan.Anderson@Sun.COM * Send down a T_OPTMGMT_REQ to ip asking for all data in the various 2819*8865SJonathan.Anderson@Sun.COM * tables defined by mib2.h. Pass the table information returned to the 2820*8865SJonathan.Anderson@Sun.COM * supplied function. 2821*8865SJonathan.Anderson@Sun.COM */ 2822*8865SJonathan.Anderson@Sun.COM static int 2823*8865SJonathan.Anderson@Sun.COM mibwalk(void (*proc)(mib_item_t *)) 2824*8865SJonathan.Anderson@Sun.COM { 2825*8865SJonathan.Anderson@Sun.COM mib_item_t *head_item = NULL; 2826*8865SJonathan.Anderson@Sun.COM mib_item_t *last_item = NULL; 2827*8865SJonathan.Anderson@Sun.COM mib_item_t *tmp; 2828*8865SJonathan.Anderson@Sun.COM struct strbuf ctlbuf, databuf; 2829*8865SJonathan.Anderson@Sun.COM int flags; 2830*8865SJonathan.Anderson@Sun.COM int rval; 2831*8865SJonathan.Anderson@Sun.COM uintptr_t buf[512 / sizeof (uintptr_t)]; 2832*8865SJonathan.Anderson@Sun.COM struct T_optmgmt_req *tor = (struct T_optmgmt_req *)buf; 2833*8865SJonathan.Anderson@Sun.COM struct T_optmgmt_ack *toa = (struct T_optmgmt_ack *)buf; 2834*8865SJonathan.Anderson@Sun.COM struct T_error_ack *tea = (struct T_error_ack *)buf; 2835*8865SJonathan.Anderson@Sun.COM struct opthdr *req, *optp; 2836*8865SJonathan.Anderson@Sun.COM int status = -1; 2837*8865SJonathan.Anderson@Sun.COM 2838*8865SJonathan.Anderson@Sun.COM if (mibfd == -1) { 2839*8865SJonathan.Anderson@Sun.COM if ((mibfd = open("/dev/ip", O_RDWR)) < 0) { 2840*8865SJonathan.Anderson@Sun.COM logperror("mibwalk(): ip open"); 2841*8865SJonathan.Anderson@Sun.COM return (status); 2842*8865SJonathan.Anderson@Sun.COM } 2843*8865SJonathan.Anderson@Sun.COM } 2844*8865SJonathan.Anderson@Sun.COM 2845*8865SJonathan.Anderson@Sun.COM tor->PRIM_type = T_SVR4_OPTMGMT_REQ; 2846*8865SJonathan.Anderson@Sun.COM tor->OPT_offset = sizeof (struct T_optmgmt_req); 2847*8865SJonathan.Anderson@Sun.COM tor->OPT_length = sizeof (struct opthdr); 2848*8865SJonathan.Anderson@Sun.COM tor->MGMT_flags = T_CURRENT; 2849*8865SJonathan.Anderson@Sun.COM 2850*8865SJonathan.Anderson@Sun.COM /* 2851*8865SJonathan.Anderson@Sun.COM * Note: we use the special level value below so that IP will return 2852*8865SJonathan.Anderson@Sun.COM * us information concerning IRE_MARK_TESTHIDDEN routes. 2853*8865SJonathan.Anderson@Sun.COM */ 2854*8865SJonathan.Anderson@Sun.COM req = (struct opthdr *)&tor[1]; 2855*8865SJonathan.Anderson@Sun.COM req->level = EXPER_IP_AND_TESTHIDDEN; 2856*8865SJonathan.Anderson@Sun.COM req->name = 0; 2857*8865SJonathan.Anderson@Sun.COM req->len = 0; 2858*8865SJonathan.Anderson@Sun.COM 2859*8865SJonathan.Anderson@Sun.COM ctlbuf.buf = (char *)&buf; 2860*8865SJonathan.Anderson@Sun.COM ctlbuf.len = tor->OPT_length + tor->OPT_offset; 2861*8865SJonathan.Anderson@Sun.COM 2862*8865SJonathan.Anderson@Sun.COM if (putmsg(mibfd, &ctlbuf, NULL, 0) == -1) { 2863*8865SJonathan.Anderson@Sun.COM logperror("mibwalk(): putmsg(ctl)"); 2864*8865SJonathan.Anderson@Sun.COM return (status); 2865*8865SJonathan.Anderson@Sun.COM } 2866*8865SJonathan.Anderson@Sun.COM 2867*8865SJonathan.Anderson@Sun.COM /* 2868*8865SJonathan.Anderson@Sun.COM * The response consists of multiple T_OPTMGMT_ACK msgs, 1 msg for 2869*8865SJonathan.Anderson@Sun.COM * each table defined in mib2.h. Each T_OPTMGMT_ACK msg contains 2870*8865SJonathan.Anderson@Sun.COM * a control and data part. The control part contains a struct 2871*8865SJonathan.Anderson@Sun.COM * T_optmgmt_ack followed by a struct opthdr. The 'opthdr' identifies 2872*8865SJonathan.Anderson@Sun.COM * the level, name and length of the data in the data part. The 2873*8865SJonathan.Anderson@Sun.COM * data part contains the actual table data. The last message 2874*8865SJonathan.Anderson@Sun.COM * is an end-of-data (EOD), consisting of a T_OPTMGMT_ACK and a 2875*8865SJonathan.Anderson@Sun.COM * single option with zero optlen. 2876*8865SJonathan.Anderson@Sun.COM */ 2877*8865SJonathan.Anderson@Sun.COM for (;;) { 2878*8865SJonathan.Anderson@Sun.COM errno = flags = 0; 2879*8865SJonathan.Anderson@Sun.COM ctlbuf.maxlen = sizeof (buf); 2880*8865SJonathan.Anderson@Sun.COM rval = getmsg(mibfd, &ctlbuf, NULL, &flags); 2881*8865SJonathan.Anderson@Sun.COM if (rval & MORECTL || rval < 0) { 2882*8865SJonathan.Anderson@Sun.COM if (errno == EINTR) 2883*8865SJonathan.Anderson@Sun.COM continue; 2884*8865SJonathan.Anderson@Sun.COM logerr("mibwalk(): getmsg(ctl) ret: %d err: %d\n", 2885*8865SJonathan.Anderson@Sun.COM rval, errno); 2886*8865SJonathan.Anderson@Sun.COM goto error; 2887*8865SJonathan.Anderson@Sun.COM } 2888*8865SJonathan.Anderson@Sun.COM if (ctlbuf.len < sizeof (t_scalar_t)) { 2889*8865SJonathan.Anderson@Sun.COM logerr("mibwalk(): ctlbuf.len %d\n", ctlbuf.len); 2890*8865SJonathan.Anderson@Sun.COM goto error; 2891*8865SJonathan.Anderson@Sun.COM } 2892*8865SJonathan.Anderson@Sun.COM 2893*8865SJonathan.Anderson@Sun.COM switch (toa->PRIM_type) { 2894*8865SJonathan.Anderson@Sun.COM case T_ERROR_ACK: 2895*8865SJonathan.Anderson@Sun.COM if (ctlbuf.len < sizeof (struct T_error_ack)) { 2896*8865SJonathan.Anderson@Sun.COM logerr("mibwalk(): T_ERROR_ACK ctlbuf " 2897*8865SJonathan.Anderson@Sun.COM "too short: %d\n", ctlbuf.len); 2898*8865SJonathan.Anderson@Sun.COM goto error; 2899*8865SJonathan.Anderson@Sun.COM } 2900*8865SJonathan.Anderson@Sun.COM logerr("mibwalk(): T_ERROR_ACK: TLI_err = 0x%lx: %s\n" 2901*8865SJonathan.Anderson@Sun.COM " UNIX_err = 0x%lx\n", tea->TLI_error, 2902*8865SJonathan.Anderson@Sun.COM t_strerror(tea->TLI_error), tea->UNIX_error); 2903*8865SJonathan.Anderson@Sun.COM goto error; 2904*8865SJonathan.Anderson@Sun.COM 2905*8865SJonathan.Anderson@Sun.COM case T_OPTMGMT_ACK: 2906*8865SJonathan.Anderson@Sun.COM optp = (struct opthdr *)&toa[1]; 2907*8865SJonathan.Anderson@Sun.COM if (ctlbuf.len < (sizeof (struct T_optmgmt_ack) + 2908*8865SJonathan.Anderson@Sun.COM sizeof (struct opthdr))) { 2909*8865SJonathan.Anderson@Sun.COM logerr("mibwalk(): T_OPTMGMT_ACK ctlbuf too " 2910*8865SJonathan.Anderson@Sun.COM "short: %d\n", ctlbuf.len); 2911*8865SJonathan.Anderson@Sun.COM goto error; 2912*8865SJonathan.Anderson@Sun.COM } 2913*8865SJonathan.Anderson@Sun.COM if (toa->MGMT_flags != T_SUCCESS) { 2914*8865SJonathan.Anderson@Sun.COM logerr("mibwalk(): MGMT_flags != T_SUCCESS: " 2915*8865SJonathan.Anderson@Sun.COM "0x%lx\n", toa->MGMT_flags); 2916*8865SJonathan.Anderson@Sun.COM goto error; 2917*8865SJonathan.Anderson@Sun.COM } 2918*8865SJonathan.Anderson@Sun.COM break; 2919*8865SJonathan.Anderson@Sun.COM 2920*8865SJonathan.Anderson@Sun.COM default: 2921*8865SJonathan.Anderson@Sun.COM goto error; 2922*8865SJonathan.Anderson@Sun.COM } 2923*8865SJonathan.Anderson@Sun.COM /* The following assert also implies MGMT_flags == T_SUCCESS */ 2924*8865SJonathan.Anderson@Sun.COM assert(toa->PRIM_type == T_OPTMGMT_ACK); 2925*8865SJonathan.Anderson@Sun.COM 2926*8865SJonathan.Anderson@Sun.COM /* 2927*8865SJonathan.Anderson@Sun.COM * We have reached the end of this T_OPTMGMT_ACK 2928*8865SJonathan.Anderson@Sun.COM * message. If this is the last message i.e EOD, 2929*8865SJonathan.Anderson@Sun.COM * break, else process the next T_OPTMGMT_ACK msg. 2930*8865SJonathan.Anderson@Sun.COM */ 2931*8865SJonathan.Anderson@Sun.COM if (rval == 0) { 2932*8865SJonathan.Anderson@Sun.COM if (optp->len == 0 && optp->name == 0 && 2933*8865SJonathan.Anderson@Sun.COM optp->level == 0) { 2934*8865SJonathan.Anderson@Sun.COM /* This is the EOD message. */ 2935*8865SJonathan.Anderson@Sun.COM break; 2936*8865SJonathan.Anderson@Sun.COM } 2937*8865SJonathan.Anderson@Sun.COM /* Not EOD but no data to retrieve */ 2938*8865SJonathan.Anderson@Sun.COM continue; 2939*8865SJonathan.Anderson@Sun.COM } 2940*8865SJonathan.Anderson@Sun.COM 2941*8865SJonathan.Anderson@Sun.COM /* 2942*8865SJonathan.Anderson@Sun.COM * We should only be here if MOREDATA was set. 2943*8865SJonathan.Anderson@Sun.COM * Allocate an empty mib_item_t and link into the list 2944*8865SJonathan.Anderson@Sun.COM * of MIB items. 2945*8865SJonathan.Anderson@Sun.COM */ 2946*8865SJonathan.Anderson@Sun.COM if ((tmp = malloc(sizeof (*tmp))) == NULL) { 2947*8865SJonathan.Anderson@Sun.COM logperror("mibwalk(): malloc() failed."); 2948*8865SJonathan.Anderson@Sun.COM goto error; 2949*8865SJonathan.Anderson@Sun.COM } 2950*8865SJonathan.Anderson@Sun.COM if (last_item != NULL) 2951*8865SJonathan.Anderson@Sun.COM last_item->mi_next = tmp; 2952*8865SJonathan.Anderson@Sun.COM else 2953*8865SJonathan.Anderson@Sun.COM head_item = tmp; 2954*8865SJonathan.Anderson@Sun.COM last_item = tmp; 2955*8865SJonathan.Anderson@Sun.COM last_item->mi_next = NULL; 2956*8865SJonathan.Anderson@Sun.COM last_item->mi_opthdr = *optp; 2957*8865SJonathan.Anderson@Sun.COM last_item->mi_valp = malloc(optp->len); 2958*8865SJonathan.Anderson@Sun.COM if (last_item->mi_valp == NULL) { 2959*8865SJonathan.Anderson@Sun.COM logperror("mibwalk(): malloc() failed."); 2960*8865SJonathan.Anderson@Sun.COM goto error; 2961*8865SJonathan.Anderson@Sun.COM } 2962*8865SJonathan.Anderson@Sun.COM 2963*8865SJonathan.Anderson@Sun.COM databuf.maxlen = last_item->mi_opthdr.len; 2964*8865SJonathan.Anderson@Sun.COM databuf.buf = (char *)last_item->mi_valp; 2965*8865SJonathan.Anderson@Sun.COM databuf.len = 0; 2966*8865SJonathan.Anderson@Sun.COM 2967*8865SJonathan.Anderson@Sun.COM /* Retrieve the actual MIB data */ 2968*8865SJonathan.Anderson@Sun.COM for (;;) { 2969*8865SJonathan.Anderson@Sun.COM flags = 0; 2970*8865SJonathan.Anderson@Sun.COM if ((rval = getmsg(mibfd, NULL, &databuf, 2971*8865SJonathan.Anderson@Sun.COM &flags)) != 0) { 2972*8865SJonathan.Anderson@Sun.COM if (rval < 0 && errno == EINTR) 2973*8865SJonathan.Anderson@Sun.COM continue; 2974*8865SJonathan.Anderson@Sun.COM /* 2975*8865SJonathan.Anderson@Sun.COM * We shouldn't get MOREDATA here so treat that 2976*8865SJonathan.Anderson@Sun.COM * as an error. 2977*8865SJonathan.Anderson@Sun.COM */ 2978*8865SJonathan.Anderson@Sun.COM logperror("mibwalk(): getmsg(data)"); 2979*8865SJonathan.Anderson@Sun.COM goto error; 2980*8865SJonathan.Anderson@Sun.COM } 2981*8865SJonathan.Anderson@Sun.COM break; 2982*8865SJonathan.Anderson@Sun.COM } 2983*8865SJonathan.Anderson@Sun.COM } 2984*8865SJonathan.Anderson@Sun.COM status = 0; 2985*8865SJonathan.Anderson@Sun.COM /* Pass the accumulated MIB data to the supplied function pointer */ 2986*8865SJonathan.Anderson@Sun.COM (*proc)(head_item); 2987*8865SJonathan.Anderson@Sun.COM error: 2988*8865SJonathan.Anderson@Sun.COM while (head_item != NULL) { 2989*8865SJonathan.Anderson@Sun.COM tmp = head_item; 2990*8865SJonathan.Anderson@Sun.COM head_item = tmp->mi_next; 2991*8865SJonathan.Anderson@Sun.COM free(tmp->mi_valp); 2992*8865SJonathan.Anderson@Sun.COM free(tmp); 2993*8865SJonathan.Anderson@Sun.COM } 2994*8865SJonathan.Anderson@Sun.COM return (status); 2995*8865SJonathan.Anderson@Sun.COM } 2996*8865SJonathan.Anderson@Sun.COM 2997*8865SJonathan.Anderson@Sun.COM /* 2998*8865SJonathan.Anderson@Sun.COM * Parse the supplied mib2 information to get the size of routing table 2999*8865SJonathan.Anderson@Sun.COM * entries. This is needed when running in a branded zone where the 3000*8865SJonathan.Anderson@Sun.COM * Solaris application environment and the Solaris kernel may not be the 3001*8865SJonathan.Anderson@Sun.COM * the same release version. 3002*8865SJonathan.Anderson@Sun.COM */ 3003*8865SJonathan.Anderson@Sun.COM static void 3004*8865SJonathan.Anderson@Sun.COM mib_get_constants(mib_item_t *item) 3005*8865SJonathan.Anderson@Sun.COM { 3006*8865SJonathan.Anderson@Sun.COM mib2_ip_t *ipv4; 3007*8865SJonathan.Anderson@Sun.COM mib2_ipv6IfStatsEntry_t *ipv6; 3008*8865SJonathan.Anderson@Sun.COM 3009*8865SJonathan.Anderson@Sun.COM for (; item != NULL; item = item->mi_next) { 3010*8865SJonathan.Anderson@Sun.COM if (item->mi_opthdr.name != 0) 3011*8865SJonathan.Anderson@Sun.COM continue; 3012*8865SJonathan.Anderson@Sun.COM if (item->mi_opthdr.level == MIB2_IP) { 3013*8865SJonathan.Anderson@Sun.COM ipv4 = (mib2_ip_t *)item->mi_valp; 3014*8865SJonathan.Anderson@Sun.COM ipRouteEntrySize = ipv4->ipRouteEntrySize; 3015*8865SJonathan.Anderson@Sun.COM } else if (item->mi_opthdr.level == MIB2_IP6) { 3016*8865SJonathan.Anderson@Sun.COM ipv6 = (mib2_ipv6IfStatsEntry_t *)item->mi_valp; 3017*8865SJonathan.Anderson@Sun.COM ipv6RouteEntrySize = ipv6->ipv6RouteEntrySize; 3018*8865SJonathan.Anderson@Sun.COM } 3019*8865SJonathan.Anderson@Sun.COM } 3020*8865SJonathan.Anderson@Sun.COM } 3021