]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BFD: Better handling of BFD options in BGP configs
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 12 Nov 2020 03:02:38 +0000 (04:02 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Thu, 12 Nov 2020 03:02:38 +0000 (04:02 +0100)
Merge multiple BFD option blocks in BGP configs instead of using the last
one. That is necessary for proper handling of templates when BFD options
are used both in a BGP template and in a BGP protocol derived from that
template.

conf/confbase.Y
nest/config.Y
proto/bgp/bgp.h
proto/bgp/config.Y

index f76dcb3c1aefc01325b3e57f961d53af834d584c..f0343a9398ba991f2965ca5035a396efe54515cd 100644 (file)
@@ -79,7 +79,6 @@ CF_DECLS
   struct f_trie *trie;
   struct f_val v;
   struct password_item *p;
-  struct bfd_options *bo;
   struct rt_show_data *ra;
   struct sym_show_data *sd;
   struct lsadb_show_data *ld;
index 73556f15335e68a08f2b2bc03057fa519597ec1d..83f2c7ba9fe83e06c008a0ec96acb109edceb24e 100644 (file)
@@ -52,6 +52,28 @@ get_passwords(void)
   return rv;
 }
 
+static inline void
+init_bfd_opts(struct bfd_options **opts)
+{
+  cf_check_bfd(1);
+
+  if (! *opts)
+    *opts = bfd_new_options();
+}
+
+static inline void
+open_bfd_opts(struct bfd_options **opts)
+{
+  init_bfd_opts(opts);
+  this_bfd_opts = *opts;
+}
+
+static inline void
+close_bfd_opts(void)
+{
+  this_bfd_opts = NULL;
+}
+
 static void
 proto_postconfig(void)
 {
@@ -99,7 +121,6 @@ CF_ENUM_PX(T_ENUM_AF, AF_, AFI_, IPV4, IPV6)
 %type <ps> proto_patt proto_patt2
 %type <cc> channel_start proto_channel
 %type <cl> limit_spec
-%type <bo> bfd_opts
 %type <net> r_args_for_val
 %type <net_ptr> r_args_for
 %type <t> r_args_channel
@@ -519,7 +540,7 @@ bfd_items:
  ;
 
 bfd_opts:
- '{' { this_bfd_opts = bfd_new_options(); } bfd_items '}' { $$ = this_bfd_opts; this_bfd_opts = NULL; }
+   '{' bfd_items '}'
  ;
 
 /* Core commands */
index 5f365fcd249b7f7aec1bbf77f344b33bb49b3a64..ff52a1a1f7436bb57ddf73ea96c96603c267b80a 100644 (file)
@@ -130,7 +130,7 @@ struct bgp_config {
   const char *dynamic_name;            /* Name pattern for dynamic BGP */
   int dynamic_name_digits;             /* Minimum number of digits for dynamic names */
   int check_link;                      /* Use iface link state for liveness detection */
-  const struct bfd_options *bfd;       /* Use BFD for liveness detection */
+  struct bfd_options *bfd;             /* Use BFD for liveness detection */
 };
 
 struct bgp_channel_config {
index dc2956451e129de6f9047ef233dc8d14647c6b11..cc83bfc7be640594ad0225315b3d3bcbb4d0b1b1 100644 (file)
@@ -190,9 +190,9 @@ bgp_proto:
  | bgp_proto LONG LIVED STALE TIME expr ';' { BGP_CFG->llgr_time = $6; }
  | bgp_proto TTL SECURITY bool ';' { BGP_CFG->ttl_security = $4; }
  | bgp_proto CHECK LINK bool ';' { BGP_CFG->check_link = $4; }
- | bgp_proto BFD bool ';' { cf_check_bfd($3); BGP_CFG->bfd = $3 ? bfd_new_options() : NULL; }
- | bgp_proto BFD GRACEFUL ';' { cf_check_bfd(1); struct bfd_options *opts = bfd_new_options(); opts->mode = BGP_BFD_GRACEFUL; BGP_CFG->bfd = opts; }
- | bgp_proto BFD bfd_opts ';' { BGP_CFG->bfd = $3; cf_check_bfd(1); }
+ | bgp_proto BFD bool ';' { if ($3) init_bfd_opts(&BGP_CFG->bfd); else BGP_CFG->bfd = NULL; }
+ | bgp_proto BFD GRACEFUL ';' { init_bfd_opts(&BGP_CFG->bfd); BGP_CFG->bfd->mode = BGP_BFD_GRACEFUL; }
+ | bgp_proto BFD { open_bfd_opts(&BGP_CFG->bfd); } bfd_opts { close_bfd_opts(); } ';'
  | bgp_proto ENFORCE FIRST AS bool ';' { BGP_CFG->enforce_first_as = $5; }
  ;