diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 43f517cb..1b84ce8f 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -132,10 +132,6 @@ build-fedora-34-amd64: <<: *build-linux image: registry.nic.cz/labs/bird:fedora-33-amd64 -#build-centos-7-amd64: -# <<: *build-linux -# image: registry.nic.cz/labs/bird:centos-7-amd64 - build-centos-8-amd64: <<: *build-linux image: registry.nic.cz/labs/bird:centos-8-amd64 @@ -260,13 +256,6 @@ pkg-fedora-34-amd64: needs: [build-fedora-34-amd64] image: registry.nic.cz/labs/bird:fedora-34-amd64 -#pkg-centos-7-amd64: -# <<: *pkg-rpm-wa -# variables: -# LC_ALL: en_US.UTF-8 -# needs: [build-centos-7-amd64] -# image: registry.nic.cz/labs/bird:centos-7-amd64 - pkg-centos-8-amd64: <<: *pkg-rpm-wa needs: [build-centos-8-amd64] @@ -334,7 +323,7 @@ build-netlab: script: - cd $TOOLS_DIR/netlab - sudo ./stop - - sudo ./runtest -s v2 -m check $TEST_NAME + - sudo ./runtest -s v3 -m check $TEST_NAME test-ospf-base: <<: *test-base @@ -446,11 +435,11 @@ test-ibgp-loop: variables: TEST_NAME: cf-ibgp-loop -test-ibgp-loop-big: - <<: *test-base - variables: - TEST_NAME: cf-ibgp-loop-big - +#test-ibgp-loop-big: +# <<: *test-base +# variables: +# TEST_NAME: cf-ibgp-loop-big +# test-ibgp-flat: <<: *test-base variables: diff --git a/INSTALL b/INSTALL index 7a179284..c1094ee5 100644 --- a/INSTALL +++ b/INSTALL @@ -27,9 +27,9 @@ Requirements For compiling BIRD you need these programs and libraries: - - GNU C Compiler (or LLVM Clang) + - GNU C Compiler (or LLVM Clang) capable of compiling C11 code - GNU Make - - GNU Bison + - GNU Bison (at least 3.0) - GNU M4 - Flex diff --git a/NEWS b/NEWS index 4016179a..cc1deff8 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,35 @@ +Version 3.0alpha2 (2023-05-11) + o Fixed memory leaks and use-after free bugs + o Simple thread work balancing + o MRT switched off + o Slow kernel route synchronization to be fixed later + +Version 3.0alpha1 (2023-04-18) + o Worker threads for BGP, Pipe, RPKI and BFD + o Configurable number of threads + o Asynchronous route export + o Flat attribute structure + o Inline import tables + o Export tables merged with BGP prefix / attribute buckets + o Fixed ROA check locking inversion in route table dumps + o MRT switched off + +Version 3.0-alpha0 (2022-02-07) + o Removal of fixed protocol-specific route attributes + o Asynchronous route export + o Explicit table import / export hooks + o Partially lockless route attribute cache + o Thread-safe resource management + o Thread-safe interface notifications + o Thread-safe protocol API + o Adoption of BFD IO loop for general use + o Parallel Pipe protocol + o Parallel RPKI protocol + o Parallel BGP protocol + o Lots of refactoring + o Bugfixes and improvements as they came along + + Version 2.15.1 (2024-03-22) o OSPF: Fix regression in handling PtP links o RPKI: Handle connection resets properly diff --git a/aclocal.m4 b/aclocal.m4 index 3fdc446f..ffe67706 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -1,5 +1,32 @@ dnl ** Additional Autoconf tests for BIRD configure script dnl ** (c) 1999 Martin Mares +dnl ** (c) 2021 Maria Matejka + +AC_DEFUN([BIRD_CHECK_POINTER_ALIGNMENT], +[ + AC_CACHE_CHECK( + [how pointers are aligned], + [bird_cv_pointer_alignment], + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM( + [ + _Static_assert(_Alignof(void *) == 8, "bad"); + ], [] + ) + ], + [bird_cv_pointer_alignment=8], + AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM( + [ + _Static_assert(_Alignof(void *) == 4, "bad"); + ], [] + ) + ], + [bird_cv_pointer_alignment=4], + [bird_cv_pointer_alignment=unknown] + )) + ) +]) AC_DEFUN([BIRD_CHECK_THREAD_LOCAL], [ @@ -9,14 +36,23 @@ AC_DEFUN([BIRD_CHECK_THREAD_LOCAL], AC_COMPILE_IFELSE([ AC_LANG_PROGRAM( [ - _Thread_local static int x = 42; + static _Thread_local int x = 42; ], [] ) ], [bird_cv_thread_local=yes], + [AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM( + [ + static __thread int x = 42; + ], + [] + ) + ], + [bird_cv_thread_local=__thread], [bird_cv_thread_local=no] - ) + )]) ) ]) diff --git a/bird-gdb.py b/bird-gdb.py index 262035dc..b277cb0a 100644 --- a/bird-gdb.py +++ b/bird-gdb.py @@ -4,9 +4,10 @@ class BIRDPrinter: @classmethod def lookup(cls, val): - if val.type.code != cls.typeCode: + t = val.type.strip_typedefs() + if t.code != cls.typeCode: return None - if val.type.tag != cls.typeTag: + if t.tag != cls.typeTag: return None return cls(val) @@ -25,7 +26,6 @@ class BIRDFValPrinter(BIRDPrinter): "T_ENUM_RTS": "i", "T_ENUM_BGP_ORIGIN": "i", "T_ENUM_SCOPE": "i", - "T_ENUM_RTC": "i", "T_ENUM_RTD": "i", "T_ENUM_ROA": "i", "T_ENUM_NETTYPE": "i", @@ -124,7 +124,7 @@ class BIRDFLinePrinter(BIRDPrinter): "n": n, "code": str(self.val['items'][n]['fi_code']), } if n % 8 == 0 else str(self.val['items'][n]['fi_code']) for n in range(cnt)])) - + class BIRDFExecStackPrinter(BIRDPrinter): "Print BIRD's struct f_exec_stack" @@ -142,6 +142,317 @@ class BIRDFExecStackPrinter(BIRDPrinter): "n": n } for n in range(cnt-1, -1, -1) ]) + +class BIRD: + def skip_back(t, i, v): + if isinstance(t, str): + t = gdb.lookup_type(t) + elif isinstance(t, gdb.Value): + t = gdb.lookup_type(t.string()) + elif not isinstance(t, gdb.Type): + raise Exception(f"First argument of skip_back(t, i, v) must be a type, got {type(t)}") + + t = t.strip_typedefs() + nullptr = gdb.Value(0).cast(t.pointer()) + + if isinstance(i, gdb.Value): + i = i.string() + elif not isinstance(i, str): + raise Exception(f"Second argument of skip_back(t, i, v) must be a item name, got {type(i)}") + + if not isinstance(v, gdb.Value): + raise Exception(f"Third argument of skip_back(t, i, v) must be a value, got {type(v)}") + if v.type.code != gdb.TYPE_CODE_PTR and v.type.code != gdb.TYPE_CODE_REF: + raise Exception(f"Third argument of skip_back(t, i, v) must be a pointer, is {v.type} ({v.type.code})") + if v.type.target().strip_typedefs() != nullptr[i].type: + raise Exception(f"Third argument of skip_back(t, i, v) points to type {v.type.target().strip_typedefs()}, should be {nullptr[i].type}") + + uintptr_t = gdb.lookup_type("uintptr_t") + taddr = v.dereference().address.cast(uintptr_t) - nullptr[i].address.cast(uintptr_t) + return gdb.Value(taddr).cast(t.pointer()) + + class skip_back_gdb(gdb.Function): + "Given address of a structure item, returns address of the structure, as the SKIP_BACK macro does" + def __init__(self): + gdb.Function.__init__(self, "SKIP_BACK") + + def invoke(self, t, i, v): + return BIRD.skip_back(t, i, v) + + +BIRD.skip_back_gdb() + + +class BIRDList: + def __init__(self, val): + ltype = val.type.strip_typedefs() + if ltype.code != gdb.TYPE_CODE_UNION or ltype.tag != "list": + raise Exception(f"Not a list, is type {ltype}") + + self.head = val["head"] + self.tail_node = val["tail_node"] + + if str(self.head.address) == '0x0': + raise Exception("List head is NULL") + + if str(self.tail_node["prev"].address) == '0x0': + raise Exception("List tail is NULL") + + def walk(self, do): + cur = self.head + while cur.dereference() != self.tail_node: + do(cur) + cur = cur.dereference()["next"] + + +class BIRDListLength(gdb.Function): + """Returns length of the list, as in + print $list_length(routing_tables)""" + def __init__(self): + super(BIRDListLength, self).__init__("list_length") + + def count(self, _): + self.cnt += 1 + + def invoke(self, l): + self.cnt = 0 + BIRDList(l).walk(self.count) + return self.cnt + +BIRDListLength() + +class BIRDListItem(gdb.Function): + """Returns n-th item of the list.""" + def __init__(self): + super(BIRDListItem, self).__init__("list_item") + + class BLException(Exception): + def __init__(self, node, msg): + Exception.__init__(self, msg) + self.node = node + + def count(self, node): + if self.cnt == self.pos: + raise self.BLException(node, "Node found") + + self.cnt += 1 + + def invoke(self, l, n, t=None, item="n"): + self.cnt = 0 + self.pos = n + bl = BIRDList(l) + try: + bl.walk(self.count) + except self.BLException as e: + if t is None: + return e.node + else: + return BIRD.skip_back(t, item, e.node) + + raise Exception("List too short") + +BIRDListItem() + +class BIRDResourceSize(): + def __init__(self, netto, overhead, free): + self.netto = netto + self.overhead = overhead + self.free = free + + def __str__(self): + ns = str(self.netto) + os = str(self.overhead) + fs = str(self.free) + + return "{: >12s} | {: >12s} | {: >12s}".format(ns, os, fs) + + def __add__(self, val): + return BIRDResourceSize(self.netto + val.netto, self.overhead + val.overhead, self.free + val.free) + +class BIRDResource(): + def __init__(self, val): + self.val = val + + def __str__(self): + return f"Item {self.val.address} of class \"{self.val['class']['name'].string()}\"" + + def memsize(self): + if str(self.val["class"]["memsize"]) == '0x0': + size = self.val["class"]["size"] + ressize = gdb.lookup_type("struct resource").sizeof + return BIRDResourceSize(size - ressize, ressize, 0) + else: + raise Exception(f"Resource class {self.val['class']['name']} with defined memsize() not known by Python") + + def parse(self): + pass + +class BIRDMBResource(BIRDResource): + def __init__(self, val): + self.mbtype = gdb.lookup_type("struct mblock") + self.val = val.cast(self.mbtype) + + def memsize(self): + return BIRDResourceSize(self.val["size"], 8 + self.mbtype.sizeof, 0) + + def __str__(self): + return f"Standalone memory block {self.val.address} of size {self.val['size']}, data at {self.val['data'].address}" + +class BIRDLinPoolResource(BIRDResource): + def __init__(self, val): + self.lptype = gdb.lookup_type("struct linpool") + self.val = val.cast(self.lptype) + self.info = None + + def count_chunk(self, which): + cnt = 0 + chunk = self.val[which] + while str(chunk) != '0x0': + cnt += 1 + chunk = chunk.dereference()["next"] + return cnt + + def parse(self): + self.info = { + "std_chunks": self.count_chunk("first"), + "large_chunks": self.count_chunk("first_large"), + } + + def memsize(self): + if self.info is None: + self.parse() + + overhead = (8 - 8*self.val["use_pages"]) + gdb.lookup_type("struct lp_chunk").sizeof + return BIRDResourceSize( + self.val["total"] + self.val["total_large"], + (self.info["std_chunks"] + self.info["large_chunks"]) * overhead, + 0) + + def __str__(self): + if self.info is None: + self.parse() + + return f"Linpool {self.val.address} with {self.info['std_chunks']} standard chunks of size {self.val['chunk_size']} and {self.info['large_chunks']} large chunks" + +class BIRDSlabResource(BIRDResource): + def __init__(self, val): + self.slabtype = gdb.lookup_type("struct slab") + self.val = val.cast(self.slabtype) + self.info = None + + def count_heads_item(self, item): + self.hcnt += 1 + self.used += item.dereference().cast(self.slheadtype)["num_full"] + + def count_heads(self, which): + self.hcnt = 0 + self.used = 0 + BIRDList(self.val[which + "_heads"]).walk(self.count_heads_item) + self.info[which + "_heads"] = self.hcnt + self.info[which + "_used"] = self.used + return (self.hcnt, self.used) + + def parse(self): + self.page_size = gdb.lookup_symbol("page_size")[0].value() + self.slheadtype = gdb.lookup_type("struct sl_head") + self.info = {} + self.count_heads("empty") + self.count_heads("partial") + self.count_heads("full") + + def memsize(self): + if self.info is None: + self.parse() + + total_used = self.info["empty_used"] + self.info["partial_used"] + self.info["full_used"] + total_heads = self.info["empty_heads"] + self.info["partial_heads"] + self.info["full_heads"] + + eff_size = total_used * self.val["obj_size"] + free_size = self.info["empty_heads"] * self.page_size + total_size = total_heads * self.page_size + self.slabtype.sizeof + + return BIRDResourceSize( eff_size, total_size - free_size - eff_size, free_size) + + def __str__(self): + if self.info is None: + self.parse() + + return f"Slab {self.val.address} " + ", ".join([ + f"{self.info[x + '_heads']} {x} heads" for x in [ "empty", "partial", "full" ]]) + \ + f", {self.val['objs_per_slab']} objects of size {self.val['obj_size']} per head" + + +class BIRDPoolResource(BIRDResource): + def __init__(self, val): + self.pooltype = gdb.lookup_type("struct pool") + self.resptrtype = gdb.lookup_type("struct resource").pointer() + self.page_size = gdb.lookup_symbol("page_size")[0].value() + self.val = val.cast(self.pooltype) + self.items = None + + def parse_inside(self, val): + self.items.append(BIRDNewResource(val.cast(self.resptrtype).dereference())) + + def parse(self): + self.items = [] + BIRDList(self.val["inside"]).walk(self.parse_inside) + + def memsize(self): + if self.items is None: + self.parse() + + sum = BIRDResourceSize(0, self.pooltype.sizeof, 0) +# for i in self.items: +# sum += i.memsize() + + return sum + + def __str__(self): + if self.items is None: + self.parse() + +# for i in self.items: +# print(i) + + return f"Resource pool {self.val.address} \"{self.val['name'].string()}\" containing {len(self.items)} items" + +BIRDResourceMap = { + "mbl_memsize": BIRDMBResource, + "pool_memsize": BIRDPoolResource, + "lp_memsize": BIRDLinPoolResource, + "slab_memsize": BIRDSlabResource, + } + +def BIRDNewResource(res): + cms = res["class"].dereference()["memsize"] + for cx in BIRDResourceMap: + if cms == gdb.lookup_symbol(cx)[0].value(): + return BIRDResourceMap[cx](res) + + return BIRDResource(res) + + +class BIRDResourcePrinter(BIRDPrinter): + "Print BIRD's resource" + typeCode = gdb.TYPE_CODE_STRUCT + typeTag = "resource" + + def __init__(self, val): + super(BIRDResourcePrinter, self).__init__(val) + self.resource = BIRDNewResource(val) + self.resource.parse() + self.resourcetype = gdb.lookup_type("struct resource") + + if type(self.resource) == BIRDPoolResource: + self.children = self.pool_children + + def pool_children(self): + return iter([ ("\n", i.val.cast(self.resourcetype)) for i in self.resource.items ]) + + def to_string(self): + return f"[ {str(self.resource.memsize())} ] {str(self.resource)}" + + def register_printers(objfile): objfile.pretty_printers.append(BIRDFInstPrinter.lookup) objfile.pretty_printers.append(BIRDFValPrinter.lookup) @@ -149,6 +460,7 @@ def register_printers(objfile): objfile.pretty_printers.append(BIRDFLineItemPrinter.lookup) objfile.pretty_printers.append(BIRDFLinePrinter.lookup) objfile.pretty_printers.append(BIRDFExecStackPrinter.lookup) + objfile.pretty_printers.append(BIRDResourcePrinter.lookup) register_printers(gdb.current_objfile()) diff --git a/conf/cf-lex.l b/conf/cf-lex.l index 2f95f2e1..b7ecfb7b 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -73,9 +73,18 @@ static uint cf_hash(const byte *c); HASH_DEFINE_REHASH_FN(SYM, struct symbol) -struct sym_scope *global_root_scope; +/* Global symbol scopes */ pool *global_root_scope_pool; linpool *global_root_scope_linpool; +struct sym_scope + global_root_scope = { + }, + global_filter_scope = { + .next = &global_root_scope, + }; + +/* Local symbol scope: TODO this isn't thread-safe */ +struct sym_scope *conf_this_scope; linpool *cfg_mem; @@ -323,7 +332,7 @@ else: { return DDOT; } -[={}:;,.()+*/%<>~\[\]?!\|-] { +[={}:;,.()+*/%<>~\[\]?!\|&-] { return yytext[0]; } @@ -567,7 +576,7 @@ cf_new_symbol(struct sym_scope *scope, pool *p, struct linpool *lp, const byte * 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 (!scope->hash.data) HASH_INIT(scope->hash, p, SYM_ORDER); @@ -580,6 +589,31 @@ cf_new_symbol(struct sym_scope *scope, pool *p, struct linpool *lp, const byte * return s; } +struct symbol * +cf_root_symbol(const byte *c, struct sym_scope *ss) +{ + uint l = strlen(c); + if (l > SYM_MAX_LEN) + bug("Root symbol %s too long", c); + + if (!global_root_scope_pool) + { + global_root_scope_pool = rp_new(&root_pool, the_bird_domain.the_bird, "Keywords pool"); + global_root_scope_linpool = lp_new(global_root_scope_pool); + } + + struct symbol *s = lp_alloc(global_root_scope_linpool, sizeof(struct symbol) + l + 1); + *s = (struct symbol) { .scope = ss, .class = SYM_VOID, }; + memcpy(s->name, c, l+1); + + if (!ss->hash.data) + HASH_INIT(ss->hash, &root_pool, SYM_ORDER); + + HASH_INSERT2(ss->hash, SYM, &root_pool, s); + return s; +} + + /** * cf_find_symbol_scope - find a symbol by name * @scope: config scope @@ -598,7 +632,8 @@ cf_find_symbol_scope(const struct sym_scope *scope, const byte *c) /* Find the symbol here or anywhere below */ while (scope) - if (scope->hash.data && (s = HASH_FIND(scope->hash, SYM, c))) + if (((scope != &global_filter_scope) || !new_config || new_config->allow_attributes) && + scope->hash.data && (s = HASH_FIND(scope->hash, SYM, c))) return s; else scope = scope->next; @@ -691,6 +726,33 @@ cf_lex_symbol(const char *data) } } +void +ea_lex_register(struct ea_class *def) +{ + def->sym = cf_root_symbol(def->name, &global_filter_scope); + def->sym->class = SYM_ATTRIBUTE; + def->sym->attribute = def; +} + +#if 0 +/* When we start to support complete protocol removal, we may need this function */ +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; +} +#endif + +struct ea_class * +ea_class_find_by_name(const char *name) +{ + struct symbol *sym = cf_find_symbol_scope(config ? config->root_scope : &global_filter_scope, name); + return sym && (sym->class == SYM_ATTRIBUTE) ? sym->attribute : NULL; +} + void f_type_methods_register(void); /** @@ -704,20 +766,17 @@ void f_type_methods_register(void); void cf_lex_init(int is_cli, struct config *c) { - if (!global_root_scope_pool) + if (!global_root_scope.readonly) { - global_root_scope_pool = rp_new(&root_pool, "Keywords pool"); - global_root_scope_linpool = lp_new(global_root_scope_pool); - global_root_scope = lp_allocz(global_root_scope_linpool, sizeof(*global_root_scope)); - for (const struct keyword *k = keyword_list; k->name; k++) { - struct symbol *sym = cf_new_symbol(global_root_scope, global_root_scope_pool, global_root_scope_linpool, 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; } - global_root_scope->readonly = 1; + global_root_scope.readonly = 1; + global_filter_scope.readonly = 1; f_type_methods_register(); } @@ -739,12 +798,11 @@ cf_lex_init(int is_cli, struct config *c) BEGIN(INITIAL); c->root_scope = c->current_scope = cfg_allocz(sizeof(struct sym_scope)); - c->root_scope->active = 1; if (is_cli) c->current_scope->next = config->root_scope; else - c->current_scope->next = global_root_scope; + c->current_scope->next = &global_filter_scope; } /** @@ -764,7 +822,6 @@ cf_push_scope(struct config *conf, struct symbol *sym) s->next = conf->current_scope; conf->current_scope = s; - s->active = 1; s->name = sym; s->slots = 0; } @@ -780,10 +837,7 @@ void cf_pop_scope(struct config *conf) { ASSERT(!conf->current_scope->soft_scopes); - - conf->current_scope->active = 0; conf->current_scope = conf->current_scope->next; - ASSERT(conf->current_scope); } @@ -833,6 +887,41 @@ cf_swap_soft_scope(struct config *conf) } } +/** + * cf_enter_filters - enable filter / route attributes namespace + */ +void +cf_enter_filters(void) +{ + ASSERT_DIE(!cf_maybe_enter_filters()); +} + +int +cf_maybe_enter_filters(void) +{ + int o = new_config->allow_attributes; + new_config->allow_attributes = 1; + return o; +} + +/** + * cf_exit_filters - disable filter / route attributes namespace + */ +void +cf_exit_filters(void) +{ + ASSERT_DIE(cf_maybe_exit_filters()); +} + +int +cf_maybe_exit_filters(void) +{ + int o = new_config->allow_attributes; + new_config->allow_attributes = 0; + return o; +} + + /** * cf_symbol_class_name - get name of a symbol class * @sym: symbol @@ -863,6 +952,8 @@ cf_symbol_class_name(struct symbol *sym) return "MPLS domain"; case SYM_MPLS_RANGE: return "MPLS label range"; + case SYM_KEYWORD: + return "symbol"; case SYM_CONSTANT_RANGE: return "constant"; case SYM_VARIABLE_RANGE: diff --git a/conf/conf.c b/conf/conf.c index d98d421c..c5ce6f5a 100644 --- a/conf/conf.c +++ b/conf/conf.c @@ -61,7 +61,8 @@ static jmp_buf conf_jmpbuf; -struct config *config, *new_config; +struct config *config; +_Thread_local struct config *new_config; pool *config_pool; static struct config *old_config; /* Old configuration */ @@ -71,7 +72,7 @@ static int future_cftype; /* Type of scheduled transition, may also be RECONFIG /* Note that when future_cftype is RECONFIG_UNDO, then future_config is NULL, therefore proper check for future scheduled config checks future_cftype */ -static event *config_event; /* Event for finalizing reconfiguration */ +static void config_done(void *cf); static timer *config_timer; /* Timer for scheduled configuration rollback */ /* These are public just for cmd_show_status(), should not be accessed elsewhere */ @@ -91,7 +92,7 @@ int undo_available; /* Undo was not requested from last reconfiguration */ struct config * config_alloc(const char *name) { - pool *p = rp_new(config_pool, "Config"); + pool *p = rp_new(config_pool, the_bird_domain.the_bird, "Config"); linpool *l = lp_new_default(p); struct config *c = lp_allocz(l, sizeof(struct config)); @@ -102,7 +103,6 @@ config_alloc(const char *name) init_list(&c->tests); init_list(&c->symbols); - c->mrtdump_file = -1; /* Hack, this should be sysdep-specific */ c->pool = p; c->mem = l; c->file_name = ndup; @@ -111,6 +111,8 @@ config_alloc(const char *name) c->tf_base = c->tf_log = TM_ISO_LONG_MS; c->gr_wait = DEFAULT_GR_WAIT; + c->done_event = (event) { .hook = config_done, .data = c, }; + return c; } @@ -202,7 +204,7 @@ config_free(struct config *c) ASSERT(!c->obstacle_count); - rfree(c->pool); + rp_free(c->pool); } /** @@ -230,29 +232,20 @@ void config_add_obstacle(struct config *c) { DBG("+++ adding obstacle %d\n", c->obstacle_count); - c->obstacle_count++; + atomic_fetch_add_explicit(&c->obstacle_count, 1, memory_order_acq_rel); } void config_del_obstacle(struct config *c) { DBG("+++ deleting obstacle %d\n", c->obstacle_count); - c->obstacle_count--; - if (!c->obstacle_count && (c != config)) - ev_schedule(config_event); + if (atomic_fetch_sub_explicit(&c->obstacle_count, 1, memory_order_acq_rel) == 1) + ev_send_loop(&main_birdloop, &c->done_event); } static int global_commit(struct config *new, struct config *old) { - if (!new->hostname) - { - new->hostname = get_hostname(new->mem); - - if (!new->hostname) - log(L_WARN "Cannot determine hostname"); - } - if (!old) return 0; @@ -288,6 +281,14 @@ config_do_commit(struct config *c, int type) old_cftype = type; config = c; + if (!c->hostname) + { + c->hostname = get_hostname(c->mem); + + if (!c->hostname) + log(L_WARN "Cannot determine hostname"); + } + configuring = 1; if (old_config && !config->shutdown) log(L_INFO "Reconfiguring"); @@ -316,8 +317,11 @@ config_do_commit(struct config *c, int type) } static void -config_done(void *unused UNUSED) +config_done(void *cf) { + if (cf == config) + return; + if (config->shutdown) sysdep_shutdown_done(); @@ -518,10 +522,7 @@ config_timeout(timer *t UNUSED) void config_init(void) { - config_pool = rp_new(&root_pool, "Configurations"); - - config_event = ev_new(config_pool); - config_event->hook = config_done; + config_pool = rp_new(&root_pool, the_bird_domain.the_bird, "Configurations"); config_timer = tm_new(config_pool); config_timer->hook = config_timeout; diff --git a/conf/conf.h b/conf/conf.h index c0a897fc..ea4aac35 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -26,9 +26,9 @@ struct config { list tests; /* Configured unit tests (f_bt_test_suite) */ list symbols; /* Configured symbols in config order */ - int mrtdump_file; /* Configured MRTDump file (sysdep, fd in unix) */ + struct rfile *mrtdump_file; /* Configured MRTDump file */ const char *syslog_name; /* Name used for syslog (NULL -> no syslog) */ - struct rtable_config *def_tables[NET_MAX]; /* Default routing tables for each network */ + struct symbol *def_tables[NET_MAX]; /* Default routing tables for each network */ struct iface_patt *router_id_from; /* Configured list of router ID iface patterns */ u32 router_id; /* Our Router ID */ @@ -36,6 +36,7 @@ struct config { u32 proto_default_mrtdump; /* Default protocol mrtdump mask */ u32 channel_default_debug; /* Default channel debug mask */ u32 table_default_debug; /* Default table debug mask */ + u16 filter_vstk, filter_estk; /* Filter stack depth */ struct timeformat tf_route; /* Time format for 'show route' */ struct timeformat tf_proto; /* Time format for 'show protocol' */ struct timeformat tf_log; /* Time format for the logfile */ @@ -54,10 +55,13 @@ 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 */ + int allow_attributes; /* Allow attributes in the current state of configuration parsing */ + _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 */ @@ -65,7 +69,7 @@ struct config { /* Please don't use these variables in protocols. Use proto_config->global instead. */ extern struct config *config; /* Currently active configuration */ -extern struct config *new_config; /* Configuration being parsed */ +extern _Thread_local struct config *new_config; /* Configuration being parsed */ struct config *config_alloc(const char *name); int config_parse(struct config *); @@ -129,7 +133,7 @@ struct symbol { const struct f_line *function; /* For SYM_FUNCTION */ const struct filter *filter; /* For SYM_FILTER */ struct rtable_config *table; /* For SYM_TABLE */ - struct f_dynamic_attr *attribute; /* For SYM_ATTRIBUTE */ + struct ea_class *attribute; /* For SYM_ATTRIBUTE */ struct mpls_domain_config *mpls_domain; /* For SYM_MPLS_DOMAIN */ struct mpls_range_config *mpls_range; /* For SYM_MPLS_RANGE */ struct f_val *val; /* For SYM_CONSTANT */ @@ -149,12 +153,15 @@ struct sym_scope { uint slots; /* Variable slots */ byte soft_scopes; /* Number of soft scopes above */ - byte active:1; /* Currently entered */ byte block:1; /* No independent stack frame */ byte readonly:1; /* Do not add new symbols */ }; -extern struct sym_scope *global_root_scope; +void cf_enter_filters(void); +void cf_exit_filters(void); +int cf_maybe_enter_filters(void); +int cf_maybe_exit_filters(void); + extern pool *global_root_scope_pool; extern linpool *global_root_scope_linpool; @@ -222,6 +229,7 @@ static inline int cf_symbol_is_local(struct config *conf, struct symbol *sym) /* internal */ struct symbol *cf_new_symbol(struct sym_scope *scope, pool *p, struct linpool *lp, const byte *c); +struct symbol *cf_root_symbol(const byte *, struct sym_scope *); /** * cf_define_symbol - define meaning of a symbol @@ -244,9 +252,6 @@ struct symbol *cf_new_symbol(struct sym_scope *scope, pool *p, struct linpool *l sym_->var_ = def_; \ sym_; }) -#define cf_create_symbol(conf_, name_, type_, var_, def_) \ - cf_define_symbol(conf_, cf_get_symbol(conf_, name_), type_, var_, def_) - void cf_push_scope(struct config *, struct symbol *); void cf_pop_scope(struct config *); void cf_push_soft_scope(struct config *); diff --git a/conf/confbase.Y b/conf/confbase.Y index b29abf4c..3a16cdbb 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -14,6 +14,7 @@ CF_HDR #include "conf/conf.h" #include "lib/resource.h" #include "lib/socket.h" +#include "lib/settle.h" #include "lib/timer.h" #include "lib/string.h" #include "nest/protocol.h" @@ -27,6 +28,8 @@ CF_HDR CF_DEFINES +static _Bool this_sadr_from_hack_active; + static void check_u16(uint val) { @@ -63,7 +66,6 @@ CF_DECLS net_addr net; net_addr *net_ptr; struct symbol *s; - struct keyword *kw; const char *t; struct rtable_config *r; struct channel_config *cc; @@ -74,14 +76,16 @@ CF_DECLS } xp; enum filter_return fret; enum ec_subtype ecs; - struct f_dynamic_attr fda; + struct ea_class *ea_class; struct f_static_attr fsa; + struct f_attr_bit fab; struct f_lval flv; struct f_line *fl; struct f_arg *fa; const struct filter *f; struct f_tree *e; struct f_trie *trie; + const struct f_trie *const_trie; struct f_val v; struct password_item *p; struct rt_show_data *ra; @@ -98,7 +102,8 @@ CF_DECLS struct table_spec ts; struct channel_limit cl; struct timeformat *tf; - mpls_label_stack *mls; + struct settle_config settle; + struct adata *ad; const struct adata *bs; struct aggr_item_node *ai; struct logging_rate_targets *lrt; @@ -120,14 +125,15 @@ CF_DECLS %type expr bool pxlen4 %type