Skip to content

Commit afc76a5

Browse files
committed
Make DoC resource path configurable
1 parent f8798ec commit afc76a5

File tree

8 files changed

+36
-7
lines changed

8 files changed

+36
-7
lines changed

daemon/worker.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,6 +2255,7 @@ worker_init(struct worker* worker, struct config_file *cfg,
22552255
: cfg->tcp_idle_timeout,
22562256
cfg->harden_large_queries, cfg->http_max_streams,
22572257
cfg->http_endpoint, cfg->http_notls_downstream,
2258+
cfg->coap_endpoint,
22582259
worker->daemon->tcl, worker->daemon->listen_dot_sslctx,
22592260
worker->daemon->listen_doh_sslctx,
22602261
worker->daemon->listen_quic_sslctx,

services/listen_dnsport.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,10 +1530,14 @@ doc_handle_fetch(coap_resource_t *resource, coap_session_t *session,
15301530
}
15311531

15321532
static void
1533-
doc_init_resources(coap_context_t* ctx, struct comm_point* cp) {
1533+
doc_init_resources(coap_context_t* ctx, const char* resource_path, struct comm_point* cp) {
15341534
coap_resource_t* r;
15351535

1536-
log_info("Registering coap resource /");
1536+
log_info("Registering coap resource `%s`\n", resource_path);
1537+
if (resource_path[0] == '/')
1538+
{
1539+
resource_path += 1;
1540+
}
15371541
r = coap_resource_init(coap_make_str_const(""),
15381542
COAP_RESOURCE_FLAGS_NOTIFY_CON);
15391543

@@ -2000,7 +2004,9 @@ struct listen_dnsport*
20002004
listen_create(struct comm_base* base, struct listen_port* ports,
20012005
size_t bufsize, int tcp_accept_count, int tcp_idle_timeout,
20022006
int harden_large_queries, uint32_t http_max_streams,
2003-
char* http_endpoint, int http_notls, struct tcl_list* tcp_conn_limit,
2007+
char* http_endpoint, int http_notls,
2008+
char* coap_endpoint,
2009+
struct tcl_list* tcp_conn_limit,
20042010
void* dot_sslctx, void* doh_sslctx, void* quic_sslctx,
20052011
struct dt_env* dtenv,
20062012
struct doq_table* doq_table,
@@ -2036,7 +2042,7 @@ listen_create(struct comm_base* base, struct listen_port* ports,
20362042
front->udp_buff, ports->pp2_enabled, cb,
20372043
cb_arg, ports->socket);
20382044
cp->coap_context = ports->coap_context;
2039-
doc_init_resources(cp->coap_context, cp);
2045+
doc_init_resources(cp->coap_context, coap_endpoint, cp);
20402046
#endif /* HAVE_COAP */
20412047
} else if(ports->ftype == listen_type_doq) {
20422048
#ifndef HAVE_NGTCP2

services/listen_dnsport.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ int resolve_interface_names(char** ifs, int num_ifs,
213213
* @param http_max_streams: maximum number of HTTP/2 streams per connection.
214214
* @param http_endpoint: HTTP endpoint to service queries on
215215
* @param http_notls: no TLS for http downstream
216+
* @param coap_endpoint: CoAP resource path to service queries on
216217
* @param tcp_conn_limit: TCP connection limit info.
217218
* @param dot_sslctx: nonNULL if dot ssl context.
218219
* @param doh_sslctx: nonNULL if doh ssl context.
@@ -230,7 +231,9 @@ struct listen_dnsport*
230231
listen_create(struct comm_base* base, struct listen_port* ports,
231232
size_t bufsize, int tcp_accept_count, int tcp_idle_timeout,
232233
int harden_large_queries, uint32_t http_max_streams,
233-
char* http_endpoint, int http_notls, struct tcl_list* tcp_conn_limit,
234+
char* http_endpoint, int http_notls,
235+
char* coap_endpoint,
236+
struct tcl_list* tcp_conn_limit,
234237
void* dot_sslctx, void* doh_sslctx, void* quic_sslctx,
235238
struct dt_env* dtenv,
236239
struct doq_table* doq_table,

testcode/fake_event.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,7 @@ listen_create(struct comm_base* base, struct listen_port* ATTR_UNUSED(ports),
953953
uint32_t ATTR_UNUSED(http_max_streams),
954954
char* ATTR_UNUSED(http_endpoint),
955955
int ATTR_UNUSED(http_notls),
956+
char* ATTR_UNUSED(coap_endpoint),
956957
struct tcl_list* ATTR_UNUSED(tcp_conn_limit),
957958
void* ATTR_UNUSED(dot_sslctx), void* ATTR_UNUSED(doh_sslctx),
958959
void* ATTR_UNUSED(quic_ssl),

util/config_file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ config_create(void)
140140
cfg->quic_size = 8*1024*1024;
141141
cfg->coap_port = UNBOUND_DNS_OVER_COAP_PORT;
142142
cfg->coaps_port = UNBOUND_DNS_OVER_COAPS_PORT;
143+
if(!(cfg->coap_endpoint = strdup("/"))) goto error_exit;
143144
cfg->coaps_psk = NULL;
144145
cfg->coaps_psk_id = NULL;
145146
cfg->coap_oscore_conf = NULL;
@@ -1760,6 +1761,7 @@ config_delete(struct config_file* cfg)
17601761
free(cfg->tls_ciphers);
17611762
free(cfg->tls_ciphersuites);
17621763
free(cfg->http_endpoint);
1764+
free(cfg->coap_endpoint);
17631765
if(cfg->log_identity) {
17641766
log_ident_revert_to_default();
17651767
free(cfg->log_identity);

util/config_file.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ struct config_file {
175175
int coap_port;
176176
/** port on which to provide DNS over CoAP over DTLS over UDP service */
177177
int coaps_port;
178+
/** endpoint for CoAP service */
179+
char* coap_endpoint;
178180
/** CoAPS pre-shared key */
179181
char *coaps_psk;
180182
/** Identity sent for CoAPS pre-shared key */

util/configlexer.lex

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ quic-port{COLON} { YDVAR(1, VAR_QUIC_PORT) }
274274
quic-size{COLON} { YDVAR(1, VAR_QUIC_SIZE) }
275275
coap-port{COLON} { YDVAR(1, VAR_COAP_PORT) }
276276
coaps-port{COLON} { YDVAR(1, VAR_COAPS_PORT) }
277+
coap-endpoit{COLON} { YDVAR(1, VAR_COAP_ENDPOINT) }
277278
coaps-psk{COLON} { YDVAR(1, VAR_COAPS_PSK) }
278279
coaps-psk-id{COLON} { YDVAR(1, VAR_COAPS_PSK_ID) }
279280
coap-oscore-conf{COLON} { YDVAR(1, VAR_COAP_OSCORE_CONF) }

util/configparser.y

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ extern struct config_parser_state* cfg_parser;
211211
%token VAR_INTERFACE_ACTION VAR_INTERFACE_VIEW VAR_INTERFACE_TAG
212212
%token VAR_INTERFACE_TAG_ACTION VAR_INTERFACE_TAG_DATA
213213
%token VAR_QUIC_PORT VAR_QUIC_SIZE
214-
%token VAR_COAP_PORT VAR_COAPS_PORT VAR_COAPS_PSK VAR_COAPS_PSK_ID
214+
%token VAR_COAP_PORT VAR_COAPS_PORT VAR_COAP_ENDPOINT
215+
%token VAR_COAPS_PSK VAR_COAPS_PSK_ID
215216
%token VAR_COAP_OSCORE_CONF VAR_COAP_OSCORE_SEQ_FILE
216217
%token VAR_PROXY_PROTOCOL_PORT VAR_STATISTICS_INHIBIT_ZERO
217218
%token VAR_HARDEN_UNKNOWN_ADDITIONAL VAR_DISABLE_EDNS_DO VAR_CACHEDB_NO_STORE
@@ -355,7 +356,8 @@ content_server: server_num_threads | server_verbosity | server_port |
355356
server_zonemd_permissive_mode | server_max_reuse_tcp_queries |
356357
server_tcp_reuse_timeout | server_tcp_auth_query_timeout |
357358
server_quic_port | server_quic_size |
358-
server_coap_port | server_coaps_port | server_coaps_psk | server_coaps_psk_id |
359+
server_coap_port | server_coaps_port | server_coap_endpoint |
360+
server_coaps_psk | server_coaps_psk_id |
359361
server_coap_oscore_conf | server_coap_oscore_seq_file |
360362
server_interface_automatic_ports | server_ede |
361363
server_dns_error_reporting |
@@ -1282,6 +1284,17 @@ server_coaps_port: VAR_COAPS_PORT STRING_ARG
12821284
else cfg_parser->cfg->coaps_port = atoi($2);
12831285
free($2);
12841286
};
1287+
server_coap_endpoint: VAR_COAP_ENDPOINT STRING_ARG
1288+
{
1289+
OUTYY(("P(server_coap_endpoint:%s)\n", $2));
1290+
#ifndef HAVE_COAP
1291+
log_warn("%s:%d: Unbound is not compiled with "
1292+
"libcoap. This is required to use DNS "
1293+
"over CoAP.", cfg_parser->filename, cfg_parser->line);
1294+
#endif
1295+
free(cfg_parser->cfg->coap_endpoint);
1296+
cfg_parser->cfg->coap_endpoint = $2;
1297+
};
12851298
server_coaps_psk: VAR_COAPS_PSK STRING_ARG
12861299
{
12871300
OUTYY(("P(server_coaps_psk:%s)\n", $2));

0 commit comments

Comments
 (0)