mirror of
https://github.com/containers/podman.git
synced 2025-08-05 19:02:37 +08:00
libpod: Re-work the container's network state to help code sharing
This replaces the NetworkJail string field with a struct pointer named NetNS. This does not try to emulate the complete NetNS interface but does help to re-use code that just refers to c.state.NetNS. [NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
This commit is contained in:
@ -26,8 +26,8 @@ var (
|
||||
|
||||
// Network stubs to decouple container_internal_freebsd.go from
|
||||
// networking_freebsd.go so they can be reviewed separately.
|
||||
func (r *Runtime) createNetNS(ctr *Container) (netJail string, q map[string]types.StatusBlock, retErr error) {
|
||||
return "", nil, errors.New("not implemented (*Runtime) createNetNS")
|
||||
func (r *Runtime) createNetNS(ctr *Container) (netJail *jailNetNS, q map[string]types.StatusBlock, retErr error) {
|
||||
return nil, nil, errors.New("not implemented (*Runtime) createNetNS")
|
||||
}
|
||||
|
||||
func (r *Runtime) teardownNetNS(ctr *Container) error {
|
||||
@ -51,7 +51,7 @@ func (c *Container) unmountSHM(path string) error {
|
||||
func (c *Container) prepare() error {
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
jailName string
|
||||
ctrNS *jailNetNS
|
||||
networkStatus map[string]types.StatusBlock
|
||||
createNetNSErr, mountStorageErr error
|
||||
mountPoint string
|
||||
@ -63,9 +63,9 @@ func (c *Container) prepare() error {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
// Set up network namespace if not already set up
|
||||
noNetNS := c.state.NetworkJail == ""
|
||||
noNetNS := c.state.NetNS == nil
|
||||
if c.config.CreateNetNS && noNetNS && !c.config.PostConfigureNetNS {
|
||||
jailName, networkStatus, createNetNSErr = c.runtime.createNetNS(c)
|
||||
ctrNS, networkStatus, createNetNSErr = c.runtime.createNetNS(c)
|
||||
if createNetNSErr != nil {
|
||||
return
|
||||
}
|
||||
@ -74,7 +74,7 @@ func (c *Container) prepare() error {
|
||||
defer tmpStateLock.Unlock()
|
||||
|
||||
// Assign NetNS attributes to container
|
||||
c.state.NetworkJail = jailName
|
||||
c.state.NetNS = ctrNS
|
||||
c.state.NetworkStatus = networkStatus
|
||||
}
|
||||
}()
|
||||
@ -164,7 +164,7 @@ func (c *Container) addNetworkContainer(g *generate.Generator, ctr string) error
|
||||
if err != nil {
|
||||
return fmt.Errorf("retrieving dependency %s of container %s from state: %w", ctr, c.ID(), err)
|
||||
}
|
||||
g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetworkJail)
|
||||
g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetNS.Name)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -187,7 +187,7 @@ func openDirectory(path string) (fd int, err error) {
|
||||
|
||||
func (c *Container) addNetworkNamespace(g *generate.Generator) error {
|
||||
if c.config.CreateNetNS {
|
||||
g.AddAnnotation("org.freebsd.parentJail", c.state.NetworkJail)
|
||||
g.AddAnnotation("org.freebsd.parentJail", c.state.NetNS.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -272,7 +272,7 @@ func (c *Container) isSlirp4netnsIPv6() (bool, error) {
|
||||
|
||||
// check for net=none
|
||||
func (c *Container) hasNetNone() bool {
|
||||
return c.state.NetworkJail == ""
|
||||
return c.state.NetNS == nil
|
||||
}
|
||||
|
||||
func setVolumeAtime(mountPoint string, st os.FileInfo) error {
|
||||
|
Reference in New Issue
Block a user