Skip to content

Commit

Permalink
Fix issue with detection whether to use ipv6 or ipv4
Browse files Browse the repository at this point in the history
Also factor out the duplicated check to own function while at it
Closes troglobit#497
  • Loading branch information
hrzlgnm committed Sep 25, 2024
1 parent da1d1af commit 87d3945
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions include/ddns.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion plugins/cloudflare.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion plugins/core-networks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
4 changes: 2 additions & 2 deletions plugins/dnspod.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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";
Expand Down
2 changes: 1 addition & 1 deletion plugins/freedns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion plugins/porkbun.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 10 additions & 2 deletions src/ddns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 87d3945

Please sign in to comment.