1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Introduce UnsetGateway(IPv6) methods

Sandbox needs unset gateway methods to cleanup
gateway settings to enable smooth transition
of the sandbox between endpoints.

Signed-off-by: Jana Radhakrishnan <mrjana@docker.com>
This commit is contained in:
Jana Radhakrishnan 2015-06-02 13:20:15 -07:00
parent c3d02744c6
commit 36303270c6
3 changed files with 64 additions and 4 deletions

View file

@ -30,7 +30,7 @@ func configureInterface(iface netlink.Link, settings *Interface) error {
return nil
}
func programGateway(path string, gw net.IP) error {
func programGateway(path string, gw net.IP, isAdd bool) error {
runtime.LockOSThread()
defer runtime.UnlockOSThread()
@ -57,7 +57,15 @@ func programGateway(path string, gw net.IP) error {
return fmt.Errorf("route for the gateway could not be found: %v", err)
}
return netlink.RouteAdd(&netlink.Route{
if isAdd {
return netlink.RouteAdd(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: gwRoutes[0].LinkIndex,
Gw: gw,
})
}
return netlink.RouteDel(&netlink.Route{
Scope: netlink.SCOPE_UNIVERSE,
LinkIndex: gwRoutes[0].LinkIndex,
Gw: gw,

View file

@ -308,26 +308,72 @@ func (n *networkNamespace) AddInterface(i *Interface) error {
}
func (n *networkNamespace) SetGateway(gw net.IP) error {
// Silently return if the gateway is empty
if len(gw) == 0 {
return nil
}
err := programGateway(n.path, gw)
err := programGateway(n.path, gw, true)
if err == nil {
n.Lock()
n.sinfo.Gateway = gw
n.Unlock()
}
return err
}
func (n *networkNamespace) UnsetGateway() error {
n.Lock()
gw := n.sinfo.Gateway
n.Unlock()
// Silently return if the gateway is empty
if len(gw) == 0 {
return nil
}
err := programGateway(n.path, gw, false)
if err == nil {
n.Lock()
n.sinfo.Gateway = net.IP{}
n.Unlock()
}
return err
}
func (n *networkNamespace) SetGatewayIPv6(gw net.IP) error {
// Silently return if the gateway is empty
if len(gw) == 0 {
return nil
}
err := programGateway(n.path, gw)
err := programGateway(n.path, gw, true)
if err == nil {
n.Lock()
n.sinfo.GatewayIPv6 = gw
n.Unlock()
}
return err
}
func (n *networkNamespace) UnsetGatewayIPv6() error {
n.Lock()
gw := n.sinfo.GatewayIPv6
n.Unlock()
// Silently return if the gateway is empty
if len(gw) == 0 {
return nil
}
err := programGateway(n.path, gw, false)
if err == nil {
n.Lock()
n.sinfo.GatewayIPv6 = net.IP{}
n.Unlock()
}
return err

View file

@ -35,6 +35,12 @@ type Sandbox interface {
// Set default IPv6 gateway for the sandbox
SetGatewayIPv6(gw net.IP) error
// Unset the previously set default IPv4 gateway in the sandbox
UnsetGateway() error
// Unset the previously set default IPv6 gateway in the sandbox
UnsetGatewayIPv6() error
// Add a static route to the sandbox.
AddStaticRoute(*types.StaticRoute) error