Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keep nse container net ns open until inject connection close is done #334

Merged
merged 2 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions pkg/kernel/networkservice/inject/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ func move(ctx context.Context, conn *networkservice.Connection, isClient, isMove
return nil
}

vfConfig, ok := vfconfig.Load(ctx, isClient)
if !ok {
return nil
}

hostNetNS, err := nshandle.Current()
if err != nil {
return err
Expand All @@ -86,15 +91,21 @@ func move(ctx context.Context, conn *networkservice.Connection, isClient, isMove
if err != nil {
return err
}
defer func() { _ = contNetNS.Close() }()
if !contNetNS.IsOpen() && isMoveBack {
contNetNS = vfConfig.ContNetNS
}

vfConfig, ok := vfconfig.Load(ctx, isClient)
if !ok {
return nil
// keep NSE container's net ns open until connection close is done,.
// this would properly move back VF into host net namespace even when
// container is accidentally deleted before close.
if !isClient || isMoveBack {
defer func() { _ = contNetNS.Close() }()
}

ifName := mech.GetInterfaceName()
if !isMoveBack {
err = moveToContNetNS(vfConfig, ifName, hostNetNS, contNetNS)
vfConfig.ContNetNS = contNetNS
} else {
err = moveToHostNetNS(vfConfig, ifName, hostNetNS, contNetNS)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/kernel/networkservice/vfconfig/metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ package vfconfig
import (
"context"

"github.com/vishvananda/netns"

"github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata"
)

Expand All @@ -37,6 +39,8 @@ type VFConfig struct {
VFPCIAddress string
// VFNum is a VF num for the parent PF
VFNum int
// ContNetNS is a container netns id on which VF is attached
ContNetNS netns.NsHandle
}

// Store sets the VFConfig stored in per Connection.Id metadata.
Expand Down