/usr/include/libcorkipset/ipset.h is in libcorkipset-dev 1.1.1+20150311-8.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /* -*- coding: utf-8 -*-
* ----------------------------------------------------------------------
* Copyright © 2009-2012, RedJack, LLC.
* All rights reserved.
*
* Please see the LICENSE.txt file in this distribution for license
* details.
* ----------------------------------------------------------------------
*/
#ifndef IPSET_IPSET_H
#define IPSET_IPSET_H
#include <stdio.h>
#include <libcork/core.h>
#include <libcork/ds.h>
#include <libcorkipset/bdd/nodes.h>
struct ip_set {
struct ipset_node_cache *cache;
ipset_node_id set_bdd;
};
struct ip_map {
struct ipset_node_cache *cache;
ipset_node_id map_bdd;
ipset_node_id default_bdd;
};
/*---------------------------------------------------------------------
* General functions
*/
int
ipset_init_library(void);
/*---------------------------------------------------------------------
* IP set functions
*/
void
ipset_init(struct ip_set *set);
void
ipset_done(struct ip_set *set);
struct ip_set *
ipset_new(void);
void
ipset_free(struct ip_set *set);
bool
ipset_is_empty(const struct ip_set *set);
bool
ipset_is_equal(const struct ip_set *set1, const struct ip_set *set2);
size_t
ipset_memory_size(const struct ip_set *set);
int
ipset_save(FILE *stream, const struct ip_set *set);
int
ipset_save_to_stream(struct cork_stream_consumer *stream,
const struct ip_set *set);
int
ipset_save_dot(FILE *stream, const struct ip_set *set);
struct ip_set *
ipset_load(FILE *stream);
bool
ipset_ipv4_add(struct ip_set *set, struct cork_ipv4 *elem);
bool
ipset_ipv4_add_network(struct ip_set *set, struct cork_ipv4 *elem,
unsigned int cidr_prefix);
bool
ipset_ipv4_remove(struct ip_set *set, struct cork_ipv4 *elem);
bool
ipset_ipv4_remove_network(struct ip_set *set, struct cork_ipv4 *elem,
unsigned int cidr_prefix);
bool
ipset_contains_ipv4(const struct ip_set *set, struct cork_ipv4 *elem);
bool
ipset_ipv6_add(struct ip_set *set, struct cork_ipv6 *elem);
bool
ipset_ipv6_add_network(struct ip_set *set, struct cork_ipv6 *elem,
unsigned int cidr_prefix);
bool
ipset_ipv6_remove(struct ip_set *set, struct cork_ipv6 *elem);
bool
ipset_ipv6_remove_network(struct ip_set *set, struct cork_ipv6 *elem,
unsigned int cidr_prefix);
bool
ipset_contains_ipv6(const struct ip_set *set, struct cork_ipv6 *elem);
bool
ipset_ip_add(struct ip_set *set, struct cork_ip *addr);
bool
ipset_ip_add_network(struct ip_set *set, struct cork_ip *addr,
unsigned int cidr_prefix);
bool
ipset_ip_remove(struct ip_set *set, struct cork_ip *addr);
bool
ipset_ip_remove_network(struct ip_set *set, struct cork_ip *addr,
unsigned int cidr_prefix);
bool
ipset_contains_ip(const struct ip_set *set, struct cork_ip *elem);
/* An internal state type used by the ipset_iterator_multiple_expansion_state
* field. */
enum ipset_iterator_state {
IPSET_ITERATOR_NORMAL = 0,
IPSET_ITERATOR_MULTIPLE_IPV4,
IPSET_ITERATOR_MULTIPLE_IPV6
};
/* An iterator that returns all of the IP addresses that have a given value in
* an IP set or map. */
struct ipset_iterator {
/* The address of the current IP network in the iterator. */
struct cork_ip addr;
/* The netmask of the current IP network in the iterator, given as a
* CIDR prefix. For a single IP address, this will be 32 or 128. */
unsigned int cidr_prefix;
/* Whether the current assignment needs to be expanded a second
* time.
*
* We have to expand IPv4 and IPv6 assignments separately, since the
* set of variables to turn into address bits is different.
* Unfortunately, a BDD assignment can contain both IPv4 and IPv6
* addresses, if variable 0 is EITHER. (This is trivially true for
* the empty set, for instance.) In this case, we have to
* explicitly set variable 0 to TRUE, expand it as IPv4, and then
* set it to FALSE, and expand it as IPv6. This variable tells us
* whether we're in an assignment that needs to be expanded twice,
* and if so, which expansion we're currently in.
*/
enum ipset_iterator_state multiple_expansion_state;
/* An iterator for retrieving each assignment in the set's BDD. */
struct ipset_bdd_iterator *bdd_iterator;
/* An iterator for expanding each assignment into individual IP
* addresses. */
struct ipset_expanded_assignment *assignment_iterator;
/* Whether there are any more IP addresses in this iterator. */
bool finished;
/* The desired value for each IP address. */
bool desired_value;
/* Whether to summarize the contents of the IP set as networks,
* where possible. */
bool summarize;
};
struct ipset_iterator *
ipset_iterate(struct ip_set *set, bool desired_value);
struct ipset_iterator *
ipset_iterate_networks(struct ip_set *set, bool desired_value);
void
ipset_iterator_free(struct ipset_iterator *iterator);
void
ipset_iterator_advance(struct ipset_iterator *iterator);
/*---------------------------------------------------------------------
* IP map functions
*/
void
ipmap_init(struct ip_map *map, int default_value);
void
ipmap_done(struct ip_map *map);
struct ip_map *
ipmap_new(int default_value);
void
ipmap_free(struct ip_map *map);
bool
ipmap_is_empty(const struct ip_map *map);
bool
ipmap_is_equal(const struct ip_map *map1, const struct ip_map *map2);
size_t
ipmap_memory_size(const struct ip_map *map);
int
ipmap_save(FILE *stream, const struct ip_map *map);
int
ipmap_save_to_stream(struct cork_stream_consumer *stream,
const struct ip_map *map);
struct ip_map *
ipmap_load(FILE *stream);
void
ipmap_ipv4_set(struct ip_map *map, struct cork_ipv4 *elem, int value);
void
ipmap_ipv4_set_network(struct ip_map *map, struct cork_ipv4 *elem,
unsigned int cidr_prefix, int value);
int
ipmap_ipv4_get(struct ip_map *map, struct cork_ipv4 *elem);
void
ipmap_ipv6_set(struct ip_map *map, struct cork_ipv6 *elem, int value);
void
ipmap_ipv6_set_network(struct ip_map *map, struct cork_ipv6 *elem,
unsigned int cidr_prefix, int value);
int
ipmap_ipv6_get(struct ip_map *map, struct cork_ipv6 *elem);
void
ipmap_ip_set(struct ip_map *map, struct cork_ip *addr, int value);
void
ipmap_ip_set_network(struct ip_map *map, struct cork_ip *addr,
unsigned int cidr_prefix, int value);
int
ipmap_ip_get(struct ip_map *map, struct cork_ip *addr);
#endif /* IPSET_IPSET_H */
|