]> git.ipfire.org Git - thirdparty/bird.git/blobdiff - nest/protocol.h
Nest: VRF of protocol can be explicitly specified as 'default'
[thirdparty/bird.git] / nest / protocol.h
index 61160c0a49b1af00d6d559447c95ec4eea29e181..c8110f3cd663459a1ba76cf2052ed7cafee15997 100644 (file)
@@ -47,6 +47,7 @@ enum protocol_class {
   PROTOCOL_KERNEL,
   PROTOCOL_OSPF,
   PROTOCOL_MRT,
+  PROTOCOL_PERF,
   PROTOCOL_PIPE,
   PROTOCOL_RADV,
   PROTOCOL_RIP,
@@ -88,6 +89,7 @@ void protos_build(void);
 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 */
@@ -100,7 +102,8 @@ void protos_dump_all(void);
 
 extern struct protocol
   proto_device, proto_radv, proto_rip, proto_static, proto_mrt,
-  proto_ospf, proto_pipe, proto_bgp, proto_bfd, proto_babel, proto_rpki;
+  proto_ospf, proto_perf,
+  proto_pipe, proto_bgp, proto_bfd, proto_babel, proto_rpki;
 
 /*
  *     Routing Protocol Instance
@@ -111,11 +114,13 @@ struct proto_config {
   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 */
   u8 net_type;                         /* Protocol network type (NET_*), 0 for undefined */
   u8 disabled;                         /* Protocol enabled/disabled by default */
+  u8 vrf_set;                          /* Related VRF instance (below) is defined */
   u32 debug, mrtdump;                  /* Debugging bitfields, both use D_* constants */
   u32 router_id;                       /* Protocol specific router ID */
 
@@ -132,6 +137,7 @@ struct proto_stats {
   /* 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 */
@@ -171,6 +177,7 @@ struct proto {
   uint active_channels;                        /* Number of active channels */
   byte net_type;                       /* Protocol network type (NET_*), 0 for undefined */
   byte disabled;                       /* Manually disabled */
+  byte vrf_set;                                /* Related VRF instance (above) is defined */
   byte proto_state;                    /* Protocol state machine (PS_*, see below) */
   byte active;                         /* From PS_START to cleanup after PS_STOP */
   byte do_start;                       /* Start actions are scheduled */
@@ -191,12 +198,12 @@ struct proto {
    *      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 rta. The route MUST NOT be cached.
-   *      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).
@@ -208,9 +215,9 @@ struct proto {
   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);
   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);
-  int (*import_control)(struct proto *, struct rte **rt, 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 *);
@@ -252,6 +259,7 @@ struct proto_spec {
 #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 */
@@ -260,6 +268,7 @@ struct proto_spec {
 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);
@@ -294,20 +303,6 @@ proto_get_router_id(struct proto_config *pc)
   return pc->router_id ? pc->router_id : pc->global->router_id;
 }
 
-static inline void
-rte_make_tmp_attrs(struct rte **rt, struct linpool *pool)
-{
-  struct ea_list *(*mta)(struct rte *rt, struct linpool *pool);
-  mta = (*rt)->attrs->src->proto->make_tmp_attrs;
-  if (!mta) return;
-  *rt = rte_cow_rta(*rt, pool);
-  struct ea_list *ea = mta(*rt, pool);
-  ea->next = (*rt)->attrs->eattrs;
-  (*rt)->attrs->eattrs = ea;
-}
-
-/* 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); }
 
 extern pool *proto_pool;
 extern list proto_list;
@@ -539,6 +534,11 @@ struct channel {
 
   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 */
 };
 
 
@@ -606,6 +606,8 @@ 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); }
@@ -617,4 +619,17 @@ void *channel_config_get(const struct channel_class *cc, const char *name, uint
 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