Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6aa225f0ed | ||
|
|
d2bb93cdb7 | ||
|
|
2e2294b8c6 | ||
|
|
7518716d41 | ||
|
|
1f4ba2266e | ||
|
|
4ee3549d08 | ||
|
|
08f71dfcfb | ||
|
|
4487757fbf | ||
|
|
eed316a229 | ||
|
|
0249086217 | ||
|
|
89419de6e8 | ||
|
|
77dd8b6112 | ||
|
|
f623097eb9 |
+5
-71
@@ -50,7 +50,6 @@
|
||||
#include <isc/netmgr.h>
|
||||
#include <isc/nonce.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/portset.h>
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/signal.h>
|
||||
@@ -7946,12 +7945,10 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
dns_view_t *view_next = NULL;
|
||||
dns_viewlist_t tmpviewlist;
|
||||
dns_viewlist_t viewlist, builtin_viewlist;
|
||||
in_port_t listen_port, udpport_low, udpport_high;
|
||||
in_port_t listen_port;
|
||||
int i, backlog;
|
||||
isc_interval_t interval;
|
||||
isc_logconfig_t *logc = NULL;
|
||||
isc_portset_t *v4portset = NULL;
|
||||
isc_portset_t *v6portset = NULL;
|
||||
isc_result_t result;
|
||||
uint32_t interface_interval;
|
||||
uint32_t udpsize;
|
||||
@@ -8346,62 +8343,6 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
|
||||
#undef CAP_IF_NOT_ZERO
|
||||
|
||||
/*
|
||||
* Configure sets of UDP query source ports.
|
||||
*/
|
||||
result = isc_portset_create(named_g_mctx, &v4portset);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||
ISC_LOG_ERROR, "creating UDP/IPv4 port set: %s",
|
||||
isc_result_totext(result));
|
||||
goto cleanup_bindkeys_parser;
|
||||
}
|
||||
result = isc_portset_create(named_g_mctx, &v6portset);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||
ISC_LOG_ERROR, "creating UDP/IPv6 port set: %s",
|
||||
isc_result_totext(result));
|
||||
goto cleanup_v4portset;
|
||||
}
|
||||
|
||||
result = isc_net_getudpportrange(AF_INET, &udpport_low, &udpport_high);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||
ISC_LOG_ERROR,
|
||||
"get the default UDP/IPv4 port range: %s",
|
||||
isc_result_totext(result));
|
||||
goto cleanup_v6portset;
|
||||
}
|
||||
|
||||
isc_portset_addrange(v4portset, udpport_low, udpport_high);
|
||||
if (!ns_server_getoption(server->sctx, NS_SERVER_DISABLE4)) {
|
||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||
ISC_LOG_INFO,
|
||||
"using default UDP/IPv4 port range: "
|
||||
"[%d, %d]",
|
||||
udpport_low, udpport_high);
|
||||
}
|
||||
|
||||
result = isc_net_getudpportrange(AF_INET6, &udpport_low, &udpport_high);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||
ISC_LOG_ERROR,
|
||||
"get the default UDP/IPv6 port range: %s",
|
||||
isc_result_totext(result));
|
||||
goto cleanup_v6portset;
|
||||
}
|
||||
isc_portset_addrange(v6portset, udpport_low, udpport_high);
|
||||
if (!ns_server_getoption(server->sctx, NS_SERVER_DISABLE6)) {
|
||||
isc_log_write(NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
|
||||
ISC_LOG_INFO,
|
||||
"using default UDP/IPv6 port range: "
|
||||
"[%d, %d]",
|
||||
udpport_low, udpport_high);
|
||||
}
|
||||
|
||||
dns_dispatchmgr_setavailports(named_g_dispatchmgr, v4portset,
|
||||
v6portset);
|
||||
|
||||
/*
|
||||
* Set the EDNS UDP size when we don't match a view.
|
||||
*/
|
||||
@@ -8467,7 +8408,7 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
} else {
|
||||
result = named_config_getport(config, "port", &listen_port);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup_v6portset;
|
||||
goto cleanup_bindkeys_parser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8533,7 +8474,7 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
AF_INET, &listenon);
|
||||
}
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup_v6portset;
|
||||
goto cleanup_bindkeys_parser;
|
||||
}
|
||||
|
||||
if (listenon != NULL) {
|
||||
@@ -8567,7 +8508,7 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
AF_INET6, &listenon);
|
||||
}
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup_v6portset;
|
||||
goto cleanup_bindkeys_parser;
|
||||
}
|
||||
if (listenon != NULL) {
|
||||
ns_interfacemgr_setlistenon6(server->interfacemgr,
|
||||
@@ -8597,7 +8538,7 @@ load_configuration(const char *filename, named_server_t *server,
|
||||
"unable to listen on any configured "
|
||||
"interfaces");
|
||||
result = ISC_R_FAILURE;
|
||||
goto cleanup_v6portset;
|
||||
goto cleanup_bindkeys_parser;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9401,14 +9342,7 @@ cleanup_keystorelist:
|
||||
dns_keystore_detach(&keystore);
|
||||
}
|
||||
|
||||
cleanup_v6portset:
|
||||
isc_portset_destroy(named_g_mctx, &v6portset);
|
||||
|
||||
cleanup_v4portset:
|
||||
isc_portset_destroy(named_g_mctx, &v4portset);
|
||||
|
||||
cleanup_bindkeys_parser:
|
||||
|
||||
if (bindkeys_parser != NULL) {
|
||||
if (bindkeys != NULL) {
|
||||
cfg_obj_destroy(bindkeys_parser, &bindkeys);
|
||||
|
||||
@@ -37,7 +37,6 @@
|
||||
#include <isc/netmgr.h>
|
||||
#include <isc/nonce.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/portset.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/region.h>
|
||||
#include <isc/result.h>
|
||||
@@ -757,34 +756,6 @@ shutdown_program(void *arg) {
|
||||
maybeshutdown();
|
||||
}
|
||||
|
||||
/*
|
||||
* Try honoring the operating system's preferred ephemeral port range.
|
||||
*/
|
||||
static void
|
||||
set_source_ports(dns_dispatchmgr_t *manager) {
|
||||
isc_portset_t *v4portset = NULL, *v6portset = NULL;
|
||||
in_port_t udpport_low, udpport_high;
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_portset_create(gmctx, &v4portset);
|
||||
check_result(result, "isc_portset_create (v4)");
|
||||
result = isc_net_getudpportrange(AF_INET, &udpport_low, &udpport_high);
|
||||
check_result(result, "isc_net_getudpportrange (v4)");
|
||||
isc_portset_addrange(v4portset, udpport_low, udpport_high);
|
||||
|
||||
result = isc_portset_create(gmctx, &v6portset);
|
||||
check_result(result, "isc_portset_create (v6)");
|
||||
result = isc_net_getudpportrange(AF_INET6, &udpport_low, &udpport_high);
|
||||
check_result(result, "isc_net_getudpportrange (v6)");
|
||||
isc_portset_addrange(v6portset, udpport_low, udpport_high);
|
||||
|
||||
result = dns_dispatchmgr_setavailports(manager, v4portset, v6portset);
|
||||
check_result(result, "dns_dispatchmgr_setavailports");
|
||||
|
||||
isc_portset_destroy(gmctx, &v4portset);
|
||||
isc_portset_destroy(gmctx, &v6portset);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
create_name(const char *str, char *namedata, size_t len, dns_name_t *name) {
|
||||
isc_buffer_t namesrc, namebuf;
|
||||
@@ -920,8 +891,6 @@ setup_system(void *arg ISC_ATTR_UNUSED) {
|
||||
result = dns_dispatchmgr_create(gmctx, loopmgr, netmgr, &dispatchmgr);
|
||||
check_result(result, "dns_dispatchmgr_create");
|
||||
|
||||
set_source_ports(dispatchmgr);
|
||||
|
||||
if (have_ipv6) {
|
||||
isc_sockaddr_any6(&bind_any6);
|
||||
result = dns_dispatch_createudp(dispatchmgr, &bind_any6,
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
#include <isc/netmgr.h>
|
||||
#include <isc/nonce.h>
|
||||
#include <isc/parseint.h>
|
||||
#include <isc/portset.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/sockaddr.h>
|
||||
@@ -2035,47 +2034,6 @@ parse_args(bool is_batchfile, int argc, char **argv) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Try honoring the operating system's preferred ephemeral port range.
|
||||
*/
|
||||
static void
|
||||
set_source_ports(dns_dispatchmgr_t *manager) {
|
||||
isc_portset_t *v4portset = NULL, *v6portset = NULL;
|
||||
in_port_t udpport_low, udpport_high;
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_portset_create(mctx, &v4portset);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("isc_portset_create (v4) failed");
|
||||
}
|
||||
|
||||
result = isc_net_getudpportrange(AF_INET, &udpport_low, &udpport_high);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("isc_net_getudpportrange (v4) failed");
|
||||
}
|
||||
|
||||
isc_portset_addrange(v4portset, udpport_low, udpport_high);
|
||||
|
||||
result = isc_portset_create(mctx, &v6portset);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("isc_portset_create (v6) failed");
|
||||
}
|
||||
result = isc_net_getudpportrange(AF_INET6, &udpport_low, &udpport_high);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("isc_net_getudpportrange (v6) failed");
|
||||
}
|
||||
|
||||
isc_portset_addrange(v6portset, udpport_low, udpport_high);
|
||||
|
||||
result = dns_dispatchmgr_setavailports(manager, v4portset, v6portset);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
fatal("dns_dispatchmgr_setavailports failed");
|
||||
}
|
||||
|
||||
isc_portset_destroy(mctx, &v4portset);
|
||||
isc_portset_destroy(mctx, &v6portset);
|
||||
}
|
||||
|
||||
static void
|
||||
teardown(void *arg ISC_ATTR_UNUSED) {
|
||||
dns_view_detach(&view);
|
||||
@@ -2089,8 +2047,6 @@ static void
|
||||
setup(void *arg ISC_ATTR_UNUSED) {
|
||||
RUNCHECK(dns_dispatchmgr_create(mctx, loopmgr, netmgr, &dispatchmgr));
|
||||
|
||||
set_source_ports(dispatchmgr);
|
||||
|
||||
if (have_ipv4) {
|
||||
isc_sockaddr_any(&bind_any);
|
||||
} else {
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include <isc/mem.h>
|
||||
#include <isc/mutex.h>
|
||||
#include <isc/netmgr.h>
|
||||
#include <isc/portset.h>
|
||||
#include <isc/refcount.h>
|
||||
#include <isc/result.h>
|
||||
#include <isc/safe.h>
|
||||
@@ -135,48 +134,6 @@ client_resfind(resctx_t *rctx, dns_fetchresponse_t *event);
|
||||
static void
|
||||
destroyrestrans(dns_clientrestrans_t **transp);
|
||||
|
||||
/*
|
||||
* Try honoring the operating system's preferred ephemeral port range.
|
||||
*/
|
||||
static isc_result_t
|
||||
setsourceports(isc_mem_t *mctx, dns_dispatchmgr_t *manager) {
|
||||
isc_portset_t *v4portset = NULL, *v6portset = NULL;
|
||||
in_port_t udpport_low, udpport_high;
|
||||
isc_result_t result;
|
||||
|
||||
result = isc_portset_create(mctx, &v4portset);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
result = isc_net_getudpportrange(AF_INET, &udpport_low, &udpport_high);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
isc_portset_addrange(v4portset, udpport_low, udpport_high);
|
||||
|
||||
result = isc_portset_create(mctx, &v6portset);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
result = isc_net_getudpportrange(AF_INET6, &udpport_low, &udpport_high);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup;
|
||||
}
|
||||
isc_portset_addrange(v6portset, udpport_low, udpport_high);
|
||||
|
||||
result = dns_dispatchmgr_setavailports(manager, v4portset, v6portset);
|
||||
|
||||
cleanup:
|
||||
if (v4portset != NULL) {
|
||||
isc_portset_destroy(mctx, &v4portset);
|
||||
}
|
||||
if (v6portset != NULL) {
|
||||
isc_portset_destroy(mctx, &v6portset);
|
||||
}
|
||||
|
||||
return (result);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr,
|
||||
dns_dispatch_t **dispp, const isc_sockaddr_t *localaddr) {
|
||||
@@ -258,8 +215,6 @@ dns_client_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *nm,
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
goto cleanup_client;
|
||||
}
|
||||
(void)setsourceports(mctx, client->dispatchmgr);
|
||||
|
||||
/*
|
||||
* If only one address family is specified, use it.
|
||||
* If neither family is specified, or if both are, use both.
|
||||
|
||||
+7
-136
@@ -28,7 +28,6 @@
|
||||
#include <isc/mutex.h>
|
||||
#include <isc/net.h>
|
||||
#include <isc/netmgr.h>
|
||||
#include <isc/portset.h>
|
||||
#include <isc/random.h>
|
||||
#include <isc/stats.h>
|
||||
#include <isc/string.h>
|
||||
@@ -61,11 +60,6 @@ struct dns_dispatchmgr {
|
||||
struct cds_lfht **tcps;
|
||||
|
||||
struct cds_lfht *qids;
|
||||
|
||||
in_port_t *v4ports; /*%< available ports for IPv4 */
|
||||
unsigned int nv4ports; /*%< # of available ports for IPv4 */
|
||||
in_port_t *v6ports; /*%< available ports for IPv4 */
|
||||
unsigned int nv6ports; /*%< # of available ports for IPv4 */
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
@@ -90,7 +84,6 @@ struct dns_dispentry {
|
||||
isc_time_t start;
|
||||
isc_sockaddr_t local;
|
||||
isc_sockaddr_t peer;
|
||||
in_port_t port;
|
||||
dns_messageid_t id;
|
||||
dispatch_cb_t connected;
|
||||
dispatch_cb_t sent;
|
||||
@@ -336,38 +329,15 @@ dispentry_log(dns_dispentry_t *resp, int level, const char *fmt, ...) {
|
||||
* Choose a random port number for a dispatch entry.
|
||||
*/
|
||||
static isc_result_t
|
||||
setup_socket(dns_dispatch_t *disp, dns_dispentry_t *resp,
|
||||
const isc_sockaddr_t *dest, in_port_t *portp) {
|
||||
dns_dispatchmgr_t *mgr = disp->mgr;
|
||||
unsigned int nports;
|
||||
in_port_t *ports = NULL;
|
||||
in_port_t port = *portp;
|
||||
|
||||
setup_socket(isc_sockaddr_t *local_address, const isc_sockaddr_t *dest,
|
||||
dns_dispentry_t *resp) {
|
||||
if (resp->retries++ > 5) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
if (isc_sockaddr_pf(&disp->local) == AF_INET) {
|
||||
nports = mgr->nv4ports;
|
||||
ports = mgr->v4ports;
|
||||
} else {
|
||||
nports = mgr->nv6ports;
|
||||
ports = mgr->v6ports;
|
||||
}
|
||||
if (nports == 0) {
|
||||
return (ISC_R_ADDRNOTAVAIL);
|
||||
}
|
||||
|
||||
resp->local = disp->local;
|
||||
resp->local = *local_address;
|
||||
resp->peer = *dest;
|
||||
|
||||
if (port == 0) {
|
||||
port = ports[isc_random_uniform(nports)];
|
||||
isc_sockaddr_setport(&resp->local, port);
|
||||
*portp = port;
|
||||
}
|
||||
resp->port = port;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -376,10 +346,7 @@ qid_hash(const dns_dispentry_t *dispentry) {
|
||||
isc_hash32_t hash;
|
||||
|
||||
isc_hash32_init(&hash);
|
||||
|
||||
isc_sockaddr_hash_ex(&hash, &dispentry->peer, true);
|
||||
isc_hash32_hash(&hash, &dispentry->id, sizeof(dispentry->id), true);
|
||||
isc_hash32_hash(&hash, &dispentry->port, sizeof(dispentry->port), true);
|
||||
|
||||
return (isc_hash32_finalize(&hash));
|
||||
}
|
||||
@@ -390,8 +357,7 @@ qid_match(struct cds_lfht_node *node, const void *key0) {
|
||||
caa_container_of(node, dns_dispentry_t, ht_node);
|
||||
const dns_dispentry_t *key = key0;
|
||||
|
||||
return (dispentry->id == key->id && dispentry->port == key->port &&
|
||||
isc_sockaddr_equal(&dispentry->peer, &key->peer));
|
||||
return dispentry->id == key->id;
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -681,7 +647,6 @@ tcp_recv_success(dns_dispatch_t *disp, isc_region_t *region,
|
||||
dns_dispentry_t key = {
|
||||
.id = id,
|
||||
.peer = *peer,
|
||||
.port = isc_sockaddr_getport(&disp->local),
|
||||
};
|
||||
struct cds_lfht_iter iter;
|
||||
cds_lfht_lookup(disp->mgr->qids, qid_hash(&key), qid_match, &key,
|
||||
@@ -893,69 +858,6 @@ tcp_recv(isc_nmhandle_t *handle, isc_result_t result, isc_region_t *region,
|
||||
dns_dispatch_detach(&disp); /* DISPATCH002 */
|
||||
}
|
||||
|
||||
/*%
|
||||
* Create a temporary port list to set the initial default set of dispatch
|
||||
* ephemeral ports. This is almost meaningless as the application will
|
||||
* normally set the ports explicitly, but is provided to fill some minor corner
|
||||
* cases.
|
||||
*/
|
||||
static void
|
||||
create_default_portset(isc_mem_t *mctx, int family, isc_portset_t **portsetp) {
|
||||
in_port_t low, high;
|
||||
|
||||
isc_net_getudpportrange(family, &low, &high);
|
||||
|
||||
isc_portset_create(mctx, portsetp);
|
||||
isc_portset_addrange(*portsetp, low, high);
|
||||
}
|
||||
|
||||
static isc_result_t
|
||||
setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset,
|
||||
isc_portset_t *v6portset) {
|
||||
in_port_t *v4ports, *v6ports, p = 0;
|
||||
unsigned int nv4ports, nv6ports, i4 = 0, i6 = 0;
|
||||
|
||||
nv4ports = isc_portset_nports(v4portset);
|
||||
nv6ports = isc_portset_nports(v6portset);
|
||||
|
||||
v4ports = NULL;
|
||||
if (nv4ports != 0) {
|
||||
v4ports = isc_mem_cget(mgr->mctx, nv4ports, sizeof(in_port_t));
|
||||
}
|
||||
v6ports = NULL;
|
||||
if (nv6ports != 0) {
|
||||
v6ports = isc_mem_cget(mgr->mctx, nv6ports, sizeof(in_port_t));
|
||||
}
|
||||
|
||||
do {
|
||||
if (isc_portset_isset(v4portset, p)) {
|
||||
INSIST(i4 < nv4ports);
|
||||
v4ports[i4++] = p;
|
||||
}
|
||||
if (isc_portset_isset(v6portset, p)) {
|
||||
INSIST(i6 < nv6ports);
|
||||
v6ports[i6++] = p;
|
||||
}
|
||||
} while (p++ < 65535);
|
||||
INSIST(i4 == nv4ports && i6 == nv6ports);
|
||||
|
||||
if (mgr->v4ports != NULL) {
|
||||
isc_mem_cput(mgr->mctx, mgr->v4ports, mgr->nv4ports,
|
||||
sizeof(in_port_t));
|
||||
}
|
||||
mgr->v4ports = v4ports;
|
||||
mgr->nv4ports = nv4ports;
|
||||
|
||||
if (mgr->v6ports != NULL) {
|
||||
isc_mem_cput(mgr->mctx, mgr->v6ports, mgr->nv6ports,
|
||||
sizeof(in_port_t));
|
||||
}
|
||||
mgr->v6ports = v6ports;
|
||||
mgr->nv6ports = nv6ports;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Publics.
|
||||
*/
|
||||
@@ -964,9 +866,6 @@ isc_result_t
|
||||
dns_dispatchmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *nm,
|
||||
dns_dispatchmgr_t **mgrp) {
|
||||
dns_dispatchmgr_t *mgr = NULL;
|
||||
isc_portset_t *v4portset = NULL;
|
||||
isc_portset_t *v6portset = NULL;
|
||||
|
||||
REQUIRE(mctx != NULL);
|
||||
REQUIRE(mgrp != NULL && *mgrp == NULL);
|
||||
|
||||
@@ -992,14 +891,6 @@ dns_dispatchmgr_create(isc_mem_t *mctx, isc_loopmgr_t *loopmgr, isc_nm_t *nm,
|
||||
NULL);
|
||||
}
|
||||
|
||||
create_default_portset(mgr->mctx, AF_INET, &v4portset);
|
||||
create_default_portset(mgr->mctx, AF_INET6, &v6portset);
|
||||
|
||||
setavailports(mgr, v4portset, v6portset);
|
||||
|
||||
isc_portset_destroy(mgr->mctx, &v4portset);
|
||||
isc_portset_destroy(mgr->mctx, &v6portset);
|
||||
|
||||
mgr->qids = cds_lfht_new(QIDS_INIT_SIZE, QIDS_MIN_SIZE, 0,
|
||||
CDS_LFHT_AUTO_RESIZE | CDS_LFHT_ACCOUNTING,
|
||||
NULL);
|
||||
@@ -1031,13 +922,6 @@ dns_dispatchmgr_getblackhole(dns_dispatchmgr_t *mgr) {
|
||||
return (mgr->blackhole);
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
dns_dispatchmgr_setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset,
|
||||
isc_portset_t *v6portset) {
|
||||
REQUIRE(VALID_DISPATCHMGR(mgr));
|
||||
return (setavailports(mgr, v4portset, v6portset));
|
||||
}
|
||||
|
||||
static void
|
||||
dispatchmgr_destroy(dns_dispatchmgr_t *mgr) {
|
||||
REQUIRE(VALID_DISPATCHMGR(mgr));
|
||||
@@ -1061,15 +945,6 @@ dispatchmgr_destroy(dns_dispatchmgr_t *mgr) {
|
||||
isc_stats_detach(&mgr->stats);
|
||||
}
|
||||
|
||||
if (mgr->v4ports != NULL) {
|
||||
isc_mem_cput(mgr->mctx, mgr->v4ports, mgr->nv4ports,
|
||||
sizeof(in_port_t));
|
||||
}
|
||||
if (mgr->v6ports != NULL) {
|
||||
isc_mem_cput(mgr->mctx, mgr->v6ports, mgr->nv6ports,
|
||||
sizeof(in_port_t));
|
||||
}
|
||||
|
||||
isc_nm_detach(&mgr->nm);
|
||||
|
||||
isc_mem_putanddetach(&mgr->mctx, mgr, sizeof(dns_dispatchmgr_t));
|
||||
@@ -1420,7 +1295,6 @@ dns_dispatch_add(dns_dispatch_t *disp, isc_loop_t *loop,
|
||||
return (ISC_R_CANCELED);
|
||||
}
|
||||
|
||||
in_port_t localport = isc_sockaddr_getport(&disp->local);
|
||||
dns_dispentry_t *resp = isc_mem_get(disp->mctx, sizeof(*resp));
|
||||
*resp = (dns_dispentry_t){
|
||||
.timeout = timeout,
|
||||
@@ -1443,8 +1317,7 @@ dns_dispatch_add(dns_dispatch_t *disp, isc_loop_t *loop,
|
||||
isc_refcount_init(&resp->references, 1); /* DISPENTRY000 */
|
||||
|
||||
if (disp->socktype == isc_socktype_udp) {
|
||||
isc_result_t result = setup_socket(disp, resp, dest,
|
||||
&localport);
|
||||
isc_result_t result = setup_socket(&disp->local, dest, resp);
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
isc_mem_put(disp->mctx, resp, sizeof(*resp));
|
||||
inc_stats(disp->mgr, dns_resstatscounter_dispsockfail);
|
||||
@@ -1891,11 +1764,9 @@ udp_connected(isc_nmhandle_t *handle, isc_result_t eresult, void *arg) {
|
||||
break;
|
||||
case ISC_R_NOPERM:
|
||||
case ISC_R_ADDRINUSE: {
|
||||
in_port_t localport = isc_sockaddr_getport(&disp->local);
|
||||
isc_result_t result;
|
||||
|
||||
/* probably a port collision; try a different one */
|
||||
result = setup_socket(disp, resp, &resp->peer, &localport);
|
||||
isc_result_t result = setup_socket(&disp->local, &resp->peer,
|
||||
resp);
|
||||
if (result == ISC_R_SUCCESS) {
|
||||
udp_dispatch_connect(disp, resp);
|
||||
goto detach;
|
||||
|
||||
@@ -138,18 +138,6 @@ dns_dispatchmgr_getblackhole(dns_dispatchmgr_t *mgr);
|
||||
*\li A pointer to the current blackhole list, or NULL.
|
||||
*/
|
||||
|
||||
isc_result_t
|
||||
dns_dispatchmgr_setavailports(dns_dispatchmgr_t *mgr, isc_portset_t *v4portset,
|
||||
isc_portset_t *v6portset);
|
||||
/*%<
|
||||
* Sets a list of UDP ports that can be used for outgoing UDP messages.
|
||||
*
|
||||
* Requires:
|
||||
*\li mgr is a valid dispatchmgr
|
||||
*\li v4portset is NULL or a valid port set
|
||||
*\li v6portset is NULL or a valid port set
|
||||
*/
|
||||
|
||||
void
|
||||
dns_dispatchmgr_setstats(dns_dispatchmgr_t *mgr, isc_stats_t *stats);
|
||||
/*%<
|
||||
|
||||
@@ -62,7 +62,6 @@ libisc_la_HEADERS = \
|
||||
include/isc/overflow.h \
|
||||
include/isc/parseint.h \
|
||||
include/isc/pause.h \
|
||||
include/isc/portset.h \
|
||||
include/isc/proxy2.h \
|
||||
include/isc/queue.h \
|
||||
include/isc/quota.h \
|
||||
@@ -171,7 +170,6 @@ libisc_la_SOURCES = \
|
||||
parseint.c \
|
||||
picohttpparser.c \
|
||||
picohttpparser.h \
|
||||
portset.c \
|
||||
probes.d \
|
||||
proxy2.c \
|
||||
quota.c \
|
||||
|
||||
@@ -244,21 +244,4 @@ isc_net_enableipv4(void);
|
||||
void
|
||||
isc_net_enableipv6(void);
|
||||
|
||||
isc_result_t
|
||||
isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high);
|
||||
/*%<
|
||||
* Returns system's default range of ephemeral UDP ports, if defined.
|
||||
* If the range is not available or unknown, ISC_NET_PORTRANGELOW and
|
||||
* ISC_NET_PORTRANGEHIGH will be returned.
|
||||
*
|
||||
* Requires:
|
||||
*
|
||||
*\li 'low' and 'high' must be non NULL.
|
||||
*
|
||||
* Returns:
|
||||
*
|
||||
*\li *low and *high will be the ports specifying the low and high ends of
|
||||
* the range.
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
|
||||
@@ -1,135 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file isc/portset.h
|
||||
* \brief Transport Protocol Port Manipulation Module
|
||||
*
|
||||
* This module provides simple utilities to handle a set of transport protocol
|
||||
* (UDP or TCP) port numbers, e.g., for creating an ACL list. An isc_portset_t
|
||||
* object is an opaque instance of a port set, for which the user can add or
|
||||
* remove a specific port or a range of consecutive ports. This object is
|
||||
* expected to be used as a temporary work space only, and does not protect
|
||||
* simultaneous access from multiple threads. Therefore it must not be stored
|
||||
* in a place that can be accessed from multiple threads.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/***
|
||||
*** Imports
|
||||
***/
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <isc/net.h>
|
||||
|
||||
/***
|
||||
*** Functions
|
||||
***/
|
||||
|
||||
ISC_LANG_BEGINDECLS
|
||||
|
||||
isc_result_t
|
||||
isc_portset_create(isc_mem_t *mctx, isc_portset_t **portsetp);
|
||||
/*%<
|
||||
* Create a port set and initialize it as an empty set.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'mctx' to be valid.
|
||||
*\li 'portsetp' to be non NULL and '*portsetp' to be NULL;
|
||||
*
|
||||
* Returns:
|
||||
*\li #ISC_R_SUCCESS
|
||||
*\li #ISC_R_NOMEMORY
|
||||
*/
|
||||
|
||||
void
|
||||
isc_portset_destroy(isc_mem_t *mctx, isc_portset_t **portsetp);
|
||||
/*%<
|
||||
* Destroy a port set.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'mctx' to be valid and must be the same context given when the port set
|
||||
* was created.
|
||||
*\li '*portsetp' to be a valid set.
|
||||
*/
|
||||
|
||||
bool
|
||||
isc_portset_isset(isc_portset_t *portset, in_port_t port);
|
||||
/*%<
|
||||
* Test whether the given port is stored in the portset.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'portset' to be a valid set.
|
||||
*
|
||||
* Returns
|
||||
* \li #true if the port is found, false otherwise.
|
||||
*/
|
||||
|
||||
unsigned int
|
||||
isc_portset_nports(isc_portset_t *portset);
|
||||
/*%<
|
||||
* Provides the number of ports stored in the given portset.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'portset' to be a valid set.
|
||||
*
|
||||
* Returns
|
||||
* \li the number of ports stored in portset.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_portset_add(isc_portset_t *portset, in_port_t port);
|
||||
/*%<
|
||||
* Add the given port to the portset. The port may or may not be stored in
|
||||
* the portset.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'portlist' to be valid.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_portset_remove(isc_portset_t *portset, in_port_t port);
|
||||
/*%<
|
||||
* Remove the given port to the portset. The port may or may not be stored in
|
||||
* the portset.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'portlist' to be valid.
|
||||
*/
|
||||
|
||||
void
|
||||
isc_portset_addrange(isc_portset_t *portset, in_port_t port_lo,
|
||||
in_port_t port_hi);
|
||||
/*%<
|
||||
* Add a subset of [port_lo, port_hi] (inclusive) to the portset. Ports in the
|
||||
* subset may or may not be stored in portset.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'portlist' to be valid.
|
||||
*\li port_lo <= port_hi
|
||||
*/
|
||||
|
||||
void
|
||||
isc_portset_removerange(isc_portset_t *portset, in_port_t port_lo,
|
||||
in_port_t port_hi);
|
||||
/*%<
|
||||
* Subtract a subset of [port_lo, port_hi] (inclusive) from the portset. Ports
|
||||
* in the subset may or may not be stored in portset.
|
||||
*
|
||||
* Requires:
|
||||
*\li 'portlist' to be valid.
|
||||
*\li port_lo <= port_hi
|
||||
*/
|
||||
|
||||
ISC_LANG_ENDDECLS
|
||||
@@ -58,7 +58,6 @@ 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 */
|
||||
typedef struct isc_quota isc_quota_t; /*%< Quota */
|
||||
typedef struct isc_ratelimiter isc_ratelimiter_t; /*%< Rate Limiter */
|
||||
typedef struct isc_region isc_region_t; /*%< Region */
|
||||
|
||||
-120
@@ -330,126 +330,6 @@ isc_net_probe_ipv6pktinfo(void) {
|
||||
return (ipv6pktinfo_result);
|
||||
}
|
||||
|
||||
#if defined(USE_SYSCTL_PORTRANGE)
|
||||
#if defined(HAVE_SYSCTLBYNAME)
|
||||
static isc_result_t
|
||||
getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) {
|
||||
int port_low, port_high;
|
||||
size_t portlen;
|
||||
const char *sysctlname_lowport, *sysctlname_hiport;
|
||||
|
||||
if (af == AF_INET) {
|
||||
sysctlname_lowport = SYSCTL_V4PORTRANGE_LOW;
|
||||
sysctlname_hiport = SYSCTL_V4PORTRANGE_HIGH;
|
||||
} else {
|
||||
sysctlname_lowport = SYSCTL_V6PORTRANGE_LOW;
|
||||
sysctlname_hiport = SYSCTL_V6PORTRANGE_HIGH;
|
||||
}
|
||||
portlen = sizeof(port_low);
|
||||
if (sysctlbyname(sysctlname_lowport, &port_low, &portlen, NULL, 0) < 0)
|
||||
{
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
portlen = sizeof(port_high);
|
||||
if (sysctlbyname(sysctlname_hiport, &port_high, &portlen, NULL, 0) < 0)
|
||||
{
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0) {
|
||||
return (ISC_R_RANGE);
|
||||
}
|
||||
|
||||
*low = (in_port_t)port_low;
|
||||
*high = (in_port_t)port_high;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
#else /* !HAVE_SYSCTLBYNAME */
|
||||
static isc_result_t
|
||||
getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) {
|
||||
int mib_lo4[4] = SYSCTL_V4PORTRANGE_LOW;
|
||||
int mib_hi4[4] = SYSCTL_V4PORTRANGE_HIGH;
|
||||
int mib_lo6[4] = SYSCTL_V6PORTRANGE_LOW;
|
||||
int mib_hi6[4] = SYSCTL_V6PORTRANGE_HIGH;
|
||||
int *mib_lo, *mib_hi, miblen;
|
||||
int port_low, port_high;
|
||||
size_t portlen;
|
||||
|
||||
if (af == AF_INET) {
|
||||
mib_lo = mib_lo4;
|
||||
mib_hi = mib_hi4;
|
||||
miblen = sizeof(mib_lo4) / sizeof(mib_lo4[0]);
|
||||
} else {
|
||||
mib_lo = mib_lo6;
|
||||
mib_hi = mib_hi6;
|
||||
miblen = sizeof(mib_lo6) / sizeof(mib_lo6[0]);
|
||||
}
|
||||
|
||||
portlen = sizeof(port_low);
|
||||
if (sysctl(mib_lo, miblen, &port_low, &portlen, NULL, 0) < 0) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
portlen = sizeof(port_high);
|
||||
if (sysctl(mib_hi, miblen, &port_high, &portlen, NULL, 0) < 0) {
|
||||
return (ISC_R_FAILURE);
|
||||
}
|
||||
|
||||
if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0) {
|
||||
return (ISC_R_RANGE);
|
||||
}
|
||||
|
||||
*low = (in_port_t)port_low;
|
||||
*high = (in_port_t)port_high;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
#endif /* HAVE_SYSCTLBYNAME */
|
||||
#endif /* USE_SYSCTL_PORTRANGE */
|
||||
|
||||
isc_result_t
|
||||
isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) {
|
||||
int result = ISC_R_FAILURE;
|
||||
#if !defined(USE_SYSCTL_PORTRANGE) && defined(__linux)
|
||||
FILE *fp;
|
||||
#endif /* if !defined(USE_SYSCTL_PORTRANGE) && defined(__linux) */
|
||||
|
||||
REQUIRE(low != NULL && high != NULL);
|
||||
|
||||
#if defined(USE_SYSCTL_PORTRANGE)
|
||||
result = getudpportrange_sysctl(af, low, high);
|
||||
#elif defined(__linux)
|
||||
|
||||
UNUSED(af);
|
||||
|
||||
/*
|
||||
* Linux local ports are address family agnostic.
|
||||
*/
|
||||
fp = fopen("/proc/sys/net/ipv4/ip_local_port_range", "r");
|
||||
if (fp != NULL) {
|
||||
int n;
|
||||
unsigned int l, h;
|
||||
|
||||
n = fscanf(fp, "%u %u", &l, &h);
|
||||
if (n == 2 && (l & ~0xffff) == 0 && (h & ~0xffff) == 0) {
|
||||
*low = l;
|
||||
*high = h;
|
||||
result = ISC_R_SUCCESS;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
#else /* if defined(USE_SYSCTL_PORTRANGE) */
|
||||
UNUSED(af);
|
||||
#endif /* if defined(USE_SYSCTL_PORTRANGE) */
|
||||
|
||||
if (result != ISC_R_SUCCESS) {
|
||||
*low = ISC_NET_PORTRANGELOW;
|
||||
*high = ISC_NET_PORTRANGEHIGH;
|
||||
}
|
||||
|
||||
return (ISC_R_SUCCESS); /* we currently never fail in this function */
|
||||
}
|
||||
|
||||
void
|
||||
isc_net_disableipv4(void) {
|
||||
initialize();
|
||||
|
||||
@@ -1,133 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
|
||||
*
|
||||
* SPDX-License-Identifier: MPL-2.0
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*
|
||||
* See the COPYRIGHT file distributed with this work for additional
|
||||
* information regarding copyright ownership.
|
||||
*/
|
||||
|
||||
/*! \file */
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <isc/mem.h>
|
||||
#include <isc/portset.h>
|
||||
#include <isc/string.h>
|
||||
#include <isc/types.h>
|
||||
#include <isc/util.h>
|
||||
|
||||
#define ISC_PORTSET_BUFSIZE (65536 / (sizeof(uint32_t) * 8))
|
||||
|
||||
/*%
|
||||
* Internal representation of portset. It's an array of 32-bit integers, each
|
||||
* bit corresponding to a single port in the ascending order. For example,
|
||||
* the second most significant bit of buf[0] corresponds to port 1.
|
||||
*/
|
||||
struct isc_portset {
|
||||
unsigned int nports; /*%< number of ports in the set */
|
||||
uint32_t buf[ISC_PORTSET_BUFSIZE];
|
||||
};
|
||||
|
||||
static bool
|
||||
portset_isset(isc_portset_t *portset, in_port_t port) {
|
||||
return ((portset->buf[port >> 5] & ((uint32_t)1 << (port & 31))) != 0);
|
||||
}
|
||||
|
||||
static void
|
||||
portset_add(isc_portset_t *portset, in_port_t port) {
|
||||
if (!portset_isset(portset, port)) {
|
||||
portset->nports++;
|
||||
portset->buf[port >> 5] |= ((uint32_t)1 << (port & 31));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
portset_remove(isc_portset_t *portset, in_port_t port) {
|
||||
if (portset_isset(portset, port)) {
|
||||
portset->nports--;
|
||||
portset->buf[port >> 5] &= ~((uint32_t)1 << (port & 31));
|
||||
}
|
||||
}
|
||||
|
||||
isc_result_t
|
||||
isc_portset_create(isc_mem_t *mctx, isc_portset_t **portsetp) {
|
||||
isc_portset_t *portset;
|
||||
|
||||
REQUIRE(portsetp != NULL && *portsetp == NULL);
|
||||
|
||||
portset = isc_mem_get(mctx, sizeof(*portset));
|
||||
*portset = (isc_portset_t){ 0 };
|
||||
*portsetp = portset;
|
||||
|
||||
return (ISC_R_SUCCESS);
|
||||
}
|
||||
|
||||
void
|
||||
isc_portset_destroy(isc_mem_t *mctx, isc_portset_t **portsetp) {
|
||||
isc_portset_t *portset;
|
||||
|
||||
REQUIRE(portsetp != NULL);
|
||||
portset = *portsetp;
|
||||
|
||||
isc_mem_put(mctx, portset, sizeof(*portset));
|
||||
}
|
||||
|
||||
bool
|
||||
isc_portset_isset(isc_portset_t *portset, in_port_t port) {
|
||||
REQUIRE(portset != NULL);
|
||||
|
||||
return (portset_isset(portset, port));
|
||||
}
|
||||
|
||||
unsigned int
|
||||
isc_portset_nports(isc_portset_t *portset) {
|
||||
REQUIRE(portset != NULL);
|
||||
|
||||
return (portset->nports);
|
||||
}
|
||||
|
||||
void
|
||||
isc_portset_add(isc_portset_t *portset, in_port_t port) {
|
||||
REQUIRE(portset != NULL);
|
||||
|
||||
portset_add(portset, port);
|
||||
}
|
||||
|
||||
void
|
||||
isc_portset_remove(isc_portset_t *portset, in_port_t port) {
|
||||
portset_remove(portset, port);
|
||||
}
|
||||
|
||||
void
|
||||
isc_portset_addrange(isc_portset_t *portset, in_port_t port_lo,
|
||||
in_port_t port_hi) {
|
||||
in_port_t p;
|
||||
|
||||
REQUIRE(portset != NULL);
|
||||
REQUIRE(port_lo <= port_hi);
|
||||
|
||||
p = port_lo;
|
||||
do {
|
||||
portset_add(portset, p);
|
||||
} while (p++ < port_hi);
|
||||
}
|
||||
|
||||
void
|
||||
isc_portset_removerange(isc_portset_t *portset, in_port_t port_lo,
|
||||
in_port_t port_hi) {
|
||||
in_port_t p;
|
||||
|
||||
REQUIRE(portset != NULL);
|
||||
REQUIRE(port_lo <= port_hi);
|
||||
|
||||
p = port_lo;
|
||||
do {
|
||||
portset_remove(portset, p);
|
||||
} while (p++ < port_hi);
|
||||
}
|
||||
Reference in New Issue
Block a user