Protocols have their own explicit init routines

This commit is contained in:
Maria Matejka 2022-03-18 22:05:50 +01:00
parent 0f68515263
commit 4a23ede2b0
31 changed files with 131 additions and 65 deletions

View file

@ -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) conf-y-targets := $(addprefix $(objdir)/conf/,cf-parse.y keywords.h commands.h)
cf-local = $(conf-y-targets): $(s)config.Y 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)) src-o-files = $(patsubst %.c,$(o)%.o,$(src))
tests-target-files = $(patsubst %.c,$(o)%,$(tests_src)) tests-target-files = $(patsubst %.c,$(o)%,$(tests_src))
@ -95,6 +98,13 @@ else
o = $(patsubst $(srcdir)%,$(objdir)%,$(s)) o = $(patsubst $(srcdir)%,$(objdir)%,$(s))
endif 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 = define clean_in =
clean:: clean::
rm -f $(addprefix $(o),$(1)) rm -f $(addprefix $(o),$(1))

View file

@ -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) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(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_src := a-set_test.c a-path_test.c
tests_targets := $(tests_targets) $(tests-target-files) tests_targets := $(tests_targets) $(tests-target-files)

View file

@ -23,9 +23,9 @@
#include "filter/f-inst.h" #include "filter/f-inst.h"
pool *proto_pool; 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]; 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); }) #define CD(c, msg, args...) ({ if (c->debug & D_STATES) log(L_TRACE "%s.%s: " msg, c->proto->name, c->name ?: "?", ## args); })
@ -1651,6 +1651,8 @@ proto_build(struct protocol *p)
/* FIXME: convert this call to some protocol hook */ /* FIXME: convert this call to some protocol hook */
extern void bfd_init_all(void); extern void bfd_init_all(void);
void protos_build_gen(void);
/** /**
* protos_build - build a protocol list * protos_build - build a protocol list
* *
@ -1663,44 +1665,7 @@ extern void bfd_init_all(void);
void void
protos_build(void) protos_build(void)
{ {
init_list(&proto_list); protos_build_gen();
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
proto_pool = rp_new(&root_pool, "Protocols"); proto_pool = rp_new(&root_pool, "Protocols");
proto_shutdown_timer = tm_new(proto_pool); proto_shutdown_timer = tm_new(proto_pool);

View file

@ -84,8 +84,8 @@ struct protocol {
void (*copy_config)(struct proto_config *, struct proto_config *); /* Copy config from given protocol instance */ void (*copy_config)(struct proto_config *, struct proto_config *); /* Copy config from given protocol instance */
}; };
void protos_build(void); void protos_build(void); /* Called from sysdep to initialize protocols */
void proto_build(struct protocol *); void proto_build(struct protocol *); /* Called from protocol to register itself */
void protos_preconfig(struct config *); void protos_preconfig(struct config *);
void protos_commit(struct config *new, struct config *old, int force_restart, int type); void protos_commit(struct config *new, struct config *old, int force_restart, int type);
struct proto * proto_spawn(struct proto_config *cf, uint disabled); struct proto * proto_spawn(struct proto_config *cf, uint disabled);

View file

@ -195,3 +195,9 @@ struct protocol proto_device = {
.reconfigure = dev_reconfigure, .reconfigure = dev_reconfigure,
.copy_config = dev_copy_config .copy_config = dev_copy_config
}; };
void
dev_build(void)
{
proto_build(&proto_device);
}

View file

@ -2,5 +2,6 @@ src := babel.c packets.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,babel_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -2494,3 +2494,9 @@ struct protocol proto_babel = {
.get_route_info = babel_get_route_info, .get_route_info = babel_get_route_info,
.get_attr = babel_get_attr .get_attr = babel_get_attr
}; };
void
babel_build(void)
{
proto_build(&proto_babel);
}

View file

@ -2,5 +2,6 @@ src := bfd.c io.c packets.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,bfd_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -113,8 +113,8 @@
#define HASH_IP_EQ(a1,n1,a2,n2) ipa_equal(a1, a2) && n1 == n2 #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) #define HASH_IP_FN(a,n) ipa_hash(a) ^ u32_hash(n)
static list bfd_proto_list; static list STATIC_LIST_INIT(bfd_proto_list);
static list bfd_wait_list; static list STATIC_LIST_INIT(bfd_wait_list);
const char *bfd_state_names[] = { "AdminDown", "Down", "Init", "Up" }; const char *bfd_state_names[] = { "AdminDown", "Down", "Init", "Up" };
@ -998,13 +998,6 @@ bfd_notify_init(struct bfd_proto *p)
* BFD protocol glue * BFD protocol glue
*/ */
void
bfd_init_all(void)
{
init_list(&bfd_proto_list);
init_list(&bfd_wait_list);
}
static struct proto * static struct proto *
bfd_init(struct proto_config *c) bfd_init(struct proto_config *c)
{ {
@ -1186,3 +1179,9 @@ struct protocol proto_bfd = {
.reconfigure = bfd_reconfigure, .reconfigure = bfd_reconfigure,
.copy_config = bfd_copy_config, .copy_config = bfd_copy_config,
}; };
void
bfd_build(void)
{
proto_build(&proto_bfd);
}

View file

@ -2,5 +2,6 @@ src := attrs.c bgp.c packets.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,bgp_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -2592,3 +2592,8 @@ struct protocol proto_bgp = {
.get_route_info = bgp_get_route_info, .get_route_info = bgp_get_route_info,
.show_proto_info = bgp_show_proto_info .show_proto_info = bgp_show_proto_info
}; };
void bgp_build(void)
{
proto_build(&proto_bgp);
}

View file

@ -2,5 +2,6 @@ src := mrt.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,mrt_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -916,3 +916,9 @@ struct protocol proto_mrt = {
.reconfigure = mrt_reconfigure, .reconfigure = mrt_reconfigure,
.copy_config = mrt_copy_config, .copy_config = mrt_copy_config,
}; };
void
mrt_build(void)
{
proto_build(&proto_mrt);
}

View file

@ -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) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,ospf_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -1534,3 +1534,9 @@ struct protocol proto_ospf = {
.get_attr = ospf_get_attr, .get_attr = ospf_get_attr,
.get_route_info = ospf_get_route_info .get_route_info = ospf_get_route_info
}; };
void
ospf_build(void)
{
proto_build(&proto_ospf);
}

View file

@ -2,5 +2,6 @@ src := perf.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,perf_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -315,3 +315,9 @@ struct protocol proto_perf = {
.reconfigure = perf_reconfigure, .reconfigure = perf_reconfigure,
.copy_config = perf_copy_config, .copy_config = perf_copy_config,
}; };
void
perf_build(void)
{
proto_build(&proto_perf);
}

View file

@ -2,5 +2,6 @@ src := pipe.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,pipe_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -303,3 +303,9 @@ struct protocol proto_pipe = {
.get_status = pipe_get_status, .get_status = pipe_get_status,
.show_proto_info = pipe_show_proto_info .show_proto_info = pipe_show_proto_info
}; };
void
pipe_build(void)
{
proto_build(&proto_pipe);
}

View file

@ -2,5 +2,6 @@ src := packets.c radv.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,radv_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -771,3 +771,9 @@ struct protocol proto_radv = {
.get_status = radv_get_status, .get_status = radv_get_status,
.get_attr = radv_get_attr .get_attr = radv_get_attr
}; };
void
radv_build(void)
{
proto_build(&proto_radv);
}

View file

@ -2,5 +2,6 @@ src := packets.c rip.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,rip_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -1342,3 +1342,9 @@ struct protocol proto_rip = {
.get_route_info = rip_get_route_info, .get_route_info = rip_get_route_info,
.get_attr = rip_get_attr .get_attr = rip_get_attr
}; };
void
rip_build(void)
{
proto_build(&proto_rip);
}

View file

@ -2,5 +2,6 @@ src := rpki.c packets.c tcp_transport.c ssh_transport.c transport.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,rpki_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -949,3 +949,9 @@ struct protocol proto_rpki = {
.reconfigure = rpki_reconfigure, .reconfigure = rpki_reconfigure,
.get_status = rpki_get_status, .get_status = rpki_get_status,
}; };
void
rpki_build(void)
{
proto_build(&proto_rpki);
}

View file

@ -2,5 +2,6 @@ src := static.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,static_build)
tests_objs := $(tests_objs) $(src-o-files) tests_objs := $(tests_objs) $(src-o-files)

View file

@ -793,3 +793,9 @@ struct protocol proto_static = {
.copy_config = static_copy_config, .copy_config = static_copy_config,
.get_route_info = static_get_route_info, .get_route_info = static_get_route_info,
}; };
void
static_build(void)
{
proto_build(&proto_static);
}

View file

@ -2,6 +2,8 @@ src := alloc.c io.c krt.c log.c main.c random.c
obj := $(src-o-files) obj := $(src-o-files)
$(all-daemon) $(all-daemon)
$(cf-local) $(cf-local)
$(call proto-build,kif_build)
$(call proto-build,krt_build)
$(conf-y-targets): $(s)krt.Y $(conf-y-targets): $(s)krt.Y
src := $(filter-out main.c, $(src)) src := $(filter-out main.c, $(src))

View file

@ -243,6 +243,13 @@ struct protocol proto_unix_iface = {
.copy_config = kif_copy_config .copy_config = kif_copy_config
}; };
void
kif_build(void)
{
proto_build(&proto_unix_iface);
}
/* /*
* Tracing of routes * Tracing of routes
*/ */
@ -1177,3 +1184,9 @@ struct protocol proto_unix_kernel = {
.dump = krt_dump, .dump = krt_dump,
#endif #endif
}; };
void
krt_build(void)
{
proto_build(&proto_unix_kernel);
}

View file

@ -906,8 +906,6 @@ main(int argc, char **argv)
open_pid_file(); open_pid_file();
protos_build(); protos_build();
proto_build(&proto_unix_kernel);
proto_build(&proto_unix_iface);
struct config *conf = read_config(); struct config *conf = read_config();

View file

@ -68,8 +68,6 @@ bt_bird_init(void)
config_init(); config_init();
protos_build(); protos_build();
proto_build(&proto_unix_kernel);
proto_build(&proto_unix_iface);
} }
void bt_bird_cleanup(void) void bt_bird_cleanup(void)