mirror of
https://github.com/clearlinux/libnetwork.git
synced 2026-09-07 14:22:05 +00: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:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user