From: Maria Matejka Date: Fri, 27 Oct 2023 16:29:31 +0000 (+0200) Subject: Merge commit '51f2e7af' into thread-next X-Git-Tag: v3.0.0~378 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ba22509a8bb0d443927aa3f87003e0fd0c9ce2c;p=thirdparty%2Fbird.git Merge commit '51f2e7af' into thread-next Conflicts: conf/cf-lex.l conf/conf.h conf/confbase.Y filter/config.Y nest/config.Y nest/proto.c nest/rt-table.c proto/bgp/bgp.c sysdep/unix/main.c --- 0ba22509a8bb0d443927aa3f87003e0fd0c9ce2c diff --cc conf/cf-lex.l index 85f43c369,952372150..6399fa66d --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@@ -576,18 -565,16 +576,16 @@@ cf_new_symbol(struct sym_scope *scope, if (l > SYM_MAX_LEN) cf_error("Symbol too long"); - cf_swap_soft_scope(); - - s = cfg_allocz(sizeof(struct symbol) + l + 1); - *s = (struct symbol) { .scope = conf_this_scope, .class = SYM_VOID, }; + s = lp_alloc(lp, sizeof(struct symbol) + l + 1); + *s = (struct symbol) { .scope = scope, .class = SYM_VOID, }; - strcpy(s->name, c); + memcpy(s->name, c, l+1); - if (!conf_this_scope->hash.data) - HASH_INIT(conf_this_scope->hash, new_config->pool, SYM_ORDER); + if (!scope->hash.data) + HASH_INIT(scope->hash, p, SYM_ORDER); - HASH_INSERT2(conf_this_scope->hash, SYM, new_config->pool, s); + HASH_INSERT2(scope->hash, SYM, p, s); - if (conf_this_scope == new_config->root_scope) + if (new_config && (scope == new_config->root_scope)) add_tail(&(new_config->symbols), &(s->n)); return s; @@@ -718,35 -689,6 +719,37 @@@ cf_lex_symbol(const char *data } } +void +ea_lex_register(struct ea_class *def) +{ - def->sym = cf_define_symbol(cf_root_symbol(def->name, &global_filter_scope), SYM_ATTRIBUTE, attribute, def); ++ def->sym = cf_root_symbol(def->name, &global_filter_scope); ++ def->sym->class = SYM_ATTRIBUTE; ++ def->sym->attribute = def; +} + +void +ea_lex_unregister(struct ea_class *def) +{ + struct symbol *sym = def->sym; + HASH_REMOVE2(global_filter_scope.hash, SYM, &root_pool, sym); + mb_free(sym); + def->sym = NULL; +} + +struct ea_class * +ea_class_find_by_name(const char *name) +{ + if (!global_filter_scope.hash.data) + return NULL; + + struct symbol *sym = HASH_FIND(global_filter_scope.hash, SYM, name); + + if (!sym || (sym->class != SYM_ATTRIBUTE)) + return NULL; + else + return sym->attribute; +} + /** * cf_lex_init - initialize the lexer * @is_cli: true if we're going to parse CLI command, false for configuration @@@ -760,10 -702,16 +763,14 @@@ cf_lex_init(int is_cli, struct config * { if (!global_root_scope_pool) { - global_root_scope_pool = rp_new(&root_pool, "Keywords pool"); - linpool *kwlp = lp_new(global_root_scope_pool); - global_root_scope = lp_allocz(kwlp, sizeof(*global_root_scope)); + global_root_scope_pool = rp_new(&root_pool, the_bird_domain.the_bird, "Keywords pool"); for (const struct keyword *k = keyword_list; k->name; k++) - cf_define_symbol(cf_root_symbol(k->name, &global_root_scope), SYM_KEYWORD, keyword, k); + { - struct symbol *sym = cf_new_symbol(global_root_scope, global_root_scope_pool, kwlp, k->name); - sym->class = SYM_KEYWORD; - sym->keyword = k; ++ struct symbol *s = cf_root_symbol(k->name, &global_root_scope); ++ s->class = SYM_KEYWORD; ++ s->keyword = k; + } } ifs_head = ifs = push_ifs(NULL); @@@ -782,14 -730,12 +789,13 @@@ else BEGIN(INITIAL); - c->root_scope = cfg_allocz(sizeof(struct sym_scope)); - conf_this_scope = c->root_scope; - conf_this_scope->active = 1; + c->root_scope = c->current_scope = cfg_allocz(sizeof(struct sym_scope)); ++ c->root_scope->active = 1; if (is_cli) - conf_this_scope->next = config->root_scope; + c->current_scope->next = config->root_scope; else - conf_this_scope->next = &global_filter_scope; - c->current_scope->next = global_root_scope; ++ c->current_scope->next = &global_filter_scope; } /** diff --cc conf/conf.h index 19663b3f6,ec8c97e84..767544b87 --- a/conf/conf.h +++ b/conf/conf.h @@@ -54,11 -52,10 +54,12 @@@ struct config char *err_file_name; /* File name containing error */ char *file_name; /* Name of main configuration file */ int file_fd; /* File descriptor of main configuration file */ + int thread_count; /* How many worker threads to prefork */ struct sym_scope *root_scope; /* Scope for root symbols */ + struct sym_scope *current_scope; /* Current scope where we are actually in while parsing */ - int obstacle_count; /* Number of items blocking freeing of this config */ + _Atomic int obstacle_count; /* Number of items blocking freeing of this config */ + event done_event; /* Called when obstacle_count reaches zero */ int shutdown; /* This is a pseudo-config for daemon shutdown */ int gr_down; /* This is a pseudo-config for graceful restart */ btime load_time; /* When we've got this configuration */ diff --cc conf/confbase.Y index c92d4810e,df1e038b8..eaa57541f --- a/conf/confbase.Y +++ b/conf/confbase.Y @@@ -161,8 -157,9 +161,8 @@@ conf: definition definition: DEFINE symbol '=' term ';' { - struct f_val *val = cfg_allocz(sizeof(struct f_val)); - *val = cf_eval($4, T_VOID); + struct f_val *val = cf_eval($4, T_VOID); - cf_define_symbol($2, SYM_CONSTANT | val->type, val, val); + cf_define_symbol(new_config, $2, SYM_CONSTANT | val->type, val, val); } ; diff --cc filter/config.Y index e83c68be8,e1eca9a5e..aededce0e --- a/filter/config.Y +++ b/filter/config.Y @@@ -391,25 -375,15 +391,25 @@@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UN CF_GRAMMAR +conf: FILTER STACKS expr expr ';' { + new_config->filter_vstk = $3; + new_config->filter_estk = $4; + } + ; + conf: filter_def ; filter_def: - FILTER symbol { $2 = cf_define_symbol(new_config, $2, SYM_FILTER, filter, NULL); cf_push_scope( new_config, $2 ); } - filter_body { + FILTER symbol { - $2 = cf_define_symbol($2, SYM_FILTER, filter, NULL); ++ $2 = cf_define_symbol(new_config, $2, SYM_FILTER, filter, NULL); + cf_enter_filters(); - cf_push_scope( $2 ); ++ cf_push_scope( new_config, $2 ); + } filter_body { struct filter *f = cfg_alloc(sizeof(struct filter)); *f = (struct filter) { .sym = $2, .root = $4 }; $2->filter = f; - cf_pop_scope(); + cf_pop_scope(new_config); + cf_exit_filters(); } ; @@@ -420,14 -394,7 +420,14 @@@ filter_eval conf: custom_attr ; custom_attr: ATTRIBUTE type symbol ';' { - cf_define_symbol(new_config, $3, SYM_ATTRIBUTE, attribute, ca_lookup(new_config->pool, $3->name, $2)->fda); + if (($3->class == SYM_ATTRIBUTE) && ($3->scope == new_config->root_scope)) + cf_error("Duplicate attribute %s definition", $3->name); + - cf_define_symbol($3, SYM_ATTRIBUTE, attribute, ++ cf_define_symbol(new_config, $3, SYM_ATTRIBUTE, attribute, + ea_register_alloc(new_config->pool, (struct ea_class) { + .name = $3->name, + .type = $2, + })->class); }; conf: bt_test_suite ; @@@ -531,16 -498,12 +531,16 @@@ filter cf_assert_symbol($1, SYM_FILTER); $$ = $1->filter; } - | { cf_push_scope(new_config, NULL); } filter_body { + | { + cf_enter_filters(); - cf_push_scope(NULL); ++ cf_push_scope(new_config, NULL); + } filter_body { struct filter *f = cfg_alloc(sizeof(struct filter)); *f = (struct filter) { .root = $2 }; $$ = f; - cf_pop_scope(); + cf_pop_scope(new_config); + cf_exit_filters(); } ; @@@ -565,9 -525,8 +565,9 @@@ conf: function_def function_def: FUNCTION symbol { DBG( "Beginning of function %s\n", $2->name ); - $2 = cf_define_symbol($2, SYM_FUNCTION, function, NULL); + $2 = cf_define_symbol(new_config, $2, SYM_FUNCTION, function, NULL); + cf_enter_filters(); - cf_push_scope($2); + cf_push_scope(new_config, $2); } function_args { /* Make dummy f_line for storing function prototype */ struct f_line *dummy = cfg_allocz(sizeof(struct f_line)); @@@ -586,8 -545,7 +586,8 @@@ $6->args = $2->function->args; $6->arg_list = $2->function->arg_list; $2->function = $6; - cf_pop_scope(); + cf_pop_scope(new_config); + cf_exit_filters(); } ; diff --cc nest/rt-table.c index fbbfd4be6,742e2f05b..8d0fc4036 --- a/nest/rt-table.c +++ b/nest/rt-table.c @@@ -3442,8 -2409,8 +3442,8 @@@ rt_preconfig(struct config *c { init_list(&c->tables); - c->def_tables[NET_IP4] = cf_define_symbol(cf_get_symbol("master4"), SYM_TABLE, table, NULL); - c->def_tables[NET_IP6] = cf_define_symbol(cf_get_symbol("master6"), SYM_TABLE, table, NULL); - rt_new_table(cf_get_symbol(c, "master4"), NET_IP4); - rt_new_table(cf_get_symbol(c, "master6"), NET_IP6); ++ c->def_tables[NET_IP4] = cf_define_symbol(c, cf_get_symbol(c, "master4"), SYM_TABLE, table, NULL); ++ c->def_tables[NET_IP6] = cf_define_symbol(c, cf_get_symbol(c, "master6"), SYM_TABLE, table, NULL); } void @@@ -4077,11 -2838,7 +4077,11 @@@ rt_new_table(struct symbol *s, uint add struct rtable_config *c = cfg_allocz(sizeof(struct rtable_config)); - cf_define_symbol(new_config, s, SYM_TABLE, table, c); + if (s == new_config->def_tables[addr_type]) + s->table = c; + else - cf_define_symbol(s, SYM_TABLE, table, c); ++ cf_define_symbol(new_config, s, SYM_TABLE, table, c); + c->name = s->name; c->addr_type = addr_type; c->gc_threshold = 1000;