Commit | Line | Data |
---|---|---|
794f2398 SE |
1 | /* Useful functions for dealing with collections of IP addresses */ |
2 | ||
7138d0c5 SE |
3 | #ifndef ipaddr_h |
4 | #define ipaddr_h | |
5 | ||
794f2398 SE |
6 | struct subnet { |
7 | uint32_t prefix; | |
8 | uint32_t mask; | |
1caa23ff | 9 | int len; |
794f2398 SE |
10 | }; |
11 | ||
12 | struct subnet_list { | |
1caa23ff IJ |
13 | int32_t entries; |
14 | int32_t alloc; | |
794f2398 SE |
15 | struct subnet *list; |
16 | }; | |
17 | ||
18 | struct iprange { | |
19 | uint32_t a,b; | |
20 | }; | |
21 | ||
22 | struct ipset { | |
1caa23ff IJ |
23 | int32_t l; /* Number of entries in list */ |
24 | int32_t a; /* Allocated space in list */ | |
794f2398 SE |
25 | struct iprange *d; |
26 | }; | |
7138d0c5 | 27 | |
794f2398 SE |
28 | extern struct subnet_list *subnet_list_new(void); |
29 | extern void subnet_list_free(struct subnet_list *a); | |
1caa23ff | 30 | extern void subnet_list_append(struct subnet_list *a, uint32_t prefix, int len); |
794f2398 SE |
31 | |
32 | static inline bool_t subnet_match(struct subnet s, uint32_t address) | |
33 | { | |
34 | return (s.prefix==(address&s.mask)); | |
35 | } | |
36 | ||
37 | extern struct ipset *ipset_new(void); | |
38 | extern void ipset_free(struct ipset *a); | |
39 | extern struct ipset *ipset_from_subnet(struct subnet s); | |
40 | extern struct ipset *ipset_from_subnet_list(struct subnet_list *l); | |
41 | extern struct ipset *ipset_union(struct ipset *a, struct ipset *b); | |
42 | extern struct ipset *ipset_intersection(struct ipset *a, struct ipset *b); | |
43 | extern struct ipset *ipset_complement(struct ipset *a); | |
44 | extern struct ipset *ipset_subtract(struct ipset *a, struct ipset *b); | |
45 | extern bool_t ipset_is_empty(struct ipset *a); | |
46 | extern bool_t ipset_contains_addr(struct ipset *a, uint32_t addr); | |
47 | extern bool_t ipset_is_subset(struct ipset *super, struct ipset *sub); | |
48 | extern struct subnet_list *ipset_to_subnet_list(struct ipset *is); | |
7138d0c5 SE |
49 | |
50 | extern string_t ipaddr_to_string(uint32_t addr); | |
794f2398 SE |
51 | extern string_t subnet_to_string(struct subnet sn); |
52 | ||
53 | extern struct ipset *string_list_to_ipset(list_t *l,struct cloc loc, | |
fe5e9cc4 | 54 | cstring_t module, cstring_t param); |
794f2398 | 55 | |
a094a1ba | 56 | extern uint32_t string_item_to_ipaddr(const item_t *i, cstring_t desc); |
7138d0c5 SE |
57 | |
58 | #endif /* ipaddr_h */ |