]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Protocols have their own explicit init routines
authorMaria Matejka <mq@ucw.cz>
Fri, 18 Mar 2022 21:05:50 +0000 (22:05 +0100)
committerMaria Matejka <mq@ucw.cz>
Wed, 6 Apr 2022 16:14:08 +0000 (18:14 +0200)
31 files changed:
Makefile.in
nest/Makefile
nest/proto.c
nest/protocol.h
nest/rt-dev.c
proto/babel/Makefile
proto/babel/babel.c
proto/bfd/Makefile
proto/bfd/bfd.c
proto/bgp/Makefile
proto/bgp/bgp.c
proto/mrt/Makefile
proto/mrt/mrt.c
proto/ospf/Makefile
proto/ospf/ospf.c
proto/perf/Makefile
proto/perf/perf.c
proto/pipe/Makefile
proto/pipe/pipe.c
proto/radv/Makefile
proto/radv/radv.c
proto/rip/Makefile
proto/rip/rip.c
proto/rpki/Makefile
proto/rpki/rpki.c
proto/static/Makefile
proto/static/static.c
sysdep/unix/Makefile
sysdep/unix/krt.c
sysdep/unix/main.c
test/bt-utils.c

index e0ff4a1d45e8e3ed5605343bf5e13b1b81529544..0d55807b4bc995cd4c0a336d0feff62ed6850a1d 100644 (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)
 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))
index 884d39506a37136e65042c4249c42f89d028c656..7d451ba429144c3c971499699ad40ad874eecf03 100644 (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)
 $(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)
index 7cfb1555a365581d369476da47e0ea8e20affb6a..7074f73a4e491ef1e0d5f15448ef4252fe3e66b8 100644 (file)
@@ -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); })
@@ -1651,6 +1651,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
  *
@@ -1663,44 +1665,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);
index e05dd7ecacbf39f365078eebd28a5dbab5685c03..d0810a8fcf1d4357ad071eac6788b67fb45816ed 100644 (file)
@@ -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);
index e2e6592609abb31df0b31a6bc7245fbd44ea9cd7..05e64fc39bec82b16fa295dc98fbc549e3a9fe60 100644 (file)
@@ -195,3 +195,9 @@ struct protocol proto_device = {
   .reconfigure =       dev_reconfigure,
   .copy_config =       dev_copy_config
 };
+
+void
+dev_build(void)
+{
+  proto_build(&proto_device);
+}
index 06b58e95b9555d4e459f2456953c3b652e3ea2a0..ae6aeaf24d27401843e2ca8f1cbc3473783312b8 100644 (file)
@@ -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)
index b3411fc2948204fb83cb3b9148b51cf30612255f..8040345faf81e7aa20e22bf4b57dc364464047f1 100644 (file)
@@ -2494,3 +2494,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);
+}
index 402122fc37804e42ca24dc43f60d2ddea40767af..dbdc0a098bc6c8e7975c7ea1e459329cd4e0b781 100644 (file)
@@ -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)
index 277f38bf2ee76f84827ba033c78dff03de05b703..d1e97cd5c8bf80644d6c25681ad13b3335a05d59 100644 (file)
 #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);
+}
index 00aaef5e123a68a5282ed3d435c8fbad9d66fc97..2a4cc99ca06116643f96800694d4831d0dccd009 100644 (file)
@@ -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)
index 524007629faa5f563cf58e21f816a99d2d4a5f2e..8c97f7b33a1e7a6ec6547e12f600e2bee484de52 100644 (file)
@@ -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);
+}
index 925fb10262941fe09788ec825a059381cb08a06c..000e1c1c587aae7d8455b8a652f8e0066599ea19 100644 (file)
@@ -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)
index e885611aa9158bfdc7653939ea851894dfe87ec6..70b2aeff4eeffcfb5f35ef9415aa286cef29fc83 100644 (file)
@@ -916,3 +916,9 @@ struct protocol proto_mrt = {
   .reconfigure =       mrt_reconfigure,
   .copy_config =       mrt_copy_config,
 };
+
+void
+mrt_build(void)
+{
+  proto_build(&proto_mrt);
+}
index 39e74f719413d994345d8c6875de092cc6c66952..85664543f96aa3d6126a6df3fc31bbcd9bc0a4b6 100644 (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)
 $(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)
index f9aa6cd19e3963e487bf9c1ff32b5f8df1d5d2b7..4ea539421800f78ad809c2b30e8b00c4539be787 100644 (file)
@@ -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);
+}
index 7877fb193cf56fdae4c5ad57df5a566dd5dcd77a..42051f439efaf45bffdb569ab492690a257c7cc2 100644 (file)
@@ -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)
index 52784c148ce48462f89033e0b2bbc15983811e9c..5d228045e7275bf520883ea0751ce5c78456283a 100644 (file)
@@ -315,3 +315,9 @@ struct protocol proto_perf = {
   .reconfigure =       perf_reconfigure,
   .copy_config =       perf_copy_config,
 };
+
+void
+perf_build(void)
+{
+  proto_build(&proto_perf);
+}
index 5093da98e38f7a8aecb084fc39e777db469bdfaf..ba66027f675cb6a86e0bbdef97708f8703c62269 100644 (file)
@@ -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)
index 978627804ca9e8f9f2be5dcffd87142afac95d13..c34571353dc4fad426bb65d2e1477827f66310f6 100644 (file)
@@ -303,3 +303,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);
+}
index 05317eff20c65b573da6d1a40728ce27f1e9145b..4780bee3b931643ae714cf1f718c76228e9e8ed0 100644 (file)
@@ -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)
index 540ff2a7a418e305c27bb55f88cc0086fbb7a9e5..7985997a32baca767014b0a51addd3633f1eb53d 100644 (file)
@@ -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);
+}
index 7feabcd8b051784e595a41df3fc694ac174f5536..b9ff62d68283e4f96684ee3d94384423a0df43f2 100644 (file)
@@ -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)
index eb2323160fbbf009b070662982661d5854534fd1..9d8b9849fbf5c8edb9bc9d1241abc638aa6268f9 100644 (file)
@@ -1342,3 +1342,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);
+}
index eb09b7df470545e812e591f5aac6b613693944ff..8e3a2761d8ede525ef78d23170fad021a4ecc8aa 100644 (file)
@@ -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)
index be3d19abdfa1d559e7c519eaffd9f01ca2a5b779..6e111a81fd9afd8fe5f390f67d1f8f08b8857f09 100644 (file)
@@ -949,3 +949,9 @@ struct protocol proto_rpki = {
   .reconfigure =       rpki_reconfigure,
   .get_status =        rpki_get_status,
 };
+
+void
+rpki_build(void)
+{
+  proto_build(&proto_rpki);
+}
index e38f9b741ba5176bf077311e256d4168b4bbb58f..26aed31fe8b8e2cea2a10c1bd06766f4ba6c03aa 100644 (file)
@@ -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)
index 6d3871cc5946f82a09e6ec4ed098342405bb4773..cf2e458516b5e942a758859acc069dd305bc896d 100644 (file)
@@ -793,3 +793,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);
+}
index d0d36b5f7cdbe404c6a64a35220a3345ac504ab3..51ab98a96efd3cb8ccd9ca2285e5a00f925c9d80 100644 (file)
@@ -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))
index 7d7ec7e6e606a73bb16708f0bc2e0ade3222ec93..bfd69b7371122e8921bb5648b8781150986edace 100644 (file)
@@ -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
  */
@@ -1177,3 +1184,9 @@ struct protocol proto_unix_kernel = {
   .dump =              krt_dump,
 #endif
 };
+
+void
+krt_build(void)
+{
+  proto_build(&proto_unix_kernel);
+}
index cdf0a3101bb3afb2488d322548b4ee9621a17923..7174932434bad1f6d879e58d7d39995e3c0a7a0b 100644 (file)
@@ -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();
 
index 2a7799c379d5a0fbaac1ef26e9c737eefc01299b..8496e185ac54a96e8adf9ef5c699df2b864e208e 100644 (file)
@@ -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)