]> git.ipfire.org Git - thirdparty/bird.git/blob - nest/protocol.h
MPLS subsystem
[thirdparty/bird.git] / nest / protocol.h
1 /*
2 * BIRD Internet Routing Daemon -- Protocols
3 *
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #ifndef _BIRD_PROTOCOL_H_
10 #define _BIRD_PROTOCOL_H_
11
12 #include "lib/lists.h"
13 #include "lib/resource.h"
14 #include "lib/event.h"
15 #include "nest/route.h"
16 #include "conf/conf.h"
17
18 struct iface;
19 struct ifa;
20 struct rtable;
21 struct rte;
22 struct neighbor;
23 struct rta;
24 struct network;
25 struct proto_config;
26 struct channel_limit;
27 struct channel_config;
28 struct config;
29 struct proto;
30 struct channel;
31 struct ea_list;
32 struct eattr;
33 struct symbol;
34 struct mpls_fec_map;
35
36
37 /*
38 * Routing Protocol
39 */
40
41 enum protocol_class {
42 PROTOCOL_NONE,
43 PROTOCOL_AGGREGATOR,
44 PROTOCOL_BABEL,
45 PROTOCOL_BFD,
46 PROTOCOL_BGP,
47 PROTOCOL_BMP,
48 PROTOCOL_DEVICE,
49 PROTOCOL_DIRECT,
50 PROTOCOL_KERNEL,
51 PROTOCOL_OSPF,
52 PROTOCOL_MRT,
53 PROTOCOL_PERF,
54 PROTOCOL_PIPE,
55 PROTOCOL_RADV,
56 PROTOCOL_RIP,
57 PROTOCOL_RPKI,
58 PROTOCOL_STATIC,
59 PROTOCOL__MAX
60 };
61
62 extern struct protocol *class_to_protocol[PROTOCOL__MAX];
63
64 struct protocol {
65 node n;
66 char *name;
67 char *template; /* Template for automatic generation of names */
68 int name_counter; /* Counter for automatic name generation */
69 enum protocol_class class; /* Machine readable protocol class */
70 uint preference; /* Default protocol preference */
71 uint channel_mask; /* Mask of accepted channel types (NB_*) */
72 uint proto_size; /* Size of protocol data structure */
73 uint config_size; /* Size of protocol config data structure */
74
75 void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
76 void (*postconfig)(struct proto_config *); /* After configuring each instance */
77 struct proto * (*init)(struct proto_config *); /* Create new instance */
78 int (*reconfigure)(struct proto *, struct proto_config *); /* Try to reconfigure instance, returns success */
79 void (*dump)(struct proto *); /* Debugging dump */
80 int (*start)(struct proto *); /* Start the instance */
81 int (*shutdown)(struct proto *); /* Stop the instance */
82 void (*cleanup)(struct proto *); /* Called after shutdown when protocol became hungry/down */
83 void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
84 void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
85 int (*get_attr)(const struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */
86 void (*show_proto_info)(struct proto *); /* Show protocol info (for `show protocols all' command) */
87 void (*copy_config)(struct proto_config *, struct proto_config *); /* Copy config from given protocol instance */
88 };
89
90 void protos_build(void); /* Called from sysdep to initialize protocols */
91 void proto_build(struct protocol *); /* Called from protocol to register itself */
92 void protos_preconfig(struct config *);
93 void protos_commit(struct config *new, struct config *old, int force_restart, int type);
94 struct proto * proto_spawn(struct proto_config *cf, uint disabled);
95 void protos_dump_all(void);
96
97 #define GA_UNKNOWN 0 /* Attribute not recognized */
98 #define GA_NAME 1 /* Result = name */
99 #define GA_FULL 2 /* Result = both name and value */
100 #define GA_HIDDEN 3 /* Attribute should not be printed */
101
102 /*
103 * Known protocols
104 */
105
106 extern struct protocol
107 proto_device, proto_radv, proto_rip, proto_static, proto_mrt,
108 proto_ospf, proto_perf, proto_aggregator,
109 proto_pipe, proto_bgp, proto_bmp, proto_bfd, proto_babel, proto_rpki;
110
111 /*
112 * Routing Protocol Instance
113 */
114
115 struct proto_config {
116 node n;
117 struct config *global; /* Global configuration data */
118 struct protocol *protocol; /* Protocol */
119 struct proto *proto; /* Instance we've created */
120 struct proto_config *parent; /* Parent proto_config for dynamic protocols */
121 const char *name;
122 const char *dsc;
123 int class; /* SYM_PROTO or SYM_TEMPLATE */
124 u8 net_type; /* Protocol network type (NET_*), 0 for undefined */
125 u8 disabled; /* Protocol enabled/disabled by default */
126 u8 vrf_set; /* Related VRF instance (below) is defined */
127 u32 debug, mrtdump; /* Debugging bitfields, both use D_* constants */
128 u32 router_id; /* Protocol specific router ID */
129
130 list channels; /* List of channel configs (struct channel_config) */
131 struct iface *vrf; /* Related VRF instance, NULL if global */
132
133 /* Check proto_reconfigure() and proto_copy_config() after changing struct proto_config */
134
135 /* Protocol-specific data follow... */
136 };
137
138 /* Protocol statistics */
139 struct proto_stats {
140 /* Import - from protocol to core */
141 u32 imp_routes; /* Number of routes successfully imported to the (adjacent) routing table */
142 u32 filt_routes; /* Number of routes rejected in import filter but kept in the routing table */
143 u32 pref_routes; /* Number of routes selected as best in the (adjacent) routing table */
144 u32 imp_updates_received; /* Number of route updates received */
145 u32 imp_updates_invalid; /* Number of route updates rejected as invalid */
146 u32 imp_updates_filtered; /* Number of route updates rejected by filters */
147 u32 imp_updates_ignored; /* Number of route updates rejected as already in route table */
148 u32 imp_updates_accepted; /* Number of route updates accepted and imported */
149 u32 imp_withdraws_received; /* Number of route withdraws received */
150 u32 imp_withdraws_invalid; /* Number of route withdraws rejected as invalid */
151 u32 imp_withdraws_ignored; /* Number of route withdraws rejected as already not in route table */
152 u32 imp_withdraws_accepted; /* Number of route withdraws accepted and processed */
153
154 /* Export - from core to protocol */
155 u32 exp_routes; /* Number of routes successfully exported to the protocol */
156 u32 exp_updates_received; /* Number of route updates received */
157 u32 exp_updates_rejected; /* Number of route updates rejected by protocol */
158 u32 exp_updates_filtered; /* Number of route updates rejected by filters */
159 u32 exp_updates_accepted; /* Number of route updates accepted and exported */
160 u32 exp_withdraws_received; /* Number of route withdraws received */
161 u32 exp_withdraws_accepted; /* Number of route withdraws accepted and processed */
162 };
163
164 struct proto {
165 node n; /* Node in global proto_list */
166 struct protocol *proto; /* Protocol */
167 struct proto_config *cf; /* Configuration data */
168 struct proto_config *cf_new; /* Configuration we want to switch to after shutdown (NULL=delete) */
169 pool *pool; /* Pool containing local objects */
170 event *event; /* Protocol event */
171
172 list channels; /* List of channels to rtables (struct channel) */
173 struct channel *main_channel; /* Primary channel */
174 struct rte_src *main_source; /* Primary route source */
175 struct iface *vrf; /* Related VRF instance, NULL if global */
176 struct channel *mpls_channel; /* MPLS channel, when used */
177 struct mpls_fec_map *mpls_map; /* Maps protocol routes to FECs / labels */
178
179 const char *name; /* Name of this instance (== cf->name) */
180 u32 debug; /* Debugging flags */
181 u32 mrtdump; /* MRTDump flags */
182 uint active_channels; /* Number of active channels */
183 byte net_type; /* Protocol network type (NET_*), 0 for undefined */
184 byte disabled; /* Manually disabled */
185 byte vrf_set; /* Related VRF instance (above) is defined */
186 byte proto_state; /* Protocol state machine (PS_*, see below) */
187 byte active; /* From PS_START to cleanup after PS_STOP */
188 byte do_start; /* Start actions are scheduled */
189 byte do_stop; /* Stop actions are scheduled */
190 byte reconfiguring; /* We're shutting down due to reconfiguration */
191 byte gr_recovery; /* Protocol should participate in graceful restart recovery */
192 byte down_sched; /* Shutdown is scheduled for later (PDS_*) */
193 byte down_code; /* Reason for shutdown (PDC_* codes) */
194 u32 hash_key; /* Random key used for hashing of neighbors */
195 btime last_state_change; /* Time of last state transition */
196 char *last_state_name_announced; /* Last state name we've announced to the user */
197 char *message; /* State-change message, allocated from proto_pool */
198
199 /*
200 * General protocol hooks:
201 *
202 * if_notify Notify protocol about interface state changes.
203 * ifa_notify Notify protocol about interface address changes.
204 * rt_notify Notify protocol about routing table updates.
205 * neigh_notify Notify protocol about neighbor cache events.
206 * preexport Called as the first step of the route exporting process.
207 * It can decide whether the route shall be exported:
208 * -1 = reject,
209 * 0 = continue to export filter
210 * 1 = accept immediately
211 * reload_routes Request channel to reload all its routes to the core
212 * (using rte_update()). Returns: 0=reload cannot be done,
213 * 1= reload is scheduled and will happen (asynchronously).
214 * feed_begin Notify channel about beginning of route feeding.
215 * feed_end Notify channel about finish of route feeding.
216 */
217
218 void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
219 void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
220 void (*rt_notify)(struct proto *, struct channel *, struct network *net, struct rte *new, struct rte *old);
221 void (*neigh_notify)(struct neighbor *neigh);
222 int (*preexport)(struct channel *, struct rte *rt);
223 void (*reload_routes)(struct channel *);
224 void (*feed_begin)(struct channel *, int initial);
225 void (*feed_end)(struct channel *);
226
227 /*
228 * Routing entry hooks (called only for routes belonging to this protocol):
229 *
230 * rte_recalculate Called at the beginning of the best route selection
231 * rte_better Compare two rte's and decide which one is better (1=first, 0=second).
232 * rte_same Compare two rte's and decide whether they are identical (1=yes, 0=no).
233 * rte_mergable Compare two rte's and decide whether they could be merged (1=yes, 0=no).
234 * rte_insert Called whenever a rte is inserted to a routing table.
235 * rte_remove Called whenever a rte is removed from the routing table.
236 */
237
238 int (*rte_recalculate)(struct rtable *, struct network *, struct rte *, struct rte *, struct rte *);
239 int (*rte_better)(struct rte *, struct rte *);
240 int (*rte_mergable)(struct rte *, struct rte *);
241 struct rte * (*rte_modify)(struct rte *, struct linpool *);
242 void (*rte_insert)(struct network *, struct rte *);
243 void (*rte_remove)(struct network *, struct rte *);
244 u32 (*rte_igp_metric)(struct rte *);
245
246 /* Hic sunt protocol-specific data */
247 };
248
249 struct proto_spec {
250 const void *ptr;
251 int patt;
252 };
253
254
255 #define PDS_DISABLE 1 /* Proto disable scheduled */
256 #define PDS_RESTART 2 /* Proto restart scheduled */
257
258 #define PDC_CF_REMOVE 0x01 /* Removed in new config */
259 #define PDC_CF_DISABLE 0x02 /* Disabled in new config */
260 #define PDC_CF_RESTART 0x03 /* Restart due to reconfiguration */
261 #define PDC_CMD_DISABLE 0x11 /* Result of disable command */
262 #define PDC_CMD_RESTART 0x12 /* Result of restart command */
263 #define PDC_CMD_SHUTDOWN 0x13 /* Result of global shutdown */
264 #define PDC_CMD_GR_DOWN 0x14 /* Result of global graceful restart */
265 #define PDC_RX_LIMIT_HIT 0x21 /* Route receive limit reached */
266 #define PDC_IN_LIMIT_HIT 0x22 /* Route import limit reached */
267 #define PDC_OUT_LIMIT_HIT 0x23 /* Route export limit reached */
268
269
270 void *proto_new(struct proto_config *);
271 void *proto_config_new(struct protocol *, int class);
272 void proto_copy_config(struct proto_config *dest, struct proto_config *src);
273 void proto_clone_config(struct symbol *sym, struct proto_config *parent);
274 void proto_set_message(struct proto *p, char *msg, int len);
275
276 void graceful_restart_recovery(void);
277 void graceful_restart_init(void);
278 void graceful_restart_show_status(void);
279 void channel_graceful_restart_lock(struct channel *c);
280 void channel_graceful_restart_unlock(struct channel *c);
281
282 #define DEFAULT_GR_WAIT 240
283
284 void channel_show_limit(struct channel_limit *l, const char *dsc);
285 void channel_show_info(struct channel *c);
286 void channel_cmd_debug(struct channel *c, uint mask);
287
288 void proto_cmd_show(struct proto *, uintptr_t, int);
289 void proto_cmd_disable(struct proto *, uintptr_t, int);
290 void proto_cmd_enable(struct proto *, uintptr_t, int);
291 void proto_cmd_restart(struct proto *, uintptr_t, int);
292 void proto_cmd_reload(struct proto *, uintptr_t, int);
293 void proto_cmd_debug(struct proto *, uintptr_t, int);
294 void proto_cmd_mrtdump(struct proto *, uintptr_t, int);
295
296 void proto_apply_cmd(struct proto_spec ps, void (* cmd)(struct proto *, uintptr_t, int), int restricted, uintptr_t arg);
297 struct proto *proto_get_named(struct symbol *, struct protocol *);
298 struct proto *proto_iterate_named(struct symbol *sym, struct protocol *proto, struct proto *old);
299
300 #define PROTO_WALK_CMD(sym,pr,p) for(struct proto *p = NULL; p = proto_iterate_named(sym, pr, p); )
301
302
303 #define CMD_RELOAD 0
304 #define CMD_RELOAD_IN 1
305 #define CMD_RELOAD_OUT 2
306
307 static inline u32
308 proto_get_router_id(struct proto_config *pc)
309 {
310 return pc->router_id ? pc->router_id : pc->global->router_id;
311 }
312
313
314 extern pool *proto_pool;
315 extern list proto_list;
316
317 /*
318 * Each protocol instance runs two different state machines:
319 *
320 * [P] The protocol machine: (implemented inside protocol)
321 *
322 * DOWN ----> START
323 * ^ |
324 * | V
325 * STOP <---- UP
326 *
327 * States: DOWN Protocol is down and it's waiting for the core
328 * requesting protocol start.
329 * START Protocol is waiting for connection with the rest
330 * of the network and it's not willing to accept
331 * packets. When it connects, it goes to UP state.
332 * UP Protocol is up and running. When the network
333 * connection breaks down or the core requests
334 * protocol to be terminated, it goes to STOP state.
335 * STOP Protocol is disconnecting from the network.
336 * After it disconnects, it returns to DOWN state.
337 *
338 * In: start() Called in DOWN state to request protocol startup.
339 * Returns new state: either UP or START (in this
340 * case, the protocol will notify the core when it
341 * finally comes UP).
342 * stop() Called in START, UP or STOP state to request
343 * protocol shutdown. Returns new state: either
344 * DOWN or STOP (in this case, the protocol will
345 * notify the core when it finally comes DOWN).
346 *
347 * Out: proto_notify_state() -- called by protocol instance when
348 * it does any state transition not covered by
349 * return values of start() and stop(). This includes
350 * START->UP (delayed protocol startup), UP->STOP
351 * (spontaneous shutdown) and STOP->DOWN (delayed
352 * shutdown).
353 */
354
355 #define PS_DOWN 0
356 #define PS_START 1
357 #define PS_UP 2
358 #define PS_STOP 3
359
360 void proto_notify_state(struct proto *p, unsigned state);
361
362 /*
363 * [F] The feeder machine: (implemented in core routines)
364 *
365 * HUNGRY ----> FEEDING
366 * ^ |
367 * | V
368 * FLUSHING <---- HAPPY
369 *
370 * States: HUNGRY Protocol either administratively down (i.e.,
371 * disabled by the user) or temporarily down
372 * (i.e., [P] is not UP)
373 * FEEDING The protocol came up and we're feeding it
374 * initial routes. [P] is UP.
375 * HAPPY The protocol is up and it's receiving normal
376 * routing updates. [P] is UP.
377 * FLUSHING The protocol is down and we're removing its
378 * routes from the table. [P] is STOP or DOWN.
379 *
380 * Normal lifecycle of a protocol looks like:
381 *
382 * HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
383 * FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
384 * HUNGRY/STOP|DOWN --> HUNGRY/DOWN
385 *
386 * Sometimes, protocol might switch from HAPPY/UP to FEEDING/UP
387 * if it wants to refeed the routes (for example BGP does so
388 * as a result of received ROUTE-REFRESH request).
389 */
390
391
392
393 /*
394 * Debugging flags
395 */
396
397 #define D_STATES 1 /* [core] State transitions */
398 #define D_ROUTES 2 /* [core] Routes passed by the filters */
399 #define D_FILTERS 4 /* [core] Routes rejected by the filters */
400 #define D_IFACES 8 /* [core] Interface events */
401 #define D_EVENTS 16 /* Protocol events */
402 #define D_PACKETS 32 /* Packets sent/received */
403
404 #ifndef PARSER
405 #define TRACE(flags, msg, args...) \
406 do { if (p->p.debug & flags) log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
407 #endif
408
409
410 /*
411 * MRTDump flags
412 */
413
414 #define MD_STATES 1 /* Protocol state changes (BGP4MP_MESSAGE_AS4) */
415 #define MD_MESSAGES 2 /* Protocol packets (BGP4MP_MESSAGE_AS4) */
416
417 /*
418 * Known unique protocol instances as referenced by config routines
419 */
420
421 extern struct proto_config *cf_dev_proto;
422
423
424 /*
425 * Protocol limits
426 */
427
428 #define PLD_RX 0 /* Receive limit */
429 #define PLD_IN 1 /* Import limit */
430 #define PLD_OUT 2 /* Export limit */
431 #define PLD_MAX 3
432
433 #define PLA_NONE 0 /* No limit */
434 #define PLA_WARN 1 /* Issue log warning */
435 #define PLA_BLOCK 2 /* Block new routes */
436 #define PLA_RESTART 4 /* Force protocol restart */
437 #define PLA_DISABLE 5 /* Shutdown and disable protocol */
438
439 #define PLS_INITIAL 0 /* Initial limit state after protocol start */
440 #define PLS_ACTIVE 1 /* Limit was hit */
441 #define PLS_BLOCKED 2 /* Limit is active and blocking new routes */
442
443 struct channel_limit {
444 u32 limit; /* Maximum number of prefixes */
445 u8 action; /* Action to take (PLA_*) */
446 u8 state; /* State of limit (PLS_*) */
447 };
448
449 void channel_notify_limit(struct channel *c, struct channel_limit *l, int dir, u32 rt_count);
450
451
452 /*
453 * Channels
454 */
455
456 struct channel_class {
457 uint channel_size; /* Size of channel data structure */
458 uint config_size; /* Size of channel config data structure */
459
460 void (*init)(struct channel *, struct channel_config *); /* Create new instance */
461 int (*reconfigure)(struct channel *, struct channel_config *, int *import_changed, int *export_changed); /* Try to reconfigure instance, returns success */
462 int (*start)(struct channel *); /* Start the instance */
463 void (*shutdown)(struct channel *); /* Stop the instance */
464 void (*cleanup)(struct channel *); /* Channel finished flush */
465
466 void (*copy_config)(struct channel_config *, struct channel_config *); /* Copy config from given channel instance */
467 #if 0
468 XXXX;
469 void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
470 void (*postconfig)(struct proto_config *); /* After configuring each instance */
471
472
473 void (*dump)(struct proto *); /* Debugging dump */
474
475 void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
476 void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
477 int (*get_attr)(struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */
478 void (*show_proto_info)(struct proto *); /* Show protocol info (for `show protocols all' command) */
479
480 #endif
481 };
482
483 extern const struct channel_class channel_basic;
484 extern const struct channel_class channel_bgp;
485
486 struct channel_config {
487 node n;
488 const char *name;
489 const struct channel_class *channel;
490
491 struct proto_config *parent; /* Where channel is defined (proto or template) */
492 struct rtable_config *table; /* Table we're attached to */
493 const struct filter *in_filter, *out_filter; /* Attached filters */
494 struct channel_limit rx_limit; /* Limit for receiving routes from protocol
495 (relevant when in_keep_filtered is active) */
496 struct channel_limit in_limit; /* Limit for importing routes from protocol */
497 struct channel_limit out_limit; /* Limit for exporting routes to protocol */
498
499 u8 net_type; /* Routing table network type (NET_*), 0 for undefined */
500 u8 ra_mode; /* Mode of received route advertisements (RA_*) */
501 u16 preference; /* Default route preference */
502 u32 debug; /* Debugging flags (D_*) */
503 u8 copy; /* Value from channel_config_get() is new (0) or from template (1) */
504 u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
505 u8 in_keep_filtered; /* Routes rejected in import filter are kept */
506 u8 rpki_reload; /* RPKI changes trigger channel reload */
507 u8 bmp_hack; /* No flush */
508 };
509
510 struct channel {
511 node n; /* Node in proto->channels */
512 node table_node; /* Node in table->channels */
513
514 const char *name; /* Channel name (may be NULL) */
515 const struct channel_class *channel;
516 struct proto *proto;
517
518 struct rtable *table;
519 const struct filter *in_filter; /* Input filter */
520 const struct filter *out_filter; /* Output filter */
521 struct bmap export_map; /* Keeps track which routes passed export filter */
522 struct channel_limit rx_limit; /* Receive limit (for in_keep_filtered) */
523 struct channel_limit in_limit; /* Input limit */
524 struct channel_limit out_limit; /* Output limit */
525
526 struct event *feed_event; /* Event responsible for feeding */
527 struct fib_iterator feed_fit; /* Routing table iterator used during feeding */
528 struct proto_stats stats; /* Per-channel protocol statistics */
529 u32 refeed_count; /* Number of routes exported during refeed regardless of out_limit */
530
531 u8 net_type; /* Routing table network type (NET_*), 0 for undefined */
532 u8 ra_mode; /* Mode of received route advertisements (RA_*) */
533 u16 preference; /* Default route preference */
534 u32 debug; /* Debugging flags (D_*) */
535 u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
536 u8 in_keep_filtered; /* Routes rejected in import filter are kept */
537 u8 disabled;
538 u8 stale; /* Used in reconfiguration */
539
540 u8 channel_state;
541 u8 export_state; /* Route export state (ES_*, see below) */
542 u8 feed_active;
543 u8 flush_active;
544 u8 refeeding; /* We are refeeding (valid only if export_state == ES_FEEDING) */
545 u8 reloadable; /* Hook reload_routes() is allowed on the channel */
546 u8 gr_lock; /* Graceful restart mechanism should wait for this channel */
547 u8 gr_wait; /* Route export to channel is postponed until graceful restart */
548
549 btime last_state_change; /* Time of last state transition */
550
551 struct rtable *in_table; /* Internal table for received routes */
552 struct event *reload_event; /* Event responsible for reloading from in_table */
553 struct fib_iterator reload_fit; /* FIB iterator in in_table used during reloading */
554 struct rte *reload_next_rte; /* Route iterator in in_table used during reloading */
555 u8 reload_active; /* Iterator reload_fit is linked */
556
557 u8 reload_pending; /* Reloading and another reload is scheduled */
558 u8 refeed_pending; /* Refeeding and another refeed is scheduled */
559 u8 rpki_reload; /* RPKI changes trigger channel reload */
560 u8 bmp_hack; /* No flush */
561
562 struct rtable *out_table; /* Internal table for exported routes */
563
564 list roa_subscriptions; /* List of active ROA table subscriptions based on filters roa_check() */
565 };
566
567
568 /*
569 * Channel states
570 *
571 * CS_DOWN - The initial and the final state of a channel. There is no route
572 * exchange between the protocol and the table. Channel is not counted as
573 * active. Channel keeps a ptr to the table, but do not lock the table and is
574 * not linked in the table. Generally, new closed channels are created in
575 * protocols' init() hooks. The protocol is expected to explicitly activate its
576 * channels (by calling channel_init() or channel_open()).
577 *
578 * CS_START - The channel as a connection between the protocol and the table is
579 * initialized (counted as active by the protocol, linked in the table and keeps
580 * the table locked), but there is no current route exchange. There still may be
581 * routes associated with the channel in the routing table if the channel falls
582 * to CS_START from CS_UP. Generally, channels are initialized in protocols'
583 * start() hooks when going to PS_START.
584 *
585 * CS_UP - The channel is initialized and the route exchange is allowed. Note
586 * that even in CS_UP state, route export may still be down (ES_DOWN) by the
587 * core decision (e.g. waiting for table convergence after graceful restart).
588 * I.e., the protocol decides to open the channel but the core decides to start
589 * route export. Route import (caused by rte_update() from the protocol) is not
590 * restricted by that and is on volition of the protocol. Generally, channels
591 * are opened in protocols' start() hooks when going to PS_UP.
592 *
593 * CS_FLUSHING - The transitional state between initialized channel and closed
594 * channel. The channel is still initialized, but no route exchange is allowed.
595 * Instead, the associated table is running flush loop to remove routes imported
596 * through the channel. After that, the channel changes state to CS_DOWN and
597 * is detached from the table (the table is unlocked and the channel is unlinked
598 * from it). Unlike other states, the CS_FLUSHING state is not explicitly
599 * entered or left by the protocol. A protocol may request to close a channel
600 * (by calling channel_close()), which causes the channel to change state to
601 * CS_FLUSHING and later to CS_DOWN. Also note that channels are closed
602 * automatically by the core when the protocol is going down.
603 *
604 * Allowed transitions:
605 *
606 * CS_DOWN -> CS_START / CS_UP
607 * CS_START -> CS_UP / CS_FLUSHING
608 * CS_UP -> CS_START / CS_FLUSHING
609 * CS_FLUSHING -> CS_DOWN (automatic)
610 */
611
612 #define CS_DOWN 0
613 #define CS_START 1
614 #define CS_UP 2
615 #define CS_FLUSHING 3
616
617 #define ES_DOWN 0
618 #define ES_FEEDING 1
619 #define ES_READY 2
620
621
622 struct channel_config *proto_cf_find_channel(struct proto_config *p, uint net_type);
623 static inline struct channel_config *proto_cf_main_channel(struct proto_config *pc)
624 { return proto_cf_find_channel(pc, pc->net_type); }
625 static inline struct channel_config *proto_cf_mpls_channel(struct proto_config *pc)
626 { return proto_cf_find_channel(pc, NET_MPLS); }
627
628 struct channel *proto_find_channel_by_table(struct proto *p, struct rtable *t);
629 struct channel *proto_find_channel_by_name(struct proto *p, const char *n);
630 struct channel *proto_add_channel(struct proto *p, struct channel_config *cf);
631 void proto_remove_channel(struct proto *p, struct channel *c);
632 int proto_configure_channel(struct proto *p, struct channel **c, struct channel_config *cf);
633 void proto_setup_mpls_map(struct proto *p, uint rts, int hooks);
634 void proto_shutdown_mpls_map(struct proto *p, int hooks);
635
636 void channel_set_state(struct channel *c, uint state);
637 void channel_setup_in_table(struct channel *c);
638 void channel_setup_out_table(struct channel *c);
639 void channel_schedule_reload(struct channel *c);
640
641 static inline void channel_init(struct channel *c) { channel_set_state(c, CS_START); }
642 static inline void channel_open(struct channel *c) { channel_set_state(c, CS_UP); }
643 static inline void channel_close(struct channel *c) { channel_set_state(c, CS_FLUSHING); }
644
645 void channel_request_feeding(struct channel *c);
646 void *channel_config_new(const struct channel_class *cc, const char *name, uint net_type, struct proto_config *proto);
647 void *channel_config_get(const struct channel_class *cc, const char *name, uint net_type, struct proto_config *proto);
648 int channel_reconfigure(struct channel *c, struct channel_config *cf);
649
650
651 /* Moved from route.h to avoid dependency conflicts */
652 static inline void rte_update(struct proto *p, const net_addr *n, rte *new) { rte_update2(p->main_channel, n, new, p->main_source); }
653
654 static inline void
655 rte_update3(struct channel *c, const net_addr *n, rte *new, struct rte_src *src)
656 {
657 if (c->in_table && !rte_update_in(c, n, new, src))
658 return;
659
660 rte_update2(c, n, new, src);
661 }
662
663
664 #endif