-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
listeners: Add network interface binding support, with IP version modes #7256
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
base: master
Are you sure you want to change the base?
listeners: Add network interface binding support, with IP version modes #7256
Conversation
More interface names to test:
|
listeners.go
Outdated
// Check if contains only supported placeholders | ||
if strings.Contains(s, "{env.") || strings.Contains(s, "{file.") { | ||
// Check for unsupported placeholders | ||
if strings.Contains(s, "{http.") || strings.Contains(s, "{vars.") || | ||
strings.Contains(s, "{system.") || strings.Contains(s, "{time.") || | ||
strings.Contains(s, "{upstream}") { | ||
return "", false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need all this, NewReplacer()
implicitly has that protection for you anyway since it only has those placeholders registered
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added explicit checks for system.*
and time.*
placeholders since they are still processed by ReplaceKnown()
and could produce invalid interface names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like having any kind of limitations here, it means if we later add more global placeholders we'd have to remember to consider this code to allow it. Don't need to hand-hold users, if they use placeholders that don't make sense, that's on them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Removed explicit placeholder restrictions and now trust the replacer system - any globally registered placeholder will work.
…t unsupported placeholders
Im interested in this, thats why Im asking some questions. Why does it bind to only a single IP address per interface (the first), and not all of the available ones on an interface? Especially for IPv6 there could be a link local address, one or multiple GUAs (with and without privacy extension) and possibly even ULAs. IPv4 can also have virtual IPs on the same interface. Also what happens if IP addresses change during runtime, e.g. DHCPv4 and v6 leases on ISP provided WAN interfaces (and by extension SLAAC prefix changes), does Caddy notice that the runtime environment changed and reload with the updated addresses? Or will it crash, or stop to serve until manually restarted? |
…w any globally registered placeholder
Implements GitHub issue #6856 - adds support for binding Caddy listeners to network interfaces by name instead of requiring specific IP addresses.
Features
bind "eth0:8080:ipv4"
,bind "eth0:8080:ipv6"
, orbind "eth0:8080:auto"
Usage Examples
Basic Interface Binding
With Specific Ports and IP Version Modes
Key Functions
isInterfaceName()
: Validates interface names and handlesinterface:port:mode
patternsselectIPByMode()
: Chooses appropriate IP address based on binding moderesolveInterfaceNameWithMode()
: Resolves interface names to IP addressesparseInterfaceAddress()
: Parses and validates interface binding syntaxTesting
Assistance Disclosure
I consulted Claude to understand the project architecture, but I authored/coded the fix myself