mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Add service virtual IP to sandbox's loopback address
Refreshed the PR: https://github.com/docker/libnetwork/pull/1585 Addressed comments suggesting to remove the IPAlias logic not anymore used Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
parent
1662fc9709
commit
3c1ebfaef9
5 changed files with 36 additions and 39 deletions
|
@ -26,7 +26,6 @@ type nwIface struct {
|
||||||
mac net.HardwareAddr
|
mac net.HardwareAddr
|
||||||
address *net.IPNet
|
address *net.IPNet
|
||||||
addressIPv6 *net.IPNet
|
addressIPv6 *net.IPNet
|
||||||
ipAliases []*net.IPNet
|
|
||||||
llAddrs []*net.IPNet
|
llAddrs []*net.IPNet
|
||||||
routes []*net.IPNet
|
routes []*net.IPNet
|
||||||
bridge bool
|
bridge bool
|
||||||
|
@ -97,13 +96,6 @@ func (i *nwIface) LinkLocalAddresses() []*net.IPNet {
|
||||||
return i.llAddrs
|
return i.llAddrs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *nwIface) IPAliases() []*net.IPNet {
|
|
||||||
i.Lock()
|
|
||||||
defer i.Unlock()
|
|
||||||
|
|
||||||
return i.ipAliases
|
|
||||||
}
|
|
||||||
|
|
||||||
func (i *nwIface) Routes() []*net.IPNet {
|
func (i *nwIface) Routes() []*net.IPNet {
|
||||||
i.Lock()
|
i.Lock()
|
||||||
defer i.Unlock()
|
defer i.Unlock()
|
||||||
|
@ -337,7 +329,6 @@ func configureInterface(nlh *netlink.Handle, iface netlink.Link, i *nwIface) err
|
||||||
{setInterfaceIPv6, fmt.Sprintf("error setting interface %q IPv6 to %v", ifaceName, i.AddressIPv6())},
|
{setInterfaceIPv6, fmt.Sprintf("error setting interface %q IPv6 to %v", ifaceName, i.AddressIPv6())},
|
||||||
{setInterfaceMaster, fmt.Sprintf("error setting interface %q master to %q", ifaceName, i.DstMaster())},
|
{setInterfaceMaster, fmt.Sprintf("error setting interface %q master to %q", ifaceName, i.DstMaster())},
|
||||||
{setInterfaceLinkLocalIPs, fmt.Sprintf("error setting interface %q link local IPs to %v", ifaceName, i.LinkLocalAddresses())},
|
{setInterfaceLinkLocalIPs, fmt.Sprintf("error setting interface %q link local IPs to %v", ifaceName, i.LinkLocalAddresses())},
|
||||||
{setInterfaceIPAliases, fmt.Sprintf("error setting interface %q IP Aliases to %v", ifaceName, i.IPAliases())},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, config := range ifaceConfigurators {
|
for _, config := range ifaceConfigurators {
|
||||||
|
@ -399,16 +390,6 @@ func setInterfaceLinkLocalIPs(nlh *netlink.Handle, iface netlink.Link, i *nwIfac
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func setInterfaceIPAliases(nlh *netlink.Handle, iface netlink.Link, i *nwIface) error {
|
|
||||||
for _, si := range i.IPAliases() {
|
|
||||||
ipAddr := &netlink.Addr{IPNet: si}
|
|
||||||
if err := nlh.AddrAdd(iface, ipAddr); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func setInterfaceName(nlh *netlink.Handle, iface netlink.Link, i *nwIface) error {
|
func setInterfaceName(nlh *netlink.Handle, iface netlink.Link, i *nwIface) error {
|
||||||
return nlh.LinkSetName(iface, i.DstName())
|
return nlh.LinkSetName(iface, i.DstName())
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,6 +356,22 @@ func (n *networkNamespace) loopbackUp() error {
|
||||||
return n.nlHandle.LinkSetUp(iface)
|
return n.nlHandle.LinkSetUp(iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (n *networkNamespace) AddLoopbackAliasIP(ip *net.IPNet) error {
|
||||||
|
iface, err := n.nlHandle.LinkByName("lo")
|
||||||
|
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")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return n.nlHandle.AddrDel(iface, &netlink.Addr{IPNet: ip})
|
||||||
|
}
|
||||||
|
|
||||||
func (n *networkNamespace) InvokeFunc(f func()) error {
|
func (n *networkNamespace) InvokeFunc(f func()) error {
|
||||||
return nsInvoke(n.nsPath(), func(nsFD int) error { return nil }, func(callerFD int) error {
|
return nsInvoke(n.nsPath(), func(nsFD int) error { return nil }, func(callerFD int) error {
|
||||||
f()
|
f()
|
||||||
|
|
|
@ -66,12 +66,6 @@ func (n *networkNamespace) LinkLocalAddresses(list []*net.IPNet) IfaceOption {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *networkNamespace) IPAliases(list []*net.IPNet) IfaceOption {
|
|
||||||
return func(i *nwIface) {
|
|
||||||
i.ipAliases = list
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n *networkNamespace) Routes(routes []*net.IPNet) IfaceOption {
|
func (n *networkNamespace) Routes(routes []*net.IPNet) IfaceOption {
|
||||||
return func(i *nwIface) {
|
return func(i *nwIface) {
|
||||||
i.routes = routes
|
i.routes = routes
|
||||||
|
|
|
@ -32,6 +32,12 @@ type Sandbox interface {
|
||||||
// Unset the previously set default IPv6 gateway in the sandbox
|
// Unset the previously set default IPv6 gateway in the sandbox
|
||||||
UnsetGatewayIPv6() error
|
UnsetGatewayIPv6() error
|
||||||
|
|
||||||
|
// AddLoopbackAliasIP adds the passed IP address to the sandbox loopback interface
|
||||||
|
AddLoopbackAliasIP(ip *net.IPNet) error
|
||||||
|
|
||||||
|
// RemoveLoopbackAliasIP removes the passed IP address from the sandbox loopback interface
|
||||||
|
RemoveLoopbackAliasIP(ip *net.IPNet) error
|
||||||
|
|
||||||
// Add a static route to the sandbox.
|
// Add a static route to the sandbox.
|
||||||
AddStaticRoute(*types.StaticRoute) error
|
AddStaticRoute(*types.StaticRoute) error
|
||||||
|
|
||||||
|
@ -91,9 +97,6 @@ type IfaceOptionSetter interface {
|
||||||
// LinkLocalAddresses returns an option setter to set the link-local IP addresses.
|
// LinkLocalAddresses returns an option setter to set the link-local IP addresses.
|
||||||
LinkLocalAddresses([]*net.IPNet) IfaceOption
|
LinkLocalAddresses([]*net.IPNet) IfaceOption
|
||||||
|
|
||||||
// IPAliases returns an option setter to set IP address Aliases
|
|
||||||
IPAliases([]*net.IPNet) IfaceOption
|
|
||||||
|
|
||||||
// Master returns an option setter to set the master interface if any for this
|
// Master returns an option setter to set the master interface if any for this
|
||||||
// interface. The master interface name should refer to the srcname of a
|
// interface. The master interface name should refer to the srcname of a
|
||||||
// previously added interface of type bridge.
|
// previously added interface of type bridge.
|
||||||
|
@ -150,9 +153,6 @@ type Interface interface {
|
||||||
// LinkLocalAddresses returns the link-local IP addresses assigned to the interface.
|
// LinkLocalAddresses returns the link-local IP addresses assigned to the interface.
|
||||||
LinkLocalAddresses() []*net.IPNet
|
LinkLocalAddresses() []*net.IPNet
|
||||||
|
|
||||||
// IPAliases returns the IP address aliases assigned to the interface.
|
|
||||||
IPAliases() []*net.IPNet
|
|
||||||
|
|
||||||
// IP routes for the interface.
|
// IP routes for the interface.
|
||||||
Routes() []*net.IPNet
|
Routes() []*net.IPNet
|
||||||
|
|
||||||
|
|
|
@ -709,8 +709,15 @@ func releaseOSSboxResources(osSbox osl.Sandbox, ep *endpoint) {
|
||||||
|
|
||||||
ep.Lock()
|
ep.Lock()
|
||||||
joinInfo := ep.joinInfo
|
joinInfo := ep.joinInfo
|
||||||
|
vip := ep.virtualIP
|
||||||
ep.Unlock()
|
ep.Unlock()
|
||||||
|
|
||||||
|
if len(vip) != 0 {
|
||||||
|
if err := osSbox.RemoveLoopbackAliasIP(&net.IPNet{IP: vip, Mask: net.CIDRMask(32, 32)}); err != nil {
|
||||||
|
logrus.Warnf("Remove virtual IP %v failed: %v", vip, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if joinInfo == nil {
|
if joinInfo == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -767,10 +774,6 @@ func (sb *sandbox) restoreOslSandbox() error {
|
||||||
if len(i.llAddrs) != 0 {
|
if len(i.llAddrs) != 0 {
|
||||||
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().LinkLocalAddresses(i.llAddrs))
|
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().LinkLocalAddresses(i.llAddrs))
|
||||||
}
|
}
|
||||||
if len(ep.virtualIP) != 0 {
|
|
||||||
vipAlias := &net.IPNet{IP: ep.virtualIP, Mask: net.CIDRMask(32, 32)}
|
|
||||||
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().IPAliases([]*net.IPNet{vipAlias}))
|
|
||||||
}
|
|
||||||
Ifaces[fmt.Sprintf("%s+%s", i.srcName, i.dstPrefix)] = ifaceOptions
|
Ifaces[fmt.Sprintf("%s+%s", i.srcName, i.dstPrefix)] = ifaceOptions
|
||||||
if joinInfo != nil {
|
if joinInfo != nil {
|
||||||
routes = append(routes, joinInfo.StaticRoutes...)
|
routes = append(routes, joinInfo.StaticRoutes...)
|
||||||
|
@ -818,10 +821,6 @@ func (sb *sandbox) populateNetworkResources(ep *endpoint) error {
|
||||||
if len(i.llAddrs) != 0 {
|
if len(i.llAddrs) != 0 {
|
||||||
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().LinkLocalAddresses(i.llAddrs))
|
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().LinkLocalAddresses(i.llAddrs))
|
||||||
}
|
}
|
||||||
if len(ep.virtualIP) != 0 {
|
|
||||||
vipAlias := &net.IPNet{IP: ep.virtualIP, Mask: net.CIDRMask(32, 32)}
|
|
||||||
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().IPAliases([]*net.IPNet{vipAlias}))
|
|
||||||
}
|
|
||||||
if i.mac != nil {
|
if i.mac != nil {
|
||||||
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().MacAddress(i.mac))
|
ifaceOptions = append(ifaceOptions, sb.osSbox.InterfaceOptions().MacAddress(i.mac))
|
||||||
}
|
}
|
||||||
|
@ -831,6 +830,13 @@ 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)})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to add virtual IP %v: %v", ep.virtualIP, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if joinInfo != nil {
|
if joinInfo != nil {
|
||||||
// Set up non-interface routes.
|
// Set up non-interface routes.
|
||||||
for _, r := range joinInfo.StaticRoutes {
|
for _, r := range joinInfo.StaticRoutes {
|
||||||
|
|
Loading…
Reference in a new issue