From: Jeremy Harris Date: Tue, 13 Aug 2024 12:14:12 +0000 (+0100) Subject: move router infos to individual driver files X-Git-Url: https://git.exim.org/exim.git/commitdiff_plain/51d2588be64b116d4b4318b182e0ab2bad14570c?ds=sidebyside move router infos to individual driver files --- diff --git a/src/src/drtables.c b/src/src/drtables.c index 9225fafe1..1a3a80460 100644 --- a/src/src/drtables.c +++ b/src/src/drtables.c @@ -230,10 +230,7 @@ exim binary. */ #include "routers/rf_functions.h" -#ifdef ROUTER_ACCEPT -# include "routers/accept.h" -#endif - +/*XXX delete */ #ifdef ROUTER_DNSLOOKUP # include "routers/dnslookup.h" #endif @@ -288,96 +285,6 @@ router_info * routers_available_newlist = NULL; /* Now set up the structures, terminated by an entry with a null name. */ router_info routers_available_oldarray[] = { -#ifdef ROUTER_ACCEPT - { - .drinfo = { - .driver_name = US"accept", - .options = accept_router_options, - .options_count = &accept_router_options_count, - .options_block = &accept_router_option_defaults, - .options_len = sizeof(accept_router_options_block), - .init = accept_router_init, - }, - .code = accept_router_entry, - .tidyup = NULL, /* no tidyup entry */ - .ri_flags = ri_yestransport - }, -#endif -#ifdef ROUTER_DNSLOOKUP - { - .drinfo = { - .driver_name = US"dnslookup", - .options = dnslookup_router_options, - .options_count = &dnslookup_router_options_count, - .options_block = &dnslookup_router_option_defaults, - .options_len = sizeof(dnslookup_router_options_block), - .init = dnslookup_router_init, - }, - .code = dnslookup_router_entry, - .tidyup = NULL, /* no tidyup entry */ - .ri_flags = ri_yestransport - }, -#endif -#ifdef ROUTER_IPLITERAL - { - .drinfo = { - .driver_name = US"ipliteral", - .options = ipliteral_router_options, - .options_count = &ipliteral_router_options_count, - .options_block = &ipliteral_router_option_defaults, - .options_len = sizeof(ipliteral_router_options_block), - .init = ipliteral_router_init, - }, - .code = ipliteral_router_entry, - .tidyup = NULL, /* no tidyup entry */ - .ri_flags = ri_yestransport - }, -#endif -#ifdef ROUTER_IPLOOKUP - { - .drinfo = { - .driver_name = US"iplookup", - .options = iplookup_router_options, - .options_count = &iplookup_router_options_count, - .options_block = &iplookup_router_option_defaults, - .options_len = sizeof(iplookup_router_options_block), - .init = iplookup_router_init, - }, - .code = iplookup_router_entry, - .tidyup = NULL, /* no tidyup entry */ - .ri_flags = ri_notransport - }, -#endif -#ifdef ROUTER_MANUALROUTE - { - .drinfo = { - .driver_name = US"manualroute", - .options = manualroute_router_options, - .options_count = &manualroute_router_options_count, - .options_block = &manualroute_router_option_defaults, - .options_len = sizeof(manualroute_router_options_block), - .init = manualroute_router_init, - }, - .code = manualroute_router_entry, - .tidyup = NULL, /* no tidyup entry */ - .ri_flags = 0 - }, -#endif -#ifdef ROUTER_REDIRECT - { - .drinfo = { - .driver_name = US"redirect", - .options = redirect_router_options, - .options_count = &redirect_router_options_count, - .options_block = &redirect_router_option_defaults, - .options_len = sizeof(redirect_router_options_block), - .init = redirect_router_init, - }, - .code = redirect_router_entry, - .tidyup = NULL, /* no tidyup entry */ - .ri_flags = ri_notransport - }, -#endif { .drinfo = { .driver_name = US"" }} }; diff --git a/src/src/lookups/cdb.c b/src/src/lookups/cdb.c index 696e52019..a0f668b98 100644 --- a/src/src/lookups/cdb.c +++ b/src/src/lookups/cdb.c @@ -482,7 +482,7 @@ lookup_info cdb_lookup_info = { }; #ifdef DYNLOOKUP -#define cdb_lookup_module_info _lookup_module_info +# define cdb_lookup_module_info _lookup_module_info #endif static lookup_info *_lookup_list[] = { &cdb_lookup_info }; diff --git a/src/src/route.c b/src/src/route.c index c0cc1fee9..cce120967 100644 --- a/src/src/route.c +++ b/src/src/route.c @@ -220,6 +220,17 @@ if (after && !afterthis) * Initialize router list * *************************************************/ +/*XXX will likely want to rename to generic */ + +static void +add_router(driver_info ** drlist_p, const driver_info * newent, size_t size) +{ +driver_info * listent = store_get(size, newent); +memcpy(listent, newent, size); +listent->next = *drlist_p; +*drlist_p= listent; +} + /* Read the routers section of the configuration file, and set up a chain of router instances according to its contents. Each router has generic options and may also have its own private options. This function is only ever called when @@ -230,10 +241,9 @@ function. */ void route_init(void) { -/*XXX temp loop just copying the old array to build the new list. -Will replace with haul from either static build file or dyn module -done by readconf_driver_init() */ +#ifdef old +/*XXX temp loop just copying the old array to build the new list. */ for (router_info * tblent = routers_available_oldarray; *tblent->drinfo.driver_name; tblent++) { @@ -242,7 +252,58 @@ for (router_info * tblent = routers_available_oldarray; listent->next = (driver_info *)routers_available_newlist; routers_available_newlist = (router_info *)listent; } +#else + +/*XXX +Will replace with ifdeffed explicit calls in drtab.c just building list +(2 lists?) of names for -bV (DONE), +plut ifdeffed repeated code here adding static-build modules to list (DONE) +plus code in readconf.c for dlopen()s just before per-driver init api call. +*/ + +int old_pool = store_pool; +store_pool = POOL_PERM; + { + driver_info ** anchor = (driver_info **) &routers_available_newlist; + extern router_info accept_router_info; + extern router_info dnslookup_router_info; + extern router_info ipliteral_router_info; + extern router_info iplookup_router_info; + extern router_info manualroute_router_info; + extern router_info redirect_router_info; + extern router_info queryprogram_router_info; + + /*XXX this addsonly the statics. We can't get the dynamics as they + are not linked. Until dlopen(), when we can use dlsym(). So the discovery + is by the file exitence, via the filename pattern. */ + /*XXX TODO: move the info structs to individual driver files */ +#if defined(ROUTER_ACCEPT) && ROUTER_ACCEPT!=2 + add_router(anchor, &accept_router_info.drinfo, sizeof(router_info)); +#endif +#if defined(ROUTER_DNSLOOKUP) && ROUTER_DNSLOOKUP!=2 + add_router(anchor, &dnslookup_router_info.drinfo, sizeof(router_info)); +#endif +# if defined(ROUTER_IPLITERAL) && ROUTER_IPLITERAL!=2 + add_router(anchor, &ipliteral_router_info.drinfo, sizeof(router_info)); +#endif +#if defined(ROUTER_IPLOOKUP) && ROUTER_IPLOOKUP!=2 + add_router(anchor, &iplookup_router_info.drinfo, sizeof(router_info)); +#endif +#if defined(ROUTER_MANUALROUTE) && ROUTER_MANUALROUTE!=2 + add_router(anchor, &manualroute_router_info.drinfo, sizeof(router_info)); +#endif +#if defined(ROUTER_REDIRECT) && ROUTER_REDIRECT!=2 + add_router(anchor, &redirect_router_info.drinfo, sizeof(router_info)); +#endif +#if defined(ROUTER_QUERYPROGRAM) && ROUTER_QUERYPROGRAM!=2 + add_router(anchor, &queryprogram_router_info.drinfo, sizeof(router_info)); +#endif + } +store_pool = old_pool; + +#endif /*!old*/ +/*XXX this does the config file "routers" section reading */ readconf_driver_init((driver_instance **)&routers, /* chain anchor */ (driver_info *)routers_available_newlist, /* available drivers */ sizeof(router_info), /* size of info blocks */ diff --git a/src/src/routers/accept.c b/src/src/routers/accept.c index 6cbde6dec..353d1762c 100644 --- a/src/src/routers/accept.c +++ b/src/src/routers/accept.c @@ -140,6 +140,30 @@ addr->prop.remove_headers = remove_headers; return rf_queue_add(addr, addr_local, addr_remote, rblock, pw) ? OK : DEFER; } + + +# ifdef DYNLOOKUP +# define accept_router_info _router_info +# endif + +router_info accept_router_info = +{ +.drinfo = { + .driver_name = US"accept", + .options = accept_router_options, + .options_count = &accept_router_options_count, + .options_block = &accept_router_option_defaults, + .options_len = sizeof(accept_router_options_block), + .init = accept_router_init, +# ifdef DYNLOOKUP + .dyn_magic = ROUTER_MAGIC, /*XXX*/ +# endif + }, +.code = accept_router_entry, +.tidyup = NULL, /* no tidyup entry */ +.ri_flags = ri_yestransport +}; + #endif /*!MACRO_PREDEF*/ #endif /*ROUTER_ACCEPT*/ diff --git a/src/src/routers/dnslookup.c b/src/src/routers/dnslookup.c index 8a6f72d5d..90ea0f613 100644 --- a/src/src/routers/dnslookup.c +++ b/src/src/routers/dnslookup.c @@ -475,6 +475,31 @@ addr->transport = rblock->transport; return rf_queue_add(addr, addr_local, addr_remote, rblock, pw) ? OK : DEFER; } + + + +# ifdef DYNLOOKUP +# define dnslookup_router_info _router_info +# endif + +router_info dnslookup_router_info = +{ +.drinfo = { + .driver_name = US"dnslookup", + .options = dnslookup_router_options, + .options_count = &dnslookup_router_options_count, + .options_block = &dnslookup_router_option_defaults, + .options_len = sizeof(dnslookup_router_options_block), + .init = dnslookup_router_init, +# ifdef DYNLOOKUP + .dyn_magic = ROUTER_MAGIC, /*XXX*/ +# endif + }, +.code = dnslookup_router_entry, +.tidyup = NULL, /* no tidyup entry */ +.ri_flags = ri_yestransport +}; + #endif /*!MACRO_PREDEF*/ #endif /*ROUTER_DNSLOOKUP*/ /* End of routers/dnslookup.c */ diff --git a/src/src/routers/ipliteral.c b/src/src/routers/ipliteral.c index 790ef15f0..a5ef20d32 100644 --- a/src/src/routers/ipliteral.c +++ b/src/src/routers/ipliteral.c @@ -201,6 +201,30 @@ return rf_queue_add(addr, addr_local, addr_remote, rblock, pw)? OK : DEFER; } + + +# ifdef DYNLOOKUP +# define ipliteral_router_info _router_info +# endif + +router_info ipliteral_router_info = +{ +.drinfo = { + .driver_name = US"ipliteral", + .options = ipliteral_router_options, + .options_count = &ipliteral_router_options_count, + .options_block = &ipliteral_router_option_defaults, + .options_len = sizeof(ipliteral_router_options_block), + .init = ipliteral_router_init, +# ifdef DYNLOOKUP + .dyn_magic = ROUTER_MAGIC, /*XXX*/ +# endif + }, +.code = ipliteral_router_entry, +.tidyup = NULL, /* no tidyup entry */ +.ri_flags = ri_yestransport +}; + #endif /*!MACRO_PREDEF*/ #endif /*ROUTER_IPLITERAL*/ /* End of routers/ipliteral.c */ diff --git a/src/src/routers/iplookup.c b/src/src/routers/iplookup.c index 26e9b7ce7..24362fa88 100644 --- a/src/src/routers/iplookup.c +++ b/src/src/routers/iplookup.c @@ -417,6 +417,30 @@ if (rc != OK) return rc; return OK; } + + +# ifdef DYNLOOKUP +# define iplookup_router_info _router_info +# endif + +router_info iplookup_router_info = +{ +.drinfo = { + .driver_name = US"iplookup", + .options = iplookup_router_options, + .options_count = &iplookup_router_options_count, + .options_block = &iplookup_router_option_defaults, + .options_len = sizeof(iplookup_router_options_block), + .init = iplookup_router_init, +# ifdef DYNLOOKUP + .dyn_magic = ROUTER_MAGIC, /*XXX*/ +# endif + }, +.code = iplookup_router_entry, +.tidyup = NULL, /* no tidyup entry */ +.ri_flags = ri_notransport +}; + #endif /*!MACRO_PREDEF*/ #endif /*ROUTER_IPLOOKUP*/ /* End of routers/iplookup.c */ diff --git a/src/src/routers/manualroute.c b/src/src/routers/manualroute.c index 05043a814..095a3af16 100644 --- a/src/src/routers/manualroute.c +++ b/src/src/routers/manualroute.c @@ -495,6 +495,31 @@ addr->transport = transport; return OK; } + + + +# ifdef DYNLOOKUP +# define manualroute_router_info _router_info +# endif + +router_info manualroute_router_info = +{ +.drinfo = { + .driver_name = US"manualroute", + .options = manualroute_router_options, + .options_count = &manualroute_router_options_count, + .options_block = &manualroute_router_option_defaults, + .options_len = sizeof(manualroute_router_options_block), + .init = manualroute_router_init, +# ifdef DYNLOOKUP + .dyn_magic = ROUTER_MAGIC, /*XXX*/ +# endif + }, +.code = manualroute_router_entry, +.tidyup = NULL, /* no tidyup entry */ +.ri_flags = 0 +}; + #endif /*!MACRO_PREDEF*/ #endif /*ROUTER_MANUALROUTE*/ /* End of routers/manualroute.c */ diff --git a/src/src/routers/queryprogram.c b/src/src/routers/queryprogram.c index 82c3f2001..606124e7e 100644 --- a/src/src/routers/queryprogram.c +++ b/src/src/routers/queryprogram.c @@ -534,6 +534,30 @@ addr->prop = addr_prop; return rf_queue_add(addr, addr_local, addr_remote, rblock, pw) ? OK : DEFER; } + + +# ifdef DYNLOOKUP +# define queryprogram_router_info _router_info +# endif + +router_info queryprogram_router_info = +{ +.drinfo = { + .driver_name = US"queryprogram", + .options = queryprogram_router_options, + .options_count = &queryprogram_router_options_count, + .options_block = &queryprogram_router_option_defaults, + .options_len = sizeof(queryprogram_router_options_block), + .init = queryprogram_router_init, +# ifdef DYNLOOKUP + .dyn_magic = ROUTER_MAGIC, /*XXX*/ +# endif + }, +.code = queryprogram_router_entry, +.tidyup = NULL, /* no tidyup entry */ +.ri_flags = 0 +}; + #endif /*!MACRO_PREDEF*/ #endif /*ROUTER_QUERYPROGRAM*/ /* End of routers/queryprogram.c */ diff --git a/src/src/routers/redirect.c b/src/src/routers/redirect.c index 936cfca14..50b180372 100644 --- a/src/src/routers/redirect.c +++ b/src/src/routers/redirect.c @@ -788,6 +788,30 @@ addr->next = *addr_succeed; return yield; } + + +# ifdef DYNLOOKUP +# define redirect_router_info _router_info +# endif + +router_info redirect_router_info = +{ +.drinfo = { + .driver_name = US"redirect", + .options = redirect_router_options, + .options_count = &redirect_router_options_count, + .options_block = &redirect_router_option_defaults, + .options_len = sizeof(redirect_router_options_block), + .init = redirect_router_init, +# ifdef DYNLOOKUP + .dyn_magic = ROUTER_MAGIC, /*XXX*/ +# endif + }, +.code = redirect_router_entry, +.tidyup = NULL, /* no tidyup entry */ +.ri_flags = ri_notransport +}; + #endif /*!MACRO_PREDEF*/ #endif /*ROUTER_REDIRECT*/ /* End of routers/redirect.c */ diff --git a/src/src/structs.h b/src/src/structs.h index 392a4a08c..3446664cd 100644 --- a/src/src/structs.h +++ b/src/src/structs.h @@ -150,9 +150,14 @@ typedef struct driver_info { int options_len; /* Length of same in bytes */ void (*init)( /* Initialization entry point */ struct driver_instance *); - BOOL dynamic; /* Built as dynamic-load module */ + uint dyn_magic; /* Magic num if dynamic, else zero */ } driver_info; +/* Values for dyn_magic. Encode types and api version. */ +#define ROUTER_MAGIC 0x52544d31 /* RTM1 */ +#define TRANSPORT_MAGIC 0x54504d31 /* TPM1 */ +#define AUTH_MAGIC 0x65554d31 /* AUM1 */ + /* Structure for holding information about the configured transports. Some of the generally accessible options are set from the configuration file; others