Commit 67ecae0
authored
Add -S flag for configurable source address on outbound connections (#196)
Motivation:
-----------
Enable routing DNS-over-HTTPS traffic through different network paths per instance. Primary use case: running multiple `https_dns_proxy` instances on a router where each WiFi LAN gateway routes through a different WireGuard tunnel to different geographic locations. This allows DNS traffic from different WiFi networks to exit via different VPN endpoints.
Implementation:
---------------
- Added `source_addr` field to `struct Options`
- New `-S` command-line flag to specify source IPv4/v6 address
- Uses `CURLOPT_INTERFACE` to bind outbound HTTPS connections
- Backward compatible: without -S, uses system default routing
- Logs `Using source address: X` at `debug` level when configured
Example Usage:
--------------
### Instance 1: WiFi LAN 1 gateway (routes via WireGuard to US)
```shell
https_dns_proxy -a 192.168.1.1 -p 53 -S 192.168.1.1 \
-r https://security.cloudflare-dns.com/dns-query \
-b 1.1.1.2,1.0.0.2
```
### Instance 2: WiFi LAN 2 gateway (routes via WireGuard to EU)
```shell
https_dns_proxy -a 192.168.2.1 -p 53 -S 192.168.2.1 \
-r https://security.cloudflare-dns.com/dns-query \
-b 1.1.1.2,1.0.0.2
```
Each instance binds to its WiFi interface address for both listening and outbound HTTPS, ensuring traffic routes through the correct WireGuard tunnel configured for that interface.
Verification:
-------------
With `-S` flag, CURL binds to specified source address:
```
[D] https_client.c:260 F0C1: Requesting HTTP/2
[D] https_client.c:324 F0C1: Using source address: 192.168.1.1
[D] https_client.c:218 F0C1: * Added security.cloudflare-dns.com:443:1.0.0.2,1.1.1.2,... to DNS cache
[D] https_client.c:218 F0C1: * Hostname security.cloudflare-dns.com was found in DNS cache
[D] https_client.c:94 curl opened socket: 9
[D] https_client.c:218 F0C1: * Trying 1.0.0.2:443...
[D] https_client.c:218 F0C1: * Name '192.168.1.1' family 2 resolved to '192.168.1.1' family 2
[D] https_client.c:218 F0C1: * Local port: 0
[D] https_client.c:639 Reserved new io event: 0xffffc0ed3568
[D] https_client.c:218 F0C1: * Connected to security.cloudflare-dns.com (1.0.0.2) port 443 (#0)
```
Without `-S` flag, no source binding (backward compatible):
```
[D] https_client.c:260 39BF: Requesting HTTP/2
[D] https_client.c:218 39BF: * Added security.cloudflare-dns.com:443:1.1.1.2,1.0.0.2,... to DNS cache
[D] https_client.c:218 39BF: * Hostname security.cloudflare-dns.com was found in DNS cache
[D] https_client.c:94 curl opened socket: 9
[D] https_client.c:218 39BF: * Trying 1.1.1.2:443...
[D] https_client.c:639 Reserved new io event: 0xffffe69a0f18
[D] https_client.c:218 39BF: * Connected to security.cloudflare-dns.com (1.1.1.2) port 443 (#0)
```
Note the presence of `Using source address` and `Name '192.168.1.1' ... resolved` lines only when `-S` is specified.
Files Modified:
---------------
- `src/options.h`: Added source_addr field
- `src/options.c`: Added -S flag parsing and help text
- `src/https_client.c`: Implemented CURLOPT_INTERFACE binding
- `tests/robot/functional_tests.robot`: Added test case
- `README.md`: Updated documentation1 parent b499aa9 commit 67ecae0
File tree
5 files changed
+25
-3
lines changed- src
- tests/robot
5 files changed
+25
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
| 164 | + | |
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
323 | 327 | | |
324 | 328 | | |
325 | 329 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
58 | 59 | | |
59 | 60 | | |
60 | 61 | | |
61 | | - | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
123 | 124 | | |
124 | 125 | | |
125 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
126 | 130 | | |
127 | 131 | | |
128 | 132 | | |
| |||
222 | 226 | | |
223 | 227 | | |
224 | 228 | | |
225 | | - | |
| 229 | + | |
226 | 230 | | |
227 | 231 | | |
228 | 232 | | |
| |||
250 | 254 | | |
251 | 255 | | |
252 | 256 | | |
| 257 | + | |
| 258 | + | |
253 | 259 | | |
254 | 260 | | |
255 | 261 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
46 | 49 | | |
47 | 50 | | |
48 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
0 commit comments