1 /* Useful functions for dealing with collections of IP addresses */
3 * This file is part of secnet.
4 * See README for full list of copyright holders.
6 * secnet is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version d of the License, or
9 * (at your option) any later version.
11 * secnet is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * version 3 along with secnet; if not, see
18 * https://www.gnu.org/licenses/gpl.html.
41 int32_t l
; /* Number of entries in list */
42 int32_t a
; /* Allocated space in list */
46 extern struct subnet_list
*subnet_list_new(void);
47 extern void subnet_list_free(struct subnet_list
*a
);
48 extern void subnet_list_append(struct subnet_list
*a
, uint32_t prefix
, int len
);
50 static inline bool_t
subnet_match(struct subnet s
, uint32_t address
)
52 return (s
.prefix
==(address
&s
.mask
));
55 extern struct ipset
*ipset_new(void);
56 extern void ipset_free(struct ipset
*a
);
57 extern struct ipset
*ipset_from_subnet(struct subnet s
);
58 extern struct ipset
*ipset_from_subnet_list(struct subnet_list
*l
);
59 extern struct ipset
*ipset_union(struct ipset
*a
, struct ipset
*b
);
60 extern struct ipset
*ipset_intersection(struct ipset
*a
, struct ipset
*b
);
61 extern struct ipset
*ipset_complement(struct ipset
*a
);
62 extern struct ipset
*ipset_subtract(struct ipset
*a
, struct ipset
*b
);
63 extern bool_t
ipset_is_empty(struct ipset
*a
);
64 extern bool_t
ipset_contains_addr(struct ipset
*a
, uint32_t addr
);
65 extern bool_t
ipset_is_subset(struct ipset
*super
, struct ipset
*sub
);
66 extern struct subnet_list
*ipset_to_subnet_list(struct ipset
*is
);
68 extern string_t
ipaddr_to_string(uint32_t addr
);
69 extern string_t
subnet_to_string(struct subnet sn
);
71 extern struct ipset
*string_list_to_ipset(list_t
*l
,struct cloc loc
,
72 cstring_t module
, cstring_t param
);
74 extern uint32_t string_item_to_ipaddr(const item_t
*i
, cstring_t desc
);