Revision 04632fd7

View differences:

conf/confbase.Y
41 41
  ip_addr a;
42 42
  ip4_addr ip4;
43 43
  ip6_addr ip6;
44
  net_addr_union net;
44
  net_addr net;
45 45
  net_addr *net_ptr;
46 46
  struct symbol *s;
47 47
  char *t;
......
76 76
%token <t> TEXT
77 77
%type <iface> ipa_scope
78 78

  
79
%type <i> expr bool pxlen4 pxlen6
79
%type <i> expr bool pxlen4
80 80
%type <i32> expr_us
81 81
%type <time> datetime
82
%type <a> ipa ipa_raw
83
%type <net> net_ip4 net_ip6 net_ip net_or_ipa
84
%type <net_ptr> net_any
82
%type <a> ipa
83
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
84
%type <net_ptr> net_ net_any
85 85

  
86 86
%type <t> text opttext
87 87

  
......
151 151
 | /* Silence means agreement */ { $$ = 1; }
152 152
 ;
153 153

  
154
/* Addresses, prefixes and netmasks */
155 154

  
156
ipa_raw:
157
   IP4 { $$ = ipa_from_ip4($1); }
158
 | IP6 { $$ = ipa_from_ip6($1); }
159
 ;
155
/* Addresses */
160 156

  
161 157
ipa:
162
   ipa_raw
158
   IP4 { $$ = ipa_from_ip4($1); }
159
 | IP6 { $$ = ipa_from_ip6($1); }
163 160
 | SYM {
164 161
     if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
165 162
     $$ = SYM_VAL($1).ip;
......
172 169
 ;
173 170

  
174 171

  
175
/* XXXX - symbols and tests */
172
/* Networks - internal */
176 173

  
177
net_ip4: IP4 pxlen4 { $$.ip4 = NET_ADDR_IP4($1, $2); }
174
pxlen4:
175
   '/' NUM {
176
     if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
177
     $$ = $2;
178
   }
179
 | ':' IP4 {
180
     $$ = ip4_masklen($2);
181
     if ($$ == 255) cf_error("Invalid netmask %I", $2); /* XXXX */
182
   }
183
 ;
178 184

  
179
net_ip6: IP6 pxlen6 { $$.ip6 = NET_ADDR_IP6($1, $2); }
185
net_ip4_: IP4 pxlen4
186
{
187
  net_fill_ip4(&($$), $1, $2);
188
  if (!net_validate_ip4((net_addr_ip4 *) &($$)))
189
    cf_error("Invalid IPv4 prefix");
190
};
180 191

  
181
net_ip: net_ip4 | net_ip6 ;
192
net_ip6_: IP6 '/' NUM
193
{
194
  net_fill_ip6(&($$), $1, $3);
195
  if ($3 < 0 || $3 > IP6_MAX_PREFIX_LENGTH)
196
    cf_error("Invalid prefix length %d", $3);
197
  if (!net_validate_ip6((net_addr_ip6 *) &($$)))
198
    cf_error("Invalid IPv6 prefix");
199
};
182 200

  
183
net_any: net_ip { $$ = cfg_alloc($1.n.length); net_copy($$, &($1.n)); }
201
net_ip_: net_ip4_ | net_ip6_ ;
184 202

  
185
net_or_ipa:
186
   net_ip4
187
 | net_ip6
188
 | IP4 { $$.ip4 = NET_ADDR_IP4($1, IP4_MAX_PREFIX_LENGTH); }
189
 | IP6 { $$.ip6 = NET_ADDR_IP6($1, IP6_MAX_PREFIX_LENGTH); }
190
 ;
203
net_: net_ip_ { $$ = cfg_alloc($1.length); net_copy($$, &($1)); } ;
191 204

  
192 205

  
193
pxlen4:
194
   '/' expr {
195
     if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
196
     $$ = $2;
206
/* Networks - regular */
207

  
208
net_ip6:
209
   net_ip6_
210
 | SYM {
211
     if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
212
       cf_error("IPv6 network expected");
213
     $$ = * SYM_VAL($1).net;
197 214
   }
198
 | ':' IP4 {
199
     $$ = ip4_masklen($2);
200
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
215
 ;
216

  
217
net_ip:
218
   net_ip_
219
 | SYM {
220
     if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
221
       cf_error("IP network expected");
222
     $$ = * SYM_VAL($1).net;
201 223
   }
202 224
 ;
203 225

  
204
pxlen6:
205
   '/' expr {
206
     if ($2 < 0 || $2 > IP6_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
207
     $$ = $2;
226
net_any:
227
   net_
228
 | SYM {
229
     if ($1->class != (SYM_CONSTANT | T_NET))
230
       cf_error("Network expected");
231
     $$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
232
   }
233
 ;
234

  
235
net_or_ipa:
236
   net_ip4_
237
 | net_ip6_
238
 | IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
239
 | IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
240
 | SYM {
241
     if ($1->class == (SYM_CONSTANT | T_IP))
242
       net_fill_ip_host(&($$), SYM_VAL($1).ip);
243
     else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
244
       $$ = * SYM_VAL($1).net;
245
     else
246
       cf_error("IP address or network expected");
208 247
   }
209 248
 ;
210 249

  
250

  
211 251
datetime:
212 252
   TEXT {
213 253
     $$ = tm_parse_datetime($1);
filter/config.Y
475 475
 * Complex types, their bison value is struct f_val
476 476
 */
477 477
fipa:
478
   ipa_raw %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = $1; }
478
   IP4 %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = ipa_from_ip4($1); }
479
 | IP6 %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = ipa_from_ip6($1); }
479 480
 ;
480 481

  
481 482

  
......
571 572
 ;
572 573

  
573 574
fprefix:
574
   net_ip	{ $$.net = $1; $$.lo = $1.n.pxlen; $$.hi = $1.n.pxlen; }
575
 | net_ip '+'	{ $$.net = $1; $$.lo = $1.n.pxlen; $$.hi = net_max_prefix_length[$1.n.type]; }
576
 | net_ip '-'	{ $$.net = $1; $$.lo = 0; $$.hi = $1.n.pxlen; }
577
 | net_ip '{' NUM ',' NUM '}' {
575
   net_ip_	{ $$.net = $1; $$.lo = $1.pxlen; $$.hi = $1.pxlen; }
576
 | net_ip_ '+'	{ $$.net = $1; $$.lo = $1.pxlen; $$.hi = net_max_prefix_length[$1.type]; }
577
 | net_ip_ '-'	{ $$.net = $1; $$.lo = 0; $$.hi = $1.pxlen; }
578
 | net_ip_ '{' NUM ',' NUM '}' {
578 579
     $$.net = $1; $$.lo = $3; $$.hi = $5;
579
     if ((0 > $3) || ($3 > $5) || ($5 > net_max_prefix_length[$1.n.type]))
580
     if ((0 > $3) || ($3 > $5) || ($5 > net_max_prefix_length[$1.type]))
580 581
       cf_error("Invalid prefix pattern range: {%d, %d}", $3, $5);
581 582
   }
582 583
 ;
583 584

  
584 585
fprefix_set:
585
   fprefix { $$ = f_new_trie(cfg_mem, sizeof(struct f_trie_node)); trie_add_prefix($$, &($1.net.n), $1.lo, $1.hi); }
586
 | fprefix_set ',' fprefix { $$ = $1; trie_add_prefix($$, &($3.net.n), $3.lo, $3.hi); }
586
   fprefix { $$ = f_new_trie(cfg_mem, sizeof(struct f_trie_node)); trie_add_prefix($$, &($1.net), $1.lo, $1.hi); }
587
 | fprefix_set ',' fprefix { $$ = $1; trie_add_prefix($$, &($3.net), $3.lo, $3.hi); }
587 588
 ;
588 589

  
589 590
switch_body: /* EMPTY */ { $$ = NULL; }
......
635 636
 | FALSE  { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 0;  }
636 637
 | TEXT   { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_STRING; $$->a2.p = $1; }
637 638
 | fipa	  { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
638
 | net_any { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; val->type = T_NET; val->val.net = $1; $$->a1.p = val; }
639
 | net_   { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; val->type = T_NET; val->val.net = $1; $$->a1.p = val; }
639 640
 | '[' set_items ']' { DBG( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_SET; $$->a2.p = build_tree($2); DBG( "ook\n" ); }
640 641
 | '[' fprefix_set ']' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_PREFIX_SET;  $$->a2.p = $2; }
641 642
 | ENUM	  { $$ = f_new_inst(); $$->code = 'c'; $$->aux = $1 >> 16; $$->a2.i = $1 & 0xffff; }
filter/filter.h
39 39
};
40 40

  
41 41
struct f_prefix {
42
  net_addr_union net;
42
  net_addr net;
43 43
  u8 lo, hi;
44 44
};
45 45

  
filter/test.conf
16 16
define p23 = (2, 3);
17 17
define ip1222 = 1.2.2.2;
18 18

  
19
define net10 = 10.0.0.0/8;
20
define netdoc = 2001:db8::/32;
21

  
22

  
19 23
function onef(int a)
20 24
{
21 25
	return 1;
......
55 59
	return 15;
56 60
}
57 61

  
62
/*
58 63
roa table rl
59 64
{
60 65
	roa 10.110.0.0/16 max 16 as 1000;
......
80 85
	      " ", roa_check(rl, 10.130.30.0/24, 3000) = ROA_INVALID,
81 86
	      " ", roa_check(rl, 10.130.130.0/24, 3000) = ROA_VALID;
82 87
}
88
*/
83 89

  
84 90
function path_test()
85 91
bgpmask pm1;
......
232 238
function test_pxset(prefix set pxs)
233 239
{
234 240
	print pxs;
235
	print "  must be true:  ",	10.0.0.0/8  ~ pxs, ",", 10.0.0.0/10  ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",",
241
	print "  must be true:  ",	net10  ~ pxs, ",", 10.0.0.0/10  ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",",
236 242
					20.0.0.0/24 ~ pxs, ",", 20.0.40.0/24 ~ pxs, ",", 20.0.0.0/26 ~ pxs, ",",
237 243
					20.0.100.0/26 ~ pxs, ",", 20.0.0.0/28 ~ pxs, ",", 20.0.255.0/28 ~ pxs;
238 244
	print "  must be false: ",	10.0.0.0/7 ~ pxs,  ",", 10.0.0.0/13 ~ pxs, ",", 10.0.0.0/16 ~ pxs, ",",
......
312 318

  
313 319
	px = 1.2.0.0/18;
314 320
	print "Testing prefixes: 1.2.0.0/18 = ", px;
315
	print "  must be true:  ",	192.168.0.0/16 ~ 192.168.0.0/16, " ", 192.168.0.0/17 ~ 192.168.0.0/16, " ", 192.168.254.0/24 ~ 192.168.0.0/16;
316
	print "  must be false: ",	192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16;
321
	print "  must be true:  ",	192.168.0.0/16 ~ 192.168.0.0/16, " ", 192.168.0.0/17 ~ 192.168.0.0/16, " ", 192.168.254.0/24 ~ 192.168.0.0/16, " ", netdoc ~ 2001::/16;
322
	print "  must be false: ",	192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16, " ", px ~ netdoc;
317 323

  
318 324
	p = 127.1.2.3;
319 325
	print "Testing mask : 127.0.0.0 = ", p.mask(8);
320
	
326

  
321 327
	pp = (1, 2);
322 328
	print "Testing pairs: (1,2) = ", (1,2), " = ", pp, " = ", (1,1+1), " = ", 'mkpair-a'(2);
323 329
	print "  must be true:  ", (1,2) = (1,1+1);
......
397 403
	print "1.2.3.4 = ", onetwo;
398 404

  
399 405
	i = 4200000000;
400
	print "4200000000 = ", i, "   false: ", i = 4200000000, " ", i > 4100000000, "   false: ", i > 4250000000;
406
	print "4200000000 = ", i, "    true: ", i = 4200000000, " ", i > 4100000000, "   false: ", i > 4250000000;
401 407

  
402 408
	test_undef(2);
403 409
	test_undef(3);
lib/ip.c
67 67
    if (a->addr[i] != ~0U)
68 68
    {
69 69
      j = u32_masklen(a->addr[i]);
70
      if (j < 0)
70
      if (j == 255)
71 71
	return j;
72 72
      n += j;
73 73
      while (++i < 4)
lib/ip.h
91 91

  
92 92
#define ipa_is_ip4(a) ip6_is_v4mapped(a)
93 93

  
94
#define IPA_NONE4 ipa_from_ip4(IP4_NONE)
95
#define IPA_NONE6 ipa_from_ip6(IP6_NONE)
96

  
94 97

  
95 98
/*
96 99
 *	Public constructors
......
180 183
 *	Hash and compare functions
181 184
 */
182 185

  
183
static inline uint ip4_hash(ip4_addr a)
184
{
185
  /* Returns a 16-bit value */
186
  u32 x = _I(a);
187
  x ^= x >> 16;
188
  x ^= x << 10;
189
  return x & 0xffff;
190
}
191

  
192
static inline u32 ip4_hash32(ip4_addr a)
186
static inline u32 ip4_hash(ip4_addr a)
193 187
{
194 188
  /* Returns a 32-bit value, although low-order bits are not mixed */
195 189
  u32 x = _I(a);
......
198 192
  return x;
199 193
}
200 194

  
201
static inline uint ip6_hash(ip6_addr a)
202
{
203
  /* Returns a 16-bit hash key */
204
  u32 x = _I0(a) ^ _I1(a) ^ _I2(a) ^ _I3(a);
205
  return (x ^ (x >> 16) ^ (x >> 8)) & 0xffff;
206
}
207

  
208
static inline u32 ip6_hash32(ip6_addr a)
195
static inline u32 ip6_hash(ip6_addr a)
209 196
{
210 197
  /* Returns a 32-bit hash key, although low-order bits are not mixed */
211 198
  u32 x = _I0(a) ^ _I1(a) ^ _I2(a) ^ _I3(a);
......
218 205
int ip6_compare(ip6_addr a, ip6_addr b);
219 206

  
220 207
#define ipa_hash(x) ip6_hash(x)
221
#define ipa_hash32(x) ip6_hash32(x)
222 208
#define ipa_compare(x,y) ip6_compare(x,y)
223 209

  
224 210

  
lib/net.h
107 107
    net_fill_ip6(a, ipa_to_ip6(prefix), pxlen);
108 108
}
109 109

  
110
static inline void net_fill_ip_host(net_addr *a, ip_addr prefix)
111
{
112
  if (ipa_is_ip4(prefix))
113
    net_fill_ip4(a, ipa_to_ip4(prefix), IP4_MAX_PREFIX_LENGTH);
114
  else
115
    net_fill_ip6(a, ipa_to_ip6(prefix), IP6_MAX_PREFIX_LENGTH);
116
}
117

  
118
static inline int net_is_ip(const net_addr *a)
119
{ return (a->type == NET_IP4) || (a->type == NET_IP6); }
120

  
110 121

  
111 122
static inline ip4_addr net4_prefix(const net_addr *a)
112 123
{ return ((net_addr_ip4 *) a)->prefix; }
......
199 210

  
200 211

  
201 212
static inline u32 net_hash_ip4(const net_addr_ip4 *n)
202
{ return ip4_hash32(n->prefix) ^ ((u32) n->pxlen << 26); }
213
{ return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
203 214

  
204 215
static inline u32 net_hash_ip6(const net_addr_ip6 *n)
205
{ return ip6_hash32(n->prefix) ^ ((u32) n->pxlen << 26); }
216
{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26); }
206 217

  
207 218
/* XXXX */
208
static inline u32 u64_hash(u32 a)
219
static inline u32 u64_hash(u64 a)
209 220
{ return u32_hash(a); }
210 221

  
211 222
static inline u32 net_hash_vpn4(const net_addr_vpn4 *n)
212
{ return ip4_hash32(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
223
{ return ip4_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
213 224

  
214 225
static inline u32 net_hash_vpn6(const net_addr_vpn6 *n)
215
{ return ip6_hash32(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
226
{ return ip6_hash(n->prefix) ^ ((u32) n->pxlen << 26) ^ u64_hash(n->rd); }
216 227

  
217 228

  
218 229
static inline int net_validate_ip4(const net_addr_ip4 *n)
nest/config.Y
30 30
  struct iface_patt_node *pn;
31 31

  
32 32
  WALK_LIST(pn, this_ipatt->ipn_list)
33
    if (!pn->pattern || pn->prefix.pxlen) /* XXXX */
33
    if (!pn->pattern || pn->prefix.type)
34 34
      cf_error("Interface name/mask expected, not IP prefix");
35 35
}
36 36

  
......
85 85

  
86 86
CF_ADDTO(conf, rtrid)
87 87

  
88
rtrid: 
88
rtrid:
89 89
   ROUTER ID idval ';' { new_config->router_id = $3; }
90 90
 | ROUTER ID FROM iface_patt ';' { new_config->router_id_from = this_ipatt; }
91 91
 ;
......
261 261
 ;
262 262

  
263 263
iface_patt_node_body:
264
   TEXT { this_ipn->pattern = $1; net_fill_ip6(&this_ipn->prefix, IP6_NONE, 0); /* XXXX */ }
265
 | opttext net_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.n; }
264
   TEXT { this_ipn->pattern = $1; /* this_ipn->prefix stays zero */ }
265
 | opttext net_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2; }
266 266
 ;
267 267

  
268 268
iface_negate:
......
271 271
 ;
272 272

  
273 273
iface_patt_node:
274
   iface_patt_node_init iface_negate iface_patt_node_body 
274
   iface_patt_node_init iface_negate iface_patt_node_body
275 275
 ;
276 276

  
277 277

  
......
450 450
   }
451 451
 | r_args net_any {
452 452
     $$ = $1;
453
     if ($$->prefix) cf_error("Only one prefix expected");
454
     $$->prefix = $2;
453
     if ($$->addr) cf_error("Only one prefix expected");
454
     $$->addr = $2;
455 455
   }
456 456
 | r_args FOR net_or_ipa {
457 457
     $$ = $1;
458
     if ($$->prefix) cf_error("Only one prefix expected");
459
     $$->prefix = &($3.n);
458
     if ($$->addr) cf_error("Only one prefix expected");
460 459
     $$->show_for = 1;
460
     $$->addr = cfg_alloc($3.length);
461
     net_copy($$->addr, &($3));
461 462
   }
462 463
 | r_args TABLE SYM {
463 464
     $$ = $1;
nest/neighbor.c
45 45
#include "lib/resource.h"
46 46

  
47 47
#define NEIGH_HASH_SIZE 256
48
#define NEIGH_HASH_OFFSET 24
48 49

  
49 50
static slab *neigh_slab;
50 51
static list sticky_neigh_list, neigh_hash_table[NEIGH_HASH_SIZE];
......
52 53
static inline uint
53 54
neigh_hash(struct proto *p, ip_addr *a)
54 55
{
55
  return (p->hash_key ^ ipa_hash(*a)) & (NEIGH_HASH_SIZE-1);
56
  return (p->hash_key ^ ipa_hash(*a)) >> NEIGH_HASH_OFFSET;
56 57
}
57 58

  
58 59
static int
nest/route.h
56 56
  struct fib_node **hash_table;		/* Node hash table */
57 57
  uint hash_size;			/* Number of hash table entries (a power of two) */
58 58
  uint hash_order;			/* Binary logarithm of hash_size */
59
  uint hash_shift;			/* 16 - hash_log */
59
  uint hash_shift;			/* 32 - hash_order */
60 60
  uint addr_type;			/* Type of address data stored in fib (NET_*) */
61 61
  uint node_size;	/* XXXX */
62 62
  uint node_offset;	/* XXXX */
......
277 277
static inline net *net_find(rtable *tab, net_addr *addr) { return (net *) fib_find(&tab->fib, addr); }
278 278
static inline net *net_get(rtable *tab, net_addr *addr) { return (net *) fib_get(&tab->fib, addr); }
279 279

  
280
static inline net *net_find_ipa(rtable *tab, ip_addr px, uint pxlen)
281
{ net_addr addr; net_fill_ipa(&addr, px, pxlen); return (net *) fib_find(&tab->fib, &addr); }
282
static inline net *net_get_ipa(rtable *tab, ip_addr px, uint pxlen)
283
{ net_addr addr; net_fill_ipa(&addr, px, pxlen); return (net *) fib_get(&tab->fib, &addr); }
284

  
285 280
rte *rte_find(net *net, struct rte_src *src);
286 281
rte *rte_get_temp(struct rta *);
287 282
void rte_update2(struct announce_hook *ah, net *net, rte *new, struct rte_src *src);
......
313 308
}
314 309

  
315 310
struct rt_show_data {
316
  net_addr *prefix;
311
  net_addr *addr;
317 312
  rtable *table;
318 313
  struct filter *filter;
319 314
  int verbose;
nest/rt-attr.c
195 195
 *	Multipath Next Hop
196 196
 */
197 197

  
198
static inline uint
198
static inline u32
199 199
mpnh_hash(struct mpnh *x)
200 200
{
201
  uint h = 0;
201
  u32 h = 0;
202 202
  for (; x; x = x->next)
203 203
    h ^= ipa_hash(x->gw);
204 204

  
......
1008 1008
static inline uint
1009 1009
rta_hash(rta *a)
1010 1010
{
1011
  return (((uint) (uintptr_t) a->src) ^ ipa_hash(a->gw) ^
1012
	  mpnh_hash(a->nexthops) ^ ea_hash(a->eattrs)) & 0xffff;
1011
  /* XXXX fully convert to u32 hashing */
1012
  return (((uint) (uintptr_t) a->src) ^ (ipa_hash(a->gw) >> 16) ^
1013
	  (mpnh_hash(a->nexthops) >> 16) ^ ea_hash(a->eattrs)) & 0xffff;
1013 1014
}
1014 1015

  
1015 1016
static inline int
nest/rt-fib.c
43 43
#define HASH_DEF_ORDER 10
44 44
#define HASH_HI_MARK *4
45 45
#define HASH_HI_STEP 2
46
#define HASH_HI_MAX 16			/* Must be at most 16 */
46
#define HASH_HI_MAX 16
47 47
#define HASH_LO_MARK /5
48 48
#define HASH_LO_STEP 2
49 49
#define HASH_LO_MIN 10
......
266 266
  return b;
267 267
}
268 268

  
269
static void *
270
fib_route_ip4(struct fib *f, const net_addr *n0)
269
static inline void *
270
fib_route_ip4(struct fib *f, net_addr_ip4 *n)
271 271
{
272
  net_addr net;
273
  net_addr_ip4 *n = (net_addr_ip4 *) &net;
274
  void *b;
272
  void *r;
275 273

  
276
  net_copy(&net, n0);
277
  while (!(b = fib_find(f, &net)) && (n->pxlen > 0))
274
  while (!(r = fib_find(f, (net_addr *) n)) && (n->pxlen > 0))
278 275
  {
279 276
    n->pxlen--;
280 277
    ip4_clrbit(&n->prefix, n->pxlen);
281 278
  }
282 279

  
283
  return b;
280
  return r;
284 281
}
285 282

  
286
static void *
287
fib_route_ip6(struct fib *f, const net_addr *n0)
283
static inline void *
284
fib_route_ip6(struct fib *f, net_addr_ip6 *n)
288 285
{
289
  net_addr net;
290
  net_addr_ip6 *n = (net_addr_ip6 *) &net;
291
  void *b;
286
  void *r;
292 287

  
293
  net_copy(&net, n0);
294
  while (!(b = fib_find(f, &net)) && (n->pxlen > 0))
288
  while (!(r = fib_find(f, (net_addr *) n)) && (n->pxlen > 0))
295 289
  {
296 290
    n->pxlen--;
297 291
    ip6_clrbit(&n->prefix, n->pxlen);
298 292
  }
299 293

  
300
  return b;
294
  return r;
301 295
}
302 296

  
303 297
/**
......
314 308
{
315 309
  ASSERT(f->addr_type == n->type);
316 310

  
311
  net_addr *n0 = alloca(n->length);
312
  net_copy(n0, n);
313

  
317 314
  switch (n->type)
318 315
  {
319 316
  case NET_IP4:
320 317
  case NET_VPN4:
321
    return fib_route_ip4(f, n);
318
    return fib_route_ip4(f, (net_addr_ip4 *) n0);
322 319

  
323 320
  case NET_IP6:
324 321
  case NET_VPN6:
325
    return fib_route_ip6(f, n);
322
    return fib_route_ip6(f, (net_addr_ip6 *) n0);
326 323

  
327 324
  default:
328 325
    return NULL;
329 326
  }
330 327
}
331 328

  
329

  
332 330
static inline void
333 331
fib_merge_readers(struct fib_iterator *i, struct fib_node *to)
334 332
{
......
398 396
		}
399 397
	      fib_merge_readers(it, l);
400 398
	    }
401
	  sl_free(f->fib_slab, e);
399

  
400
	  if (f->fib_slab)
401
	    sl_free(f->fib_slab, E);
402
	  else
403
	    mb_free(E);
404

  
402 405
	  if (f->entries-- < f->entries_min)
403 406
	    fib_rehash(f, -HASH_LO_STEP);
404 407
	  return;
nest/rt-table.c
68 68
  return mta ? mta(rt, rte_update_pool) : NULL;
69 69
}
70 70

  
71

  
71 72
/* Like fib_route(), but skips empty net entries */
72
/*
73
static net *
74
net_route(rtable *tab, ip_addr a, int len)
73
static inline void *
74
net_route_ip4(struct fib *f, net_addr_ip4 *n)
75 75
{
76
  ip_addr a0;
77
  net *n;
76
  net *r;
78 77

  
79
  while (len >= 0)
80
    {
81
      a0 = ipa_and(a, ipa_mkmask(len));
82
      n = fib_find(&tab->fib, &a0, len);
83
      if (n && rte_is_valid(n->routes))
84
	return n;
85
      len--;
86
    }
87
  return NULL;
78
  while (r = fib_find(f, (net_addr *) n),
79
	 !(r && rte_is_valid(r->routes)) && (n->pxlen > 0))
80
  {
81
    n->pxlen--;
82
    ip4_clrbit(&n->prefix, n->pxlen);
83
  }
84

  
85
  return r;
86
}
87

  
88
static inline void *
89
net_route_ip6(struct fib *f, net_addr_ip6 *n)
90
{
91
  net *r;
92

  
93
  while (r = fib_find(f, (net_addr *) n),
94
	 !(r && rte_is_valid(r->routes)) && (n->pxlen > 0))
95
  {
96
    n->pxlen--;
97
    ip6_clrbit(&n->prefix, n->pxlen);
98
  }
99

  
100
  return r;
101
}
102

  
103
void *
104
net_route(rtable *tab, const net_addr *n)
105
{
106
  ASSERT(f->addr_type == n->type);
107

  
108
  net_addr *n0 = alloca(n->length);
109
  net_copy(n0, n);
110

  
111
  switch (n->type)
112
  {
113
  case NET_IP4:
114
  case NET_VPN4:
115
    return net_route_ip4(&tab->fib, (net_addr_ip4 *) n0);
116

  
117
  case NET_IP6:
118
  case NET_VPN6:
119
    return net_route_ip6(&tab->fib, (net_addr_ip6 *) n0);
120

  
121
  default:
122
    return NULL;
123
  }
88 124
}
89
*/
90 125

  
91 126
/**
92 127
 * rte_find - find a route
......
2040 2075
  return p ^ (p << 8) ^ (p >> 16);
2041 2076
}
2042 2077

  
2043
static inline unsigned
2078
static inline u32
2044 2079
hc_hash(ip_addr a, rtable *dep)
2045 2080
{
2046
  return (ipa_hash(a) ^ ptr_hash(dep)) & 0xffff;
2081
  return ipa_hash(a) ^ ptr_hash(dep);
2047 2082
}
2048 2083

  
2049 2084
static inline void
......
2077 2112
{
2078 2113
  unsigned hsize = 1 << order;
2079 2114
  hc->hash_order = order;
2080
  hc->hash_shift = 16 - order;
2115
  hc->hash_shift = 32 - order;
2081 2116
  hc->hash_max = (order >= HC_HI_ORDER) ? ~0 : (hsize HC_HI_MARK);
2082 2117
  hc->hash_min = (order <= HC_LO_ORDER) ?  0 : (hsize HC_LO_MARK);
2083 2118

  
......
2178 2213
static void
2179 2214
rt_notify_hostcache(rtable *tab, net *net)
2180 2215
{
2181
  struct hostcache *hc = tab->hostcache;
2182

  
2183 2216
  if (tab->hcu_scheduled)
2184 2217
    return;
2185 2218

  
2186
  // XXXX
2187
  // if (trie_match_prefix(hc->trie, net->n.prefix, net->n.pxlen))
2188
  // rt_schedule_hcu(tab);
2219
  if (trie_match_net(tab->hostcache->trie, net->n.addr))
2220
    rt_schedule_hcu(tab);
2189 2221
}
2190 2222

  
2191 2223
static int
......
2235 2267
  rta *old_src = he->src;
2236 2268
  int pxlen = 0;
2237 2269

  
2238
  /* Reset the hostentry */ 
2270
  /* Reset the hostentry */
2239 2271
  he->src = NULL;
2240 2272
  he->gw = IPA_NONE;
2241 2273
  he->dest = RTD_UNREACHABLE;
2242 2274
  he->igp_metric = 0;
2243 2275

  
2244
  // XXXX
2245
  // net *n = net_route(tab, he->addr, MAX_PREFIX_LENGTH);
2246
  net *n = NULL;
2276
  net_addr he_addr;
2277
  net_fill_ip_host(&he_addr, he->addr);
2278
  net *n = net_route(tab, &he_addr);
2247 2279
  if (n)
2248 2280
    {
2249 2281
      rte *e = n->routes;
......
2285 2317

  
2286 2318
 done:
2287 2319
  /* Add a prefix range to the trie */
2288
  /* XXXX
2289
  if (ipa_is_ip4(he->addr))
2290
    trie_add_prefix(tab->hostcache->trie, he->addr, IP4_MAX_PREFIX_LENGTH, pxlen, IP4_MAX_PREFIX_LENGTH);
2291
  else
2292
    trie_add_prefix(tab->hostcache->trie, he->addr, IP6_MAX_PREFIX_LENGTH, pxlen, IP6_MAX_PREFIX_LENGTH);
2293
  */
2320
  trie_add_prefix(tab->hostcache->trie, &he_addr, pxlen, he_addr.pxlen);
2294 2321

  
2295 2322
  rta_free(old_src);
2296 2323
  return old_src != he->src;
......
2331 2358
  if (!tab->hostcache)
2332 2359
    rt_init_hostcache(tab);
2333 2360

  
2334
  uint k = hc_hash(a, dep);
2361
  u32 k = hc_hash(a, dep);
2335 2362
  struct hostcache *hc = tab->hostcache;
2336 2363
  for (he = hc->hash_table[k >> hc->hash_shift]; he != NULL; he = he->next)
2337 2364
    if (ipa_equal(he->addr, a) && (he->tab == dep))
......
2575 2602
  if (d->filtered && (d->export_mode || d->primary_only))
2576 2603
    cli_msg(0, "");
2577 2604

  
2578
  if (!d->prefix)
2605
  if (!d->addr)
2579 2606
    {
2580 2607
      FIB_ITERATE_INIT(&d->fit, &d->table->fib);
2581 2608
      this_cli->cont = rt_show_cont;
......
2584 2611
    }
2585 2612
  else
2586 2613
    {
2587
      /* XXXX 
2588 2614
      if (d->show_for)
2589
	n = net_route(d->table, d->prefix, d->pxlen);
2615
	n = net_route(d->table, d->addr);
2590 2616
      else
2591
	n = net_find(d->table, d->prefix, d->pxlen);
2592
      */
2593
      n = NULL;
2617
	n = net_find(d->table, d->addr);
2594 2618

  
2595 2619
      if (n)
2596 2620
	rt_show_net(this_cli, n, d);
proto/bfd/bfd.c
112 112
#define HASH_IP_KEY(n)		n->addr
113 113
#define HASH_IP_NEXT(n)		n->next_ip
114 114
#define HASH_IP_EQ(a,b)		ipa_equal(a,b)
115
#define HASH_IP_FN(k)		ipa_hash32(k)
115
#define HASH_IP_FN(k)		ipa_hash(k)
116 116

  
117 117
static list bfd_proto_list;
118 118
static list bfd_wait_list;
proto/ospf/config.Y
220 220
   net_ip {
221 221
     this_stubnet = cfg_allocz(sizeof(struct ospf_stubnet_config));
222 222
     add_tail(&this_area->stubnet_list, NODE this_stubnet);
223
     this_stubnet->prefix = $1.n;
223
     this_stubnet->prefix = $1;
224 224
     this_stubnet->cost = COST_D;
225 225
   }
226 226
 ;
......
330 330
 {
331 331
   this_pref = cfg_allocz(sizeof(struct area_net_config));
332 332
   add_tail(this_nets, NODE this_pref);
333
   this_pref->prefix = $1.n;
333
   this_pref->prefix = $1;
334 334
 }
335 335
;
336 336

  
proto/ospf/iface.c
581 581
  if (ip->ptp_netmask < 2)
582 582
    ifa->ptp_netmask = ip->ptp_netmask;
583 583

  
584
  ifa->drip = ifa->bdrip = ospf_is_v2(p) ? IPA_NONE4 : IPA_NONE6;
584 585

  
585 586
  ifa->type = ospf_iface_classify(ip->type, addr);
586 587

  
......
1333 1334
    else if (ifa->addr->flags & IA_PEER)
1334 1335
      cli_msg(-1015, "Interface %s (peer %I)", ifa->ifname, ifa->addr->opposite);
1335 1336
    else
1336
      cli_msg(-1015, "Interface %s (%N)", ifa->ifname, ifa->addr->prefix);
1337
      cli_msg(-1015, "Interface %s (%N)", ifa->ifname, &ifa->addr->prefix);
1337 1338

  
1338 1339
    cli_msg(-1015, "\tType: %s%s", ospf_it[ifa->type], more);
1339 1340
    cli_msg(-1015, "\tArea: %R (%u)", ifa->oa->areaid, ifa->oa->areaid);
proto/ospf/neighbor.c
506 506

  
507 507
  u32 old_drid = ifa->drid;
508 508
  u32 old_bdrid = ifa->bdrid;
509
  ip_addr none = ospf_is_v2(p) ? IPA_NONE4 : IPA_NONE6;
509 510

  
510 511
  ifa->drid = ndr ? ndr->rid : 0;
511
  ifa->drip = ndr ? ndr->ip  : IPA_NONE;
512
  ifa->drip = ndr ? ndr->ip  : none;
512 513
  ifa->dr_iface_id = ndr ? ndr->iface_id : 0;
513 514

  
514 515
  ifa->bdrid = nbdr ? nbdr->rid : 0;
515
  ifa->bdrip = nbdr ? nbdr->ip  : IPA_NONE;
516
  ifa->bdrip = nbdr ? nbdr->ip  : none;
516 517

  
517 518
  DBG("DR=%R, BDR=%R\n", ifa->drid, ifa->bdrid);
518 519

  
proto/ospf/packet.c
500 500
void
501 501
ospf_send_to_bdr(struct ospf_iface *ifa)
502 502
{
503
  if (ipa_nonzero(ifa->drip))
503
  if (ipa_nonzero2(ifa->drip))
504 504
    ospf_send_to(ifa, ifa->drip);
505
  if (ipa_nonzero(ifa->bdrip))
505
  if (ipa_nonzero2(ifa->bdrip))
506 506
    ospf_send_to(ifa, ifa->bdrip);
507 507
}
proto/radv/config.Y
150 150
radv_prefix_start: net_ip6
151 151
{
152 152
  this_radv_prefix = cfg_allocz(sizeof(struct radv_prefix_config));
153
  RADV_PREFIX->prefix = $1.ip6;
153
  RADV_PREFIX->prefix = *(net_addr_ip6 *) &($1);
154 154

  
155 155
  RADV_PREFIX->onlink = 1;
156 156
  RADV_PREFIX->autonomous = 1;
sysdep/unix/krt.Y
69 69
   }
70 70
 | PRIMARY opttext net_or_ipa {
71 71
     struct kif_primary_item *kpi = cfg_alloc(sizeof (struct kif_primary_item));
72
     kpi->addr = $3.n;
72
     kpi->addr = $3;
73 73
     add_tail(&THIS_KIF->primary, &kpi->n);
74 74
   }
75 75
 ;

Also available in: Unified diff