]> git.ipfire.org Git - zone-sync.git/commitdiff
main: Allow the user to choose the transport type
authorMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 15:26:55 +0000 (15:26 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 11 May 2026 15:26:55 +0000 (15:26 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
main.c

diff --git a/main.c b/main.c
index e7a97a6f3629a3f84cd3cee1097141961d82b6ce..381fc32288a15a80418c5b95a67d34c3d0245733 100644 (file)
--- 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) {