Skip to content

Commit 073577c

Browse files
committed
Add --no-tcp, --no-udp to disable tcp/udp respectively
1 parent 4642bc3 commit 073577c

File tree

3 files changed

+30
-4
lines changed

3 files changed

+30
-4
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ install: all
207207
uninstall:
208208
$(RM) $(sbindir)/dnscrypt-wrapper
209209

210+
test:
211+
make -C tests
212+
210213
clean:
211214
$(RM) dnscrypt-wrapper
212215
$(RM) $(LIB_OBJS)

main.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ main(int argc, const char **argv)
451451
int verbose = 0;
452452
int use_xchacha20 = 0;
453453
int nolog = 0, dnssec = 0, nofilter = 0;
454+
bool no_tcp = false, no_udp = false;
454455
struct argparse argparse;
455456
struct argparse_option options[] = {
456457
OPT_HELP(),
@@ -479,6 +480,8 @@ main(int argc, const char **argv)
479480
OPT_BOOLEAN(0, "dnssec", &dnssec, "indicate that the server supports DNSSEC"),
480481
OPT_STRING('a', "listen-address", &c.listen_address,
481482
"local address to listen (default: 0.0.0.0:53)"),
483+
OPT_BOOLEAN(0, "no-udp", &no_udp, "do not listen on UDP"),
484+
OPT_BOOLEAN(0, "no-tcp", &no_tcp, "do not listen on TCP"),
482485
OPT_STRING('b', "blacklist-file", &blacklist_file, "blacklist file"),
483486
OPT_STRING('E', "ext-address", &c.ext_address, "external IP address"),
484487
OPT_STRING('r', "resolver-address", &c.resolver_address,
@@ -504,6 +507,15 @@ main(int argc, const char **argv)
504507

505508
argparse_init(&argparse, options, config_usage, 0);
506509
argparse_parse(&argparse, argc, argv);
510+
511+
if (no_udp && no_tcp) {
512+
fprintf(stderr,
513+
"Error: UDP/TCP listeners are both disabled\n\n");
514+
argparse_usage(&argparse);
515+
exit(1);
516+
}
517+
518+
507519
if (sodium_init() != 0) {
508520
return 1;
509521
}
@@ -846,12 +858,23 @@ main(int argc, const char **argv)
846858
exit(1);
847859
}
848860

849-
if (udp_listener_bind(&c) != 0 || tcp_listener_bind(&c) != 0) {
861+
if (!no_udp && udp_listener_bind(&c) != 0) {
862+
logger(LOG_ERR, "Failed to bind UDP listener on %s", c.listen_address);
863+
exit(1);
864+
}
865+
866+
if (!no_tcp && tcp_listener_bind(&c) != 0) {
867+
logger(LOG_ERR, "Failed to bind TCP listener on %s", c.listen_address);
868+
exit(1);
869+
}
870+
871+
if (!no_udp && udp_listener_start(&c) != 0) {
872+
logger(LOG_ERR, "Unable to start UDP listener on %s", c.listen_address);
850873
exit(1);
851874
}
852875

853-
if (udp_listener_start(&c) != 0 || tcp_listener_start(&c) != 0) {
854-
logger(LOG_ERR, "Unable to start udp listener.");
876+
if (!no_tcp && tcp_listener_start(&c) != 0) {
877+
logger(LOG_ERR, "Unable to start TCP listener on %s", c.listen_address);
855878
exit(1);
856879
}
857880

tests/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
all:
1+
all: test
22

33
test:
44
rake cucumber

0 commit comments

Comments
 (0)