17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5648495d6Svikram * Common Development and Distribution License (the "License").
6648495d6Svikram * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
22*e11c3f44Smeem * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
257c478bd9Sstevel@tonic-gate
267c478bd9Sstevel@tonic-gate /*
277c478bd9Sstevel@tonic-gate * RCM module to prevent plumbed IP addresses from being removed.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <ctype.h>
337c478bd9Sstevel@tonic-gate #include <memory.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <fcntl.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate #include <thread.h>
387c478bd9Sstevel@tonic-gate #include <synch.h>
397c478bd9Sstevel@tonic-gate #include <assert.h>
407c478bd9Sstevel@tonic-gate #include <errno.h>
417c478bd9Sstevel@tonic-gate #include <libintl.h>
427c478bd9Sstevel@tonic-gate #include <sys/param.h>
437c478bd9Sstevel@tonic-gate #include <sys/wait.h>
447c478bd9Sstevel@tonic-gate #include <sys/types.h>
457c478bd9Sstevel@tonic-gate #include <sys/stat.h>
467c478bd9Sstevel@tonic-gate #include <sys/cladm.h>
477c478bd9Sstevel@tonic-gate #include <sys/file.h>
487c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
497c478bd9Sstevel@tonic-gate #include <sys/socket.h>
507c478bd9Sstevel@tonic-gate #include <sys/sockio.h>
517c478bd9Sstevel@tonic-gate #include <sys/time.h>
527c478bd9Sstevel@tonic-gate #include <net/if.h>
537c478bd9Sstevel@tonic-gate #include <netinet/in.h>
547c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
557c478bd9Sstevel@tonic-gate #include <netinet/ip6.h>
567c478bd9Sstevel@tonic-gate #include <inet/ip.h>
577c478bd9Sstevel@tonic-gate #include <inet/ip6.h>
580406ceaaSmeem #include <libinetutil.h>
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate #include "rcm_module.h"
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate #define SUNW_IP "SUNW_ip/"
637c478bd9Sstevel@tonic-gate #define IP_REG_SIZE (9 + INET6_ADDRSTRLEN)
647c478bd9Sstevel@tonic-gate #define IP_ANON_USAGE gettext("Plumbed IP Address")
657c478bd9Sstevel@tonic-gate #define IP_SUSPEND_ERR gettext("Plumbed IP Addresses cannot be suspended")
667c478bd9Sstevel@tonic-gate #define IP_OFFLINE_ERR gettext("Invalid operation: IP cannot be offlined")
677c478bd9Sstevel@tonic-gate #define IP_REMOVE_ERR gettext("Invalid operation: IP cannot be removed")
687c478bd9Sstevel@tonic-gate #define IP_REG_FAIL gettext("Registration Failed")
697c478bd9Sstevel@tonic-gate #define IP_NO_CLUSTER gettext("Could not read cluster network addresses")
707c478bd9Sstevel@tonic-gate
717c478bd9Sstevel@tonic-gate #define IP_FLAG_NEW 0x00
727c478bd9Sstevel@tonic-gate #define IP_FLAG_REG 0x01
737c478bd9Sstevel@tonic-gate #define IP_FLAG_CL 0x02
747c478bd9Sstevel@tonic-gate #define IP_FLAG_IGNORE 0x04
757c478bd9Sstevel@tonic-gate #define IP_FLAG_DELETE 0x08
767c478bd9Sstevel@tonic-gate
777c478bd9Sstevel@tonic-gate static int ip_anon_register(rcm_handle_t *);
787c478bd9Sstevel@tonic-gate static int ip_anon_unregister(rcm_handle_t *);
797c478bd9Sstevel@tonic-gate static int ip_anon_getinfo(rcm_handle_t *, char *, id_t, uint_t,
807c478bd9Sstevel@tonic-gate char **, char **, nvlist_t *, rcm_info_t **);
817c478bd9Sstevel@tonic-gate static int ip_anon_suspend(rcm_handle_t *, char *, id_t,
827c478bd9Sstevel@tonic-gate timespec_t *, uint_t, char **, rcm_info_t **);
837c478bd9Sstevel@tonic-gate static int ip_anon_resume(rcm_handle_t *, char *, id_t, uint_t,
847c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
857c478bd9Sstevel@tonic-gate static int ip_anon_offline(rcm_handle_t *, char *, id_t, uint_t,
867c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
877c478bd9Sstevel@tonic-gate static int ip_anon_online(rcm_handle_t *, char *, id_t, uint_t,
887c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
897c478bd9Sstevel@tonic-gate static int ip_anon_remove(rcm_handle_t *, char *, id_t, uint_t,
907c478bd9Sstevel@tonic-gate char **, rcm_info_t **);
917c478bd9Sstevel@tonic-gate
927c478bd9Sstevel@tonic-gate static int exclude_ipv4(cladm_netaddrs_t exclude_addrs,
937c478bd9Sstevel@tonic-gate ipaddr_t address);
947c478bd9Sstevel@tonic-gate static int exclude_ipv6(cladm_netaddrs_t exclude_addrs,
957c478bd9Sstevel@tonic-gate uint32_t address[4]);
967c478bd9Sstevel@tonic-gate
977c478bd9Sstevel@tonic-gate
987c478bd9Sstevel@tonic-gate typedef struct ip_status {
997c478bd9Sstevel@tonic-gate int flags;
1007c478bd9Sstevel@tonic-gate char device[IP_REG_SIZE];
1017c478bd9Sstevel@tonic-gate struct ip_status *next;
1027c478bd9Sstevel@tonic-gate } ip_status_t;
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate static ip_status_t *findreg(char *reg);
1057c478bd9Sstevel@tonic-gate static ip_status_t *addreg(char *reg);
1067c478bd9Sstevel@tonic-gate static int deletereg(ip_status_t *entry);
1077c478bd9Sstevel@tonic-gate
1087c478bd9Sstevel@tonic-gate static ip_status_t *ip_list = NULL;
1097c478bd9Sstevel@tonic-gate static mutex_t ip_list_lock;
1107c478bd9Sstevel@tonic-gate
1117c478bd9Sstevel@tonic-gate static struct rcm_mod_ops ip_anon_ops =
1127c478bd9Sstevel@tonic-gate {
1137c478bd9Sstevel@tonic-gate RCM_MOD_OPS_VERSION,
1147c478bd9Sstevel@tonic-gate ip_anon_register,
1157c478bd9Sstevel@tonic-gate ip_anon_unregister,
1167c478bd9Sstevel@tonic-gate ip_anon_getinfo,
1177c478bd9Sstevel@tonic-gate ip_anon_suspend,
1187c478bd9Sstevel@tonic-gate ip_anon_resume,
1197c478bd9Sstevel@tonic-gate ip_anon_offline,
1207c478bd9Sstevel@tonic-gate ip_anon_online,
1217c478bd9Sstevel@tonic-gate ip_anon_remove,
1227c478bd9Sstevel@tonic-gate NULL,
1237c478bd9Sstevel@tonic-gate NULL,
1247c478bd9Sstevel@tonic-gate NULL
1257c478bd9Sstevel@tonic-gate };
1267c478bd9Sstevel@tonic-gate
1277c478bd9Sstevel@tonic-gate struct rcm_mod_ops *
rcm_mod_init()1287c478bd9Sstevel@tonic-gate rcm_mod_init()
1297c478bd9Sstevel@tonic-gate {
1307c478bd9Sstevel@tonic-gate return (&ip_anon_ops);
1317c478bd9Sstevel@tonic-gate }
1327c478bd9Sstevel@tonic-gate
1337c478bd9Sstevel@tonic-gate const char *
rcm_mod_info()1347c478bd9Sstevel@tonic-gate rcm_mod_info()
1357c478bd9Sstevel@tonic-gate {
136648495d6Svikram return ("RCM IP address module 1.4");
1377c478bd9Sstevel@tonic-gate }
1387c478bd9Sstevel@tonic-gate
1397c478bd9Sstevel@tonic-gate int
rcm_mod_fini()1407c478bd9Sstevel@tonic-gate rcm_mod_fini()
1417c478bd9Sstevel@tonic-gate {
1427c478bd9Sstevel@tonic-gate ip_status_t *tlist;
1437c478bd9Sstevel@tonic-gate
1447c478bd9Sstevel@tonic-gate /* free the registration list */
1457c478bd9Sstevel@tonic-gate
1467c478bd9Sstevel@tonic-gate (void) mutex_lock(&ip_list_lock);
1477c478bd9Sstevel@tonic-gate while (ip_list != NULL) {
1487c478bd9Sstevel@tonic-gate tlist = ip_list->next;
1497c478bd9Sstevel@tonic-gate free(ip_list);
1507c478bd9Sstevel@tonic-gate ip_list = tlist;
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate (void) mutex_destroy(&ip_list_lock);
1557c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
1567c478bd9Sstevel@tonic-gate }
1577c478bd9Sstevel@tonic-gate
1587c478bd9Sstevel@tonic-gate static int
ip_anon_register(rcm_handle_t * hdl)1597c478bd9Sstevel@tonic-gate ip_anon_register(rcm_handle_t *hdl)
1607c478bd9Sstevel@tonic-gate {
1617c478bd9Sstevel@tonic-gate int bootflags;
1627c478bd9Sstevel@tonic-gate struct ifaddrlist *al = NULL, *al6 = NULL;
1630406ceaaSmeem char errbuf[ERRBUFSIZE];
1647c478bd9Sstevel@tonic-gate char treg[IP_REG_SIZE], tstr[IP_REG_SIZE];
1657c478bd9Sstevel@tonic-gate cladm_netaddrs_t exclude_addrs;
1667c478bd9Sstevel@tonic-gate int num_ifs, num_ifs6, i, ret;
1677c478bd9Sstevel@tonic-gate uint32_t num_exclude_addrs = 0;
1687c478bd9Sstevel@tonic-gate ip_status_t *tlist, *tentry;
1697c478bd9Sstevel@tonic-gate
1707c478bd9Sstevel@tonic-gate (void) mutex_lock(&ip_list_lock);
1717c478bd9Sstevel@tonic-gate
1727c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: registration refresh.\n");
1737c478bd9Sstevel@tonic-gate
1747c478bd9Sstevel@tonic-gate exclude_addrs.cladm_num_netaddrs = 0;
1757c478bd9Sstevel@tonic-gate
1767c478bd9Sstevel@tonic-gate if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
1777c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
178*e11c3f44Smeem gettext("unable to check cluster status\n"));
1797c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
1807c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
1817c478bd9Sstevel@tonic-gate }
1827c478bd9Sstevel@tonic-gate
1837c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
1847c478bd9Sstevel@tonic-gate "ip_anon: cladm bootflags=%d\n", bootflags);
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate if (bootflags == 3) {
1877c478bd9Sstevel@tonic-gate
1887c478bd9Sstevel@tonic-gate /* build the exclusion list */
1897c478bd9Sstevel@tonic-gate
1907c478bd9Sstevel@tonic-gate if ((ret = _cladm(CL_CONFIG, CL_GET_NUM_NETADDRS,
1917c478bd9Sstevel@tonic-gate &num_exclude_addrs)) == 0) {
1927c478bd9Sstevel@tonic-gate exclude_addrs.cladm_num_netaddrs = num_exclude_addrs;
1937c478bd9Sstevel@tonic-gate
1947c478bd9Sstevel@tonic-gate if (num_exclude_addrs == 0)
1957c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
1967c478bd9Sstevel@tonic-gate "ip_anon: no addresses excluded\n");
1977c478bd9Sstevel@tonic-gate else {
1987c478bd9Sstevel@tonic-gate if ((exclude_addrs.cladm_netaddrs_array =
1997c478bd9Sstevel@tonic-gate malloc(sizeof (cladm_netaddr_entry_t) *
200*e11c3f44Smeem (num_exclude_addrs))) == NULL) {
2017c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
2027c478bd9Sstevel@tonic-gate gettext("out of memory\n"));
2037c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
2047c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
2057c478bd9Sstevel@tonic-gate }
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate if ((ret = _cladm(CL_CONFIG,
2087c478bd9Sstevel@tonic-gate CL_GET_NETADDRS, &exclude_addrs))
2097c478bd9Sstevel@tonic-gate != 0) {
2107c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
2117c478bd9Sstevel@tonic-gate IP_NO_CLUSTER);
2127c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
2137c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate }
2167c478bd9Sstevel@tonic-gate
2177c478bd9Sstevel@tonic-gate } else {
2187c478bd9Sstevel@tonic-gate if ((ret != 0) && (errno == EINVAL)) {
2197c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
2207c478bd9Sstevel@tonic-gate "no _cladm() backend to get addrs\n");
2217c478bd9Sstevel@tonic-gate } else {
2227c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, IP_NO_CLUSTER);
2237c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
2247c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
2257c478bd9Sstevel@tonic-gate }
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
2287c478bd9Sstevel@tonic-gate "cladm returned %d errno=%d\n", ret, errno);
2297c478bd9Sstevel@tonic-gate
2307c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
2317c478bd9Sstevel@tonic-gate "ip_anon: num exclude addrs: %d\n",
2327c478bd9Sstevel@tonic-gate exclude_addrs.cladm_num_netaddrs);
2337c478bd9Sstevel@tonic-gate
2347c478bd9Sstevel@tonic-gate /* print the exclusion list for debugging purposes */
2357c478bd9Sstevel@tonic-gate
2367c478bd9Sstevel@tonic-gate for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
2377c478bd9Sstevel@tonic-gate (void) strcpy(treg, "<UNKNOWN>");
2387c478bd9Sstevel@tonic-gate (void) strcpy(tstr, "<UNKNOWN>");
2397c478bd9Sstevel@tonic-gate if (exclude_addrs.cladm_netaddrs_array[i].\
2407c478bd9Sstevel@tonic-gate cl_ipversion == IPV4_VERSION) {
2417c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET,
2427c478bd9Sstevel@tonic-gate &exclude_addrs.cladm_netaddrs_array[i].
2437c478bd9Sstevel@tonic-gate cl_ipv_un.cl_ipv4.ipv4_netaddr,
2447c478bd9Sstevel@tonic-gate treg, INET_ADDRSTRLEN);
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET,
2477c478bd9Sstevel@tonic-gate &exclude_addrs.cladm_netaddrs_array[i].
2487c478bd9Sstevel@tonic-gate cl_ipv_un.cl_ipv4.ipv4_netmask,
2497c478bd9Sstevel@tonic-gate tstr, INET_ADDRSTRLEN);
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate if (exclude_addrs.cladm_netaddrs_array[i].\
2537c478bd9Sstevel@tonic-gate cl_ipversion == IPV6_VERSION) {
2547c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6,
2557c478bd9Sstevel@tonic-gate &exclude_addrs.cladm_netaddrs_array[i].
2567c478bd9Sstevel@tonic-gate cl_ipv_un.cl_ipv6.ipv6_netaddr,
2577c478bd9Sstevel@tonic-gate treg, INET6_ADDRSTRLEN);
2587c478bd9Sstevel@tonic-gate
2597c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6,
2607c478bd9Sstevel@tonic-gate &exclude_addrs.cladm_netaddrs_array[i].
2617c478bd9Sstevel@tonic-gate cl_ipv_un.cl_ipv6.ipv6_netmask,
2627c478bd9Sstevel@tonic-gate tstr, INET6_ADDRSTRLEN);
2637c478bd9Sstevel@tonic-gate }
2647c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "IPV%d: %s %s\n",
2657c478bd9Sstevel@tonic-gate exclude_addrs.cladm_netaddrs_array[i].
2667c478bd9Sstevel@tonic-gate cl_ipversion, treg, tstr);
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate }
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate /* obtain a list of all IPv4 and IPv6 addresses in the system */
2727c478bd9Sstevel@tonic-gate
2737c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
2747c478bd9Sstevel@tonic-gate "ip_anon: obtaining list of IPv4 addresses.\n");
275*e11c3f44Smeem num_ifs = ifaddrlist(&al, AF_INET, LIFC_UNDER_IPMP, errbuf);
2760406ceaaSmeem if (num_ifs == -1) {
2777c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
2787c478bd9Sstevel@tonic-gate gettext("cannot get IPv4 address list errno=%d (%s)\n"),
2797c478bd9Sstevel@tonic-gate errno, errbuf);
2807c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
2817c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate
2847c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
2857c478bd9Sstevel@tonic-gate "ip_anon: obtaining list of IPv6 addresses.\n");
2867c478bd9Sstevel@tonic-gate
287*e11c3f44Smeem num_ifs6 = ifaddrlist(&al6, AF_INET6, LIFC_UNDER_IPMP, errbuf);
2880406ceaaSmeem if (num_ifs6 == -1) {
2897c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
2907c478bd9Sstevel@tonic-gate gettext("cannot get IPv6 address list errno=%d (%s)\n"),
2910406ceaaSmeem errno, errbuf);
2927c478bd9Sstevel@tonic-gate free(al);
2937c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
2947c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
2957c478bd9Sstevel@tonic-gate }
2967c478bd9Sstevel@tonic-gate
2977c478bd9Sstevel@tonic-gate /* check the state of outstanding registrations against the list */
2987c478bd9Sstevel@tonic-gate
2997c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
3007c478bd9Sstevel@tonic-gate "ip_anon: checking outstanding registrations.\n");
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate tlist = ip_list;
3037c478bd9Sstevel@tonic-gate while (tlist != NULL) {
3047c478bd9Sstevel@tonic-gate tlist->flags |= IP_FLAG_DELETE;
3057c478bd9Sstevel@tonic-gate tlist = tlist->next;
3067c478bd9Sstevel@tonic-gate }
3077c478bd9Sstevel@tonic-gate
3087c478bd9Sstevel@tonic-gate /* IPv4 */
3097c478bd9Sstevel@tonic-gate
3107c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: checking IPv4 addresses.\n");
3117c478bd9Sstevel@tonic-gate
3127c478bd9Sstevel@tonic-gate for (i = 0; i < num_ifs; i++) {
3137c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET, &al[i].addr.addr, tstr,
3147c478bd9Sstevel@tonic-gate INET_ADDRSTRLEN);
3157c478bd9Sstevel@tonic-gate (void) strcpy(treg, SUNW_IP);
3167c478bd9Sstevel@tonic-gate (void) strcat(treg, tstr);
3177c478bd9Sstevel@tonic-gate
3187c478bd9Sstevel@tonic-gate if ((tlist = findreg(treg)) == NULL)
3197c478bd9Sstevel@tonic-gate tlist = addreg(treg);
3207c478bd9Sstevel@tonic-gate else
3217c478bd9Sstevel@tonic-gate tlist->flags &= (~IP_FLAG_DELETE);
3227c478bd9Sstevel@tonic-gate
3237c478bd9Sstevel@tonic-gate if (tlist == NULL) {
3247c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
3257c478bd9Sstevel@tonic-gate gettext("out of memory\n"));
3267c478bd9Sstevel@tonic-gate free(al);
3277c478bd9Sstevel@tonic-gate free(al6);
3287c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
3297c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate
3327c478bd9Sstevel@tonic-gate if (exclude_ipv4(exclude_addrs, al[i].addr.addr.s_addr))
3337c478bd9Sstevel@tonic-gate tlist->flags |= IP_FLAG_CL;
3347c478bd9Sstevel@tonic-gate }
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate /* IPv6 */
3377c478bd9Sstevel@tonic-gate
3387c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: checking IPv6 addresses.\n");
3397c478bd9Sstevel@tonic-gate
3407c478bd9Sstevel@tonic-gate for (i = 0; i < num_ifs6; i++) {
3417c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, &al6[i].addr.addr, tstr,
3427c478bd9Sstevel@tonic-gate INET6_ADDRSTRLEN);
3437c478bd9Sstevel@tonic-gate (void) strcpy(treg, SUNW_IP);
3447c478bd9Sstevel@tonic-gate (void) strcat(treg, tstr);
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate if ((tlist = findreg(treg)) == NULL)
3477c478bd9Sstevel@tonic-gate tlist = addreg(treg);
3487c478bd9Sstevel@tonic-gate else
3497c478bd9Sstevel@tonic-gate tlist->flags &= (~IP_FLAG_DELETE);
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate if (tlist == NULL) {
3527c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
3537c478bd9Sstevel@tonic-gate gettext("out of memory\n"));
3547c478bd9Sstevel@tonic-gate free(al);
3557c478bd9Sstevel@tonic-gate free(al6);
3567c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
3577c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
3587c478bd9Sstevel@tonic-gate }
3597c478bd9Sstevel@tonic-gate
3607c478bd9Sstevel@tonic-gate if (exclude_ipv6(exclude_addrs, al6[i].addr.addr6._S6_un.\
3617c478bd9Sstevel@tonic-gate _S6_u32))
3627c478bd9Sstevel@tonic-gate tlist->flags |= IP_FLAG_CL;
3637c478bd9Sstevel@tonic-gate }
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: updating reg. state.\n");
3667c478bd9Sstevel@tonic-gate
3677c478bd9Sstevel@tonic-gate /* examine the list of ip address registrations and their state */
3687c478bd9Sstevel@tonic-gate
3697c478bd9Sstevel@tonic-gate tlist = ip_list;
3707c478bd9Sstevel@tonic-gate while (tlist != NULL) {
3717c478bd9Sstevel@tonic-gate tentry = tlist;
3727c478bd9Sstevel@tonic-gate tlist = tlist->next;
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate if (tentry->flags & IP_FLAG_DELETE) {
3757c478bd9Sstevel@tonic-gate if (tentry->flags & IP_FLAG_REG) {
3767c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
3777c478bd9Sstevel@tonic-gate "ip_anon: unregistering interest in %s\n",
3787c478bd9Sstevel@tonic-gate tentry->device);
3797c478bd9Sstevel@tonic-gate if (rcm_unregister_interest(hdl,
3807c478bd9Sstevel@tonic-gate tentry->device, 0) != 0) {
3817c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
3827c478bd9Sstevel@tonic-gate gettext("failed to unregister"));
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate }
3857c478bd9Sstevel@tonic-gate (void) deletereg(tentry);
3867c478bd9Sstevel@tonic-gate } else if (!(tentry->flags & IP_FLAG_IGNORE)) {
3877c478bd9Sstevel@tonic-gate /*
3887c478bd9Sstevel@tonic-gate * If the registration is not a clustered devices and
3897c478bd9Sstevel@tonic-gate * not already registered, then RCM doesn't
3907c478bd9Sstevel@tonic-gate * currently know about it.
3917c478bd9Sstevel@tonic-gate */
3927c478bd9Sstevel@tonic-gate if (!(tentry->flags & IP_FLAG_CL) &&
393*e11c3f44Smeem !(tentry->flags & IP_FLAG_REG)) {
3947c478bd9Sstevel@tonic-gate tentry->flags |= IP_FLAG_REG;
3957c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
3967c478bd9Sstevel@tonic-gate "ip_anon: registering interest in %s\n",
3977c478bd9Sstevel@tonic-gate tentry->device);
3987c478bd9Sstevel@tonic-gate if (rcm_register_interest(hdl,
3997c478bd9Sstevel@tonic-gate tentry->device, 0, NULL) !=
4007c478bd9Sstevel@tonic-gate RCM_SUCCESS) {
4017c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
4027c478bd9Sstevel@tonic-gate IP_REG_FAIL);
4037c478bd9Sstevel@tonic-gate free(al);
4047c478bd9Sstevel@tonic-gate free(al6);
4057c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
4067c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
4077c478bd9Sstevel@tonic-gate } else {
4087c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
4097c478bd9Sstevel@tonic-gate "ip_anon: registered %s\n",
4107c478bd9Sstevel@tonic-gate tentry->device);
4117c478bd9Sstevel@tonic-gate }
4127c478bd9Sstevel@tonic-gate }
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate /*
4157c478bd9Sstevel@tonic-gate * If the entry is registered and clustered, then
4167c478bd9Sstevel@tonic-gate * the configuration has been changed and it
4177c478bd9Sstevel@tonic-gate * should be unregistered.
4187c478bd9Sstevel@tonic-gate */
4197c478bd9Sstevel@tonic-gate if ((tentry->flags & IP_FLAG_REG) &
4207c478bd9Sstevel@tonic-gate (tentry->flags & IP_FLAG_CL)) {
4217c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
4227c478bd9Sstevel@tonic-gate "ip_anon: unregistering in %s\n",
4237c478bd9Sstevel@tonic-gate tentry->device);
4247c478bd9Sstevel@tonic-gate if (rcm_unregister_interest(hdl,
4257c478bd9Sstevel@tonic-gate tentry->device, 0) != 0) {
4267c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
4277c478bd9Sstevel@tonic-gate gettext("failed to unregister"));
4287c478bd9Sstevel@tonic-gate }
4297c478bd9Sstevel@tonic-gate tentry->flags &= (~IP_FLAG_REG);
4307c478bd9Sstevel@tonic-gate }
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate }
4337c478bd9Sstevel@tonic-gate
4347c478bd9Sstevel@tonic-gate tlist = ip_list;
4357c478bd9Sstevel@tonic-gate while (tlist != NULL) {
4367c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: %s (%Xh)\n",
4377c478bd9Sstevel@tonic-gate tlist->device, tlist->flags);
4387c478bd9Sstevel@tonic-gate tlist = tlist->next;
4397c478bd9Sstevel@tonic-gate }
4407c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: registration complete.\n");
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate free(al);
4437c478bd9Sstevel@tonic-gate free(al6);
4447c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
4457c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
4467c478bd9Sstevel@tonic-gate }
4477c478bd9Sstevel@tonic-gate
4487c478bd9Sstevel@tonic-gate static int
ip_anon_unregister(rcm_handle_t * hdl)4497c478bd9Sstevel@tonic-gate ip_anon_unregister(rcm_handle_t *hdl)
4507c478bd9Sstevel@tonic-gate {
4517c478bd9Sstevel@tonic-gate ip_status_t *tlist;
4527c478bd9Sstevel@tonic-gate
4537c478bd9Sstevel@tonic-gate (void) mutex_lock(&ip_list_lock);
4547c478bd9Sstevel@tonic-gate
4557c478bd9Sstevel@tonic-gate tlist = ip_list;
4567c478bd9Sstevel@tonic-gate while (tlist != NULL) {
4577c478bd9Sstevel@tonic-gate if ((tlist->flags & IP_FLAG_REG)) {
4587c478bd9Sstevel@tonic-gate if (rcm_unregister_interest(hdl,
4597c478bd9Sstevel@tonic-gate tlist->device, 0) != 0) {
4607c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR,
4617c478bd9Sstevel@tonic-gate gettext("failed to unregister"));
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate tlist->flags &= (~IP_FLAG_REG);
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate tlist = tlist->next;
4667c478bd9Sstevel@tonic-gate }
4677c478bd9Sstevel@tonic-gate
4687c478bd9Sstevel@tonic-gate (void) mutex_unlock(&ip_list_lock);
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate
4737c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4747c478bd9Sstevel@tonic-gate static int
ip_anon_getinfo(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** infostr,char ** errstr,nvlist_t * props,rcm_info_t ** dependent)4757c478bd9Sstevel@tonic-gate ip_anon_getinfo(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
4767c478bd9Sstevel@tonic-gate char **infostr, char **errstr, nvlist_t *props, rcm_info_t **dependent)
4777c478bd9Sstevel@tonic-gate {
4787c478bd9Sstevel@tonic-gate
4797c478bd9Sstevel@tonic-gate assert(rsrcname != NULL && infostr != NULL);
4807c478bd9Sstevel@tonic-gate
4817c478bd9Sstevel@tonic-gate if ((*infostr = strdup(IP_ANON_USAGE)) == NULL)
4827c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
4837c478bd9Sstevel@tonic-gate
4847c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
4857c478bd9Sstevel@tonic-gate }
4867c478bd9Sstevel@tonic-gate
4877c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4887c478bd9Sstevel@tonic-gate static int
ip_anon_suspend(rcm_handle_t * hdl,char * rsrcname,id_t id,timespec_t * interval,uint_t flags,char ** errstr,rcm_info_t ** dependent)4897c478bd9Sstevel@tonic-gate ip_anon_suspend(rcm_handle_t *hdl, char *rsrcname, id_t id,
4907c478bd9Sstevel@tonic-gate timespec_t *interval, uint_t flags, char **errstr,
4917c478bd9Sstevel@tonic-gate rcm_info_t **dependent)
4927c478bd9Sstevel@tonic-gate {
4937c478bd9Sstevel@tonic-gate if ((*errstr = strdup(IP_SUSPEND_ERR)) == NULL)
4947c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
4957c478bd9Sstevel@tonic-gate
4967c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5007c478bd9Sstevel@tonic-gate static int
ip_anon_resume(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)5017c478bd9Sstevel@tonic-gate ip_anon_resume(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
5027c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
5037c478bd9Sstevel@tonic-gate {
5047c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate
5077c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5087c478bd9Sstevel@tonic-gate static int
ip_anon_offline(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)5097c478bd9Sstevel@tonic-gate ip_anon_offline(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
5107c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
5117c478bd9Sstevel@tonic-gate {
5127c478bd9Sstevel@tonic-gate if ((*errstr = strdup(IP_OFFLINE_ERR)) == NULL)
5137c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
5147c478bd9Sstevel@tonic-gate
5157c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
5167c478bd9Sstevel@tonic-gate }
5177c478bd9Sstevel@tonic-gate
5187c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5197c478bd9Sstevel@tonic-gate static int
ip_anon_online(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)5207c478bd9Sstevel@tonic-gate ip_anon_online(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
5217c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
5227c478bd9Sstevel@tonic-gate {
5237c478bd9Sstevel@tonic-gate return (RCM_SUCCESS);
5247c478bd9Sstevel@tonic-gate }
5257c478bd9Sstevel@tonic-gate
5267c478bd9Sstevel@tonic-gate /*ARGSUSED*/
5277c478bd9Sstevel@tonic-gate static int
ip_anon_remove(rcm_handle_t * hdl,char * rsrcname,id_t id,uint_t flags,char ** errstr,rcm_info_t ** dependent)5287c478bd9Sstevel@tonic-gate ip_anon_remove(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
5297c478bd9Sstevel@tonic-gate char **errstr, rcm_info_t **dependent)
5307c478bd9Sstevel@tonic-gate {
5317c478bd9Sstevel@tonic-gate if ((*errstr = strdup(IP_REMOVE_ERR)) == NULL)
5327c478bd9Sstevel@tonic-gate rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));
5337c478bd9Sstevel@tonic-gate
5347c478bd9Sstevel@tonic-gate return (RCM_FAILURE);
5357c478bd9Sstevel@tonic-gate }
5367c478bd9Sstevel@tonic-gate
5377c478bd9Sstevel@tonic-gate /*
5387c478bd9Sstevel@tonic-gate * Call with ip_list_lock held.
5397c478bd9Sstevel@tonic-gate */
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate static ip_status_t *
findreg(char * reg)5427c478bd9Sstevel@tonic-gate findreg(char *reg)
5437c478bd9Sstevel@tonic-gate {
5447c478bd9Sstevel@tonic-gate ip_status_t *tlist;
5457c478bd9Sstevel@tonic-gate int done;
5467c478bd9Sstevel@tonic-gate
5477c478bd9Sstevel@tonic-gate tlist = ip_list;
5487c478bd9Sstevel@tonic-gate done = 0;
5497c478bd9Sstevel@tonic-gate while ((tlist != NULL) && (!done)) {
5507c478bd9Sstevel@tonic-gate if (strcmp(tlist->device, reg) == 0)
5517c478bd9Sstevel@tonic-gate done = 1;
5527c478bd9Sstevel@tonic-gate else
5537c478bd9Sstevel@tonic-gate tlist = tlist->next;
5547c478bd9Sstevel@tonic-gate }
5557c478bd9Sstevel@tonic-gate
5567c478bd9Sstevel@tonic-gate return (tlist);
5577c478bd9Sstevel@tonic-gate }
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate static ip_status_t *
addreg(char * reg)5607c478bd9Sstevel@tonic-gate addreg(char *reg)
5617c478bd9Sstevel@tonic-gate {
5627c478bd9Sstevel@tonic-gate ip_status_t *tlist, *tentry;
5637c478bd9Sstevel@tonic-gate
5647c478bd9Sstevel@tonic-gate tentry = (ip_status_t *)malloc(sizeof (ip_status_t));
5657c478bd9Sstevel@tonic-gate if (tentry == NULL)
5667c478bd9Sstevel@tonic-gate return (tentry);
5677c478bd9Sstevel@tonic-gate
5687c478bd9Sstevel@tonic-gate tentry->flags = IP_FLAG_NEW;
5697c478bd9Sstevel@tonic-gate tentry->next = NULL;
5707c478bd9Sstevel@tonic-gate (void) strcpy(tentry->device, reg);
5717c478bd9Sstevel@tonic-gate
5727c478bd9Sstevel@tonic-gate if (ip_list == NULL)
5737c478bd9Sstevel@tonic-gate ip_list = tentry;
5747c478bd9Sstevel@tonic-gate else {
5757c478bd9Sstevel@tonic-gate tlist = ip_list;
5767c478bd9Sstevel@tonic-gate while (tlist->next != NULL)
5777c478bd9Sstevel@tonic-gate tlist = tlist->next;
5787c478bd9Sstevel@tonic-gate tlist->next = tentry;
5797c478bd9Sstevel@tonic-gate }
5807c478bd9Sstevel@tonic-gate
5817c478bd9Sstevel@tonic-gate return (tentry);
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate static int
deletereg(ip_status_t * entry)5857c478bd9Sstevel@tonic-gate deletereg(ip_status_t *entry)
5867c478bd9Sstevel@tonic-gate {
5877c478bd9Sstevel@tonic-gate ip_status_t *tlist;
5887c478bd9Sstevel@tonic-gate
5897c478bd9Sstevel@tonic-gate if (entry == NULL)
5907c478bd9Sstevel@tonic-gate return (-1);
5917c478bd9Sstevel@tonic-gate
5927c478bd9Sstevel@tonic-gate if (entry == ip_list) {
5937c478bd9Sstevel@tonic-gate ip_list = ip_list->next;
5947c478bd9Sstevel@tonic-gate free(entry);
5957c478bd9Sstevel@tonic-gate } else {
5967c478bd9Sstevel@tonic-gate tlist = ip_list;
5977c478bd9Sstevel@tonic-gate while ((tlist->next != NULL) && (tlist->next != entry))
5987c478bd9Sstevel@tonic-gate tlist = tlist->next;
5997c478bd9Sstevel@tonic-gate
6007c478bd9Sstevel@tonic-gate if (tlist->next != entry)
6017c478bd9Sstevel@tonic-gate return (-1);
6027c478bd9Sstevel@tonic-gate tlist->next = entry->next;
6037c478bd9Sstevel@tonic-gate free(entry);
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate return (0);
6067c478bd9Sstevel@tonic-gate }
6077c478bd9Sstevel@tonic-gate
6087c478bd9Sstevel@tonic-gate static int
exclude_ipv4(cladm_netaddrs_t exclude_addrs,ipaddr_t address)6097c478bd9Sstevel@tonic-gate exclude_ipv4(cladm_netaddrs_t exclude_addrs, ipaddr_t address)
6107c478bd9Sstevel@tonic-gate {
6117c478bd9Sstevel@tonic-gate int i;
6127c478bd9Sstevel@tonic-gate char taddr[IP_REG_SIZE], tmask[IP_REG_SIZE], tmatch[IP_REG_SIZE];
6137c478bd9Sstevel@tonic-gate ipaddr_t ipv4_netaddr, ipv4_netmask;
6147c478bd9Sstevel@tonic-gate
6157c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET, &address, taddr, INET_ADDRSTRLEN);
6167c478bd9Sstevel@tonic-gate
6177c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: exclude_ipv4 (%s, %d)\n",
6187c478bd9Sstevel@tonic-gate taddr, exclude_addrs.cladm_num_netaddrs);
6197c478bd9Sstevel@tonic-gate /*
6207c478bd9Sstevel@tonic-gate * If this falls in the exclusion list, the IP_FLAG_CL
6217c478bd9Sstevel@tonic-gate * bit should be set for the adapter.
6227c478bd9Sstevel@tonic-gate */
6237c478bd9Sstevel@tonic-gate for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
6247c478bd9Sstevel@tonic-gate if (exclude_addrs.cladm_netaddrs_array[i].\
6257c478bd9Sstevel@tonic-gate cl_ipversion == IPV4_VERSION) {
6267c478bd9Sstevel@tonic-gate
6277c478bd9Sstevel@tonic-gate ipv4_netaddr = exclude_addrs.\
6287c478bd9Sstevel@tonic-gate cladm_netaddrs_array[i].cl_ipv_un.cl_ipv4.\
6297c478bd9Sstevel@tonic-gate ipv4_netaddr;
6307c478bd9Sstevel@tonic-gate ipv4_netmask = exclude_addrs.\
6317c478bd9Sstevel@tonic-gate cladm_netaddrs_array[i].cl_ipv_un.cl_ipv4.\
6327c478bd9Sstevel@tonic-gate ipv4_netmask;
6337c478bd9Sstevel@tonic-gate
6347c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET, &ipv4_netaddr, tmatch,
6357c478bd9Sstevel@tonic-gate INET_ADDRSTRLEN);
6367c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET, &ipv4_netmask, tmask,
6377c478bd9Sstevel@tonic-gate INET_ADDRSTRLEN);
6387c478bd9Sstevel@tonic-gate
6397c478bd9Sstevel@tonic-gate if ((address & ipv4_netmask) == ipv4_netaddr) {
6407c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG,
6417c478bd9Sstevel@tonic-gate "ip_anon: matched %s:%s => %s\n",
6427c478bd9Sstevel@tonic-gate taddr, tmask, tmatch);
6437c478bd9Sstevel@tonic-gate return (1);
6447c478bd9Sstevel@tonic-gate }
6457c478bd9Sstevel@tonic-gate }
6467c478bd9Sstevel@tonic-gate }
6477c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: no match for %s\n",
6487c478bd9Sstevel@tonic-gate taddr);
6497c478bd9Sstevel@tonic-gate return (0);
6507c478bd9Sstevel@tonic-gate }
6517c478bd9Sstevel@tonic-gate
6527c478bd9Sstevel@tonic-gate static int
exclude_ipv6(cladm_netaddrs_t exclude_addrs,uint32_t address[4])6537c478bd9Sstevel@tonic-gate exclude_ipv6(cladm_netaddrs_t exclude_addrs, uint32_t address[4])
6547c478bd9Sstevel@tonic-gate {
6557c478bd9Sstevel@tonic-gate int i, j, numequal;
6567c478bd9Sstevel@tonic-gate uint32_t addr[4], ipv6_netaddr[4], ipv6_netmask[4];
6577c478bd9Sstevel@tonic-gate char taddr[IP_REG_SIZE], tmask[IP_REG_SIZE], tmatch[IP_REG_SIZE];
6587c478bd9Sstevel@tonic-gate
6597c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, address, taddr, INET6_ADDRSTRLEN);
6607c478bd9Sstevel@tonic-gate
6617c478bd9Sstevel@tonic-gate /*
6627c478bd9Sstevel@tonic-gate * If this falls in the exclusion list, the IP_FLAG_CL
6637c478bd9Sstevel@tonic-gate * bit should be set for the adapter.
6647c478bd9Sstevel@tonic-gate */
6657c478bd9Sstevel@tonic-gate
6667c478bd9Sstevel@tonic-gate for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
6677c478bd9Sstevel@tonic-gate if (exclude_addrs.cladm_netaddrs_array[i].\
6687c478bd9Sstevel@tonic-gate cl_ipversion == IPV6_VERSION) {
6697c478bd9Sstevel@tonic-gate numequal = 0;
6707c478bd9Sstevel@tonic-gate for (j = 0; j < 4; j++) {
6717c478bd9Sstevel@tonic-gate ipv6_netaddr[j] = exclude_addrs.\
6727c478bd9Sstevel@tonic-gate cladm_netaddrs_array[i].\
6737c478bd9Sstevel@tonic-gate cl_ipv_un.cl_ipv6.ipv6_netaddr[j];
6747c478bd9Sstevel@tonic-gate
6757c478bd9Sstevel@tonic-gate ipv6_netmask[j] = exclude_addrs.\
6767c478bd9Sstevel@tonic-gate cladm_netaddrs_array[i].\
6777c478bd9Sstevel@tonic-gate cl_ipv_un.cl_ipv6.ipv6_netmask[j];
6787c478bd9Sstevel@tonic-gate
6797c478bd9Sstevel@tonic-gate addr[j] = address[j] & ipv6_netmask[j];
6807c478bd9Sstevel@tonic-gate if (addr[j] == ipv6_netaddr[j])
6817c478bd9Sstevel@tonic-gate numequal++;
6827c478bd9Sstevel@tonic-gate }
6837c478bd9Sstevel@tonic-gate
6847c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, ipv6_netaddr, tmatch,
6857c478bd9Sstevel@tonic-gate INET6_ADDRSTRLEN);
6867c478bd9Sstevel@tonic-gate (void) inet_ntop(AF_INET6, ipv6_netmask, tmask,
6877c478bd9Sstevel@tonic-gate INET6_ADDRSTRLEN);
6887c478bd9Sstevel@tonic-gate
6897c478bd9Sstevel@tonic-gate if (numequal == 4)
6907c478bd9Sstevel@tonic-gate return (1);
6917c478bd9Sstevel@tonic-gate }
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate rcm_log_message(RCM_DEBUG, "ip_anon: no match for %s\n",
6947c478bd9Sstevel@tonic-gate taddr);
6957c478bd9Sstevel@tonic-gate return (0);
6967c478bd9Sstevel@tonic-gate }
697