Skip to content

Commit

Permalink
Merge pull request networkservicemesh#334 from Nordix/store-netns-id
Browse files Browse the repository at this point in the history
keep nse container net ns open until inject connection close is done
  • Loading branch information
edwarnicke authored Sep 9, 2021
2 parents 7818952 + f981f52 commit aec84d8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
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

0 comments on commit aec84d8

Please sign in to comment.