mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-17 08:38:42 +00:00
Conf: Allowing keyword redefinition
Some tokens are both keywords and symbols. For now, we allow only specific keywords to be redefined; in future, more of the keywords may be added to this category. The redefinable keywords must be specified in any .Y file as follows: toksym: THE_KEYWORD ; See proto/bgp/config.Y for an example. Also dropped a lot of unused terminals.
This commit is contained in:
parent
8ebac84bc8
commit
cce974e8ea
@ -709,10 +709,7 @@ cf_lex_symbol(const char *data)
|
||||
struct symbol *sym = cf_get_symbol(data);
|
||||
cf_lval.s = sym;
|
||||
|
||||
if (sym->class != SYM_VOID)
|
||||
return CF_SYM_KNOWN;
|
||||
|
||||
/* Is it a keyword? */
|
||||
/* Is it a keyword? Prefer the keyword. */
|
||||
struct keyword *k = HASH_FIND(kw_hash, KW, data);
|
||||
if (k)
|
||||
{
|
||||
@ -725,9 +722,11 @@ cf_lex_symbol(const char *data)
|
||||
}
|
||||
}
|
||||
|
||||
/* OK, undefined symbol */
|
||||
cf_lval.s = sym;
|
||||
return CF_SYM_UNDEFINED;
|
||||
/* OK, only a symbol. */
|
||||
if (sym->class == SYM_VOID)
|
||||
return CF_SYM_UNDEFINED;
|
||||
else
|
||||
return CF_SYM_KNOWN;
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -116,7 +116,7 @@ CF_DECLS
|
||||
%type <mls> label_stack_start label_stack
|
||||
|
||||
%type <t> text opttext
|
||||
%type <s> symbol
|
||||
%type <s> symbol symbol_known toksym
|
||||
|
||||
%nonassoc PREFIX_DUMMY
|
||||
%left AND OR
|
||||
@ -162,7 +162,7 @@ definition:
|
||||
expr:
|
||||
NUM
|
||||
| '(' term ')' { $$ = f_eval_int(f_linearize($2)); }
|
||||
| CF_SYM_KNOWN {
|
||||
| symbol_known {
|
||||
if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number constant expected");
|
||||
$$ = SYM_VAL($1).i; }
|
||||
;
|
||||
@ -173,7 +173,9 @@ expr_us:
|
||||
| expr US { $$ = $1 US_; }
|
||||
;
|
||||
|
||||
symbol: CF_SYM_UNDEFINED | CF_SYM_KNOWN ;
|
||||
toksym: FROM ;
|
||||
symbol: CF_SYM_UNDEFINED | CF_SYM_KNOWN | toksym ;
|
||||
symbol_known: CF_SYM_KNOWN | toksym ;
|
||||
|
||||
/* Switches */
|
||||
|
||||
|
@ -26,8 +26,7 @@ m4_define(CF_DEFINES, `m4_divert(-1)')
|
||||
m4_define(CF_handle_kw, `m4_divert(1){ "m4_translit($1,[[A-Z]],[[a-z]])", $1, NULL },
|
||||
m4_divert(-1)')
|
||||
m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)CF_handle_kw($1)]])')
|
||||
m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks
|
||||
)DNL')
|
||||
m4_define(CF_KEYWORDS, `CF_iterate([[CF_keywd]], [[$@]])DNL')
|
||||
|
||||
# CLI commands generate keywords as well
|
||||
m4_define(CF_CLI, `CF_KEYWORDS(m4_translit($1, [[ ]], [[,]]))
|
||||
|
@ -31,7 +31,7 @@ m4_define(CF_iterate, `m4_define([[CF_iter]], m4_defn([[$1]]))CF_itera($2)')
|
||||
|
||||
# Keywords act as untyped %token
|
||||
m4_define(CF_keywd, `m4_ifdef([[CF_tok_$1]],,[[m4_define([[CF_tok_$1]],1)m4_define([[CF_toks]],CF_toks $1)]])')
|
||||
m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token[[]]CF_toks
|
||||
m4_define(CF_KEYWORDS, `m4_define([[CF_toks]],[[]])CF_iterate([[CF_keywd]], [[$@]])m4_ifelse(CF_toks,,,%token<s>[[]]CF_toks
|
||||
)DNL')
|
||||
|
||||
# CLI commands
|
||||
|
@ -291,8 +291,8 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
|
||||
LEN, MAXLEN,
|
||||
DATA, DATA1, DATA2,
|
||||
DEFINED,
|
||||
ADD, DELETE, CONTAINS, RESET,
|
||||
PREPEND, FIRST, LAST, LAST_NONAGGREGATED, MATCH,
|
||||
ADD, DELETE, RESET,
|
||||
PREPEND, FIRST, LAST, LAST_NONAGGREGATED,
|
||||
MIN, MAX,
|
||||
EMPTY,
|
||||
FILTER, WHERE, EVAL, ATTRIBUTE,
|
||||
@ -357,7 +357,7 @@ custom_attr: ATTRIBUTE type symbol ';' {
|
||||
|
||||
conf: bt_test_suite ;
|
||||
bt_test_suite:
|
||||
BT_TEST_SUITE '(' CF_SYM_KNOWN ',' text ')' {
|
||||
BT_TEST_SUITE '(' symbol_known ',' text ')' {
|
||||
cf_assert_symbol($3, SYM_FUNCTION);
|
||||
struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite));
|
||||
t->fn = $3->function;
|
||||
@ -370,7 +370,7 @@ bt_test_suite:
|
||||
|
||||
conf: bt_test_same ;
|
||||
bt_test_same:
|
||||
BT_TEST_SAME '(' CF_SYM_KNOWN ',' CF_SYM_KNOWN ',' NUM ')' {
|
||||
BT_TEST_SAME '(' symbol_known ',' symbol_known ',' NUM ')' {
|
||||
cf_assert_symbol($3, SYM_FUNCTION);
|
||||
cf_assert_symbol($5, SYM_FUNCTION);
|
||||
struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite));
|
||||
@ -448,7 +448,7 @@ function_vars:
|
||||
filter_body: function_body ;
|
||||
|
||||
filter:
|
||||
CF_SYM_KNOWN {
|
||||
symbol_known {
|
||||
cf_assert_symbol($1, SYM_FILTER);
|
||||
$$ = $1->filter;
|
||||
}
|
||||
@ -549,7 +549,7 @@ set_atom:
|
||||
if (f_eval(f_linearize($2), &($$)) > F_RETURN) cf_error("Runtime error");
|
||||
if (!f_valid_set_type($$.type)) cf_error("Set-incompatible type");
|
||||
}
|
||||
| CF_SYM_KNOWN {
|
||||
| symbol_known {
|
||||
cf_assert_symbol($1, SYM_CONSTANT);
|
||||
if (!f_valid_set_type(SYM_TYPE($1))) cf_error("%s: set-incompatible type", $1->name);
|
||||
$$ = *$1->val;
|
||||
@ -719,7 +719,7 @@ var_list: /* EMPTY */ { $$ = NULL; }
|
||||
| var_list ',' term { $$ = $3; $$->next = $1; }
|
||||
|
||||
function_call:
|
||||
CF_SYM_KNOWN '(' var_list ')' {
|
||||
symbol_known '(' var_list ')' {
|
||||
if ($1->class != SYM_FUNCTION)
|
||||
cf_error("You can't call something which is not a function. Really.");
|
||||
|
||||
@ -743,7 +743,7 @@ function_call:
|
||||
}
|
||||
;
|
||||
|
||||
symbol_value: CF_SYM_KNOWN
|
||||
symbol_value: symbol_known
|
||||
{
|
||||
switch ($1->class) {
|
||||
case SYM_CONSTANT_RANGE:
|
||||
@ -872,7 +872,7 @@ cmd:
|
||||
| IF term THEN block ELSE block {
|
||||
$$ = f_new_inst(FI_CONDITION, $2, $4, $6);
|
||||
}
|
||||
| CF_SYM_KNOWN '=' term ';' {
|
||||
| symbol_known '=' term ';' {
|
||||
switch ($1->class) {
|
||||
case SYM_VARIABLE_RANGE:
|
||||
$$ = f_new_inst(FI_VAR_SET, $3, $1);
|
||||
@ -895,7 +895,7 @@ cmd:
|
||||
cf_error( "This static attribute is read-only.");
|
||||
$$ = f_new_inst(FI_RTA_SET, $3, $1);
|
||||
}
|
||||
| UNSET '(' CF_SYM_KNOWN ')' ';' {
|
||||
| UNSET '(' symbol_known ')' ';' {
|
||||
if ($3->class != SYM_ATTRIBUTE)
|
||||
cf_error("Can't unset %s", $3->name);
|
||||
if ($3->attribute->readonly)
|
||||
@ -933,11 +933,11 @@ cmd:
|
||||
$$ = f_new_inst(FI_SWITCH, $2, build_tree($4));
|
||||
}
|
||||
|
||||
| CF_SYM_KNOWN '.' EMPTY ';' { $$ = f_generate_empty($1); }
|
||||
| CF_SYM_KNOWN '.' PREPEND '(' term ')' ';' { $$ = f_generate_complex_sym( FI_PATH_PREPEND, $1, $5 ); }
|
||||
| CF_SYM_KNOWN '.' ADD '(' term ')' ';' { $$ = f_generate_complex_sym( FI_CLIST_ADD, $1, $5 ); }
|
||||
| CF_SYM_KNOWN '.' DELETE '(' term ')' ';' { $$ = f_generate_complex_sym( FI_CLIST_DEL, $1, $5 ); }
|
||||
| CF_SYM_KNOWN '.' FILTER '(' term ')' ';' { $$ = f_generate_complex_sym( FI_CLIST_FILTER, $1, $5 ); }
|
||||
| symbol_known '.' EMPTY ';' { $$ = f_generate_empty($1); }
|
||||
| symbol_known '.' PREPEND '(' term ')' ';' { $$ = f_generate_complex_sym( FI_PATH_PREPEND, $1, $5 ); }
|
||||
| symbol_known '.' ADD '(' term ')' ';' { $$ = f_generate_complex_sym( FI_CLIST_ADD, $1, $5 ); }
|
||||
| symbol_known '.' DELETE '(' term ')' ';' { $$ = f_generate_complex_sym( FI_CLIST_DEL, $1, $5 ); }
|
||||
| symbol_known '.' FILTER '(' term ')' ';' { $$ = f_generate_complex_sym( FI_CLIST_FILTER, $1, $5 ); }
|
||||
| BT_ASSERT '(' get_cf_position term get_cf_position ')' ';' { $$ = assert_done($4, $3 + 1, $5 - 1); }
|
||||
| BT_CHECK_ASSIGN '(' get_cf_position lvalue get_cf_position ',' term ')' ';' { $$ = assert_assign(&$4, $7, $3 + 1, $5 - 1); }
|
||||
;
|
||||
@ -948,7 +948,7 @@ get_cf_position:
|
||||
};
|
||||
|
||||
lvalue:
|
||||
CF_SYM_KNOWN {
|
||||
symbol_known {
|
||||
switch ($1->class) {
|
||||
case SYM_VARIABLE_RANGE:
|
||||
$$ = (struct f_lval) { .type = F_LVAL_VARIABLE, .sym = $1 };
|
||||
|
@ -118,11 +118,11 @@ CF_KEYWORDS(IPV4, IPV6, VPN4, VPN6, ROA4, ROA6, FLOW4, FLOW6, SADR, MPLS)
|
||||
CF_KEYWORDS(RECEIVE, LIMIT, ACTION, WARN, BLOCK, RESTART, DISABLE, KEEP, FILTERED, RPKI)
|
||||
CF_KEYWORDS(PASSWORD, KEY, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, CHANNELS, INTERFACES)
|
||||
CF_KEYWORDS(ALGORITHM, KEYED, HMAC, MD5, SHA1, SHA256, SHA384, SHA512, BLAKE2S128, BLAKE2S256, BLAKE2B256, BLAKE2B512)
|
||||
CF_KEYWORDS(PRIMARY, STATS, COUNT, BY, FOR, IN, COMMANDS, PREEXPORT, NOEXPORT, EXPORTED, GENERATE)
|
||||
CF_KEYWORDS(PRIMARY, STATS, COUNT, FOR, IN, COMMANDS, PREEXPORT, NOEXPORT, EXPORTED, GENERATE)
|
||||
CF_KEYWORDS(BGP, PASSWORDS, DESCRIPTION)
|
||||
CF_KEYWORDS(RELOAD, IN, OUT, MRTDUMP, MESSAGES, RESTRICT, MEMORY, CLASS, DSCP)
|
||||
CF_KEYWORDS(TIMEFORMAT, ISO, SHORT, LONG, ROUTE, PROTOCOL, BASE, LOG, S, MS, US)
|
||||
CF_KEYWORDS(GRACEFUL, RESTART, WAIT, MAX, FLUSH, AS)
|
||||
CF_KEYWORDS(GRACEFUL, RESTART, WAIT, MAX, AS)
|
||||
CF_KEYWORDS(MIN, IDLE, RX, TX, INTERVAL, MULTIPLIER, PASSIVE)
|
||||
CF_KEYWORDS(CHECK, LINK)
|
||||
CF_KEYWORDS(SORTED, TRIE, MIN, MAX, SETTLE, TIME)
|
||||
@ -659,7 +659,7 @@ r_args:
|
||||
$$->addr = $3;
|
||||
$$->addr_mode = RSD_ADDR_IN;
|
||||
}
|
||||
| r_args TABLE CF_SYM_KNOWN {
|
||||
| r_args TABLE symbol_known {
|
||||
cf_assert_symbol($3, SYM_TABLE);
|
||||
$$ = $1;
|
||||
rt_show_add_table($$, $3->table->table);
|
||||
@ -704,7 +704,7 @@ r_args:
|
||||
$$ = $1;
|
||||
$$->filtered = 1;
|
||||
}
|
||||
| r_args export_mode CF_SYM_KNOWN {
|
||||
| r_args export_mode symbol_known {
|
||||
cf_assert_symbol($3, SYM_PROTO);
|
||||
struct proto_config *c = (struct proto_config *) $3->proto;
|
||||
$$ = $1;
|
||||
@ -721,7 +721,7 @@ r_args:
|
||||
$$->export_channel = $3;
|
||||
$$->tables_defined_by = RSD_TDB_INDIRECT;
|
||||
}
|
||||
| r_args PROTOCOL CF_SYM_KNOWN {
|
||||
| r_args PROTOCOL symbol_known {
|
||||
cf_assert_symbol($3, SYM_PROTO);
|
||||
struct proto_config *c = (struct proto_config *) $3->proto;
|
||||
$$ = $1;
|
||||
|
@ -24,7 +24,7 @@ CF_DECLS
|
||||
|
||||
CF_KEYWORDS(BABEL, INTERFACE, METRIC, RXCOST, HELLO, UPDATE, INTERVAL, PORT,
|
||||
TYPE, WIRED, WIRELESS, RX, TX, BUFFER, PRIORITY, LENGTH, CHECK, LINK,
|
||||
NEXT, HOP, IPV4, IPV6, BABEL_METRIC, SHOW, INTERFACES, NEIGHBORS,
|
||||
NEXT, HOP, IPV4, IPV6, SHOW, INTERFACES, NEIGHBORS,
|
||||
ENTRIES, RANDOMIZE, ROUTER, ID, AUTHENTICATION, NONE, MAC, PERMISSIVE)
|
||||
|
||||
CF_GRAMMAR
|
||||
|
@ -19,18 +19,17 @@ CF_DECLS
|
||||
|
||||
CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, KEEPALIVE,
|
||||
MULTIHOP, STARTUP, VIA, NEXT, HOP, SELF, DEFAULT, PATH, METRIC, ERROR,
|
||||
START, DELAY, FORGET, WAIT, ENABLE, DISABLE, AFTER, BGP_PATH,
|
||||
BGP_LOCAL_PREF, BGP_MED, BGP_ORIGIN, BGP_NEXT_HOP, BGP_ATOMIC_AGGR,
|
||||
BGP_AGGREGATOR, BGP_COMMUNITY, BGP_EXT_COMMUNITY, BGP_LARGE_COMMUNITY,
|
||||
START, DELAY, FORGET, WAIT, ENABLE, DISABLE, AFTER,
|
||||
BGP_LOCAL_PREF, BGP_MED,
|
||||
SOURCE, ADDRESS, PASSWORD, RR, RS, CLIENT, CLUSTER, ID, AS4, ADVERTISE,
|
||||
IPV4, CAPABILITIES, LIMIT, PASSIVE, PREFER, OLDER, MISSING, LLADDR,
|
||||
DROP, IGNORE, ROUTE, REFRESH, INTERPRET, COMMUNITIES, BGP_ORIGINATOR_ID,
|
||||
BGP_CLUSTER_LIST, IGP, TABLE, GATEWAY, DIRECT, RECURSIVE, MED, TTL,
|
||||
DROP, IGNORE, ROUTE, REFRESH, INTERPRET, COMMUNITIES,
|
||||
IGP, TABLE, GATEWAY, DIRECT, RECURSIVE, MED, TTL,
|
||||
SECURITY, DETERMINISTIC, SECONDARY, ALLOW, BFD, ADD, PATHS, RX, TX,
|
||||
GRACEFUL, RESTART, AWARE, CHECK, LINK, PORT, EXTENDED, MESSAGES, SETKEY,
|
||||
STRICT, BIND, CONFEDERATION, MEMBER, MULTICAST, FLOW4, FLOW6, LONG,
|
||||
LIVED, STALE, IMPORT, IBGP, EBGP, MANDATORY, INTERNAL, EXTERNAL, SETS,
|
||||
DYNAMIC, RANGE, NAME, DIGITS, BGP_AIGP, AIGP, ORIGINATE, COST, ENFORCE,
|
||||
DYNAMIC, RANGE, NAME, DIGITS, AIGP, ORIGINATE, COST, ENFORCE,
|
||||
FIRST, FREE, VALIDATE, BASE)
|
||||
|
||||
%type <i> bgp_nh
|
||||
@ -44,6 +43,8 @@ CF_KEYWORDS(CEASE, PREFIX, LIMIT, HIT, ADMINISTRATIVE, SHUTDOWN, RESET, PEER,
|
||||
|
||||
CF_GRAMMAR
|
||||
|
||||
toksym: BGP_MED | BGP_LOCAL_PREF ;
|
||||
|
||||
proto: bgp_proto '}' ;
|
||||
|
||||
bgp_proto_start: proto_start BGP {
|
||||
|
@ -190,7 +190,7 @@ ospf_check_auth(void)
|
||||
|
||||
CF_DECLS
|
||||
|
||||
CF_KEYWORDS(OSPF, V2, V3, OSPF_METRIC1, OSPF_METRIC2, OSPF_TAG, OSPF_ROUTER_ID)
|
||||
CF_KEYWORDS(OSPF, V2, V3)
|
||||
CF_KEYWORDS(AREA, NEIGHBORS, RFC1583COMPAT, STUB, TICK, COST, COST2, RETRANSMIT)
|
||||
CF_KEYWORDS(HELLO, TRANSMIT, PRIORITY, DEAD, TYPE, BROADCAST, BCAST, DEFAULT)
|
||||
CF_KEYWORDS(NONBROADCAST, NBMA, POINTOPOINT, PTP, POINTOMULTIPOINT, PTMP)
|
||||
|
@ -33,7 +33,7 @@ CF_KEYWORDS(RADV, PREFIX, INTERFACE, MIN, MAX, RA, DELAY, INTERVAL, SOLICITED,
|
||||
RETRANS, TIMER, CURRENT, HOP, LIMIT, DEFAULT, VALID, PREFERRED, MULT,
|
||||
LIFETIME, SKIP, ONLINK, AUTONOMOUS, RDNSS, DNSSL, NS, DOMAIN, LOCAL,
|
||||
TRIGGER, SENSITIVE, PREFERENCE, LOW, MEDIUM, HIGH, PROPAGATE, ROUTE,
|
||||
ROUTES, RA_PREFERENCE, RA_LIFETIME)
|
||||
ROUTES)
|
||||
|
||||
CF_ENUM(T_ENUM_RA_PREFERENCE, RA_PREF_, LOW, MEDIUM, HIGH)
|
||||
|
||||
|
@ -37,7 +37,7 @@ CF_KEYWORDS(RIP, NG, ECMP, LIMIT, WEIGHT, INFINITY, METRIC, UPDATE, TIMEOUT,
|
||||
PASSIVE, VERSION, SPLIT, HORIZON, POISON, REVERSE, CHECK, ZERO,
|
||||
TIME, BFD, AUTHENTICATION, NONE, PLAINTEXT, CRYPTOGRAPHIC, MD5,
|
||||
TTL, SECURITY, RX, TX, BUFFER, LENGTH, PRIORITY, ONLY, LINK,
|
||||
DEMAND, CIRCUIT, RIP_METRIC, RIP_TAG)
|
||||
DEMAND, CIRCUIT)
|
||||
|
||||
%type <i> rip_variant rip_auth
|
||||
|
||||
|
@ -11,9 +11,6 @@ CF_HDR
|
||||
CF_DECLS
|
||||
|
||||
CF_KEYWORDS(KERNEL, TABLE, METRIC, NETLINK, RX, BUFFER,
|
||||
KRT_PREFSRC, KRT_REALM, KRT_SCOPE, KRT_MTU, KRT_WINDOW,
|
||||
KRT_RTT, KRT_RTTVAR, KRT_SSTRESH, KRT_CWND, KRT_ADVMSS, KRT_REORDERING,
|
||||
KRT_HOPLIMIT, KRT_INITCWND, KRT_RTO_MIN, KRT_INITRWND, KRT_QUICKACK,
|
||||
KRT_LOCK_MTU, KRT_LOCK_WINDOW, KRT_LOCK_RTT, KRT_LOCK_RTTVAR,
|
||||
KRT_LOCK_SSTRESH, KRT_LOCK_CWND, KRT_LOCK_ADVMSS, KRT_LOCK_REORDERING,
|
||||
KRT_LOCK_HOPLIMIT, KRT_LOCK_RTO_MIN, KRT_FEATURE_ECN, KRT_FEATURE_ALLFRAG)
|
||||
|
@ -29,7 +29,7 @@ kif_set_preferred(ip_addr ip)
|
||||
|
||||
CF_DECLS
|
||||
|
||||
CF_KEYWORDS(KERNEL, PERSIST, SCAN, TIME, LEARN, DEVICE, ROUTES, GRACEFUL, RESTART, KRT_SOURCE, KRT_METRIC, MERGE, PATHS)
|
||||
CF_KEYWORDS(KERNEL, PERSIST, SCAN, TIME, LEARN, DEVICE, ROUTES, GRACEFUL, RESTART, MERGE, PATHS)
|
||||
CF_KEYWORDS(INTERFACE, PREFERRED)
|
||||
|
||||
%type <i> kern_mp_limit
|
||||
|
Loading…
Reference in New Issue
Block a user