1998-04-22 12:58:34 +00:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Protocols
|
|
|
|
*
|
2000-03-01 14:49:07 +00:00
|
|
|
* (c) 1998--2000 Martin Mares <mj@ucw.cz>
|
1998-04-22 12:58:34 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_PROTOCOL_H_
|
|
|
|
#define _BIRD_PROTOCOL_H_
|
|
|
|
|
2023-02-01 11:10:34 +00:00
|
|
|
#include "lib/tlists.h"
|
1998-04-28 14:39:34 +00:00
|
|
|
#include "lib/resource.h"
|
2016-01-26 10:48:58 +00:00
|
|
|
#include "lib/event.h"
|
2023-02-01 11:10:34 +00:00
|
|
|
#include "nest/iface.h"
|
2022-09-09 13:04:36 +00:00
|
|
|
#include "lib/settle.h"
|
2023-10-29 15:25:01 +00:00
|
|
|
#include "nest/route.h"
|
2021-11-06 19:34:16 +00:00
|
|
|
#include "nest/limit.h"
|
2009-10-12 21:31:42 +00:00
|
|
|
#include "conf/conf.h"
|
2023-09-29 14:24:50 +00:00
|
|
|
#include "filter/data.h"
|
1998-04-22 12:58:34 +00:00
|
|
|
|
1998-05-20 11:54:33 +00:00
|
|
|
struct iface;
|
1999-05-06 21:38:11 +00:00
|
|
|
struct ifa;
|
1998-05-20 11:54:33 +00:00
|
|
|
struct rte;
|
|
|
|
struct neighbor;
|
1999-03-01 20:13:54 +00:00
|
|
|
struct rta;
|
1998-08-31 21:13:42 +00:00
|
|
|
struct network;
|
1999-02-05 21:37:34 +00:00
|
|
|
struct proto_config;
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel_limit;
|
|
|
|
struct channel_config;
|
1999-02-05 21:37:34 +00:00
|
|
|
struct config;
|
|
|
|
struct proto;
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel;
|
1999-05-31 18:55:35 +00:00
|
|
|
struct ea_list;
|
2000-04-01 10:19:47 +00:00
|
|
|
struct eattr;
|
1999-11-25 15:35:30 +00:00
|
|
|
struct symbol;
|
1998-05-20 11:54:33 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
|
1998-04-22 12:58:34 +00:00
|
|
|
/*
|
|
|
|
* Routing Protocol
|
|
|
|
*/
|
|
|
|
|
2018-05-07 12:47:00 +00:00
|
|
|
|
2023-09-24 21:22:43 +00:00
|
|
|
enum protocol_startup {
|
|
|
|
PROTOCOL_STARTUP_REGULAR = 0, /* Regular network routing protocol, start last */
|
|
|
|
PROTOCOL_STARTUP_GENERATOR = 1, /* Static route generator, start ahead of regulars */
|
|
|
|
PROTOCOL_STARTUP_CONNECTOR = 2, /* Data connector, start first */
|
|
|
|
PROTOCOL_STARTUP_NECESSARY = 3, /* Vital auxiliary data, start zeroth */
|
|
|
|
};
|
|
|
|
|
1998-04-22 12:58:34 +00:00
|
|
|
struct protocol {
|
1998-06-03 08:38:06 +00:00
|
|
|
node n;
|
1998-04-22 12:58:34 +00:00
|
|
|
char *name;
|
2000-01-17 11:52:50 +00:00
|
|
|
char *template; /* Template for automatic generation of names */
|
1999-03-26 21:37:29 +00:00
|
|
|
int name_counter; /* Counter for automatic name generation */
|
2015-02-21 20:08:23 +00:00
|
|
|
uint preference; /* Default protocol preference */
|
2023-09-24 21:22:43 +00:00
|
|
|
enum protocol_startup startup; /* When to start / stop this protocol */
|
2016-01-26 10:48:58 +00:00
|
|
|
uint channel_mask; /* Mask of accepted channel types (NB_*) */
|
|
|
|
uint proto_size; /* Size of protocol data structure */
|
|
|
|
uint config_size; /* Size of protocol config data structure */
|
1998-04-22 12:58:34 +00:00
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
|
|
|
|
void (*postconfig)(struct proto_config *); /* After configuring each instance */
|
|
|
|
struct proto * (*init)(struct proto_config *); /* Create new instance */
|
2000-01-16 16:44:50 +00:00
|
|
|
int (*reconfigure)(struct proto *, struct proto_config *); /* Try to reconfigure instance, returns success */
|
1999-02-05 21:37:34 +00:00
|
|
|
void (*dump)(struct proto *); /* Debugging dump */
|
|
|
|
int (*start)(struct proto *); /* Start the instance */
|
|
|
|
int (*shutdown)(struct proto *); /* Stop the instance */
|
2023-02-07 13:27:23 +00:00
|
|
|
void (*cleanup)(struct proto *); /* Cleanup the instance right before tearing it all down */
|
1999-12-01 12:00:15 +00:00
|
|
|
void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
|
2022-03-19 15:23:42 +00:00
|
|
|
// int (*get_attr)(const struct eattr *, byte *buf, int buflen); /* ASCIIfy dynamic attribute (returns GA_*) */
|
2010-04-06 22:19:23 +00:00
|
|
|
void (*show_proto_info)(struct proto *); /* Show protocol info (for `show protocols all' command) */
|
2011-11-06 23:31:23 +00:00
|
|
|
void (*copy_config)(struct proto_config *, struct proto_config *); /* Copy config from given protocol instance */
|
1998-04-22 12:58:34 +00:00
|
|
|
};
|
|
|
|
|
2022-03-18 21:05:50 +00:00
|
|
|
void protos_build(void); /* Called from sysdep to initialize protocols */
|
|
|
|
void proto_build(struct protocol *); /* Called from protocol to register itself */
|
1999-02-05 21:37:34 +00:00
|
|
|
void protos_preconfig(struct config *);
|
2009-06-19 21:49:34 +00:00
|
|
|
void protos_commit(struct config *new, struct config *old, int force_restart, int type);
|
2019-04-08 15:05:07 +00:00
|
|
|
struct proto * proto_spawn(struct proto_config *cf, uint disabled);
|
1998-07-09 19:36:52 +00:00
|
|
|
void protos_dump_all(void);
|
1998-06-03 08:38:06 +00:00
|
|
|
|
2000-04-01 10:19:47 +00:00
|
|
|
#define GA_UNKNOWN 0 /* Attribute not recognized */
|
|
|
|
#define GA_NAME 1 /* Result = name */
|
|
|
|
#define GA_FULL 2 /* Result = both name and value */
|
1998-04-22 12:58:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Known protocols
|
|
|
|
*/
|
|
|
|
|
2000-03-19 22:09:07 +00:00
|
|
|
extern struct protocol
|
2018-11-20 16:38:19 +00:00
|
|
|
proto_device, proto_radv, proto_rip, proto_static, proto_mrt,
|
2024-05-10 14:22:16 +00:00
|
|
|
proto_ospf, proto_l3vpn, proto_aggregator,
|
2021-03-29 20:45:21 +00:00
|
|
|
proto_pipe, proto_bgp, proto_bmp, proto_bfd, proto_babel, proto_rpki;
|
1998-04-22 12:58:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Routing Protocol Instance
|
|
|
|
*/
|
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
struct proto_config {
|
|
|
|
node n;
|
|
|
|
struct config *global; /* Global configuration data */
|
1999-11-30 14:04:09 +00:00
|
|
|
struct protocol *protocol; /* Protocol */
|
|
|
|
struct proto *proto; /* Instance we've created */
|
2019-04-08 15:05:07 +00:00
|
|
|
struct proto_config *parent; /* Parent proto_config for dynamic protocols */
|
2020-04-08 20:25:15 +00:00
|
|
|
const char *name;
|
|
|
|
const char *dsc;
|
2011-11-06 23:31:23 +00:00
|
|
|
int class; /* SYM_PROTO or SYM_TEMPLATE */
|
2016-01-26 10:48:58 +00:00
|
|
|
u8 net_type; /* Protocol network type (NET_*), 0 for undefined */
|
|
|
|
u8 disabled; /* Protocol enabled/disabled by default */
|
2021-06-19 18:50:18 +00:00
|
|
|
u8 late_if_feed; /* Delay interface feed after channels are up */
|
2010-01-03 11:17:52 +00:00
|
|
|
u32 debug, mrtdump; /* Debugging bitfields, both use D_* constants */
|
2009-10-12 21:31:42 +00:00
|
|
|
u32 router_id; /* Protocol specific router ID */
|
2021-06-19 18:50:18 +00:00
|
|
|
uint loop_order; /* Launch a birdloop on this locking level; use DOMAIN_ORDER(the_bird) for mainloop */
|
2023-04-17 09:37:29 +00:00
|
|
|
btime loop_max_latency; /* Request this specific maximum latency of loop; zero to default */
|
2016-01-26 10:48:58 +00:00
|
|
|
|
|
|
|
list channels; /* List of channel configs (struct channel_config) */
|
2017-09-06 15:38:48 +00:00
|
|
|
struct iface *vrf; /* Related VRF instance, NULL if global */
|
1999-02-05 21:37:34 +00:00
|
|
|
|
2011-11-06 23:31:23 +00:00
|
|
|
/* Check proto_reconfigure() and proto_copy_config() after changing struct proto_config */
|
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
/* Protocol-specific data follow... */
|
|
|
|
};
|
|
|
|
|
2023-11-02 13:33:00 +00:00
|
|
|
struct channel_import_request {
|
|
|
|
struct channel_import_request *next; /* Next in request chain */
|
|
|
|
void (*done)(struct channel_import_request *); /* Called when import finishes */
|
|
|
|
const struct f_trie *trie; /* Reload only matching nets */
|
|
|
|
};
|
|
|
|
|
2023-04-19 19:18:12 +00:00
|
|
|
#define TLIST_PREFIX proto
|
|
|
|
#define TLIST_TYPE struct proto
|
|
|
|
#define TLIST_ITEM n
|
|
|
|
#define TLIST_WANT_WALK
|
|
|
|
#define TLIST_WANT_ADD_TAIL
|
|
|
|
#define TLIST_WANT_ADD_AFTER
|
|
|
|
|
2012-04-15 13:28:29 +00:00
|
|
|
/* Protocol statistics */
|
1998-04-22 12:58:34 +00:00
|
|
|
struct proto {
|
2023-04-19 19:18:12 +00:00
|
|
|
TLIST_DEFAULT_NODE; /* Node in global proto_list */
|
1998-04-22 12:58:34 +00:00
|
|
|
struct protocol *proto; /* Protocol */
|
1999-02-05 21:37:34 +00:00
|
|
|
struct proto_config *cf; /* Configuration data */
|
2000-01-16 16:44:50 +00:00
|
|
|
struct proto_config *cf_new; /* Configuration we want to switch to after shutdown (NULL=delete) */
|
1999-02-05 21:37:34 +00:00
|
|
|
pool *pool; /* Pool containing local objects */
|
2023-10-13 08:22:09 +00:00
|
|
|
pool *pool_up; /* Pool containing local objects which should be dropped as soon
|
|
|
|
as the protocol enters the STOP / DOWN state */
|
|
|
|
pool *pool_inloop; /* Pool containing local objects which need to be freed
|
2023-05-07 15:30:33 +00:00
|
|
|
before the protocol's birdloop actually stops, like olocks */
|
2016-01-26 10:48:58 +00:00
|
|
|
event *event; /* Protocol event */
|
2023-02-06 14:06:12 +00:00
|
|
|
timer *restart_timer; /* Timer to restart the protocol from limits */
|
|
|
|
event *restart_event; /* Event to restart/shutdown the protocol from limits */
|
2021-06-19 18:50:18 +00:00
|
|
|
struct birdloop *loop; /* BIRDloop running this protocol */
|
2016-01-26 10:48:58 +00:00
|
|
|
|
|
|
|
list channels; /* List of channels to rtables (struct channel) */
|
|
|
|
struct channel *main_channel; /* Primary channel */
|
|
|
|
struct rte_src *main_source; /* Primary route source */
|
2021-09-27 14:40:28 +00:00
|
|
|
struct rte_owner sources; /* Route source owner structure */
|
2017-12-07 17:35:46 +00:00
|
|
|
struct iface *vrf; /* Related VRF instance, NULL if global */
|
2023-02-01 11:10:34 +00:00
|
|
|
TLIST_LIST(proto_neigh) neighbors; /* List of neighbor structures */
|
2023-01-31 12:07:46 +00:00
|
|
|
struct iface_subscription iface_sub; /* Interface notification subscription */
|
2022-09-14 23:38:18 +00:00
|
|
|
struct channel *mpls_channel; /* MPLS channel, when used */
|
1999-02-05 21:37:34 +00:00
|
|
|
|
2023-02-01 11:10:34 +00:00
|
|
|
const char *name; /* Name of this instance (== cf->name) */
|
2010-01-03 11:17:52 +00:00
|
|
|
u32 debug; /* Debugging flags */
|
|
|
|
u32 mrtdump; /* MRTDump flags */
|
2016-01-26 10:48:58 +00:00
|
|
|
uint active_channels; /* Number of active channels */
|
2022-07-28 17:49:03 +00:00
|
|
|
uint active_loops; /* Number of active IO loops */
|
2016-01-26 10:48:58 +00:00
|
|
|
byte net_type; /* Protocol network type (NET_*), 0 for undefined */
|
2012-04-15 13:28:29 +00:00
|
|
|
byte disabled; /* Manually disabled */
|
|
|
|
byte proto_state; /* Protocol state machine (PS_*, see below) */
|
2016-01-26 10:48:58 +00:00
|
|
|
byte active; /* From PS_START to cleanup after PS_STOP */
|
|
|
|
byte do_stop; /* Stop actions are scheduled */
|
2012-04-15 13:28:29 +00:00
|
|
|
byte reconfiguring; /* We're shutting down due to reconfiguration */
|
2014-03-20 13:07:12 +00:00
|
|
|
byte gr_recovery; /* Protocol should participate in graceful restart recovery */
|
2012-04-15 13:28:29 +00:00
|
|
|
byte down_sched; /* Shutdown is scheduled for later (PDS_*) */
|
|
|
|
byte down_code; /* Reason for shutdown (PDC_* codes) */
|
2000-03-01 14:49:07 +00:00
|
|
|
u32 hash_key; /* Random key used for hashing of neighbors */
|
2017-06-06 14:47:30 +00:00
|
|
|
btime last_state_change; /* Time of last state transition */
|
2000-05-16 13:43:26 +00:00
|
|
|
char *last_state_name_announced; /* Last state name we've announced to the user */
|
2017-09-19 17:55:37 +00:00
|
|
|
char *message; /* State-change message, allocated from proto_pool */
|
1998-04-22 12:58:34 +00:00
|
|
|
|
1999-04-05 20:17:59 +00:00
|
|
|
/*
|
|
|
|
* General protocol hooks:
|
|
|
|
*
|
|
|
|
* if_notify Notify protocol about interface state changes.
|
1999-05-06 21:38:11 +00:00
|
|
|
* ifa_notify Notify protocol about interface address changes.
|
1999-04-05 20:17:59 +00:00
|
|
|
* rt_notify Notify protocol about routing table updates.
|
|
|
|
* neigh_notify Notify protocol about neighbor cache events.
|
2020-04-12 19:54:20 +00:00
|
|
|
* preexport Called as the first step of the route exporting process.
|
|
|
|
* It can decide whether the route shall be exported:
|
|
|
|
* -1 = reject,
|
|
|
|
* 0 = continue to export filter
|
|
|
|
* 1 = accept immediately
|
2016-01-26 10:48:58 +00:00
|
|
|
* reload_routes Request channel to reload all its routes to the core
|
2009-11-26 19:47:59 +00:00
|
|
|
* (using rte_update()). Returns: 0=reload cannot be done,
|
|
|
|
* 1= reload is scheduled and will happen (asynchronously).
|
2016-01-26 10:48:58 +00:00
|
|
|
* feed_begin Notify channel about beginning of route feeding.
|
|
|
|
* feed_end Notify channel about finish of route feeding.
|
1999-04-05 20:17:59 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-28 10:42:46 +00:00
|
|
|
void (*rt_notify)(struct proto *, struct channel *, const net_addr *net, struct rte *new, const struct rte *old);
|
|
|
|
int (*preexport)(struct channel *, struct rte *rt);
|
2023-11-02 13:33:00 +00:00
|
|
|
int (*reload_routes)(struct channel *, struct channel_import_request *cir);
|
2023-09-29 14:24:50 +00:00
|
|
|
void (*feed_begin)(struct channel *);
|
2016-01-26 10:48:58 +00:00
|
|
|
void (*feed_end)(struct channel *);
|
1999-04-05 20:17:59 +00:00
|
|
|
|
|
|
|
/*
|
2012-08-14 14:25:22 +00:00
|
|
|
* Routing entry hooks (called only for routes belonging to this protocol):
|
1999-04-05 20:17:59 +00:00
|
|
|
*
|
2015-02-21 20:08:23 +00:00
|
|
|
* rte_recalculate Called at the beginning of the best route selection
|
2015-06-08 00:20:43 +00:00
|
|
|
* rte_mergable Compare two rte's and decide whether they could be merged (1=yes, 0=no).
|
1999-04-05 20:17:59 +00:00
|
|
|
*/
|
1998-04-22 12:58:34 +00:00
|
|
|
|
2022-09-07 11:54:20 +00:00
|
|
|
int (*rte_recalculate)(struct rtable_private *, struct network *, struct rte *, struct rte *, struct rte *);
|
2015-06-08 00:20:43 +00:00
|
|
|
int (*rte_mergable)(struct rte *, struct rte *);
|
2022-05-30 15:11:30 +00:00
|
|
|
u32 (*rte_igp_metric)(const struct rte *);
|
1998-05-20 11:54:33 +00:00
|
|
|
|
1998-04-22 12:58:34 +00:00
|
|
|
/* Hic sunt protocol-specific data */
|
|
|
|
};
|
|
|
|
|
2023-04-19 19:18:12 +00:00
|
|
|
#include "lib/tlists.h"
|
|
|
|
|
2010-02-19 23:03:31 +00:00
|
|
|
struct proto_spec {
|
2020-04-08 20:25:15 +00:00
|
|
|
const void *ptr;
|
2010-02-19 23:03:31 +00:00
|
|
|
int patt;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-04-15 13:28:29 +00:00
|
|
|
#define PDS_DISABLE 1 /* Proto disable scheduled */
|
|
|
|
#define PDS_RESTART 2 /* Proto restart scheduled */
|
|
|
|
|
|
|
|
#define PDC_CF_REMOVE 0x01 /* Removed in new config */
|
|
|
|
#define PDC_CF_DISABLE 0x02 /* Disabled in new config */
|
|
|
|
#define PDC_CF_RESTART 0x03 /* Restart due to reconfiguration */
|
|
|
|
#define PDC_CMD_DISABLE 0x11 /* Result of disable command */
|
|
|
|
#define PDC_CMD_RESTART 0x12 /* Result of restart command */
|
2012-08-06 00:42:24 +00:00
|
|
|
#define PDC_CMD_SHUTDOWN 0x13 /* Result of global shutdown */
|
2019-06-18 14:27:21 +00:00
|
|
|
#define PDC_CMD_GR_DOWN 0x14 /* Result of global graceful restart */
|
2013-01-10 12:07:33 +00:00
|
|
|
#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 */
|
2012-04-15 13:28:29 +00:00
|
|
|
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
void *proto_new(struct proto_config *);
|
2015-02-21 20:08:23 +00:00
|
|
|
void *proto_config_new(struct protocol *, int class);
|
2011-11-06 23:31:23 +00:00
|
|
|
void proto_copy_config(struct proto_config *dest, struct proto_config *src);
|
2019-04-08 15:05:07 +00:00
|
|
|
void proto_clone_config(struct symbol *sym, struct proto_config *parent);
|
2017-09-19 17:55:37 +00:00
|
|
|
void proto_set_message(struct proto *p, char *msg, int len);
|
2011-11-06 23:31:23 +00:00
|
|
|
|
2014-03-20 13:07:12 +00:00
|
|
|
void graceful_restart_recovery(void);
|
|
|
|
void graceful_restart_init(void);
|
|
|
|
void graceful_restart_show_status(void);
|
2016-01-26 10:48:58 +00:00
|
|
|
void channel_graceful_restart_lock(struct channel *c);
|
|
|
|
void channel_graceful_restart_unlock(struct channel *c);
|
2014-03-20 13:07:12 +00:00
|
|
|
|
|
|
|
#define DEFAULT_GR_WAIT 240
|
2012-03-15 10:58:08 +00:00
|
|
|
|
2023-04-02 17:34:22 +00:00
|
|
|
static inline event_list *proto_event_list(struct proto *p)
|
|
|
|
{ return p->loop == &main_birdloop ? &global_event_list : birdloop_event_list(p->loop); }
|
|
|
|
|
|
|
|
static inline event_list *proto_work_list(struct proto *p)
|
|
|
|
{ return p->loop == &main_birdloop ? &global_work_list : birdloop_event_list(p->loop); }
|
|
|
|
|
|
|
|
static inline void proto_send_event(struct proto *p, event *e)
|
|
|
|
{ ev_send(proto_event_list(p), e); }
|
|
|
|
|
2021-11-06 19:34:16 +00:00
|
|
|
void channel_show_limit(struct limit *l, const char *dsc, int active, int action);
|
2016-01-26 10:48:58 +00:00
|
|
|
void channel_show_info(struct channel *c);
|
2020-12-07 21:19:40 +00:00
|
|
|
void channel_cmd_debug(struct channel *c, uint mask);
|
2012-03-15 10:58:08 +00:00
|
|
|
|
2017-09-19 17:55:37 +00:00
|
|
|
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);
|
2015-05-19 06:53:34 +00:00
|
|
|
|
2017-09-19 17:55:37 +00:00
|
|
|
void proto_apply_cmd(struct proto_spec ps, void (* cmd)(struct proto *, uintptr_t, int), int restricted, uintptr_t arg);
|
1999-12-03 11:40:45 +00:00
|
|
|
struct proto *proto_get_named(struct symbol *, struct protocol *);
|
2020-05-14 01:48:17 +00:00
|
|
|
struct proto *proto_iterate_named(struct symbol *sym, struct protocol *proto, struct proto *old);
|
|
|
|
|
|
|
|
#define PROTO_WALK_CMD(sym,pr,p) for(struct proto *p = NULL; p = proto_iterate_named(sym, pr, p); )
|
|
|
|
|
2023-11-02 13:33:00 +00:00
|
|
|
/* Request from CLI to reload multiple protocols */
|
|
|
|
struct proto_reload_request {
|
|
|
|
const struct f_trie *trie; /* Trie to apply */
|
|
|
|
_Atomic uint counter; /* How many channels remaining */
|
2024-03-27 10:34:19 +00:00
|
|
|
enum cmd_reload {
|
|
|
|
CMD_RELOAD_IN = 1,
|
|
|
|
CMD_RELOAD_OUT = 2,
|
|
|
|
CMD_RELOAD = (CMD_RELOAD_IN | CMD_RELOAD_OUT),
|
|
|
|
} dir; /* Direction of reload */
|
2023-11-02 13:33:00 +00:00
|
|
|
event ev; /* Event to run when finished */
|
|
|
|
};
|
|
|
|
|
2023-04-02 17:34:22 +00:00
|
|
|
#define PROTO_ENTER_FROM_MAIN(p) ({ \
|
|
|
|
ASSERT_DIE(birdloop_inside(&main_birdloop)); \
|
|
|
|
struct birdloop *_loop = (p)->loop; \
|
|
|
|
if (_loop != &main_birdloop) birdloop_enter(_loop); \
|
|
|
|
_loop; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define PROTO_LEAVE_FROM_MAIN(loop) ({ if (loop != &main_birdloop) birdloop_leave(loop); })
|
|
|
|
|
|
|
|
#define PROTO_LOCKED_FROM_MAIN(p) for (struct birdloop *_proto_loop = PROTO_ENTER_FROM_MAIN(p); _proto_loop; PROTO_LEAVE_FROM_MAIN(_proto_loop), (_proto_loop = NULL))
|
|
|
|
|
2023-04-21 13:26:06 +00:00
|
|
|
static inline struct domain_generic *proto_domain(struct proto *p)
|
|
|
|
{ return birdloop_domain(p->loop); }
|
2010-02-19 23:03:31 +00:00
|
|
|
|
2009-10-12 21:31:42 +00:00
|
|
|
static inline u32
|
|
|
|
proto_get_router_id(struct proto_config *pc)
|
|
|
|
{
|
|
|
|
return pc->router_id ? pc->router_id : pc->global->router_id;
|
|
|
|
}
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
extern pool *proto_pool;
|
1998-05-20 11:54:33 +00:00
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
/*
|
|
|
|
* Each protocol instance runs two different state machines:
|
|
|
|
*
|
|
|
|
* [P] The protocol machine: (implemented inside protocol)
|
|
|
|
*
|
|
|
|
* DOWN ----> START
|
|
|
|
* ^ |
|
|
|
|
* | V
|
|
|
|
* STOP <---- UP
|
|
|
|
*
|
|
|
|
* States: DOWN Protocol is down and it's waiting for the core
|
|
|
|
* requesting protocol start.
|
|
|
|
* START Protocol is waiting for connection with the rest
|
|
|
|
* of the network and it's not willing to accept
|
|
|
|
* packets. When it connects, it goes to UP state.
|
|
|
|
* UP Protocol is up and running. When the network
|
|
|
|
* connection breaks down or the core requests
|
|
|
|
* protocol to be terminated, it goes to STOP state.
|
|
|
|
* STOP Protocol is disconnecting from the network.
|
|
|
|
* After it disconnects, it returns to DOWN state.
|
|
|
|
*
|
|
|
|
* In: start() Called in DOWN state to request protocol startup.
|
|
|
|
* Returns new state: either UP or START (in this
|
|
|
|
* case, the protocol will notify the core when it
|
|
|
|
* finally comes UP).
|
|
|
|
* stop() Called in START, UP or STOP state to request
|
|
|
|
* protocol shutdown. Returns new state: either
|
|
|
|
* DOWN or STOP (in this case, the protocol will
|
|
|
|
* notify the core when it finally comes DOWN).
|
|
|
|
*
|
|
|
|
* Out: proto_notify_state() -- called by protocol instance when
|
|
|
|
* it does any state transition not covered by
|
|
|
|
* return values of start() and stop(). This includes
|
|
|
|
* START->UP (delayed protocol startup), UP->STOP
|
|
|
|
* (spontaneous shutdown) and STOP->DOWN (delayed
|
|
|
|
* shutdown).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PS_DOWN 0
|
|
|
|
#define PS_START 1
|
|
|
|
#define PS_UP 2
|
|
|
|
#define PS_STOP 3
|
|
|
|
|
|
|
|
void proto_notify_state(struct proto *p, unsigned state);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* [F] The feeder machine: (implemented in core routines)
|
|
|
|
*
|
|
|
|
* HUNGRY ----> FEEDING
|
|
|
|
* ^ |
|
2018-02-06 16:43:55 +00:00
|
|
|
* | V
|
1999-02-05 21:37:34 +00:00
|
|
|
* FLUSHING <---- HAPPY
|
|
|
|
*
|
|
|
|
* States: HUNGRY Protocol either administratively down (i.e.,
|
|
|
|
* disabled by the user) or temporarily down
|
|
|
|
* (i.e., [P] is not UP)
|
|
|
|
* FEEDING The protocol came up and we're feeding it
|
|
|
|
* initial routes. [P] is UP.
|
|
|
|
* HAPPY The protocol is up and it's receiving normal
|
|
|
|
* routing updates. [P] is UP.
|
|
|
|
* FLUSHING The protocol is down and we're removing its
|
|
|
|
* routes from the table. [P] is STOP or DOWN.
|
|
|
|
*
|
|
|
|
* Normal lifecycle of a protocol looks like:
|
|
|
|
*
|
|
|
|
* HUNGRY/DOWN --> HUNGRY/START --> HUNGRY/UP -->
|
|
|
|
* FEEDING/UP --> HAPPY/UP --> FLUSHING/STOP|DOWN -->
|
|
|
|
* HUNGRY/STOP|DOWN --> HUNGRY/DOWN
|
2009-11-26 19:47:59 +00:00
|
|
|
*
|
2015-02-21 20:08:23 +00:00
|
|
|
* Sometimes, protocol might switch from HAPPY/UP to FEEDING/UP
|
2009-11-26 19:47:59 +00:00
|
|
|
* if it wants to refeed the routes (for example BGP does so
|
|
|
|
* as a result of received ROUTE-REFRESH request).
|
1999-02-05 21:37:34 +00:00
|
|
|
*/
|
|
|
|
|
2021-06-19 18:50:18 +00:00
|
|
|
static inline int proto_is_inactive(struct proto *p)
|
2023-02-07 13:27:23 +00:00
|
|
|
{
|
|
|
|
return (p->active_channels == 0)
|
|
|
|
&& (p->active_loops == 0)
|
|
|
|
&& (p->sources.uc == 0)
|
|
|
|
&& EMPTY_TLIST(proto_neigh, &p->neighbors)
|
|
|
|
;
|
|
|
|
}
|
2014-03-20 13:07:12 +00:00
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
|
2000-03-07 20:49:48 +00:00
|
|
|
/*
|
|
|
|
* Debugging flags
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define D_STATES 1 /* [core] State transitions */
|
|
|
|
#define D_ROUTES 2 /* [core] Routes passed by the filters */
|
2000-03-12 20:50:35 +00:00
|
|
|
#define D_FILTERS 4 /* [core] Routes rejected by the filters */
|
|
|
|
#define D_IFACES 8 /* [core] Interface events */
|
|
|
|
#define D_EVENTS 16 /* Protocol events */
|
|
|
|
#define D_PACKETS 32 /* Packets sent/received */
|
2000-03-07 20:49:48 +00:00
|
|
|
|
2013-09-16 21:57:40 +00:00
|
|
|
#ifndef PARSER
|
|
|
|
#define TRACE(flags, msg, args...) \
|
|
|
|
do { if (p->p.debug & flags) log(L_TRACE "%s: " msg, p->p.name , ## args ); } while(0)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-01-03 11:17:52 +00:00
|
|
|
/*
|
|
|
|
* MRTDump flags
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MD_STATES 1 /* Protocol state changes (BGP4MP_MESSAGE_AS4) */
|
|
|
|
#define MD_MESSAGES 2 /* Protocol packets (BGP4MP_MESSAGE_AS4) */
|
|
|
|
|
1998-11-29 22:03:58 +00:00
|
|
|
/*
|
|
|
|
* Known unique protocol instances as referenced by config routines
|
|
|
|
*/
|
|
|
|
|
1999-02-05 21:37:34 +00:00
|
|
|
extern struct proto_config *cf_dev_proto;
|
1998-11-29 22:03:58 +00:00
|
|
|
|
2012-04-15 13:28:29 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Protocol limits
|
|
|
|
*/
|
|
|
|
|
2013-01-10 12:07:33 +00:00
|
|
|
#define PLD_RX 0 /* Receive limit */
|
|
|
|
#define PLD_IN 1 /* Import limit */
|
|
|
|
#define PLD_OUT 2 /* Export limit */
|
|
|
|
#define PLD_MAX 3
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
#define PLA_NONE 0 /* No limit */
|
2012-04-15 13:28:29 +00:00
|
|
|
#define PLA_WARN 1 /* Issue log warning */
|
|
|
|
#define PLA_BLOCK 2 /* Block new routes */
|
|
|
|
#define PLA_RESTART 4 /* Force protocol restart */
|
|
|
|
#define PLA_DISABLE 5 /* Shutdown and disable protocol */
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel_limit {
|
2012-04-15 13:28:29 +00:00
|
|
|
u32 limit; /* Maximum number of prefixes */
|
2016-01-26 10:48:58 +00:00
|
|
|
u8 action; /* Action to take (PLA_*) */
|
2012-04-15 13:28:29 +00:00
|
|
|
};
|
|
|
|
|
2021-11-06 19:34:16 +00:00
|
|
|
struct channel_limit_data {
|
|
|
|
struct channel *c;
|
|
|
|
int dir;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define CLP__RX(_c) (&(_c)->rx_limit)
|
|
|
|
#define CLP__IN(_c) (&(_c)->in_limit)
|
|
|
|
#define CLP__OUT(_c) (&(_c)->out_limit)
|
|
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
#define CHANNEL_LIMIT_LOG(_c, _dir, _op) log(L_TRACE "%s.%s: %s limit %s %u", (_c)->proto->name, (_c)->name, #_dir, _op, (CLP__##_dir(_c))->count)
|
|
|
|
#else
|
|
|
|
#define CHANNEL_LIMIT_LOG(_c, _dir, _op)
|
|
|
|
#endif
|
2012-04-21 19:05:36 +00:00
|
|
|
|
2021-11-06 19:34:16 +00:00
|
|
|
#define CHANNEL_LIMIT_PUSH(_c, _dir) ({ CHANNEL_LIMIT_LOG(_c, _dir, "push from"); struct channel_limit_data cld = { .c = (_c), .dir = PLD_##_dir }; limit_push(CLP__##_dir(_c), &cld); })
|
|
|
|
#define CHANNEL_LIMIT_POP(_c, _dir) ({ limit_pop(CLP__##_dir(_c)); CHANNEL_LIMIT_LOG(_c, _dir, "pop to"); })
|
2015-02-21 20:08:23 +00:00
|
|
|
|
1999-05-17 20:14:52 +00:00
|
|
|
/*
|
2016-01-26 10:48:58 +00:00
|
|
|
* Channels
|
1999-05-17 20:14:52 +00:00
|
|
|
*/
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel_class {
|
|
|
|
uint channel_size; /* Size of channel data structure */
|
|
|
|
uint config_size; /* Size of channel config data structure */
|
|
|
|
|
2016-12-07 13:11:28 +00:00
|
|
|
void (*init)(struct channel *, struct channel_config *); /* Create new instance */
|
2019-08-06 13:29:06 +00:00
|
|
|
int (*reconfigure)(struct channel *, struct channel_config *, int *import_changed, int *export_changed); /* Try to reconfigure instance, returns success */
|
2016-01-26 10:48:58 +00:00
|
|
|
int (*start)(struct channel *); /* Start the instance */
|
2016-12-07 13:11:28 +00:00
|
|
|
void (*shutdown)(struct channel *); /* Stop the instance */
|
|
|
|
void (*cleanup)(struct channel *); /* Channel finished flush */
|
2016-01-26 10:48:58 +00:00
|
|
|
|
|
|
|
void (*copy_config)(struct channel_config *, struct channel_config *); /* Copy config from given channel instance */
|
|
|
|
#if 0
|
2016-12-07 13:11:28 +00:00
|
|
|
XXXX;
|
2016-01-26 10:48:58 +00:00
|
|
|
void (*preconfig)(struct protocol *, struct config *); /* Just before configuring */
|
|
|
|
void (*postconfig)(struct proto_config *); /* After configuring each instance */
|
|
|
|
|
|
|
|
|
|
|
|
void (*dump)(struct proto *); /* Debugging dump */
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
void (*get_status)(struct proto *, byte *buf); /* Get instance status (for `show protocols' command) */
|
2018-05-29 10:08:12 +00:00
|
|
|
void (*get_route_info)(struct rte *, byte *buf); /* Get route information (for `show route' command) */
|
2016-01-26 10:48:58 +00:00
|
|
|
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
|
|
|
|
};
|
|
|
|
|
2023-08-18 01:53:58 +00:00
|
|
|
extern const struct channel_class channel_basic;
|
|
|
|
extern const struct channel_class channel_bgp;
|
2016-12-07 13:11:28 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel_config {
|
1999-05-17 20:14:52 +00:00
|
|
|
node n;
|
2016-01-26 10:48:58 +00:00
|
|
|
const char *name;
|
2023-09-14 13:21:53 +00:00
|
|
|
const struct channel_class *class;
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2018-01-09 17:42:22 +00:00
|
|
|
struct proto_config *parent; /* Where channel is defined (proto or template) */
|
2016-01-26 10:48:58 +00:00
|
|
|
struct rtable_config *table; /* Table we're attached to */
|
2019-02-15 12:53:17 +00:00
|
|
|
const struct filter *in_filter, *out_filter; /* Attached filters */
|
2022-06-22 10:45:42 +00:00
|
|
|
const net_addr *out_subprefix; /* Export only subprefixes of this net */
|
2021-11-06 19:34:16 +00:00
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel_limit rx_limit; /* Limit for receiving routes from protocol
|
2022-06-16 21:24:56 +00:00
|
|
|
(relevant when in_keep & RIK_REJECTED) */
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel_limit in_limit; /* Limit for importing routes from protocol */
|
|
|
|
struct channel_limit out_limit; /* Limit for exporting routes to protocol */
|
|
|
|
|
2022-09-09 13:04:36 +00:00
|
|
|
struct settle_config roa_settle; /* Settle times for ROA-induced reload */
|
2022-09-01 08:39:56 +00:00
|
|
|
|
2023-05-07 21:04:47 +00:00
|
|
|
uint feed_block_size; /* How many routes to feed at once */
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
u8 net_type; /* Routing table network type (NET_*), 0 for undefined */
|
|
|
|
u8 ra_mode; /* Mode of received route advertisements (RA_*) */
|
|
|
|
u16 preference; /* Default route preference */
|
2020-12-07 21:19:40 +00:00
|
|
|
u32 debug; /* Debugging flags (D_*) */
|
2022-10-03 16:53:21 +00:00
|
|
|
u8 copy; /* Value from channel_config_get() is new (0) or from template (1) */
|
2016-01-26 10:48:58 +00:00
|
|
|
u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
|
2022-06-16 21:24:56 +00:00
|
|
|
u8 in_keep; /* Which states of routes to keep (RIK_*) */
|
2021-02-12 04:05:18 +00:00
|
|
|
u8 rpki_reload; /* RPKI changes trigger channel reload */
|
2016-01-26 10:48:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct channel {
|
|
|
|
node n; /* Node in proto->channels */
|
|
|
|
|
|
|
|
const char *name; /* Channel name (may be NULL) */
|
2023-09-14 13:21:53 +00:00
|
|
|
const struct channel_class *class;
|
1999-05-17 20:14:52 +00:00
|
|
|
struct proto *proto;
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2022-09-07 11:54:20 +00:00
|
|
|
rtable *table;
|
2019-02-15 12:53:17 +00:00
|
|
|
const struct filter *in_filter; /* Input filter */
|
|
|
|
const struct filter *out_filter; /* Output filter */
|
2022-06-22 10:45:42 +00:00
|
|
|
const net_addr *out_subprefix; /* Export only subprefixes of this net */
|
2020-03-09 14:31:10 +00:00
|
|
|
struct bmap export_map; /* Keeps track which routes were really exported */
|
|
|
|
struct bmap export_reject_map; /* Keeps track which routes were rejected by export filter */
|
2021-11-06 19:34:16 +00:00
|
|
|
|
2022-06-16 21:24:56 +00:00
|
|
|
struct limit rx_limit; /* Receive limit (for in_keep & RIK_REJECTED) */
|
2021-11-06 19:34:16 +00:00
|
|
|
struct limit in_limit; /* Input limit */
|
|
|
|
struct limit out_limit; /* Output limit */
|
|
|
|
|
2022-09-09 13:04:36 +00:00
|
|
|
struct settle_config roa_settle; /* Settle times for ROA-induced reload */
|
2022-09-01 08:39:56 +00:00
|
|
|
|
2021-11-06 19:34:16 +00:00
|
|
|
u8 limit_actions[PLD_MAX]; /* Limit actions enum */
|
|
|
|
u8 limit_active; /* Flags for active limits */
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2021-06-21 15:07:31 +00:00
|
|
|
struct channel_import_stats {
|
|
|
|
/* Import - from protocol to core */
|
|
|
|
u32 updates_received; /* Number of route updates received */
|
|
|
|
u32 updates_invalid; /* Number of route updates rejected as invalid */
|
|
|
|
u32 updates_filtered; /* Number of route updates rejected by filters */
|
|
|
|
u32 updates_limited_rx; /* Number of route updates exceeding the rx_limit */
|
|
|
|
u32 updates_limited_in; /* Number of route updates exceeding the in_limit */
|
|
|
|
u32 withdraws_received; /* Number of route withdraws received */
|
|
|
|
u32 withdraws_invalid; /* Number of route withdraws rejected as invalid */
|
|
|
|
} import_stats;
|
|
|
|
|
|
|
|
struct channel_export_stats {
|
|
|
|
/* Export - from core to protocol */
|
|
|
|
u32 updates_rejected; /* Number of route updates rejected by protocol */
|
|
|
|
u32 updates_filtered; /* Number of route updates rejected by filters */
|
|
|
|
u32 updates_accepted; /* Number of route updates accepted and exported */
|
|
|
|
u32 updates_limited; /* Number of route updates exceeding the out_limit */
|
|
|
|
u32 withdraws_accepted; /* Number of route withdraws accepted and processed */
|
|
|
|
} export_stats;
|
|
|
|
|
|
|
|
struct rt_import_request in_req; /* Table import connection */
|
|
|
|
struct rt_export_request out_req; /* Table export connection */
|
2021-06-21 17:11:42 +00:00
|
|
|
|
2023-09-29 14:24:50 +00:00
|
|
|
struct rt_export_request refeed_req; /* Auxiliary refeed request */
|
2024-01-08 11:02:25 +00:00
|
|
|
struct bmap refeed_map; /* Auxiliary refeed netindex bitmap */
|
2023-09-29 14:24:50 +00:00
|
|
|
struct channel_feeding_request *refeeding; /* Refeeding the channel */
|
|
|
|
struct channel_feeding_request *refeed_pending; /* Scheduled refeeds */
|
2023-11-02 13:33:00 +00:00
|
|
|
struct channel_import_request *importing; /* Importing the channel */
|
|
|
|
struct channel_import_request *import_pending; /* Scheduled imports */
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2023-05-07 21:04:47 +00:00
|
|
|
uint feed_block_size; /* How many routes to feed at once */
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
u8 net_type; /* Routing table network type (NET_*), 0 for undefined */
|
|
|
|
u8 ra_mode; /* Mode of received route advertisements (RA_*) */
|
|
|
|
u16 preference; /* Default route preference */
|
2020-12-07 21:19:40 +00:00
|
|
|
u32 debug; /* Debugging flags (D_*) */
|
2016-01-26 10:48:58 +00:00
|
|
|
u8 merge_limit; /* Maximal number of nexthops for RA_MERGED */
|
2022-06-16 21:24:56 +00:00
|
|
|
u8 in_keep; /* Which states of routes to keep (RIK_*) */
|
2016-01-26 10:48:58 +00:00
|
|
|
u8 disabled;
|
2016-12-07 13:11:28 +00:00
|
|
|
u8 stale; /* Used in reconfiguration */
|
2016-01-26 10:48:58 +00:00
|
|
|
|
|
|
|
u8 channel_state;
|
|
|
|
u8 reloadable; /* Hook reload_routes() is allowed on the channel */
|
|
|
|
u8 gr_lock; /* Graceful restart mechanism should wait for this channel */
|
|
|
|
u8 gr_wait; /* Route export to channel is postponed until graceful restart */
|
|
|
|
|
2023-11-24 11:19:44 +00:00
|
|
|
u32 obstacles; /* External obstacles remaining before cleanup */
|
|
|
|
|
2017-06-06 14:47:30 +00:00
|
|
|
btime last_state_change; /* Time of last state transition */
|
2018-09-27 20:57:55 +00:00
|
|
|
|
2022-06-16 21:24:56 +00:00
|
|
|
struct rt_export_request reload_req; /* Feeder for import reload */
|
2019-08-13 16:22:07 +00:00
|
|
|
|
2021-02-10 02:09:57 +00:00
|
|
|
u8 reload_pending; /* Reloading and another reload is scheduled */
|
2021-02-12 04:05:18 +00:00
|
|
|
u8 rpki_reload; /* RPKI changes trigger channel reload */
|
2021-02-10 02:09:57 +00:00
|
|
|
|
2022-06-20 17:10:49 +00:00
|
|
|
struct rt_exporter *out_table; /* Internal table for exported routes */
|
2021-02-10 02:09:57 +00:00
|
|
|
|
2022-09-01 08:39:56 +00:00
|
|
|
list roa_subscriptions; /* List of active ROA table subscriptions based on filters' roa_check() calls */
|
1999-05-17 20:14:52 +00:00
|
|
|
};
|
|
|
|
|
2022-06-16 21:24:56 +00:00
|
|
|
#define RIK_REJECTED 1 /* Routes rejected in import filter are kept */
|
|
|
|
#define RIK_PREFILTER (2 | RIK_REJECTED) /* All routes' attribute state before import filter is kept */
|
2016-01-26 10:48:58 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Channel states
|
|
|
|
*
|
|
|
|
* CS_DOWN - The initial and the final state of a channel. There is no route
|
|
|
|
* exchange between the protocol and the table. Channel is not counted as
|
|
|
|
* active. Channel keeps a ptr to the table, but do not lock the table and is
|
|
|
|
* not linked in the table. Generally, new closed channels are created in
|
|
|
|
* protocols' init() hooks. The protocol is expected to explicitly activate its
|
|
|
|
* channels (by calling channel_init() or channel_open()).
|
|
|
|
*
|
|
|
|
* CS_START - The channel as a connection between the protocol and the table is
|
|
|
|
* initialized (counted as active by the protocol, linked in the table and keeps
|
|
|
|
* the table locked), but there is no current route exchange. There still may be
|
|
|
|
* routes associated with the channel in the routing table if the channel falls
|
|
|
|
* to CS_START from CS_UP. Generally, channels are initialized in protocols'
|
|
|
|
* start() hooks when going to PS_START.
|
|
|
|
*
|
|
|
|
* CS_UP - The channel is initialized and the route exchange is allowed. Note
|
|
|
|
* that even in CS_UP state, route export may still be down (ES_DOWN) by the
|
|
|
|
* core decision (e.g. waiting for table convergence after graceful restart).
|
|
|
|
* I.e., the protocol decides to open the channel but the core decides to start
|
|
|
|
* route export. Route import (caused by rte_update() from the protocol) is not
|
|
|
|
* restricted by that and is on volition of the protocol. Generally, channels
|
|
|
|
* are opened in protocols' start() hooks when going to PS_UP.
|
|
|
|
*
|
2021-06-21 15:07:31 +00:00
|
|
|
* CS_STOP - The transitional state between initialized channel and closed
|
2016-01-26 10:48:58 +00:00
|
|
|
* channel. The channel is still initialized, but no route exchange is allowed.
|
|
|
|
* Instead, the associated table is running flush loop to remove routes imported
|
|
|
|
* through the channel. After that, the channel changes state to CS_DOWN and
|
|
|
|
* is detached from the table (the table is unlocked and the channel is unlinked
|
2021-06-21 15:07:31 +00:00
|
|
|
* from it). Unlike other states, the CS_STOP state is not explicitly
|
2016-01-26 10:48:58 +00:00
|
|
|
* entered or left by the protocol. A protocol may request to close a channel
|
|
|
|
* (by calling channel_close()), which causes the channel to change state to
|
2021-06-21 15:07:31 +00:00
|
|
|
* CS_STOP and later to CS_DOWN. Also note that channels are closed
|
2016-01-26 10:48:58 +00:00
|
|
|
* automatically by the core when the protocol is going down.
|
|
|
|
*
|
2021-06-21 15:07:31 +00:00
|
|
|
* CS_PAUSE - Almost the same as CS_STOP, just the table import is kept and
|
|
|
|
* the table export is stopped before transitioning to CS_START.
|
|
|
|
*
|
2016-01-26 10:48:58 +00:00
|
|
|
* Allowed transitions:
|
|
|
|
*
|
|
|
|
* CS_DOWN -> CS_START / CS_UP
|
2021-06-21 15:07:31 +00:00
|
|
|
* CS_START -> CS_UP / CS_STOP
|
|
|
|
* CS_UP -> CS_PAUSE / CS_STOP
|
|
|
|
* CS_PAUSE -> CS_START (automatic)
|
|
|
|
* CS_STOP -> CS_DOWN (automatic)
|
2016-01-26 10:48:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#define CS_DOWN 0
|
|
|
|
#define CS_START 1
|
|
|
|
#define CS_UP 2
|
2021-06-21 15:07:31 +00:00
|
|
|
#define CS_STOP 3
|
|
|
|
#define CS_PAUSE 4
|
2016-01-26 10:48:58 +00:00
|
|
|
|
|
|
|
struct channel_config *proto_cf_find_channel(struct proto_config *p, uint net_type);
|
|
|
|
static inline struct channel_config *proto_cf_main_channel(struct proto_config *pc)
|
2021-06-17 14:56:51 +00:00
|
|
|
{ return proto_cf_find_channel(pc, pc->net_type); }
|
2022-09-14 23:38:18 +00:00
|
|
|
static inline struct channel_config *proto_cf_mpls_channel(struct proto_config *pc)
|
2023-10-05 15:54:43 +00:00
|
|
|
{ return (pc->net_type != NET_MPLS) ? proto_cf_find_channel(pc, NET_MPLS) : NULL; }
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2022-09-07 11:54:20 +00:00
|
|
|
struct channel *proto_find_channel_by_table(struct proto *p, rtable *t);
|
2017-04-25 17:02:31 +00:00
|
|
|
struct channel *proto_find_channel_by_name(struct proto *p, const char *n);
|
2016-01-26 10:48:58 +00:00
|
|
|
struct channel *proto_add_channel(struct proto *p, struct channel_config *cf);
|
2023-08-18 01:53:58 +00:00
|
|
|
void proto_remove_channel(struct proto *p, struct channel *c);
|
2016-01-26 10:48:58 +00:00
|
|
|
int proto_configure_channel(struct proto *p, struct channel **c, struct channel_config *cf);
|
|
|
|
|
|
|
|
void channel_set_state(struct channel *c, uint state);
|
2023-11-02 13:33:00 +00:00
|
|
|
void channel_schedule_reload(struct channel *c, struct channel_import_request *cir);
|
|
|
|
int channel_import_request_prefilter(struct channel_import_request *cir_head, const net_addr *n);
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2023-11-24 11:19:44 +00:00
|
|
|
void channel_add_obstacle(struct channel *c);
|
|
|
|
void channel_del_obstacle(struct channel *c);
|
|
|
|
|
2016-01-26 10:48:58 +00:00
|
|
|
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); }
|
2021-06-21 15:07:31 +00:00
|
|
|
static inline void channel_close(struct channel *c) { channel_set_state(c, CS_STOP); }
|
2016-01-26 10:48:58 +00:00
|
|
|
|
2023-09-29 14:24:50 +00:00
|
|
|
struct channel_feeding_request {
|
2023-10-04 08:02:43 +00:00
|
|
|
struct channel_feeding_request *next; /* Next in request chain */
|
|
|
|
void (*done)(struct channel_feeding_request *); /* Called when refeed finishes */
|
2023-11-02 13:33:00 +00:00
|
|
|
const struct f_trie *trie; /* Reload only matching nets */
|
2023-09-29 14:24:50 +00:00
|
|
|
PACKED enum channel_feeding_request_type {
|
2023-10-04 08:02:43 +00:00
|
|
|
CFRT_DIRECT = 1, /* Refeed by export restart */
|
|
|
|
CFRT_AUXILIARY, /* Refeed by auxiliary request */
|
2023-09-29 14:24:50 +00:00
|
|
|
} type;
|
|
|
|
PACKED enum {
|
2023-10-04 08:02:43 +00:00
|
|
|
CFRS_INACTIVE = 0, /* Inactive request */
|
|
|
|
CFRS_PENDING, /* Request enqueued, do not touch */
|
|
|
|
CFRS_RUNNING, /* Request active, do not touch */
|
2023-09-29 14:24:50 +00:00
|
|
|
} state;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct channel *channel_from_export_request(struct rt_export_request *req);
|
|
|
|
void channel_request_feeding(struct channel *c, struct channel_feeding_request *);
|
|
|
|
void channel_request_feeding_dynamic(struct channel *c, enum channel_feeding_request_type);
|
|
|
|
|
|
|
|
static inline int channel_net_is_refeeding(struct channel *c, const net_addr *n)
|
2023-10-04 08:39:46 +00:00
|
|
|
{
|
|
|
|
/* Not refeeding if not refeeding at all */
|
2024-01-08 11:02:25 +00:00
|
|
|
if (!c->refeeding)
|
2023-10-04 08:39:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Not refeeding if already refed */
|
2024-01-08 11:02:25 +00:00
|
|
|
struct netindex *ni = NET_TO_INDEX(n);
|
|
|
|
if (bmap_test(&c->refeed_map, ni->index))
|
2023-10-04 08:39:46 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* Refeeding if matching any request */
|
|
|
|
for (struct channel_feeding_request *cfr = c->refeeding; cfr; cfr = cfr->next)
|
|
|
|
if (!cfr->trie || trie_match_net(cfr->trie, n))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Not matching any request */
|
|
|
|
return 0;
|
|
|
|
}
|
2023-09-29 14:24:50 +00:00
|
|
|
static inline void channel_net_mark_refed(struct channel *c, const net_addr *n)
|
|
|
|
{
|
2024-01-08 11:02:25 +00:00
|
|
|
ASSERT_DIE(c->refeeding);
|
|
|
|
|
|
|
|
struct netindex *ni = NET_TO_INDEX(n);
|
|
|
|
bmap_set(&c->refeed_map, ni->index);
|
2023-09-29 14:24:50 +00:00
|
|
|
}
|
2023-10-04 08:39:46 +00:00
|
|
|
|
2023-11-09 15:53:34 +00:00
|
|
|
void channel_request_reload(struct channel *c);
|
2018-09-27 20:57:55 +00:00
|
|
|
|
2018-01-09 17:42:22 +00:00
|
|
|
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);
|
2016-01-26 10:48:58 +00:00
|
|
|
int channel_reconfigure(struct channel *c, struct channel_config *cf);
|
|
|
|
|
1998-04-22 12:58:34 +00:00
|
|
|
#endif
|