diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 8a28879949..f186ee2591 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -109,7 +109,6 @@ static dns_stats_t *resquerystats = NULL; static FILE *logfp = NULL; /* Managers */ -static isc_nm_t *netmgr = NULL; static dns_dispatchmgr_t *dispatchmgr = NULL; static dns_requestmgr_t *requestmgr = NULL; static ns_interfacemgr_t *interfacemgr = NULL; @@ -1879,8 +1878,8 @@ run_resolve(void *arg) { } /* Create client */ - CHECK(dns_client_create(mctx, netmgr, 0, tlsctx_client_cache, &client, - srcaddr4, srcaddr6)); + CHECK(dns_client_create(mctx, 0, tlsctx_client_cache, &client, srcaddr4, + srcaddr6)); dns_client_setmaxrestarts(client, restarts); dns_client_setmaxqueries(client, maxtotal); @@ -2082,8 +2081,7 @@ sendquery(void *arg) { dns_view_attach(view, &(dns_view_t *){ NULL }); - const unsigned int timeout = isc_nm_getinitialtimeout(netmgr) / - MS_PER_SEC; + const unsigned int timeout = isc_nm_getinitialtimeout() / MS_PER_SEC; CHECK(dns_request_create(requestmgr, message, NULL, &peer, NULL, NULL, DNS_REQUESTOPT_TCP, NULL, timeout, timeout, 0, 0, isc_loop(), recvresponse, message, @@ -2133,7 +2131,7 @@ run_server(void *arg) { ns_server_create(mctx, matchview, &sctx); - CHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr)); + CHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); if (use_ipv4) { isc_sockaddr_any(&any); @@ -2147,7 +2145,7 @@ run_server(void *arg) { CHECK(dns_dispatch_createudp(dispatchmgr, a, &dispatch6)); } - CHECK(ns_interfacemgr_create(mctx, sctx, netmgr, dispatchmgr, NULL, + CHECK(ns_interfacemgr_create(mctx, sctx, dispatchmgr, NULL, &interfacemgr)); dns_view_create(mctx, dispatchmgr, dns_rdataclass_in, "_default", @@ -2169,8 +2167,8 @@ run_server(void *arg) { dns_view_initsecroots(view); CHECK(setup_dnsseckeys(NULL, view)); - CHECK(dns_view_createresolver(view, netmgr, 0, tlsctx_client_cache, - dispatch4, dispatch6)); + CHECK(dns_view_createresolver(view, 0, tlsctx_client_cache, dispatch4, + dispatch6)); dns_resolver_setmaxqueries(view->resolver, maxqueries); isc_stats_create(mctx, &resstats, dns_resstatscounter_max); @@ -2185,10 +2183,9 @@ run_server(void *arg) { ns_interface_create(interfacemgr, &addr, NULL, &ifp); - CHECK(isc_nm_listenstreamdns(netmgr, ISC_NM_LISTEN_ONE, &addr, - ns_client_request, ifp, accept_cb, ifp, 10, - NULL, NULL, ISC_NM_PROXY_NONE, - &ifp->tcplistensocket)); + CHECK(isc_nm_listenstreamdns( + ISC_NM_LISTEN_ONE, &addr, ns_client_request, ifp, accept_cb, + ifp, 10, NULL, NULL, ISC_NM_PROXY_NONE, &ifp->tcplistensocket)); ifp->flags |= NS_INTERFACEFLAG_LISTENING; isc_async_current(sendquery, ifp->tcplistensocket); @@ -2215,7 +2212,7 @@ main(int argc, char *argv[]) { argc--; argv++; - isc_managers_create(&mctx, 1, &netmgr); + isc_managers_create(&mctx, 1); loop = isc_loop_main(); parse_args(argc, argv); @@ -2259,7 +2256,7 @@ cleanup: dns_master_styledestroy(&style, mctx); } - isc_managers_destroy(&mctx, &netmgr); + isc_managers_destroy(&mctx); return 0; } diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index db937629f6..85e90ff398 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -100,7 +100,6 @@ bool port_set = false; unsigned int timeout = 0; unsigned int extrabytes; isc_mem_t *mctx = NULL; -isc_nm_t *netmgr = NULL; isc_loop_t *mainloop = NULL; isc_sockaddr_t localaddr; isc_refcount_t sendcount = 0; @@ -1345,7 +1344,7 @@ setup_libs(int argc, char **argv) { fatal("can't find either v4 or v6 networking"); } - isc_managers_create(&mctx, 1, &netmgr); + isc_managers_create(&mctx, 1); logconfig = isc_logconfig_get(); isc_log_createandusechannel(logconfig, "debug", ISC_LOG_TOFILEDESC, @@ -3011,7 +3010,7 @@ start_tcp(dig_query_t *query) { if (tlsctx == NULL) { goto failure_tls; } - isc_nm_streamdnsconnect(netmgr, &localaddr, &query->sockaddr, + isc_nm_streamdnsconnect(&localaddr, &query->sockaddr, tcp_connected, connectquery, local_timeout, tlsctx, get_tls_sni_hostname(query), sess_cache, @@ -3032,14 +3031,14 @@ start_tcp(dig_query_t *query) { } } - isc_nm_httpconnect(netmgr, &localaddr, &query->sockaddr, uri, + isc_nm_httpconnect(&localaddr, &query->sockaddr, uri, !query->lookup->https_get, tcp_connected, connectquery, tlsctx, get_tls_sni_hostname(query), sess_cache, local_timeout, proxy_type, ppi); #endif } else { - isc_nm_streamdnsconnect(netmgr, &localaddr, &query->sockaddr, + isc_nm_streamdnsconnect(&localaddr, &query->sockaddr, tcp_connected, connectquery, local_timeout, NULL, NULL, NULL, proxy_type, ppi); @@ -3305,13 +3304,12 @@ start_udp(dig_query_t *query) { &query->lookup->proxy_dst_addr, NULL); ppi = &proxy_info; } - isc_nm_proxyudpconnect(netmgr, &localaddr, &query->sockaddr, - udp_ready, connectquery, - (timeout ? timeout : UDP_TIMEOUT) * 1000, - ppi); + isc_nm_proxyudpconnect( + &localaddr, &query->sockaddr, udp_ready, connectquery, + (timeout ? timeout : UDP_TIMEOUT) * 1000, ppi); } else { - isc_nm_udpconnect(netmgr, &localaddr, &query->sockaddr, - udp_ready, connectquery, + isc_nm_udpconnect(&localaddr, &query->sockaddr, udp_ready, + connectquery, (timeout ? timeout : UDP_TIMEOUT) * 1000); } } @@ -4709,7 +4707,7 @@ destroy_libs(void) { isc_mem_stats(mctx, stderr); } - isc_managers_destroy(&mctx, &netmgr); + isc_managers_destroy(&mctx); #if ENABLE_LEAK_DETECTION isc__crypto_setdestroycheck(true); diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 4bcc8d7d15..9bf9dffe97 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -139,7 +139,6 @@ static atomic_uint_fast32_t nsigned = 0, nretained = 0, ndropped = 0; static atomic_uint_fast32_t nverified = 0, nverifyfailed = 0; static const char *directory = NULL, *dsdir = NULL; static isc_mutex_t namelock; -static isc_nm_t *netmgr = NULL; static dns_db_t *gdb; /* The database */ static dns_dbversion_t *gversion; /* The database version */ static dns_dbiterator_t *gdbiter; /* The database iterator */ @@ -3636,7 +3635,7 @@ main(int argc, char *argv[]) { directory = "."; } - isc_managers_create(&mctx, nloops, &netmgr); + isc_managers_create(&mctx, nloops); setup_logging(); @@ -4006,7 +4005,7 @@ main(int argc, char *argv[]) { isc_mem_stats(mctx, stdout); } - isc_managers_destroy(&mctx, &netmgr); + isc_managers_destroy(&mctx); if (printstats) { timer_finish = isc_time_now(); diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index 39e01c86a4..890c57076b 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -1102,9 +1102,9 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp, CHECK(ISC_R_FAMILYNOSUPPORT); } - CHECK(isc_nm_listentcp(named_g_netmgr, ISC_NM_LISTEN_ONE, - &listener->address, control_newconn, listener, 5, - NULL, &listener->sock)); + CHECK(isc_nm_listentcp(ISC_NM_LISTEN_ONE, &listener->address, + control_newconn, listener, 5, NULL, + &listener->sock)); isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_CONTROL, ISC_LOG_NOTICE, "command channel listening on %s", diff --git a/bin/named/include/named/globals.h b/bin/named/include/named/globals.h index 22a2e2a804..f2ac435bb5 100644 --- a/bin/named/include/named/globals.h +++ b/bin/named/include/named/globals.h @@ -62,7 +62,6 @@ EXTERN bool named_g_run_done INIT(false); * for really short timers, another for client timers, and one * for zone timers. */ -EXTERN isc_nm_t *named_g_netmgr INIT(NULL); EXTERN cfg_parser_t *named_g_parser INIT(NULL); EXTERN cfg_parser_t *named_g_addparser INIT(NULL); EXTERN const char *named_g_version INIT(PACKAGE_VERSION); diff --git a/bin/named/main.c b/bin/named/main.c index 3e21332056..78dc190428 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -970,9 +970,9 @@ create_managers(void) { "thread count limit)" : ""); - isc_managers_create(&named_g_mctx, named_g_cpus, &named_g_netmgr); + isc_managers_create(&named_g_mctx, named_g_cpus); - isc_nm_maxudp(named_g_netmgr, maxudp); + isc_nm_maxudp(maxudp); return ISC_R_SUCCESS; } @@ -1505,7 +1505,7 @@ main(int argc, char *argv[]) { } } - isc_managers_destroy(&named_g_mctx, &named_g_netmgr); + isc_managers_destroy(&named_g_mctx); #if ENABLE_LEAK_DETECTION isc__crypto_setdestroycheck(true); diff --git a/bin/named/server.c b/bin/named/server.c index ee95afca4e..a1467640d1 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -4463,7 +4463,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, goto cleanup; } - CHECK(dns_view_createresolver(view, named_g_netmgr, resopts, + CHECK(dns_view_createresolver(view, resopts, named_g_server->tlsctx_client_cache, dispatch4, dispatch6)); @@ -8144,11 +8144,11 @@ apply_configuration(cfg_parser_t *configparser, cfg_obj_t *config, primaries = MIN_PRIMARIES_TIMEOUT; } - isc_nm_setinitialtimeout(named_g_netmgr, initial); - isc_nm_setprimariestimeout(named_g_netmgr, primaries); - isc_nm_setidletimeout(named_g_netmgr, idle); - isc_nm_setkeepalivetimeout(named_g_netmgr, keepalive); - isc_nm_setadvertisedtimeout(named_g_netmgr, advertised); + isc_nm_setinitialtimeout(initial); + isc_nm_setprimariestimeout(primaries); + isc_nm_setidletimeout(idle); + isc_nm_setkeepalivetimeout(keepalive); + isc_nm_setadvertisedtimeout(advertised); #define CAP_IF_NOT_ZERO(v, min, max) \ if (v > 0 && v < min) { \ @@ -8182,9 +8182,8 @@ apply_configuration(cfg_parser_t *configparser, cfg_obj_t *config, send_udp_buffer_size = cfg_obj_asuint32(obj); CAP_IF_NOT_ZERO(send_udp_buffer_size, 4096, INT32_MAX); - isc_nm_setnetbuffers(named_g_netmgr, recv_tcp_buffer_size, - send_tcp_buffer_size, recv_udp_buffer_size, - send_udp_buffer_size); + isc_nm_setnetbuffers(recv_tcp_buffer_size, send_tcp_buffer_size, + recv_udp_buffer_size, send_udp_buffer_size); #undef CAP_IF_NOT_ZERO @@ -8319,11 +8318,8 @@ apply_configuration(cfg_parser_t *configparser, cfg_obj_t *config, loadbalancesockets = cfg_obj_asboolean(obj); #if HAVE_SO_REUSEPORT_LB if (first_time) { - isc_nm_setloadbalancesockets(named_g_netmgr, - cfg_obj_asboolean(obj)); - } else if (loadbalancesockets != - isc_nm_getloadbalancesockets(named_g_netmgr)) - { + isc_nm_setloadbalancesockets(cfg_obj_asboolean(obj)); + } else if (loadbalancesockets != isc_nm_getloadbalancesockets()) { cfg_obj_log(obj, ISC_LOG_WARNING, "changing reuseport value requires server restart"); } @@ -9378,10 +9374,9 @@ run_server(void *arg) { named_server_t *server = (named_server_t *)arg; dns_geoip_databases_t *geoip = NULL; - dns_zonemgr_create(named_g_mctx, named_g_netmgr, &server->zonemgr); + dns_zonemgr_create(named_g_mctx, &server->zonemgr); - CHECKFATAL(dns_dispatchmgr_create(named_g_mctx, named_g_netmgr, - &named_g_dispatchmgr), + CHECKFATAL(dns_dispatchmgr_create(named_g_mctx, &named_g_dispatchmgr), "creating dispatch manager"); dns_dispatchmgr_setstats(named_g_dispatchmgr, server->resolverstats); @@ -9393,8 +9388,8 @@ run_server(void *arg) { #endif /* if defined(HAVE_GEOIP2) */ CHECKFATAL(ns_interfacemgr_create(named_g_mctx, server->sctx, - named_g_netmgr, named_g_dispatchmgr, - geoip, &server->interfacemgr), + named_g_dispatchmgr, geoip, + &server->interfacemgr), "creating interface manager"); isc_timer_create(isc_loop_main(), interface_timer_tick, server, @@ -9802,7 +9797,7 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) { isc_stats_create(server->mctx, &server->sockstats, isc_sockstatscounter_max); - isc_nm_setstats(named_g_netmgr, server->sockstats); + isc_nm_setstats(server->sockstats); isc_stats_create(named_g_mctx, &server->zonestats, dns_zonestatscounter_max); @@ -15704,11 +15699,11 @@ named_server_tcptimeouts(isc_lex_t *lex, isc_buffer_t **text) { return ISC_R_UNEXPECTEDEND; } - initial = isc_nm_getinitialtimeout(named_g_netmgr); - primaries = isc_nm_getprimariestimeout(named_g_netmgr); - idle = isc_nm_getidletimeout(named_g_netmgr); - keepalive = isc_nm_getkeepalivetimeout(named_g_netmgr); - advertised = isc_nm_getadvertisedtimeout(named_g_netmgr); + initial = isc_nm_getinitialtimeout(); + primaries = isc_nm_getprimariestimeout(); + idle = isc_nm_getidletimeout(); + keepalive = isc_nm_getkeepalivetimeout(); + advertised = isc_nm_getadvertisedtimeout(); /* Look for optional arguments. */ ptr = next_token(lex, NULL); @@ -15771,11 +15766,11 @@ named_server_tcptimeouts(isc_lex_t *lex, isc_buffer_t **text) { CHECK(ISC_R_RANGE); } - isc_nm_setinitialtimeout(named_g_netmgr, initial); - isc_nm_setprimariestimeout(named_g_netmgr, primaries); - isc_nm_setidletimeout(named_g_netmgr, idle); - isc_nm_setkeepalivetimeout(named_g_netmgr, keepalive); - isc_nm_setadvertisedtimeout(named_g_netmgr, advertised); + isc_nm_setinitialtimeout(initial); + isc_nm_setprimariestimeout(primaries); + isc_nm_setidletimeout(idle); + isc_nm_setkeepalivetimeout(keepalive); + isc_nm_setadvertisedtimeout(advertised); } snprintf(msg, sizeof(msg), "tcp-initial-timeout=%u\n", initial / 100); diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index e177c6cbab..89c3c825a5 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -3665,7 +3665,7 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp, CHECK(ISC_R_FAMILYNOSUPPORT); } - CHECK(isc_httpdmgr_create(named_g_netmgr, server->mctx, addr, client_ok, + CHECK(isc_httpdmgr_create(server->mctx, addr, client_ok, destroy_listener, listener, &listener->httpdmgr)); diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index 870885c806..b829b03e5a 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -121,7 +121,6 @@ static bool use_tls = false; static bool usevc = false; static bool usegsstsig = false; static bool local_only = false; -static isc_nm_t *netmgr = NULL; static isc_mem_t *gmctx = NULL; static dns_dispatchmgr_t *dispatchmgr = NULL; static dns_requestmgr_t *requestmgr = NULL; @@ -907,7 +906,7 @@ setup_system(void *arg ISC_ATTR_UNUSED) { irs_resconf_destroy(&resconf); - result = dns_dispatchmgr_create(gmctx, netmgr, &dispatchmgr); + result = dns_dispatchmgr_create(gmctx, &dispatchmgr); check_result(result, "dns_dispatchmgr_create"); set_source_ports(dispatchmgr); @@ -3472,7 +3471,7 @@ cleanup(void) { isc_mutex_destroy(&answer_lock); ddebug("Shutting down managers"); - isc_managers_destroy(&gmctx, &netmgr); + isc_managers_destroy(&gmctx); } static void @@ -3521,16 +3520,16 @@ main(int argc, char **argv) { pre_parse_args(argc, argv); - isc_managers_create(&gmctx, 1, &netmgr); + isc_managers_create(&gmctx, 1); parse_args(argc, argv); /* Set the network manager timeouts in milliseconds. */ - isc_nm_setinitialtimeout(netmgr, timeoutms); - isc_nm_setprimariestimeout(netmgr, timeoutms); - isc_nm_setidletimeout(netmgr, timeoutms); - isc_nm_setkeepalivetimeout(netmgr, timeoutms); - isc_nm_setadvertisedtimeout(netmgr, timeoutms); + isc_nm_setinitialtimeout(timeoutms); + isc_nm_setprimariestimeout(timeoutms); + isc_nm_setidletimeout(timeoutms); + isc_nm_setkeepalivetimeout(timeoutms); + isc_nm_setadvertisedtimeout(timeoutms); isc_loopmgr_setup(setup_system, NULL); isc_loopmgr_setup(getinput, NULL); diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 7d2fae8c0b..87165afb5c 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -57,8 +57,6 @@ bool verbose; -static isc_nm_t *netmgr = NULL; - static const char *admin_conffile = NULL; static const char *admin_keyfile = NULL; static const char *version = PACKAGE_VERSION; @@ -526,8 +524,7 @@ rndc_startconnect(isc_sockaddr_t *addr) { UNREACHABLE(); } - isc_nm_tcpconnect(netmgr, local, addr, rndc_connected, &rndc_ccmsg, - timeout); + isc_nm_tcpconnect(local, addr, rndc_connected, &rndc_ccmsg, timeout); } static void @@ -951,13 +948,13 @@ main(int argc, char **argv) { serial = isc_random32(); - isc_managers_create(&rndc_mctx, 1, &netmgr); + isc_managers_create(&rndc_mctx, 1); isc_loopmgr_setup(rndc_start, NULL); - isc_nm_setinitialtimeout(netmgr, timeout); - isc_nm_setprimariestimeout(netmgr, timeout); - isc_nm_setidletimeout(netmgr, timeout); - isc_nm_setkeepalivetimeout(netmgr, timeout); + isc_nm_setinitialtimeout(timeout); + isc_nm_setprimariestimeout(timeout); + isc_nm_setidletimeout(timeout); + isc_nm_setkeepalivetimeout(timeout); logconfig = isc_logconfig_get(); isc_log_settag(logconfig, isc_commandline_progname); @@ -1014,7 +1011,7 @@ main(int argc, char **argv) { isc_mem_stats(rndc_mctx, stderr); } - isc_managers_destroy(&rndc_mctx, &netmgr); + isc_managers_destroy(&rndc_mctx); if (failed) { return 1; diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index 0fce2918bd..ff4771e07e 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -217,7 +217,6 @@ main(int argc, char *argv[]) { isc_sockaddr_t bind_any; struct in_addr inaddr; isc_result_t result; - isc_nm_t *netmgr = NULL; dns_dispatchmgr_t *dispatchmgr = NULL; dns_dispatch_t *dispatchv4 = NULL; dns_view_t *view = NULL; @@ -270,9 +269,9 @@ main(int argc, char *argv[]) { } isc_sockaddr_fromin(&dstaddr, &inaddr, port); - isc_managers_create(&mctx, 1, &netmgr); + isc_managers_create(&mctx, 1); - RUNCHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr)); + RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); RUNCHECK(dns_dispatch_createudp( dispatchmgr, have_src ? &srcaddr : &bind_any, &dispatchv4)); @@ -289,7 +288,7 @@ main(int argc, char *argv[]) { isc_loopmgr_run(); - isc_managers_destroy(&mctx, &netmgr); + isc_managers_destroy(&mctx); return 0; } diff --git a/bin/tests/test_client.c b/bin/tests/test_client.c index 8db23bf8dc..9af2def982 100644 --- a/bin/tests/test_client.c +++ b/bin/tests/test_client.c @@ -52,7 +52,6 @@ static const char *protocols[] = { "udp", "tcp", "http-plain-get" }; static isc_mem_t *mctx = NULL; -static isc_nm_t *netmgr = NULL; static protocol_t protocol; static const char *address; @@ -286,7 +285,7 @@ parse_options(int argc, char **argv) { static void setup(void) { - isc_managers_create(&mctx, workers, &netmgr); + isc_managers_create(&mctx, workers); } static void @@ -299,7 +298,7 @@ teardown(void) { isc_tlsctx_free(&tls_ctx); } - isc_managers_destroy(&mctx, &netmgr); + isc_managers_destroy(&mctx); } static void @@ -374,22 +373,20 @@ static void run(void) { switch (protocol) { case UDP: - isc_nm_udpconnect(netmgr, &sockaddr_local, &sockaddr_remote, - connect_cb, NULL, timeout); + isc_nm_udpconnect(&sockaddr_local, &sockaddr_remote, connect_cb, + NULL, timeout); break; case TCP: - isc_nm_streamdnsconnect(netmgr, &sockaddr_local, - &sockaddr_remote, connect_cb, NULL, - timeout, NULL, NULL, NULL, - ISC_NM_PROXY_NONE, NULL); + isc_nm_streamdnsconnect(&sockaddr_local, &sockaddr_remote, + connect_cb, NULL, timeout, NULL, NULL, + NULL, ISC_NM_PROXY_NONE, NULL); break; case DOT: { isc_tlsctx_createclient(&tls_ctx); - isc_nm_streamdnsconnect(netmgr, &sockaddr_local, - &sockaddr_remote, connect_cb, NULL, - timeout, tls_ctx, NULL, NULL, - ISC_NM_PROXY_NONE, NULL); + isc_nm_streamdnsconnect(&sockaddr_local, &sockaddr_remote, + connect_cb, NULL, timeout, tls_ctx, + NULL, NULL, ISC_NM_PROXY_NONE, NULL); break; } #if HAVE_LIBNGHTTP2 @@ -408,10 +405,9 @@ run(void) { if (is_https) { isc_tlsctx_createclient(&tls_ctx); } - isc_nm_httpconnect(netmgr, &sockaddr_local, &sockaddr_remote, - req_url, is_post, connect_cb, NULL, tls_ctx, - NULL, NULL, timeout, ISC_NM_PROXY_NONE, - NULL); + isc_nm_httpconnect(&sockaddr_local, &sockaddr_remote, req_url, + is_post, connect_cb, NULL, tls_ctx, NULL, + NULL, timeout, ISC_NM_PROXY_NONE, NULL); } break; #endif default: diff --git a/bin/tests/test_server.c b/bin/tests/test_server.c index 28b7ed29d7..03d1feff92 100644 --- a/bin/tests/test_server.c +++ b/bin/tests/test_server.c @@ -34,7 +34,6 @@ typedef enum { UDP, TCP, DOT, HTTPS, HTTP } protocol_t; static const char *protocols[] = { "udp", "tcp", "dot", "https", "http-plain" }; static isc_mem_t *mctx = NULL; -static isc_nm_t *netmgr = NULL; static protocol_t protocol; static in_port_t port; @@ -167,7 +166,7 @@ parse_options(int argc, char **argv) { static void setup(void) { - isc_managers_create(&mctx, workers, &netmgr); + isc_managers_create(&mctx, workers); } static void @@ -176,7 +175,7 @@ teardown(void) { isc_tlsctx_free(&tls_ctx); } - isc_managers_destroy(&mctx, &netmgr); + isc_managers_destroy(&mctx); } static void @@ -244,22 +243,20 @@ run(void) { switch (protocol) { case UDP: - result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ALL, &sockaddr, - read_cb, NULL, &sock); + result = isc_nm_listenudp(ISC_NM_LISTEN_ALL, &sockaddr, read_cb, + NULL, &sock); break; case TCP: - result = isc_nm_listenstreamdns(netmgr, ISC_NM_LISTEN_ALL, - &sockaddr, read_cb, NULL, - accept_cb, NULL, 0, NULL, NULL, - ISC_NM_PROXY_NONE, &sock); + result = isc_nm_listenstreamdns( + ISC_NM_LISTEN_ALL, &sockaddr, read_cb, NULL, accept_cb, + NULL, 0, NULL, NULL, ISC_NM_PROXY_NONE, &sock); break; case DOT: { isc_tlsctx_createserver(NULL, NULL, &tls_ctx); result = isc_nm_listenstreamdns( - netmgr, ISC_NM_LISTEN_ALL, &sockaddr, read_cb, NULL, - accept_cb, NULL, 0, NULL, tls_ctx, ISC_NM_PROXY_NONE, - &sock); + ISC_NM_LISTEN_ALL, &sockaddr, read_cb, NULL, accept_cb, + NULL, 0, NULL, tls_ctx, ISC_NM_PROXY_NONE, &sock); break; } #if HAVE_LIBNGHTTP2 @@ -275,9 +272,9 @@ run(void) { eps, ISC_NM_HTTP_DEFAULT_PATH, read_cb, NULL); if (result == ISC_R_SUCCESS) { - result = isc_nm_listenhttp( - netmgr, ISC_NM_LISTEN_ALL, &sockaddr, 0, NULL, - tls_ctx, eps, 0, ISC_NM_PROXY_NONE, &sock); + result = isc_nm_listenhttp(ISC_NM_LISTEN_ALL, &sockaddr, + 0, NULL, tls_ctx, eps, 0, + ISC_NM_PROXY_NONE, &sock); } isc_nm_http_endpoints_detach(&eps); } break; diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index ba8d34c8a5..ace38273d0 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -118,7 +118,6 @@ static int onfly = 0; static char hexcookie[81]; static isc_sockaddr_t bind_any; -static isc_nm_t *netmgr = NULL; static dns_dispatchmgr_t *dispatchmgr = NULL; static dns_dispatch_t *dispatchvx = NULL; static dns_view_t *view = NULL; @@ -2057,7 +2056,7 @@ teardown(void *arg ISC_ATTR_UNUSED) { static void setup(void *arg ISC_ATTR_UNUSED) { - RUNCHECK(dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr)); + RUNCHECK(dns_dispatchmgr_create(mctx, &dispatchmgr)); set_source_ports(dispatchmgr); @@ -2095,7 +2094,7 @@ main(int argc, char *argv[]) { preparse_args(argc, argv); - isc_managers_create(&mctx, 1, &netmgr); + isc_managers_create(&mctx, 1); isc_nonce_buf(cookie_secret, sizeof(cookie_secret)); @@ -2175,6 +2174,6 @@ main(int argc, char *argv[]) { isc_mem_free(mctx, default_query.ecs_addr); } - isc_managers_destroy(&mctx, &netmgr); + isc_managers_destroy(&mctx); return 0; } diff --git a/lib/dns/client.c b/lib/dns/client.c index 82efefcb07..cfe1e497dc 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -74,7 +74,6 @@ struct dns_client { unsigned int attributes; isc_mem_t *mctx; isc_loop_t *loop; - isc_nm_t *nm; dns_dispatchmgr_t *dispatchmgr; dns_dispatch_t *dispatchv4; dns_dispatch_t *dispatchv6; @@ -197,7 +196,7 @@ getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr, } static isc_result_t -createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_nm_t *nm, +createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_tlsctx_cache_t *tlsctx_client_cache, dns_dispatchmgr_t *dispatchmgr, dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6, dns_view_t **viewp) { @@ -209,8 +208,8 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, isc_nm_t *nm, /* Initialize view security roots */ dns_view_initsecroots(view); - CHECK(dns_view_createresolver(view, nm, 0, tlsctx_client_cache, - dispatchv4, dispatchv6)); + CHECK(dns_view_createresolver(view, 0, tlsctx_client_cache, dispatchv4, + dispatchv6)); CHECK(dns_db_create(mctx, CACHEDB_DEFAULT, dns_rootname, dns_dbtype_cache, rdclass, 0, NULL, &view->cachedb)); @@ -224,7 +223,7 @@ cleanup: } isc_result_t -dns_client_create(isc_mem_t *mctx, isc_nm_t *nm, unsigned int options, +dns_client_create(isc_mem_t *mctx, unsigned int options, isc_tlsctx_cache_t *tlsctx_client_cache, dns_client_t **clientp, const isc_sockaddr_t *localaddr4, const isc_sockaddr_t *localaddr6) { @@ -235,7 +234,6 @@ dns_client_create(isc_mem_t *mctx, isc_nm_t *nm, unsigned int options, dns_view_t *view = NULL; REQUIRE(mctx != NULL); - REQUIRE(nm != NULL); REQUIRE(tlsctx_client_cache != NULL); REQUIRE(clientp != NULL && *clientp == NULL); @@ -244,12 +242,11 @@ dns_client_create(isc_mem_t *mctx, isc_nm_t *nm, unsigned int options, client = isc_mem_get(mctx, sizeof(*client)); *client = (dns_client_t){ .loop = isc_loop_get(0), - .nm = nm, .max_restarts = DEF_MAX_RESTARTS, .max_queries = DEF_MAX_QUERIES, }; - result = dns_dispatchmgr_create(mctx, nm, &client->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &client->dispatchmgr); if (result != ISC_R_SUCCESS) { goto cleanup_client; } @@ -286,7 +283,7 @@ dns_client_create(isc_mem_t *mctx, isc_nm_t *nm, unsigned int options, isc_refcount_init(&client->references, 1); /* Create the default view for class IN */ - result = createview(mctx, dns_rdataclass_in, nm, tlsctx_client_cache, + result = createview(mctx, dns_rdataclass_in, tlsctx_client_cache, client->dispatchmgr, dispatchv4, dispatchv6, &view); if (result != ISC_R_SUCCESS) { goto cleanup_references; diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index 8e1bb9dfdf..752815fabe 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -13,6 +13,10 @@ /*! \file */ +/* + * FIXME: Might need dns_dispatch_shuttingdown() + */ + #include #include #include @@ -54,7 +58,6 @@ struct dns_dispatchmgr { isc_mem_t *mctx; dns_acl_t *blackhole; isc_stats_t *stats; - isc_nm_t *nm; uint32_t nloops; @@ -969,8 +972,7 @@ setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset, */ isc_result_t -dns_dispatchmgr_create(isc_mem_t *mctx, isc_nm_t *nm, - dns_dispatchmgr_t **mgrp) { +dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp) { dns_dispatchmgr_t *mgr = NULL; isc_portset_t *v4portset = NULL; isc_portset_t *v6portset = NULL; @@ -991,7 +993,6 @@ dns_dispatchmgr_create(isc_mem_t *mctx, isc_nm_t *nm, isc_refcount_init(&mgr->references, 1); isc_mem_attach(mctx, &mgr->mctx); - isc_nm_attach(nm, &mgr->nm); mgr->tcps = isc_mem_cget(mgr->mctx, mgr->nloops, sizeof(mgr->tcps[0])); for (size_t i = 0; i < mgr->nloops; i++) { @@ -1078,8 +1079,6 @@ dispatchmgr_destroy(dns_dispatchmgr_t *mgr) { sizeof(in_port_t)); } - isc_nm_detach(&mgr->nm); - isc_mem_putanddetach(&mgr->mctx, mgr, sizeof(dns_dispatchmgr_t)); } @@ -1091,13 +1090,6 @@ dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, isc_stats_t *stats) { isc_stats_attach(stats, &mgr->stats); } -isc_nm_t * -dns_dispatchmgr_getnetmgr(dns_dispatchmgr_t *mgr) { - REQUIRE(VALID_DISPATCHMGR(mgr)); - - return mgr->nm; -} - /* * Allocate and set important limits. */ @@ -1952,8 +1944,8 @@ udp_dispatch_connect(dns_dispatch_t *disp, dns_dispentry_t *resp) { dns_dispentry_ref(resp); /* DISPENTRY004 */ ISC_LIST_APPEND(disp->pending, resp, plink); - isc_nm_udpconnect(disp->mgr->nm, &resp->local, &resp->peer, - udp_connected, resp, resp->timeout); + isc_nm_udpconnect(&resp->local, &resp->peer, udp_connected, resp, + resp->timeout); } static inline const char * @@ -2024,8 +2016,8 @@ tcp_dispatch_connect(dns_dispatch_t *disp, dns_dispentry_t *resp) { const char *hostname = get_tls_sni_hostname(resp); - isc_nm_streamdnsconnect(disp->mgr->nm, &disp->local, - &disp->peer, tcp_connected, disp, + isc_nm_streamdnsconnect(&disp->local, &disp->peer, + tcp_connected, disp, resp->connect_timeout, tlsctx, hostname, sess_cache, ISC_NM_PROXY_NONE, NULL); break; diff --git a/lib/dns/include/dns/client.h b/lib/dns/include/dns/client.h index eb04547089..695c829880 100644 --- a/lib/dns/include/dns/client.h +++ b/lib/dns/include/dns/client.h @@ -95,7 +95,7 @@ typedef struct dns_clientresume { } dns_clientresume_t; /* too long? */ isc_result_t -dns_client_create(isc_mem_t *mctx, isc_nm_t *nm, unsigned int options, +dns_client_create(isc_mem_t *mctx, unsigned int options, isc_tlsctx_cache_t *tlsctx_client_cache, dns_client_t **clientp, const isc_sockaddr_t *localaddr4, const isc_sockaddr_t *localaddr6); diff --git a/lib/dns/include/dns/dispatch.h b/lib/dns/include/dns/dispatch.h index 047e42fde2..3e54f00662 100644 --- a/lib/dns/include/dns/dispatch.h +++ b/lib/dns/include/dns/dispatch.h @@ -75,7 +75,7 @@ typedef enum dns_dispatchopt { } dns_dispatchopt_t; isc_result_t -dns_dispatchmgr_create(isc_mem_t *mctx, isc_nm_t *nm, dns_dispatchmgr_t **mgrp); +dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp); /*%< * Creates a new dispatchmgr object, and sets the available ports * to the default range (1024-65535). @@ -161,15 +161,6 @@ dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, isc_stats_t *stats); * (see dns/stats.h). */ -isc_nm_t * -dns_dispatchmgr_getnetmgr(dns_dispatchmgr_t *mgr); -/*%< - * Get the network manager object associated with the dispatch manager. - * - * Requires: - *\li disp is valid - */ - isc_result_t dns_dispatch_createudp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *localaddr, dns_dispatch_t **dispp); diff --git a/lib/dns/include/dns/resolver.h b/lib/dns/include/dns/resolver.h index 03fee94bb3..14f510696e 100644 --- a/lib/dns/include/dns/resolver.h +++ b/lib/dns/include/dns/resolver.h @@ -170,7 +170,7 @@ enum { #define DNS_QMIN_MAX_NO_DELEGATION 3 isc_result_t -dns_resolver_create(dns_view_t *view, isc_nm_t *nm, unsigned int options, +dns_resolver_create(dns_view_t *view, unsigned int options, isc_tlsctx_cache_t *tlsctx_cache, dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6, dns_resolver_t **resp); diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index e92a5603ef..9f7c0d43f9 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -362,8 +362,8 @@ dns_view_weakdetach(dns_view_t **targetp); */ isc_result_t -dns_view_createresolver(dns_view_t *view, isc_nm_t *netmgr, - unsigned int options, isc_tlsctx_cache_t *tlsctx_cache, +dns_view_createresolver(dns_view_t *view, unsigned int options, + isc_tlsctx_cache_t *tlsctx_cache, dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6); /*%< * Create a resolver and address database for the view. diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 50f65c1921..193121b920 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -1706,7 +1706,7 @@ dns_zone_prepare_shutdown(dns_zone_t *zone); */ void -dns_zonemgr_create(isc_mem_t *mctx, isc_nm_t *netmgr, dns_zonemgr_t **zmgrp); +dns_zonemgr_create(isc_mem_t *mctx, dns_zonemgr_t **zmgrp); /*%< * Create a zone manager. * diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index 7b56442a15..dd61162d9a 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -551,7 +551,6 @@ struct dns_resolver { isc_mutex_t lock; isc_mutex_t primelock; dns_rdataclass_t rdclass; - isc_nm_t *nm; dns_view_t *view; bool frozen; unsigned int options; @@ -9848,7 +9847,7 @@ spillattimer_countdown(void *arg) { } isc_result_t -dns_resolver_create(dns_view_t *view, isc_nm_t *nm, unsigned int options, +dns_resolver_create(dns_view_t *view, unsigned int options, isc_tlsctx_cache_t *tlsctx_cache, dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6, dns_resolver_t **resp) { @@ -9866,7 +9865,6 @@ dns_resolver_create(dns_view_t *view, isc_nm_t *nm, unsigned int options, res = isc_mem_get(view->mctx, sizeof(*res)); *res = (dns_resolver_t){ .rdclass = view->rdclass, - .nm = nm, .options = options, .tlsctx_cache = tlsctx_cache, .spillatmin = 10, diff --git a/lib/dns/view.c b/lib/dns/view.c index 33ce0c6ad6..4193a43b9e 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -536,8 +536,8 @@ dns_view_weakdetach(dns_view_t **viewp) { } isc_result_t -dns_view_createresolver(dns_view_t *view, isc_nm_t *netmgr, - unsigned int options, isc_tlsctx_cache_t *tlsctx_cache, +dns_view_createresolver(dns_view_t *view, unsigned int options, + isc_tlsctx_cache_t *tlsctx_cache, dns_dispatch_t *dispatchv4, dns_dispatch_t *dispatchv6) { isc_result_t result; @@ -548,8 +548,8 @@ dns_view_createresolver(dns_view_t *view, isc_nm_t *netmgr, REQUIRE(view->resolver == NULL); REQUIRE(view->dispatchmgr != NULL); - result = dns_resolver_create(view, netmgr, options, tlsctx_cache, - dispatchv4, dispatchv6, &view->resolver); + result = dns_resolver_create(view, options, tlsctx_cache, dispatchv4, + dispatchv6, &view->resolver); if (result != ISC_R_SUCCESS) { return result; } diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index 609bad2118..91515fdab1 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -1314,8 +1314,7 @@ xfrin_start(dns_xfrin_t *xfr) { goto failure; } - primaries_timeout = - isc_nm_getprimariestimeout(dns_dispatchmgr_getnetmgr(dispmgr)); + primaries_timeout = isc_nm_getprimariestimeout(); result = dns_dispatch_createtcp(dispmgr, &xfr->sourceaddr, &xfr->primaryaddr, xfr->transport, DNS_DISPATCHOPT_UNSHARED, &xfr->disp); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index d3a507f5e1..f015a2c01e 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -616,7 +616,6 @@ struct dns_zonemgr { unsigned int magic; isc_mem_t *mctx; isc_refcount_t refs; - isc_nm_t *netmgr; uint32_t workers; isc_mem_t **mctxpool; isc_ratelimiter_t *checkdsrl; @@ -12930,9 +12929,8 @@ again: zmgr_tlsctx_attach(notify->zone->zmgr, &zmgr_tlsctx_cache); - const unsigned int connect_timeout = - isc_nm_getinitialtimeout(notify->zone->zmgr->netmgr) / - MS_PER_SEC; + const unsigned int connect_timeout = isc_nm_getinitialtimeout() / + MS_PER_SEC; result = dns_request_create( notify->zone->view->requestmgr, message, &src, ¬ify->dst, notify->transport, zmgr_tlsctx_cache, options, key, @@ -14856,8 +14854,8 @@ again: } zone_iattach(zone, &(dns_zone_t *){ NULL }); - const unsigned int connect_timeout = - isc_nm_getprimariestimeout(zone->zmgr->netmgr) / MS_PER_SEC; + const unsigned int connect_timeout = isc_nm_getprimariestimeout() / + MS_PER_SEC; result = dns_request_create( zone->view->requestmgr, message, &zone->sourceaddr, &curraddr, NULL, NULL, options, key, connect_timeout, TCP_REQUEST_TIMEOUT, @@ -15131,8 +15129,7 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) { cb_args->stub = stub; cb_args->tsig_key = key; cb_args->udpsize = udpsize; - cb_args->connect_timeout = - isc_nm_getprimariestimeout(zone->zmgr->netmgr) / MS_PER_SEC; + cb_args->connect_timeout = isc_nm_getprimariestimeout() / MS_PER_SEC; cb_args->timeout = TCP_REQUEST_TIMEOUT; cb_args->reqnsid = reqnsid; @@ -18969,8 +18966,8 @@ next: } zmgr_tlsctx_attach(zone->zmgr, &zmgr_tlsctx_cache); - const unsigned int connect_timeout = - isc_nm_getprimariestimeout(zone->zmgr->netmgr) / MS_PER_SEC; + const unsigned int connect_timeout = isc_nm_getprimariestimeout() / + MS_PER_SEC; result = dns_request_createraw( forward->zone->view->requestmgr, forward->msgbuf, &src, &forward->addr, forward->transport, zmgr_tlsctx_cache, @@ -19317,18 +19314,16 @@ zonemgr_keymgmt_delete(dns_zonemgr_t *zmgr, dns_keyfileio_t **deleted) { } void -dns_zonemgr_create(isc_mem_t *mctx, isc_nm_t *netmgr, dns_zonemgr_t **zmgrp) { +dns_zonemgr_create(isc_mem_t *mctx, dns_zonemgr_t **zmgrp) { dns_zonemgr_t *zmgr = NULL; isc_loop_t *loop = isc_loop(); REQUIRE(mctx != NULL); - REQUIRE(netmgr != NULL); REQUIRE(zmgrp != NULL && *zmgrp == NULL); zmgr = isc_mem_get(mctx, sizeof(*zmgr)); *zmgr = (dns_zonemgr_t){ - .netmgr = netmgr, .workers = isc_loopmgr_nloops(), .transfersin = 10, .transfersperns = 2, @@ -21517,9 +21512,8 @@ checkds_send_toaddr(void *arg) { "checkds: create request for DS query to %s", addrbuf); options |= DNS_REQUESTOPT_TCP; - const unsigned int connect_timeout = - isc_nm_getinitialtimeout(checkds->zone->zmgr->netmgr) / - MS_PER_SEC; + const unsigned int connect_timeout = isc_nm_getinitialtimeout() / + MS_PER_SEC; result = dns_request_create( checkds->zone->view->requestmgr, message, &src, &checkds->dst, NULL, NULL, options, key, connect_timeout, TCP_REQUEST_TIMEOUT, diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index faa4b5c552..83cbb41722 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -226,14 +226,13 @@ static void (*finishhook)(void) = NULL; #endif /* ENABLE_AFL */ isc_result_t -isc_httpdmgr_create(isc_nm_t *nm, isc_mem_t *mctx, isc_sockaddr_t *addr, +isc_httpdmgr_create(isc_mem_t *mctx, isc_sockaddr_t *addr, isc_httpdclientok_t *client_ok, isc_httpdondestroy_t *ondestroy, void *cb_arg, isc_httpdmgr_t **httpdmgrp) { isc_result_t result; isc_httpdmgr_t *httpdmgr = NULL; - REQUIRE(nm != NULL); REQUIRE(mctx != NULL); REQUIRE(httpdmgrp != NULL && *httpdmgrp == NULL); @@ -252,8 +251,8 @@ isc_httpdmgr_create(isc_nm_t *nm, isc_mem_t *mctx, isc_sockaddr_t *addr, isc_refcount_init(&httpdmgr->references, 1); - CHECK(isc_nm_listentcp(nm, ISC_NM_LISTEN_ONE, addr, httpd_newconn, - httpdmgr, 5, NULL, &httpdmgr->sock)); + CHECK(isc_nm_listentcp(ISC_NM_LISTEN_ONE, addr, httpd_newconn, httpdmgr, + 5, NULL, &httpdmgr->sock)); httpdmgr->magic = HTTPDMGR_MAGIC; *httpdmgrp = httpdmgr; diff --git a/lib/isc/include/isc/httpd.h b/lib/isc/include/isc/httpd.h index 23472d0f82..9321603e18 100644 --- a/lib/isc/include/isc/httpd.h +++ b/lib/isc/include/isc/httpd.h @@ -35,7 +35,7 @@ typedef isc_result_t(isc_httpdaction_t)( typedef bool(isc_httpdclientok_t)(const isc_sockaddr_t *, void *); isc_result_t -isc_httpdmgr_create(isc_nm_t *nm, isc_mem_t *mctx, isc_sockaddr_t *addr, +isc_httpdmgr_create(isc_mem_t *mctx, isc_sockaddr_t *addr, isc_httpdclientok_t *client_ok, isc_httpdondestroy_t *ondestroy, void *cb_arg, isc_httpdmgr_t **httpdmgrp); diff --git a/lib/isc/include/isc/managers.h b/lib/isc/include/isc/managers.h index 8c6f37220d..5320506c24 100644 --- a/lib/isc/include/isc/managers.h +++ b/lib/isc/include/isc/managers.h @@ -20,7 +20,7 @@ typedef struct isc_managers isc_managers_t; void -isc_managers_create(isc_mem_t **mctx, uint32_t workers, isc_nm_t **netmgrp); +isc_managers_create(isc_mem_t **mctx, uint32_t workers); void -isc_managers_destroy(isc_mem_t **mctx, isc_nm_t **netmgrp); +isc_managers_destroy(isc_mem_t **mctx); diff --git a/lib/isc/include/isc/netmgr.h b/lib/isc/include/isc/netmgr.h index 2518527a0a..fcb75873ce 100644 --- a/lib/isc/include/isc/netmgr.h +++ b/lib/isc/include/isc/netmgr.h @@ -118,24 +118,15 @@ typedef enum isc_nm_proxy_type { */ void -isc_netmgr_create(isc_mem_t *mctx, isc_nm_t **netgmrp); +isc_netmgr_create(isc_mem_t *mctx); /*%< * Creates a new network manager and starts it running when loopmgr is started. */ -#if ISC_NETMGR_TRACE -#define isc_nm_ref(ptr) isc_nm__ref(ptr, __func__, __FILE__, __LINE__) -#define isc_nm_unref(ptr) isc_nm__unref(ptr, __func__, __FILE__, __LINE__) -#define isc_nm_attach(ptr, ptrp) \ - isc_nm__attach(ptr, ptrp, __func__, __FILE__, __LINE__) -#define isc_nm_detach(ptrp) isc_nm__detach(ptrp, __func__, __FILE__, __LINE__) -ISC_REFCOUNT_TRACE_DECL(isc_nm); -#else -ISC_REFCOUNT_DECL(isc_nm); -#endif - +void +isc_netmgr_destroy(void); /*%< - * Attach/detach a network manager. When all references have been + * Destroy a network manager. When all references have been * released, the network manager is shut down, freeing all resources. */ @@ -283,15 +274,9 @@ isc_nmhandle_real_localaddr(isc_nmhandle_t *handle); * 'isc_nmhandle_localaddr()' instead. */ -isc_nm_t * -isc_nmhandle_netmgr(isc_nmhandle_t *handle); -/*%< - * Return a pointer to the netmgr object for the given handle. - */ - isc_result_t -isc_nm_listenudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, - isc_nm_recv_cb_t cb, void *cbarg, isc_nmsocket_t **sockp); +isc_nm_listenudp(uint32_t workers, isc_sockaddr_t *iface, isc_nm_recv_cb_t cb, + void *cbarg, isc_nmsocket_t **sockp); /*%< * Start listening for UDP packets on interface 'iface' using net manager * 'mgr'. @@ -303,8 +288,8 @@ isc_nm_listenudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, */ void -isc_nm_udpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, - isc_nm_cb_t cb, void *cbarg, unsigned int timeout); +isc_nm_udpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, isc_nm_cb_t cb, + void *cbarg, unsigned int timeout); /*%< * Open a UDP socket, bind to 'local' and connect to 'peer', and * immediately call 'cb' with a handle so that the caller can begin @@ -317,7 +302,7 @@ isc_nm_udpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, */ isc_result_t -isc_nm_routeconnect(isc_nm_t *mgr, isc_nm_cb_t cb, void *cbarg); +isc_nm_routeconnect(isc_nm_cb_t cb, void *cbarg); /*%< * Open a route/netlink socket and call 'cb', so the caller can be * begin listening for interface changes. This behaves similarly to @@ -328,7 +313,7 @@ isc_nm_routeconnect(isc_nm_t *mgr, isc_nm_cb_t cb, void *cbarg); */ isc_result_t -isc_nm_listenproxyudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listenproxyudp(uint32_t workers, isc_sockaddr_t *iface, isc_nm_recv_cb_t cb, void *cbarg, isc_nmsocket_t **sockp); /*%< * The same as `isc_nm_listenudp()`, but PROXYv2 headers are @@ -336,9 +321,8 @@ isc_nm_listenproxyudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, */ void -isc_nm_proxyudpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, - isc_sockaddr_t *peer, isc_nm_cb_t cb, void *cbarg, - unsigned int timeout, +isc_nm_proxyudpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, + isc_nm_cb_t cb, void *cbarg, unsigned int timeout, isc_nm_proxyheader_info_t *proxy_info); /*%< * The same as `isc_nm_udpconnect()`, but PROXYv2 headers are added @@ -402,7 +386,7 @@ isc_nm_send(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb, */ isc_result_t -isc_nm_listentcp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listentcp(uint32_t workers, isc_sockaddr_t *iface, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, isc_nmsocket_t **sockp); /*%< @@ -421,7 +405,7 @@ isc_nm_listentcp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, */ void -isc_nm_tcpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, +isc_nm_tcpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, isc_nm_cb_t connect_cb, void *connect_cbarg, unsigned int timeout); /*%< @@ -438,7 +422,7 @@ isc_nm_tcpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, */ isc_result_t -isc_nm_listenstreamdns(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listenstreamdns(uint32_t workers, isc_sockaddr_t *iface, isc_nm_recv_cb_t recv_cb, void *recv_cbarg, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, isc_tlsctx_t *tlsctx, @@ -469,7 +453,7 @@ isc_nm_listenstreamdns(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, */ isc_result_t -isc_nm_listenproxystream(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listenproxystream(uint32_t workers, isc_sockaddr_t *iface, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, isc_tlsctx_t *tlsctx, isc_nmsocket_t **sockp); @@ -492,10 +476,9 @@ isc_nm_listenproxystream(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, */ void -isc_nm_proxystreamconnect(isc_nm_t *mgr, isc_sockaddr_t *local, - isc_sockaddr_t *peer, isc_nm_cb_t cb, void *cbarg, - unsigned int timeout, isc_tlsctx_t *tlsctx, - const char *sni_hostname, +isc_nm_proxystreamconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, + isc_nm_cb_t cb, void *cbarg, unsigned int timeout, + isc_tlsctx_t *tlsctx, const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, isc_nm_proxyheader_info_t *proxy_info); /*%< @@ -537,7 +520,7 @@ isc_nm_proxyheader_info_init_complete(isc_nm_proxyheader_info_t *restrict info, */ void -isc_nm_setinitialtimeout(isc_nm_t *mgr, uint32_t timeout_ms); +isc_nm_setinitialtimeout(uint32_t timeout_ms); /*%< * Sets the initial TCP timeout value (in milliseconds). * @@ -546,7 +529,7 @@ isc_nm_setinitialtimeout(isc_nm_t *mgr, uint32_t timeout_ms); */ void -isc_nm_setprimariestimeout(isc_nm_t *mgr, uint32_t timeout_ms); +isc_nm_setprimariestimeout(uint32_t timeout_ms); /*%< * Sets the primary servers connect TCP timeout value (in milliseconds). * @@ -555,7 +538,7 @@ isc_nm_setprimariestimeout(isc_nm_t *mgr, uint32_t timeout_ms); */ void -isc_nm_setidletimeout(isc_nm_t *mgr, uint32_t timeout_ms); +isc_nm_setidletimeout(uint32_t timeout_ms); /*%< * Sets the idle TCP timeout value (in milliseconds). * @@ -564,7 +547,7 @@ isc_nm_setidletimeout(isc_nm_t *mgr, uint32_t timeout_ms); */ void -isc_nm_setkeepalivetimeout(isc_nm_t *mgr, uint32_t timeout_ms); +isc_nm_setkeepalivetimeout(uint32_t timeout_ms); /*%< * Sets the keepalive TCP timeout value (in milliseconds), and the timeout value * to advertise in responses using the EDNS TCP Keepalive option. @@ -574,7 +557,7 @@ isc_nm_setkeepalivetimeout(isc_nm_t *mgr, uint32_t timeout_ms); */ void -isc_nm_setadvertisedtimeout(isc_nm_t *mgr, uint32_t timeout_ms); +isc_nm_setadvertisedtimeout(uint32_t timeout_ms); /*%< * Sets the advertised TCP timeout value (in milliseconds). * @@ -583,8 +566,8 @@ isc_nm_setadvertisedtimeout(isc_nm_t *mgr, uint32_t timeout_ms); */ void -isc_nm_setnetbuffers(isc_nm_t *mgr, int32_t recv_tcp, int32_t send_tcp, - int32_t recv_udp, int32_t send_udp); +isc_nm_setnetbuffers(int32_t recv_tcp, int32_t send_tcp, int32_t recv_udp, + int32_t send_udp); /*%< * If not 0, sets the SO_RCVBUF and SO_SNDBUF socket options for TCP and UDP * respectively. @@ -594,9 +577,9 @@ isc_nm_setnetbuffers(isc_nm_t *mgr, int32_t recv_tcp, int32_t send_tcp, */ bool -isc_nm_getloadbalancesockets(isc_nm_t *mgr); +isc_nm_getloadbalancesockets(void); void -isc_nm_setloadbalancesockets(isc_nm_t *mgr, bool enabled); +isc_nm_setloadbalancesockets(bool enabled); /*%< * Get and set value of load balancing of the sockets. * @@ -605,7 +588,7 @@ isc_nm_setloadbalancesockets(isc_nm_t *mgr, bool enabled); */ uint32_t -isc_nm_getinitialtimeout(isc_nm_t *mgr); +isc_nm_getinitialtimeout(void); /*%< * Gets the initial TCP timeout value in milliseconds. * @@ -614,7 +597,7 @@ isc_nm_getinitialtimeout(isc_nm_t *mgr); */ uint32_t -isc_nm_getprimariestimeout(isc_nm_t *mgr); +isc_nm_getprimariestimeout(void); /*%< * Gets the primary servers connect TCP timeout value in milliseconds. * @@ -623,7 +606,7 @@ isc_nm_getprimariestimeout(isc_nm_t *mgr); */ uint32_t -isc_nm_getidletimeout(isc_nm_t *mgr); +isc_nm_getidletimeout(void); /*%< * Gets the idle TCP timeout value in milliseconds. * @@ -632,7 +615,7 @@ isc_nm_getidletimeout(isc_nm_t *mgr); */ uint32_t -isc_nm_getkeepalivetimeout(isc_nm_t *mgr); +isc_nm_getkeepalivetimeout(void); /*%< * Gets the keepalive TCP timeout value in milliseconds. * @@ -641,7 +624,7 @@ isc_nm_getkeepalivetimeout(isc_nm_t *mgr); */ uint32_t -isc_nm_getadvertisedtimeout(isc_nm_t *mgr); +isc_nm_getadvertisedtimeout(void); /*%< * Gets the advertised TCP timeout value in milliseconds. * @@ -650,14 +633,14 @@ isc_nm_getadvertisedtimeout(isc_nm_t *mgr); */ void -isc_nm_maxudp(isc_nm_t *mgr, uint32_t maxudp); +isc_nm_maxudp(uint32_t maxudp); /*%< * Simulate a broken firewall that blocks UDP messages larger than a given * size. */ void -isc_nm_setstats(isc_nm_t *mgr, isc_stats_t *stats); +isc_nm_setstats(isc_stats_t *stats); /*%< * Set a socket statistics counter set 'stats' for 'mgr'. * @@ -679,10 +662,9 @@ isc_nm_checkaddr(const isc_sockaddr_t *addr, isc_socktype_t type); */ void -isc_nm_streamdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, - isc_sockaddr_t *peer, isc_nm_cb_t cb, void *cbarg, - unsigned int timeout, isc_tlsctx_t *tlsctx, - const char *sni_hostname, +isc_nm_streamdnsconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, + isc_nm_cb_t cb, void *cbarg, unsigned int timeout, + isc_tlsctx_t *tlsctx, const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, isc_nm_proxy_type_t proxy_type, isc_nm_proxyheader_info_t *proxy_info); @@ -731,13 +713,13 @@ isc_nmhandle_proxy_type(isc_nmhandle_t *handle); */ isc_result_t -isc_nm_listentls(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listentls(uint32_t workers, isc_sockaddr_t *iface, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, isc_tlsctx_t *sslctx, bool proxy, isc_nmsocket_t **sockp); void -isc_nm_tlsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, +isc_nm_tlsconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, isc_nm_cb_t connect_cb, void *connect_cbarg, isc_tlsctx_t *ctx, const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, @@ -749,16 +731,16 @@ isc_nm_tlsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, #define ISC_NM_HTTP_DEFAULT_PATH "/dns-query" void -isc_nm_httpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, - const char *uri, bool POST, isc_nm_cb_t cb, void *cbarg, - isc_tlsctx_t *ctx, const char *sni_hostname, +isc_nm_httpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, const char *uri, + bool POST, isc_nm_cb_t cb, void *cbarg, isc_tlsctx_t *ctx, + const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, unsigned int timeout, isc_nm_proxy_type_t proxy_type, isc_nm_proxyheader_info_t *proxy_info); isc_result_t -isc_nm_listenhttp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, - int backlog, isc_quota_t *quota, isc_tlsctx_t *ctx, +isc_nm_listenhttp(uint32_t workers, isc_sockaddr_t *iface, int backlog, + isc_quota_t *quota, isc_tlsctx_t *ctx, isc_nm_http_endpoints_t *eps, uint32_t max_concurrent_streams, isc_nm_proxy_type_t proxy_type, isc_nmsocket_t **sockp); diff --git a/lib/isc/include/isc/types.h b/lib/isc/include/isc/types.h index b02239e24c..3ab5f5d771 100644 --- a/lib/isc/include/isc/types.h +++ b/lib/isc/include/isc/types.h @@ -54,7 +54,6 @@ typedef struct isc_mem isc_mem_t; /*%< Memory */ typedef struct isc_mempool isc_mempool_t; /*%< Memory Pool */ typedef struct isc_netaddr isc_netaddr_t; /*%< Net Address */ typedef struct isc_netprefix isc_netprefix_t; /*%< Net Prefix */ -typedef struct isc_nm isc_nm_t; /*%< Network manager */ typedef struct isc_nmsocket isc_nmsocket_t; /*%< Network manager socket */ typedef struct isc_nmhandle isc_nmhandle_t; /*%< Network manager handle */ typedef struct isc_portset isc_portset_t; /*%< Port Set */ diff --git a/lib/isc/managers.c b/lib/isc/managers.c index 3df53cdaac..ed8730745f 100644 --- a/lib/isc/managers.c +++ b/lib/isc/managers.c @@ -18,30 +18,27 @@ #include void -isc_managers_create(isc_mem_t **mctxp, uint32_t workers, isc_nm_t **netmgrp) { +isc_managers_create(isc_mem_t **mctxp, uint32_t workers) { REQUIRE(mctxp != NULL && *mctxp == NULL); isc_mem_create("managers", mctxp); INSIST(*mctxp != NULL); isc_loopmgr_create(*mctxp, workers); - REQUIRE(netmgrp != NULL && *netmgrp == NULL); - isc_netmgr_create(*mctxp, netmgrp); - INSIST(*netmgrp != NULL); + isc_netmgr_create(*mctxp); isc_rwlock_setworkers(workers); } void -isc_managers_destroy(isc_mem_t **mctxp, isc_nm_t **netmgrp) { +isc_managers_destroy(isc_mem_t **mctxp) { REQUIRE(mctxp != NULL && *mctxp != NULL); - REQUIRE(netmgrp != NULL && *netmgrp != NULL); /* * The sequence of operations here is important: */ - isc_nm_detach(netmgrp); + isc_netmgr_destroy(); isc_loopmgr_destroy(); isc_mem_detach(mctxp); } diff --git a/lib/isc/netmgr/http.c b/lib/isc/netmgr/http.c index ad234bbadc..15eb00a3a2 100644 --- a/lib/isc/netmgr/http.c +++ b/lib/isc/netmgr/http.c @@ -1892,24 +1892,21 @@ error: } void -isc_nm_httpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, - const char *uri, bool post, isc_nm_cb_t cb, void *cbarg, - isc_tlsctx_t *tlsctx, const char *sni_hostname, +isc_nm_httpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, const char *uri, + bool post, isc_nm_cb_t cb, void *cbarg, isc_tlsctx_t *tlsctx, + const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, unsigned int timeout, isc_nm_proxy_type_t proxy_type, isc_nm_proxyheader_info_t *proxy_info) { isc_sockaddr_t local_interface; isc_nmsocket_t *sock = NULL; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_current(); - REQUIRE(VALID_NM(mgr)); REQUIRE(cb != NULL); REQUIRE(peer != NULL); REQUIRE(uri != NULL); REQUIRE(*uri != '\0'); - worker = &mgr->workers[isc_tid()]; - if (isc__nm_closing(worker)) { cb(NULL, ISC_R_SHUTTINGDOWN, cbarg); return; @@ -1963,32 +1960,32 @@ isc_nm_httpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, switch (proxy_type) { case ISC_NM_PROXY_NONE: if (tlsctx != NULL) { - isc_nm_tlsconnect(mgr, local, peer, - transport_connect_cb, sock, tlsctx, - sni_hostname, client_sess_cache, - timeout, false, NULL); + isc_nm_tlsconnect(local, peer, transport_connect_cb, + sock, tlsctx, sni_hostname, + client_sess_cache, timeout, false, + NULL); } else { - isc_nm_tcpconnect(mgr, local, peer, - transport_connect_cb, sock, timeout); + isc_nm_tcpconnect(local, peer, transport_connect_cb, + sock, timeout); } break; case ISC_NM_PROXY_PLAIN: if (tlsctx != NULL) { - isc_nm_tlsconnect(mgr, local, peer, - transport_connect_cb, sock, tlsctx, - sni_hostname, client_sess_cache, - timeout, true, proxy_info); + isc_nm_tlsconnect(local, peer, transport_connect_cb, + sock, tlsctx, sni_hostname, + client_sess_cache, timeout, true, + proxy_info); } else { isc_nm_proxystreamconnect( - mgr, local, peer, transport_connect_cb, sock, + local, peer, transport_connect_cb, sock, timeout, NULL, NULL, NULL, proxy_info); } break; case ISC_NM_PROXY_ENCRYPTED: INSIST(tlsctx != NULL); - isc_nm_proxystreamconnect( - mgr, local, peer, transport_connect_cb, sock, timeout, - tlsctx, sni_hostname, client_sess_cache, proxy_info); + isc_nm_proxystreamconnect(local, peer, transport_connect_cb, + sock, timeout, tlsctx, sni_hostname, + client_sess_cache, proxy_info); break; default: UNREACHABLE(); @@ -2943,20 +2940,18 @@ httplisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { } isc_result_t -isc_nm_listenhttp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, - int backlog, isc_quota_t *quota, isc_tlsctx_t *ctx, +isc_nm_listenhttp(uint32_t workers, isc_sockaddr_t *iface, int backlog, + isc_quota_t *quota, isc_tlsctx_t *ctx, isc_nm_http_endpoints_t *eps, uint32_t max_concurrent_streams, isc_nm_proxy_type_t proxy_type, isc_nmsocket_t **sockp) { isc_nmsocket_t *sock = NULL; isc_result_t result = ISC_R_FAILURE; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_current(); - REQUIRE(VALID_NM(mgr)); REQUIRE(!ISC_LIST_EMPTY(eps->handlers)); REQUIRE(atomic_load(&eps->in_use) == false); REQUIRE(isc_tid() == 0); - worker = &mgr->workers[isc_tid()]; sock = isc_mempool_get(worker->nmsocket_pool); isc__nmsocket_init(sock, worker, isc_nm_httplistener, iface, NULL); http_initsocket(sock); @@ -2972,10 +2967,10 @@ isc_nm_listenhttp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, case ISC_NM_PROXY_NONE: if (ctx != NULL) { result = isc_nm_listentls( - mgr, workers, iface, httplisten_acceptcb, sock, + workers, iface, httplisten_acceptcb, sock, backlog, quota, ctx, false, &sock->outer); } else { - result = isc_nm_listentcp(mgr, workers, iface, + result = isc_nm_listentcp(workers, iface, httplisten_acceptcb, sock, backlog, quota, &sock->outer); } @@ -2983,18 +2978,18 @@ isc_nm_listenhttp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, case ISC_NM_PROXY_PLAIN: if (ctx != NULL) { result = isc_nm_listentls( - mgr, workers, iface, httplisten_acceptcb, sock, + workers, iface, httplisten_acceptcb, sock, backlog, quota, ctx, true, &sock->outer); } else { result = isc_nm_listenproxystream( - mgr, workers, iface, httplisten_acceptcb, sock, + workers, iface, httplisten_acceptcb, sock, backlog, quota, NULL, &sock->outer); } break; case ISC_NM_PROXY_ENCRYPTED: INSIST(ctx != NULL); result = isc_nm_listenproxystream( - mgr, workers, iface, httplisten_acceptcb, sock, backlog, + workers, iface, httplisten_acceptcb, sock, backlog, quota, ctx, &sock->outer); break; default: @@ -3388,7 +3383,7 @@ http_set_endpoints_cb(void *arg) { const isc_tid_t tid = isc_tid(); isc_nmsocket_t *listener = data->listener; isc_nm_http_endpoints_t *endpoints = data->endpoints; - isc__networker_t *worker = &listener->worker->netmgr->workers[tid]; + isc__networker_t *worker = isc__networker_current(); isc_mem_put(worker->loop->mctx, data, sizeof(*data)); @@ -3410,8 +3405,7 @@ isc_nm_http_set_endpoints(isc_nmsocket_t *listener, atomic_store(&eps->in_use, true); for (size_t i = 0; i < isc_loopmgr_nloops(); i++) { - isc__networker_t *worker = - &listener->worker->netmgr->workers[i]; + isc__networker_t *worker = isc__networker_get(i); http_endpoints_data_t *data = isc_mem_cget(worker->loop->mctx, 1, sizeof(*data)); @@ -3428,7 +3422,7 @@ http_init_listener_endpoints(isc_nmsocket_t *listener, size_t nworkers; REQUIRE(VALID_NMSOCK(listener)); - REQUIRE(listener->worker != NULL && VALID_NM(listener->worker->netmgr)); + REQUIRE(listener->worker != NULL); REQUIRE(VALID_HTTP_ENDPOINTS(epset)); nworkers = (size_t)isc_loopmgr_nloops(); @@ -3447,7 +3441,7 @@ http_init_listener_endpoints(isc_nmsocket_t *listener, static void http_cleanup_listener_endpoints(isc_nmsocket_t *listener) { - REQUIRE(listener->worker != NULL && VALID_NM(listener->worker->netmgr)); + REQUIRE(listener->worker != NULL); if (listener->h2->listener_endpoints == NULL) { return; diff --git a/lib/isc/netmgr/netmgr-int.h b/lib/isc/netmgr/netmgr-int.h index 02a687ab53..04e2a398c1 100644 --- a/lib/isc/netmgr/netmgr-int.h +++ b/lib/isc/netmgr/netmgr-int.h @@ -210,7 +210,6 @@ typedef struct isc__networker { isc_mem_t *mctx; isc_refcount_t references; isc_loop_t *loop; - isc_nm_t *netmgr; bool shuttingdown; char *recvbuf; @@ -229,7 +228,7 @@ void isc__nm_dump_active(isc__networker_t *worker); void -isc__nm_dump_active_manager(isc_nm_t *netmgr); +isc__nm_dump_active_manager(void); #endif /* ISC_NETMGR_TRACE */ /* @@ -320,13 +319,7 @@ struct isc__nm_uvreq { isc_job_t job; }; -/* - * Network manager - */ -#define NM_MAGIC ISC_MAGIC('N', 'E', 'T', 'M') -#define VALID_NM(t) ISC_MAGIC_VALID(t, NM_MAGIC) - -struct isc_nm { +typedef struct isc__netmgr { int magic; isc_refcount_t references; isc_mem_t *mctx; @@ -365,7 +358,28 @@ struct isc_nm { atomic_int_fast32_t send_udp_buffer_size; atomic_int_fast32_t recv_tcp_buffer_size; atomic_int_fast32_t send_tcp_buffer_size; -}; +} isc__netmgr_t; + +extern isc__netmgr_t *isc__netmgr; + +/* + * Network manager + */ +#define NM_MAGIC ISC_MAGIC('N', 'E', 'T', 'M') +#define VALID_NM(t) ISC_MAGIC_VALID(t, NM_MAGIC) + +#if ISC_NETMGR_TRACE +#define isc__netmgr_ref(ptr) isc__netmgr__ref(ptr, __func__, __FILE__, __LINE__) +#define isc__netmgr_unref(ptr) \ + isc__netmgr__unref(ptr, __func__, __FILE__, __LINE__) +#define isc__netmgr_attach(ptr, ptrp) \ + isc__netmgr__attach(ptr, ptrp, __func__, __FILE__, __LINE__) +#define isc__netmgr_detach(ptrp) \ + isc__netmgr__detach(ptrp, __func__, __FILE__, __LINE__) +ISC_REFCOUNT_TRACE_DECL(isc__netmgr); +#else +ISC_REFCOUNT_DECL(isc__netmgr); +#endif /*% * A universal structure for either a single socket or a group of @@ -1373,7 +1387,7 @@ isc__nm_socket_min_mtu(uv_os_sock_t fd, sa_family_t sa_family); */ void -isc__nm_set_network_buffers(isc_nm_t *nm, uv_handle_t *handle); +isc__nm_set_network_buffers(uv_handle_t *handle); /*%> * Sets the pre-configured network buffers size on the handle. */ @@ -1469,8 +1483,7 @@ isc__nmsocket_log_tls_session_reuse(isc_nmsocket_t *sock, isc_tls_t *tls); * Logging helpers */ void -isc__netmgr_log(const isc_nm_t *netmgr, int level, const char *fmt, ...) - ISC_FORMAT_PRINTF(3, 4); +isc__netmgr_log(int level, const char *fmt, ...) ISC_FORMAT_PRINTF(2, 3); void isc__nmsocket_log(const isc_nmsocket_t *sock, int level, const char *fmt, ...) ISC_FORMAT_PRINTF(3, 4); @@ -1512,3 +1525,9 @@ isc__nm_senddns(isc_nmhandle_t *handle, isc_region_t *region, isc_nm_cb_t cb, * The same as 'isc_nm_send()', but with data length sent * ahead of data (two bytes (16 bit) in big-endian format). */ + +isc__networker_t * +isc__networker_current(void); + +isc__networker_t * +isc__networker_get(uint32_t tid); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index 551aa002a6..cd706a848c 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -47,6 +47,8 @@ #include "netmgr-int.h" #include "openssl_shim.h" +isc__netmgr_t *isc__netmgr = NULL; + /*% * Shortcut index arrays to get access to statistics counters. */ @@ -119,7 +121,7 @@ networker_teardown(void *arg) { worker->shuttingdown = true; isc__netmgr_log( - worker->netmgr, ISC_LOG_DEBUG(1), + ISC_LOG_DEBUG(1), "Shutting down network manager worker on loop %p(%" PRItid ")", loop, isc_tid()); @@ -129,13 +131,11 @@ networker_teardown(void *arg) { } static void -netmgr_teardown(void *arg) { - isc_nm_t *netmgr = (void *)arg; - - if (atomic_compare_exchange_strong_acq_rel(&netmgr->shuttingdown, +netmgr_teardown(void *arg ISC_ATTR_UNUSED) { + if (atomic_compare_exchange_strong_acq_rel(&isc__netmgr->shuttingdown, &(bool){ false }, true)) { - isc__netmgr_log(netmgr, ISC_LOG_DEBUG(1), + isc__netmgr_log(ISC_LOG_DEBUG(1), "Shutting down network manager"); } } @@ -153,8 +153,8 @@ netmgr_teardown(void *arg) { #endif void -isc_netmgr_create(isc_mem_t *mctx, isc_nm_t **netmgrp) { - isc_nm_t *netmgr = NULL; +isc_netmgr_create(isc_mem_t *mctx) { + isc__netmgr_t *netmgr = NULL; #ifdef MAXIMAL_UV_VERSION if (uv_version() > MAXIMAL_UV_VERSION) { @@ -173,7 +173,7 @@ isc_netmgr_create(isc_mem_t *mctx, isc_nm_t **netmgrp) { } netmgr = isc_mem_get(mctx, sizeof(*netmgr)); - *netmgr = (isc_nm_t){ + *netmgr = (isc__netmgr_t){ .nloops = isc_loopmgr_nloops(), }; @@ -218,7 +218,7 @@ isc_netmgr_create(isc_mem_t *mctx, isc_nm_t **netmgrp) { .active_sockets = ISC_LIST_INITIALIZER, }; - isc_nm_attach(netmgr, &worker->netmgr); + isc__netmgr_ref(netmgr); isc_mem_attach(loop->mctx, &worker->mctx); @@ -236,14 +236,14 @@ isc_netmgr_create(isc_mem_t *mctx, isc_nm_t **netmgrp) { isc_refcount_init(&worker->references, 1); } - *netmgrp = netmgr; + isc__netmgr = netmgr; } /* * Free the resources of the network manager. */ static void -nm_destroy(isc_nm_t *netmgr) { +netmgr_destroy(isc__netmgr_t *netmgr) { REQUIRE(VALID_NM(netmgr)); isc_refcount_destroy(&netmgr->references); @@ -260,16 +260,21 @@ nm_destroy(isc_nm_t *netmgr) { } #if ISC_NETMGR_TRACE -ISC_REFCOUNT_TRACE_IMPL(isc_nm, nm_destroy) +ISC_REFCOUNT_TRACE_IMPL(isc__netmgr, netmgr_destroy) #else -ISC_REFCOUNT_IMPL(isc_nm, nm_destroy); +ISC_REFCOUNT_IMPL(isc__netmgr, netmgr_destroy); #endif void -isc_nm_maxudp(isc_nm_t *mgr, uint32_t maxudp) { - REQUIRE(VALID_NM(mgr)); +isc_netmgr_destroy(void) { + isc__netmgr_detach(&isc__netmgr); +} - atomic_store_relaxed(&mgr->maxudp, maxudp); +void +isc_nm_maxudp(uint32_t maxudp) { + REQUIRE(VALID_NM(isc__netmgr)); + + atomic_store_relaxed(&isc__netmgr->maxudp, maxudp); } void @@ -303,100 +308,100 @@ isc_nmhandle_setwritetimeout(isc_nmhandle_t *handle, uint64_t write_timeout) { } void -isc_nm_setinitialtimeout(isc_nm_t *mgr, uint32_t timeout_ms) { - REQUIRE(VALID_NM(mgr)); +isc_nm_setinitialtimeout(uint32_t timeout_ms) { + REQUIRE(VALID_NM(isc__netmgr)); - atomic_store_relaxed(&mgr->init, timeout_ms); + atomic_store_relaxed(&isc__netmgr->init, timeout_ms); } void -isc_nm_setprimariestimeout(isc_nm_t *mgr, uint32_t timeout_ms) { - REQUIRE(VALID_NM(mgr)); +isc_nm_setprimariestimeout(uint32_t timeout_ms) { + REQUIRE(VALID_NM(isc__netmgr)); - atomic_store_relaxed(&mgr->primaries, timeout_ms); + atomic_store_relaxed(&isc__netmgr->primaries, timeout_ms); } void -isc_nm_setidletimeout(isc_nm_t *mgr, uint32_t timeout_ms) { - REQUIRE(VALID_NM(mgr)); +isc_nm_setidletimeout(uint32_t timeout_ms) { + REQUIRE(VALID_NM(isc__netmgr)); - atomic_store_relaxed(&mgr->idle, timeout_ms); + atomic_store_relaxed(&isc__netmgr->idle, timeout_ms); } void -isc_nm_setkeepalivetimeout(isc_nm_t *mgr, uint32_t timeout_ms) { - REQUIRE(VALID_NM(mgr)); +isc_nm_setkeepalivetimeout(uint32_t timeout_ms) { + REQUIRE(VALID_NM(isc__netmgr)); - atomic_store_relaxed(&mgr->keepalive, timeout_ms); + atomic_store_relaxed(&isc__netmgr->keepalive, timeout_ms); } void -isc_nm_setadvertisedtimeout(isc_nm_t *mgr, uint32_t timeout_ms) { - REQUIRE(VALID_NM(mgr)); +isc_nm_setadvertisedtimeout(uint32_t timeout_ms) { + REQUIRE(VALID_NM(isc__netmgr)); - atomic_store_relaxed(&mgr->advertised, timeout_ms); + atomic_store_relaxed(&isc__netmgr->advertised, timeout_ms); } void -isc_nm_setnetbuffers(isc_nm_t *mgr, int32_t recv_tcp, int32_t send_tcp, - int32_t recv_udp, int32_t send_udp) { - REQUIRE(VALID_NM(mgr)); +isc_nm_setnetbuffers(int32_t recv_tcp, int32_t send_tcp, int32_t recv_udp, + int32_t send_udp) { + REQUIRE(VALID_NM(isc__netmgr)); - atomic_store_relaxed(&mgr->recv_tcp_buffer_size, recv_tcp); - atomic_store_relaxed(&mgr->send_tcp_buffer_size, send_tcp); - atomic_store_relaxed(&mgr->recv_udp_buffer_size, recv_udp); - atomic_store_relaxed(&mgr->send_udp_buffer_size, send_udp); + atomic_store_relaxed(&isc__netmgr->recv_tcp_buffer_size, recv_tcp); + atomic_store_relaxed(&isc__netmgr->send_tcp_buffer_size, send_tcp); + atomic_store_relaxed(&isc__netmgr->recv_udp_buffer_size, recv_udp); + atomic_store_relaxed(&isc__netmgr->send_udp_buffer_size, send_udp); } bool -isc_nm_getloadbalancesockets(isc_nm_t *mgr) { - REQUIRE(VALID_NM(mgr)); +isc_nm_getloadbalancesockets(void) { + REQUIRE(VALID_NM(isc__netmgr)); - return mgr->load_balance_sockets; + return isc__netmgr->load_balance_sockets; } void -isc_nm_setloadbalancesockets(isc_nm_t *mgr, ISC_ATTR_UNUSED bool enabled) { - REQUIRE(VALID_NM(mgr)); +isc_nm_setloadbalancesockets(ISC_ATTR_UNUSED bool enabled) { + REQUIRE(VALID_NM(isc__netmgr)); #if HAVE_SO_REUSEPORT_LB - mgr->load_balance_sockets = enabled; + isc__netmgr->load_balance_sockets = enabled; #endif } uint32_t -isc_nm_getinitialtimeout(isc_nm_t *mgr) { - REQUIRE(VALID_NM(mgr)); +isc_nm_getinitialtimeout(void) { + REQUIRE(VALID_NM(isc__netmgr)); - return atomic_load_relaxed(&mgr->init); + return atomic_load_relaxed(&isc__netmgr->init); } uint32_t -isc_nm_getprimariestimeout(isc_nm_t *mgr) { - REQUIRE(VALID_NM(mgr)); +isc_nm_getprimariestimeout(void) { + REQUIRE(VALID_NM(isc__netmgr)); - return atomic_load_relaxed(&mgr->primaries); + return atomic_load_relaxed(&isc__netmgr->primaries); } uint32_t -isc_nm_getidletimeout(isc_nm_t *mgr) { - REQUIRE(VALID_NM(mgr)); +isc_nm_getidletimeout(void) { + REQUIRE(VALID_NM(isc__netmgr)); - return atomic_load_relaxed(&mgr->idle); + return atomic_load_relaxed(&isc__netmgr->idle); } uint32_t -isc_nm_getkeepalivetimeout(isc_nm_t *mgr) { - REQUIRE(VALID_NM(mgr)); +isc_nm_getkeepalivetimeout(void) { + REQUIRE(VALID_NM(isc__netmgr)); - return atomic_load_relaxed(&mgr->keepalive); + return atomic_load_relaxed(&isc__netmgr->keepalive); } uint32_t -isc_nm_getadvertisedtimeout(isc_nm_t *mgr) { - REQUIRE(VALID_NM(mgr)); +isc_nm_getadvertisedtimeout(void) { + REQUIRE(VALID_NM(isc__netmgr)); - return atomic_load_relaxed(&mgr->advertised); + return atomic_load_relaxed(&isc__netmgr->advertised); } bool @@ -1488,25 +1493,20 @@ isc_nmhandle_settimeout(isc_nmhandle_t *handle, uint32_t timeout) { void isc_nmhandle_keepalive(isc_nmhandle_t *handle, bool value) { isc_nmsocket_t *sock = NULL; - isc_nm_t *netmgr = NULL; REQUIRE(VALID_NMHANDLE(handle)); REQUIRE(VALID_NMSOCK(handle->sock)); sock = handle->sock; - netmgr = sock->worker->netmgr; REQUIRE(sock->tid == isc_tid()); switch (sock->type) { - case isc_nm_tcpsocket: + case isc_nm_tcpsocket:; sock->keepalive = value; - sock->read_timeout = - value ? atomic_load_relaxed(&netmgr->keepalive) - : atomic_load_relaxed(&netmgr->idle); - sock->write_timeout = - value ? atomic_load_relaxed(&netmgr->keepalive) - : atomic_load_relaxed(&netmgr->idle); + sock->read_timeout = sock->write_timeout = + value ? atomic_load_relaxed(&isc__netmgr->keepalive) + : atomic_load_relaxed(&isc__netmgr->idle); break; case isc_nm_streamdnssocket: isc__nmhandle_streamdns_keepalive(handle, value); @@ -1588,14 +1588,6 @@ isc_nmhandle_localaddr(isc_nmhandle_t *handle) { return addr; } -isc_nm_t * -isc_nmhandle_netmgr(isc_nmhandle_t *handle) { - REQUIRE(VALID_NMHANDLE(handle)); - REQUIRE(VALID_NMSOCK(handle->sock)); - - return handle->sock->worker->netmgr; -} - isc__nm_uvreq_t * isc___nm_uvreq_get(isc_nmsocket_t *sock FLARG) { REQUIRE(VALID_NMSOCK(sock)); @@ -2055,12 +2047,12 @@ shutdown_walk_cb(uv_handle_t *handle, void *arg) { } void -isc_nm_setstats(isc_nm_t *mgr, isc_stats_t *stats) { - REQUIRE(VALID_NM(mgr)); - REQUIRE(mgr->stats == NULL); +isc_nm_setstats(isc_stats_t *stats) { + REQUIRE(VALID_NM(isc__netmgr)); + REQUIRE(isc__netmgr->stats == NULL); REQUIRE(isc_stats_ncounters(stats) == isc_sockstatscounter_max); - isc_stats_attach(stats, &mgr->stats); + isc_stats_attach(stats, &isc__netmgr->stats); } void @@ -2068,9 +2060,8 @@ isc__nm_incstats(isc_nmsocket_t *sock, isc__nm_statid_t id) { REQUIRE(VALID_NMSOCK(sock)); REQUIRE(id < STATID_MAX); - if (sock->statsindex != NULL && sock->worker->netmgr->stats != NULL) { - isc_stats_increment(sock->worker->netmgr->stats, - sock->statsindex[id]); + if (sock->statsindex != NULL && isc__netmgr->stats != NULL) { + isc_stats_increment(isc__netmgr->stats, sock->statsindex[id]); } } @@ -2079,9 +2070,8 @@ isc__nm_decstats(isc_nmsocket_t *sock, isc__nm_statid_t id) { REQUIRE(VALID_NMSOCK(sock)); REQUIRE(id < STATID_MAX); - if (sock->statsindex != NULL && sock->worker->netmgr->stats != NULL) { - isc_stats_decrement(sock->worker->netmgr->stats, - sock->statsindex[id]); + if (sock->statsindex != NULL && isc__netmgr->stats != NULL) { + isc_stats_decrement(isc__netmgr->stats, sock->statsindex[id]); } } @@ -2143,22 +2133,22 @@ isc_nm_checkaddr(const isc_sockaddr_t *addr, isc_socktype_t type) { #endif void -isc__nm_set_network_buffers(isc_nm_t *nm, uv_handle_t *handle) { +isc__nm_set_network_buffers(uv_handle_t *handle) { int32_t recv_buffer_size = 0; int32_t send_buffer_size = 0; switch (handle->type) { case UV_TCP: recv_buffer_size = - atomic_load_relaxed(&nm->recv_tcp_buffer_size); + atomic_load_relaxed(&isc__netmgr->recv_tcp_buffer_size); send_buffer_size = - atomic_load_relaxed(&nm->send_tcp_buffer_size); + atomic_load_relaxed(&isc__netmgr->send_tcp_buffer_size); break; case UV_UDP: recv_buffer_size = - atomic_load_relaxed(&nm->recv_udp_buffer_size); + atomic_load_relaxed(&isc__netmgr->recv_udp_buffer_size); send_buffer_size = - atomic_load_relaxed(&nm->send_udp_buffer_size); + atomic_load_relaxed(&isc__netmgr->send_udp_buffer_size); break; default: UNREACHABLE(); @@ -2526,7 +2516,7 @@ settlsctx_cb(void *arg) { const isc_tid_t tid = isc_tid(); isc_nmsocket_t *listener = data->listener; isc_tlsctx_t *tlsctx = data->tlsctx; - isc__networker_t *worker = &listener->worker->netmgr->workers[tid]; + isc__networker_t *worker = isc__networker_current(); isc_mem_put(worker->loop->mctx, data, sizeof(*data)); @@ -2543,8 +2533,7 @@ set_tlsctx_workers(isc_nmsocket_t *listener, isc_tlsctx_t *tlsctx) { const size_t nworkers = (size_t)isc_loopmgr_nloops(); /* Update the TLS context reference for every worker thread. */ for (size_t i = 0; i < nworkers; i++) { - isc__networker_t *worker = - &listener->worker->netmgr->workers[i]; + isc__networker_t *worker = isc__networker_get(i); settlsctx_data_t *data = isc_mem_cget(worker->loop->mctx, 1, sizeof(*data)); @@ -2626,10 +2615,7 @@ isc__nmsocket_log_tls_session_reuse(isc_nmsocket_t *sock, isc_tls_t *tls) { static void isc__networker_destroy(isc__networker_t *worker) { - isc_nm_t *netmgr = worker->netmgr; - worker->netmgr = NULL; - - isc__netmgr_log(netmgr, ISC_LOG_DEBUG(1), + isc__netmgr_log(ISC_LOG_DEBUG(1), "Destroying network manager worker on loop %p(%" PRItid ")", worker->loop, isc_tid()); @@ -2641,13 +2627,14 @@ isc__networker_destroy(isc__networker_t *worker) { isc_mem_putanddetach(&worker->mctx, worker->recvbuf, ISC_NETMGR_RECVBUF_SIZE); - isc_nm_detach(&netmgr); + + isc__netmgr_unref(isc__netmgr); } ISC_REFCOUNT_IMPL(isc__networker, isc__networker_destroy); void -isc__netmgr_log(const isc_nm_t *netmgr, int level, const char *fmt, ...) { +isc__netmgr_log(int level, const char *fmt, ...) { char msgbuf[2048]; va_list ap; @@ -2660,7 +2647,7 @@ isc__netmgr_log(const isc_nm_t *netmgr, int level, const char *fmt, ...) { va_end(ap); isc_log_write(ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_NETMGR, level, - "netmgr %p: %s", netmgr, msgbuf); + "netmgr %p: %s", isc__netmgr, msgbuf); } void @@ -2899,6 +2886,18 @@ isc_nm_proxyheader_info_init_complete(isc_nm_proxyheader_info_t *restrict info, .complete_header = *header_data }; } +isc__networker_t * +isc__networker_current(void) { + REQUIRE(VALID_NM(isc__netmgr)); + return &isc__netmgr->workers[isc_tid()]; +} + +isc__networker_t * +isc__networker_get(uint32_t tid) { + REQUIRE(VALID_NM(isc__netmgr)); + return &isc__netmgr->workers[tid]; +} + #if ISC_NETMGR_TRACE /* * Dump all active sockets in netmgr. We output to stderr @@ -2998,11 +2997,9 @@ isc__nm_dump_active(isc__networker_t *worker) { } void -isc__nm_dump_active_manager(isc_nm_t *netmgr) { - size_t i = 0; - - for (i = 0; i < netmgr->nloops; i++) { - isc__networker_t *worker = &netmgr->workers[i]; +isc__nm_dump_active_manager(void) { + for (size_t i = 0; i < isc__netmgr->nloops; i++) { + isc__networker_t *worker = isc__networker_get(i); if (!ISC_LIST_EMPTY(worker->active_sockets)) { fprintf(stderr, "Worker #%zu (%p)\n", i, worker); diff --git a/lib/isc/netmgr/proxystream.c b/lib/isc/netmgr/proxystream.c index bf2ca1feb9..68e57c19ed 100644 --- a/lib/isc/netmgr/proxystream.c +++ b/lib/isc/netmgr/proxystream.c @@ -241,7 +241,7 @@ proxystream_sock_new(isc__networker_t *worker, const isc_nmsocket_type_t type, isc__nmsocket_init(sock, worker, type, addr, NULL); sock->result = ISC_R_UNSET; if (type == isc_nm_proxystreamsocket) { - sock->read_timeout = isc_nm_getinitialtimeout(worker->netmgr); + sock->read_timeout = isc_nm_getinitialtimeout(); sock->client = !is_server; sock->connecting = !is_server; if (is_server) { @@ -313,15 +313,14 @@ proxystream_accept_cb(isc_nmhandle_t *handle, isc_result_t result, } isc_result_t -isc_nm_listenproxystream(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listenproxystream(uint32_t workers, isc_sockaddr_t *iface, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, isc_tlsctx_t *tlsctx, isc_nmsocket_t **sockp) { isc_result_t result; isc_nmsocket_t *listener = NULL; - isc__networker_t *worker = &mgr->workers[isc_tid()]; + isc__networker_t *worker = isc__networker_current(); - REQUIRE(VALID_NM(mgr)); REQUIRE(isc_tid() == 0); REQUIRE(sockp != NULL && *sockp == NULL); @@ -335,13 +334,13 @@ isc_nm_listenproxystream(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, listener->accept_cbarg = accept_cbarg; if (tlsctx == NULL) { - result = isc_nm_listentcp(mgr, workers, iface, - proxystream_accept_cb, listener, - backlog, quota, &listener->outer); + result = isc_nm_listentcp(workers, iface, proxystream_accept_cb, + listener, backlog, quota, + &listener->outer); } else { - result = isc_nm_listentls( - mgr, workers, iface, proxystream_accept_cb, listener, - backlog, quota, tlsctx, false, &listener->outer); + result = isc_nm_listentls(workers, iface, proxystream_accept_cb, + listener, backlog, quota, tlsctx, + false, &listener->outer); } if (result != ISC_R_SUCCESS) { @@ -455,17 +454,14 @@ error: } void -isc_nm_proxystreamconnect(isc_nm_t *mgr, isc_sockaddr_t *local, - isc_sockaddr_t *peer, isc_nm_cb_t cb, void *cbarg, - unsigned int timeout, isc_tlsctx_t *tlsctx, - const char *sni_hostname, +isc_nm_proxystreamconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, + isc_nm_cb_t cb, void *cbarg, unsigned int timeout, + isc_tlsctx_t *tlsctx, const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, isc_nm_proxyheader_info_t *proxy_info) { isc_result_t result = ISC_R_FAILURE; isc_nmsocket_t *nsock = NULL; - isc__networker_t *worker = &mgr->workers[isc_tid()]; - - REQUIRE(VALID_NM(mgr)); + isc__networker_t *worker = isc__networker_current(); if (isc__nm_closing(worker)) { cb(NULL, ISC_R_SHUTTINGDOWN, cbarg); @@ -497,13 +493,12 @@ isc_nm_proxystreamconnect(isc_nm_t *mgr, isc_sockaddr_t *local, RUNTIME_CHECK(result == ISC_R_SUCCESS); if (tlsctx == NULL) { - isc_nm_tcpconnect(mgr, local, peer, proxystream_connect_cb, - nsock, nsock->connect_timeout); + isc_nm_tcpconnect(local, peer, proxystream_connect_cb, nsock, + nsock->connect_timeout); } else { - isc_nm_tlsconnect(mgr, local, peer, proxystream_connect_cb, - nsock, tlsctx, sni_hostname, - client_sess_cache, nsock->connect_timeout, - false, NULL); + isc_nm_tlsconnect(local, peer, proxystream_connect_cb, nsock, + tlsctx, sni_hostname, client_sess_cache, + nsock->connect_timeout, false, NULL); } } diff --git a/lib/isc/netmgr/proxyudp.c b/lib/isc/netmgr/proxyudp.c index 27f40fea9e..20d44a0ebd 100644 --- a/lib/isc/netmgr/proxyudp.c +++ b/lib/isc/netmgr/proxyudp.c @@ -213,7 +213,7 @@ proxyudp_sock_new(isc__networker_t *worker, const isc_nmsocket_type_t type, isc__nmsocket_init(sock, worker, type, addr, NULL); sock->result = ISC_R_UNSET; if (type == isc_nm_proxyudpsocket) { - sock->read_timeout = isc_nm_getinitialtimeout(worker->netmgr); + sock->read_timeout = isc_nm_getinitialtimeout(); sock->client = !is_server; sock->connecting = !is_server; if (!is_server) { @@ -222,7 +222,7 @@ proxyudp_sock_new(isc__networker_t *worker, const isc_nmsocket_type_t type, ISC_NM_PROXY2_DEFAULT_BUFFER_SIZE); } } else if (type == isc_nm_proxyudplistener) { - size_t nworkers = worker->netmgr->nloops; + size_t nworkers = isc_loopmgr_nloops(); sock->proxy.udp_server_socks_num = nworkers; sock->proxy.udp_server_socks = isc_mem_cget( worker->mctx, nworkers, sizeof(isc_nmsocket_t *)); @@ -315,14 +315,13 @@ failed: } isc_result_t -isc_nm_listenproxyudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listenproxyudp(uint32_t workers, isc_sockaddr_t *iface, isc_nm_recv_cb_t cb, void *cbarg, isc_nmsocket_t **sockp) { isc_result_t result; isc_nmsocket_t *listener = NULL; - isc__networker_t *worker = &mgr->workers[isc_tid()]; + isc__networker_t *worker = isc__networker_current(); - REQUIRE(VALID_NM(mgr)); REQUIRE(isc_tid() == 0); REQUIRE(sockp != NULL && *sockp == NULL); @@ -336,8 +335,9 @@ isc_nm_listenproxyudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, listener->recv_cbarg = cbarg; for (size_t i = 0; i < listener->proxy.udp_server_socks_num; i++) { - listener->proxy.udp_server_socks[i] = proxyudp_sock_new( - &mgr->workers[i], isc_nm_proxyudpsocket, iface, true); + listener->proxy.udp_server_socks[i] = + proxyudp_sock_new(isc__networker_get(i), + isc_nm_proxyudpsocket, iface, true); listener->proxy.udp_server_socks[i]->recv_cb = listener->recv_cb; @@ -350,8 +350,8 @@ isc_nm_listenproxyudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, &listener->proxy.udp_server_socks[i]->listener); } - result = isc_nm_listenudp(mgr, workers, iface, proxyudp_read_cb, - listener, &listener->outer); + result = isc_nm_listenudp(workers, iface, proxyudp_read_cb, listener, + &listener->outer); if (result == ISC_R_SUCCESS) { listener->active = true; @@ -441,15 +441,12 @@ error: } void -isc_nm_proxyudpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, - isc_sockaddr_t *peer, isc_nm_cb_t cb, void *cbarg, - unsigned int timeout, +isc_nm_proxyudpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, + isc_nm_cb_t cb, void *cbarg, unsigned int timeout, isc_nm_proxyheader_info_t *proxy_info) { isc_result_t result = ISC_R_FAILURE; isc_nmsocket_t *nsock = NULL; - isc__networker_t *worker = &mgr->workers[isc_tid()]; - - REQUIRE(VALID_NM(mgr)); + isc__networker_t *worker = isc__networker_current(); if (isc__nm_closing(worker)) { cb(NULL, ISC_R_SHUTTINGDOWN, cbarg); @@ -480,8 +477,7 @@ isc_nm_proxyudpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, } RUNTIME_CHECK(result == ISC_R_SUCCESS); - isc_nm_udpconnect(mgr, local, peer, proxyudp_connect_cb, nsock, - timeout); + isc_nm_udpconnect(local, peer, proxyudp_connect_cb, nsock, timeout); } /* diff --git a/lib/isc/netmgr/streamdns.c b/lib/isc/netmgr/streamdns.c index 82b6beb9a8..2da8a63a0a 100644 --- a/lib/isc/netmgr/streamdns.c +++ b/lib/isc/netmgr/streamdns.c @@ -271,7 +271,7 @@ streamdns_sock_new(isc__networker_t *worker, const isc_nmsocket_type_t type, isc__nmsocket_init(sock, worker, type, addr, NULL); sock->result = ISC_R_UNSET; if (type == isc_nm_streamdnssocket) { - sock->read_timeout = isc_nm_getinitialtimeout(worker->netmgr); + sock->read_timeout = isc_nm_getinitialtimeout(); sock->client = !is_server; sock->connecting = !is_server; sock->streamdns.input = isc_dnsstream_assembler_new( @@ -382,19 +382,14 @@ error: } void -isc_nm_streamdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, - isc_sockaddr_t *peer, isc_nm_cb_t cb, void *cbarg, - unsigned int timeout, isc_tlsctx_t *tlsctx, - const char *sni_hostname, +isc_nm_streamdnsconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, + isc_nm_cb_t cb, void *cbarg, unsigned int timeout, + isc_tlsctx_t *tlsctx, const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, isc_nm_proxy_type_t proxy_type, isc_nm_proxyheader_info_t *proxy_info) { isc_nmsocket_t *nsock = NULL; - isc__networker_t *worker = NULL; - - REQUIRE(VALID_NM(mgr)); - - worker = &mgr->workers[isc_tid()]; + isc__networker_t *worker = isc__networker_current(); if (isc__nm_closing(worker)) { cb(NULL, ISC_R_SHUTTINGDOWN, cbarg); @@ -411,25 +406,25 @@ isc_nm_streamdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, case ISC_NM_PROXY_NONE: if (tlsctx == NULL) { INSIST(client_sess_cache == NULL); - isc_nm_tcpconnect(mgr, local, peer, + isc_nm_tcpconnect(local, peer, streamdns_transport_connected, nsock, nsock->connect_timeout); } else { isc_nm_tlsconnect( - mgr, local, peer, streamdns_transport_connected, + local, peer, streamdns_transport_connected, nsock, tlsctx, sni_hostname, client_sess_cache, nsock->connect_timeout, false, proxy_info); } break; case ISC_NM_PROXY_PLAIN: if (tlsctx == NULL) { - isc_nm_proxystreamconnect(mgr, local, peer, + isc_nm_proxystreamconnect(local, peer, streamdns_transport_connected, nsock, nsock->connect_timeout, NULL, NULL, NULL, proxy_info); } else { isc_nm_tlsconnect( - mgr, local, peer, streamdns_transport_connected, + local, peer, streamdns_transport_connected, nsock, tlsctx, sni_hostname, client_sess_cache, nsock->connect_timeout, true, proxy_info); } @@ -437,7 +432,7 @@ isc_nm_streamdnsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, case ISC_NM_PROXY_ENCRYPTED: INSIST(tlsctx != NULL); isc_nm_proxystreamconnect( - mgr, local, peer, streamdns_transport_connected, nsock, + local, peer, streamdns_transport_connected, nsock, nsock->connect_timeout, tlsctx, sni_hostname, client_sess_cache, proxy_info); break; @@ -722,8 +717,7 @@ streamdns_accept_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { nsock->peer = isc_nmhandle_peeraddr(handle); nsock->tid = tid; - nsock->read_timeout = - isc_nm_getinitialtimeout(handle->sock->worker->netmgr); + nsock->read_timeout = isc_nm_getinitialtimeout(); nsock->accepting = true; nsock->active = true; @@ -748,9 +742,7 @@ streamdns_accept_cb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { nsock->closehandle_cb = streamdns_resume_processing; isc__nmhandle_set_manual_timer(nsock->outerhandle, true); /* settimeout restarts the timer */ - isc_nmhandle_settimeout( - nsock->outerhandle, - isc_nm_getinitialtimeout(nsock->worker->netmgr)); + isc_nmhandle_settimeout(nsock->outerhandle, isc_nm_getinitialtimeout()); (void)isc_nmhandle_set_tcp_nodelay(nsock->outerhandle, true); streamdns_handle_incoming_data(nsock, nsock->outerhandle, NULL, 0); @@ -761,20 +753,17 @@ exit: } isc_result_t -isc_nm_listenstreamdns(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listenstreamdns(uint32_t workers, isc_sockaddr_t *iface, isc_nm_recv_cb_t recv_cb, void *recv_cbarg, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, isc_tlsctx_t *tlsctx, isc_nm_proxy_type_t proxy_type, isc_nmsocket_t **sockp) { isc_result_t result = ISC_R_FAILURE; isc_nmsocket_t *listener = NULL; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_current(); - REQUIRE(VALID_NM(mgr)); REQUIRE(isc_tid() == 0); - worker = &mgr->workers[isc_tid()]; - if (isc__nm_closing(worker)) { return ISC_R_SHUTTINGDOWN; } @@ -790,10 +779,10 @@ isc_nm_listenstreamdns(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, case ISC_NM_PROXY_NONE: if (tlsctx == NULL) { result = isc_nm_listentcp( - mgr, workers, iface, streamdns_accept_cb, - listener, backlog, quota, &listener->outer); + workers, iface, streamdns_accept_cb, listener, + backlog, quota, &listener->outer); } else { - result = isc_nm_listentls(mgr, workers, iface, + result = isc_nm_listentls(workers, iface, streamdns_accept_cb, listener, backlog, quota, tlsctx, false, &listener->outer); @@ -802,21 +791,19 @@ isc_nm_listenstreamdns(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, case ISC_NM_PROXY_PLAIN: if (tlsctx == NULL) { result = isc_nm_listenproxystream( - mgr, workers, iface, streamdns_accept_cb, - listener, backlog, quota, NULL, - &listener->outer); + workers, iface, streamdns_accept_cb, listener, + backlog, quota, NULL, &listener->outer); } else { - result = isc_nm_listentls(mgr, workers, iface, - streamdns_accept_cb, listener, - backlog, quota, tlsctx, true, - &listener->outer); + result = isc_nm_listentls( + workers, iface, streamdns_accept_cb, listener, + backlog, quota, tlsctx, true, &listener->outer); } break; case ISC_NM_PROXY_ENCRYPTED: INSIST(tlsctx != NULL); result = isc_nm_listenproxystream( - mgr, workers, iface, streamdns_accept_cb, listener, - backlog, quota, tlsctx, &listener->outer); + workers, iface, streamdns_accept_cb, listener, backlog, + quota, tlsctx, &listener->outer); break; default: UNREACHABLE(); diff --git a/lib/isc/netmgr/tcp.c b/lib/isc/netmgr/tcp.c index 327b345ec3..694286aebd 100644 --- a/lib/isc/netmgr/tcp.c +++ b/lib/isc/netmgr/tcp.c @@ -149,8 +149,7 @@ tcp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { } } - isc__nm_set_network_buffers(sock->worker->netmgr, - &sock->uv_handle.handle); + isc__nm_set_network_buffers(&sock->uv_handle.handle); uv_handle_set_data(&req->uv_req.handle, req); r = uv_tcp_connect(&req->uv_req.connect, &sock->uv_handle.tcp, @@ -248,22 +247,19 @@ error: } void -isc_nm_tcpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, +isc_nm_tcpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, isc_nm_cb_t connect_cb, void *connect_cbarg, unsigned int timeout) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *sock = NULL; isc__nm_uvreq_t *req = NULL; sa_family_t sa_family; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_current(); uv_os_sock_t fd = -1; - REQUIRE(VALID_NM(mgr)); REQUIRE(local != NULL); REQUIRE(peer != NULL); - worker = &mgr->workers[isc_tid()]; - if (isc__nm_closing(worker)) { connect_cb(NULL, ISC_R_SHUTTINGDOWN, connect_cbarg); return; @@ -310,7 +306,7 @@ isc_nm_tcpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, } static uv_os_sock_t -isc__nm_tcp_lb_socket(isc_nm_t *mgr, sa_family_t sa_family) { +isc__nm_tcp_lb_socket(sa_family_t sa_family) { isc_result_t result; uv_os_sock_t sock; @@ -324,7 +320,7 @@ isc__nm_tcp_lb_socket(isc_nm_t *mgr, sa_family_t sa_family) { result = isc__nm_socket_reuse(sock, 1); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (mgr->load_balance_sockets) { + if (isc__netmgr->load_balance_sockets) { result = isc__nm_socket_reuse_lb(sock); RUNTIME_CHECK(result == ISC_R_SUCCESS); } @@ -372,7 +368,7 @@ start_tcp_child_job(void *arg) { flags = UV_TCP_IPV6ONLY; } - if (sock->worker->netmgr->load_balance_sockets) { + if (isc__netmgr->load_balance_sockets) { r = isc__nm_tcp_freebind(&sock->uv_handle.tcp, &sock->iface.type.sa, flags); if (r < 0) { @@ -392,8 +388,7 @@ start_tcp_child_job(void *arg) { sock->uv_handle.tcp.flags = sock->parent->uv_handle.tcp.flags; } - isc__nm_set_network_buffers(sock->worker->netmgr, - &sock->uv_handle.handle); + isc__nm_set_network_buffers(&sock->uv_handle.handle); /* * The callback will run in the same thread uv_listen() was called @@ -441,10 +436,10 @@ done_result: } static void -start_tcp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock, - uv_os_sock_t fd, isc_tid_t tid) { +start_tcp_child(isc_sockaddr_t *iface, isc_nmsocket_t *sock, uv_os_sock_t fd, + isc_tid_t tid) { isc_nmsocket_t *csock = &sock->children[tid]; - isc__networker_t *worker = &mgr->workers[tid]; + isc__networker_t *worker = isc__networker_get(tid); isc__nmsocket_init(csock, worker, isc_nm_tcpsocket, iface, sock); csock->accept_cb = sock->accept_cb; @@ -456,10 +451,9 @@ start_tcp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock, */ csock->pquota = sock->pquota; - if (mgr->load_balance_sockets) { + if (isc__netmgr->load_balance_sockets) { UNUSED(fd); - csock->fd = isc__nm_tcp_lb_socket(mgr, - iface->type.sa.sa_family); + csock->fd = isc__nm_tcp_lb_socket(iface->type.sa.sa_family); } else { csock->fd = dup(fd); } @@ -473,28 +467,27 @@ start_tcp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock, } isc_result_t -isc_nm_listentcp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listentcp(uint32_t workers, isc_sockaddr_t *iface, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, isc_nmsocket_t **sockp) { isc_nmsocket_t *sock = NULL; uv_os_sock_t fd = -1; isc_result_t result = ISC_R_UNSET; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_get(0); - REQUIRE(VALID_NM(mgr)); REQUIRE(isc_tid() == 0); if (workers == 0) { - workers = mgr->nloops; + workers = isc__netmgr->nloops; } - REQUIRE(workers <= mgr->nloops); + REQUIRE(workers <= isc__netmgr->nloops); - worker = &mgr->workers[0]; sock = isc_mempool_get(worker->nmsocket_pool); isc__nmsocket_init(sock, worker, isc_nm_tcplistener, iface, NULL); - sock->nchildren = (workers == ISC_NM_LISTEN_ALL) ? (uint32_t)mgr->nloops - : workers; + sock->nchildren = (workers == ISC_NM_LISTEN_ALL) + ? (uint32_t)isc__netmgr->nloops + : workers; sock->children = isc_mem_cget(worker->mctx, sock->nchildren, sizeof(sock->children[0])); @@ -505,21 +498,21 @@ isc_nm_listentcp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, sock->backlog = backlog; sock->pquota = quota; - if (!mgr->load_balance_sockets) { - fd = isc__nm_tcp_lb_socket(mgr, iface->type.sa.sa_family); + if (!isc__netmgr->load_balance_sockets) { + fd = isc__nm_tcp_lb_socket(iface->type.sa.sa_family); } - start_tcp_child(mgr, iface, sock, fd, 0); + start_tcp_child(iface, sock, fd, 0); result = sock->children[0].result; INSIST(result != ISC_R_UNSET); for (size_t i = 1; i < sock->nchildren; i++) { - start_tcp_child(mgr, iface, sock, fd, i); + start_tcp_child(iface, sock, fd, i); } isc_barrier_wait(&sock->listen_barrier); - if (!mgr->load_balance_sockets) { + if (!isc__netmgr->load_balance_sockets) { isc__nm_closesocket(fd); } @@ -705,14 +698,12 @@ isc__nm_tcp_failed_read_cb(isc_nmsocket_t *sock, isc_result_t result, void isc__nm_tcp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) { isc_nmsocket_t *sock; - isc_nm_t *netmgr; isc_result_t result; REQUIRE(VALID_NMHANDLE(handle)); REQUIRE(VALID_NMSOCK(handle->sock)); sock = handle->sock; - netmgr = sock->worker->netmgr; REQUIRE(sock->type == isc_nm_tcpsocket); REQUIRE(sock->statichandle == handle); @@ -724,8 +715,8 @@ isc__nm_tcp_read(isc_nmhandle_t *handle, isc_nm_recv_cb_t cb, void *cbarg) { if (sock->read_timeout == 0) { sock->read_timeout = sock->keepalive - ? atomic_load_relaxed(&netmgr->keepalive) - : atomic_load_relaxed(&netmgr->idle); + ? atomic_load_relaxed(&isc__netmgr->keepalive) + : atomic_load_relaxed(&isc__netmgr->idle); } if (isc__nmsocket_closing(sock)) { @@ -771,14 +762,11 @@ void isc__nm_tcp_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { isc_nmsocket_t *sock = uv_handle_get_data((uv_handle_t *)stream); isc__nm_uvreq_t *req = NULL; - isc_nm_t *netmgr = NULL; REQUIRE(VALID_NMSOCK(sock)); REQUIRE(sock->tid == isc_tid()); REQUIRE(buf != NULL); - netmgr = sock->worker->netmgr; - if (isc__nmsocket_closing(sock)) { isc__nm_tcp_failed_read_cb(sock, ISC_R_CANCELED, false); goto free; @@ -808,8 +796,8 @@ isc__nm_tcp_read_cb(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf) { if (!sock->client) { sock->read_timeout = sock->keepalive - ? atomic_load_relaxed(&netmgr->keepalive) - : atomic_load_relaxed(&netmgr->idle); + ? atomic_load_relaxed(&isc__netmgr->keepalive) + : atomic_load_relaxed(&isc__netmgr->idle); } isc__nm_readcb(sock, req, ISC_R_SUCCESS, false); @@ -909,7 +897,7 @@ accept_connection(isc_nmsocket_t *csock) { csock->accept_cbarg = csock->server->accept_cbarg; csock->recv_cb = csock->server->recv_cb; csock->recv_cbarg = csock->server->recv_cbarg; - csock->read_timeout = atomic_load_relaxed(&csock->worker->netmgr->init); + csock->read_timeout = atomic_load_relaxed(&isc__netmgr->init); r = uv_tcp_init(&csock->worker->loop->loop, &csock->uv_handle.tcp); UV_RUNTIME_CHECK(uv_tcp_init, r); @@ -1042,7 +1030,6 @@ tcp_send(isc_nmhandle_t *handle, const isc_region_t *region, isc_nm_cb_t cb, isc_nmsocket_t *sock = handle->sock; isc_result_t result; isc__nm_uvreq_t *uvreq = NULL; - isc_nm_t *netmgr = sock->worker->netmgr; REQUIRE(sock->type == isc_nm_tcpsocket); REQUIRE(sock->tid == isc_tid()); @@ -1062,8 +1049,8 @@ tcp_send(isc_nmhandle_t *handle, const isc_region_t *region, isc_nm_cb_t cb, if (sock->write_timeout == 0) { sock->write_timeout = sock->keepalive - ? atomic_load_relaxed(&netmgr->keepalive) - : atomic_load_relaxed(&netmgr->idle); + ? atomic_load_relaxed(&isc__netmgr->keepalive) + : atomic_load_relaxed(&isc__netmgr->idle); } result = tcp_send_direct(sock, uvreq); diff --git a/lib/isc/netmgr/tlsstream.c b/lib/isc/netmgr/tlsstream.c index 5393453267..3c32f76a4a 100644 --- a/lib/isc/netmgr/tlsstream.c +++ b/lib/isc/netmgr/tlsstream.c @@ -943,8 +943,7 @@ tlslisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { isc__nmsocket_attach(handle->sock, &tlssock->listener); isc_nmhandle_attach(handle, &tlssock->outerhandle); tlssock->peer = isc_nmhandle_peeraddr(handle); - tlssock->read_timeout = - atomic_load_relaxed(&handle->sock->worker->netmgr->init); + tlssock->read_timeout = atomic_load_relaxed(&isc__netmgr->init); /* * Hold a reference to tlssock in the TCP socket: it will @@ -964,28 +963,25 @@ tlslisten_acceptcb(isc_nmhandle_t *handle, isc_result_t result, void *cbarg) { } isc_result_t -isc_nm_listentls(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, +isc_nm_listentls(uint32_t workers, isc_sockaddr_t *iface, isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_quota_t *quota, SSL_CTX *sslctx, bool proxy, isc_nmsocket_t **sockp) { isc_result_t result; isc_nmsocket_t *tlssock = NULL; isc_nmsocket_t *tsock = NULL; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_current(); - REQUIRE(VALID_NM(mgr)); REQUIRE(isc_tid() == 0); - worker = &mgr->workers[isc_tid()]; - if (isc__nm_closing(worker)) { return ISC_R_SHUTTINGDOWN; } if (workers == 0) { - workers = mgr->nloops; + workers = isc__netmgr->nloops; } - REQUIRE(workers <= mgr->nloops); + REQUIRE(workers <= isc__netmgr->nloops); tlssock = isc_mempool_get(worker->nmsocket_pool); isc__nmsocket_init(tlssock, worker, isc_nm_tlslistener, iface, NULL); @@ -1000,12 +996,12 @@ isc_nm_listentls(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, */ if (proxy) { result = isc_nm_listenproxystream( - mgr, workers, iface, tlslisten_acceptcb, tlssock, - backlog, quota, NULL, &tlssock->outer); + workers, iface, tlslisten_acceptcb, tlssock, backlog, + quota, NULL, &tlssock->outer); } else { - result = isc_nm_listentcp(mgr, workers, iface, - tlslisten_acceptcb, tlssock, backlog, - quota, &tlssock->outer); + result = isc_nm_listentcp(workers, iface, tlslisten_acceptcb, + tlssock, backlog, quota, + &tlssock->outer); } if (result != ISC_R_SUCCESS) { tlssock->closed = true; @@ -1212,18 +1208,14 @@ static void tcp_connected(isc_nmhandle_t *handle, isc_result_t result, void *cbarg); void -isc_nm_tlsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, +isc_nm_tlsconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, isc_nm_cb_t connect_cb, void *connect_cbarg, isc_tlsctx_t *ctx, const char *sni_hostname, isc_tlsctx_client_session_cache_t *client_sess_cache, unsigned int timeout, bool proxy, isc_nm_proxyheader_info_t *proxy_info) { isc_nmsocket_t *sock = NULL; - isc__networker_t *worker = NULL; - - REQUIRE(VALID_NM(mgr)); - - worker = &mgr->workers[isc_tid()]; + isc__networker_t *worker = isc__networker_current(); if (isc__nm_closing(worker)) { connect_cb(NULL, ISC_R_SHUTTINGDOWN, connect_cbarg); @@ -1249,11 +1241,11 @@ isc_nm_tlsconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, } if (proxy) { - isc_nm_proxystreamconnect(mgr, local, peer, tcp_connected, sock, + isc_nm_proxystreamconnect(local, peer, tcp_connected, sock, sock->connect_timeout, NULL, NULL, NULL, proxy_info); } else { - isc_nm_tcpconnect(mgr, local, peer, tcp_connected, sock, + isc_nm_tcpconnect(local, peer, tcp_connected, sock, sock->connect_timeout); } } diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index 9ea9af5958..ce1f4bb638 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -67,7 +67,7 @@ static void udp_close_cb(uv_handle_t *handle); static uv_os_sock_t -isc__nm_udp_lb_socket(isc_nm_t *mgr, sa_family_t sa_family) { +isc__nm_udp_lb_socket(sa_family_t sa_family) { isc_result_t result; uv_os_sock_t sock = -1; @@ -80,7 +80,7 @@ isc__nm_udp_lb_socket(isc_nm_t *mgr, sa_family_t sa_family) { result = isc__nm_socket_reuse(sock, 1); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (mgr->load_balance_sockets) { + if (isc__netmgr->load_balance_sockets) { result = isc__nm_socket_reuse_lb(sock); RUNTIME_CHECK(result == ISC_R_SUCCESS); } @@ -104,7 +104,6 @@ start_udp_child_job(void *arg) { int uv_init_flags = 0; sa_family_t sa_family = sock->iface.type.sa.sa_family; isc_result_t result = ISC_R_UNSET; - isc_nm_t *mgr = sock->worker->netmgr; isc_loop_t *loop = sock->worker->loop; (void)isc__nm_socket_min_mtu(sock->fd, sa_family); @@ -134,7 +133,7 @@ start_udp_child_job(void *arg) { uv_bind_flags |= UV_UDP_IPV6ONLY; } - if (mgr->load_balance_sockets) { + if (isc__netmgr->load_balance_sockets) { r = isc__nm_udp_freebind(&sock->uv_handle.udp, &sock->parent->iface.type.sa, uv_bind_flags); @@ -157,7 +156,7 @@ start_udp_child_job(void *arg) { sock->uv_handle.udp.flags = sock->parent->uv_handle.udp.flags; } - isc__nm_set_network_buffers(mgr, &sock->uv_handle.handle); + isc__nm_set_network_buffers(&sock->uv_handle.handle); r = uv_udp_recv_start(&sock->uv_handle.udp, isc__nm_alloc_cb, isc__nm_udp_read_cb); @@ -179,9 +178,9 @@ done: } static void -start_udp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock, - uv_os_sock_t fd, isc_tid_t tid) { - isc__networker_t *worker = &mgr->workers[tid]; +start_udp_child(isc_sockaddr_t *iface, isc_nmsocket_t *sock, uv_os_sock_t fd, + isc_tid_t tid) { + isc__networker_t *worker = isc__networker_get(tid); isc_nmsocket_t *csock = &sock->children[tid]; isc__nmsocket_init(csock, worker, isc_nm_udpsocket, iface, sock); @@ -189,9 +188,8 @@ start_udp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock, csock->recv_cbarg = sock->recv_cbarg; csock->inactive_handles_max = ISC_NM_NMHANDLES_MAX; - if (mgr->load_balance_sockets) { - csock->fd = isc__nm_udp_lb_socket(mgr, - iface->type.sa.sa_family); + if (isc__netmgr->load_balance_sockets) { + csock->fd = isc__nm_udp_lb_socket(iface->type.sa.sa_family); } else { csock->fd = dup(fd); } @@ -205,32 +203,30 @@ start_udp_child(isc_nm_t *mgr, isc_sockaddr_t *iface, isc_nmsocket_t *sock, } isc_result_t -isc_nm_listenudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, - isc_nm_recv_cb_t cb, void *cbarg, isc_nmsocket_t **sockp) { +isc_nm_listenudp(uint32_t workers, isc_sockaddr_t *iface, isc_nm_recv_cb_t cb, + void *cbarg, isc_nmsocket_t **sockp) { isc_result_t result = ISC_R_UNSET; isc_nmsocket_t *sock = NULL; uv_os_sock_t fd = -1; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_get(0); - REQUIRE(VALID_NM(mgr)); REQUIRE(isc_tid() == 0); - worker = &mgr->workers[0]; - if (isc__nm_closing(worker)) { return ISC_R_SHUTTINGDOWN; } if (workers == 0) { - workers = mgr->nloops; + workers = isc__netmgr->nloops; } - REQUIRE(workers <= mgr->nloops); + REQUIRE(workers <= isc__netmgr->nloops); sock = isc_mempool_get(worker->nmsocket_pool); isc__nmsocket_init(sock, worker, isc_nm_udplistener, iface, NULL); - sock->nchildren = (workers == ISC_NM_LISTEN_ALL) ? (uint32_t)mgr->nloops - : workers; + sock->nchildren = (workers == ISC_NM_LISTEN_ALL) + ? (uint32_t)isc__netmgr->nloops + : workers; sock->children = isc_mem_cget(worker->mctx, sock->nchildren, sizeof(sock->children[0])); @@ -239,21 +235,21 @@ isc_nm_listenudp(isc_nm_t *mgr, uint32_t workers, isc_sockaddr_t *iface, sock->recv_cb = cb; sock->recv_cbarg = cbarg; - if (!mgr->load_balance_sockets) { - fd = isc__nm_udp_lb_socket(mgr, iface->type.sa.sa_family); + if (!isc__netmgr->load_balance_sockets) { + fd = isc__nm_udp_lb_socket(iface->type.sa.sa_family); } - start_udp_child(mgr, iface, sock, fd, 0); + start_udp_child(iface, sock, fd, 0); result = sock->children[0].result; INSIST(result != ISC_R_UNSET); for (size_t i = 1; i < sock->nchildren; i++) { - start_udp_child(mgr, iface, sock, fd, i); + start_udp_child(iface, sock, fd, i); } isc_barrier_wait(&sock->listen_barrier); - if (!mgr->load_balance_sockets) { + if (!isc__netmgr->load_balance_sockets) { isc__nm_closesocket(fd); } @@ -341,8 +337,7 @@ route_connect_direct(isc_nmsocket_t *sock) { return isc_uverr2result(r); } - isc__nm_set_network_buffers(sock->worker->netmgr, - &sock->uv_handle.handle); + isc__nm_set_network_buffers(&sock->uv_handle.handle); sock->connecting = false; sock->connected = true; @@ -353,19 +348,16 @@ route_connect_direct(isc_nmsocket_t *sock) { #endif /* USE_ROUTE_SOCKET */ isc_result_t -isc_nm_routeconnect(isc_nm_t *mgr, isc_nm_cb_t cb, void *cbarg) { +isc_nm_routeconnect(isc_nm_cb_t cb, void *cbarg) { #ifdef USE_ROUTE_SOCKET isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *sock = NULL; isc__nm_uvreq_t *req = NULL; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_current(); uv_os_sock_t fd = -1; - REQUIRE(VALID_NM(mgr)); REQUIRE(isc_tid() == 0); - worker = &mgr->workers[isc_tid()]; - if (isc__nm_closing(worker)) { return ISC_R_SHUTTINGDOWN; } @@ -504,7 +496,7 @@ isc__nm_udp_read_cb(uv_udp_t *handle, ssize_t nrecv, const uv_buf_t *buf, * - If we're simulating a firewall blocking UDP packets * bigger than 'maxudp' bytes for testing purposes. */ - maxudp = atomic_load_relaxed(&sock->worker->netmgr->maxudp); + maxudp = atomic_load_relaxed(&isc__netmgr->maxudp); if (maxudp != 0 && (uint32_t)nrecv > maxudp) { /* * We need to keep the read_cb intact in case, so the @@ -675,7 +667,7 @@ isc__nm_udp_send(isc_nmhandle_t *handle, const isc_region_t *region, REQUIRE(sock->tid == isc_tid()); worker = sock->worker; - maxudp = atomic_load(&worker->netmgr->maxudp); + maxudp = atomic_load(&isc__netmgr->maxudp); sa = sock->connected ? NULL : &peer->type.sa; /* @@ -721,7 +713,7 @@ isc__nm_udp_send(isc_nmhandle_t *handle, const isc_region_t *region, if (r < 0) { if (can_log_udp_sends()) { isc__netmgr_log( - worker->netmgr, ISC_LOG_ERROR, + ISC_LOG_ERROR, "Sending UDP messages failed: %s", isc_result_totext(isc_uverr2result(r))); } @@ -792,8 +784,7 @@ udp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { return isc_uverr2result(r); } - isc__nm_set_network_buffers(sock->worker->netmgr, - &sock->uv_handle.handle); + isc__nm_set_network_buffers(&sock->uv_handle.handle); /* * On FreeBSD the UDP connect() call sometimes results in a @@ -813,21 +804,18 @@ udp_connect_direct(isc_nmsocket_t *sock, isc__nm_uvreq_t *req) { } void -isc_nm_udpconnect(isc_nm_t *mgr, isc_sockaddr_t *local, isc_sockaddr_t *peer, - isc_nm_cb_t cb, void *cbarg, unsigned int timeout) { +isc_nm_udpconnect(isc_sockaddr_t *local, isc_sockaddr_t *peer, isc_nm_cb_t cb, + void *cbarg, unsigned int timeout) { isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *sock = NULL; isc__nm_uvreq_t *req = NULL; sa_family_t sa_family; - isc__networker_t *worker = NULL; + isc__networker_t *worker = isc__networker_current(); uv_os_sock_t fd = -1; - REQUIRE(VALID_NM(mgr)); REQUIRE(local != NULL); REQUIRE(peer != NULL); - worker = &mgr->workers[isc_tid()]; - if (isc__nm_closing(worker)) { cb(NULL, ISC_R_SHUTTINGDOWN, cbarg); return; diff --git a/lib/ns/client.c b/lib/ns/client.c index 5908a512ed..4af61516fe 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -1189,8 +1189,7 @@ no_nsid: } if (TCP_CLIENT(client) && USEKEEPALIVE(client)) { isc_buffer_t buf; - uint32_t advertised_timeout = isc_nm_getadvertisedtimeout( - isc_nmhandle_netmgr(client->inner.handle)); + uint32_t advertised_timeout = isc_nm_getadvertisedtimeout(); INSIST(count < DNS_EDNSOPTIONS); diff --git a/lib/ns/include/ns/interfacemgr.h b/lib/ns/include/ns/interfacemgr.h index 20f4eb5a03..c338563b1f 100644 --- a/lib/ns/include/ns/interfacemgr.h +++ b/lib/ns/include/ns/interfacemgr.h @@ -98,7 +98,7 @@ struct ns_interface { ***/ isc_result_t -ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_nm_t *nm, +ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, dns_dispatchmgr_t *dispatchmgr, dns_geoip_databases_t *geoip, ns_interfacemgr_t **mgrp); /*%< diff --git a/lib/ns/interfacemgr.c b/lib/ns/interfacemgr.c index 5cf3d0821b..14805db6a5 100644 --- a/lib/ns/interfacemgr.c +++ b/lib/ns/interfacemgr.c @@ -65,7 +65,6 @@ struct ns_interfacemgr { isc_mutex_t lock; isc_mem_t *mctx; /*%< Memory context */ ns_server_t *sctx; /*%< Server context */ - isc_nm_t *nm; /*%< Net manager */ uint32_t ncpus; /*%< Number of workers */ dns_dispatchmgr_t *dispatchmgr; unsigned int generation; /*%< Current generation no */ @@ -266,7 +265,7 @@ route_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) { } isc_result_t -ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_nm_t *nm, +ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, dns_dispatchmgr_t *dispatchmgr, dns_geoip_databases_t *geoip, ns_interfacemgr_t **mgrp) { isc_result_t result; @@ -278,7 +277,6 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_nm_t *nm, mgr = isc_mem_get(mctx, sizeof(*mgr)); *mgr = (ns_interfacemgr_t){ - .nm = nm, .dispatchmgr = dispatchmgr, .generation = 1, .ncpus = isc_loopmgr_nloops(), @@ -342,8 +340,7 @@ ns_interfacemgr_routeconnect(ns_interfacemgr_t *mgr) { ns_interfacemgr_ref(mgr); - isc_result_t result = isc_nm_routeconnect(mgr->nm, route_connected, - mgr); + isc_result_t result = isc_nm_routeconnect(route_connected, mgr); if (result != ISC_R_SUCCESS) { isc_log_write(NS_LOGCATEGORY_NETWORK, NS_LOGMODULE_INTERFACEMGR, ISC_LOG_INFO, "unable to open route socket: %s", @@ -477,14 +474,14 @@ ns_interface_listenudp(ns_interface_t *ifp, isc_nm_proxy_type_t proxy) { /* Reserve space for an ns_client_t with the netmgr handle */ if (proxy == ISC_NM_PROXY_NONE) { - result = isc_nm_listenudp(ifp->mgr->nm, ISC_NM_LISTEN_ALL, - &ifp->addr, ns_client_request, ifp, + result = isc_nm_listenudp(ISC_NM_LISTEN_ALL, &ifp->addr, + ns_client_request, ifp, &ifp->udplistensocket); } else { INSIST(proxy == ISC_NM_PROXY_PLAIN); - result = isc_nm_listenproxyudp(ifp->mgr->nm, ISC_NM_LISTEN_ALL, - &ifp->addr, ns_client_request, - ifp, &ifp->udplistensocket); + result = isc_nm_listenproxyudp(ISC_NM_LISTEN_ALL, &ifp->addr, + ns_client_request, ifp, + &ifp->udplistensocket); } return result; } @@ -494,8 +491,8 @@ ns_interface_listentcp(ns_interface_t *ifp, isc_nm_proxy_type_t proxy) { isc_result_t result; result = isc_nm_listenstreamdns( - ifp->mgr->nm, ISC_NM_LISTEN_ALL, &ifp->addr, ns_client_request, - ifp, ns__client_tcpconn, ifp, ifp->mgr->backlog, + ISC_NM_LISTEN_ALL, &ifp->addr, ns_client_request, ifp, + ns__client_tcpconn, ifp, ifp->mgr->backlog, &ifp->mgr->sctx->tcpquota, NULL, proxy, &ifp->tcplistensocket); if (result != ISC_R_SUCCESS) { isc_log_write(NS_LOGCATEGORY_NETWORK, NS_LOGMODULE_INTERFACEMGR, @@ -528,8 +525,8 @@ ns_interface_listentls(ns_interface_t *ifp, isc_nm_proxy_type_t proxy, isc_result_t result; result = isc_nm_listenstreamdns( - ifp->mgr->nm, ISC_NM_LISTEN_ALL, &ifp->addr, ns_client_request, - ifp, ns__client_tcpconn, ifp, ifp->mgr->backlog, + ISC_NM_LISTEN_ALL, &ifp->addr, ns_client_request, ifp, + ns__client_tcpconn, ifp, ifp->mgr->backlog, &ifp->mgr->sctx->tcpquota, sslctx, proxy, &ifp->tlslistensocket); @@ -591,9 +588,8 @@ ns_interface_listenhttp(ns_interface_t *ifp, isc_nm_proxy_type_t proxy, quota = isc_mem_get(ifp->mgr->mctx, sizeof(*quota)); isc_quota_init(quota, max_clients); result = isc_nm_listenhttp( - ifp->mgr->nm, ISC_NM_LISTEN_ALL, &ifp->addr, - ifp->mgr->backlog, quota, sslctx, epset, - max_concurrent_streams, proxy, &sock); + ISC_NM_LISTEN_ALL, &ifp->addr, ifp->mgr->backlog, quota, + sslctx, epset, max_concurrent_streams, proxy, &sock); } isc_nm_http_endpoints_detach(&epset); diff --git a/tests/dns/dispatch_test.c b/tests/dns/dispatch_test.c index dc24a2bd92..15c8ee132e 100644 --- a/tests/dns/dispatch_test.c +++ b/tests/dns/dispatch_test.c @@ -73,8 +73,6 @@ static dns_transport_list_t *transport_list = NULL; static isc_nmsocket_t *sock = NULL; -static isc_nm_t *connect_nm = NULL; - const struct in6_addr in6addr_blackhole = { { { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 } } }; @@ -162,8 +160,6 @@ setup_test(void **state) { setup_netmgr(state); - isc_netmgr_create(mctx, &connect_nm); - udp_connect_addr = (isc_sockaddr_t){ .length = 0 }; isc_sockaddr_fromin6(&udp_connect_addr, &in6addr_loopback, 0); @@ -194,21 +190,25 @@ setup_test(void **state) { } close(socket); - isc_nm_setinitialtimeout(netmgr, T_SERVER_INIT); - isc_nm_setprimariestimeout(netmgr, T_SERVER_PRIMARIES); - isc_nm_setidletimeout(netmgr, T_SERVER_IDLE); - isc_nm_setkeepalivetimeout(netmgr, T_SERVER_KEEPALIVE); - isc_nm_setadvertisedtimeout(netmgr, T_SERVER_ADVERTISED); + isc_nm_setinitialtimeout(T_SERVER_INIT); + isc_nm_setprimariestimeout(T_SERVER_PRIMARIES); + isc_nm_setidletimeout(T_SERVER_IDLE); + isc_nm_setkeepalivetimeout(T_SERVER_KEEPALIVE); + isc_nm_setadvertisedtimeout(T_SERVER_ADVERTISED); + + /* + * FIXME: This is not going to work now. + */ /* * Use shorter client-side timeouts, to ensure that clients * time out before the server. */ - isc_nm_setinitialtimeout(connect_nm, T_CLIENT_INIT); - isc_nm_setprimariestimeout(connect_nm, T_CLIENT_PRIMARIES); - isc_nm_setidletimeout(connect_nm, T_CLIENT_IDLE); - isc_nm_setkeepalivetimeout(connect_nm, T_CLIENT_KEEPALIVE); - isc_nm_setadvertisedtimeout(connect_nm, T_CLIENT_ADVERTISED); + isc_nm_setinitialtimeout(T_CLIENT_INIT); + isc_nm_setprimariestimeout(T_CLIENT_PRIMARIES); + isc_nm_setidletimeout(T_CLIENT_IDLE); + isc_nm_setkeepalivetimeout(T_CLIENT_KEEPALIVE); + isc_nm_setadvertisedtimeout(T_CLIENT_ADVERTISED); memset(testdata.rbuf, 0, sizeof(testdata.rbuf)); testdata.region.base = testdata.rbuf; @@ -244,8 +244,6 @@ teardown_test(void **state) { isc_tlsctx_cache_detach(&tls_tlsctx_client_cache); isc_tlsctx_free(&tls_listen_tlsctx); - isc_nm_detach(&connect_nm); - teardown_netmgr(state); teardown_loopmgr(state); @@ -279,7 +277,7 @@ ISC_LOOP_TEST_IMPL(dispatchset_create) { UNUSED(arg); - result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = make_dispatchset(dispatchmgr, 1, &dset); @@ -305,7 +303,7 @@ ISC_LOOP_TEST_IMPL(dispatchset_get) { UNUSED(arg); - result = dns_dispatchmgr_create(mctx, connect_nm, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, &dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = make_dispatchset(dispatchmgr, 1, &dset); @@ -593,7 +591,7 @@ ISC_LOOP_TEST_IMPL(dispatch_timeout_tcp_connect) { testdata.region.base = testdata.message; testdata.region.length = sizeof(testdata.message); - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp(test->dispatchmgr, &tcp_connect_addr, @@ -630,15 +628,15 @@ ISC_LOOP_TEST_IMPL(dispatch_timeout_tcp_response) { /* Server */ result = isc_nm_listenstreamdns( - netmgr, ISC_NM_LISTEN_ONE, &tcp_server_addr, noop_nameserver, - NULL, accept_cb, NULL, 0, NULL, NULL, ISC_NM_PROXY_NONE, &sock); + ISC_NM_LISTEN_ONE, &tcp_server_addr, noop_nameserver, NULL, + accept_cb, NULL, 0, NULL, NULL, ISC_NM_PROXY_NONE, &sock); assert_int_equal(result, ISC_R_SUCCESS); /* ensure we stop listening after the test is done */ isc_loop_teardown(isc_loop_main(), stop_listening, sock); /* Client */ - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp(test->dispatchmgr, &tcp_connect_addr, @@ -662,9 +660,9 @@ ISC_LOOP_TEST_IMPL(dispatch_tcp_response) { *test = (test_dispatch_t){ 0 }; /* Server */ - result = isc_nm_listenstreamdns( - netmgr, ISC_NM_LISTEN_ONE, &tcp_server_addr, nameserver, NULL, - accept_cb, NULL, 0, NULL, NULL, ISC_NM_PROXY_NONE, &sock); + result = isc_nm_listenstreamdns(ISC_NM_LISTEN_ONE, &tcp_server_addr, + nameserver, NULL, accept_cb, NULL, 0, + NULL, NULL, ISC_NM_PROXY_NONE, &sock); assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), stop_listening, sock); @@ -673,7 +671,7 @@ ISC_LOOP_TEST_IMPL(dispatch_tcp_response) { testdata.region.base = testdata.message; testdata.region.length = sizeof(testdata.message); - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp(test->dispatchmgr, &tcp_connect_addr, @@ -700,10 +698,10 @@ ISC_LOOP_TEST_IMPL(dispatch_tls_response) { *test = (test_dispatch_t){ 0 }; /* Server */ - result = isc_nm_listenstreamdns( - netmgr, ISC_NM_LISTEN_ONE, &tls_server_addr, nameserver, NULL, - accept_cb, NULL, 0, NULL, tls_listen_tlsctx, ISC_NM_PROXY_NONE, - &sock); + result = isc_nm_listenstreamdns(ISC_NM_LISTEN_ONE, &tls_server_addr, + nameserver, NULL, accept_cb, NULL, 0, + NULL, tls_listen_tlsctx, + ISC_NM_PROXY_NONE, &sock); assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), stop_listening, sock); @@ -712,7 +710,7 @@ ISC_LOOP_TEST_IMPL(dispatch_tls_response) { testdata.region.base = testdata.message; testdata.region.length = sizeof(testdata.message); - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp(test->dispatchmgr, &tls_connect_addr, @@ -739,7 +737,7 @@ ISC_LOOP_TEST_IMPL(dispatch_timeout_udp_response) { *test = (test_dispatch_t){ 0 }; /* Server */ - result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ONE, &udp_server_addr, + result = isc_nm_listenudp(ISC_NM_LISTEN_ONE, &udp_server_addr, noop_nameserver, NULL, &sock); assert_int_equal(result, ISC_R_SUCCESS); @@ -747,7 +745,7 @@ ISC_LOOP_TEST_IMPL(dispatch_timeout_udp_response) { isc_loop_teardown(isc_loop_main(), stop_listening, sock); /* Client */ - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createudp(test->dispatchmgr, &udp_connect_addr, @@ -771,7 +769,7 @@ ISC_LOOP_TEST_IMPL(dispatch_getnext) { *test = (test_dispatch_t){ 0 }; /* Server */ - result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ONE, &udp_server_addr, + result = isc_nm_listenudp(ISC_NM_LISTEN_ONE, &udp_server_addr, nameserver, NULL, &sock); assert_int_equal(result, ISC_R_SUCCESS); @@ -781,7 +779,7 @@ ISC_LOOP_TEST_IMPL(dispatch_getnext) { testdata.region.base = testdata.message; testdata.region.length = sizeof(testdata.message); - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createudp(test->dispatchmgr, &udp_connect_addr, @@ -807,15 +805,15 @@ ISC_LOOP_TEST_IMPL(dispatch_gettcp) { *test = (test_dispatch_t){ 0 }; /* Server */ - result = isc_nm_listenstreamdns( - netmgr, ISC_NM_LISTEN_ONE, &tcp_server_addr, nameserver, NULL, - accept_cb, NULL, 0, NULL, NULL, ISC_NM_PROXY_NONE, &sock); + result = isc_nm_listenstreamdns(ISC_NM_LISTEN_ONE, &tcp_server_addr, + nameserver, NULL, accept_cb, NULL, 0, + NULL, NULL, ISC_NM_PROXY_NONE, &sock); assert_int_equal(result, ISC_R_SUCCESS); /* ensure we stop listening after the test is done */ isc_loop_teardown(isc_loop_main(), stop_listening, sock); - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); /* Client */ @@ -840,16 +838,16 @@ ISC_LOOP_TEST_IMPL(dispatch_newtcp) { *test = (test_dispatch_t){ 0 }; /* Server */ - result = isc_nm_listenstreamdns( - netmgr, ISC_NM_LISTEN_ONE, &tcp_server_addr, nameserver, NULL, - accept_cb, NULL, 0, NULL, NULL, ISC_NM_PROXY_NONE, &sock); + result = isc_nm_listenstreamdns(ISC_NM_LISTEN_ONE, &tcp_server_addr, + nameserver, NULL, accept_cb, NULL, 0, + NULL, NULL, ISC_NM_PROXY_NONE, &sock); assert_int_equal(result, ISC_R_SUCCESS); /* ensure we stop listening after the test is done */ isc_loop_teardown(isc_loop_main(), stop_listening, sock); /* Client - unshared */ - result = dns_dispatchmgr_create(mctx, connect_nm, &test->dispatchmgr); + result = dns_dispatchmgr_create(mctx, &test->dispatchmgr); assert_int_equal(result, ISC_R_SUCCESS); result = dns_dispatch_createtcp( diff --git a/tests/dns/resolver_test.c b/tests/dns/resolver_test.c index 1059d7f070..56a15050e0 100644 --- a/tests/dns/resolver_test.c +++ b/tests/dns/resolver_test.c @@ -78,8 +78,8 @@ mkres(dns_resolver_t **resolverp) { isc_result_t result; isc_tlsctx_cache_create(mctx, &tlsctx_cache); - result = dns_resolver_create(view, netmgr, 0, tlsctx_cache, dispatch, - NULL, resolverp); + result = dns_resolver_create(view, 0, tlsctx_cache, dispatch, NULL, + resolverp); assert_int_equal(result, ISC_R_SUCCESS); } diff --git a/tests/dns/zonemgr_test.c b/tests/dns/zonemgr_test.c index 2fcceb8eea..29ba0fe638 100644 --- a/tests/dns/zonemgr_test.c +++ b/tests/dns/zonemgr_test.c @@ -57,7 +57,7 @@ ISC_LOOP_TEST_IMPL(zonemgr_create) { UNUSED(arg); - dns_zonemgr_create(mctx, netmgr, &myzonemgr); + dns_zonemgr_create(mctx, &myzonemgr); dns_zonemgr_shutdown(myzonemgr); dns_zonemgr_detach(&myzonemgr); @@ -74,7 +74,7 @@ ISC_LOOP_TEST_IMPL(zonemgr_managezone) { UNUSED(arg); - dns_zonemgr_create(mctx, netmgr, &myzonemgr); + dns_zonemgr_create(mctx, &myzonemgr); result = dns_test_makezone("foo", &zone, NULL, false); assert_int_equal(result, ISC_R_SUCCESS); @@ -107,7 +107,7 @@ ISC_LOOP_TEST_IMPL(zonemgr_createzone) { UNUSED(arg); - dns_zonemgr_create(mctx, netmgr, &myzonemgr); + dns_zonemgr_create(mctx, &myzonemgr); result = dns_zonemgr_createzone(myzonemgr, &zone); assert_int_equal(result, ISC_R_SUCCESS); diff --git a/tests/include/tests/isc.h b/tests/include/tests/isc.h index db1878f50d..61103d83b7 100644 --- a/tests/include/tests/isc.h +++ b/tests/include/tests/isc.h @@ -31,7 +31,6 @@ #include extern isc_mem_t *mctx; -extern isc_nm_t *netmgr; extern int ncpus; extern unsigned int workers; extern bool debug; diff --git a/tests/isc/doh_test.c b/tests/isc/doh_test.c index ed5e36b2fc..854e3cedde 100644 --- a/tests/isc/doh_test.c +++ b/tests/isc/doh_test.c @@ -54,8 +54,6 @@ #include -#define MAX_NM 2 - static isc_sockaddr_t tcp_listen_addr; static uint64_t send_magic = 0; @@ -106,8 +104,6 @@ static isc_nm_http_endpoints_t *endpoints = NULL; static atomic_bool use_PROXY = false; static atomic_bool use_PROXY_over_TLS = false; -static isc_nm_t **nm = NULL; - /* Timeout for soft-timeout tests (0.05 seconds) */ #define T_SOFT 50 #define T_CONNECT 30 * 1000 @@ -195,26 +191,26 @@ error: } static void -connect_send_request(isc_nm_t *mgr, const char *uri, bool post, - isc_region_t *region, isc_nm_recv_cb_t cb, void *cbarg, - bool tls, unsigned int timeout) { +connect_send_request(const char *uri, bool post, isc_region_t *region, + isc_nm_recv_cb_t cb, void *cbarg, bool tls, + unsigned int timeout) { isc_region_t copy; csdata_t *data = NULL; isc_tlsctx_t *ctx = NULL; - copy = (isc_region_t){ .base = isc_mem_get(mgr->mctx, region->length), + copy = (isc_region_t){ .base = isc_mem_get(mctx, region->length), .length = region->length }; memmove(copy.base, region->base, region->length); - data = isc_mem_get(mgr->mctx, sizeof(*data)); + data = isc_mem_get(mctx, sizeof(*data)); *data = (csdata_t){ .reply_cb = cb, .cb_arg = cbarg, .region = copy }; - isc_mem_attach(mgr->mctx, &data->mctx); + isc_mem_attach(mctx, &data->mctx); if (tls) { ctx = client_tlsctx; } - isc_nm_httpconnect(mgr, NULL, &tcp_listen_addr, uri, post, - connect_send_cb, data, ctx, NULL, client_sess_cache, - timeout, get_proxy_type(), NULL); + isc_nm_httpconnect(NULL, &tcp_listen_addr, uri, post, connect_send_cb, + data, ctx, NULL, client_sess_cache, timeout, + get_proxy_type(), NULL); } static int @@ -345,12 +341,7 @@ setup_test(void **state) { } setup_loopmgr(state); - - nm = isc_mem_cget(mctx, MAX_NM, sizeof(nm[0])); - for (size_t i = 0; i < MAX_NM; i++) { - isc_netmgr_create(mctx, &nm[i]); - assert_non_null(nm[i]); - } + setup_netmgr(state); server_tlsctx = NULL; isc_tlsctx_createserver(NULL, NULL, &server_tlsctx); @@ -369,19 +360,12 @@ setup_test(void **state) { INSIST(endpoints == NULL); endpoints = isc_nm_http_endpoints_new(mctx); - *state = nm; - return 0; } static int teardown_test(void **state ISC_ATTR_UNUSED) { - for (size_t i = 0; i < MAX_NM; i++) { - isc_nm_detach(&nm[i]); - assert_null(nm[i]); - } - isc_mem_cput(mctx, nm, MAX_NM, sizeof(nm[0])); - + teardown_netmgr(state); teardown_loopmgr(state); if (server_tlsctx != NULL) { @@ -501,7 +485,6 @@ doh_receive_request_cb(isc_nmhandle_t *handle, isc_result_t eresult, } ISC_LOOP_TEST_IMPL(mock_doh_uv_tcp_bind) { - isc_nm_t *listen_nm = nm[0]; isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; @@ -510,9 +493,8 @@ ISC_LOOP_TEST_IMPL(mock_doh_uv_tcp_bind) { result = isc_nm_http_endpoints_add(endpoints, ISC_NM_HTTP_DEFAULT_PATH, noop_read_cb, NULL); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL, - &tcp_listen_addr, 0, NULL, NULL, endpoints, - 0, false, &listen_sock); + result = isc_nm_listenhttp(ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, NULL, + NULL, endpoints, 0, false, &listen_sock); assert_int_not_equal(result, ISC_R_SUCCESS); assert_null(listen_sock); @@ -532,8 +514,6 @@ listen_sock_close(void *arg) { static void doh_noop(void *arg ISC_ATTR_UNUSED) { - isc_nm_t *listen_nm = nm[0]; - isc_nm_t *connect_nm = nm[1]; isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; char req_url[256]; @@ -542,15 +522,15 @@ doh_noop(void *arg ISC_ATTR_UNUSED) { noop_read_cb, NULL); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL, - &tcp_listen_addr, 0, NULL, NULL, endpoints, - 0, get_proxy_type(), &listen_sock); + result = isc_nm_listenhttp(ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, NULL, + NULL, endpoints, 0, get_proxy_type(), + &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), listen_sock_close, listen_sock); sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url), ISC_NM_HTTP_DEFAULT_PATH); - connect_send_request(connect_nm, req_url, atomic_load(&POST), + connect_send_request(req_url, atomic_load(&POST), &(isc_region_t){ .base = (uint8_t *)send_msg.base, .length = send_msg.len }, noop_read_cb, NULL, atomic_load(&use_TLS), 30000); @@ -575,8 +555,6 @@ ISC_LOOP_TEST_IMPL(doh_noop_GET) { static void doh_noresponse(void *arg ISC_ATTR_UNUSED) { - isc_nm_t *listen_nm = nm[0]; - isc_nm_t *connect_nm = nm[1]; isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; char req_url[256]; @@ -585,15 +563,15 @@ doh_noresponse(void *arg ISC_ATTR_UNUSED) { noop_read_cb, NULL); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL, - &tcp_listen_addr, 0, NULL, NULL, endpoints, - 0, get_proxy_type(), &listen_sock); + result = isc_nm_listenhttp(ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, NULL, + NULL, endpoints, 0, get_proxy_type(), + &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), listen_sock_close, listen_sock); sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url), ISC_NM_HTTP_DEFAULT_PATH); - connect_send_request(connect_nm, req_url, atomic_load(&POST), + connect_send_request(req_url, atomic_load(&POST), &(isc_region_t){ .base = (uint8_t *)send_msg.base, .length = send_msg.len }, noop_read_cb, NULL, atomic_load(&use_TLS), 30000); @@ -661,14 +639,13 @@ timeout_request_cb(isc_nmhandle_t *handle, isc_result_t result, void *arg) { timeout_query_sent_cb, arg); isc_nmhandle_attach(handle, &readhandle); + isc_nmhandle_settimeout(handle, T_SOFT); isc_nm_read(handle, timeout_retry_cb, NULL); } static void doh_timeout_recovery(void *arg ISC_ATTR_UNUSED) { - isc_nm_t *listen_nm = nm[0]; isc_nmsocket_t *listen_sock = NULL; - isc_nm_t *connect_nm = nm[1]; isc_result_t result = ISC_R_SUCCESS; isc_tlsctx_t *ctx = atomic_load(&use_TLS) ? server_tlsctx : NULL; char req_url[256]; @@ -677,9 +654,9 @@ doh_timeout_recovery(void *arg ISC_ATTR_UNUSED) { doh_receive_request_cb, NULL); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_nm_listenhttp(listen_nm, ISC_NM_LISTEN_ALL, - &tcp_listen_addr, 0, NULL, NULL, endpoints, - 0, get_proxy_type(), &listen_sock); + result = isc_nm_listenhttp(ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, NULL, + NULL, endpoints, 0, get_proxy_type(), + &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), listen_sock_close, listen_sock); @@ -690,19 +667,13 @@ doh_timeout_recovery(void *arg ISC_ATTR_UNUSED) { noanswer = true; /* - * Shorten all the TCP client timeouts to 0.05 seconds. * timeout_retry_cb() will give up after five timeouts. */ - isc_nm_setinitialtimeout(connect_nm, T_SOFT); - isc_nm_setprimariestimeout(connect_nm, T_SOFT); - isc_nm_setidletimeout(connect_nm, T_SOFT); - isc_nm_setkeepalivetimeout(connect_nm, T_SOFT); - isc_nm_setadvertisedtimeout(connect_nm, T_SOFT); sockaddr_to_url(&tcp_listen_addr, false, req_url, sizeof(req_url), ISC_NM_HTTP_DEFAULT_PATH); - isc_nm_httpconnect(connect_nm, NULL, &tcp_listen_addr, req_url, - atomic_load(&POST), timeout_request_cb, NULL, ctx, - NULL, client_sess_cache, T_CONNECT, get_proxy_type(), + isc_nm_httpconnect(NULL, &tcp_listen_addr, req_url, atomic_load(&POST), + timeout_request_cb, NULL, ctx, NULL, + client_sess_cache, T_CONNECT, get_proxy_type(), NULL); } @@ -727,9 +698,7 @@ doh_connect_thread(void *arg); static void doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult, - isc_region_t *region, void *cbarg) { - isc_nm_t *connect_nm = (isc_nm_t *)cbarg; - + isc_region_t *region, void *cbarg ISC_ATTR_UNUSED) { if (eresult != ISC_R_SUCCESS) { return; } @@ -740,7 +709,7 @@ doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult, int_fast64_t sends = atomic_fetch_sub(&nsends, 1); atomic_fetch_add(&csends, 1); atomic_fetch_add(&creads, 1); - if (sends > 0 && connect_nm != NULL) { + if (sends > 0) { size_t i; for (i = 0; i < NWRITES / 2; i++) { eresult = isc__nm_http_request( @@ -755,7 +724,7 @@ doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult, assert_true(eresult == ISC_R_SUCCESS); } - isc_async_current(doh_connect_thread, connect_nm); + isc_async_current(doh_connect_thread, NULL); } if (sends <= 0) { isc_loopmgr_shutdown(); @@ -763,8 +732,7 @@ doh_receive_send_reply_cb(isc_nmhandle_t *handle, isc_result_t eresult, } static void -doh_connect_thread(void *arg) { - isc_nm_t *connect_nm = (isc_nm_t *)arg; +doh_connect_thread(void *arg ISC_ATTR_UNUSED) { char req_url[256]; int64_t sends = atomic_load(&nsends); @@ -780,10 +748,10 @@ doh_connect_thread(void *arg) { atomic_fetch_sub(&active_cconnects, 1); return; } - connect_send_request(connect_nm, req_url, atomic_load(&POST), + connect_send_request(req_url, atomic_load(&POST), &(isc_region_t){ .base = (uint8_t *)send_msg.base, .length = send_msg.len }, - doh_receive_send_reply_cb, connect_nm, + doh_receive_send_reply_cb, NULL, atomic_load(&use_TLS), 30000); if (sends <= 0) { @@ -793,8 +761,6 @@ doh_connect_thread(void *arg) { static void doh_recv_one(void *arg ISC_ATTR_UNUSED) { - isc_nm_t *listen_nm = nm[0]; - isc_nm_t *connect_nm = nm[1]; isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; char req_url[256]; @@ -810,14 +776,14 @@ doh_recv_one(void *arg ISC_ATTR_UNUSED) { assert_int_equal(result, ISC_R_SUCCESS); result = isc_nm_listenhttp( - listen_nm, ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, quotap, + ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, quotap, atomic_load(&use_TLS) ? server_tlsctx : NULL, endpoints, 0, get_proxy_type(), &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); sockaddr_to_url(&tcp_listen_addr, atomic_load(&use_TLS), req_url, sizeof(req_url), ISC_NM_HTTP_DEFAULT_PATH); - connect_send_request(connect_nm, req_url, atomic_load(&POST), + connect_send_request(req_url, atomic_load(&POST), &(isc_region_t){ .base = (uint8_t *)send_msg.base, .length = send_msg.len }, doh_receive_reply_cb, NULL, atomic_load(&use_TLS), @@ -919,8 +885,6 @@ doh_connect_send_two_requests_cb(isc_nmhandle_t *handle, isc_result_t result, static void doh_recv_two(void *arg ISC_ATTR_UNUSED) { - isc_nm_t *listen_nm = nm[0]; - isc_nm_t *connect_nm = nm[1]; isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; char req_url[256]; @@ -937,7 +901,7 @@ doh_recv_two(void *arg ISC_ATTR_UNUSED) { assert_int_equal(result, ISC_R_SUCCESS); result = isc_nm_listenhttp( - listen_nm, ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, quotap, + ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, quotap, atomic_load(&use_TLS) ? server_tlsctx : NULL, endpoints, 0, get_proxy_type(), &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); @@ -949,10 +913,9 @@ doh_recv_two(void *arg ISC_ATTR_UNUSED) { ctx = client_tlsctx; } - isc_nm_httpconnect(connect_nm, NULL, &tcp_listen_addr, req_url, - atomic_load(&POST), doh_connect_send_two_requests_cb, - NULL, ctx, NULL, client_sess_cache, 5000, - get_proxy_type(), NULL); + isc_nm_httpconnect(NULL, &tcp_listen_addr, req_url, atomic_load(&POST), + doh_connect_send_two_requests_cb, NULL, ctx, NULL, + client_sess_cache, 5000, get_proxy_type(), NULL); isc_loop_teardown(isc_loop_main(), listen_sock_close, listen_sock); } @@ -1023,8 +986,6 @@ ISC_LOOP_TEST_IMPL(doh_recv_two_GET_TLS_quota) { static void doh_recv_send(void *arg ISC_ATTR_UNUSED) { - isc_nm_t *listen_nm = nm[0]; - isc_nm_t *connect_nm = nm[1]; isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; size_t nthreads = isc_loopmgr_nloops(); @@ -1038,13 +999,13 @@ doh_recv_send(void *arg ISC_ATTR_UNUSED) { assert_int_equal(result, ISC_R_SUCCESS); result = isc_nm_listenhttp( - listen_nm, ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, quotap, + ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, quotap, atomic_load(&use_TLS) ? server_tlsctx : NULL, endpoints, 0, get_proxy_type(), &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); for (size_t i = 0; i < nthreads; i++) { - isc_async_run(isc_loop_get(i), doh_connect_thread, connect_nm); + isc_async_run(isc_loop_get(i), doh_connect_thread, NULL); } isc_loop_teardown(isc_loop_main(), listen_sock_close, listen_sock); @@ -1135,8 +1096,6 @@ doh_bad_connect_uri_teardown(void **state) { /* See: GL #2858, !5319 */ ISC_LOOP_TEST_IMPL(doh_bad_connect_uri) { - isc_nm_t *listen_nm = nm[0]; - isc_nm_t *connect_nm = nm[1]; isc_result_t result = ISC_R_SUCCESS; isc_nmsocket_t *listen_sock = NULL; char req_url[256]; @@ -1150,9 +1109,9 @@ ISC_LOOP_TEST_IMPL(doh_bad_connect_uri) { doh_receive_request_cb, NULL); assert_int_equal(result, ISC_R_SUCCESS); - result = isc_nm_listenhttp( - listen_nm, ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, quotap, - server_tlsctx, endpoints, 0, get_proxy_type(), &listen_sock); + result = isc_nm_listenhttp(ISC_NM_LISTEN_ALL, &tcp_listen_addr, 0, + quotap, server_tlsctx, endpoints, 0, + get_proxy_type(), &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); /* @@ -1162,7 +1121,7 @@ ISC_LOOP_TEST_IMPL(doh_bad_connect_uri) { (void)snprintf(req_url, sizeof(req_url), "https://::1:%u/%s", isc_sockaddr_getport(&tcp_listen_addr), ISC_NM_HTTP_DEFAULT_PATH); - connect_send_request(connect_nm, req_url, atomic_load(&POST), + connect_send_request(req_url, atomic_load(&POST), &(isc_region_t){ .base = (uint8_t *)send_msg.base, .length = send_msg.len }, doh_receive_reply_cb, NULL, true, 30000); diff --git a/tests/isc/netmgr_common.c b/tests/isc/netmgr_common.c index 27a1199ce2..4ebb652ad6 100644 --- a/tests/isc/netmgr_common.c +++ b/tests/isc/netmgr_common.c @@ -46,9 +46,6 @@ #include -isc_nm_t *listen_nm = NULL; -isc_nm_t *connect_nm = NULL; - isc_sockaddr_t tcp_listen_addr; isc_sockaddr_t tcp_connect_addr; isc_tlsctx_t *tcp_listen_tlsctx = NULL; @@ -178,21 +175,12 @@ setup_netmgr_test(void **state) { isc_nonce_buf(&send_magic, sizeof(send_magic)); setup_loopmgr(state); - isc_netmgr_create(mctx, &listen_nm); - assert_non_null(listen_nm); - isc_nm_setinitialtimeout(listen_nm, T_INIT); - isc_nm_setprimariestimeout(listen_nm, T_PRIMARIES); - isc_nm_setidletimeout(listen_nm, T_IDLE); - isc_nm_setkeepalivetimeout(listen_nm, T_KEEPALIVE); - isc_nm_setadvertisedtimeout(listen_nm, T_ADVERTISED); - - isc_netmgr_create(mctx, &connect_nm); - assert_non_null(connect_nm); - isc_nm_setinitialtimeout(connect_nm, T_INIT); - isc_nm_setprimariestimeout(connect_nm, T_PRIMARIES); - isc_nm_setidletimeout(connect_nm, T_IDLE); - isc_nm_setkeepalivetimeout(connect_nm, T_KEEPALIVE); - isc_nm_setadvertisedtimeout(connect_nm, T_ADVERTISED); + isc_netmgr_create(mctx); + isc_nm_setinitialtimeout(T_INIT); + isc_nm_setprimariestimeout(T_PRIMARIES); + isc_nm_setidletimeout(T_IDLE); + isc_nm_setkeepalivetimeout(T_KEEPALIVE); + isc_nm_setadvertisedtimeout(T_ADVERTISED); isc_quota_init(&listener_quota, 0); atomic_store(&check_listener_quota, false); @@ -228,11 +216,7 @@ teardown_netmgr_test(void **state ISC_ATTR_UNUSED) { isc_tlsctx_free(&tcp_connect_tlsctx); isc_tlsctx_free(&tcp_listen_tlsctx); - isc_nm_detach(&connect_nm); - assert_null(connect_nm); - - isc_nm_detach(&listen_nm); - assert_null(listen_nm); + isc_netmgr_destroy(); teardown_loopmgr(state); @@ -404,6 +388,10 @@ connect_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, void *cbarg) { isc_refcount_increment0(&active_creads); isc_nmhandle_attach(handle, &readhandle); + /* + * Shorten all the client timeouts to 0.05 seconds. + */ + isc_nmhandle_settimeout(handle, T_SOFT); isc_nm_read(handle, connect_readcb, NULL); connect_send(handle); @@ -554,7 +542,7 @@ stream_recv_send_connect(void *arg) { isc_sockaddr_fromin6(&connect_addr, &in6addr_loopback, 0); isc_refcount_increment0(&active_cconnects); - connect(connect_nm); + connect(); } /* Common stream protocols code */ @@ -595,14 +583,14 @@ tcp_listener_init_quota(size_t nthreads) { } static void -tcp_connect(isc_nm_t *nm) { - isc_nm_tcpconnect(nm, &tcp_connect_addr, &tcp_listen_addr, +tcp_connect(void) { + isc_nm_tcpconnect(&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, NULL, T_CONNECT); } static void -tls_connect(isc_nm_t *nm) { - isc_nm_tlsconnect(nm, &tcp_connect_addr, &tcp_listen_addr, +tls_connect(void) { + isc_nm_tlsconnect(&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, NULL, tcp_connect_tlsctx, NULL, tcp_tlsctx_client_sess_cache, T_CONNECT, stream_use_PROXY, NULL); @@ -631,13 +619,13 @@ get_proxyheader_info(void) { } static void -proxystream_connect(isc_nm_t *nm) { +proxystream_connect(void) { isc_tlsctx_t *tlsctx = stream_PROXY_over_TLS ? tcp_connect_tlsctx : NULL; isc_tlsctx_client_session_cache_t *sess_cache = stream_PROXY_over_TLS ? tcp_tlsctx_client_sess_cache : NULL; - isc_nm_proxystreamconnect(nm, &tcp_connect_addr, &tcp_listen_addr, + isc_nm_proxystreamconnect(&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, NULL, T_CONNECT, tlsctx, NULL, sess_cache, get_proxyheader_info()); } @@ -661,22 +649,22 @@ stream_listen(isc_nm_accept_cb_t accept_cb, void *accept_cbarg, int backlog, isc_result_t result = ISC_R_SUCCESS; if (stream_use_TLS && !stream_PROXY_over_TLS) { - result = isc_nm_listentls( - listen_nm, ISC_NM_LISTEN_ALL, &tcp_listen_addr, - accept_cb, accept_cbarg, backlog, quota, - tcp_listen_tlsctx, stream_use_PROXY, sockp); + result = isc_nm_listentls(ISC_NM_LISTEN_ALL, &tcp_listen_addr, + accept_cb, accept_cbarg, backlog, + quota, tcp_listen_tlsctx, + stream_use_PROXY, sockp); return result; } else if (stream_use_PROXY) { isc_tlsctx_t *tlsctx = stream_PROXY_over_TLS ? tcp_listen_tlsctx : NULL; result = isc_nm_listenproxystream( - listen_nm, ISC_NM_LISTEN_ALL, &tcp_listen_addr, - accept_cb, accept_cbarg, backlog, quota, tlsctx, sockp); + ISC_NM_LISTEN_ALL, &tcp_listen_addr, accept_cb, + accept_cbarg, backlog, quota, tlsctx, sockp); return result; } else { - result = isc_nm_listentcp(listen_nm, ISC_NM_LISTEN_ALL, - &tcp_listen_addr, accept_cb, - accept_cbarg, backlog, quota, sockp); + result = isc_nm_listentcp(ISC_NM_LISTEN_ALL, &tcp_listen_addr, + accept_cb, accept_cbarg, backlog, + quota, sockp); return result; } @@ -688,9 +676,8 @@ stream_connect(isc_nm_cb_t cb, void *cbarg, unsigned int timeout) { isc_refcount_increment0(&active_cconnects); if (stream_use_TLS && !stream_PROXY_over_TLS) { - isc_nm_tlsconnect(connect_nm, &tcp_connect_addr, - &tcp_listen_addr, cb, cbarg, - tcp_connect_tlsctx, NULL, + isc_nm_tlsconnect(&tcp_connect_addr, &tcp_listen_addr, cb, + cbarg, tcp_connect_tlsctx, NULL, tcp_tlsctx_client_sess_cache, timeout, stream_use_PROXY, NULL); return; @@ -701,14 +688,13 @@ stream_connect(isc_nm_cb_t cb, void *cbarg, unsigned int timeout) { isc_tlsctx_client_session_cache_t *sess_cache = stream_PROXY_over_TLS ? tcp_tlsctx_client_sess_cache : NULL; - isc_nm_proxystreamconnect(connect_nm, &tcp_connect_addr, - &tcp_listen_addr, cb, cbarg, timeout, - tlsctx, NULL, sess_cache, - get_proxyheader_info()); + isc_nm_proxystreamconnect(&tcp_connect_addr, &tcp_listen_addr, + cb, cbarg, timeout, tlsctx, NULL, + sess_cache, get_proxyheader_info()); return; } else { - isc_nm_tcpconnect(connect_nm, &tcp_connect_addr, - &tcp_listen_addr, cb, cbarg, timeout); + isc_nm_tcpconnect(&tcp_connect_addr, &tcp_listen_addr, cb, + cbarg, timeout); return; } UNREACHABLE(); @@ -1031,14 +1017,7 @@ stream_timeout_recovery(void **state ISC_ATTR_UNUSED) { assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), stop_listening, listen_sock); - /* - * Shorten all the client timeouts to 0.05 seconds. - */ - isc_nm_setinitialtimeout(connect_nm, T_SOFT); - isc_nm_setprimariestimeout(connect_nm, T_SOFT); - isc_nm_setidletimeout(connect_nm, T_SOFT); - isc_nm_setkeepalivetimeout(connect_nm, T_SOFT); - isc_nm_setadvertisedtimeout(connect_nm, T_SOFT); + // isc_nm_setinitialtimeout(T_SOFT); connect_readcb = timeout_retry_cb; stream_connect(connect_connect_cb, NULL, T_CONNECT); } @@ -1342,12 +1321,11 @@ teardown_udp_test(void **state) { static void udp_connect(isc_nm_cb_t cb, void *cbarg, unsigned int timeout) { if (udp_use_PROXY) { - isc_nm_proxyudpconnect(netmgr, &udp_connect_addr, - &udp_listen_addr, cb, cbarg, timeout, - NULL); + isc_nm_proxyudpconnect(&udp_connect_addr, &udp_listen_addr, cb, + cbarg, timeout, NULL); } else { - isc_nm_udpconnect(netmgr, &udp_connect_addr, &udp_listen_addr, - cb, cbarg, timeout); + isc_nm_udpconnect(&udp_connect_addr, &udp_listen_addr, cb, + cbarg, timeout); } } @@ -1365,12 +1343,11 @@ udp_start_listening(uint32_t nworkers, isc_nm_recv_cb_t cb) { isc_result_t result; if (udp_use_PROXY) { - result = isc_nm_listenproxyudp(netmgr, nworkers, - &udp_listen_addr, cb, NULL, - &listen_sock); + result = isc_nm_listenproxyudp(nworkers, &udp_listen_addr, cb, + NULL, &listen_sock); } else { - result = isc_nm_listenudp(netmgr, nworkers, &udp_listen_addr, - cb, NULL, &listen_sock); + result = isc_nm_listenudp(nworkers, &udp_listen_addr, cb, NULL, + &listen_sock); } assert_int_equal(result, ISC_R_SUCCESS); @@ -1831,7 +1808,7 @@ udp_shutdown_connect_connect_cb(isc_nmhandle_t *handle, isc_result_t eresult, */ if (atomic_fetch_add(&cconnects, 1) == 0) { assert_int_equal(eresult, ISC_R_SUCCESS); - isc_async_current(udp_shutdown_connect_async_cb, netmgr); + isc_async_current(udp_shutdown_connect_async_cb, NULL); } else { assert_int_equal(eresult, ISC_R_SHUTTINGDOWN); } @@ -1864,7 +1841,7 @@ udp_shutdown_connect(void **arg ISC_ATTR_UNUSED) { * isc_nm_udpconnect() is synchronous, so we need to launch this on the * async loop. */ - isc_async_current(udp_shutdown_connect_async_cb, netmgr); + isc_async_current(udp_shutdown_connect_async_cb, NULL); } int diff --git a/tests/isc/netmgr_common.h b/tests/isc/netmgr_common.h index b1c784adf9..0a1fd73fa3 100644 --- a/tests/isc/netmgr_common.h +++ b/tests/isc/netmgr_common.h @@ -31,11 +31,8 @@ #define PROXYSTREAM_TEST_PORT 9158 #define PROXYUDP_TEST_PORT 9159 -typedef void (*stream_connect_function)(isc_nm_t *nm); -typedef void (*connect_func)(isc_nm_t *); - -extern isc_nm_t *listen_nm; -extern isc_nm_t *connect_nm; +typedef void (*stream_connect_function)(void); +typedef void (*connect_func)(void); extern isc_sockaddr_t tcp_listen_addr; extern isc_sockaddr_t tcp_connect_addr; diff --git a/tests/isc/tcpdns_test.c b/tests/isc/tcpdns_test.c index 4a3fe2d43c..fcd1de8329 100644 --- a/tests/isc/tcpdns_test.c +++ b/tests/isc/tcpdns_test.c @@ -53,16 +53,16 @@ static void start_listening(uint32_t nworkers, isc_nm_accept_cb_t accept_cb, isc_nm_recv_cb_t recv_cb) { isc_result_t result = isc_nm_listenstreamdns( - listen_nm, nworkers, &tcp_listen_addr, recv_cb, NULL, accept_cb, - NULL, 128, NULL, NULL, get_proxy_type(), &listen_sock); + nworkers, &tcp_listen_addr, recv_cb, NULL, accept_cb, NULL, 128, + NULL, NULL, get_proxy_type(), &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), stop_listening, listen_sock); } static void -tcpdns_connect(isc_nm_t *nm) { - isc_nm_streamdnsconnect(nm, &tcp_connect_addr, &tcp_listen_addr, +tcpdns_connect(void) { + isc_nm_streamdnsconnect(&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, tcpdns_connect, T_CONNECT, NULL, NULL, NULL, get_proxy_type(), NULL); } @@ -72,7 +72,7 @@ ISC_LOOP_TEST_IMPL(tcpdns_noop) { connect_readcb = NULL; isc_refcount_increment0(&active_cconnects); - isc_nm_streamdnsconnect(connect_nm, &tcp_connect_addr, &tcp_listen_addr, + isc_nm_streamdnsconnect(&tcp_connect_addr, &tcp_listen_addr, connect_success_cb, tcpdns_connect, T_CONNECT, NULL, NULL, NULL, get_proxy_type(), NULL); } @@ -81,7 +81,7 @@ ISC_LOOP_TEST_IMPL(tcpdns_noresponse) { start_listening(ISC_NM_LISTEN_ALL, noop_accept_cb, noop_recv_cb); isc_refcount_increment0(&active_cconnects); - isc_nm_streamdnsconnect(connect_nm, &tcp_connect_addr, &tcp_listen_addr, + isc_nm_streamdnsconnect(&tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, tcpdns_connect, T_CONNECT, NULL, NULL, NULL, get_proxy_type(), NULL); } @@ -100,11 +100,6 @@ ISC_LOOP_TEST_IMPL(tcpdns_timeout_recovery) { * timeout_retry_cb() will give up after five timeouts. */ connect_readcb = timeout_retry_cb; - isc_nm_setinitialtimeout(connect_nm, T_SOFT); - isc_nm_setprimariestimeout(connect_nm, T_SOFT); - isc_nm_setidletimeout(connect_nm, T_SOFT); - isc_nm_setkeepalivetimeout(connect_nm, T_SOFT); - isc_nm_setadvertisedtimeout(connect_nm, T_SOFT); isc_async_current(stream_recv_send_connect, tcpdns_connect); } diff --git a/tests/isc/tlsdns_test.c b/tests/isc/tlsdns_test.c index 7dd24c44b2..037b3d8d73 100644 --- a/tests/isc/tlsdns_test.c +++ b/tests/isc/tlsdns_test.c @@ -52,18 +52,17 @@ static void start_listening(uint32_t nworkers, isc_nm_accept_cb_t accept_cb, isc_nm_recv_cb_t recv_cb) { isc_result_t result = isc_nm_listenstreamdns( - listen_nm, nworkers, &tcp_listen_addr, recv_cb, NULL, accept_cb, - NULL, 128, NULL, tcp_listen_tlsctx, get_proxy_type(), - &listen_sock); + nworkers, &tcp_listen_addr, recv_cb, NULL, accept_cb, NULL, 128, + NULL, tcp_listen_tlsctx, get_proxy_type(), &listen_sock); assert_int_equal(result, ISC_R_SUCCESS); isc_loop_teardown(isc_loop_main(), stop_listening, listen_sock); } static void -tlsdns_connect(isc_nm_t *nm) { +tlsdns_connect(void) { isc_nm_streamdnsconnect( - nm, &tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, + &tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, tlsdns_connect, T_CONNECT, tcp_connect_tlsctx, NULL, tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL); } @@ -73,22 +72,20 @@ ISC_LOOP_TEST_IMPL(tlsdns_noop) { connect_readcb = NULL; isc_refcount_increment0(&active_cconnects); - isc_nm_streamdnsconnect(connect_nm, &tcp_connect_addr, &tcp_listen_addr, - connect_success_cb, tlsdns_connect, T_CONNECT, - tcp_connect_tlsctx, NULL, - tcp_tlsctx_client_sess_cache, get_proxy_type(), - NULL); + isc_nm_streamdnsconnect( + &tcp_connect_addr, &tcp_listen_addr, connect_success_cb, + tlsdns_connect, T_CONNECT, tcp_connect_tlsctx, NULL, + tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL); } ISC_LOOP_TEST_IMPL(tlsdns_noresponse) { start_listening(ISC_NM_LISTEN_ALL, noop_accept_cb, noop_recv_cb); isc_refcount_increment0(&active_cconnects); - isc_nm_streamdnsconnect(connect_nm, &tcp_connect_addr, &tcp_listen_addr, - connect_connect_cb, tlsdns_connect, T_CONNECT, - tcp_connect_tlsctx, NULL, - tcp_tlsctx_client_sess_cache, get_proxy_type(), - NULL); + isc_nm_streamdnsconnect( + &tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, + tlsdns_connect, T_CONNECT, tcp_connect_tlsctx, NULL, + tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL); } ISC_LOOP_TEST_IMPL(tlsdns_timeout_recovery) { @@ -100,39 +97,32 @@ ISC_LOOP_TEST_IMPL(tlsdns_timeout_recovery) { start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb); /* - * Shorten all the TCP client timeouts to 0.05 seconds, connect, - * then sleep for at least a second for each 'tick'. * timeout_retry_cb() will give up after five timeouts. */ connect_readcb = timeout_retry_cb; - isc_nm_setinitialtimeout(connect_nm, T_SOFT); - isc_nm_setprimariestimeout(connect_nm, T_SOFT); - isc_nm_setidletimeout(connect_nm, T_SOFT); - isc_nm_setkeepalivetimeout(connect_nm, T_SOFT); - isc_nm_setadvertisedtimeout(connect_nm, T_SOFT); isc_refcount_increment0(&active_cconnects); isc_nm_streamdnsconnect( - connect_nm, &tcp_connect_addr, &tcp_listen_addr, - connect_connect_cb, tlsdns_connect, T_SOFT, tcp_connect_tlsctx, - NULL, tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL); + &tcp_connect_addr, &tcp_listen_addr, connect_connect_cb, + tlsdns_connect, T_SOFT, tcp_connect_tlsctx, NULL, + tcp_tlsctx_client_sess_cache, get_proxy_type(), NULL); } ISC_LOOP_TEST_IMPL(tlsdns_recv_one) { start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb); isc_refcount_increment0(&active_cconnects); - tlsdns_connect(connect_nm); + tlsdns_connect(); } ISC_LOOP_TEST_IMPL(tlsdns_recv_two) { start_listening(ISC_NM_LISTEN_ONE, listen_accept_cb, listen_read_cb); isc_refcount_increment0(&active_cconnects); - tlsdns_connect(connect_nm); + tlsdns_connect(); isc_refcount_increment0(&active_cconnects); - tlsdns_connect(connect_nm); + tlsdns_connect(); } ISC_LOOP_TEST_IMPL(tlsdns_recv_send) { diff --git a/tests/isc/udp_test.c b/tests/isc/udp_test.c index 13c6e9c78f..23557a988f 100644 --- a/tests/isc/udp_test.c +++ b/tests/isc/udp_test.c @@ -80,7 +80,7 @@ ISC_LOOP_TEST_IMPL(mock_listenudp_uv_udp_open) { WILL_RETURN(uv_udp_open, UV_ENOMEM); - result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ALL, &udp_listen_addr, + result = isc_nm_listenudp(ISC_NM_LISTEN_ALL, &udp_listen_addr, mock_recv_cb, NULL, &listen_sock); assert_int_not_equal(result, ISC_R_SUCCESS); assert_null(listen_sock); @@ -95,7 +95,7 @@ ISC_LOOP_TEST_IMPL(mock_listenudp_uv_udp_bind) { WILL_RETURN(uv_udp_bind, UV_EADDRINUSE); - result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ALL, &udp_listen_addr, + result = isc_nm_listenudp(ISC_NM_LISTEN_ALL, &udp_listen_addr, mock_recv_cb, NULL, &listen_sock); assert_int_not_equal(result, ISC_R_SUCCESS); assert_null(listen_sock); @@ -110,7 +110,7 @@ ISC_LOOP_TEST_IMPL(mock_listenudp_uv_udp_recv_start) { WILL_RETURN(uv_udp_recv_start, UV_EADDRINUSE); - result = isc_nm_listenudp(netmgr, ISC_NM_LISTEN_ALL, &udp_listen_addr, + result = isc_nm_listenudp(ISC_NM_LISTEN_ALL, &udp_listen_addr, mock_recv_cb, NULL, &listen_sock); assert_int_not_equal(result, ISC_R_SUCCESS); assert_null(listen_sock); @@ -124,7 +124,7 @@ ISC_LOOP_TEST_IMPL(mock_udpconnect_uv_udp_open) { WILL_RETURN(uv_udp_open, UV_ENOMEM); isc_refcount_increment0(&active_cconnects); - isc_nm_udpconnect(netmgr, &udp_connect_addr, &udp_listen_addr, + isc_nm_udpconnect(&udp_connect_addr, &udp_listen_addr, udp_connect_nomemory_cb, NULL, UDP_T_CONNECT); isc_loopmgr_shutdown(); @@ -135,7 +135,7 @@ ISC_LOOP_TEST_IMPL(mock_udpconnect_uv_udp_bind) { WILL_RETURN(uv_udp_bind, UV_ENOMEM); isc_refcount_increment0(&active_cconnects); - isc_nm_udpconnect(netmgr, &udp_connect_addr, &udp_listen_addr, + isc_nm_udpconnect(&udp_connect_addr, &udp_listen_addr, udp_connect_nomemory_cb, NULL, UDP_T_CONNECT); isc_loopmgr_shutdown(); @@ -146,7 +146,7 @@ ISC_LOOP_TEST_IMPL(mock_udpconnect_uv_udp_connect) { WILL_RETURN(uv_udp_connect, UV_ENOMEM); isc_refcount_increment0(&active_cconnects); - isc_nm_udpconnect(netmgr, &udp_connect_addr, &udp_listen_addr, + isc_nm_udpconnect(&udp_connect_addr, &udp_listen_addr, udp_connect_nomemory_cb, NULL, UDP_T_CONNECT); isc_loopmgr_shutdown(); @@ -157,7 +157,7 @@ ISC_LOOP_TEST_IMPL(mock_udpconnect_uv_recv_buffer_size) { WILL_RETURN(uv_recv_buffer_size, UV_ENOMEM); isc_refcount_increment0(&active_cconnects); - isc_nm_udpconnect(netmgr, &udp_connect_addr, &udp_listen_addr, + isc_nm_udpconnect(&udp_connect_addr, &udp_listen_addr, connect_success_cb, NULL, UDP_T_CONNECT); isc_loopmgr_shutdown(); @@ -168,7 +168,7 @@ ISC_LOOP_TEST_IMPL(mock_udpconnect_uv_send_buffer_size) { WILL_RETURN(uv_send_buffer_size, UV_ENOMEM); isc_refcount_increment0(&active_cconnects); - isc_nm_udpconnect(netmgr, &udp_connect_addr, &udp_listen_addr, + isc_nm_udpconnect(&udp_connect_addr, &udp_listen_addr, connect_success_cb, NULL, UDP_T_CONNECT); isc_loopmgr_shutdown(); diff --git a/tests/libtest/dns.c b/tests/libtest/dns.c index d31ba9b5b5..1684c4c0bd 100644 --- a/tests/libtest/dns.c +++ b/tests/libtest/dns.c @@ -65,7 +65,7 @@ dns_test_makeview(const char *name, bool with_dispatchmgr, bool with_cache, dns_dispatchmgr_t *dispatchmgr = NULL; if (with_dispatchmgr) { - result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, &dispatchmgr); if (result != ISC_R_SUCCESS) { return result; } @@ -160,7 +160,7 @@ void dns_test_setupzonemgr(void) { REQUIRE(zonemgr == NULL); - dns_zonemgr_create(mctx, netmgr, &zonemgr); + dns_zonemgr_create(mctx, &zonemgr); } isc_result_t diff --git a/tests/libtest/isc.c b/tests/libtest/isc.c index d9eed102db..7ea320095e 100644 --- a/tests/libtest/isc.c +++ b/tests/libtest/isc.c @@ -33,7 +33,6 @@ #include isc_mem_t *mctx = NULL; -isc_nm_t *netmgr = NULL; unsigned int workers = 0; bool debug = false; @@ -95,8 +94,6 @@ setup_loopmgr(void **state ISC_ATTR_UNUSED) { int teardown_loopmgr(void **state ISC_ATTR_UNUSED) { - REQUIRE(netmgr == NULL); - isc_loopmgr_destroy(); return 0; @@ -106,14 +103,14 @@ int setup_netmgr(void **state ISC_ATTR_UNUSED) { adjustnofile(); - isc_netmgr_create(mctx, &netmgr); + isc_netmgr_create(mctx); return 0; } int teardown_netmgr(void **state ISC_ATTR_UNUSED) { - isc_nm_detach(&netmgr); + isc_netmgr_destroy(); return 0; } diff --git a/tests/libtest/ns.c b/tests/libtest/ns.c index 76d909c055..8583f64060 100644 --- a/tests/libtest/ns.c +++ b/tests/libtest/ns.c @@ -90,12 +90,12 @@ setup_server(void **state) { ns_server_create(mctx, matchview, &sctx); - result = dns_dispatchmgr_create(mctx, netmgr, &dispatchmgr); + result = dns_dispatchmgr_create(mctx, &dispatchmgr); if (result != ISC_R_SUCCESS) { goto cleanup; } - result = ns_interfacemgr_create(mctx, sctx, netmgr, dispatchmgr, NULL, + result = ns_interfacemgr_create(mctx, sctx, dispatchmgr, NULL, &interfacemgr); if (result != ISC_R_SUCCESS) { goto cleanup;