mirror of
				https://github.com/containers/podman.git
				synced 2025-11-04 08:56:05 +08:00 
			
		
		
		
	use etchosts package from c/common
Use the new logic from c/common to create the hosts file. This will help to better allign the hosts files between buildah and podman. Also this fixes several bugs: - remove host entries when container is stopped and has a netNsCtr - add entries for containers in a pod - do not duplicate entries in the hosts file - use the correct slirp ip when an userns is used Features: - configure host.containers.internal entry in containers.conf - configure base hosts file in containers.conf Fixes #12003 Fixes #13224 Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
		
							
								
								
									
										30
									
								
								vendor/github.com/containers/common/libnetwork/etchosts/util.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										30
									
								
								vendor/github.com/containers/common/libnetwork/etchosts/util.go
									
									
									
										generated
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,30 @@
 | 
			
		||||
package etchosts
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"fmt"
 | 
			
		||||
 | 
			
		||||
	"github.com/containers/common/pkg/config"
 | 
			
		||||
	securejoin "github.com/cyphar/filepath-securejoin"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// GetBaseHostFile return the hosts file which should be used as base.
 | 
			
		||||
// The first param should be the config value config.Containers.BaseHostsFile
 | 
			
		||||
// The second param should be the root path to the mounted image. This is
 | 
			
		||||
// required when the user conf value is set to "image".
 | 
			
		||||
func GetBaseHostFile(confValue, imageRoot string) (string, error) {
 | 
			
		||||
	switch confValue {
 | 
			
		||||
	case "":
 | 
			
		||||
		return config.DefaultHostsFile, nil
 | 
			
		||||
	case "none":
 | 
			
		||||
		return "", nil
 | 
			
		||||
	case "image":
 | 
			
		||||
		// use secure join to prevent problems with symlinks
 | 
			
		||||
		path, err := securejoin.SecureJoin(imageRoot, config.DefaultHostsFile)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return "", fmt.Errorf("failed to get /etc/hosts path in image: %w", err)
 | 
			
		||||
		}
 | 
			
		||||
		return path, nil
 | 
			
		||||
	default:
 | 
			
		||||
		return confValue, nil
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user