Statistics
| Branch: | Revision:

iof-bird-daemon / nest / route.h @ 094d2bdb

History | View | Annotate | Download (19.8 KB)

1 58ef912c Martin Mares
/*
2
 *        BIRD Internet Routing Daemon -- Routing Table
3
 *
4 50fe90ed Martin Mares
 *        (c) 1998--2000 Martin Mares <mj@ucw.cz>
5 58ef912c Martin Mares
 *
6
 *        Can be freely distributed and used under the terms of the GNU GPL.
7
 */
8
9
#ifndef _BIRD_ROUTE_H_
10
#define _BIRD_ROUTE_H_
11
12 0e02abfd Martin Mares
#include "lib/lists.h"
13 1feea03e Martin Mares
#include "lib/resource.h"
14 a2ccbb0b Martin Mares
#include "lib/timer.h"
15 c0adf7e9 Ondrej Zajicek
#include "nest/protocol.h"
16 58ef912c Martin Mares
17 2326b001 Martin Mares
struct protocol;
18 4cc78c50 Martin Mares
struct proto;
19 730f2e2c Martin Mares
struct symbol;
20
struct filter;
21
struct cli;
22 2326b001 Martin Mares
23 58ef912c Martin Mares
/*
24
 *        Generic data structure for storing network prefixes. Also used
25 3ab001b9 Martin Mares
 *        for the master routing table. Currently implemented as a hash
26 62aa008a Martin Mares
 *        table.
27 58ef912c Martin Mares
 *
28
 *        Available operations:
29
 *                - insertion of new entry
30
 *                - deletion of entry
31 62aa008a Martin Mares
 *                - searching for entry by network prefix
32 3ab001b9 Martin Mares
 *                - asynchronous retrieval of fib contents
33 58ef912c Martin Mares
 */
34
35
struct fib_node {
36 3ab001b9 Martin Mares
  struct fib_node *next;                /* Next in hash chain */
37
  struct fib_iterator *readers;                /* List of readers of this node */
38 58ef912c Martin Mares
  byte pxlen;
39 4c45595e Martin Mares
  byte flags;                                /* User-defined */
40 12df4d90 Martin Mares
  byte x0, x1;                                /* User-defined */
41 d82fc18d Ondrej Zajicek
  u32 uid;                                /* Unique ID based on hash */
42 3ab001b9 Martin Mares
  ip_addr prefix;                        /* In host order */
43
};
44
45
struct fib_iterator {                        /* See lib/slists.h for an explanation */
46
  struct fib_iterator *prev, *next;        /* Must be synced with struct fib_node! */
47
  byte efef;                                /* 0xff to distinguish between iterator and node */
48
  byte pad[3];
49 0ba8a614 Martin Mares
  struct fib_node *node;                /* Or NULL if freshly merged */
50 3ab001b9 Martin Mares
  unsigned int hash;
51 58ef912c Martin Mares
};
52
53 ce4aca09 Martin Mares
typedef void (*fib_init_func)(struct fib_node *);
54
55 58ef912c Martin Mares
struct fib {
56 62aa008a Martin Mares
  pool *fib_pool;                        /* Pool holding all our data */
57
  slab *fib_slab;                        /* Slab holding all fib nodes */
58
  struct fib_node **hash_table;                /* Node hash table */
59 a8b60382 Martin Mares
  unsigned int hash_size;                /* Number of hash table entries (a power of two) */
60 3ab001b9 Martin Mares
  unsigned int hash_order;                /* Binary logarithm of hash_size */
61
  unsigned int hash_shift;                /* 16 - hash_log */
62 a8b60382 Martin Mares
  unsigned int entries;                        /* Number of entries */
63
  unsigned int entries_min, entries_max;/* Entry count limits (else start rehashing) */
64 ce4aca09 Martin Mares
  fib_init_func init;                        /* Constructor */
65 58ef912c Martin Mares
};
66
67 ce4aca09 Martin Mares
void fib_init(struct fib *, pool *, unsigned node_size, unsigned hash_order, fib_init_func init);
68 58ef912c Martin Mares
void *fib_find(struct fib *, ip_addr *, int);        /* Find or return NULL if doesn't exist */
69
void *fib_get(struct fib *, ip_addr *, int);         /* Find or create new if nonexistent */
70 56d6c530 Martin Mares
void *fib_route(struct fib *, ip_addr, int);        /* Longest-match routing lookup */
71 62aa008a Martin Mares
void fib_delete(struct fib *, void *);        /* Remove fib entry */
72 a8b60382 Martin Mares
void fib_free(struct fib *);                /* Destroy the fib */
73 3ab001b9 Martin Mares
void fib_check(struct fib *);                /* Consistency check for debugging */
74
75
void fit_init(struct fib_iterator *, struct fib *); /* Internal functions, don't call */
76
struct fib_node *fit_get(struct fib *, struct fib_iterator *);
77
void fit_put(struct fib_iterator *, struct fib_node *);
78 a8b60382 Martin Mares
79 236d4eb8 Martin Mares
#define FIB_WALK(fib, z) do {                                        \
80 62aa008a Martin Mares
        struct fib_node *z, **ff = (fib)->hash_table;                \
81 a8b60382 Martin Mares
        unsigned int count = (fib)->hash_size;                        \
82
        while (count--)                                                \
83 236d4eb8 Martin Mares
          for(z = *ff++; z; z=z->next)
84
85
#define FIB_WALK_END } while (0)
86 a8b60382 Martin Mares
87 3ab001b9 Martin Mares
#define FIB_ITERATE_INIT(it, fib) fit_init(it, fib)
88
89
#define FIB_ITERATE_START(fib, it, z) do {                        \
90
        struct fib_node *z = fit_get(fib, it);                        \
91
        unsigned int count = (fib)->hash_size;                        \
92
        unsigned int hpos = (it)->hash;                                \
93
        for(;;) {                                                \
94 8abbde02 Martin Mares
          if (!z)                                                \
95
            {                                                        \
96
               if (++hpos >= count)                                \
97
                 break;                                                \
98
               z = (fib)->hash_table[hpos];                        \
99
               continue;                                        \
100
            }
101 3ab001b9 Martin Mares
102 2569bc40 Martin Mares
#define FIB_ITERATE_END(z) z = z->next; } } while(0)
103 3ab001b9 Martin Mares
104
#define FIB_ITERATE_PUT(it, z) fit_put(it, z)
105
106 a8b60382 Martin Mares
/*
107 08e2d625 Martin Mares
 *        Master Routing Tables. Generally speaking, each of them contains a FIB
108
 *        with each entry pointing to a list of route entries representing routes
109
 *        to given network (with the selected one at the head).
110
 *
111 58ef912c Martin Mares
 *        Each of the RTE's contains variable data (the preference and protocol-dependent
112 62aa008a Martin Mares
 *        metrics) and a pointer to a route attribute block common for many routes).
113 08e2d625 Martin Mares
 *
114
 *        It's guaranteed that there is at most one RTE for every (prefix,proto) pair.
115 58ef912c Martin Mares
 */
116
117 0e02abfd Martin Mares
struct rtable_config {
118
  node n;
119
  char *name;
120
  struct rtable *table;
121 7de45ba4 Martin Mares
  struct proto_config *krt_attached;        /* Kernel syncer attached to this table */
122 b9626ec6 Martin Mares
  int gc_max_ops;                        /* Maximum number of operations before GC is run */
123
  int gc_min_time;                        /* Minimum time between two consecutive GC runs */
124 26822d8f Ondrej Zajicek
  byte sorted;                                /* Routes of network are sorted according to rte_better() */
125 0e02abfd Martin Mares
};
126
127 62aa008a Martin Mares
typedef struct rtable {
128 0e02abfd Martin Mares
  node n;                                /* Node in list of all tables */
129 62aa008a Martin Mares
  struct fib fib;
130
  char *name;                                /* Name of this table */
131 0e02abfd Martin Mares
  list hooks;                                /* List of announcement hooks */
132 9c11ec9e Martin Mares
  int pipe_busy;                        /* Pipe loop detection */
133 50fe90ed Martin Mares
  int use_count;                        /* Number of protocols using this table */
134 cfe34a31 Ondrej Zajicek
  struct hostcache *hostcache;
135 b9626ec6 Martin Mares
  struct rtable_config *config;                /* Configuration of this table */
136 50fe90ed Martin Mares
  struct config *deleted;                /* Table doesn't exist in current configuration,
137
                                         * delete as soon as use_count becomes 0 and remove
138
                                         * obstacle from this routing table.
139
                                         */
140 cfe34a31 Ondrej Zajicek
  struct event *rt_event;                /* Routing table event */
141 b9626ec6 Martin Mares
  int gc_counter;                        /* Number of operations since last GC */
142
  bird_clock_t gc_time;                        /* Time of last GC */
143 cfe34a31 Ondrej Zajicek
  byte gc_scheduled;                        /* GC is scheduled */
144 fb829de6 Ondrej Zajicek
  byte prune_state;                        /* Table prune state, 1 -> prune is running */
145 cfe34a31 Ondrej Zajicek
  byte hcu_scheduled;                        /* Hostcache update is scheduled */
146
  byte nhu_state;                        /* Next Hop Update state */
147 fb829de6 Ondrej Zajicek
  struct fib_iterator prune_fit;        /* Rtable prune FIB iterator */
148 cfe34a31 Ondrej Zajicek
  struct fib_iterator nhu_fit;                /* Next Hop Update FIB iterator */
149 62aa008a Martin Mares
} rtable;
150
151 58ef912c Martin Mares
typedef struct network {
152 3ab001b9 Martin Mares
  struct fib_node n;                        /* FIB flags reserved for kernel syncer */
153 58ef912c Martin Mares
  struct rte *routes;                        /* Available routes for this network */
154
} net;
155
156 cfe34a31 Ondrej Zajicek
struct hostcache {
157 f2b76f2c Ondrej Zajicek
  slab *slab;                                /* Slab holding all hostentries */
158
  struct hostentry **hash_table;        /* Hash table for hostentries */
159
  unsigned hash_order, hash_shift;
160
  unsigned hash_max, hash_min;
161
  unsigned hash_items;
162 c477f489 Ondrej Zajicek
  linpool *lp;                                /* Linpool for trie */
163
  struct f_trie *trie;                        /* Trie of prefixes that might affect hostentries */
164
  list hostentries;                        /* List of all hostentries */
165 cfe34a31 Ondrej Zajicek
  byte update_hostcache;
166
};
167
168
struct hostentry {
169
  node ln;
170 1b180121 Ondrej Zajicek
  ip_addr addr;                                /* IP address of host, part of key */
171
  ip_addr link;                                /* (link-local) IP address of host, used as gw
172
                                           if host is directly attached */
173 f2b76f2c Ondrej Zajicek
  struct rtable *tab;                        /* Dependent table, part of key*/
174
  struct hostentry *next;                /* Next in hash chain */
175
  unsigned hash_key;                        /* Hash key */
176 cfe34a31 Ondrej Zajicek
  unsigned uc;                                /* Use count */
177 7e95c05d Ondrej Zajicek
  struct rta *src;                        /* Source rta entry */
178 cfe34a31 Ondrej Zajicek
  ip_addr gw;                                /* Chosen next hop */
179
  byte dest;                                /* Chosen route destination type (RTD_...) */
180 d1e146f2 Ondrej Zajicek
  u32 igp_metric;                        /* Chosen route IGP metric */
181 cfe34a31 Ondrej Zajicek
};
182
183 58ef912c Martin Mares
typedef struct rte {
184
  struct rte *next;
185 a0762910 Martin Mares
  net *net;                                /* Network this RTE belongs to */
186 c0adf7e9 Ondrej Zajicek
  struct announce_hook *sender;                /* Announce hook used to send the route to the routing table */
187 1b769b08 Martin Mares
  struct rta *attrs;                        /* Attributes of this route */
188 58ef912c Martin Mares
  byte flags;                                /* Flags (REF_...) */
189 481f6985 Martin Mares
  byte pflags;                                /* Protocol-specific flags */
190 58ef912c Martin Mares
  word pref;                                /* Route preference */
191 a2ccbb0b Martin Mares
  bird_clock_t lastmod;                        /* Last modified */
192 58ef912c Martin Mares
  union {                                /* Protocol-dependent data (metrics etc.) */
193
#ifdef CONFIG_RIP
194
    struct {
195 feb6abe0 Pavel Machek
      node garbage;                        /* List for garbage collection */
196 58ef912c Martin Mares
      byte metric;                        /* RIP metric */
197 481f6985 Martin Mares
      u16 tag;                                /* External route tag */
198 ec21aecf Pavel Machek
      struct rip_entry *entry;
199 58ef912c Martin Mares
    } rip;
200
#endif
201
#ifdef CONFIG_OSPF
202
    struct {
203
      u32 metric1, metric2;                /* OSPF Type 1 and Type 2 metrics */
204 481f6985 Martin Mares
      u32 tag;                                /* External route tag */
205 c27b2449 Ondrej Zajicek
      u32 router_id;                        /* Router that originated this route */
206 58ef912c Martin Mares
    } ospf;
207
#endif
208 be4cd99a Ondrej Zajicek
#ifdef CONFIG_BGP
209
    struct {
210
      u8 suppressed;                        /* Used for deterministic MED comparison */
211
    } bgp;
212
#endif
213 c10421d3 Martin Mares
    struct {                                /* Routes generated by krt sync (both temporary and inherited ones) */
214
      s8 src;                                /* Alleged route source (see krt.h) */
215
      u8 proto;                                /* Kernel source protocol ID */
216
      u8 type;                                /* Kernel route type */
217
      u8 seen;                                /* Seen during last scan */
218
      u32 metric;                        /* Kernel metric */
219
    } krt;
220 58ef912c Martin Mares
  } u;
221
} rte;
222
223 00a09f3c Ondrej Zajicek
#define REF_COW                1                /* Copy this rte on write */
224 e2dc2f30 Martin Mares
225 23ac9e9a Ondrej Zajicek
/* Types of route announcement, also used as flags */
226 00a09f3c Ondrej Zajicek
#define RA_OPTIMAL        1                /* Announcement of optimal route change */
227
#define RA_ACCEPTED        2                /* Announcement of first accepted route */
228
#define RA_ANY                3                /* Announcement of any route change */
229 23ac9e9a Ondrej Zajicek
230 0e02abfd Martin Mares
struct config;
231 2326b001 Martin Mares
232
void rt_init(void);
233 0e02abfd Martin Mares
void rt_preconfig(struct config *);
234 50fe90ed Martin Mares
void rt_commit(struct config *new, struct config *old);
235
void rt_lock_table(rtable *);
236
void rt_unlock_table(rtable *);
237 b9626ec6 Martin Mares
void rt_setup(pool *, rtable *, char *, struct rtable_config *);
238 08e2d625 Martin Mares
static inline net *net_find(rtable *tab, ip_addr addr, unsigned len) { return (net *) fib_find(&tab->fib, &addr, len); }
239
static inline net *net_get(rtable *tab, ip_addr addr, unsigned len) { return (net *) fib_get(&tab->fib, &addr, len); }
240 094d2bdb Ondrej Zajicek
rte *rte_find(net *net, struct rte_src *src);
241 1b769b08 Martin Mares
rte *rte_get_temp(struct rta *);
242 094d2bdb Ondrej Zajicek
void rte_update2(struct announce_hook *ah, net *net, rte *new, struct rte_src *src);
243
static inline void rte_update(struct proto *p, net *net, rte *new) { rte_update2(p->main_ahook, net, new, p->main_source); }
244 0e02abfd Martin Mares
void rte_discard(rtable *tab, rte *old);
245 a0762910 Martin Mares
void rte_dump(rte *);
246 04925e90 Martin Mares
void rte_free(rte *);
247 e2dc2f30 Martin Mares
rte *rte_do_cow(rte *);
248
static inline rte * rte_cow(rte *r) { return (r->flags & REF_COW) ? rte_do_cow(r) : r; }
249 2326b001 Martin Mares
void rt_dump(rtable *);
250 a2ccbb0b Martin Mares
void rt_dump_all(void);
251 ac5d8012 Martin Mares
int rt_feed_baby(struct proto *p);
252
void rt_feed_baby_abort(struct proto *p);
253 fb829de6 Ondrej Zajicek
void rt_schedule_prune_all(void);
254
int rt_prune_loop(void);
255 b9626ec6 Martin Mares
struct rtable_config *rt_new_table(struct symbol *s);
256 2326b001 Martin Mares
257 730f2e2c Martin Mares
struct rt_show_data {
258
  ip_addr prefix;
259
  unsigned pxlen;
260
  rtable *table;
261
  struct filter *filter;
262
  int verbose;
263
  struct fib_iterator fit;
264 4d176e14 Ondrej Filip
  struct proto *show_protocol;
265 ea2ae6dd Ondrej Zajicek
  struct proto *export_protocol;
266
  int export_mode, primary_only;
267 ce1da96e Martin Mares
  struct config *running_on_config;
268 23693958 Martin Mares
  int net_counter, rt_counter, show_counter;
269 56d6c530 Martin Mares
  int stats, show_for;
270 730f2e2c Martin Mares
};
271
void rt_show(struct rt_show_data *);
272
273 58ef912c Martin Mares
/*
274
 *        Route Attributes
275
 *
276
 *        Beware: All standard BGP attributes must be represented here instead
277
 *        of making them local to the route. This is needed to ensure proper
278
 *        construction of BGP route attribute lists.
279
 */
280
281 7e95c05d Ondrej Zajicek
/* Multipath next-hop */
282
struct mpnh {
283
  ip_addr gw;                                /* Next hop */
284
  struct iface *iface;                        /* Outgoing interface */
285
  struct mpnh *next;
286
  unsigned char weight;
287
};
288
289 094d2bdb Ondrej Zajicek
struct rte_src {
290
  struct rte_src *next;                        /* Hash chain */
291
  struct proto *proto;                        /* Protocol the source is based on */
292
  u32 private_id;                        /* Private ID, assigned by the protocol */
293
  u32 global_id;                        /* Globally unique ID of the source */
294
  unsigned uc;                                /* Use count */
295
};
296
297
298 1b769b08 Martin Mares
typedef struct rta {
299 ee76a92a Martin Mares
  struct rta *next, **pprev;                /* Hash chain */
300 094d2bdb Ondrej Zajicek
  struct rte_src *src;                        /* Route source that created the route */
301 58ef912c Martin Mares
  unsigned uc;                                /* Use count */
302
  byte source;                                /* Route source (RTS_...) */
303 a8b60382 Martin Mares
  byte scope;                                /* Route scope (SCOPE_... -- see ip.h) */
304 58ef912c Martin Mares
  byte cast;                                /* Casting type (RTC_...) */
305
  byte dest;                                /* Route destination type (RTD_...) */
306 c8518ae1 Martin Mares
  byte flags;                                /* Route flags (RTF_...), now unused */
307 04925e90 Martin Mares
  byte aflags;                                /* Attribute cache flags (RTAF_...) */
308 ee76a92a Martin Mares
  u16 hash_key;                                /* Hash over important fields */
309 d1e146f2 Ondrej Zajicek
  u32 igp_metric;                        /* IGP metric to next hop (for iBGP routes) */
310 58ef912c Martin Mares
  ip_addr gw;                                /* Next hop */
311 a8b60382 Martin Mares
  ip_addr from;                                /* Advertising router */
312 cfe34a31 Ondrej Zajicek
  struct hostentry *hostentry;                /* Hostentry for recursive next-hops */
313 58ef912c Martin Mares
  struct iface *iface;                        /* Outgoing interface */
314 7e95c05d Ondrej Zajicek
  struct mpnh *nexthops;                /* Next-hops for multipath routes */
315 2727bb7c Martin Mares
  struct ea_list *eattrs;                /* Extended Attribute chain */
316 58ef912c Martin Mares
} rta;
317
318 618533af Martin Mares
#define RTS_DUMMY 0                        /* Dummy route to be removed soon */
319 58ef912c Martin Mares
#define RTS_STATIC 1                        /* Normal static route */
320
#define RTS_INHERIT 2                        /* Route inherited from kernel */
321
#define RTS_DEVICE 3                        /* Device route */
322
#define RTS_STATIC_DEVICE 4                /* Static device route */
323
#define RTS_REDIRECT 5                        /* Learned via redirect */
324
#define RTS_RIP 6                        /* RIP route */
325 beaf86e1 Martin Mares
#define RTS_OSPF 7                        /* OSPF route */
326 8bf684ec Ondrej Filip
#define RTS_OSPF_IA 8                        /* OSPF inter-area route */
327 98ac6176 Ondrej Filip
#define RTS_OSPF_EXT1 9                        /* OSPF external route type 1 */
328
#define RTS_OSPF_EXT2 10                /* OSPF external route type 2 */
329
#define RTS_BGP 11                        /* BGP route */
330
#define RTS_PIPE 12                        /* Inter-table wormhole */
331 58ef912c Martin Mares
332
#define RTC_UNICAST 0
333
#define RTC_BROADCAST 1
334
#define RTC_MULTICAST 2
335
#define RTC_ANYCAST 3                        /* IPv6 Anycast */
336
337
#define RTD_ROUTER 0                        /* Next hop is neighbor router */
338
#define RTD_DEVICE 1                        /* Points to device */
339
#define RTD_BLACKHOLE 2                        /* Silently drop packets */
340
#define RTD_UNREACHABLE 3                /* Reject as unreachable */
341
#define RTD_PROHIBIT 4                        /* Administratively prohibited */
342 7e95c05d Ondrej Zajicek
#define RTD_MULTIPATH 5                        /* Multipath route (nexthops != NULL) */
343
#define RTD_NONE 6                        /* Invalid RTD */
344 58ef912c Martin Mares
345 32f95476 Ondrej Zajicek
                                        /* Flags for net->n.flags, used by kernel syncer */
346
#define KRF_INSTALLED 0x80                /* This route should be installed in the kernel */
347
#define KRF_SYNC_ERROR 0x40                /* Error during kernel table synchronization */
348
349 04925e90 Martin Mares
#define RTAF_CACHED 1                        /* This is a cached rta */
350
351 d1e146f2 Ondrej Zajicek
#define IGP_METRIC_UNKNOWN 0x80000000        /* Default igp_metric used when no other
352
                                           protocol-specific metric is availabe */
353
354 58ef912c Martin Mares
/*
355
 *        Extended Route Attributes
356
 */
357
358
typedef struct eattr {
359 b77ae37d Martin Mares
  word id;                                /* EA_CODE(EAP_..., protocol-dependent ID) */
360
  byte flags;                                /* Protocol-dependent flags */
361
  byte type;                                /* Attribute type and several flags (EAF_...) */
362 58ef912c Martin Mares
  union {
363
    u32 data;
364
    struct adata *ptr;                        /* Attribute data elsewhere */
365
  } u;
366
} eattr;
367
368
#define EAP_GENERIC 0                        /* Generic attributes */
369
#define EAP_BGP 1                        /* BGP attributes */
370 9c9e49ac Pavel Machek
#define EAP_RIP 2                        /* RIP */
371 5919c66e Martin Mares
#define EAP_OSPF 3                        /* OSPF */
372 71ca7716 Ondrej Zajicek
#define EAP_KRT 4                        /* Kernel route attributes */
373
#define EAP_MAX 5
374 58ef912c Martin Mares
375 b77ae37d Martin Mares
#define EA_CODE(proto,id) (((proto) << 8) | (id))
376
#define EA_PROTO(ea) ((ea) >> 8)
377
#define EA_ID(ea) ((ea) & 0xff)
378
379 ba5e5940 Ondrej Zajicek
#define EA_GEN_IGP_METRIC EA_CODE(EAP_GENERIC, 0)
380
381 8d24b689 Martin Mares
#define EA_CODE_MASK 0xffff
382
#define EA_ALLOW_UNDEF 0x10000                /* ea_find: allow EAF_TYPE_UNDEF */
383
384 b77ae37d Martin Mares
#define EAF_TYPE_MASK 0x0f                /* Mask with this to get type */
385
#define EAF_TYPE_INT 0x01                /* 32-bit signed integer number */
386
#define EAF_TYPE_OPAQUE 0x02                /* Opaque byte string (not filterable) */
387 ca97b489 Martin Mares
#define EAF_TYPE_IP_ADDRESS 0x04        /* IP address */
388
#define EAF_TYPE_ROUTER_ID 0x05                /* Router ID (IPv4 address) */
389 b475c543 Martin Mares
#define EAF_TYPE_AS_PATH 0x06                /* BGP AS path (encoding per RFC 1771:4.3) */
390
#define EAF_TYPE_INT_SET 0x0a                /* Set of u32's (e.g., a community list) */
391 42a0c054 Ondrej Zajicek
#define EAF_TYPE_EC_SET 0x0e                /* Set of pairs of u32's - ext. community list */
392 8d24b689 Martin Mares
#define EAF_TYPE_UNDEF 0x0f                /* `force undefined' entry */
393 b77ae37d Martin Mares
#define EAF_EMBEDDED 0x01                /* Data stored in eattr.u.data (part of type spec) */
394 ca97b489 Martin Mares
#define EAF_VAR_LENGTH 0x02                /* Attribute length is variable (part of type spec) */
395 51a183af Martin Mares
#define EAF_ORIGINATED 0x40                /* The attribute has originated locally */
396 9f4929e7 Martin Mares
#define EAF_TEMP 0x80                        /* A temporary attribute (the one stored in the tmp attr list) */
397 58ef912c Martin Mares
398
struct adata {
399 b475c543 Martin Mares
  unsigned int length;                        /* Length of data */
400 58ef912c Martin Mares
  byte data[0];
401
};
402
403
typedef struct ea_list {
404
  struct ea_list *next;                        /* In case we have an override list */
405 b77ae37d Martin Mares
  byte flags;                                /* Flags: EALF_... */
406 58ef912c Martin Mares
  byte rfu;
407 b77ae37d Martin Mares
  word count;                                /* Number of attributes */
408 58ef912c Martin Mares
  eattr attrs[0];                        /* Attribute definitions themselves */
409
} ea_list;
410
411 b77ae37d Martin Mares
#define EALF_SORTED 1                        /* Attributes are sorted by code */
412
#define EALF_BISECT 2                        /* Use interval bisection for searching */
413
#define EALF_CACHED 4                        /* Attributes belonging to cached rta */
414 58ef912c Martin Mares
415 094d2bdb Ondrej Zajicek
struct rte_src *rt_find_source(struct proto *p, u32 id);
416
struct rte_src *rt_get_source(struct proto *p, u32 id);
417
static inline void rt_lock_source(struct rte_src *src) { src->uc++; }
418
static inline void rt_unlock_source(struct rte_src *src) { src->uc--; }
419
void rt_prune_sources(void);
420
421
422 b77ae37d Martin Mares
eattr *ea_find(ea_list *, unsigned ea);
423 c0100454 Pavel Machek
int ea_get_int(ea_list *, unsigned ea, int def);
424 b77ae37d Martin Mares
void ea_dump(ea_list *);
425
void ea_sort(ea_list *);                /* Sort entries in all sub-lists */
426 6f57dcc0 Martin Mares
unsigned ea_scan(ea_list *);                /* How many bytes do we need for merged ea_list */
427 b77ae37d Martin Mares
void ea_merge(ea_list *from, ea_list *to); /* Merge sub-lists to allocated buffer */
428 6f57dcc0 Martin Mares
int ea_same(ea_list *x, ea_list *y);        /* Test whether two ea_lists are identical */
429
unsigned int ea_hash(ea_list *e);        /* Calculate 16-bit hash value */
430 ce1da96e Martin Mares
ea_list *ea_append(ea_list *to, ea_list *what);
431 58ef912c Martin Mares
432 7e95c05d Ondrej Zajicek
int mpnh__same(struct mpnh *x, struct mpnh *y); /* Compare multipath nexthops */
433
static inline int mpnh_same(struct mpnh *x, struct mpnh *y)
434
{ return (x == y) || mpnh__same(x, y); }
435
436 2326b001 Martin Mares
void rta_init(void);
437
rta *rta_lookup(rta *);                        /* Get rta equivalent to this one, uc++ */
438 094d2bdb Ondrej Zajicek
static inline int rta_is_cached(rta *r) { return r->aflags & RTAF_CACHED; }
439 2326b001 Martin Mares
static inline rta *rta_clone(rta *r) { r->uc++; return r; }
440 b77ae37d Martin Mares
void rta__free(rta *r);
441
static inline void rta_free(rta *r) { if (r && !--r->uc) rta__free(r); }
442 2326b001 Martin Mares
void rta_dump(rta *);
443
void rta_dump_all(void);
444 ce1da96e Martin Mares
void rta_show(struct cli *, rta *, ea_list *);
445 1b180121 Ondrej Zajicek
void rta_set_recursive_next_hop(rtable *dep, rta *a, rtable *tab, ip_addr *gw, ip_addr *ll);
446 cfe34a31 Ondrej Zajicek
447
/*
448
 * rta_set_recursive_next_hop() acquires hostentry from hostcache and
449
 * fills rta->hostentry field.  New hostentry has zero use
450
 * count. Cached rta locks its hostentry (increases its use count),
451
 * uncached rta does not lock it. Hostentry with zero use count is
452
 * removed asynchronously during host cache update, therefore it is
453 7e95c05d Ondrej Zajicek
 * safe to hold such hostentry temorarily. Hostentry holds a lock for
454
 * a 'source' rta, mainly to share multipath nexthops. There is no
455
 * need to hold a lock for hostentry->dep table, because that table
456
 * contains routes responsible for that hostentry, and therefore is
457
 * non-empty if given hostentry has non-zero use count. The protocol
458
 * responsible for routes with recursive next hops should also hold a
459
 * lock for a table governing that routes (argument tab to
460
 * rta_set_recursive_next_hop()).
461 cfe34a31 Ondrej Zajicek
 */
462
463
static inline void rt_lock_hostentry(struct hostentry *he) { if (he) he->uc++; }
464
static inline void rt_unlock_hostentry(struct hostentry *he) { if (he) he->uc--; }
465
466 2326b001 Martin Mares
467 3991d84e Martin Mares
extern struct protocol *attr_class_to_protocol[EAP_MAX];
468
469 a8b60382 Martin Mares
/*
470
 *        Default protocol preferences
471
 */
472
473
#define DEF_PREF_DIRECT                    240        /* Directly connected */
474
#define DEF_PREF_STATIC                200        /* Static route */
475 916c8c0a Martin Mares
#define DEF_PREF_OSPF                150        /* OSPF intra-area, inter-area and type 1 external routes */
476 a8b60382 Martin Mares
#define DEF_PREF_RIP                120        /* RIP */
477
#define DEF_PREF_BGP                100        /* BGP */
478 beaf86e1 Martin Mares
#define DEF_PREF_PIPE                70        /* Routes piped from other tables */
479 916c8c0a Martin Mares
#define DEF_PREF_INHERITED        10        /* Routes inherited from other routing daemons */
480 a8b60382 Martin Mares
481 af582c48 Ondrej Zajicek
482
/*
483
 *        Route Origin Authorization
484
 */
485
486
struct roa_item {
487
  u32 asn;
488
  byte maxlen;
489
  byte src;
490
  struct roa_item *next;
491
};
492
493
struct roa_node {
494
  struct fib_node n;
495
  struct roa_item *items;
496
  // u32 cached_asn;
497
};
498
499
struct roa_table {
500
  node n;                                /* Node in roa_table_list */
501
  struct fib fib;
502
  char *name;                                /* Name of this ROA table */
503
  struct roa_table_config *cf;                /* Configuration of this ROA table */
504
};
505
506
struct roa_item_config {
507
  ip_addr prefix;
508
  byte pxlen, maxlen;
509
  u32 asn;
510
  struct roa_item_config *next;
511
};
512
513
struct roa_table_config {
514
  node n;                                /* Node in config->rpa_tables */
515
  char *name;                                /* Name of this ROA table */
516
  struct roa_table *table;
517
518
  struct roa_item_config *roa_items;        /* Preconfigured ROA items */
519
520
  // char *filename;
521
  // int gc_max_ops;                        /* Maximum number of operations before GC is run */
522
  // int gc_min_time;                        /* Minimum time between two consecutive GC runs */
523
};
524
525
struct roa_show_data {
526
  struct fib_iterator fit;
527
  struct roa_table *table;
528
  ip_addr prefix;
529
  byte pxlen;
530
  byte mode;                                /* ROA_SHOW_* values */
531
  u32 asn;                                /* Filter ASN, 0 -> all */
532
};
533
534
#define ROA_UNKNOWN        0
535
#define ROA_VALID        1
536
#define ROA_INVALID        2
537
538
#define ROA_SRC_ANY        0
539
#define ROA_SRC_CONFIG        1
540
#define ROA_SRC_DYNAMIC        2
541
542
#define ROA_SHOW_ALL        0
543
#define ROA_SHOW_PX        1
544
#define ROA_SHOW_IN        2
545
#define ROA_SHOW_FOR        3
546
547
extern struct roa_table *roa_table_default;
548
549
void roa_add_item(struct roa_table *t, ip_addr prefix, byte pxlen, byte maxlen, u32 asn, byte src);
550
void roa_delete_item(struct roa_table *t, ip_addr prefix, byte pxlen, byte maxlen, u32 asn, byte src);
551
void roa_flush(struct roa_table *t, byte src);
552
byte roa_check(struct roa_table *t, ip_addr prefix, byte pxlen, u32 asn);
553
struct roa_table_config * roa_new_table_config(struct symbol *s);
554
void roa_add_item_config(struct roa_table_config *rtc, ip_addr prefix, byte pxlen, byte maxlen, u32 asn);
555
void roa_init(void);
556
void roa_preconfig(struct config *c);
557
void roa_commit(struct config *new, struct config *old);
558
void roa_show(struct roa_show_data *d);
559
560
561 58ef912c Martin Mares
#endif