From: Michael Tremer Date: Mon, 11 May 2026 15:26:55 +0000 (+0000) Subject: main: Allow the user to choose the transport type X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=52b25d80f2e4547ee83d103d273a30a2940dc4d8;p=zone-sync.git main: Allow the user to choose the transport type Signed-off-by: Michael Tremer --- diff --git a/main.c b/main.c index e7a97a6..381fc32 100644 --- a/main.c +++ b/main.c @@ -55,6 +55,9 @@ typedef struct ctx { // Source isc_sockaddr_t source_address; + // Transport + dns_transport_type_t transport; + // Zones const char** zones; unsigned int num_zones; @@ -89,7 +92,8 @@ typedef struct ctx { // Create the context static ctx_t ctx = { - .path = DEFAULT_PATH, + .path = DEFAULT_PATH, + .transport = DNS_TRANSPORT_NONE, }; static dns_fixedname_t fixed = {}; @@ -257,7 +261,7 @@ static int do_transfer(dns_zone_t* zone, uint32_t serial) { dns_zone_setminxfrratein(zone, 10240, 300); dns_xfrin_create(zone, xfrtype, &ctx.primary_address, &ctx.source_address, NULL, - DNS_TRANSPORT_NONE, NULL, ctx.tlsctx_cache, ctx.memctx, &xfrin); + ctx.transport, NULL, ctx.tlsctx_cache, ctx.memctx, &xfrin); // Start the transfer return dns_xfrin_start(xfrin, transfer_done); @@ -429,15 +433,17 @@ const char* argp_program_version = PACKAGE_VERSION; static const char* args_doc = "TODO"; enum { - OPT_DEBUG = 1, - OPT_PATH = 2, - OPT_PRIMARY = 3, + OPT_DEBUG = 1, + OPT_PATH = 2, + OPT_PRIMARY = 3, + OPT_TRANSPORT = 4, }; static struct argp_option options[] = { - { "debug", OPT_DEBUG, NULL, 0, "Run in debug mode", 0 }, - { "path", OPT_PATH, "PATH", 1, "Path where to store the zones", 0 }, - { "primary", OPT_PRIMARY, "HOSTNAME", 1, "The hostname of the primary to fetch from", 0 }, + { "debug", OPT_DEBUG, NULL, 0, "Run in debug mode", 0 }, + { "path", OPT_PATH, "PATH", 1, "Path where to store the zones", 0 }, + { "primary", OPT_PRIMARY, "HOSTNAME", 1, "The hostname of the primary to fetch from", 0 }, + { "transport", OPT_TRANSPORT, "TRANSPORT", 1, "Choose the transport to use (TCP or TLS)", 0 }, { NULL }, }; @@ -495,6 +501,21 @@ static error_t parse(int key, char* arg, struct argp_state* state) { ctx.primary = arg; break; + case OPT_TRANSPORT: + // TCP + if (strcmp(arg, "TCP") == 0) + ctx.transport = DNS_TRANSPORT_TCP; + + // TLS + else if (strcmp(arg, "TLS") == 0) + ctx.transport = DNS_TRANSPORT_TLS; + + // Fail on unknown transport + else + argp_failure(state, EXIT_FAILURE, 0, "Unknown transport: %s", arg); + + break; + case ARGP_KEY_ARG: zones = reallocarray(ctx.zones, ctx.num_zones + 1, sizeof(*ctx.zones)); if (!zones) {