mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #817 from aboch/pip
Add support for Endpoint's preferred IPv6 address
This commit is contained in:
commit
c8dcb0340d
1 changed files with 23 additions and 7 deletions
|
@ -61,6 +61,7 @@ type endpoint struct {
|
||||||
generic map[string]interface{}
|
generic map[string]interface{}
|
||||||
joinLeaveDone chan struct{}
|
joinLeaveDone chan struct{}
|
||||||
prefAddress net.IP
|
prefAddress net.IP
|
||||||
|
prefAddressV6 net.IP
|
||||||
ipamOptions map[string]string
|
ipamOptions map[string]string
|
||||||
dbIndex uint64
|
dbIndex uint64
|
||||||
dbExists bool
|
dbExists bool
|
||||||
|
@ -688,9 +689,10 @@ func EndpointOptionGeneric(generic map[string]interface{}) EndpointOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint
|
// CreateOptionIpam function returns an option setter for the ipam configuration for this endpoint
|
||||||
func CreateOptionIpam(prefAddress net.IP, ipamOptions map[string]string) EndpointOption {
|
func CreateOptionIpam(ipV4, ipV6 net.IP, ipamOptions map[string]string) EndpointOption {
|
||||||
return func(ep *endpoint) {
|
return func(ep *endpoint) {
|
||||||
ep.prefAddress = prefAddress
|
ep.prefAddress = ipV4
|
||||||
|
ep.prefAddressV6 = ipV6
|
||||||
ep.ipamOptions = ipamOptions
|
ep.ipamOptions = ipamOptions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -775,6 +777,8 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
|
||||||
var (
|
var (
|
||||||
poolID *string
|
poolID *string
|
||||||
address **net.IPNet
|
address **net.IPNet
|
||||||
|
prefAdd net.IP
|
||||||
|
progAdd net.IP
|
||||||
)
|
)
|
||||||
|
|
||||||
n := ep.getNetwork()
|
n := ep.getNetwork()
|
||||||
|
@ -782,9 +786,11 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
|
||||||
case 4:
|
case 4:
|
||||||
poolID = &ep.iface.v4PoolID
|
poolID = &ep.iface.v4PoolID
|
||||||
address = &ep.iface.addr
|
address = &ep.iface.addr
|
||||||
|
prefAdd = ep.prefAddress
|
||||||
case 6:
|
case 6:
|
||||||
poolID = &ep.iface.v6PoolID
|
poolID = &ep.iface.v6PoolID
|
||||||
address = &ep.iface.addrv6
|
address = &ep.iface.addrv6
|
||||||
|
prefAdd = ep.prefAddressV6
|
||||||
default:
|
default:
|
||||||
return types.InternalErrorf("incorrect ip version number passed: %d", ipVer)
|
return types.InternalErrorf("incorrect ip version number passed: %d", ipVer)
|
||||||
}
|
}
|
||||||
|
@ -796,12 +802,19 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The address to program may be chosen by the user or by the network driver in one specific
|
||||||
|
// case to support backward compatibility with `docker daemon --fixed-cidrv6` use case
|
||||||
|
if prefAdd != nil {
|
||||||
|
progAdd = prefAdd
|
||||||
|
} else if *address != nil {
|
||||||
|
progAdd = (*address).IP
|
||||||
|
}
|
||||||
|
|
||||||
for _, d := range ipInfo {
|
for _, d := range ipInfo {
|
||||||
var prefIP net.IP
|
if progAdd != nil && !d.Pool.Contains(progAdd) {
|
||||||
if *address != nil {
|
continue
|
||||||
prefIP = (*address).IP
|
|
||||||
}
|
}
|
||||||
addr, _, err := ipam.RequestAddress(d.PoolID, prefIP, ep.ipamOptions)
|
addr, _, err := ipam.RequestAddress(d.PoolID, progAdd, ep.ipamOptions)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ep.Lock()
|
ep.Lock()
|
||||||
*address = addr
|
*address = addr
|
||||||
|
@ -809,10 +822,13 @@ func (ep *endpoint) assignAddressVersion(ipVer int, ipam ipamapi.Ipam) error {
|
||||||
ep.Unlock()
|
ep.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if err != ipamapi.ErrNoAvailableIPs {
|
if err != ipamapi.ErrNoAvailableIPs || progAdd != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if progAdd != nil {
|
||||||
|
return types.BadRequestErrorf("Invalid preferred address %s: It does not belong to any of this network's subnets")
|
||||||
|
}
|
||||||
return fmt.Errorf("no available IPv%d addresses on this network's address pools: %s (%s)", ipVer, n.Name(), n.ID())
|
return fmt.Errorf("no available IPv%d addresses on this network's address pools: %s (%s)", ipVer, n.Name(), n.ID())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue