summaryrefslogtreecommitdiff
path: root/usr/src/cmd/rcm_daemon/common/ip_anon_rcm.c
blob: 6e1fe1bf39363f505d607eb5c663038f32e5d54b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * RCM module to prevent plumbed IP addresses from being removed.
 */


#include <stdlib.h>
#include <ctype.h>
#include <memory.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <thread.h>
#include <synch.h>
#include <assert.h>
#include <errno.h>
#include <libintl.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/cladm.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/sockio.h>
#include <sys/time.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/ip6.h>
#include <inet/ip.h>
#include <inet/ip6.h>
#include <libinetutil.h>

#include "rcm_module.h"

#define	SUNW_IP		"SUNW_ip/"
#define	IP_REG_SIZE	(9 + INET6_ADDRSTRLEN)
#define	IP_ANON_USAGE	gettext("Plumbed IP Address")
#define	IP_SUSPEND_ERR	gettext("Plumbed IP Addresses cannot be suspended")
#define	IP_OFFLINE_ERR	gettext("Invalid operation: IP cannot be offlined")
#define	IP_REMOVE_ERR	gettext("Invalid operation: IP cannot be removed")
#define	IP_REG_FAIL	gettext("Registration Failed")
#define	IP_NO_CLUSTER	gettext("Could not read cluster network addresses")

#define	IP_FLAG_NEW	0x00
#define	IP_FLAG_REG	0x01
#define	IP_FLAG_CL	0x02
#define	IP_FLAG_IGNORE	0x04
#define	IP_FLAG_DELETE	0x08

static int		ip_anon_register(rcm_handle_t *);
static int		ip_anon_unregister(rcm_handle_t *);
static int		ip_anon_getinfo(rcm_handle_t *, char *, id_t, uint_t,
			    char **, char **, nvlist_t *, rcm_info_t **);
static int		ip_anon_suspend(rcm_handle_t *, char *, id_t,
			    timespec_t *, uint_t, char **, rcm_info_t **);
static int		ip_anon_resume(rcm_handle_t *, char *, id_t, uint_t,
			    char **, rcm_info_t **);
static int		ip_anon_offline(rcm_handle_t *, char *, id_t, uint_t,
			    char **, rcm_info_t **);
static int		ip_anon_online(rcm_handle_t *, char *, id_t, uint_t,
			    char **, rcm_info_t **);
static int		ip_anon_remove(rcm_handle_t *, char *, id_t, uint_t,
			    char **, rcm_info_t **);

static int		exclude_ipv4(cladm_netaddrs_t exclude_addrs,
			    ipaddr_t address);
static int		exclude_ipv6(cladm_netaddrs_t exclude_addrs,
			    uint32_t address[4]);


typedef struct ip_status {
	int			flags;
	char			device[IP_REG_SIZE];
	struct ip_status	*next;
} ip_status_t;

static ip_status_t	*findreg(char *reg);
static ip_status_t	*addreg(char *reg);
static int		deletereg(ip_status_t *entry);

static ip_status_t	*ip_list = NULL;
static mutex_t		ip_list_lock;

static struct rcm_mod_ops ip_anon_ops =
{
	RCM_MOD_OPS_VERSION,
	ip_anon_register,
	ip_anon_unregister,
	ip_anon_getinfo,
	ip_anon_suspend,
	ip_anon_resume,
	ip_anon_offline,
	ip_anon_online,
	ip_anon_remove,
	NULL,
	NULL,
	NULL
};

struct rcm_mod_ops *
rcm_mod_init()
{
	return (&ip_anon_ops);
}

const char *
rcm_mod_info()
{
	return ("RCM IP address module 1.4");
}

int
rcm_mod_fini()
{
	ip_status_t *tlist;

	/* free the registration list */

	(void) mutex_lock(&ip_list_lock);
	while (ip_list != NULL) {
		tlist = ip_list->next;
		free(ip_list);
		ip_list = tlist;
	}
	(void) mutex_unlock(&ip_list_lock);

	(void) mutex_destroy(&ip_list_lock);
	return (RCM_SUCCESS);
}

static int
ip_anon_register(rcm_handle_t *hdl)
{
	int bootflags;
	struct ifaddrlist *al = NULL, *al6 = NULL;
	char errbuf[ERRBUFSIZE];
	char treg[IP_REG_SIZE], tstr[IP_REG_SIZE];
	cladm_netaddrs_t exclude_addrs;
	int num_ifs, num_ifs6,  i, ret;
	uint32_t num_exclude_addrs = 0;
	ip_status_t *tlist, *tentry;

	(void) mutex_lock(&ip_list_lock);

	rcm_log_message(RCM_DEBUG, "ip_anon: registration refresh.\n");

	exclude_addrs.cladm_num_netaddrs = 0;

	if (_cladm(CL_INITIALIZE, CL_GET_BOOTFLAG, &bootflags) != 0) {
		rcm_log_message(RCM_ERROR,
		    gettext("unable to check cluster status\n"));
		(void) mutex_unlock(&ip_list_lock);
		return (RCM_FAILURE);
	}

	rcm_log_message(RCM_DEBUG,
	    "ip_anon: cladm bootflags=%d\n", bootflags);

	if (bootflags == 3) {

		/* build the exclusion list */

		if ((ret = _cladm(CL_CONFIG, CL_GET_NUM_NETADDRS,
		    &num_exclude_addrs)) == 0) {
			exclude_addrs.cladm_num_netaddrs = num_exclude_addrs;

			if (num_exclude_addrs == 0)
				rcm_log_message(RCM_DEBUG,
				    "ip_anon: no addresses excluded\n");
			else {
				if ((exclude_addrs.cladm_netaddrs_array =
				    malloc(sizeof (cladm_netaddr_entry_t) *
				    (num_exclude_addrs))) == NULL) {
					rcm_log_message(RCM_ERROR,
					    gettext("out of memory\n"));
					(void) mutex_unlock(&ip_list_lock);
					return (RCM_FAILURE);
				}

				if ((ret = _cladm(CL_CONFIG,
				    CL_GET_NETADDRS, &exclude_addrs))
				    != 0) {
					rcm_log_message(RCM_ERROR,
					    IP_NO_CLUSTER);
					(void) mutex_unlock(&ip_list_lock);
					return (RCM_FAILURE);
				}
			}

		} else {
			if ((ret != 0) && (errno == EINVAL)) {
				rcm_log_message(RCM_DEBUG,
				    "no _cladm() backend to get addrs\n");
			} else {
				rcm_log_message(RCM_ERROR, IP_NO_CLUSTER);
				(void) mutex_unlock(&ip_list_lock);
				return (RCM_FAILURE);
			}
		}
		rcm_log_message(RCM_DEBUG,
		    "cladm returned %d errno=%d\n", ret, errno);

		rcm_log_message(RCM_DEBUG,
		    "ip_anon: num exclude addrs: %d\n",
		    exclude_addrs.cladm_num_netaddrs);

		/* print the exclusion list for debugging purposes */

		for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
			(void) strcpy(treg, "<UNKNOWN>");
			(void) strcpy(tstr, "<UNKNOWN>");
			if (exclude_addrs.cladm_netaddrs_array[i].\
			    cl_ipversion == IPV4_VERSION) {
				(void) inet_ntop(AF_INET,
				    &exclude_addrs.cladm_netaddrs_array[i].
				    cl_ipv_un.cl_ipv4.ipv4_netaddr,
				    treg, INET_ADDRSTRLEN);

				(void) inet_ntop(AF_INET,
				    &exclude_addrs.cladm_netaddrs_array[i].
				    cl_ipv_un.cl_ipv4.ipv4_netmask,
				    tstr, INET_ADDRSTRLEN);
			}

			if (exclude_addrs.cladm_netaddrs_array[i].\
			    cl_ipversion == IPV6_VERSION) {
				(void) inet_ntop(AF_INET6,
				    &exclude_addrs.cladm_netaddrs_array[i].
				    cl_ipv_un.cl_ipv6.ipv6_netaddr,
				    treg, INET6_ADDRSTRLEN);

				(void) inet_ntop(AF_INET6,
				    &exclude_addrs.cladm_netaddrs_array[i].
				    cl_ipv_un.cl_ipv6.ipv6_netmask,
				    tstr, INET6_ADDRSTRLEN);
			}
			rcm_log_message(RCM_DEBUG, "IPV%d: %s %s\n",
			    exclude_addrs.cladm_netaddrs_array[i].
			    cl_ipversion, treg, tstr);

		}
	}

	/* obtain a list of all IPv4 and IPv6 addresses in the system */

	rcm_log_message(RCM_DEBUG,
	    "ip_anon: obtaining list of IPv4 addresses.\n");
	num_ifs = ifaddrlist(&al, AF_INET, LIFC_UNDER_IPMP, errbuf);
	if (num_ifs == -1) {
		rcm_log_message(RCM_ERROR,
		    gettext("cannot get IPv4 address list errno=%d (%s)\n"),
		    errno, errbuf);
		(void) mutex_unlock(&ip_list_lock);
		return (RCM_FAILURE);
	}

	rcm_log_message(RCM_DEBUG,
	    "ip_anon: obtaining list of IPv6 addresses.\n");

	num_ifs6 = ifaddrlist(&al6, AF_INET6, LIFC_UNDER_IPMP, errbuf);
	if (num_ifs6 == -1) {
		rcm_log_message(RCM_ERROR,
		    gettext("cannot get IPv6 address list errno=%d (%s)\n"),
		    errno, errbuf);
		free(al);
		(void) mutex_unlock(&ip_list_lock);
		return (RCM_FAILURE);
	}

	/* check the state of outstanding registrations against the list */

	rcm_log_message(RCM_DEBUG,
	    "ip_anon: checking outstanding registrations.\n");

	tlist = ip_list;
	while (tlist != NULL) {
		tlist->flags |= IP_FLAG_DELETE;
		tlist = tlist->next;
	}

	/* IPv4 */

	rcm_log_message(RCM_DEBUG, "ip_anon: checking IPv4 addresses.\n");

	for (i = 0; i < num_ifs; i++) {
		(void) inet_ntop(AF_INET, &al[i].addr.addr, tstr,
		    INET_ADDRSTRLEN);
		(void) strcpy(treg, SUNW_IP);
		(void) strcat(treg, tstr);

		if ((tlist = findreg(treg)) == NULL)
			tlist = addreg(treg);
		else
			tlist->flags &= (~IP_FLAG_DELETE);

		if (tlist == NULL) {
			rcm_log_message(RCM_ERROR,
			    gettext("out of memory\n"));
			free(al);
			free(al6);
			(void) mutex_unlock(&ip_list_lock);
			return (RCM_FAILURE);
		}

		if (exclude_ipv4(exclude_addrs, al[i].addr.addr.s_addr))
			tlist->flags |= IP_FLAG_CL;
	}

	/* IPv6 */

	rcm_log_message(RCM_DEBUG, "ip_anon: checking IPv6 addresses.\n");

	for (i = 0; i < num_ifs6; i++) {
		(void) inet_ntop(AF_INET6, &al6[i].addr.addr, tstr,
		    INET6_ADDRSTRLEN);
		(void) strcpy(treg, SUNW_IP);
		(void) strcat(treg, tstr);

		if ((tlist = findreg(treg)) == NULL)
			tlist = addreg(treg);
		else
			tlist->flags &= (~IP_FLAG_DELETE);

		if (tlist == NULL) {
			rcm_log_message(RCM_ERROR,
			    gettext("out of memory\n"));
			free(al);
			free(al6);
			(void) mutex_unlock(&ip_list_lock);
			return (RCM_FAILURE);
		}

		if (exclude_ipv6(exclude_addrs, al6[i].addr.addr6._S6_un.\
		    _S6_u32))
			tlist->flags |= IP_FLAG_CL;
	}

	rcm_log_message(RCM_DEBUG, "ip_anon: updating reg. state.\n");

	/* examine the list of ip address registrations and their state */

	tlist = ip_list;
	while (tlist != NULL) {
		tentry = tlist;
		tlist = tlist->next;

		if (tentry->flags & IP_FLAG_DELETE) {
			if (tentry->flags & IP_FLAG_REG) {
				rcm_log_message(RCM_DEBUG,
				    "ip_anon: unregistering interest in %s\n",
				    tentry->device);
				if (rcm_unregister_interest(hdl,
				    tentry->device, 0) != 0) {
					rcm_log_message(RCM_ERROR,
					    gettext("failed to unregister"));
				}
			}
			(void) deletereg(tentry);
		} else if (!(tentry->flags & IP_FLAG_IGNORE)) {
			/*
			 * If the registration is not a clustered devices and
			 * not already registered, then RCM doesn't
			 * currently know about it.
			 */
			if (!(tentry->flags & IP_FLAG_CL) &&
			    !(tentry->flags & IP_FLAG_REG)) {
				tentry->flags |= IP_FLAG_REG;
				rcm_log_message(RCM_DEBUG,
				    "ip_anon: registering interest in %s\n",
				    tentry->device);
				if (rcm_register_interest(hdl,
				    tentry->device, 0, NULL) !=
				    RCM_SUCCESS) {
					rcm_log_message(RCM_ERROR,
					    IP_REG_FAIL);
					free(al);
					free(al6);
					(void) mutex_unlock(&ip_list_lock);
					return (RCM_FAILURE);
				} else {
					rcm_log_message(RCM_DEBUG,
					    "ip_anon: registered %s\n",
					    tentry->device);
				}
			}

			/*
			 * If the entry is registered and clustered, then
			 * the configuration has been changed and it
			 * should be unregistered.
			 */
			if ((tentry->flags & IP_FLAG_REG) &
			    (tentry->flags & IP_FLAG_CL)) {
				rcm_log_message(RCM_DEBUG,
				    "ip_anon: unregistering in %s\n",
				    tentry->device);
				if (rcm_unregister_interest(hdl,
				    tentry->device, 0) != 0) {
					rcm_log_message(RCM_ERROR,
					    gettext("failed to unregister"));
				}
				tentry->flags &= (~IP_FLAG_REG);
			}
		}
	}

	tlist = ip_list;
	while (tlist != NULL) {
		rcm_log_message(RCM_DEBUG, "ip_anon: %s (%Xh)\n",
		    tlist->device, tlist->flags);
		tlist = tlist->next;
	}
	rcm_log_message(RCM_DEBUG, "ip_anon: registration complete.\n");

	free(al);
	free(al6);
	(void) mutex_unlock(&ip_list_lock);
	return (RCM_SUCCESS);
}

static int
ip_anon_unregister(rcm_handle_t *hdl)
{
	ip_status_t *tlist;

	(void) mutex_lock(&ip_list_lock);

	tlist = ip_list;
	while (tlist != NULL) {
		if ((tlist->flags & IP_FLAG_REG)) {
			if (rcm_unregister_interest(hdl,
			    tlist->device, 0) != 0) {
				rcm_log_message(RCM_ERROR,
				    gettext("failed to unregister"));
			}
			tlist->flags &= (~IP_FLAG_REG);
		}
		tlist = tlist->next;
	}

	(void) mutex_unlock(&ip_list_lock);

	return (RCM_SUCCESS);
}

/*ARGSUSED*/
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)
{

	assert(rsrcname != NULL && infostr != NULL);

	if ((*infostr = strdup(IP_ANON_USAGE)) == NULL)
		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));

	return (RCM_SUCCESS);
}

/*ARGSUSED*/
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)
{
	if ((*errstr = strdup(IP_SUSPEND_ERR)) == NULL)
		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));

	return (RCM_FAILURE);
}

/*ARGSUSED*/
static int
ip_anon_resume(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
    char **errstr, rcm_info_t **dependent)
{
	return (RCM_SUCCESS);
}

/*ARGSUSED*/
static int
ip_anon_offline(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
    char **errstr, rcm_info_t **dependent)
{
	if ((*errstr = strdup(IP_OFFLINE_ERR)) == NULL)
		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));

	return (RCM_FAILURE);
}

/*ARGSUSED*/
static int
ip_anon_online(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
    char  **errstr, rcm_info_t **dependent)
{
	return (RCM_SUCCESS);
}

/*ARGSUSED*/
static int
ip_anon_remove(rcm_handle_t *hdl, char *rsrcname, id_t id, uint_t flags,
    char **errstr, rcm_info_t **dependent)
{
	if ((*errstr = strdup(IP_REMOVE_ERR)) == NULL)
		rcm_log_message(RCM_ERROR, gettext("strdup failure\n"));

	return (RCM_FAILURE);
}

/*
 * Call with ip_list_lock held.
 */

static ip_status_t *
findreg(char *reg)
{
	ip_status_t *tlist;
	int done;

	tlist = ip_list;
	done = 0;
	while ((tlist != NULL) && (!done)) {
		if (strcmp(tlist->device, reg) == 0)
			done = 1;
		else
			tlist = tlist->next;
	}

	return (tlist);
}

static ip_status_t *
addreg(char *reg)
{
	ip_status_t *tlist, *tentry;

	tentry = (ip_status_t *)malloc(sizeof (ip_status_t));
	if (tentry == NULL)
		return (tentry);

	tentry->flags = IP_FLAG_NEW;
	tentry->next = NULL;
	(void) strcpy(tentry->device, reg);

	if (ip_list == NULL)
		ip_list = tentry;
	else {
		tlist = ip_list;
		while (tlist->next != NULL)
			tlist = tlist->next;
		tlist->next = tentry;
	}

	return (tentry);
}

static int
deletereg(ip_status_t *entry)
{
	ip_status_t *tlist;

	if (entry == NULL)
		return (-1);

	if (entry == ip_list) {
		ip_list = ip_list->next;
		free(entry);
	} else {
		tlist = ip_list;
		while ((tlist->next != NULL) && (tlist->next != entry))
			tlist = tlist->next;

		if (tlist->next != entry)
			return (-1);
		tlist->next = entry->next;
		free(entry);
	}
	return (0);
}

static int
exclude_ipv4(cladm_netaddrs_t exclude_addrs, ipaddr_t address)
{
	int i;
	char taddr[IP_REG_SIZE], tmask[IP_REG_SIZE], tmatch[IP_REG_SIZE];
	ipaddr_t ipv4_netaddr, ipv4_netmask;

	(void) inet_ntop(AF_INET, &address, taddr, INET_ADDRSTRLEN);

	rcm_log_message(RCM_DEBUG, "ip_anon: exclude_ipv4 (%s, %d)\n",
	    taddr, exclude_addrs.cladm_num_netaddrs);
	/*
	 * If this falls in the exclusion list, the IP_FLAG_CL
	 * bit should be set for the adapter.
	 */
	for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
		if (exclude_addrs.cladm_netaddrs_array[i].\
		    cl_ipversion == IPV4_VERSION) {

			ipv4_netaddr = exclude_addrs.\
			    cladm_netaddrs_array[i].cl_ipv_un.cl_ipv4.\
			    ipv4_netaddr;
			ipv4_netmask = exclude_addrs.\
			    cladm_netaddrs_array[i].cl_ipv_un.cl_ipv4.\
			    ipv4_netmask;

			(void) inet_ntop(AF_INET, &ipv4_netaddr, tmatch,
			    INET_ADDRSTRLEN);
			(void) inet_ntop(AF_INET, &ipv4_netmask, tmask,
			    INET_ADDRSTRLEN);

			if ((address & ipv4_netmask) == ipv4_netaddr) {
				rcm_log_message(RCM_DEBUG,
				    "ip_anon: matched %s:%s => %s\n",
				    taddr, tmask, tmatch);
				return (1);
			}
		}
	}
	rcm_log_message(RCM_DEBUG, "ip_anon: no match for %s\n",
	    taddr);
	return (0);
}

static int
exclude_ipv6(cladm_netaddrs_t exclude_addrs, uint32_t address[4])
{
	int i, j, numequal;
	uint32_t addr[4], ipv6_netaddr[4], ipv6_netmask[4];
	char taddr[IP_REG_SIZE], tmask[IP_REG_SIZE], tmatch[IP_REG_SIZE];

	(void) inet_ntop(AF_INET6, address, taddr, INET6_ADDRSTRLEN);

	/*
	 * If this falls in the exclusion list, the IP_FLAG_CL
	 * bit should be set for the adapter.
	 */

	for (i = 0; i < exclude_addrs.cladm_num_netaddrs; i++) {
		if (exclude_addrs.cladm_netaddrs_array[i].\
		    cl_ipversion == IPV6_VERSION) {
			numequal = 0;
			for (j = 0; j < 4; j++) {
				ipv6_netaddr[j] = exclude_addrs.\
				    cladm_netaddrs_array[i].\
				    cl_ipv_un.cl_ipv6.ipv6_netaddr[j];

				ipv6_netmask[j] = exclude_addrs.\
				    cladm_netaddrs_array[i].\
				    cl_ipv_un.cl_ipv6.ipv6_netmask[j];

				addr[j] = address[j] & ipv6_netmask[j];
				if (addr[j] == ipv6_netaddr[j])
					numequal++;
			}

			(void) inet_ntop(AF_INET6, ipv6_netaddr, tmatch,
			    INET6_ADDRSTRLEN);
			(void) inet_ntop(AF_INET6, ipv6_netmask, tmask,
			    INET6_ADDRSTRLEN);

			if (numequal == 4)
				return (1);
		}
	}
	rcm_log_message(RCM_DEBUG, "ip_anon: no match for %s\n",
	    taddr);
	return (0);
}