mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add ability to alias any interface in a sanbox
New load balancing code will require ability to add aliases to load-balncer sandboxes. So this broadens the OSL interface to allow adding aliases to any interface, along with the facility to get the loopback interface's name based on the OS. Signed-off-by: Chris Telfer <ctelfer@docker.com>
This commit is contained in:
parent
f2c6009583
commit
78b684a24a
3 changed files with 19 additions and 10 deletions
|
@ -358,16 +358,20 @@ func (n *networkNamespace) loopbackUp() error {
|
|||
return n.nlHandle.LinkSetUp(iface)
|
||||
}
|
||||
|
||||
func (n *networkNamespace) AddLoopbackAliasIP(ip *net.IPNet) error {
|
||||
iface, err := n.nlHandle.LinkByName("lo")
|
||||
func (n *networkNamespace) GetLoopbackIfaceName() string {
|
||||
return "lo"
|
||||
}
|
||||
|
||||
func (n *networkNamespace) AddAliasIP(ifName string, ip *net.IPNet) error {
|
||||
iface, err := n.nlHandle.LinkByName(ifName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return n.nlHandle.AddrAdd(iface, &netlink.Addr{IPNet: ip})
|
||||
}
|
||||
|
||||
func (n *networkNamespace) RemoveLoopbackAliasIP(ip *net.IPNet) error {
|
||||
iface, err := n.nlHandle.LinkByName("lo")
|
||||
func (n *networkNamespace) RemoveAliasIP(ifName string, ip *net.IPNet) error {
|
||||
iface, err := n.nlHandle.LinkByName(ifName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -32,11 +32,14 @@ type Sandbox interface {
|
|||
// Unset the previously set default IPv6 gateway in the sandbox
|
||||
UnsetGatewayIPv6() error
|
||||
|
||||
// AddLoopbackAliasIP adds the passed IP address to the sandbox loopback interface
|
||||
AddLoopbackAliasIP(ip *net.IPNet) error
|
||||
// GetLoopbackIfaceName returns the name of the loopback interface
|
||||
GetLoopbackIfaceName() string
|
||||
|
||||
// RemoveLoopbackAliasIP removes the passed IP address from the sandbox loopback interface
|
||||
RemoveLoopbackAliasIP(ip *net.IPNet) error
|
||||
// AddAliasIP adds the passed IP address to the named interface
|
||||
AddAliasIP(ifName string, ip *net.IPNet) error
|
||||
|
||||
// RemoveAliasIP removes the passed IP address from the named interface
|
||||
RemoveAliasIP(ifName string, ip *net.IPNet) error
|
||||
|
||||
// Add a static route to the sandbox.
|
||||
AddStaticRoute(*types.StaticRoute) error
|
||||
|
|
|
@ -744,7 +744,8 @@ func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) {
|
|||
ep.Unlock()
|
||||
|
||||
if len(vip) != 0 {
|
||||
if err := osSbox.RemoveLoopbackAliasIP(&net.IPNet{IP: vip, Mask: net.CIDRMask(32, 32)}); err != nil {
|
||||
loopName := osSbox.GetLoopbackIfaceName()
|
||||
if err := osSbox.RemoveAliasIP(loopName, &net.IPNet{IP: vip, Mask: net.CIDRMask(32, 32)}); err != nil {
|
||||
logrus.Warnf("Remove virtual IP %v failed: %v", vip, err)
|
||||
}
|
||||
}
|
||||
|
@ -862,7 +863,8 @@ func (sb *sandbox) populateNetworkResources(ep *endpoint) error {
|
|||
}
|
||||
|
||||
if len(ep.virtualIP) != 0 {
|
||||
err := sb.osSbox.AddLoopbackAliasIP(&net.IPNet{IP: ep.virtualIP, Mask: net.CIDRMask(32, 32)})
|
||||
loopName := sb.osSbox.GetLoopbackIfaceName()
|
||||
err := sb.osSbox.AddAliasIP(loopName, &net.IPNet{IP: ep.virtualIP, Mask: net.CIDRMask(32, 32)})
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to add virtual IP %v: %v", ep.virtualIP, err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue