summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaria Matejka <mq@ucw.cz>2022-05-30 15:31:19 +0200
committerMaria Matejka <mq@ucw.cz>2022-05-30 15:31:19 +0200
commitd7b077f5d63625beaca1bcfe971e3b853dbfcc06 (patch)
tree7d0e8d62cca65ae2dd3d5e6231657f1e43630b5a
parentd024f471ea5239a8cb6ce2ccd83b686a1d438aa5 (diff)
parent4a23ede2b056a41456790cc20a0c3d92a7137693 (diff)
Merge commit '4a23ede2b056a41456790cc20a0c3d92a7137693' into haugesund
-rw-r--r--Makefile.in10
-rw-r--r--filter/f-inst.c24
-rw-r--r--lib/slab.c107
-rw-r--r--nest/Makefile7
-rw-r--r--nest/a-path.c4
-rw-r--r--nest/proto.c45
-rw-r--r--nest/protocol.h4
-rw-r--r--nest/route.h57
-rw-r--r--nest/rt-attr.c22
-rw-r--r--nest/rt-dev.c6
-rw-r--r--proto/babel/Makefile1
-rw-r--r--proto/babel/babel.c6
-rw-r--r--proto/bfd/Makefile3
-rw-r--r--proto/bfd/bfd.c17
-rw-r--r--proto/bgp/Makefile3
-rw-r--r--proto/bgp/attrs.c8
-rw-r--r--proto/bgp/bgp.c5
-rw-r--r--proto/bgp/bgp.h4
-rw-r--r--proto/bgp/packets.c2
-rw-r--r--proto/mrt/Makefile3
-rw-r--r--proto/mrt/mrt.c6
-rw-r--r--proto/ospf/Makefile3
-rw-r--r--proto/ospf/ospf.c6
-rw-r--r--proto/perf/Makefile1
-rw-r--r--proto/perf/perf.c6
-rw-r--r--proto/pipe/Makefile3
-rw-r--r--proto/pipe/pipe.c6
-rw-r--r--proto/radv/Makefile3
-rw-r--r--proto/radv/radv.c6
-rw-r--r--proto/rip/Makefile3
-rw-r--r--proto/rip/rip.c6
-rw-r--r--proto/rpki/Makefile3
-rw-r--r--proto/rpki/rpki.c6
-rw-r--r--proto/static/Makefile3
-rw-r--r--proto/static/static.c6
-rw-r--r--sysdep/unix/Makefile2
-rw-r--r--sysdep/unix/krt.c13
-rw-r--r--sysdep/unix/main.c2
-rw-r--r--test/bt-utils.c2
39 files changed, 256 insertions, 168 deletions
diff --git a/Makefile.in b/Makefile.in
index e0ff4a1d..0d55807b 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -82,6 +82,9 @@ conf-lex-targets := $(addprefix $(objdir)/conf/,cf-lex.o)
conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h)
cf-local = $(conf-y-targets): $(s)config.Y
+# nest/Makefile declarations needed for all other modules
+proto-build-c := $(addprefix $(objdir)/nest/,proto-build.c)
+
src-o-files = $(patsubst %.c,$(o)%.o,$(src))
tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
@@ -95,6 +98,13 @@ else
o = $(patsubst $(srcdir)%,$(objdir)%,$(s))
endif
+define proto-build_in =
+PROTO_BUILD += $(1)
+$(proto-build-c): $(lastword $(MAKEFILE_LIST))
+endef
+
+proto-build = $(eval $(call proto-build_in,$(1)))
+
define clean_in =
clean::
rm -f $(addprefix $(o),$(1))
diff --git a/filter/f-inst.c b/filter/f-inst.c
index 532c6989..eb75ac62 100644
--- a/filter/f-inst.c
+++ b/filter/f-inst.c
@@ -714,9 +714,6 @@
case EAF_TYPE_LC_SET:
RESULT_(T_LCLIST, ad, e->u.ptr);
break;
- case EAF_TYPE_UNDEF:
- RESULT_VOID;
- break;
default:
bug("Unknown dynamic attribute type");
}
@@ -737,7 +734,9 @@
l->count = 1;
l->attrs[0].id = da.ea_code;
l->attrs[0].flags = 0;
- l->attrs[0].type = da.type | EAF_ORIGINATED | EAF_FRESH;
+ l->attrs[0].type = da.type;
+ l->attrs[0].originated = 1;
+ l->attrs[0].fresh = 1;
switch (da.type) {
case EAF_TYPE_INT:
@@ -792,21 +791,8 @@
ACCESS_RTE;
ACCESS_EATTRS;
- {
- struct ea_list *l = lp_alloc(fs->pool, sizeof(struct ea_list) + sizeof(eattr));
-
- l->next = NULL;
- l->flags = EALF_SORTED;
- l->count = 1;
- l->attrs[0].id = da.ea_code;
- l->attrs[0].flags = 0;
- l->attrs[0].type = EAF_TYPE_UNDEF | EAF_ORIGINATED | EAF_FRESH;
- l->attrs[0].u.data = 0;
-
- f_rta_cow(fs);
- l->next = *fs->eattrs;
- *fs->eattrs = l;
- }
+ f_rta_cow(fs);
+ ea_unset_attr(fs->eattrs, fs->pool, 1, da.ea_code);
}
INST(FI_LENGTH, 1, 1) { /* Get length of */
diff --git a/lib/slab.c b/lib/slab.c
index 6da602f8..38d10626 100644
--- a/lib/slab.c
+++ b/lib/slab.c
@@ -32,6 +32,7 @@
#include "nest/bird.h"
#include "lib/resource.h"
#include "lib/string.h"
+#include "lib/tlists.h"
#undef FAKE_SLAB /* Turn on if you want to debug memory allocations */
@@ -153,11 +154,38 @@ slab_memsize(resource *r)
#define MAX_EMPTY_HEADS 1
+enum sl_head_state {
+ slh_empty = 2,
+ slh_partial = 0,
+ slh_full = 1,
+} PACKED;
+
+struct sl_head {
+ struct slab *slab;
+ TLIST_NODE(sl_head, struct sl_head) n;
+ u16 num_full;
+ enum sl_head_state state;
+ u32 used_bits[0];
+};
+
+struct sl_alignment { /* Magic structure for testing of alignment */
+ byte data;
+ int x[0];
+};
+
+#define TLIST_PREFIX sl_head
+#define TLIST_TYPE struct sl_head
+#define TLIST_ITEM n
+#define TLIST_WANT_WALK
+#define TLIST_WANT_ADD_HEAD
+
+#include "lib/tlists.h"
+
struct slab {
resource r;
uint obj_size, head_size, head_bitfield_len;
uint objs_per_slab, num_empty_heads, data_size;
- list empty_heads, partial_heads, full_heads;
+ struct sl_head_list empty_heads, partial_heads, full_heads;
};
static struct resclass sl_class = {
@@ -169,19 +197,15 @@ static struct resclass sl_class = {
slab_memsize
};
-struct sl_head {
- struct slab *slab;
- node n;
- u32 num_full;
- u32 used_bits[0];
-};
+#define SL_GET_HEAD(x) ((struct sl_head *) (((uintptr_t) (x)) & ~(page_size-1)))
-struct sl_alignment { /* Magic structure for testing of alignment */
- byte data;
- int x[0];
-};
+#define SL_HEAD_CHANGE_STATE(_s, _h, _from, _to) ({ \
+ ASSERT_DIE(_h->state == slh_##_from); \
+ sl_head_rem_node(&_s->_from##_heads, _h); \
+ sl_head_add_head(&_s->_to##_heads, _h); \
+ _h->state = slh_##_to; \
+ })
-#define SL_GET_HEAD(x) ((struct sl_head *) (((uintptr_t) (x)) & ~(page_size-1)))
/**
* sl_new - create a new Slab
@@ -218,9 +242,6 @@ sl_new(pool *p, uint size)
bug("Slab: object too large");
s->num_empty_heads = 0;
- init_list(&s->empty_heads);
- init_list(&s->partial_heads);
- init_list(&s->full_heads);
return s;
}
@@ -237,8 +258,7 @@ sl_alloc(slab *s)
struct sl_head *h;
redo:
- h = SKIP_BACK(struct sl_head, n, HEAD(s->partial_heads));
- if (!h->n.next)
+ if (!(h = s->partial_heads.first))
goto no_partial;
okay:
for (uint i=0; i<s->head_bitfield_len; i++)
@@ -258,16 +278,13 @@ okay:
return out;
}
- rem_node(&h->n);
- add_tail(&s->full_heads, &h->n);
+ SL_HEAD_CHANGE_STATE(s, h, partial, full);
goto redo;
no_partial:
- h = SKIP_BACK(struct sl_head, n, HEAD(s->empty_heads));
- if (h->n.next)
+ if (h = s->empty_heads.first)
{
- rem_node(&h->n);
- add_head(&s->partial_heads, &h->n);
+ SL_HEAD_CHANGE_STATE(s, h, empty, partial);
s->num_empty_heads--;
goto okay;
}
@@ -281,7 +298,7 @@ no_partial:
memset(h, 0, s->head_size);
h->slab = s;
- add_head(&s->partial_heads, &h->n);
+ sl_head_add_head(&s->partial_heads, h);
goto okay;
}
@@ -326,14 +343,11 @@ sl_free(void *oo)
h->used_bits[pos / 32] &= ~(1 << (pos % 32));
- if (h->num_full-- == s->objs_per_slab)
- {
- rem_node(&h->n);
- add_head(&s->partial_heads, &h->n);
- }
+ if ((h->num_full-- == s->objs_per_slab) && (h->state == slh_full))
+ SL_HEAD_CHANGE_STATE(s, h, full, partial);
else if (!h->num_full)
{
- rem_node(&h->n);
+ sl_head_rem_node(&s->partial_heads, h);
if (s->num_empty_heads >= MAX_EMPTY_HEADS)
{
#ifdef POISON
@@ -343,7 +357,8 @@ sl_free(void *oo)
}
else
{
- add_head(&s->empty_heads, &h->n);
+ sl_head_add_head(&s->empty_heads, h);
+ h->state = slh_empty;
s->num_empty_heads++;
}
}
@@ -353,14 +368,12 @@ static void
slab_free(resource *r)
{
slab *s = (slab *) r;
- struct sl_head *h;
- node *nn, *nxt;
- WALK_LIST2_DELSAFE(h, nn, nxt, s->empty_heads, n)
+ WALK_TLIST_DELSAFE(sl_head, h, &s->empty_heads)
free_page(h);
- WALK_LIST2_DELSAFE(h, nn, nxt, s->partial_heads, n)
+ WALK_TLIST_DELSAFE(sl_head, h, &s->partial_heads)
free_page(h);
- WALK_LIST2_DELSAFE(h, nn, nxt, s->full_heads, n)
+ WALK_TLIST_DELSAFE(sl_head, h, &s->full_heads)
free_page(h);
}
@@ -369,14 +382,12 @@ slab_dump(resource *r)
{
slab *s = (slab *) r;
int ec=0, pc=0, fc=0;
- struct sl_head *h;
- node *nn;
- WALK_LIST2(h, nn, s->empty_heads, n)
+ WALK_TLIST(sl_head, h, &s->empty_heads)
ec++;
- WALK_LIST2(h, nn, s->partial_heads, n)
+ WALK_TLIST(sl_head, h, &s->partial_heads)
pc++;
- WALK_LIST2(h, nn, s->full_heads, n)
+ WALK_TLIST(sl_head, h, &s->full_heads)
fc++;
debug("(%de+%dp+%df blocks per %d objs per %d bytes)\n", ec, pc, fc, s->objs_per_slab, s->obj_size);
}
@@ -386,21 +397,19 @@ slab_memsize(resource *r)
{
slab *s = (slab *) r;
size_t heads = 0;
- struct sl_head *h;
- node *nn;
- WALK_LIST2(h, nn, s->full_heads, n)
+ WALK_TLIST(sl_head, h, &s->full_heads)
heads++;
size_t items = heads * s->objs_per_slab;
- WALK_LIST2(h, nn, s->partial_heads, n)
+ WALK_TLIST(sl_head, h, &s->partial_heads)
{
heads++;
items += h->num_full;
}
- WALK_LIST2(h, nn, s->empty_heads, n)
+ WALK_TLIST(sl_head, h, &s->empty_heads)
heads++;
size_t eff = items * s->data_size;
@@ -415,13 +424,11 @@ static resource *
slab_lookup(resource *r, unsigned long a)
{
slab *s = (slab *) r;
- struct sl_head *h;
- node *nn;
- WALK_LIST2(h, nn, s->partial_heads, n)
+ WALK_TLIST(sl_head, h, &s->partial_heads)
if ((unsigned long) h < a && (unsigned long) h + page_size < a)
return r;
- WALK_LIST2(h, nn, s->full_heads, n)
+ WALK_TLIST(sl_head, h, &s->full_heads)
if ((unsigned long) h < a && (unsigned long) h + page_size < a)
return r;
return NULL;
diff --git a/nest/Makefile b/nest/Makefile
index 884d3950..7d451ba4 100644
--- a/nest/Makefile
+++ b/nest/Makefile
@@ -1,7 +1,12 @@
-src := a-path.c a-set.c cli.c cmds.c iface.c locks.c neighbor.c password.c proto.c rt-attr.c rt-dev.c rt-fib.c rt-show.c rt-table.c
+src := a-path.c a-set.c cli.c cmds.c iface.c locks.c neighbor.c password.c proto.c proto-build.c rt-attr.c rt-dev.c rt-fib.c rt-show.c rt-table.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,dev_build)
+
+$(proto-build-c): $(lastword $(MAKEFILE_LIST))
+ $(E)echo GEN $@
+ $(Q)echo "$(patsubst %,void %(void); ,$(PROTO_BUILD)) void protos_build_gen(void) { $(patsubst %, %(); ,$(PROTO_BUILD))}" > $@
tests_src := a-set_test.c a-path_test.c
tests_targets := $(tests_targets) $(tests-target-files)
diff --git a/nest/a-path.c b/nest/a-path.c
index 2e34a3d1..badbc911 100644
--- a/nest/a-path.c
+++ b/nest/a-path.c
@@ -591,7 +591,7 @@ as_path_match_set(const struct adata *path, const struct f_tree *set)
p += 2;
for (i=0; i<n; i++)
{
- struct f_val v = {T_INT, .val.i = get_as(p)};
+ struct f_val v = { .type = T_INT, .val.i = get_as(p)};
if (find_tree(set, &v))
return 1;
p += BS;
@@ -631,7 +631,7 @@ as_path_filter(struct linpool *pool, const struct adata *path, const struct f_tr
if (set)
{
- struct f_val v = {T_INT, .val.i = as};
+ struct f_val v = { .type = T_INT, .val.i = as};
match = !!find_tree(set, &v);
}
else
diff --git a/nest/proto.c b/nest/proto.c
index 09582d2e..304451cb 100644
--- a/nest/proto.c
+++ b/nest/proto.c
@@ -23,9 +23,9 @@
#include "filter/f-inst.h"
pool *proto_pool;
-list proto_list;
+list STATIC_LIST_INIT(proto_list);
-static list protocol_list;
+static list STATIC_LIST_INIT(protocol_list);
struct protocol *class_to_protocol[PROTOCOL__MAX];
#define CD(c, msg, args...) ({ if (c->debug & D_STATES) log(L_TRACE "%s.%s: " msg, c->proto->name, c->name ?: "?", ## args); })
@@ -1757,6 +1757,8 @@ proto_build(struct protocol *p)
/* FIXME: convert this call to some protocol hook */
extern void bfd_init_all(void);
+void protos_build_gen(void);
+
/**
* protos_build - build a protocol list
*
@@ -1769,44 +1771,7 @@ extern void bfd_init_all(void);
void
protos_build(void)
{
- init_list(&proto_list);
- init_list(&protocol_list);
-
- proto_build(&proto_device);
-#ifdef CONFIG_RADV
- proto_build(&proto_radv);
-#endif
-#ifdef CONFIG_RIP
- proto_build(&proto_rip);
-#endif
-#ifdef CONFIG_STATIC
- proto_build(&proto_static);
-#endif
-#ifdef CONFIG_MRT
- proto_build(&proto_mrt);
-#endif
-#ifdef CONFIG_OSPF
- proto_build(&proto_ospf);
-#endif
-#ifdef CONFIG_PIPE
- proto_build(&proto_pipe);
-#endif
-#ifdef CONFIG_BGP
- proto_build(&proto_bgp);
-#endif
-#ifdef CONFIG_BFD
- proto_build(&proto_bfd);
- bfd_init_all();
-#endif
-#ifdef CONFIG_BABEL
- proto_build(&proto_babel);
-#endif
-#ifdef CONFIG_RPKI
- proto_build(&proto_rpki);
-#endif
-#ifdef CONFIG_PERF
- proto_build(&proto_perf);
-#endif
+ protos_build_gen();
proto_pool = rp_new(&root_pool, "Protocols");
proto_shutdown_timer = tm_new(proto_pool);
diff --git a/nest/protocol.h b/nest/protocol.h
index 7447cbf0..d813c91e 100644
--- a/nest/protocol.h
+++ b/nest/protocol.h
@@ -84,8 +84,8 @@ struct protocol {
void (*copy_config)(struct proto_config *, struct proto_config *); /* Copy config from given protocol instance */
};
-void protos_build(void);
-void proto_build(struct protocol *);
+void protos_build(void); /* Called from sysdep to initialize protocols */
+void proto_build(struct protocol *); /* Called from protocol to register itself */
void protos_preconfig(struct config *);
void protos_commit(struct config *new, struct config *old, int force_restart, int type);
struct proto * proto_spawn(struct proto_config *cf, uint disabled);
diff --git a/nest/route.h b/nest/route.h
index 1aba218b..61a5f623 100644
--- a/nest/route.h
+++ b/nest/route.h
@@ -664,7 +664,10 @@ static inline int rte_is_reachable(rte *r)
typedef struct eattr {
word id; /* EA_CODE(PROTOCOL_..., protocol-dependent ID) */
byte flags; /* Protocol-dependent flags */
- byte type; /* Attribute type and several flags (EAF_...) */
+ byte type:5; /* Attribute type */
+ byte originated:1; /* The attribute has originated locally */
+ byte fresh:1; /* An uncached attribute (e.g. modified in export filter) */
+ byte undef:1; /* Explicitly undefined */
union {
uintptr_t data;
const struct adata *ptr; /* Attribute data elsewhere */
@@ -700,11 +703,8 @@ const char *ea_custom_name(uint ea);
#define EAF_TYPE_PTR 0x0d /* Pointer to an object */
#define EAF_TYPE_EC_SET 0x0e /* Set of pairs of u32's - ext. community list */
#define EAF_TYPE_LC_SET 0x12 /* Set of triplets of u32's - large community list */
-#define EAF_TYPE_UNDEF 0x1f /* `force undefined' entry */
#define EAF_EMBEDDED 0x01 /* Data stored in eattr.u.data (part of type spec) */
#define EAF_VAR_LENGTH 0x02 /* Attribute length is variable (part of type spec) */
-#define EAF_ORIGINATED 0x20 /* The attribute has originated locally */
-#define EAF_FRESH 0x40 /* An uncached attribute (e.g. modified in export filter) */
typedef struct adata {
uint length; /* Length of data */
@@ -772,27 +772,50 @@ void ea_format_bitfield(const struct eattr *a, byte *buf, int bufsize, const cha
ea = NULL; \
} while(0) \
+struct ea_one_attr_list {
+ ea_list l;
+ eattr a;
+};
+
static inline eattr *
ea_set_attr(ea_list **to, struct linpool *pool, uint id, uint flags, uint type, uintptr_t val)
{
- ea_list *a = lp_alloc(pool, sizeof(ea_list) + sizeof(eattr));
- eattr *e = &a->attrs[0];
+ struct ea_one_attr_list *ea = lp_alloc(pool, sizeof(*ea));
+ *ea = (struct ea_one_attr_list) {
+ .l.flags = EALF_SORTED,
+ .l.count = 1,
+ .l.next = *to,
- a->flags = EALF_SORTED;
- a->count = 1;
- a->next = *to;
- *to = a;
-
- e->id = id;
- e->type = type;
- e->flags = flags;
+ .a.id = id,
+ .a.type = type,
+ .a.flags = flags,
+ };
if (type & EAF_EMBEDDED)
- e->u.data = (u32) val;
+ ea->a.u.data = val;
else
- e->u.ptr = (struct adata *) val;
+ ea->a.u.ptr = (struct adata *) val;
+
+ *to = &ea->l;
- return e;
+ return &ea->a;
+}
+
+static inline void
+ea_unset_attr(ea_list **to, struct linpool *pool, _Bool local, uint code)
+{
+ struct ea_one_attr_list *ea = lp_alloc(pool, sizeof(*ea));
+ *ea = (struct ea_one_attr_list) {
+ .l.flags = EALF_SORTED,
+ .l.count = 1,
+ .l.next = *to,
+ .a.id = code,
+ .a.fresh = local,
+ .a.originated = local,
+ .a.undef = 1,
+ };
+
+ *to = &ea->l;
}
static inline void
diff --git a/nest/rt-attr.c b/nest/rt-attr.c
index 863d411b..22b45db9 100644
--- a/nest/rt-attr.c
+++ b/nest/rt-attr.c
@@ -448,8 +448,7 @@ ea_find(ea_list *e, unsigned id)
{
eattr *a = ea__find(e, id & EA_CODE_MASK);
- if (a && (a->type & EAF_TYPE_MASK) == EAF_TYPE_UNDEF &&
- !(id & EA_ALLOW_UNDEF))
+ if (a && a->undef && !(id & EA_ALLOW_UNDEF))
return NULL;
return a;
}
@@ -516,7 +515,7 @@ ea_walk(struct ea_walk_state *s, uint id, uint max)
BIT32_SET(s->visited, n);
- if ((a->type & EAF_TYPE_MASK) == EAF_TYPE_UNDEF)
+ if (a->undef)
continue;
s->eattrs = e;
@@ -616,14 +615,17 @@ ea_do_prune(ea_list *e)
/* Now s0 is the most recent version, s[-1] the oldest one */
/* Drop undefs */
- if ((s0->type & EAF_TYPE_MASK) == EAF_TYPE_UNDEF)
+ if (s0->undef)
continue;
/* Copy the newest version to destination */
*d = *s0;
/* Preserve info whether it originated locally */
- d->type = (d->type & ~(EAF_ORIGINATED|EAF_FRESH)) | (s[-1].type & EAF_ORIGINATED);
+ d->originated = s[-1].originated;
+
+ /* Not fresh any more, we prefer surstroemming */
+ d->fresh = 0;
/* Next destination */
d++;
@@ -737,6 +739,9 @@ ea_same(ea_list *x, ea_list *y)
if (a->id != b->id ||
a->flags != b->flags ||
a->type != b->type ||
+ a->originated != b->originated ||
+ a->fresh != b->fresh ||
+ a->undef != b->undef ||
((a->type & EAF_EMBEDDED) ? a->u.data != b->u.data : !adata_same(a->u.ptr, b->u.ptr)))
return 0;
}
@@ -939,6 +944,10 @@ ea_show(struct cli *c, const eattr *e)
{
*pos++ = ':';
*pos++ = ' ';
+
+ if (e->undef)
+ bsprintf(pos, "undefined");
+ else
switch (e->type & EAF_TYPE_MASK)
{
case EAF_TYPE_INT:
@@ -968,7 +977,6 @@ ea_show(struct cli *c, const eattr *e)
case EAF_TYPE_LC_SET:
ea_show_lc_set(c, ad, pos, buf, end);
return;
- case EAF_TYPE_UNDEF:
default:
bsprintf(pos, "<type %02x>", e->type);
}
@@ -1004,7 +1012,7 @@ ea_dump(ea_list *e)
eattr *a = &e->attrs[i];
debug(" %02x:%02x.%02x", EA_PROTO(a->id), EA_ID(a->id), a->flags);
debug("=%c", "?iO?I?P???S?????" [a->type & EAF_TYPE_MASK]);
- if (a->type & EAF_ORIGINATED)
+ if (a->originated)
debug("o");
if (a->type & EAF_EMBEDDED)
debug(":%08x", a->u.data);
diff --git a/nest/rt-dev.c b/nest/rt-dev.c
index 5d1e57b3..129c724f 100644
--- a/nest/rt-dev.c
+++ b/nest/rt-dev.c
@@ -194,3 +194,9 @@ struct protocol proto_device = {
.reconfigure = dev_reconfigure,
.copy_config = dev_copy_config
};
+
+void
+dev_build(void)
+{
+ proto_build(&proto_device);
+}
diff --git a/proto/babel/Makefile b/proto/babel/Makefile
index 06b58e95..ae6aeaf2 100644
--- a/proto/babel/Makefile
+++ b/proto/babel/Makefile
@@ -2,5 +2,6 @@ src := babel.c packets.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,babel_build)
tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/babel/babel.c b/proto/babel/babel.c
index 9551b594..a8ca9e52 100644
--- a/proto/babel/babel.c
+++ b/proto/babel/babel.c
@@ -2497,3 +2497,9 @@ struct protocol proto_babel = {
.get_route_info = babel_get_route_info,
.get_attr = babel_get_attr
};
+
+void
+babel_build(void)
+{
+ proto_build(&proto_babel);
+}
diff --git a/proto/bfd/Makefile b/proto/bfd/Makefile
index 402122fc..dbdc0a09 100644
--- a/proto/bfd/Makefile
+++ b/proto/bfd/Makefile
@@ -2,5 +2,6 @@ src := bfd.c io.c packets.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,bfd_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/bfd/bfd.c b/proto/bfd/bfd.c
index 277f38bf..d1e97cd5 100644
--- a/proto/bfd/bfd.c
+++ b/proto/bfd/bfd.c
@@ -113,8 +113,8 @@
#define HASH_IP_EQ(a1,n1,a2,n2) ipa_equal(a1, a2) && n1 == n2
#define HASH_IP_FN(a,n) ipa_hash(a) ^ u32_hash(n)
-static list bfd_proto_list;
-static list bfd_wait_list;
+static list STATIC_LIST_INIT(bfd_proto_list);
+static list STATIC_LIST_INIT(bfd_wait_list);
const char *bfd_state_names[] = { "AdminDown", "Down", "Init", "Up" };
@@ -998,13 +998,6 @@ bfd_notify_init(struct bfd_proto *p)
* BFD protocol glue
*/
-void
-bfd_init_all(void)
-{
- init_list(&bfd_proto_list);
- init_list(&bfd_wait_list);
-}
-
static struct proto *
bfd_init(struct proto_config *c)
{
@@ -1186,3 +1179,9 @@ struct protocol proto_bfd = {
.reconfigure = bfd_reconfigure,
.copy_config = bfd_copy_config,
};
+
+void
+bfd_build(void)
+{
+ proto_build(&proto_bfd);
+}
diff --git a/proto/bgp/Makefile b/proto/bgp/Makefile
index 00aaef5e..2a4cc99c 100644
--- a/proto/bgp/Makefile
+++ b/proto/bgp/Makefile
@@ -2,5 +2,6 @@ src := attrs.c bgp.c packets.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,bgp_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/bgp/attrs.c b/proto/bgp/attrs.c
index e2138679..f4f7d15a 100644
--- a/proto/bgp/attrs.c
+++ b/proto/bgp/attrs.c
@@ -106,7 +106,7 @@ bgp_set_attr(ea_list **attrs, struct linpool *pool, uint code, uint flags, uintp
({ REPORT(msg, ## args); s->err_withdraw = 1; return; })
#define UNSET(a) \
- ({ a->type = EAF_TYPE_UNDEF; return; })
+ ({ a->undef = 1; return; })
#define REJECT(msg, args...) \
({ log(L_ERR "%s: " msg, s->proto->p.name, ## args); s->err_reject = 1; return; })
@@ -1153,7 +1153,7 @@ bgp_export_attr(struct bgp_export_state *s, eattr *a, ea_list *to)
a->flags = (a->flags & BAF_PARTIAL) | desc->flags;
/* Set partial bit if new opt-trans attribute is attached to non-local route */
- if ((s->src != NULL) && (a->type & EAF_ORIGINATED) &&
+ if ((s->src != NULL) && (a->originated) &&
(a->flags & BAF_OPTIONAL) && (a->flags & BAF_TRANSITIVE))
a->flags |= BAF_PARTIAL;
@@ -1161,7 +1161,7 @@ bgp_export_attr(struct bgp_export_state *s, eattr *a, ea_list *to)
CALL(desc->export, s, a);
/* Attribute might become undefined in hook */
- if ((a->type & EAF_TYPE_MASK) == EAF_TYPE_UNDEF)
+ if (a->undef)
return;
}
else
@@ -1776,7 +1776,7 @@ bgp_update_attrs(struct bgp_proto *p, struct bgp_channel *c, rte *e, ea_list *at
/* MULTI_EXIT_DESC attribute - accept only if set in export filter */
a = bgp_find_attr(attrs0, BA_MULTI_EXIT_DISC);
- if (a && !(a->type & EAF_FRESH))
+ if (a && !(a->fresh))
bgp_unset_attr(&attrs, pool, BA_MULTI_EXIT_DISC);
}
diff --git a/proto/bgp/bgp.c b/proto/bgp/bgp.c
index f52eb2f0..220551f6 100644
--- a/proto/bgp/bgp.c
+++ b/proto/bgp/bgp.c
@@ -2592,3 +2592,8 @@ struct protocol proto_bgp = {
.get_route_info = bgp_get_route_info,
.show_proto_info = bgp_show_proto_info
};
+
+void bgp_build(void)
+{
+ proto_build(&proto_bgp);
+}
diff --git a/proto/bgp/bgp.h b/proto/bgp/bgp.h
index 655b2636..022adb39 100644
--- a/proto/bgp/bgp.h
+++ b/proto/bgp/bgp.h
@@ -563,9 +563,7 @@ bgp_set_attr_data(ea_list **to, struct linpool *pool, uint code, uint flags, voi
bgp_set_attr(to, pool, code, flags, (uintptr_t) a);
}
-static inline void
-bgp_unset_attr(ea_list **to, struct linpool *pool, uint code)
-{ eattr *e = bgp_set_attr(to, pool, code, 0, 0); e->type = EAF_TYPE_UNDEF; }
+#define bgp_unset_attr(to, pool, code) ea_unset_attr(to, pool, 0, code)
int bgp_encode_mp_reach_mrt(struct bgp_write_state *s, eattr *a, byte *buf, uint size);
diff --git a/proto/bgp/packets.c b/proto/bgp/packets.c
index adfaf2f1..c88165bc 100644
--- a/proto/bgp/packets.c
+++ b/proto/bgp/packets.c
@@ -1062,7 +1062,7 @@ bgp_use_next_hop(struct bgp_export_state *s, eattr *a)
return 1;
/* Keep it when explicitly set in export filter */
- if (a->type & EAF_FRESH)
+ if (a->fresh)
return 1;
/* Check for non-matching AF */
diff --git a/proto/mrt/Makefile b/proto/mrt/Makefile
index 925fb102..000e1c1c 100644
--- a/proto/mrt/Makefile
+++ b/proto/mrt/Makefile
@@ -2,5 +2,6 @@ src := mrt.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,mrt_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/mrt/mrt.c b/proto/mrt/mrt.c
index 5da3c7c6..589e43fb 100644
--- a/proto/mrt/mrt.c
+++ b/proto/mrt/mrt.c
@@ -913,3 +913,9 @@ struct protocol proto_mrt = {
.reconfigure = mrt_reconfigure,
.copy_config = mrt_copy_config,
};
+
+void
+mrt_build(void)
+{
+ proto_build(&proto_mrt);
+}
diff --git a/proto/ospf/Makefile b/proto/ospf/Makefile
index 39e74f71..85664543 100644
--- a/proto/ospf/Makefile
+++ b/proto/ospf/Makefile
@@ -2,5 +2,6 @@ src := dbdes.c hello.c iface.c lsack.c lsalib.c lsreq.c lsupd.c neighbor.c ospf.
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,ospf_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/ospf/ospf.c b/proto/ospf/ospf.c
index 22150590..d651d48d 100644
--- a/proto/ospf/ospf.c
+++ b/proto/ospf/ospf.c
@@ -1534,3 +1534,9 @@ struct protocol proto_ospf = {
.get_attr = ospf_get_attr,
.get_route_info = ospf_get_route_info
};
+
+void
+ospf_build(void)
+{
+ proto_build(&proto_ospf);
+}
diff --git a/proto/perf/Makefile b/proto/perf/Makefile
index 7877fb19..42051f43 100644
--- a/proto/perf/Makefile
+++ b/proto/perf/Makefile
@@ -2,5 +2,6 @@ src := perf.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,perf_build)
tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/perf/perf.c b/proto/perf/perf.c
index 8b2cb69f..a4945933 100644
--- a/proto/perf/perf.c
+++ b/proto/perf/perf.c
@@ -314,3 +314,9 @@ struct protocol proto_perf = {
.reconfigure = perf_reconfigure,
.copy_config = perf_copy_config,
};
+
+void
+perf_build(void)
+{
+ proto_build(&proto_perf);
+}
diff --git a/proto/pipe/Makefile b/proto/pipe/Makefile
index 5093da98..ba66027f 100644
--- a/proto/pipe/Makefile
+++ b/proto/pipe/Makefile
@@ -2,5 +2,6 @@ src := pipe.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,pipe_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/pipe/pipe.c b/proto/pipe/pipe.c
index bbcd8f0d..da4104a8 100644
--- a/proto/pipe/pipe.c
+++ b/proto/pipe/pipe.c
@@ -309,3 +309,9 @@ struct protocol proto_pipe = {
.get_status = pipe_get_status,
.show_proto_info = pipe_show_proto_info
};
+
+void
+pipe_build(void)
+{
+ proto_build(&proto_pipe);
+}
diff --git a/proto/radv/Makefile b/proto/radv/Makefile
index 05317eff..4780bee3 100644
--- a/proto/radv/Makefile
+++ b/proto/radv/Makefile
@@ -2,5 +2,6 @@ src := packets.c radv.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,radv_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/radv/radv.c b/proto/radv/radv.c
index fa228c69..24b1ce24 100644
--- a/proto/radv/radv.c
+++ b/proto/radv/radv.c
@@ -771,3 +771,9 @@ struct protocol proto_radv = {
.get_status = radv_get_status,
.get_attr = radv_get_attr
};
+
+void
+radv_build(void)
+{
+ proto_build(&proto_radv);
+}
diff --git a/proto/rip/Makefile b/proto/rip/Makefile
index 7feabcd8..b9ff62d6 100644
--- a/proto/rip/Makefile
+++ b/proto/rip/Makefile
@@ -2,5 +2,6 @@ src := packets.c rip.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,rip_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/rip/rip.c b/proto/rip/rip.c
index b04238fb..eeca7834 100644
--- a/proto/rip/rip.c
+++ b/proto/rip/rip.c
@@ -1341,3 +1341,9 @@ struct protocol proto_rip = {
.get_route_info = rip_get_route_info,
.get_attr = rip_get_attr
};
+
+void
+rip_build(void)
+{
+ proto_build(&proto_rip);
+}
diff --git a/proto/rpki/Makefile b/proto/rpki/Makefile
index eb09b7df..8e3a2761 100644
--- a/proto/rpki/Makefile
+++ b/proto/rpki/Makefile
@@ -2,5 +2,6 @@ src := rpki.c packets.c tcp_transport.c ssh_transport.c transport.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,rpki_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/rpki/rpki.c b/proto/rpki/rpki.c
index 95066499..766b8445 100644
--- a/proto/rpki/rpki.c
+++ b/proto/rpki/rpki.c
@@ -955,3 +955,9 @@ struct protocol proto_rpki = {
.reconfigure = rpki_reconfigure,
.get_status = rpki_get_status,
};
+
+void
+rpki_build(void)
+{
+ proto_build(&proto_rpki);
+}
diff --git a/proto/static/Makefile b/proto/static/Makefile
index e38f9b74..26aed31f 100644
--- a/proto/static/Makefile
+++ b/proto/static/Makefile
@@ -2,5 +2,6 @@ src := static.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,static_build)
-tests_objs := $(tests_objs) $(src-o-files) \ No newline at end of file
+tests_objs := $(tests_objs) $(src-o-files)
diff --git a/proto/static/static.c b/proto/static/static.c
index f8ac9c81..8e0a3489 100644
--- a/proto/static/static.c
+++ b/proto/static/static.c
@@ -775,3 +775,9 @@ struct protocol proto_static = {
.copy_config = static_copy_config,
.get_route_info = static_get_route_info,
};
+
+void
+static_build(void)
+{
+ proto_build(&proto_static);
+}
diff --git a/sysdep/unix/Makefile b/sysdep/unix/Makefile
index d0d36b5f..51ab98a9 100644
--- a/sysdep/unix/Makefile
+++ b/sysdep/unix/Makefile
@@ -2,6 +2,8 @@ src := alloc.c io.c krt.c log.c main.c random.c
obj := $(src-o-files)
$(all-daemon)
$(cf-local)
+$(call proto-build,kif_build)
+$(call proto-build,krt_build)
$(conf-y-targets): $(s)krt.Y
src := $(filter-out main.c, $(src))
diff --git a/sysdep/unix/krt.c b/sysdep/unix/krt.c
index f80c4c45..d8a91837 100644
--- a/sysdep/unix/krt.c
+++ b/sysdep/unix/krt.c
@@ -243,6 +243,13 @@ struct protocol proto_unix_iface = {
.copy_config = kif_copy_config
};
+void
+kif_build(void)
+{
+ proto_build(&proto_unix_iface);
+}
+
+
/*
* Tracing of routes
*/
@@ -1186,3 +1193,9 @@ struct protocol proto_unix_kernel = {
.dump = krt_dump,
#endif
};
+
+void
+krt_build(void)
+{
+ proto_build(&proto_unix_kernel);
+}
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index cdf0a310..71749324 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -906,8 +906,6 @@ main(int argc, char **argv)
open_pid_file();
protos_build();
- proto_build(&proto_unix_kernel);
- proto_build(&proto_unix_iface);
struct config *conf = read_config();
diff --git a/test/bt-utils.c b/test/bt-utils.c
index 2a7799c3..8496e185 100644
--- a/test/bt-utils.c
+++ b/test/bt-utils.c
@@ -68,8 +68,6 @@ bt_bird_init(void)
config_init();
protos_build();
- proto_build(&proto_unix_kernel);
- proto_build(&proto_unix_iface);
}
void bt_bird_cleanup(void)