← 输入框|github.com|刷新
Skip to content

Make getaddrinfo() address family configurable at build time - #644

Open
Yildirim-Tolga wants to merge 1 commit into
tinyproxy:masterfrom
Yildirim-Tolga:feature/configurable-address-family
Open

Yildirim-Tolga wants to merge 1 commit into
tinyproxy:masterfrom
Yildirim-Tolga:feature/configurable-address-family

Conversation

@Yildirim-Tolga

Copy link
Copy Markdown

Make getaddrinfo() address family configurable at build time

Summary

Tinyproxy currently uses AF_UNSPEC when calling getaddrinfo() for upstream destination resolution.

This change adds an optional build-time configuration allowing users to explicitly select:

  • AF_UNSPEC (default)
  • AF_INET
  • AF_INET6

The default behavior remains unchanged.

Motivation

While using AF_UNSPEC is generally appropriate, some deployments require deterministic address-family selection.

Examples include:

  • IPv4-only environments where IPv6 is unavailable, filtered, or partially deployed.
  • IPv6-only environments with strict networking requirements.
  • Embedded systems where only one protocol family is supported.
  • Troubleshooting scenarios where administrators want to eliminate protocol-family related variables.
  • Environments with security or compliance requirements mandating IPv4-only or IPv6-only operation.

Currently these deployments cannot enforce a specific address family without modifying the source code.

Implementation

A new configure-time option has been added to allow selecting the address family used by getaddrinfo().

Examples:

./configure --with-address-family=unspec
./configure --with-address-family=inet
./configure --with-address-family=inet6

If the option is not specified, Tinyproxy continues to use:

AF_UNSPEC

ensuring full backward compatibility.


Backward Compatibility

  • Existing behavior remains the default.
  • No runtime behavior changes occur unless the new option is explicitly enabled.
  • Existing configurations continue to work without modification.

Testing

Tested with:

Default configuration (AF_UNSPEC)
IPv4-only configuration (AF_INET)
IPv6-only configuration (AF_INET6)

and verified successful upstream hostname resolution in each mode.

Rationale

This feature is entirely optional and does not modify the default Tinyproxy behavior. It only provides additional deployment flexibility for environments requiring IPv4-only or IPv6-only operation.

Tinyproxy currently uses AF_UNSPEC when resolving upstream
destinations through getaddrinfo().
Some deployments require deterministic IPv4-only or IPv6-only
operation due to network policy, protocol availability,
troubleshooting, or embedded system constraints.
This change introduces an optional configure-time setting that
allows AF_INET or AF_INET6 to be selected while preserving the
existing AF_UNSPEC behavior as the default.
@rofl0r

rofl0r commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

i actually have this very line patched in my own checkout to prefer IPv4 always. but this should be a runtime option, not compile-time.

@Yildirim-Tolga

Copy link
Copy Markdown
Author

i actually have this very line patched in my own checkout to prefer IPv4 always. but this should be a runtime option, not compile-time.

Thanks for the feedback.

Just to make sure I understand correctly: would you prefer this to be implemented as a tinyproxy.conf option rather than a configure-time option?

I'd be happy to rework the patch in that direction if that would be more useful.

@rofl0r

rofl0r commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

would you prefer this to be implemented as a tinyproxy.conf option rather than a configure-time option?

right, we just have to bikeshed about how to call it, and whether/how we allow a fallback to the other AF if the selected one has no results.

@Yildirim-Tolga

Copy link
Copy Markdown
Author

would you prefer this to be implemented as a tinyproxy.conf option rather than a configure-time option?

right, we just have to bikeshed about how to call it, and whether/how we allow a fallback to the other AF if the selected one has no results.

AddressFamily sounds straightforward to me:

AddressFamily unspec # default
AddressFamily ipv4
AddressFamily ipv6

I'd suggest keeping ipv4 and ipv6 strict, without fallback. unspec already provides the existing system-selected behavior and would remain the default, so existing configurations would behave exactly as they do today.

If an address family is explicitly configured, I think Tinyproxy should respect that choice rather than silently falling back to the other family.

@rofl0r

rofl0r commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

AddressFamily isn't specific enough, it could mean anything. let's call it "ConnectAddressFamily", with allowed values of "ipv4", "ipv6", "unspec" (default). like ConnectPort, it can be used more than once (which would establish a prefered order), or just once in which case it disallows non-matching address families.

ConnectAddressFamily ipv4
ConnectAddressFamily ipv6

would use AF_UNSPEC for the getaddrinfo call, and then iterate twice (if needed, i.e. no AF_INET entries exist) over the returned list.

more than two values make no sense, so the conf parser would warn if it's used more often. we can use an int[2] for the configured address families, plus a counter for how many are configured. if it's 0, the loop uses AF_UNSPEC, if one the AF in connect_afs[0], if two AF_UNSPEC with the selection lined out in the above example.

sounds good?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants