/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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
* 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 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <inet/ip_listutils.h>
/*
* These functions perform set operations on sets of ipv6 addresses.
* typedef struct slist_s {
* int sl_nusmrc;
* in6_addr_t sl_addr[MAX_FILTER_SIZE];
* } slist_t;
*
* The functions were designed specifically for the implementation of
* IGMPv3 and MLDv2 in ip; they were not meant to be general-purpose.
*/
/*
* Tells if lists A and B are different or not - true if different;
* caller guarantees that lists are <= MAX_FILTER_SIZE
*/
{
int i, j;
return (B_TRUE);
for (i = 0; i < acnt; i++) {
for (j = 0; j < bcnt; j++) {
if (IN6_ARE_ADDR_EQUAL(
break;
}
}
if (!found)
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Tells if list a contains address addr - true if it does, false if not;
* caller guarantees that list is <= MAX_FILTER_SIZE.
*/
{
int i;
if (SLIST_IS_EMPTY(a))
return (B_FALSE);
for (i = 0; i < a->sl_numsrc; i++) {
return (B_TRUE);
}
return (B_FALSE);
}
/*
* Implements a * b and stores the result in target; caller guarantees
* that a and b are <= MAX_FILTER_SIZE, and that target is a valid pointer.
* target must not be the same as a or b; for that case see
* l_intersection_in_a().
*/
void
{
int i, j;
if (SLIST_IS_EMPTY(a) || SLIST_IS_EMPTY(b))
return;
for (i = 0; i < a->sl_numsrc; i++) {
for (j = 0; j < b->sl_numsrc; j++) {
if (IN6_ARE_ADDR_EQUAL(
a->sl_addr[i];
break;
}
}
}
}
/*
* Implements a - b and stores the result in target; caller guarantees
* that a and b are <= MAX_FILTER_SIZE, and that target is a valid pointer.
* target must not be the same as a or b; for that case see l_difference_in_a().
*/
void
{
int i, j;
if (SLIST_IS_EMPTY(a))
return;
if (SLIST_IS_EMPTY(b)) {
return;
}
for (i = 0; i < a->sl_numsrc; i++) {
for (j = 0; j < b->sl_numsrc; j++) {
if (IN6_ARE_ADDR_EQUAL(
break;
}
}
if (!found) {
} else {
}
}
}
/*
* Removes addr from list a. Caller guarantees that addr is a valid
* pointer, and that a <= MAX_FILTER_SIZE. addr will only be removed
* once from the list; if it appears in the list multiple times, extra
* copies may remain.
*/
void
{
int i, mvsize;
if (SLIST_IS_EMPTY(a))
return;
for (i = 0; i < a->sl_numsrc; i++) {
a->sl_numsrc--;
mvsize);
break;
}
}
}
/*
* Make a copy of list a by allocating a new slist_t and copying only
* a->sl_numsrc addrs. Caller guarantees that a <= MAX_FILTER_SIZE.
* Return a pointer to the newly alloc'd list, or NULL if a is empty
* (no memory is alloc'd in this case).
*/
slist_t *
{
slist_t *b;
if (SLIST_IS_EMPTY(a))
return (NULL);
return (NULL);
l_copy(a, b);
return (b);
}
/*
* Copy the address list from slist a into slist b, overwriting anything
* that might already be in slist b. Assumes that a <= MAX_FILTER_SIZE
* and that b points to a properly allocated slist.
*/
void
{
if (SLIST_IS_EMPTY(a)) {
b->sl_numsrc = 0;
return;
}
a->sl_numsrc * sizeof (in6_addr_t));
}
/*
* Append to a any addrs in b that are not already in a (i.e. perform
* a + b and store the result in a). If b is empty, the function returns
* without taking any action.
*
* Caller guarantees that a and b are <= MAX_FILTER_SIZE, and that a
* and overflow are valid pointers.
*
* If an overflow occurs (a + b > MAX_FILTER_SIZE), a will contain the
* first MAX_FILTER_SIZE addresses of the union, and *overflow will be
* set to true. Otherwise, *overflow will be set to false.
*/
void
{
int i, j;
if (SLIST_IS_EMPTY(b))
return;
for (i = 0; i < b->sl_numsrc; i++) {
for (j = 0; j < a->sl_numsrc; j++) {
if (IN6_ARE_ADDR_EQUAL(
break;
}
}
if (!found) {
if (a->sl_numsrc == MAX_FILTER_SIZE) {
break;
} else {
}
}
}
}
/*
* Remove from list a any addresses that are not also in list b
* (i.e. perform a * b and store the result in a).
*
* Caller guarantees that a and b are <= MAX_FILTER_SIZE, and that
* a is a valid pointer.
*/
void
{
int i, j, shift;
if (SLIST_IS_EMPTY(b)) {
a->sl_numsrc = 0;
return;
}
shift = 0;
for (i = 0; i < a->sl_numsrc; i++) {
for (j = 0; j < b->sl_numsrc; j++) {
if (IN6_ARE_ADDR_EQUAL(
break;
}
}
if (!found)
shift++;
else if (shift > 0)
}
}
/*
* Remove from list a any addresses that are in list b (i.e. perform
* a - b and store the result in a).
*
* Caller guarantees that a and b are <= MAX_FILTER_SIZE. If either
* list is empty (or a null pointer), the function returns without
* taking any action.
*/
void
{
int i, j, shift;
if (SLIST_IS_EMPTY(a) || SLIST_IS_EMPTY(b))
return;
shift = 0;
for (i = 0; i < a->sl_numsrc; i++) {
for (j = 0; j < b->sl_numsrc; j++) {
if (IN6_ARE_ADDR_EQUAL(
break;
}
}
if (found)
shift++;
else if (shift > 0)
}
}
/*
* Wrapper function to alloc an slist_t.
*/
slist_t *
l_alloc()
{
slist_t *p;
if (p != NULL)
p->sl_numsrc = 0;
return (p);
}
/*
* Frees an slist_t structure. Provided for symmetry with l_alloc().
*/
void
{
mi_free(a);
}