Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue with detection whether to use ipv6 or ipv4 #498

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion src/cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
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
Loading