From 46d2922c7cacac35bf2d38bd581703ca76f521fc Mon Sep 17 00:00:00 2001 From: hrzlgnm Date: Wed, 25 Sep 2024 22:30:56 +0200 Subject: [PATCH 1/2] Provider ipv64.net: Fix issue with detection whether to use IPv6 or IPv4 The issue was occurring while checking whether the provider name contained "ipv6" as an indication for whether to use IPv4 or IPv4. The check confused a definition like "ipv4@ipv64.net" to use IPv6 due to having "ipv6" in the name. To address the issue we changed the check to whether the prefix of the provider name is "ipv6". While doing so, we factored out this check into a own function taking a ddns_info_* struct as an argument. --- include/ddns.h | 1 + plugins/cloudflare.c | 2 +- plugins/core-networks.c | 2 +- plugins/dnspod.c | 4 ++-- plugins/freedns.c | 2 +- plugins/porkbun.c | 2 +- src/ddns.c | 12 ++++++++++-- 7 files changed, 17 insertions(+), 8 deletions(-) diff --git a/include/ddns.h b/include/ddns.h index cae57aba..ab451e32 100644 --- a/include/ddns.h +++ b/include/ddns.h @@ -222,6 +222,7 @@ extern uid_t uid; extern gid_t gid; int ddns_main_loop (ddns_t *ctx); +int ddns_get_tcp_force(const ddns_info_t *info); int common_request (ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias); int common_response(http_trans_t *trans, ddns_info_t *info, ddns_alias_t *alias); diff --git a/plugins/cloudflare.c b/plugins/cloudflare.c index 6eaae57e..f4ff7936 100644 --- a/plugins/cloudflare.c +++ b/plugins/cloudflare.c @@ -249,7 +249,7 @@ static int json_extract(char *dest, size_t dest_size, const ddns_info_t *info, c http_set_remote_name(&client, info->server_name.name); client.ssl_enabled = info->ssl_enabled; - CHECK(http_init(&client, "Json query",strstr(info->system->name, "ipv6") ? TCP_FORCE_IPV6 : TCP_FORCE_IPV4)); + CHECK(http_init(&client, "Json query", ddns_get_tcp_force(info))); trans.req = request; trans.req_len = request_len; diff --git a/plugins/core-networks.c b/plugins/core-networks.c index 74c7b853..ae0a7a0a 100644 --- a/plugins/core-networks.c +++ b/plugins/core-networks.c @@ -52,7 +52,7 @@ static ddns_system_t plugin = { static int request(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) { char *keepip; - if (strstr(info->system->name, "ipv6")) + if (ddns_get_tcp_force(info) == TCP_FORCE_IPV6) keepip = "keepipv4=1"; else keepip = "keepipv6=1"; diff --git a/plugins/dnspod.c b/plugins/dnspod.c index ba317c40..7c031958 100644 --- a/plugins/dnspod.c +++ b/plugins/dnspod.c @@ -100,7 +100,7 @@ static int fetch_record_id(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias, http_set_remote_name(&client, info->server_name.name); client.ssl_enabled = info->ssl_enabled; - rc = http_init(&client, "Sending record list query",strstr(info->system->name, "ipv6") ? TCP_FORCE_IPV6 : TCP_FORCE_IPV4); + rc = http_init(&client, "Sending record list query", ddns_get_tcp_force(info)); if (rc) return -rc; @@ -169,7 +169,7 @@ static int setup(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias) int len; char *record_type; - if (strstr(info->system->name, "ipv6")) + if (ddns_get_tcp_force(info) == TCP_FORCE_IPV6) record_type="AAAA"; else record_type="A"; diff --git a/plugins/freedns.c b/plugins/freedns.c index 25d4386f..68520197 100644 --- a/plugins/freedns.c +++ b/plugins/freedns.c @@ -69,7 +69,7 @@ static char *fetch_keys(ddns_t *ctx, ddns_info_t *info) http_set_remote_name(&client, info->server_name.name); client.ssl_enabled = info->ssl_enabled; - rc = http_init(&client, "Fetching account API key",strstr(info->system->name, "ipv6") ? TCP_FORCE_IPV6 : TCP_FORCE_IPV4); + rc = http_init(&client, "Fetching account API key", ddns_get_tcp_force(info)); if (rc) return NULL; diff --git a/plugins/porkbun.c b/plugins/porkbun.c index f7c963df..81cf7efc 100644 --- a/plugins/porkbun.c +++ b/plugins/porkbun.c @@ -225,7 +225,7 @@ static int json_extract(char *dest, size_t dest_size, const ddns_info_t *info, c http_set_remote_name(&client, info->server_name.name); client.ssl_enabled = info->ssl_enabled; - CHECK(http_init(&client, "Json query",strstr(info->system->name, "ipv6") ? TCP_FORCE_IPV6 : TCP_FORCE_IPV4)); + CHECK(http_init(&client, "Json query", ddns_get_tcp_force(info))); trans.req = request; trans.req_len = request_len; diff --git a/src/ddns.c b/src/ddns.c index 6cc87ad0..bb1683d5 100644 --- a/src/ddns.c +++ b/src/ddns.c @@ -136,7 +136,7 @@ static int server_transaction(ddns_t *ctx, ddns_info_t *provider) client = &provider->checkip; client->ssl_enabled = provider->checkip_ssl; - DO(http_init(client, "Checking for IP# change", strstr(provider->system->name, "ipv6") ? TCP_FORCE_IPV6 : TCP_FORCE_IPV4)); + DO(http_init(client, "Checking for IP# change", ddns_get_tcp_force(provider))); /* Prepare request for IP server */ memset(ctx->work_buf, 0, ctx->work_buflen); @@ -618,7 +618,7 @@ static int send_update(ddns_t *ctx, ddns_info_t *info, ddns_alias_t *alias, int DO(info->system->setup(ctx, info, alias)); client->ssl_enabled = info->ssl_enabled; - rc = http_init(client, "Sending IP# update to DDNS server", strstr(info->system->name, "ipv6") ? TCP_FORCE_IPV6 : TCP_FORCE_IPV4); + rc = http_init(client, "Sending IP# update to DDNS server", ddns_get_tcp_force(info)); if (rc) { /* Update failed, force update again in ctx->cmd_check_period seconds */ alias->force_addr_update = 1; @@ -1064,6 +1064,14 @@ int ddns_main_loop(ddns_t *ctx) return rc; } +int ddns_get_tcp_force(const ddns_info_t *info) { + const char* name = info->system->name; + if (strstr(name, "ipv6") == name) { + return TCP_FORCE_IPV6; + } + return TCP_FORCE_IPV4; +} + /** * Local Variables: * indent-tabs-mode: t From 4ea7896514cbc3679a71a246708c354dafa4af54 Mon Sep 17 00:00:00 2001 From: hrzlgnm Date: Thu, 26 Sep 2024 21:26:12 +0200 Subject: [PATCH 2/2] Fix logging of cache updates for providers having "v6" in their name The original check, checked whether the alias name contained the substring "v6". This lead to confusing logging messages for providers having "v6" in their name. For example in definitions like "ipv4@ipv64.net" or "ipv4@dynv6.com". --- src/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cache.c b/src/cache.c index 0dbd7f0b..ec6dd00f 100644 --- a/src/cache.c +++ b/src/cache.c @@ -184,7 +184,7 @@ int write_cache_file(ddns_alias_t *alias, const char *name) cache_file(alias->name, name, path, sizeof(path)); fp = fopen(path, "w"); if (fp) { - if (strstr(name, "v6")) + if (strstr(name, "ipv6") == name) logit(LOG_NOTICE, "Updating IPv6 cache for %s", alias->name); else logit(LOG_NOTICE, "Updating IPv4 cache for %s", alias->name);