Skip to content
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
3 changes: 2 additions & 1 deletion src/dns_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ static void set_bootstrap_source_addr(ares_channel channel,
}
ares_set_local_ip6(channel, (const unsigned char *)&addr_v6);
} else {
WLOG("Bootstrap source address '%s' is not a valid IP literal", source_addr);
// otherwise treat it as a device/interface name
ares_set_local_dev(channel, source_addr);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? The ares docs say:

If SO_BINDTODEVICE is not supported or the setsocktop call fails (probably because of permissions), the error is silently ignored.

main.c daemon()izes before dns_poller_init which is the caller of this function dropping root will break this and running on a non-linux system will also not work but will no longer show a warning.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested it without daemonizing and dropping root, it works.

return;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dns_poller.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct {
// provided ev_loop. `bootstrap_dns` is a comma-separated list of DNS servers to
// use for the lookup `hostname` every `interval_seconds`. For each successful
// lookup, `cb` will be called with the resolved address.
// `source_addr` optionally binds bootstrap DNS lookups to a specific IP.
// `source_addr` optionally binds bootstrap DNS lookups to a specific IP/device.
// `family` should be AF_INET for IPv4 or AF_UNSPEC for both IPv4 and IPv6.
//
// Note: hostname *not* copied. It should remain valid until
Expand Down
2 changes: 1 addition & 1 deletion src/https_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ static void https_fetch_ctx_init(https_client_t *client,
ASSERT_CURL_EASY_SETOPT(ctx, CURLOPT_PROXY, client->opt->curl_proxy);
}
if (client->opt->source_addr) {
DLOG_REQ("Using source address: %s", client->opt->source_addr);
DLOG_REQ("Using source address or device: %s", client->opt->source_addr);
ASSERT_CURL_EASY_SETOPT(ctx, CURLOPT_INTERFACE, client->opt->source_addr);
}
if (client->opt->ca_info) {
Expand Down
2 changes: 1 addition & 1 deletion src/options.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ void options_show_usage(int __attribute__((unused)) argc, char **argv) {
printf(" supports it (http, https, socks4a, socks5h), otherwise\n");
printf(" initial DNS resolution will still be done via the\n");
printf(" bootstrap DNS servers.\n");
printf(" -S source_addr Source IPv4/v6 address for outbound HTTPS and bootstrap DNS.\n");
printf(" -S source_addr/dev Source IPv4/v6 address or device for outbound HTTPS and bootstrap DNS.\n");
printf(" (Default: system default)\n");
printf(" -x Use HTTP/1.1 instead of HTTP/2. Useful with broken\n"
" or limited builds of libcurl.\n");
Expand Down
2 changes: 1 addition & 1 deletion src/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Options {
// e.g. "socks5://127.0.0.1:1080"
const char *curl_proxy;

// Source address for outbound HTTPS connections
// Source address or device for outbound HTTPS connections and ares
const char *source_addr;

// 1 = Use only HTTP/1.1 for limited OpenWRT libcurl (which is not built with HTTP/2 support)
Expand Down