Revision 5e173e9f filter/trie.c

View differences:

filter/trie.c
109 109
/**
110 110
 * trie_add_prefix
111 111
 * @t: trie to add to
112
 * @px: prefix address
113
 * @plen: prefix length
112
 * @net: IP network prefix
114 113
 * @l: prefix lower bound
115 114
 * @h: prefix upper bound
116 115
 *
117
 * Adds prefix (prefix pattern) @px/@plen to trie @t.  @l and @h are lower
116
 * Adds prefix (prefix pattern) @n to trie @t.  @l and @h are lower
118 117
 * and upper bounds on accepted prefix lengths, both inclusive.
119 118
 * 0 <= l, h <= 32 (128 for IPv6).
120 119
 *
......
124 123
 */
125 124

  
126 125
void *
127
trie_add_prefix(struct f_trie *t, ip_addr px, int plen, int l, int h)
126
trie_add_prefix(struct f_trie *t, net_addr *net, uint l, uint h)
128 127
{
128
  ip_addr px = net_prefix(net);
129
  uint plen = net_pxlen(net);
130

  
131
  if (net->type == NET_IP4)
132
  {
133
    const uint delta = IP6_MAX_PREFIX_LENGTH - IP4_MAX_PREFIX_LENGTH;
134
    plen += delta;
135
    l += delta;
136
    h += delta;
137
  }
138

  
129 139
  if (l == 0)
130 140
    t->zero = 1;
131 141
  else
......
140 150
  struct f_trie_node *o = NULL;
141 151
  struct f_trie_node *n = t->root;
142 152

  
143
  while(n)
153
  while (n)
144 154
    {
145 155
      ip_addr cmask = ipa_and(n->mask, pmask);
146 156

  
......
196 206
  return a;
197 207
}
198 208

  
199
/**
200
 * trie_match_prefix
201
 * @t: trie
202
 * @px: prefix address
203
 * @plen: prefix length
204
 *
205
 * Tries to find a matching prefix pattern in the trie such that
206
 * prefix @px/@plen matches that prefix pattern. Returns 1 if there
207
 * is such prefix pattern in the trie.
208
 */
209
int
209
static int
210 210
trie_match_prefix(struct f_trie *t, ip_addr px, int plen)
211 211
{
212 212
  ip_addr pmask = ipa_mkmask(plen);
......
241 241
  return 0;
242 242
}
243 243

  
244
/**
245
 * trie_match_net
246
 * @t: trie
247
 * @n: net address
248
 *
249
 * Tries to find a matching net in the trie such that
250
 * prefix @n matches that prefix pattern. Returns 1 if there
251
 * is such prefix pattern in the trie.
252
 */
253
int
254
trie_match_net(struct f_trie *t, const net_addr *n)
255
{
256
  int add = 0;
257
  switch (n->type) {
258
    case NET_IP4:
259
    case NET_VPN4: add = IP6_MAX_PREFIX_LENGTH - IP4_MAX_PREFIX_LENGTH;
260
  }
261

  
262
  return trie_match_prefix(t, net_prefix(n), net_pxlen(n) + add);
263
}
264

  
244 265
static int
245 266
trie_node_same(struct f_trie_node *t1, struct f_trie_node *t2)
246 267
{

Also available in: Unified diff