libnetwork: fix sandbox restore
The method to restore a network namespace takes a collection of interfaces to restore with the options to apply. The interface names are structured data, tuples of (SrcName, DstPrefix) but for whatever reason are being passed into Restore() serialized to strings. A refactor,f0be4d126d
, accidentally broke the serialization by dropping the delimiter. Rather than fix the serialization and leave the time-bomb for someone else to trip over, pass the interface names as structured data. Signed-off-by: Cory Snider <csnider@mirantis.com> (cherry picked from commit50eb2d2782
) Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
parent
fec801a103
commit
3452a76589
3 changed files with 12 additions and 14 deletions
|
@ -470,16 +470,10 @@ func (n *networkNamespace) Destroy() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore restore the network namespace
|
// Restore restore the network namespace
|
||||||
func (n *networkNamespace) Restore(ifsopt map[string][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error {
|
func (n *networkNamespace) Restore(ifsopt map[Iface][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error {
|
||||||
// restore interfaces
|
// restore interfaces
|
||||||
for name, opts := range ifsopt {
|
for name, opts := range ifsopt {
|
||||||
if !strings.Contains(name, "+") {
|
i := &nwIface{srcName: name.SrcName, dstName: name.DstPrefix, ns: n}
|
||||||
return fmt.Errorf("wrong iface name in restore osl sandbox interface: %s", name)
|
|
||||||
}
|
|
||||||
seps := strings.Split(name, "+")
|
|
||||||
srcName := seps[0]
|
|
||||||
dstPrefix := seps[1]
|
|
||||||
i := &nwIface{srcName: srcName, dstName: dstPrefix, ns: n}
|
|
||||||
i.processInterfaceOptions(opts...)
|
i.processInterfaceOptions(opts...)
|
||||||
if i.master != "" {
|
if i.master != "" {
|
||||||
i.dstMaster = n.findDst(i.master, true)
|
i.dstMaster = n.findDst(i.master, true)
|
||||||
|
@ -531,7 +525,7 @@ func (n *networkNamespace) Restore(ifsopt map[string][]IfaceOption, routes []*ty
|
||||||
}
|
}
|
||||||
|
|
||||||
var index int
|
var index int
|
||||||
indexStr := strings.TrimPrefix(i.dstName, dstPrefix)
|
indexStr := strings.TrimPrefix(i.dstName, name.DstPrefix)
|
||||||
if indexStr != "" {
|
if indexStr != "" {
|
||||||
index, err = strconv.Atoi(indexStr)
|
index, err = strconv.Atoi(indexStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -540,8 +534,8 @@ func (n *networkNamespace) Restore(ifsopt map[string][]IfaceOption, routes []*ty
|
||||||
}
|
}
|
||||||
index++
|
index++
|
||||||
n.Lock()
|
n.Lock()
|
||||||
if index > n.nextIfIndex[dstPrefix] {
|
if index > n.nextIfIndex[name.DstPrefix] {
|
||||||
n.nextIfIndex[dstPrefix] = index
|
n.nextIfIndex[name.DstPrefix] = index
|
||||||
}
|
}
|
||||||
n.iFaces = append(n.iFaces, i)
|
n.iFaces = append(n.iFaces, i)
|
||||||
n.Unlock()
|
n.Unlock()
|
||||||
|
|
|
@ -17,6 +17,10 @@ const (
|
||||||
SandboxTypeLoadBalancer = iota
|
SandboxTypeLoadBalancer = iota
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type Iface struct {
|
||||||
|
SrcName, DstPrefix string
|
||||||
|
}
|
||||||
|
|
||||||
// IfaceOption is a function option type to set interface options.
|
// IfaceOption is a function option type to set interface options.
|
||||||
type IfaceOption func(i *nwIface)
|
type IfaceOption func(i *nwIface)
|
||||||
|
|
||||||
|
@ -89,7 +93,7 @@ type Sandbox interface {
|
||||||
Destroy() error
|
Destroy() error
|
||||||
|
|
||||||
// Restore restores the sandbox.
|
// Restore restores the sandbox.
|
||||||
Restore(ifsopt map[string][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error
|
Restore(ifsopt map[Iface][]IfaceOption, routes []*types.StaticRoute, gw net.IP, gw6 net.IP) error
|
||||||
|
|
||||||
// ApplyOSTweaks applies operating system specific knobs on the sandbox.
|
// ApplyOSTweaks applies operating system specific knobs on the sandbox.
|
||||||
ApplyOSTweaks([]SandboxType)
|
ApplyOSTweaks([]SandboxType)
|
||||||
|
|
|
@ -765,7 +765,7 @@ func (sb *Sandbox) restoreOslSandbox() error {
|
||||||
var routes []*types.StaticRoute
|
var routes []*types.StaticRoute
|
||||||
|
|
||||||
// restore osl sandbox
|
// restore osl sandbox
|
||||||
Ifaces := make(map[string][]osl.IfaceOption)
|
Ifaces := make(map[osl.Iface][]osl.IfaceOption)
|
||||||
for _, ep := range sb.endpoints {
|
for _, ep := range sb.endpoints {
|
||||||
ep.mu.Lock()
|
ep.mu.Lock()
|
||||||
joinInfo := ep.joinInfo
|
joinInfo := ep.joinInfo
|
||||||
|
@ -790,7 +790,7 @@ 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))
|
||||||
}
|
}
|
||||||
Ifaces[i.srcName+i.dstPrefix] = ifaceOptions
|
Ifaces[osl.Iface{SrcName: i.srcName, DstPrefix: i.dstPrefix}] = ifaceOptions
|
||||||
if joinInfo != nil {
|
if joinInfo != nil {
|
||||||
routes = append(routes, joinInfo.StaticRoutes...)
|
routes = append(routes, joinInfo.StaticRoutes...)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue