#include "lib/lists.h"
#include "lib/resource.h"
#include "lib/event.h"
-#include "sysdep/unix/timer.h"
#include "nest/route.h"
#include "conf/conf.h"
* Routing Protocol
*/
+enum protocol_class {
+ PROTOCOL_NONE,
+ PROTOCOL_BABEL,
+ PROTOCOL_BFD,
+ PROTOCOL_BGP,
+ PROTOCOL_DEVICE,
+ PROTOCOL_DIRECT,
+ PROTOCOL_KERNEL,
+ PROTOCOL_OSPF,
+ PROTOCOL_MRT,
+ PROTOCOL_PERF,
+ PROTOCOL_PIPE,
+ PROTOCOL_RADV,
+ PROTOCOL_RIP,
+ PROTOCOL_RPKI,
+ PROTOCOL_STATIC,
+ PROTOCOL__MAX
+};
+
+extern struct protocol *class_to_protocol[PROTOCOL__MAX];
+
struct protocol {
node n;
char *name;
char *template; /* Template for automatic generation of names */
int name_counter; /* Counter for automatic name generation */
- int attr_class; /* Attribute class known to this protocol */
+ enum protocol_class class; /* Machine readable protocol class */
uint preference; /* Default protocol preference */
uint channel_mask; /* Mask of accepted channel types (NB_*) */
uint proto_size; /* Size of protocol data structure */
int (*shutdown)(struct proto *); /* Stop the instance */
void (*cleanup)(struct proto *); /* Called after shutdown when protocol became hungry/down */
void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
- void (*get_route_info)(struct rte *, byte *buf, struct ea_list *attrs); /* Get route information (for `show route' command) */
+ void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
int (*get_attr)(struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */
void (*show_proto_info)(struct proto *); /* Show protocol info (for `show protocols all' command) */
void (*copy_config)(struct proto_config *, struct proto_config *); /* Copy config from given protocol instance */
void proto_build(struct protocol *);
void protos_preconfig(struct config *);
void protos_commit(struct config *new, struct config *old, int force_restart, int type);
+struct proto * proto_spawn(struct proto_config *cf, uint disabled);
void protos_dump_all(void);
#define GA_UNKNOWN 0 /* Attribute not recognized */
*/
extern struct protocol
- proto_device, proto_radv, proto_rip, proto_static,
- proto_ospf, proto_pipe, proto_bgp, proto_bfd, proto_babel;
+ proto_device, proto_radv, proto_rip, proto_static, proto_mrt,
+ proto_ospf, proto_perf,
+ proto_pipe, proto_bgp, proto_bfd, proto_babel, proto_rpki;
/*
* Routing Protocol Instance
struct config *global; /* Global configuration data */
struct protocol *protocol; /* Protocol */
struct proto *proto; /* Instance we've created */
+ struct proto_config *parent; /* Parent proto_config for dynamic protocols */
char *name;
char *dsc;
int class; /* SYM_PROTO or SYM_TEMPLATE */
u32 router_id; /* Protocol specific router ID */
list channels; /* List of channel configs (struct channel_config) */
+ struct iface *vrf; /* Related VRF instance, NULL if global */
/* Check proto_reconfigure() and proto_copy_config() after changing struct proto_config */
/* Import - from protocol to core */
u32 imp_routes; /* Number of routes successfully imported to the (adjacent) routing table */
u32 filt_routes; /* Number of routes rejected in import filter but kept in the routing table */
+ u32 pref_routes; /* Number of routes selected as best in the (adjacent) routing table */
u32 imp_updates_received; /* Number of route updates received */
u32 imp_updates_invalid; /* Number of route updates rejected as invalid */
u32 imp_updates_filtered; /* Number of route updates rejected by filters */
list channels; /* List of channels to rtables (struct channel) */
struct channel *main_channel; /* Primary channel */
struct rte_src *main_source; /* Primary route source */
+ struct iface *vrf; /* Related VRF instance, NULL if global */
char *name; /* Name of this instance (== cf->name) */
u32 debug; /* Debugging flags */
byte down_sched; /* Shutdown is scheduled for later (PDS_*) */
byte down_code; /* Reason for shutdown (PDC_* codes) */
u32 hash_key; /* Random key used for hashing of neighbors */
- bird_clock_t last_state_change; /* Time of last state transition */
+ btime last_state_change; /* Time of last state transition */
char *last_state_name_announced; /* Last state name we've announced to the user */
+ char *message; /* State-change message, allocated from proto_pool */
/*
* General protocol hooks:
* ifa_notify Notify protocol about interface address changes.
* rt_notify Notify protocol about routing table updates.
* neigh_notify Notify protocol about neighbor cache events.
- * make_tmp_attrs Construct ea_list from private attrs stored in rte.
- * store_tmp_attrs Store private attrs back to the rte.
- * import_control Called as the first step of the route importing process.
+ * make_tmp_attrs Add attributes to rta from from private attrs stored in rte. The route and rta MUST NOT be cached.
+ * store_tmp_attrs Store private attrs back to rte and undef added attributes. The route and rta MUST NOT be cached.
+ * preexport Called as the first step of the route exporting process.
* It can construct a new rte, add private attributes and
- * decide whether the route shall be imported: 1=yes, -1=no,
- * 0=process it through the import filter set by the user.
+ * decide whether the route shall be exported: 1=yes, -1=no,
+ * 0=process it through the export filter set by the user.
* reload_routes Request channel to reload all its routes to the core
* (using rte_update()). Returns: 0=reload cannot be done,
* 1= reload is scheduled and will happen (asynchronously).
void (*if_notify)(struct proto *, unsigned flags, struct iface *i);
void (*ifa_notify)(struct proto *, unsigned flags, struct ifa *a);
- void (*rt_notify)(struct proto *, struct channel *, struct network *net, struct rte *new, struct rte *old, struct ea_list *attrs);
+ void (*rt_notify)(struct proto *, struct channel *, struct network *net, struct rte *new, struct rte *old);
void (*neigh_notify)(struct neighbor *neigh);
- struct ea_list *(*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
- void (*store_tmp_attrs)(struct rte *rt, struct ea_list *attrs);
- int (*import_control)(struct proto *, struct rte **rt, struct ea_list **attrs, struct linpool *pool);
+ void (*make_tmp_attrs)(struct rte *rt, struct linpool *pool);
+ void (*store_tmp_attrs)(struct rte *rt, struct linpool *pool);
+ int (*preexport)(struct proto *, struct rte **rt, struct linpool *pool);
void (*reload_routes)(struct channel *);
void (*feed_begin)(struct channel *, int initial);
void (*feed_end)(struct channel *);
int (*rte_better)(struct rte *, struct rte *);
int (*rte_same)(struct rte *, struct rte *);
int (*rte_mergable)(struct rte *, struct rte *);
+ struct rte * (*rte_modify)(struct rte *, struct linpool *);
void (*rte_insert)(struct network *, struct rte *);
void (*rte_remove)(struct network *, struct rte *);
#define PDC_CMD_DISABLE 0x11 /* Result of disable command */
#define PDC_CMD_RESTART 0x12 /* Result of restart command */
#define PDC_CMD_SHUTDOWN 0x13 /* Result of global shutdown */
+#define PDC_CMD_GR_DOWN 0x14 /* Result of global graceful restart */
#define PDC_RX_LIMIT_HIT 0x21 /* Route receive limit reached */
#define PDC_IN_LIMIT_HIT 0x22 /* Route import limit reached */
#define PDC_OUT_LIMIT_HIT 0x23 /* Route export limit reached */
void *proto_new(struct proto_config *);
void *proto_config_new(struct protocol *, int class);
void proto_copy_config(struct proto_config *dest, struct proto_config *src);
+void proto_clone_config(struct symbol *sym, struct proto_config *parent);
+void proto_set_message(struct proto *p, char *msg, int len);
void graceful_restart_recovery(void);
void graceful_restart_init(void);
void channel_show_limit(struct channel_limit *l, const char *dsc);
void channel_show_info(struct channel *c);
-void proto_cmd_show(struct proto *, uint, int);
-void proto_cmd_disable(struct proto *, uint, int);
-void proto_cmd_enable(struct proto *, uint, int);
-void proto_cmd_restart(struct proto *, uint, int);
-void proto_cmd_reload(struct proto *, uint, int);
-void proto_cmd_debug(struct proto *, uint, int);
-void proto_cmd_mrtdump(struct proto *, uint, int);
+void proto_cmd_show(struct proto *, uintptr_t, int);
+void proto_cmd_disable(struct proto *, uintptr_t, int);
+void proto_cmd_enable(struct proto *, uintptr_t, int);
+void proto_cmd_restart(struct proto *, uintptr_t, int);
+void proto_cmd_reload(struct proto *, uintptr_t, int);
+void proto_cmd_debug(struct proto *, uintptr_t, int);
+void proto_cmd_mrtdump(struct proto *, uintptr_t, int);
-void proto_apply_cmd(struct proto_spec ps, void (* cmd)(struct proto *, uint, int), int restricted, uint arg);
+void proto_apply_cmd(struct proto_spec ps, void (* cmd)(struct proto *, uintptr_t, int), int restricted, uintptr_t arg);
struct proto *proto_get_named(struct symbol *, struct protocol *);
#define CMD_RELOAD 0
return pc->router_id ? pc->router_id : pc->global->router_id;
}
-/* Moved from route.h to avoid dependency conflicts */
-static inline void rte_update(struct proto *p, net_addr *n, rte *new) { rte_update2(p->main_channel, n, new, p->main_source); }
+extern pool *proto_pool;
extern list proto_list;
/*
*
* HUNGRY ----> FEEDING
* ^ |
- * | V
+ * | V
* FLUSHING <---- HAPPY
*
* States: HUNGRY Protocol either administratively down (i.e.,
uint channel_size; /* Size of channel data structure */
uint config_size; /* Size of channel config data structure */
- struct channel * (*init)(struct channel *, struct channel_config *); /* Create new instance */
+ void (*init)(struct channel *, struct channel_config *); /* Create new instance */
int (*reconfigure)(struct channel *, struct channel_config *); /* Try to reconfigure instance, returns success */
int (*start)(struct channel *); /* Start the instance */
- int (*shutdown)(struct channel *); /* Stop the instance */
+ void (*shutdown)(struct channel *); /* Stop the instance */
+ void (*cleanup)(struct channel *); /* Channel finished flush */
void (*copy_config)(struct channel_config *, struct channel_config *); /* Copy config from given channel instance */
#if 0
+ XXXX;
void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
void (*postconfig)(struct proto_config *); /* After configuring each instance */
void (*dump)(struct proto *); /* Debugging dump */
void (*dump_attrs)(struct rte *); /* Dump protocol-dependent attributes */
- void (*cleanup)(struct proto *); /* Called after shutdown when protocol became hungry/down */
+
void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
- void (*get_route_info)(struct rte *, byte *buf, struct ea_list *attrs); /* Get route information (for `show route' command) */
+ void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
int (*get_attr)(struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */
void (*show_proto_info)(struct proto *); /* Show protocol info (for `show protocols all' command) */
#endif
};
+extern struct channel_class channel_bgp;
+
struct channel_config {
node n;
const char *name;
const struct channel_class *channel;
+ struct proto_config *parent; /* Where channel is defined (proto or template) */
struct rtable_config *table; /* Table we're attached to */
- struct filter *in_filter, *out_filter; /* Attached filters */
+ const struct filter *in_filter, *out_filter; /* Attached filters */
struct channel_limit rx_limit; /* Limit for receiving routes from protocol
(relevant when in_keep_filtered is active) */
struct channel_limit in_limit; /* Limit for importing routes from protocol */
struct proto *proto;
struct rtable *table;
- struct filter *in_filter; /* Input filter */
- struct filter *out_filter; /* Output filter */
+ const struct filter *in_filter; /* Input filter */
+ const struct filter *out_filter; /* Output filter */
struct channel_limit rx_limit; /* Receive limit (for in_keep_filtered) */
struct channel_limit in_limit; /* Input limit */
struct channel_limit out_limit; /* Output limit */
u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
u8 in_keep_filtered; /* Routes rejected in import filter are kept */
u8 disabled;
+ u8 stale; /* Used in reconfiguration */
u8 channel_state;
u8 export_state; /* Route export state (ES_*, see below) */
u8 gr_lock; /* Graceful restart mechanism should wait for this channel */
u8 gr_wait; /* Route export to channel is postponed until graceful restart */
- bird_clock_t last_state_change; /* Time of last state transition */
+ btime last_state_change; /* Time of last state transition */
+ btime last_tx_filter_change;
+
+ struct rtable *in_table; /* Internal table for received routes */
+ struct event *reload_event; /* Event responsible for reloading from in_table */
+ struct fib_iterator reload_fit; /* Iterator in in_table used during reloading */
+ u8 reload_active; /* Iterator reload_fit is linked */
};
{ struct channel_config *cc = HEAD(pc->channels); return NODE_VALID(cc) ? cc : NULL; }
struct channel *proto_find_channel_by_table(struct proto *p, struct rtable *t);
+struct channel *proto_find_channel_by_name(struct proto *p, const char *n);
struct channel *proto_add_channel(struct proto *p, struct channel_config *cf);
int proto_configure_channel(struct proto *p, struct channel **c, struct channel_config *cf);
void channel_set_state(struct channel *c, uint state);
+void channel_setup_in_table(struct channel *c);
+void channel_schedule_reload(struct channel *c);
-/*
static inline void channel_init(struct channel *c) { channel_set_state(c, CS_START); }
static inline void channel_open(struct channel *c) { channel_set_state(c, CS_UP); }
static inline void channel_close(struct channel *c) { channel_set_state(c, CS_FLUSHING); }
-*/
void channel_request_feeding(struct channel *c);
-void *channel_config_new(const struct channel_class *cc, uint net_type, struct proto_config *proto);
+void *channel_config_new(const struct channel_class *cc, const char *name, uint net_type, struct proto_config *proto);
+void *channel_config_get(const struct channel_class *cc, const char *name, uint net_type, struct proto_config *proto);
int channel_reconfigure(struct channel *c, struct channel_config *cf);
+/* Moved from route.h to avoid dependency conflicts */
+static inline void rte_update(struct proto *p, const net_addr *n, rte *new) { rte_update2(p->main_channel, n, new, p->main_source); }
+
+static inline void
+rte_update3(struct channel *c, const net_addr *n, rte *new, struct rte_src *src)
+{
+ if (c->in_table && !rte_update_in(c, n, new, src))
+ return;
+
+ rte_update2(c, n, new, src);
+}
+
+
#endif