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
33 changes: 32 additions & 1 deletion caddyconfig/httpcaddyfile/addresses.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,38 @@ func (st *ServerType) listenersForServerBlockAddress(sblock serverBlock, addr Ad
if err != nil {
return nil, fmt.Errorf("parsing network address: %v", err)
}
if _, ok := listeners[addr.String()]; !ok {

// Check if this is an interface with multi-address modes - expand to multiple IPs
if networkAddr.IsInterfaceNetwork() && strings.Contains(networkAddr.Host, caddy.InterfaceDelimiter) {
parts := strings.SplitN(networkAddr.Host, caddy.InterfaceDelimiter, 2)
if len(parts) == 2 {
mode := caddy.InterfaceBindingMode(parts[1])
// Check if this mode returns multiple addresses
if mode == caddy.InterfaceBindingAll || mode == caddy.InterfaceBindingIPv4 || mode == caddy.InterfaceBindingIPv6 {
// Resolve IPs for the interface with the specified mode
ipAddresses, err := caddy.ResolveInterfaceNameWithMode(parts[0], mode)
if err != nil {
return nil, fmt.Errorf("resolving interface %s with mode '%s': %v", parts[0], mode, err)
}

// Create a listener for each IP
for _, ip := range ipAddresses {
ipNA := networkAddr
ipNA.Host = ip
if _, ok := listeners[ipNA.String()]; !ok {
listeners[ipNA.String()] = map[string]struct{}{}
}
for _, protocol := range lnCfgVal.protocols {
listeners[ipNA.String()][protocol] = struct{}{}
}
}
continue
}
}
}

// Normal case - single address
if _, ok := listeners[networkAddr.String()]; !ok {
listeners[networkAddr.String()] = map[string]struct{}{}
}
for _, protocol := range lnCfgVal.protocols {
Expand Down
3 changes: 3 additions & 0 deletions caddyconfig/httpcaddyfile/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ func init() {
// bind <addresses...> [{
// protocols [h1|h2|h2c|h3] [...]
// }]
//
// Addresses can be network addresses (host:port) or network interface names (e.g., eth0:80).
// Interface names will be resolved to their IP addresses at bind time.
func parseBind(h Helper) ([]ConfigValue, error) {
h.Next() // consume directive name
var addresses, protocols []string
Expand Down
Loading
Loading