]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Conf: Use nonterminal bytestring instead of BYTETEXT
authorOndrej Zajicek <santiago@crfreenet.org>
Thu, 24 Aug 2023 14:59:23 +0000 (16:59 +0200)
committerOndrej Zajicek <santiago@crfreenet.org>
Thu, 24 Aug 2023 14:59:23 +0000 (16:59 +0200)
Nonterminal bytestring allows to provide expressions to be evaluated in
places where BYTETEXT is used now: passwords, radv custom option.

Based on the patch from Alexander Zubkov <green@qrator.net>, thanks!

conf/confbase.Y
nest/config.Y
proto/radv/config.Y

index e109ddf5a802421e35576ae507e3b8dcf95fb438..f8d244157edaedfdd1bd9a9d0f793870b1de0e35 100644 (file)
@@ -117,9 +117,13 @@ CF_DECLS
 %type <mls> label_stack_start label_stack
 
 %type <t> text opttext
+%type <bs> bytestring
 %type <s> symbol
 %type <kw> kw_sym
 
+%type <v> bytestring_text
+%type <x> bytestring_expr
+
 %nonassoc PREFIX_DUMMY
 %left AND OR
 %nonassoc '=' '<' '>' '~' GEQ LEQ NEQ NMA PO PC
@@ -395,6 +399,27 @@ opttext:
  | /* empty */ { $$ = NULL; }
  ;
 
+bytestring:
+   BYTETEXT
+ | bytestring_expr { $$ = cf_eval($1, T_BYTESTRING).val.bs; }
+ ;
+
+bytestring_text:
+   BYTETEXT { $$.type = T_BYTESTRING; $$.val.bs = $1; }
+ | TEXT { $$.type = T_STRING; $$.val.s = $1; }
+ | bytestring_expr {
+     $$ = cf_eval($1, T_VOID);
+     if (($$.type != T_BYTESTRING) && ($$.type != T_STRING))
+       cf_error("Bytestring or string value expected");
+   }
+ ;
+
+bytestring_expr:
+   symbol_value
+ | term_bs
+ | '(' term ')' { $$ = $2; }
+ ;
+
 
 CF_CODE
 
index 610b1c012f1fa2ec3fc8dd58494d07ae77258553..1c40ced6dc7d707d703d4ea296c48314ecd825de 100644 (file)
@@ -546,10 +546,15 @@ password_item:
 
 pass_key: PASSWORD | KEY;
 
-password_item_begin:
-    pass_key text { init_password_list(); init_password($2, strlen($2), password_id++); }
-  | pass_key BYTETEXT { init_password_list(); init_password($2->data, $2->length, password_id++); }
-;
+password_item_begin: pass_key bytestring_text
+{
+  init_password_list();
+  if ($2.type == T_BYTESTRING)
+    init_password($2.val.bs->data, $2.val.bs->length, password_id++);
+  else if ($2.type == T_STRING)
+    init_password($2.val.s, strlen($2.val.s), password_id++);
+  else bug("Bad bytestring_text");
+};
 
 password_item_params:
    /* empty */ { }
index 9653cd7becd971b53a4fe101158f2e02edf51928..9c5e1761c948f0f311c2160b2da399df4d40efb2 100644 (file)
@@ -73,7 +73,7 @@ radv_proto_item:
  | PREFIX radv_prefix { add_tail(&RADV_CFG->pref_list, NODE this_radv_prefix); }
  | RDNSS { init_list(&radv_dns_list); } radv_rdnss { add_tail_list(&RADV_CFG->rdnss_list, &radv_dns_list); }
  | DNSSL { init_list(&radv_dns_list); } radv_dnssl { add_tail_list(&RADV_CFG->dnssl_list, &radv_dns_list); }
- | CUSTOM OPTION TYPE expr VALUE BYTETEXT { radv_add_to_custom_list(&RADV_CFG->custom_list, $4, $6); }
+ | CUSTOM OPTION TYPE expr VALUE bytestring { radv_add_to_custom_list(&RADV_CFG->custom_list, $4, $6); }
  | TRIGGER net_ip6 { RADV_CFG->trigger = $2; }
  | PROPAGATE ROUTES bool { RADV_CFG->propagate_routes = $3; }
  ;
@@ -138,7 +138,7 @@ radv_iface_item:
  | PREFIX radv_prefix { add_tail(&RADV_IFACE->pref_list, NODE this_radv_prefix); }
  | RDNSS { init_list(&radv_dns_list); } radv_rdnss { add_tail_list(&RADV_IFACE->rdnss_list, &radv_dns_list); }
  | DNSSL { init_list(&radv_dns_list); } radv_dnssl { add_tail_list(&RADV_IFACE->dnssl_list, &radv_dns_list); }
- | CUSTOM OPTION TYPE expr VALUE BYTETEXT { radv_add_to_custom_list(&RADV_IFACE->custom_list, $4, $6); }
+ | CUSTOM OPTION TYPE expr VALUE bytestring { radv_add_to_custom_list(&RADV_IFACE->custom_list, $4, $6); }
  | RDNSS LOCAL bool { RADV_IFACE->rdnss_local = $3; }
  | DNSSL LOCAL bool { RADV_IFACE->dnssl_local = $3; }
  | CUSTOM OPTION LOCAL bool { RADV_IFACE->custom_local = $4; }