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