mirror of
https://github.com/caddyserver/caddy.git
synced 2025-12-08 06:09:53 +00:00
to_device
This commit is contained in:
parent
4435af28d3
commit
b3b711b2bc
3 changed files with 86 additions and 83 deletions
|
|
@ -321,8 +321,8 @@ func (st *ServerType) listenersForServerBlockAddress(sblock serverBlock, addr Ad
|
||||||
} else {
|
} else {
|
||||||
lnCfgVals = []bindOptions{{
|
lnCfgVals = []bindOptions{{
|
||||||
addresses: []string{""},
|
addresses: []string{""},
|
||||||
interfaces: nil,
|
|
||||||
protocols: nil,
|
protocols: nil,
|
||||||
|
to_device: false,
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -332,9 +332,9 @@ func (st *ServerType) listenersForServerBlockAddress(sblock serverBlock, addr Ad
|
||||||
interfaces := map[string][]net.Addr{}
|
interfaces := map[string][]net.Addr{}
|
||||||
for _, lnCfgVal := range lnCfgVals {
|
for _, lnCfgVal := range lnCfgVals {
|
||||||
lnAddresses := make([]string, 0, len(lnCfgVal.addresses))
|
lnAddresses := make([]string, 0, len(lnCfgVal.addresses))
|
||||||
lnAddresses = append(lnAddresses, lnCfgVal.addresses...)
|
for _, lnAddress := range lnCfgVal.addresses {
|
||||||
for _, lnIface := range lnCfgVal.interfaces {
|
if lnCfgVal.to_device {
|
||||||
lnNetw, lnDevice, _, err := caddy.SplitNetworkAddress(lnIface)
|
lnNetw, lnDevice, _, err := caddy.SplitNetworkAddress(lnAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("splitting listener interface: %v", err)
|
return nil, fmt.Errorf("splitting listener interface: %v", err)
|
||||||
}
|
}
|
||||||
|
|
@ -403,6 +403,9 @@ func (st *ServerType) listenersForServerBlockAddress(sblock serverBlock, addr Ad
|
||||||
for _, lnIfaceAddress := range lnIfaceAddresses {
|
for _, lnIfaceAddress := range lnIfaceAddresses {
|
||||||
lnAddresses = append(lnAddresses, caddy.JoinNetworkAddress(lnNetw, lnIfaceAddress, ""))
|
lnAddresses = append(lnAddresses, caddy.JoinNetworkAddress(lnNetw, lnIfaceAddress, ""))
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
lnAddresses = append(lnAddresses, lnAddress)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for _, lnAddr := range lnAddresses {
|
for _, lnAddr := range lnAddresses {
|
||||||
lnNetw, lnHost, _, err := caddy.SplitNetworkAddress(lnAddr)
|
lnNetw, lnHost, _, err := caddy.SplitNetworkAddress(lnAddr)
|
||||||
|
|
@ -427,8 +430,8 @@ func (st *ServerType) listenersForServerBlockAddress(sblock serverBlock, addr Ad
|
||||||
|
|
||||||
type bindOptions struct {
|
type bindOptions struct {
|
||||||
addresses []string
|
addresses []string
|
||||||
interfaces []string
|
|
||||||
protocols []string
|
protocols []string
|
||||||
|
to_device bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Address represents a site address. It contains
|
// Address represents a site address. It contains
|
||||||
|
|
|
||||||
|
|
@ -63,21 +63,21 @@ func init() {
|
||||||
// }]
|
// }]
|
||||||
func parseBind(h Helper) ([]ConfigValue, error) {
|
func parseBind(h Helper) ([]ConfigValue, error) {
|
||||||
h.Next() // consume directive name
|
h.Next() // consume directive name
|
||||||
var addresses, interfaces, protocols []string
|
var (
|
||||||
|
addresses, protocols []string
|
||||||
|
to_device bool
|
||||||
|
)
|
||||||
addresses = h.RemainingArgs()
|
addresses = h.RemainingArgs()
|
||||||
|
|
||||||
for h.NextBlock(0) {
|
for h.NextBlock(0) {
|
||||||
switch h.Val() {
|
switch h.Val() {
|
||||||
case "interfaces":
|
|
||||||
interfaces = h.RemainingArgs()
|
|
||||||
if len(interfaces) == 0 {
|
|
||||||
return nil, h.Errf("interfaces requires one or more arguments")
|
|
||||||
}
|
|
||||||
case "protocols":
|
case "protocols":
|
||||||
protocols = h.RemainingArgs()
|
protocols = h.RemainingArgs()
|
||||||
if len(protocols) == 0 {
|
if len(protocols) == 0 {
|
||||||
return nil, h.Errf("protocols requires one or more arguments")
|
return nil, h.Errf("protocols requires one or more arguments")
|
||||||
}
|
}
|
||||||
|
case "to_device":
|
||||||
|
to_device = true
|
||||||
default:
|
default:
|
||||||
return nil, h.Errf("unknown subdirective: %s", h.Val())
|
return nil, h.Errf("unknown subdirective: %s", h.Val())
|
||||||
}
|
}
|
||||||
|
|
@ -85,8 +85,8 @@ func parseBind(h Helper) ([]ConfigValue, error) {
|
||||||
|
|
||||||
return []ConfigValue{{Class: "bind", Value: bindOptions{
|
return []ConfigValue{{Class: "bind", Value: bindOptions{
|
||||||
addresses: addresses,
|
addresses: addresses,
|
||||||
interfaces: interfaces,
|
|
||||||
protocols: protocols,
|
protocols: protocols,
|
||||||
|
to_device: to_device,
|
||||||
}}}, nil
|
}}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -307,7 +307,10 @@ func parseOptSingleString(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||||
|
|
||||||
func parseOptDefaultBind(d *caddyfile.Dispenser, _ any) (any, error) {
|
func parseOptDefaultBind(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||||
d.Next() // consume option name
|
d.Next() // consume option name
|
||||||
var addresses, interfaces, protocols []string
|
var (
|
||||||
|
addresses, protocols []string
|
||||||
|
to_device bool
|
||||||
|
)
|
||||||
addresses = d.RemainingArgs()
|
addresses = d.RemainingArgs()
|
||||||
|
|
||||||
if len(addresses) == 0 {
|
if len(addresses) == 0 {
|
||||||
|
|
@ -316,16 +319,13 @@ func parseOptDefaultBind(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||||
|
|
||||||
for d.NextBlock(0) {
|
for d.NextBlock(0) {
|
||||||
switch d.Val() {
|
switch d.Val() {
|
||||||
case "interfaces":
|
|
||||||
interfaces = d.RemainingArgs()
|
|
||||||
if len(interfaces) == 0 {
|
|
||||||
return nil, d.Errf("interfaces requires one or more arguments")
|
|
||||||
}
|
|
||||||
case "protocols":
|
case "protocols":
|
||||||
protocols = d.RemainingArgs()
|
protocols = d.RemainingArgs()
|
||||||
if len(protocols) == 0 {
|
if len(protocols) == 0 {
|
||||||
return nil, d.Errf("protocols requires one or more arguments")
|
return nil, d.Errf("protocols requires one or more arguments")
|
||||||
}
|
}
|
||||||
|
case "to_device":
|
||||||
|
to_device = true
|
||||||
default:
|
default:
|
||||||
return nil, d.Errf("unknown subdirective: %s", d.Val())
|
return nil, d.Errf("unknown subdirective: %s", d.Val())
|
||||||
}
|
}
|
||||||
|
|
@ -333,8 +333,8 @@ func parseOptDefaultBind(d *caddyfile.Dispenser, _ any) (any, error) {
|
||||||
|
|
||||||
return []ConfigValue{{Class: "bind", Value: bindOptions{
|
return []ConfigValue{{Class: "bind", Value: bindOptions{
|
||||||
addresses: addresses,
|
addresses: addresses,
|
||||||
interfaces: interfaces,
|
|
||||||
protocols: protocols,
|
protocols: protocols,
|
||||||
|
to_device: to_device,
|
||||||
}}}, nil
|
}}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue