Revision f4a60a9b nest/protocol.h

View differences:

nest/protocol.h
11 11

  
12 12
#include "lib/lists.h"
13 13
#include "lib/resource.h"
14
#include "lib/event.h"
14 15
#include "lib/timer.h"
16
#include "nest/route.h"
15 17
#include "conf/conf.h"
16 18

  
17 19
struct iface;
......
22 24
struct rta;
23 25
struct network;
24 26
struct proto_config;
27
struct channel_limit;
28
struct channel_config;
25 29
struct config;
26 30
struct proto;
27
struct event;
31
struct channel;
28 32
struct ea_list;
29 33
struct eattr;
30 34
struct symbol;
31 35

  
36

  
32 37
/*
33 38
 *	Routing Protocol
34 39
 */
......
39 44
  char *template;			/* Template for automatic generation of names */
40 45
  int name_counter;			/* Counter for automatic name generation */
41 46
  int attr_class;			/* Attribute class known to this protocol */
42
  int multitable;			/* Protocol handles all announce hooks itself */
43 47
  uint preference;			/* Default protocol preference */
44
  uint config_size;			/* Size of protocol config */
48
  uint channel_mask;			/* Mask of accepted channel types (NB_*) */
49
  uint proto_size;			/* Size of protocol data structure */
50
  uint config_size;			/* Size of protocol config data structure */
45 51

  
46 52
  void (*preconfig)(struct protocol *, struct config *);	/* Just before configuring */
47 53
  void (*postconfig)(struct proto_config *);			/* After configuring each instance */
......
62 68
void protos_build(void);
63 69
void proto_build(struct protocol *);
64 70
void protos_preconfig(struct config *);
65
void protos_postconfig(struct config *);
66 71
void protos_commit(struct config *new, struct config *old, int force_restart, int type);
67 72
void protos_dump_all(void);
68 73

  
......
90 95
  char *name;
91 96
  char *dsc;
92 97
  int class;				/* SYM_PROTO or SYM_TEMPLATE */
98
  u8 net_type;				/* Protocol network type (NET_*), 0 for undefined */
99
  u8 disabled;				/* Protocol enabled/disabled by default */
93 100
  u32 debug, mrtdump;			/* Debugging bitfields, both use D_* constants */
94
  unsigned preference, disabled;	/* Generic parameters */
95
  int in_keep_filtered;			/* Routes rejected in import filter are kept */
96 101
  u32 router_id;			/* Protocol specific router ID */
97
  struct rtable_config *table;		/* Table we're attached to */
98
  struct filter *in_filter, *out_filter; /* Attached filters */
99
  struct proto_limit *rx_limit;		/* Limit for receiving routes from protocol
100
					   (relevant when in_keep_filtered is active) */
101
  struct proto_limit *in_limit;		/* Limit for importing routes from protocol */
102
  struct proto_limit *out_limit;	/* Limit for exporting routes to protocol */
102

  
103
  list channels;			/* List of channel configs (struct channel_config) */
103 104

  
104 105
  /* Check proto_reconfigure() and proto_copy_config() after changing struct proto_config */
105 106

  
......
111 112
  /* Import - from protocol to core */
112 113
  u32 imp_routes;		/* Number of routes successfully imported to the (adjacent) routing table */
113 114
  u32 filt_routes;		/* Number of routes rejected in import filter but kept in the routing table */
114
  u32 pref_routes;		/* Number of routes that are preferred, sum over all routing tables */
115 115
  u32 imp_updates_received;	/* Number of route updates received */
116 116
  u32 imp_updates_invalid;	/* Number of route updates rejected as invalid */
117 117
  u32 imp_updates_filtered;	/* Number of route updates rejected by filters */
......
133 133
};
134 134

  
135 135
struct proto {
136
  node n;				/* Node in *_proto_list */
137
  node glob_node;			/* Node in global proto_list */
136
  node n;				/* Node in global proto_list */
138 137
  struct protocol *proto;		/* Protocol */
139 138
  struct proto_config *cf;		/* Configuration data */
140 139
  struct proto_config *cf_new;		/* Configuration we want to switch to after shutdown (NULL=delete) */
141 140
  pool *pool;				/* Pool containing local objects */
142
  struct event *attn;			/* "Pay attention" event */
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 */
143 146

  
144 147
  char *name;				/* Name of this instance (== cf->name) */
145 148
  u32 debug;				/* Debugging flags */
146 149
  u32 mrtdump;				/* MRTDump flags */
147
  unsigned preference;			/* Default route preference */
148
  byte accept_ra_types;			/* Which types of route announcements are accepted (RA_OPTIMAL or RA_ANY) */
150
  uint active_channels;			/* Number of active channels */
151
  byte net_type;			/* Protocol network type (NET_*), 0 for undefined */
149 152
  byte disabled;			/* Manually disabled */
150 153
  byte proto_state;			/* Protocol state machine (PS_*, see below) */
151
  byte core_state;			/* Core state machine (FS_*, see below) */
152
  byte export_state;			/* Route export state (ES_*, see below) */
154
  byte active;				/* From PS_START to cleanup after PS_STOP */
155
  byte do_start;			/* Start actions are scheduled */
156
  byte do_stop;				/* Stop actions are scheduled */
153 157
  byte reconfiguring;			/* We're shutting down due to reconfiguration */
154
  byte refeeding;			/* We are refeeding (valid only if export_state == ES_FEEDING) */
155
  byte flushing;			/* Protocol is flushed in current flush loop round */
156 158
  byte gr_recovery;			/* Protocol should participate in graceful restart recovery */
157
  byte gr_lock;				/* Graceful restart mechanism should wait for this proto */
158
  byte gr_wait;				/* Route export to protocol is postponed until graceful restart */
159 159
  byte down_sched;			/* Shutdown is scheduled for later (PDS_*) */
160 160
  byte down_code;			/* Reason for shutdown (PDC_* codes) */
161
  byte merge_limit;			/* Maximal number of nexthops for RA_MERGED */
162 161
  u32 hash_key;				/* Random key used for hashing of neighbors */
163 162
  bird_clock_t last_state_change;	/* Time of last state transition */
164 163
  char *last_state_name_announced;	/* Last state name we've announced to the user */
165
  struct proto_stats stats;		/* Current protocol statistics */
166 164

  
167 165
  /*
168 166
   *	General protocol hooks:
......
177 175
   *			It can construct a new rte, add private attributes and
178 176
   *			decide whether the route shall be imported: 1=yes, -1=no,
179 177
   *			0=process it through the import filter set by the user.
180
   *	   reload_routes   Request protocol to reload all its routes to the core
178
   *	   reload_routes   Request channel to reload all its routes to the core
181 179
   *			(using rte_update()). Returns: 0=reload cannot be done,
182 180
   *			1= reload is scheduled and will happen (asynchronously).
183
   *	   feed_begin	Notify protocol about beginning of route feeding.
184
   *	   feed_end	Notify protocol about finish of route feeding.
181
   *	   feed_begin	Notify channel about beginning of route feeding.
182
   *	   feed_end	Notify channel about finish of route feeding.
185 183
   */
186 184

  
187 185
  void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
......
191 189
  struct ea_list *(*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
192 190
  void (*store_tmp_attrs)(struct rte *rt, struct ea_list *attrs);
193 191
  int (*import_control)(struct proto *, struct rte **rt, struct ea_list **attrs, struct linpool *pool);
194
  int (*reload_routes)(struct proto *);
195
  void (*feed_begin)(struct proto *, int initial);
196
  void (*feed_end)(struct proto *);
192
  void (*reload_routes)(struct channel *);
193
  void (*feed_begin)(struct channel *, int initial);
194
  void (*feed_end)(struct channel *);
197 195

  
198 196
  /*
199 197
   *	Routing entry hooks (called only for routes belonging to this protocol):
......
213 211
  void (*rte_insert)(struct network *, struct rte *);
214 212
  void (*rte_remove)(struct network *, struct rte *);
215 213

  
216
  struct rtable *table;			/* Our primary routing table */
217
  struct rte_src *main_source;		/* Primary route source */
218
  struct announce_hook *main_ahook;	/* Primary announcement hook */
219
  struct announce_hook *ahooks;		/* Announcement hooks for this protocol */
220

  
221
  struct fib_iterator *feed_iterator;	/* Routing table iterator used during protocol feeding */
222
  struct announce_hook *feed_ahook;	/* Announce hook we currently feed */
223

  
224 214
  /* Hic sunt protocol-specific data */
225 215
};
226 216

  
......
244 234
#define PDC_OUT_LIMIT_HIT	0x23	/* Route export limit reached */
245 235

  
246 236

  
247
void *proto_new(struct proto_config *, unsigned size);
237
void *proto_new(struct proto_config *);
248 238
void *proto_config_new(struct protocol *, int class);
249 239
void proto_copy_config(struct proto_config *dest, struct proto_config *src);
250
void proto_request_feeding(struct proto *p);
251

  
252
static inline void
253
proto_copy_rest(struct proto_config *dest, struct proto_config *src, unsigned size)
254
{ memcpy(dest + 1, src + 1, size - sizeof(struct proto_config)); }
255 240

  
256 241
void graceful_restart_recovery(void);
257 242
void graceful_restart_init(void);
258 243
void graceful_restart_show_status(void);
259
void proto_graceful_restart_lock(struct proto *p);
260
void proto_graceful_restart_unlock(struct proto *p);
244
void channel_graceful_restart_lock(struct channel *c);
245
void channel_graceful_restart_unlock(struct channel *c);
261 246

  
262 247
#define DEFAULT_GR_WAIT	240
263 248

  
264
void proto_show_limit(struct proto_limit *l, const char *dsc);
265
void proto_show_basic_info(struct proto *p);
249
void channel_show_limit(struct channel_limit *l, const char *dsc);
250
void channel_show_info(struct channel *c);
266 251

  
267 252
void proto_cmd_show(struct proto *, uint, int);
268 253
void proto_cmd_disable(struct proto *, uint, int);
......
285 270
  return pc->router_id ? pc->router_id : pc->global->router_id;
286 271
}
287 272

  
288
extern list active_proto_list;
273
/* Moved from route.h to avoid dependency conflicts */
274
static inline void rte_update(struct proto *p, net *net, rte *new) { rte_update2(p->main_channel, net, new, p->main_source); }
275

  
276
extern list proto_list;
289 277

  
290 278
/*
291 279
 *  Each protocol instance runs two different state machines:
......
361 349
 *	as a result of received ROUTE-REFRESH request).
362 350
 */
363 351

  
364
#define FS_HUNGRY	0
365
#define FS_FEEDING	1	/* obsolete */
366
#define FS_HAPPY	2
367
#define FS_FLUSHING	3
368

  
369

  
370
#define ES_DOWN		0
371
#define ES_FEEDING	1
372
#define ES_READY	2
373

  
374 352

  
375 353

  
376 354
/*
......
413 391
#define PLD_OUT		2	/* Export limit */
414 392
#define PLD_MAX		3
415 393

  
394
#define PLA_NONE	0	/* No limit */
416 395
#define PLA_WARN	1	/* Issue log warning */
417 396
#define PLA_BLOCK	2	/* Block new routes */
418 397
#define PLA_RESTART	4	/* Force protocol restart */
......
422 401
#define PLS_ACTIVE	1	/* Limit was hit */
423 402
#define PLS_BLOCKED	2	/* Limit is active and blocking new routes */
424 403

  
425
struct proto_limit {
404
struct channel_limit {
426 405
  u32 limit;			/* Maximum number of prefixes */
427
  byte action;			/* Action to take (PLA_*) */
428
  byte state;			/* State of limit (PLS_*) */
406
  u8 action;			/* Action to take (PLA_*) */
407
  u8 state;			/* State of limit (PLS_*) */
429 408
};
430 409

  
431
void proto_notify_limit(struct announce_hook *ah, struct proto_limit *l, int dir, u32 rt_count);
432
void proto_verify_limits(struct announce_hook *ah);
433

  
434
static inline void
435
proto_reset_limit(struct proto_limit *l)
436
{
437
  if (l)
438
    l->state = PLS_INITIAL;
439
}
410
void channel_notify_limit(struct channel *c, struct channel_limit *l, int dir, u32 rt_count);
440 411

  
441 412

  
442 413
/*
443
 *	Route Announcement Hook
414
 *	Channels
444 415
 */
445 416

  
446
struct announce_hook {
417
struct channel_class {
418
  uint channel_size;			/* Size of channel data structure */
419
  uint config_size;			/* Size of channel config data structure */
420

  
421
  struct channel * (*init)(struct channel *, struct channel_config *);	/* Create new instance */
422
  int (*reconfigure)(struct channel *, struct channel_config *);	/* Try to reconfigure instance, returns success */
423
  int (*start)(struct channel *);	/* Start the instance */
424
  int (*shutdown)(struct channel *);	/* Stop the instance */
425

  
426
  void (*copy_config)(struct channel_config *, struct channel_config *); /* Copy config from given channel instance */
427
#if 0
428
  void (*preconfig)(struct protocol *, struct config *);	/* Just before configuring */
429
  void (*postconfig)(struct proto_config *);			/* After configuring each instance */
430

  
431

  
432
  void (*dump)(struct proto *);			/* Debugging dump */
433
  void (*dump_attrs)(struct rte *);		/* Dump protocol-dependent attributes */
434
  void (*cleanup)(struct proto *);		/* Called after shutdown when protocol became hungry/down */
435
  void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
436
  void (*get_route_info)(struct rte *, byte *buf, struct ea_list *attrs); /* Get route information (for `show route' command) */
437
  int (*get_attr)(struct eattr *, byte *buf, int buflen);	/* ASCIIfy dynamic attribute (returns GA_*) */
438
  void (*show_proto_info)(struct proto *);	/* Show protocol info (for `show protocols all' command) */
439

  
440
#endif
441
};
442

  
443
struct channel_config {
447 444
  node n;
448
  struct rtable *table;
445
  const char *name;
446
  const struct channel_class *channel;
447

  
448
  struct rtable_config *table;		/* Table we're attached to */
449
  struct filter *in_filter, *out_filter; /* Attached filters */
450
  struct channel_limit rx_limit;	/* Limit for receiving routes from protocol
451
					   (relevant when in_keep_filtered is active) */
452
  struct channel_limit in_limit;	/* Limit for importing routes from protocol */
453
  struct channel_limit out_limit;	/* Limit for exporting routes to protocol */
454

  
455
  u8 net_type;				/* Routing table network type (NET_*), 0 for undefined */
456
  u8 ra_mode;				/* Mode of received route advertisements (RA_*) */
457
  u16 preference;			/* Default route preference */
458
  u8 merge_limit;			/* Maximal number of nexthops for RA_MERGED */
459
  u8 in_keep_filtered;			/* Routes rejected in import filter are kept */
460
};
461

  
462
struct channel {
463
  node n;				/* Node in proto->channels */
464
  node table_node;			/* Node in table->channels */
465

  
466
  const char *name;			/* Channel name (may be NULL) */
467
  const struct channel_class *channel;
449 468
  struct proto *proto;
469

  
470
  struct rtable *table;
450 471
  struct filter *in_filter;		/* Input filter */
451 472
  struct filter *out_filter;		/* Output filter */
452
  struct proto_limit *rx_limit;		/* Receive limit (for in_keep_filtered) */
453
  struct proto_limit *in_limit;		/* Input limit */
454
  struct proto_limit *out_limit;	/* Output limit */
455
  struct proto_stats *stats;		/* Per-table protocol statistics */
456
  struct announce_hook *next;		/* Next hook for the same protocol */
457
  int in_keep_filtered;			/* Routes rejected in import filter are kept */
473
  struct channel_limit rx_limit;	/* Receive limit (for in_keep_filtered) */
474
  struct channel_limit in_limit;	/* Input limit */
475
  struct channel_limit out_limit;	/* Output limit */
476

  
477
  struct event *feed_event;		/* Event responsible for feeding */
478
  struct fib_iterator feed_fit;		/* Routing table iterator used during feeding */
479
  struct proto_stats stats;		/* Per-channel protocol statistics */
480

  
481
  u8 net_type;				/* Routing table network type (NET_*), 0 for undefined */
482
  u8 ra_mode;				/* Mode of received route advertisements (RA_*) */
483
  u16 preference;			/* Default route preference */
484
  u8 merge_limit;			/* Maximal number of nexthops for RA_MERGED */
485
  u8 in_keep_filtered;			/* Routes rejected in import filter are kept */
486
  u8 disabled;
487

  
488
  u8 channel_state;
489
  u8 export_state;			/* Route export state (ES_*, see below) */
490
  u8 feed_active;
491
  u8 flush_active;
492
  u8 refeeding;				/* We are refeeding (valid only if export_state == ES_FEEDING) */
493
  u8 reloadable;			/* Hook reload_routes() is allowed on the channel */
494
  u8 gr_lock;				/* Graceful restart mechanism should wait for this channel */
495
  u8 gr_wait;				/* Route export to channel is postponed until graceful restart */
496

  
497
  bird_clock_t last_state_change;	/* Time of last state transition */
458 498
};
459 499

  
460
struct announce_hook *proto_add_announce_hook(struct proto *p, struct rtable *t, struct proto_stats *stats);
461
struct announce_hook *proto_find_announce_hook(struct proto *p, struct rtable *t);
500

  
501
/*
502
 * Channel states
503
 *
504
 * CS_DOWN - The initial and the final state of a channel. There is no route
505
 * exchange between the protocol and the table. Channel is not counted as
506
 * active. Channel keeps a ptr to the table, but do not lock the table and is
507
 * not linked in the table. Generally, new closed channels are created in
508
 * protocols' init() hooks. The protocol is expected to explicitly activate its
509
 * channels (by calling channel_init() or channel_open()).
510
 *
511
 * CS_START - The channel as a connection between the protocol and the table is
512
 * initialized (counted as active by the protocol, linked in the table and keeps
513
 * the table locked), but there is no current route exchange. There still may be
514
 * routes associated with the channel in the routing table if the channel falls
515
 * to CS_START from CS_UP. Generally, channels are initialized in protocols'
516
 * start() hooks when going to PS_START.
517
 *
518
 * CS_UP - The channel is initialized and the route exchange is allowed. Note
519
 * that even in CS_UP state, route export may still be down (ES_DOWN) by the
520
 * core decision (e.g. waiting for table convergence after graceful restart).
521
 * I.e., the protocol decides to open the channel but the core decides to start
522
 * route export. Route import (caused by rte_update() from the protocol) is not
523
 * restricted by that and is on volition of the protocol. Generally, channels
524
 * are opened in protocols' start() hooks when going to PS_UP.
525
 *
526
 * CS_FLUSHING - The transitional state between initialized channel and closed
527
 * channel. The channel is still initialized, but no route exchange is allowed.
528
 * Instead, the associated table is running flush loop to remove routes imported
529
 * through the channel. After that, the channel changes state to CS_DOWN and
530
 * is detached from the table (the table is unlocked and the channel is unlinked
531
 * from it). Unlike other states, the CS_FLUSHING state is not explicitly
532
 * entered or left by the protocol. A protocol may request to close a channel
533
 * (by calling channel_close()), which causes the channel to change state to
534
 * CS_FLUSHING and later to CS_DOWN. Also note that channels are closed
535
 * automatically by the core when the protocol is going down.
536
 *
537
 * Allowed transitions:
538
 *
539
 * CS_DOWN	-> CS_START / CS_UP
540
 * CS_START	-> CS_UP / CS_FLUSHING
541
 * CS_UP	-> CS_START / CS_FLUSHING
542
 * CS_FLUSHING	-> CS_DOWN (automatic)
543
 */
544

  
545
#define CS_DOWN		0
546
#define CS_START	1
547
#define CS_UP		2
548
#define CS_FLUSHING	3
549

  
550
#define ES_DOWN		0
551
#define ES_FEEDING	1
552
#define ES_READY	2
553

  
554

  
555
struct channel_config *proto_cf_find_channel(struct proto_config *p, uint net_type);
556
static inline struct channel_config *proto_cf_main_channel(struct proto_config *pc)
557
{ struct channel_config *cc = HEAD(pc->channels); return NODE_VALID(cc) ? cc : NULL; }
558

  
559
struct channel *proto_find_channel_by_table(struct proto *p, struct rtable *t);
560
struct channel *proto_add_channel(struct proto *p, struct channel_config *cf);
561
int proto_configure_channel(struct proto *p, struct channel **c, struct channel_config *cf);
562

  
563
void channel_set_state(struct channel *c, uint state);
564

  
565
/*
566
static inline void channel_init(struct channel *c) { channel_set_state(c, CS_START); }
567
static inline void channel_open(struct channel *c) { channel_set_state(c, CS_UP); }
568
static inline void channel_close(struct channel *c) { channel_set_state(c, CS_FLUSHING); }
569
*/
570

  
571
void channel_request_feeding(struct channel *c);
572
void *channel_config_new(const struct channel_class *cc, uint net_type, struct proto_config *proto);
573
int channel_reconfigure(struct channel *c, struct channel_config *cf);
574

  
462 575

  
463 576
#endif

Also available in: Unified diff