mirror of https://github.com/containers/podman.git
use libnetwork from c/common
The libpod/network packages were moved to c/common so that buildah can use it as well. To prevent duplication use it in podman as well and remove it from here. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
parent
2cdab5d539
commit
495884b319
|
@ -7,11 +7,11 @@ import (
|
|||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/image/v5/pkg/sysregistriesv2"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
systemdDefine "github.com/containers/podman/v3/pkg/systemd/define"
|
||||
|
|
|
@ -8,11 +8,11 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/cgroups"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/api/handlers"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
|
|
|
@ -3,10 +3,10 @@ package common
|
|||
import (
|
||||
"net"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
"github.com/containers/podman/v3/pkg/specgenutil"
|
||||
|
|
|
@ -7,13 +7,13 @@ import (
|
|||
"time"
|
||||
|
||||
tm "github.com/buger/goterm"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/utils"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/pkg/errors"
|
||||
|
|
|
@ -3,10 +3,10 @@ package network
|
|||
import (
|
||||
"net"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
|
|
@ -4,12 +4,12 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/libnetwork/util"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/parse"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/network/util"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
|
|
@ -6,12 +6,12 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/completion"
|
||||
"github.com/containers/common/pkg/report"
|
||||
"github.com/containers/podman/v3/cmd/podman/common"
|
||||
"github.com/containers/podman/v3/cmd/podman/registry"
|
||||
"github.com/containers/podman/v3/cmd/podman/validate"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/pkg/rootlessport"
|
||||
"github.com/pkg/errors"
|
||||
rkport "github.com/rootless-containers/rootlesskit/pkg/port"
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/lock"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/opencontainers/runtime-tools/generate"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
|
@ -10,13 +10,13 @@ import (
|
|||
"time"
|
||||
|
||||
types040 "github.com/containernetworking/cni/pkg/types/040"
|
||||
"github.com/containers/common/libnetwork/cni"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/common/pkg/secrets"
|
||||
"github.com/containers/image/v5/manifest"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/lock"
|
||||
"github.com/containers/podman/v3/libpod/network/cni"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/storage"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/secrets"
|
||||
"github.com/containers/image/v5/manifest"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/namespaces"
|
||||
"github.com/containers/storage"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
|
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/containers/buildah/pkg/chrootuser"
|
||||
"github.com/containers/buildah/pkg/overlay"
|
||||
butil "github.com/containers/buildah/util"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/apparmor"
|
||||
"github.com/containers/common/pkg/cgroups"
|
||||
"github.com/containers/common/pkg/chown"
|
||||
|
@ -35,7 +36,6 @@ import (
|
|||
"github.com/containers/common/pkg/umask"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/events"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/annotations"
|
||||
"github.com/containers/podman/v3/pkg/checkpoint/crutils"
|
||||
"github.com/containers/podman/v3/pkg/criu"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"io"
|
||||
"regexp"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -17,9 +17,9 @@ var (
|
|||
// NameRegex is a regular expression to validate container/pod names.
|
||||
// This must NOT be changed from outside of Libpod. It should be a
|
||||
// constant, but Go won't let us do that.
|
||||
NameRegex = regexp.MustCompile("^[a-zA-Z0-9][a-zA-Z0-9_.-]*$")
|
||||
NameRegex = types.NameRegex
|
||||
// RegexError is thrown in presence of an invalid container/pod name.
|
||||
RegexError = errors.Wrapf(ErrInvalidArg, "names must match [a-zA-Z0-9][a-zA-Z0-9_.-]*")
|
||||
RegexError = types.RegexError
|
||||
// UmaskRegex is a regular expression to validate Umask.
|
||||
UmaskRegex = regexp.MustCompile(`^[0-7]{1,4}$`)
|
||||
)
|
||||
|
|
|
@ -3,6 +3,8 @@ package define
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -16,7 +18,7 @@ var (
|
|||
ErrNoSuchVolume = errors.New("no such volume")
|
||||
|
||||
// ErrNoSuchNetwork indicates the requested network does not exist
|
||||
ErrNoSuchNetwork = errors.New("network not found")
|
||||
ErrNoSuchNetwork = types.ErrNoSuchNetwork
|
||||
|
||||
// ErrNoSuchExecSession indicates that the requested exec session does
|
||||
// not exist.
|
||||
|
@ -48,7 +50,7 @@ var (
|
|||
ErrExecSessionExists = errors.New("exec session already exists")
|
||||
// ErrNetworkExists indicates that a network with the given name already
|
||||
// exists.
|
||||
ErrNetworkExists = errors.New("network already exists")
|
||||
ErrNetworkExists = types.ErrNetworkExists
|
||||
|
||||
// ErrCtrStateInvalid indicates a container is in an improper state for
|
||||
// the requested operation
|
||||
|
@ -73,7 +75,7 @@ var (
|
|||
ErrVolumeFinalized = errors.New("volume has been finalized")
|
||||
|
||||
// ErrInvalidArg indicates that an invalid argument was passed
|
||||
ErrInvalidArg = errors.New("invalid argument")
|
||||
ErrInvalidArg = types.ErrInvalidArg
|
||||
// ErrEmptyID indicates that an empty ID was passed
|
||||
ErrEmptyID = errors.New("name or ID cannot be empty")
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/env"
|
||||
"github.com/containers/podman/v3/pkg/lookup"
|
||||
"github.com/containers/podman/v3/pkg/namespaces"
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
// +build linux
|
||||
|
||||
package cni_test
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/cni"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/test/utils"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
var cniPluginDirs = []string{
|
||||
"/usr/libexec/cni",
|
||||
"/usr/lib/cni",
|
||||
"/usr/local/lib/cni",
|
||||
"/opt/cni/bin",
|
||||
}
|
||||
|
||||
func TestCni(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "CNI Suite")
|
||||
}
|
||||
|
||||
func getNetworkInterface(cniConfDir string, machine bool) (types.ContainerNetwork, error) {
|
||||
return cni.NewCNINetworkInterface(cni.InitConfig{
|
||||
CNIConfigDir: cniConfDir,
|
||||
CNIPluginDirs: cniPluginDirs,
|
||||
IsMachine: machine,
|
||||
LockFile: filepath.Join(cniConfDir, "cni.lock"),
|
||||
})
|
||||
}
|
||||
|
||||
func SkipIfNoDnsname() {
|
||||
for _, path := range cniPluginDirs {
|
||||
f, err := os.Stat(filepath.Join(path, "dnsname"))
|
||||
if err == nil && f.Mode().IsRegular() {
|
||||
return
|
||||
}
|
||||
}
|
||||
Skip("dnsname cni plugin needs to be installed for this test")
|
||||
}
|
||||
|
||||
func SkipIfNotFedora(msg string) {
|
||||
info := utils.GetHostDistributionInfo()
|
||||
if info.Distribution != "fedora" {
|
||||
Skip("Test can only run on Fedora: " + msg)
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,25 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "bridge",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman9",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1"
|
||||
}
|
||||
]
|
||||
]
|
|
@ -1,51 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "invalidgw",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman8",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8",
|
||||
"rangeStart": "10.89.8.20",
|
||||
"rangeEnd": "10.89.8.50"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "bridge@123",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman9",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman9",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "bridge",
|
||||
"plugins": []
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "bridge",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman9",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "bridge",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman9",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "podman",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman0",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [{ "dst": "0.0.0.0/0" }],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.88.0.0/16",
|
||||
"gateway": "10.88.0.1"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall"
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,51 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "bridge",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman9",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1",
|
||||
"rangeStart": "10.89.8.20",
|
||||
"rangeEnd": "10.89.8.50"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "dualstack",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman21",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "::/0"
|
||||
},
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "fd10:88:a::/64",
|
||||
"gateway": "fd10:88:a::1"
|
||||
}
|
||||
],
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.19.0/24",
|
||||
"gateway": "10.89.19.10"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "internal",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman8",
|
||||
"isGateway": false,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.7.0/24"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
{
|
||||
"args": {
|
||||
"podman_labels": {
|
||||
"mykey": "value"
|
||||
}
|
||||
},
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "label",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman15",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.13.0/24",
|
||||
"gateway": "10.89.13.1"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "macvlan",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "macvlan",
|
||||
"master": "lo",
|
||||
"ipam": {
|
||||
"type": "dhcp"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "macvlan_mtu",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "macvlan",
|
||||
"master": "lo",
|
||||
"ipam": {
|
||||
"type": "dhcp"
|
||||
},
|
||||
"mtu": 1300
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "mtu",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman13",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"mtu": 1500,
|
||||
"hairpinMode": true,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.11.0/24"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
{
|
||||
"cniVersion": "0.4.0",
|
||||
"name": "vlan",
|
||||
"plugins": [
|
||||
{
|
||||
"type": "bridge",
|
||||
"bridge": "cni-podman14",
|
||||
"isGateway": true,
|
||||
"ipMasq": true,
|
||||
"hairpinMode": true,
|
||||
"vlan": 5,
|
||||
"ipam": {
|
||||
"type": "host-local",
|
||||
"routes": [
|
||||
{
|
||||
"dst": "0.0.0.0/0"
|
||||
}
|
||||
],
|
||||
"ranges": [
|
||||
[
|
||||
{
|
||||
"subnet": "10.89.12.0/24",
|
||||
"gateway": "10.89.12.1"
|
||||
}
|
||||
]
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "portmap",
|
||||
"capabilities": {
|
||||
"portMappings": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "firewall",
|
||||
"backend": ""
|
||||
},
|
||||
{
|
||||
"type": "tuning"
|
||||
},
|
||||
{
|
||||
"type": "dnsname",
|
||||
"domainName": "dns.podman",
|
||||
"capabilities": {
|
||||
"aliases": true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,63 +0,0 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func parseCIDR(n string) *net.IPNet {
|
||||
_, parsedNet, _ := net.ParseCIDR(n)
|
||||
return parsedNet
|
||||
}
|
||||
|
||||
func TestNextSubnet(t *testing.T) {
|
||||
type args struct {
|
||||
subnet *net.IPNet
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *net.IPNet
|
||||
wantErr bool
|
||||
}{
|
||||
{"class b", args{subnet: parseCIDR("192.168.0.0/16")}, parseCIDR("192.169.0.0/16"), false},
|
||||
{"class c", args{subnet: parseCIDR("192.168.1.0/24")}, parseCIDR("192.168.2.0/24"), false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
test := tt
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := NextSubnet(test.args.subnet)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("NextSubnet() error = %v, wantErr %v", err, test.wantErr)
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(got, test.want) {
|
||||
t.Errorf("NextSubnet() got = %v, want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetRandomIPv6Subnet(t *testing.T) {
|
||||
for i := 0; i < 1000; i++ {
|
||||
t.Run(fmt.Sprintf("GetRandomIPv6Subnet %d", i), func(t *testing.T) {
|
||||
sub, err := getRandomIPv6Subnet()
|
||||
if err != nil {
|
||||
t.Errorf("GetRandomIPv6Subnet() error should be nil: %v", err)
|
||||
return
|
||||
}
|
||||
if sub.IP.To4() != nil {
|
||||
t.Errorf("ip %s is not an ipv6 address", sub.IP)
|
||||
}
|
||||
if sub.IP[0] != 0xfd {
|
||||
t.Errorf("ipv6 %s does not start with fd", sub.IP)
|
||||
}
|
||||
ones, bytes := sub.Mask.Size()
|
||||
if ones != 64 || bytes != 128 {
|
||||
t.Errorf("wrong network mask %v, it should be /64", sub.Mask)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,433 +0,0 @@
|
|||
package netavark
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
var _ = Describe("IPAM", func() {
|
||||
var (
|
||||
networkInterface *netavarkNetwork
|
||||
networkConfDir string
|
||||
logBuffer bytes.Buffer
|
||||
)
|
||||
|
||||
BeforeEach(func() {
|
||||
var err error
|
||||
networkConfDir, err = ioutil.TempDir("", "podman_netavark_test")
|
||||
if err != nil {
|
||||
Fail("Failed to create tmpdir")
|
||||
|
||||
}
|
||||
logBuffer = bytes.Buffer{}
|
||||
logrus.SetOutput(&logBuffer)
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
libpodNet, err := NewNetworkInterface(InitConfig{
|
||||
NetworkConfigDir: networkConfDir,
|
||||
IPAMDBPath: filepath.Join(networkConfDir, "ipam.db"),
|
||||
LockFile: filepath.Join(networkConfDir, "netavark.lock"),
|
||||
})
|
||||
if err != nil {
|
||||
Fail("Failed to create NewCNINetworkInterface")
|
||||
}
|
||||
|
||||
networkInterface = libpodNet.(*netavarkNetwork)
|
||||
// run network list to force a network load
|
||||
networkInterface.NetworkList()
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
os.RemoveAll(networkConfDir)
|
||||
})
|
||||
|
||||
It("simple ipam alloc", func() {
|
||||
netName := types.DefaultNetworkName
|
||||
for i := 2; i < 100; i++ {
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: "someContainerID",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
|
||||
err := networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP(fmt.Sprintf("10.88.0.%d", i)).To4()))
|
||||
}
|
||||
})
|
||||
|
||||
It("ipam try to alloc same ip", func() {
|
||||
netName := types.DefaultNetworkName
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: "someContainerID",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
|
||||
err := networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP("10.88.0.2").To4()))
|
||||
|
||||
opts = &types.NetworkOptions{
|
||||
ContainerID: "otherID",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {StaticIPs: []net.IP{net.ParseIP("10.88.0.2")}},
|
||||
},
|
||||
}
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("IPAM error: requested ip address 10.88.0.2 is already allocated to container ID someContainerID"))
|
||||
})
|
||||
|
||||
It("ipam try to alloc more ips as in range", func() {
|
||||
s, _ := types.ParseCIDR("10.0.0.1/24")
|
||||
network, err := networkInterface.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{
|
||||
Subnet: s,
|
||||
LeaseRange: &types.LeaseRange{
|
||||
StartIP: net.ParseIP("10.0.0.10"),
|
||||
EndIP: net.ParseIP("10.0.0.20"),
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName := network.Name
|
||||
|
||||
for i := 10; i < 21; i++ {
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: fmt.Sprintf("someContainerID-%d", i),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP(fmt.Sprintf("10.0.0.%d", i)).To4()))
|
||||
}
|
||||
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: "someContainerID-22",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
|
||||
// now this should fail because all free ips are already assigned
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("IPAM error: failed to find free IP in range: 10.0.0.10 - 10.0.0.20"))
|
||||
})
|
||||
|
||||
It("ipam basic setup", func() {
|
||||
netName := types.DefaultNetworkName
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: "someContainerID",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
|
||||
expectedIP := net.ParseIP("10.88.0.2").To4()
|
||||
|
||||
err := networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(expectedIP))
|
||||
|
||||
// remove static ips from opts
|
||||
netOpts := opts.Networks[netName]
|
||||
netOpts.StaticIPs = nil
|
||||
opts.Networks[netName] = netOpts
|
||||
|
||||
err = networkInterface.getAssignedIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(expectedIP))
|
||||
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("IPAM error: requested ip address 10.88.0.2 is already allocated to container ID someContainerID"))
|
||||
|
||||
// dealloc the ip
|
||||
err = networkInterface.deallocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(expectedIP))
|
||||
})
|
||||
|
||||
It("ipam dual stack", func() {
|
||||
s1, _ := types.ParseCIDR("10.0.0.0/26")
|
||||
s2, _ := types.ParseCIDR("fd80::/24")
|
||||
network, err := networkInterface.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{
|
||||
Subnet: s1,
|
||||
},
|
||||
{
|
||||
Subnet: s2,
|
||||
},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName := network.Name
|
||||
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: "someContainerID",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(2))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP("10.0.0.2").To4()))
|
||||
Expect(opts.Networks[netName].StaticIPs[1]).To(Equal(net.ParseIP("fd80::2")))
|
||||
|
||||
// remove static ips from opts
|
||||
netOpts := opts.Networks[netName]
|
||||
netOpts.StaticIPs = nil
|
||||
opts.Networks[netName] = netOpts
|
||||
|
||||
err = networkInterface.getAssignedIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(2))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP("10.0.0.2").To4()))
|
||||
Expect(opts.Networks[netName].StaticIPs[1]).To(Equal(net.ParseIP("fd80::2")))
|
||||
|
||||
err = networkInterface.deallocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// try to alloc the same again
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(2))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP("10.0.0.2").To4()))
|
||||
Expect(opts.Networks[netName].StaticIPs[1]).To(Equal(net.ParseIP("fd80::2")))
|
||||
})
|
||||
|
||||
It("ipam with two networks", func() {
|
||||
s, _ := types.ParseCIDR("10.0.0.0/24")
|
||||
network, err := networkInterface.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{
|
||||
Subnet: s,
|
||||
},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName1 := network.Name
|
||||
|
||||
s, _ = types.ParseCIDR("10.0.1.0/24")
|
||||
network, err = networkInterface.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{
|
||||
Subnet: s,
|
||||
},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName2 := network.Name
|
||||
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: "someContainerID",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName1: {},
|
||||
netName2: {},
|
||||
},
|
||||
}
|
||||
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName1))
|
||||
Expect(opts.Networks[netName1].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName1].StaticIPs[0]).To(Equal(net.ParseIP("10.0.0.2").To4()))
|
||||
Expect(opts.Networks).To(HaveKey(netName2))
|
||||
Expect(opts.Networks[netName2].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName2].StaticIPs[0]).To(Equal(net.ParseIP("10.0.1.2").To4()))
|
||||
|
||||
// remove static ips from opts
|
||||
netOpts := opts.Networks[netName1]
|
||||
netOpts.StaticIPs = nil
|
||||
opts.Networks[netName1] = netOpts
|
||||
netOpts = opts.Networks[netName2]
|
||||
netOpts.StaticIPs = nil
|
||||
opts.Networks[netName2] = netOpts
|
||||
|
||||
err = networkInterface.getAssignedIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName1))
|
||||
Expect(opts.Networks[netName1].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName1].StaticIPs[0]).To(Equal(net.ParseIP("10.0.0.2").To4()))
|
||||
Expect(opts.Networks).To(HaveKey(netName2))
|
||||
Expect(opts.Networks[netName2].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName2].StaticIPs[0]).To(Equal(net.ParseIP("10.0.1.2").To4()))
|
||||
|
||||
err = networkInterface.deallocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// try to alloc the same again
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName1))
|
||||
Expect(opts.Networks[netName1].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName1].StaticIPs[0]).To(Equal(net.ParseIP("10.0.0.2").To4()))
|
||||
Expect(opts.Networks).To(HaveKey(netName2))
|
||||
Expect(opts.Networks[netName2].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName2].StaticIPs[0]).To(Equal(net.ParseIP("10.0.1.2").To4()))
|
||||
})
|
||||
|
||||
It("ipam alloc more ips as in subnet", func() {
|
||||
s, _ := types.ParseCIDR("10.0.0.0/26")
|
||||
network, err := networkInterface.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{
|
||||
Subnet: s,
|
||||
},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName := network.Name
|
||||
|
||||
for i := 2; i < 64; i++ {
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: fmt.Sprintf("id-%d", i),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
err = networkInterface.allocIPs(opts)
|
||||
if i < 63 {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP(fmt.Sprintf("10.0.0.%d", i)).To4()))
|
||||
} else {
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("IPAM error: failed to find free IP in range: 10.0.0.1 - 10.0.0.62"))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
It("ipam alloc -> dealloc -> alloc", func() {
|
||||
s, _ := types.ParseCIDR("10.0.0.0/27")
|
||||
network, err := networkInterface.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{
|
||||
Subnet: s,
|
||||
},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName := network.Name
|
||||
|
||||
for i := 2; i < 10; i++ {
|
||||
opts := types.NetworkOptions{
|
||||
ContainerID: fmt.Sprintf("id-%d", i),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
err = networkInterface.allocIPs(&opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP(fmt.Sprintf("10.0.0.%d", i)).To4()))
|
||||
|
||||
err = networkInterface.deallocIPs(&opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
}
|
||||
|
||||
for i := 0; i < 30; i++ {
|
||||
opts := types.NetworkOptions{
|
||||
ContainerID: fmt.Sprintf("id-%d", i),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
err = networkInterface.allocIPs(&opts)
|
||||
if i < 29 {
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(1))
|
||||
// The (i+8)%29+2 part looks cryptic but it is actually simple, we already have 8 ips allocated above
|
||||
// so we expect the 8 available ip. We have 29 assignable ip addresses in this subnet because "i"+8 can
|
||||
// be greater than 30 we have to modulo by 29 to go back to the beginning. Also the first free ip is
|
||||
// network address + 2, so we have to add 2 to the result
|
||||
Expect(opts.Networks[netName].StaticIPs[0]).To(Equal(net.ParseIP(fmt.Sprintf("10.0.0.%d", (i+8)%29+2)).To4()))
|
||||
} else {
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(Equal("IPAM error: failed to find free IP in range: 10.0.0.1 - 10.0.0.30"))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
It("ipam with dhcp driver should not set ips", func() {
|
||||
network, err := networkInterface.NetworkCreate(types.Network{
|
||||
IPAMOptions: map[string]string{
|
||||
"driver": types.DHCPIPAMDriver,
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName := network.Name
|
||||
|
||||
opts := &types.NetworkOptions{
|
||||
ContainerID: "someContainerID",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {},
|
||||
},
|
||||
}
|
||||
|
||||
err = networkInterface.allocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(0))
|
||||
|
||||
err = networkInterface.getAssignedIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(opts.Networks).To(HaveKey(netName))
|
||||
Expect(opts.Networks[netName].StaticIPs).To(HaveLen(0))
|
||||
|
||||
// dealloc the ip
|
||||
err = networkInterface.deallocIPs(opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
|
||||
})
|
|
@ -1,75 +0,0 @@
|
|||
// +build linux
|
||||
|
||||
package netavark_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/netavark"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/network/util"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
gomegaTypes "github.com/onsi/gomega/types"
|
||||
)
|
||||
|
||||
func TestNetavark(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Netavark Suite")
|
||||
}
|
||||
|
||||
var netavarkBinary string
|
||||
|
||||
func init() {
|
||||
netavarkBinary = os.Getenv("NETAVARK_BINARY")
|
||||
if netavarkBinary == "" {
|
||||
netavarkBinary = "/usr/libexec/podman/netavark"
|
||||
}
|
||||
}
|
||||
|
||||
func getNetworkInterface(confDir string, machine bool) (types.ContainerNetwork, error) {
|
||||
return netavark.NewNetworkInterface(netavark.InitConfig{
|
||||
NetworkConfigDir: confDir,
|
||||
IsMachine: machine,
|
||||
NetavarkBinary: netavarkBinary,
|
||||
IPAMDBPath: filepath.Join(confDir, "ipam.db"),
|
||||
LockFile: filepath.Join(confDir, "netavark.lock"),
|
||||
})
|
||||
}
|
||||
|
||||
// EqualSubnet is a custom GomegaMatcher to match a subnet
|
||||
// This makes sure to not use the 16 bytes ip representation.
|
||||
func EqualSubnet(subnet *net.IPNet) gomegaTypes.GomegaMatcher {
|
||||
return &equalSubnetMatcher{
|
||||
expected: subnet,
|
||||
}
|
||||
}
|
||||
|
||||
type equalSubnetMatcher struct {
|
||||
expected *net.IPNet
|
||||
}
|
||||
|
||||
func (m *equalSubnetMatcher) Match(actual interface{}) (bool, error) {
|
||||
util.NormalizeIP(&m.expected.IP)
|
||||
|
||||
subnet, ok := actual.(*net.IPNet)
|
||||
if !ok {
|
||||
return false, fmt.Errorf("EqualSubnet expects a *net.IPNet")
|
||||
}
|
||||
util.NormalizeIP(&subnet.IP)
|
||||
|
||||
return reflect.DeepEqual(subnet, m.expected), nil
|
||||
}
|
||||
|
||||
func (m *equalSubnetMatcher) FailureMessage(actual interface{}) string {
|
||||
return fmt.Sprintf("Expected subnet %#v to equal subnet %#v", actual, m.expected)
|
||||
}
|
||||
|
||||
func (m *equalSubnetMatcher) NegatedFailureMessage(actual interface{}) string {
|
||||
return fmt.Sprintf("Expected subnet %#v not to equal subnet %#v", actual, m.expected)
|
||||
}
|
|
@ -1,699 +0,0 @@
|
|||
// +build linux
|
||||
|
||||
package netavark_test
|
||||
|
||||
// The tests have to be run as root.
|
||||
// For each test there will be two network namespaces created,
|
||||
// netNSTest and netNSContainer. Each test must be run inside
|
||||
// netNSTest to prevent leakage in the host netns, therefore
|
||||
// it should use the following structure:
|
||||
// It("test name", func() {
|
||||
// runTest(func() {
|
||||
// // add test logic here
|
||||
// })
|
||||
// })
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/vishvananda/netlink"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/network/util"
|
||||
"github.com/containers/podman/v3/pkg/netns"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
)
|
||||
|
||||
var _ = Describe("run netavark", func() {
|
||||
var (
|
||||
libpodNet types.ContainerNetwork
|
||||
confDir string
|
||||
netNSTest ns.NetNS
|
||||
netNSContainer ns.NetNS
|
||||
)
|
||||
|
||||
// runTest is a helper function to run a test. It ensures that each test
|
||||
// is run in its own netns. It also creates a mountns to mount a tmpfs to /var/lib/cni.
|
||||
runTest := func(run func()) {
|
||||
netNSTest.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
// we have to setup the loopback adapter in this netns to use port forwarding
|
||||
link, err := netlink.LinkByName("lo")
|
||||
Expect(err).To(BeNil(), "Failed to get loopback adapter")
|
||||
err = netlink.LinkSetUp(link)
|
||||
Expect(err).To(BeNil(), "Failed to set loopback adapter up")
|
||||
run()
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
if _, ok := os.LookupEnv("NETAVARK_BINARY"); !ok {
|
||||
Skip("NETAVARK_BINARY not set skip run tests")
|
||||
}
|
||||
|
||||
// set the logrus settings
|
||||
logrus.SetLevel(logrus.TraceLevel)
|
||||
// disable extra quotes so we can easily copy the netavark command
|
||||
logrus.SetFormatter(&logrus.TextFormatter{DisableQuote: true})
|
||||
logrus.SetOutput(os.Stderr)
|
||||
// The tests need root privileges.
|
||||
// Technically we could work around that by using user namespaces and
|
||||
// the rootless cni code but this is to much work to get it right for a unit test.
|
||||
if rootless.IsRootless() {
|
||||
Skip("this test needs to be run as root")
|
||||
}
|
||||
|
||||
var err error
|
||||
confDir, err = ioutil.TempDir("", "podman_netavark_test")
|
||||
if err != nil {
|
||||
Fail("Failed to create tmpdir")
|
||||
}
|
||||
|
||||
netNSTest, err = netns.NewNS()
|
||||
if err != nil {
|
||||
Fail("Failed to create netns")
|
||||
}
|
||||
|
||||
netNSContainer, err = netns.NewNS()
|
||||
if err != nil {
|
||||
Fail("Failed to create netns")
|
||||
}
|
||||
|
||||
// Force iptables driver, firewalld is broken inside the extra
|
||||
// namespace because it still connects to firewalld on the host.
|
||||
_ = os.Setenv("NETAVARK_FW", "iptables")
|
||||
})
|
||||
|
||||
JustBeforeEach(func() {
|
||||
var err error
|
||||
libpodNet, err = getNetworkInterface(confDir, false)
|
||||
if err != nil {
|
||||
Fail("Failed to create NewCNINetworkInterface")
|
||||
}
|
||||
})
|
||||
|
||||
AfterEach(func() {
|
||||
logrus.SetFormatter(&logrus.TextFormatter{})
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
os.RemoveAll(confDir)
|
||||
|
||||
netns.UnmountNS(netNSTest)
|
||||
netNSTest.Close()
|
||||
|
||||
netns.UnmountNS(netNSContainer)
|
||||
netNSContainer.Close()
|
||||
|
||||
_ = os.Unsetenv("NETAVARK_FW")
|
||||
})
|
||||
|
||||
It("test basic setup", func() {
|
||||
runTest(func() {
|
||||
defNet := types.DefaultNetworkName
|
||||
intName := "eth0"
|
||||
opts := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: "someID",
|
||||
ContainerName: "someName",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
defNet: {
|
||||
InterfaceName: intName,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := libpodNet.Setup(netNSContainer.Path(), opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res).To(HaveLen(1))
|
||||
Expect(res).To(HaveKey(defNet))
|
||||
Expect(res[defNet].Interfaces).To(HaveKey(intName))
|
||||
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
|
||||
ip := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
|
||||
Expect(ip.String()).To(ContainSubstring("10.88.0."))
|
||||
gw := res[defNet].Interfaces[intName].Subnets[0].Gateway
|
||||
util.NormalizeIP(&gw)
|
||||
Expect(gw.String()).To(Equal("10.88.0.1"))
|
||||
macAddress := res[defNet].Interfaces[intName].MacAddress
|
||||
Expect(macAddress).To(HaveLen(6))
|
||||
// default network has no dns
|
||||
Expect(res[defNet].DNSServerIPs).To(BeEmpty())
|
||||
Expect(res[defNet].DNSSearchDomains).To(BeEmpty())
|
||||
|
||||
// check in the container namespace if the settings are applied
|
||||
err = netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
i, err := net.InterfaceByName(intName)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(i.Name).To(Equal(intName))
|
||||
Expect(i.HardwareAddr).To(Equal(net.HardwareAddr(macAddress)))
|
||||
addrs, err := i.Addrs()
|
||||
Expect(err).To(BeNil())
|
||||
subnet := &net.IPNet{
|
||||
IP: ip,
|
||||
Mask: net.CIDRMask(16, 32),
|
||||
}
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(subnet)))
|
||||
|
||||
// check loopback adapter
|
||||
i, err = net.InterfaceByName("lo")
|
||||
Expect(err).To(BeNil())
|
||||
Expect(i.Name).To(Equal("lo"))
|
||||
Expect(i.Flags & net.FlagLoopback).To(Equal(net.FlagLoopback))
|
||||
Expect(i.Flags&net.FlagUp).To(Equal(net.FlagUp), "Loopback adapter should be up")
|
||||
return nil
|
||||
})
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
// default bridge name
|
||||
bridgeName := "podman0"
|
||||
// check settings on the host side
|
||||
i, err := net.InterfaceByName(bridgeName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal(bridgeName))
|
||||
addrs, err := i.Addrs()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// test that the gateway ip is assigned to the interface
|
||||
subnet := &net.IPNet{
|
||||
IP: gw,
|
||||
Mask: net.CIDRMask(16, 32),
|
||||
}
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(subnet)))
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
expected := stringid.GenerateNonCryptoID()
|
||||
// now check ip connectivity
|
||||
err = netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
wg.Add(1)
|
||||
runNetListener(wg, "tcp", "0.0.0.0", 5000, expected)
|
||||
return nil
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
conn, err := net.Dial("tcp", ip.String()+":5000")
|
||||
Expect(err).To(BeNil())
|
||||
_, err = conn.Write([]byte(expected))
|
||||
Expect(err).To(BeNil())
|
||||
conn.Close()
|
||||
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(opts))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
wg.Wait()
|
||||
})
|
||||
})
|
||||
|
||||
It("setup two containers", func() {
|
||||
runTest(func() {
|
||||
defNet := types.DefaultNetworkName
|
||||
intName := "eth0"
|
||||
setupOpts1 := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: stringid.GenerateNonCryptoID(),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
defNet: {InterfaceName: intName},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := libpodNet.Setup(netNSContainer.Path(), setupOpts1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res).To(HaveLen(1))
|
||||
Expect(res).To(HaveKey(defNet))
|
||||
Expect(res[defNet].Interfaces).To(HaveKey(intName))
|
||||
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
|
||||
ip1 := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
|
||||
Expect(ip1.String()).To(ContainSubstring("10.88.0."))
|
||||
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
|
||||
|
||||
setupOpts2 := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: stringid.GenerateNonCryptoID(),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
defNet: {InterfaceName: intName},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
netNSContainer2, err := netns.NewNS()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defer netns.UnmountNS(netNSContainer2)
|
||||
defer netNSContainer2.Close()
|
||||
|
||||
res, err = libpodNet.Setup(netNSContainer2.Path(), setupOpts2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res).To(HaveLen(1))
|
||||
Expect(res).To(HaveKey(defNet))
|
||||
Expect(res[defNet].Interfaces).To(HaveKey(intName))
|
||||
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
|
||||
ip2 := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
|
||||
Expect(ip2.String()).To(ContainSubstring("10.88.0."))
|
||||
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
|
||||
Expect(ip1.Equal(ip2)).To(BeFalse(), "IP1 %s should not be equal to IP2 %s", ip1.String(), ip2.String())
|
||||
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(setupOpts1))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(setupOpts2))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
It("setup dualstack network", func() {
|
||||
runTest(func() {
|
||||
s1, _ := types.ParseCIDR("10.0.0.1/24")
|
||||
s2, _ := types.ParseCIDR("fd10:88:a::/64")
|
||||
network, err := libpodNet.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{Subnet: s1}, {Subnet: s2},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName := network.Name
|
||||
intName := "eth0"
|
||||
|
||||
setupOpts := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: stringid.GenerateNonCryptoID(),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName: {InterfaceName: intName},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := libpodNet.Setup(netNSContainer.Path(), setupOpts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res).To(HaveLen(1))
|
||||
Expect(res).To(HaveKey(netName))
|
||||
Expect(res[netName].Interfaces).To(HaveKey(intName))
|
||||
Expect(res[netName].Interfaces[intName].Subnets).To(HaveLen(2))
|
||||
ip1 := res[netName].Interfaces[intName].Subnets[0].IPNet.IP
|
||||
Expect(ip1.String()).To(ContainSubstring("10.0.0."))
|
||||
gw1 := res[netName].Interfaces[intName].Subnets[0].Gateway
|
||||
Expect(gw1.String()).To(Equal("10.0.0.1"))
|
||||
ip2 := res[netName].Interfaces[intName].Subnets[1].IPNet.IP
|
||||
Expect(ip2.String()).To(ContainSubstring("fd10:88:a::"))
|
||||
gw2 := res[netName].Interfaces[intName].Subnets[0].Gateway
|
||||
Expect(gw2.String()).To(Equal("fd10:88:a::1"))
|
||||
Expect(res[netName].Interfaces[intName].MacAddress).To(HaveLen(6))
|
||||
|
||||
// check in the container namespace if the settings are applied
|
||||
err = netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
i, err := net.InterfaceByName(intName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal(intName))
|
||||
addrs, err := i.Addrs()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
subnet1 := s1.IPNet
|
||||
subnet1.IP = ip1
|
||||
subnet2 := s2.IPNet
|
||||
subnet2.IP = ip2
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(&subnet1), EqualSubnet(&subnet2)))
|
||||
|
||||
// check loopback adapter
|
||||
i, err = net.InterfaceByName("lo")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal("lo"))
|
||||
Expect(i.Flags & net.FlagLoopback).To(Equal(net.FlagLoopback))
|
||||
Expect(i.Flags&net.FlagUp).To(Equal(net.FlagUp), "Loopback adapter should be up")
|
||||
return nil
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
bridgeName := network.NetworkInterface
|
||||
// check settings on the host side
|
||||
i, err := net.InterfaceByName(bridgeName)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal(bridgeName))
|
||||
addrs, err := i.Addrs()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// test that the gateway ip is assigned to the interface
|
||||
subnet1 := s1.IPNet
|
||||
subnet1.IP = gw1
|
||||
subnet2 := s2.IPNet
|
||||
subnet2.IP = gw2
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(&subnet1), EqualSubnet(&subnet2)))
|
||||
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(setupOpts))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
It("setup two networks", func() {
|
||||
runTest(func() {
|
||||
s1, _ := types.ParseCIDR("10.0.0.1/24")
|
||||
network1, err := libpodNet.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{Subnet: s1},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName1 := network1.Name
|
||||
intName1 := "eth0"
|
||||
|
||||
s2, _ := types.ParseCIDR("10.1.0.0/24")
|
||||
network2, err := libpodNet.NetworkCreate(types.Network{
|
||||
Subnets: []types.Subnet{
|
||||
{Subnet: s2},
|
||||
},
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
netName2 := network2.Name
|
||||
intName2 := "eth1"
|
||||
|
||||
setupOpts := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: stringid.GenerateNonCryptoID(),
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
netName1: {InterfaceName: intName1},
|
||||
netName2: {InterfaceName: intName2},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := libpodNet.Setup(netNSContainer.Path(), setupOpts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res).To(HaveLen(2))
|
||||
Expect(res).To(HaveKey(netName1))
|
||||
Expect(res).To(HaveKey(netName2))
|
||||
Expect(res[netName1].Interfaces).To(HaveKey(intName1))
|
||||
Expect(res[netName2].Interfaces).To(HaveKey(intName2))
|
||||
Expect(res[netName1].Interfaces[intName1].Subnets).To(HaveLen(1))
|
||||
ip1 := res[netName1].Interfaces[intName1].Subnets[0].IPNet.IP
|
||||
Expect(ip1.String()).To(ContainSubstring("10.0.0."))
|
||||
gw1 := res[netName1].Interfaces[intName1].Subnets[0].Gateway
|
||||
Expect(gw1.String()).To(Equal("10.0.0.1"))
|
||||
ip2 := res[netName2].Interfaces[intName2].Subnets[0].IPNet.IP
|
||||
Expect(ip2.String()).To(ContainSubstring("10.1.0."))
|
||||
gw2 := res[netName2].Interfaces[intName2].Subnets[0].Gateway
|
||||
Expect(gw2.String()).To(Equal("10.1.0.1"))
|
||||
mac1 := res[netName1].Interfaces[intName1].MacAddress
|
||||
Expect(mac1).To(HaveLen(6))
|
||||
mac2 := res[netName2].Interfaces[intName2].MacAddress
|
||||
Expect(mac2).To(HaveLen(6))
|
||||
|
||||
// check in the container namespace if the settings are applied
|
||||
err = netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
i, err := net.InterfaceByName(intName1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal(intName1))
|
||||
addrs, err := i.Addrs()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
subnet1 := s1.IPNet
|
||||
subnet1.IP = ip1
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(&subnet1)))
|
||||
|
||||
i, err = net.InterfaceByName(intName2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal(intName2))
|
||||
addrs, err = i.Addrs()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
subnet2 := s2.IPNet
|
||||
subnet2.IP = ip2
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(&subnet2)))
|
||||
|
||||
// check loopback adapter
|
||||
i, err = net.InterfaceByName("lo")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal("lo"))
|
||||
Expect(i.Flags & net.FlagLoopback).To(Equal(net.FlagLoopback))
|
||||
Expect(i.Flags&net.FlagUp).To(Equal(net.FlagUp), "Loopback adapter should be up")
|
||||
return nil
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
bridgeName1 := network1.NetworkInterface
|
||||
// check settings on the host side
|
||||
i, err := net.InterfaceByName(bridgeName1)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal(bridgeName1))
|
||||
addrs, err := i.Addrs()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// test that the gateway ip is assigned to the interface
|
||||
subnet1 := s1.IPNet
|
||||
subnet1.IP = gw1
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(&subnet1)))
|
||||
|
||||
bridgeName2 := network2.NetworkInterface
|
||||
// check settings on the host side
|
||||
i, err = net.InterfaceByName(bridgeName2)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(i.Name).To(Equal(bridgeName2))
|
||||
addrs, err = i.Addrs()
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
// test that the gateway ip is assigned to the interface
|
||||
subnet2 := s2.IPNet
|
||||
subnet2.IP = gw2
|
||||
Expect(addrs).To(ContainElements(EqualSubnet(&subnet2)))
|
||||
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(setupOpts))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
for _, proto := range []string{"tcp", "udp"} {
|
||||
// copy proto to extra var to keep correct references in the goroutines
|
||||
protocol := proto
|
||||
It("run with exposed ports protocol "+protocol, func() {
|
||||
runTest(func() {
|
||||
testdata := stringid.GenerateNonCryptoID()
|
||||
defNet := types.DefaultNetworkName
|
||||
intName := "eth0"
|
||||
setupOpts := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: stringid.GenerateNonCryptoID(),
|
||||
PortMappings: []types.PortMapping{{
|
||||
Protocol: protocol,
|
||||
HostIP: "127.0.0.1",
|
||||
HostPort: 5000,
|
||||
ContainerPort: 5000,
|
||||
}},
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
defNet: {InterfaceName: intName},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := libpodNet.Setup(netNSContainer.Path(), setupOpts)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(res).To(HaveLen(1))
|
||||
Expect(res).To(HaveKey(defNet))
|
||||
Expect(res[defNet].Interfaces).To(HaveKey(intName))
|
||||
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
|
||||
Expect(res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()).To(ContainSubstring("10.88.0."))
|
||||
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
|
||||
// default network has no dns
|
||||
Expect(res[defNet].DNSServerIPs).To(BeEmpty())
|
||||
Expect(res[defNet].DNSSearchDomains).To(BeEmpty())
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
// start a listener in the container ns
|
||||
err = netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
runNetListener(&wg, protocol, "0.0.0.0", 5000, testdata)
|
||||
return nil
|
||||
})
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
conn, err := net.Dial(protocol, "127.0.0.1:5000")
|
||||
Expect(err).To(BeNil())
|
||||
_, err = conn.Write([]byte(testdata))
|
||||
Expect(err).To(BeNil())
|
||||
conn.Close()
|
||||
|
||||
// wait for the listener to finish
|
||||
wg.Wait()
|
||||
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(setupOpts))
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
})
|
||||
|
||||
It("run with range ports protocol "+protocol, func() {
|
||||
runTest(func() {
|
||||
defNet := types.DefaultNetworkName
|
||||
intName := "eth0"
|
||||
setupOpts := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: stringid.GenerateNonCryptoID(),
|
||||
PortMappings: []types.PortMapping{{
|
||||
Protocol: protocol,
|
||||
HostIP: "127.0.0.1",
|
||||
HostPort: 5001,
|
||||
ContainerPort: 5000,
|
||||
Range: 3,
|
||||
}},
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
defNet: {InterfaceName: intName},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := libpodNet.Setup(netNSContainer.Path(), setupOpts)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(res).To(HaveLen(1))
|
||||
Expect(res).To(HaveKey(defNet))
|
||||
Expect(res[defNet].Interfaces).To(HaveKey(intName))
|
||||
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
|
||||
containerIP := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP.String()
|
||||
Expect(containerIP).To(ContainSubstring("10.88.0."))
|
||||
Expect(res[defNet].Interfaces[intName].MacAddress).To(HaveLen(6))
|
||||
// default network has no dns
|
||||
Expect(res[defNet].DNSServerIPs).To(BeEmpty())
|
||||
Expect(res[defNet].DNSSearchDomains).To(BeEmpty())
|
||||
|
||||
// loop over all ports
|
||||
for p := 5001; p < 5004; p++ {
|
||||
port := p
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
testdata := stringid.GenerateNonCryptoID()
|
||||
// start a listener in the container ns
|
||||
err = netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
runNetListener(&wg, protocol, containerIP, port-1, testdata)
|
||||
return nil
|
||||
})
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
conn, err := net.Dial(protocol, net.JoinHostPort("127.0.0.1", strconv.Itoa(port)))
|
||||
Expect(err).To(BeNil())
|
||||
_, err = conn.Write([]byte(testdata))
|
||||
Expect(err).To(BeNil())
|
||||
conn.Close()
|
||||
|
||||
// wait for the listener to finish
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(setupOpts))
|
||||
Expect(err).To(BeNil())
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
It("simple teardown", func() {
|
||||
runTest(func() {
|
||||
defNet := types.DefaultNetworkName
|
||||
intName := "eth0"
|
||||
opts := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: "someID",
|
||||
ContainerName: "someName",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
defNet: {
|
||||
InterfaceName: intName,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
res, err := libpodNet.Setup(netNSContainer.Path(), opts)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(res).To(HaveLen(1))
|
||||
Expect(res).To(HaveKey(defNet))
|
||||
Expect(res[defNet].Interfaces).To(HaveKey(intName))
|
||||
Expect(res[defNet].Interfaces[intName].Subnets).To(HaveLen(1))
|
||||
ip := res[defNet].Interfaces[intName].Subnets[0].IPNet.IP
|
||||
Expect(ip.String()).To(ContainSubstring("10.88.0."))
|
||||
gw := res[defNet].Interfaces[intName].Subnets[0].Gateway
|
||||
Expect(gw.String()).To(Equal("10.88.0.1"))
|
||||
macAddress := res[defNet].Interfaces[intName].MacAddress
|
||||
Expect(macAddress).To(HaveLen(6))
|
||||
|
||||
err = libpodNet.Teardown(netNSContainer.Path(), types.TeardownOptions(opts))
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
err = netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
// check that the container interface is removed
|
||||
_, err := net.InterfaceByName(intName)
|
||||
Expect(err).To(HaveOccurred())
|
||||
return nil
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
// default bridge name
|
||||
bridgeName := "podman0"
|
||||
// check that bridge interface was removed
|
||||
_, err = net.InterfaceByName(bridgeName)
|
||||
Expect(err).To(HaveOccurred())
|
||||
})
|
||||
})
|
||||
|
||||
It("test netavark error", func() {
|
||||
runTest(func() {
|
||||
intName := "eth0"
|
||||
err := netNSContainer.Do(func(_ ns.NetNS) error {
|
||||
defer GinkgoRecover()
|
||||
|
||||
attr := netlink.NewLinkAttrs()
|
||||
attr.Name = "eth0"
|
||||
err := netlink.LinkAdd(&netlink.Bridge{LinkAttrs: attr})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
return nil
|
||||
})
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
defNet := types.DefaultNetworkName
|
||||
opts := types.SetupOptions{
|
||||
NetworkOptions: types.NetworkOptions{
|
||||
ContainerID: "someID",
|
||||
ContainerName: "someName",
|
||||
Networks: map[string]types.PerNetworkOptions{
|
||||
defNet: {
|
||||
InterfaceName: intName,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
_, err = libpodNet.Setup(netNSContainer.Path(), opts)
|
||||
Expect(err).To(HaveOccurred())
|
||||
Expect(err.Error()).To(ContainSubstring("interface eth0 already exists on container namespace"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
func runNetListener(wg *sync.WaitGroup, protocol, ip string, port int, expectedData string) {
|
||||
switch protocol {
|
||||
case "tcp":
|
||||
ln, err := net.Listen(protocol, net.JoinHostPort(ip, strconv.Itoa(port)))
|
||||
Expect(err).To(BeNil())
|
||||
// make sure to read in a separate goroutine to not block
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
defer wg.Done()
|
||||
defer ln.Close()
|
||||
conn, err := ln.Accept()
|
||||
Expect(err).To(BeNil())
|
||||
defer conn.Close()
|
||||
conn.SetDeadline(time.Now().Add(1 * time.Second))
|
||||
data, err := ioutil.ReadAll(conn)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(string(data)).To(Equal(expectedData))
|
||||
}()
|
||||
case "udp":
|
||||
conn, err := net.ListenUDP("udp", &net.UDPAddr{
|
||||
IP: net.ParseIP(ip),
|
||||
Port: port,
|
||||
})
|
||||
Expect(err).To(BeNil())
|
||||
conn.SetDeadline(time.Now().Add(1 * time.Second))
|
||||
go func() {
|
||||
defer GinkgoRecover()
|
||||
defer wg.Done()
|
||||
defer conn.Close()
|
||||
data := make([]byte, len(expectedData))
|
||||
i, err := conn.Read(data)
|
||||
Expect(err).To(BeNil())
|
||||
Expect(i).To(Equal(len(expectedData)))
|
||||
Expect(string(data)).To(Equal(expectedData))
|
||||
}()
|
||||
default:
|
||||
Fail("unsupported protocol")
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
{
|
||||
"name": "bridge",
|
||||
"id": "17f29b073143d8cd97b5bbe492bdeffec1c5fee55cc1fe2112c8b9335f8b6121",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman9",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1",
|
||||
"lease_range": {
|
||||
"start_ip": "10.89.8.20",
|
||||
"end_ip": "10.89.8.50"
|
||||
}
|
||||
}
|
||||
],
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "invalid name",
|
||||
"id": "6839f44f0fd01c5c5830856b66a1d7ce46842dd8798be0addf96f7255ce9f889",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman9",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": true,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "invalid_gateway",
|
||||
"id": "49be6e401e7f8b9844afb969dcbc96e78205ed86ec1e5a46150bd4ab4fdd5686",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman9",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.9.0/24",
|
||||
"gateway": "10.89.100.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": true,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "name_miss",
|
||||
"id": "3bed2cb3a3acf7b6a8ef408420cc682d5520e26976d354254f528c965612054f",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman8",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.7.0/24",
|
||||
"gateway": "10.89.7.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": true,
|
||||
"dns_enabled": false,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "wrongID",
|
||||
"id": "someID",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman1",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.0.0/24",
|
||||
"gateway": "10.89.0.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": false,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"name": "bridge",
|
||||
"id": "17f29b073143d8cd97b5bbe492bdeffec1c5fee55cc1fe2112c8b9335f8b6121",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman9",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.8.0/24",
|
||||
"gateway": "10.89.8.1",
|
||||
"lease_range": {
|
||||
"start_ip": "10.89.8.20",
|
||||
"end_ip": "10.89.8.50"
|
||||
}
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": true,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
{
|
||||
"name": "dualstack",
|
||||
"id": "6839f44f0fd01c5c5830856b66a1d7ce46842dd8798be0addf96f7255ce9f889",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman21",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "fd10:88:a::/64",
|
||||
"gateway": "fd10:88:a::1"
|
||||
},
|
||||
{
|
||||
"subnet": "10.89.19.0/24",
|
||||
"gateway": "10.89.19.10"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": true,
|
||||
"internal": false,
|
||||
"dns_enabled": true,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
{
|
||||
"name": "internal",
|
||||
"id": "3bed2cb3a3acf7b6a8ef408420cc682d5520e26976d354254f528c965612054f",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman8",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.7.0/24"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": true,
|
||||
"dns_enabled": false,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "label",
|
||||
"id": "1aca80e8b55c802f7b43740da2990e1b5735bbb323d93eb5ebda8395b04025e2",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman15",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.13.0/24",
|
||||
"gateway": "10.89.13.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": true,
|
||||
"labels": {
|
||||
"mykey": "value"
|
||||
},
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "mtu",
|
||||
"id": "49be6e401e7f8b9844afb969dcbc96e78205ed86ec1e5a46150bd4ab4fdd5686",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman13",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.11.0/24",
|
||||
"gateway": "10.89.11.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": true,
|
||||
"options": {
|
||||
"mtu": "1500"
|
||||
},
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
{
|
||||
"name": "podman",
|
||||
"id": "2f259bab93aaaaa2542ba43ef33eb990d0999ee1b9924b557b7be53c0b7a1bb9",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman0",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.88.0.0/16",
|
||||
"gateway": "10.88.0.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": false,
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,22 +0,0 @@
|
|||
{
|
||||
"name": "vlan",
|
||||
"id": "c3b258168c41c0bce97616716bef315eeed33eb1142904bfe7f32eb392c7cf80",
|
||||
"driver": "bridge",
|
||||
"network_interface": "podman14",
|
||||
"created": "2021-10-06T18:50:54.25770461+02:00",
|
||||
"subnets": [
|
||||
{
|
||||
"subnet": "10.89.12.0/24",
|
||||
"gateway": "10.89.12.1"
|
||||
}
|
||||
],
|
||||
"ipv6_enabled": false,
|
||||
"internal": false,
|
||||
"dns_enabled": true,
|
||||
"options": {
|
||||
"vlan": "5"
|
||||
},
|
||||
"ipam_options": {
|
||||
"driver": "host-local"
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
package types_test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
)
|
||||
|
||||
func TestUnmarshalMacAddress(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
json string
|
||||
want types.HardwareAddr
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "mac as string with colon",
|
||||
json: `"52:54:00:1c:2e:46"`,
|
||||
want: types.HardwareAddr{0x52, 0x54, 0x00, 0x1c, 0x2e, 0x46},
|
||||
},
|
||||
{
|
||||
name: "mac as string with dash",
|
||||
json: `"52-54-00-1c-2e-46"`,
|
||||
want: types.HardwareAddr{0x52, 0x54, 0x00, 0x1c, 0x2e, 0x46},
|
||||
},
|
||||
{
|
||||
name: "mac as byte array",
|
||||
json: `[82, 84, 0, 28, 46, 70]`,
|
||||
want: types.HardwareAddr{0x52, 0x54, 0x00, 0x1c, 0x2e, 0x46},
|
||||
},
|
||||
{
|
||||
name: "null value",
|
||||
json: `null`,
|
||||
want: nil,
|
||||
},
|
||||
{
|
||||
name: "mac as base64",
|
||||
json: `"qrvM3e7/"`,
|
||||
want: types.HardwareAddr{0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff},
|
||||
},
|
||||
{
|
||||
name: "invalid string",
|
||||
json: `"52:54:00:1c:2e`,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid array",
|
||||
json: `[82, 84, 0, 28, 46`,
|
||||
wantErr: true,
|
||||
},
|
||||
|
||||
{
|
||||
name: "invalid value",
|
||||
json: `ab`,
|
||||
wantErr: true,
|
||||
},
|
||||
{
|
||||
name: "invalid object",
|
||||
json: `{}`,
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
test := tt
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
mac := types.HardwareAddr{}
|
||||
err := json.Unmarshal([]byte(test.json), &mac)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("types.HardwareAddress Unmarshal() error = %v, wantErr %v", err, test.wantErr)
|
||||
return
|
||||
}
|
||||
if test.wantErr {
|
||||
return
|
||||
}
|
||||
if !reflect.DeepEqual(mac, test.want) {
|
||||
t.Errorf("types.HardwareAddress Unmarshal() got = %v, want %v", mac, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -1,73 +0,0 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"net"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func parseCIDR(n string) *net.IPNet {
|
||||
_, parsedNet, _ := net.ParseCIDR(n)
|
||||
return parsedNet
|
||||
}
|
||||
|
||||
func TestFirstIPInSubnet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args *net.IPNet
|
||||
want net.IP
|
||||
wantErr bool
|
||||
}{
|
||||
{"class b", parseCIDR("192.168.0.0/16"), net.ParseIP("192.168.0.1"), false},
|
||||
{"class c", parseCIDR("192.168.1.0/24"), net.ParseIP("192.168.1.1"), false},
|
||||
{"cidr /23", parseCIDR("192.168.0.0/23"), net.ParseIP("192.168.0.1"), false},
|
||||
{"cidr /25", parseCIDR("192.168.1.0/25"), net.ParseIP("192.168.1.1"), false},
|
||||
{"cidr /26", parseCIDR("172.16.1.128/26"), net.ParseIP("172.16.1.129"), false},
|
||||
{"class a", parseCIDR("10.0.0.0/8"), net.ParseIP("10.0.0.1"), false},
|
||||
{"cidr /32", parseCIDR("192.168.255.4/32"), net.ParseIP("192.168.255.4"), false},
|
||||
{"cidr /31", parseCIDR("192.168.255.4/31"), net.ParseIP("192.168.255.5"), false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
test := tt
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := FirstIPInSubnet(test.args)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("FirstIPInSubnet() error = %v, wantErr %v", err, test.wantErr)
|
||||
return
|
||||
}
|
||||
if !got.Equal(test.want) {
|
||||
t.Errorf("FirstIPInSubnet() got = %v, want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestLastIPInSubnet(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
args *net.IPNet
|
||||
want net.IP
|
||||
wantErr bool
|
||||
}{
|
||||
{"class b", parseCIDR("192.168.0.0/16"), net.ParseIP("192.168.255.255"), false},
|
||||
{"class c", parseCIDR("192.168.1.0/24"), net.ParseIP("192.168.1.255"), false},
|
||||
{"cidr /23", parseCIDR("192.168.0.0/23"), net.ParseIP("192.168.1.255"), false},
|
||||
{"cidr /25", parseCIDR("192.168.1.0/25"), net.ParseIP("192.168.1.127"), false},
|
||||
{"cidr /26", parseCIDR("172.16.1.128/26"), net.ParseIP("172.16.1.191"), false},
|
||||
{"class a", parseCIDR("10.0.0.0/8"), net.ParseIP("10.255.255.255"), false},
|
||||
{"cidr /32", parseCIDR("192.168.255.4/32"), net.ParseIP("192.168.255.4"), false},
|
||||
{"cidr /31", parseCIDR("192.168.255.4/31"), net.ParseIP("192.168.255.5"), false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
test := tt
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
got, err := LastIPInSubnet(test.args)
|
||||
if (err != nil) != test.wantErr {
|
||||
t.Errorf("LastIPInSubnet() error = %v, wantErr %v", err, test.wantErr)
|
||||
return
|
||||
}
|
||||
if !got.Equal(test.want) {
|
||||
t.Errorf("LastIPInSubnet() got = %v, want %v", got, test.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
|
@ -19,9 +19,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/events"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/errorhandling"
|
||||
"github.com/containers/podman/v3/pkg/namespaces"
|
||||
"github.com/containers/podman/v3/pkg/netns"
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
)
|
||||
|
||||
func Test_ocicniPortsToNetTypesPorts(t *testing.T) {
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/pkg/errorhandling"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
"github.com/containers/podman/v3/pkg/rootlessport"
|
||||
|
|
|
@ -8,8 +8,8 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
|
|
@ -8,13 +8,13 @@ import (
|
|||
"syscall"
|
||||
|
||||
"github.com/containers/buildah/pkg/parse"
|
||||
nettypes "github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/common/pkg/secrets"
|
||||
"github.com/containers/image/v5/manifest"
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/events"
|
||||
nettypes "github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/namespaces"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
|
|
|
@ -19,6 +19,8 @@ import (
|
|||
|
||||
"github.com/containers/buildah/pkg/parse"
|
||||
"github.com/containers/common/libimage"
|
||||
"github.com/containers/common/libnetwork/network"
|
||||
nettypes "github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/cgroups"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/common/pkg/secrets"
|
||||
|
@ -28,9 +30,6 @@ import (
|
|||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/events"
|
||||
"github.com/containers/podman/v3/libpod/lock"
|
||||
"github.com/containers/podman/v3/libpod/network/cni"
|
||||
"github.com/containers/podman/v3/libpod/network/netavark"
|
||||
nettypes "github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/plugin"
|
||||
"github.com/containers/podman/v3/libpod/shutdown"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
|
@ -489,50 +488,16 @@ func makeRuntime(ctx context.Context, runtime *Runtime) (retErr error) {
|
|||
}
|
||||
}
|
||||
|
||||
var netInterface nettypes.ContainerNetwork
|
||||
|
||||
switch runtime.config.Network.NetworkBackend {
|
||||
case "", "cni":
|
||||
netInterface, err = cni.NewCNINetworkInterface(cni.InitConfig{
|
||||
CNIConfigDir: runtime.config.Network.NetworkConfigDir,
|
||||
CNIPluginDirs: runtime.config.Network.CNIPluginDirs,
|
||||
DefaultNetwork: runtime.config.Network.DefaultNetwork,
|
||||
DefaultSubnet: runtime.config.Network.DefaultSubnet,
|
||||
IsMachine: runtime.config.Engine.MachineEnabled,
|
||||
LockFile: filepath.Join(runtime.config.Network.NetworkConfigDir, "cni.lock"),
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create network interface")
|
||||
}
|
||||
if runtime.config.Network.NetworkBackend == "" {
|
||||
// set backend to cni so that podman info can display it
|
||||
runtime.config.Network.NetworkBackend = "cni"
|
||||
}
|
||||
|
||||
case "netavark":
|
||||
netavarkBin, err := runtime.config.FindHelperBinary("netavark", false)
|
||||
// the store is only setup when we are in the userns so we do the same for the network interface
|
||||
if !needsUserns {
|
||||
netBackend, netInterface, err := network.NetworkBackend(runtime.store, runtime.config, runtime.syslog)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
netInterface, err = netavark.NewNetworkInterface(netavark.InitConfig{
|
||||
NetavarkBinary: netavarkBin,
|
||||
NetworkConfigDir: filepath.Join(runtime.config.Engine.StaticDir, "networks"),
|
||||
DefaultNetwork: runtime.config.Network.DefaultNetwork,
|
||||
DefaultSubnet: runtime.config.Network.DefaultSubnet,
|
||||
IsMachine: runtime.config.Engine.MachineEnabled,
|
||||
LockFile: filepath.Join(runtime.config.Network.NetworkConfigDir, "netavark.lock"),
|
||||
Syslog: runtime.syslog,
|
||||
})
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create network interface")
|
||||
}
|
||||
default:
|
||||
return errors.Errorf("unsupported network backend %q, check network_backend in containers.conf", runtime.config.Network.NetworkBackend)
|
||||
runtime.config.Network.NetworkBackend = string(netBackend)
|
||||
runtime.network = netInterface
|
||||
}
|
||||
|
||||
runtime.network = netInterface
|
||||
|
||||
// We now need to see if the system has restarted
|
||||
// We check for the presence of a file in our tmp directory to verify this
|
||||
// This check must be locked to prevent races
|
||||
|
|
|
@ -10,11 +10,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/containers/buildah"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/cgroups"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/events"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/shutdown"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities/reports"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package libpod
|
||||
|
||||
import "github.com/containers/podman/v3/libpod/network/types"
|
||||
import "github.com/containers/common/libnetwork/types"
|
||||
|
||||
// State is a storage backend for libpod's current state.
|
||||
// A State is only initialized once per instance of libpod.
|
||||
|
|
|
@ -8,10 +8,10 @@ import (
|
|||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/lock"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/storage"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
|
|
@ -13,9 +13,9 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/utils"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
|
|
|
@ -6,10 +6,10 @@ import (
|
|||
"net"
|
||||
"net/http"
|
||||
|
||||
nettypes "github.com/containers/common/libnetwork/types"
|
||||
netutil "github.com/containers/common/libnetwork/util"
|
||||
"github.com/containers/podman/v3/libpod"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
nettypes "github.com/containers/podman/v3/libpod/network/types"
|
||||
netutil "github.com/containers/podman/v3/libpod/network/util"
|
||||
"github.com/containers/podman/v3/pkg/api/handlers/utils"
|
||||
api "github.com/containers/podman/v3/pkg/api/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/libpod"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/api/handlers/utils"
|
||||
api "github.com/containers/podman/v3/pkg/api/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/image/v5/manifest"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/api/handlers/utils"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/pkg/errors"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/pkg/bindings"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/pkg/bindings"
|
||||
"github.com/containers/podman/v3/pkg/bindings/containers"
|
||||
"github.com/containers/podman/v3/pkg/bindings/network"
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/pkg/ps/define"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
nettypes "github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
nettypes "github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
)
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"context"
|
||||
"io"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities/reports"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ package entities
|
|||
import (
|
||||
"net"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
)
|
||||
|
||||
// NetworkListOptions describes options for listing networks in cli
|
||||
|
|
|
@ -4,9 +4,9 @@ import (
|
|||
"net"
|
||||
|
||||
buildahDefine "github.com/containers/buildah/define"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/events"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
"github.com/containers/storage/pkg/archive"
|
||||
)
|
||||
|
|
|
@ -3,9 +3,9 @@ package abi
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
netutil "github.com/containers/common/libnetwork/util"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
netutil "github.com/containers/podman/v3/libpod/network/util"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
|
|
|
@ -13,11 +13,11 @@ import (
|
|||
|
||||
buildahDefine "github.com/containers/buildah/define"
|
||||
"github.com/containers/common/libimage"
|
||||
nettypes "github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/image/v5/types"
|
||||
"github.com/containers/podman/v3/libpod"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
nettypes "github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/autoupdate"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
|
|
|
@ -3,8 +3,8 @@ package tunnel
|
|||
import (
|
||||
"context"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/bindings/network"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/errorhandling"
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
package rootlessport
|
||||
|
||||
import (
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -9,11 +9,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/containers/common/libimage"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/parse"
|
||||
"github.com/containers/common/pkg/secrets"
|
||||
"github.com/containers/image/v5/manifest"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
ann "github.com/containers/podman/v3/pkg/annotations"
|
||||
"github.com/containers/podman/v3/pkg/domain/entities"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/containers/common/libimage"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
"github.com/containers/podman/v3/pkg/util"
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/containers/common/libimage"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/utils"
|
||||
|
||||
"github.com/containers/podman/v3/pkg/specgen"
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
)
|
||||
|
||||
func benchmarkParsePortMapping(b *testing.B, ports []types.PortMapping) {
|
||||
|
|
|
@ -3,7 +3,7 @@ package generate
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,9 +6,9 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/cgroups"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
"github.com/containers/podman/v3/pkg/util"
|
||||
"github.com/containers/storage"
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
|
|
@ -3,7 +3,7 @@ package specgen
|
|||
import (
|
||||
"net"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
)
|
||||
|
||||
|
|
|
@ -6,8 +6,8 @@ import (
|
|||
"syscall"
|
||||
|
||||
"github.com/containers/common/libimage"
|
||||
nettypes "github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/image/v5/manifest"
|
||||
nettypes "github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/storage/types"
|
||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||
"github.com/pkg/errors"
|
||||
|
|
|
@ -7,8 +7,8 @@ import (
|
|||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/pkg/config"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
storageTypes "github.com/containers/storage/types"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
|
|
@ -177,7 +177,7 @@ t GET libpod/containers/myctr/json 200 \
|
|||
.ResolvConfPath=$userdata_path/resolv.conf \
|
||||
.HostnamePath=$userdata_path/hostname \
|
||||
.HostsPath=$userdata_path/hosts \
|
||||
.NetworkSettings.SandboxKey~.*/netns/cni- \
|
||||
.NetworkSettings.SandboxKey~.*/netns/netns- \
|
||||
.OCIConfigPath~.*config\.json \
|
||||
.GraphDriver.Data.MergedDir~.*merged
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
. "github.com/containers/podman/v3/test/utils"
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
. "github.com/onsi/ginkgo"
|
||||
|
|
|
@ -6,7 +6,7 @@ import (
|
|||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
. "github.com/containers/podman/v3/test/utils"
|
||||
"github.com/containers/storage/pkg/stringid"
|
||||
|
|
|
@ -14,10 +14,10 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/containernetworking/cni/libcni"
|
||||
internalutil "github.com/containers/podman/v3/libpod/network/internal/util"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/network/util"
|
||||
pkgutil "github.com/containers/podman/v3/pkg/util"
|
||||
internalutil "github.com/containers/common/libnetwork/internal/util"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/libnetwork/util"
|
||||
pkgutil "github.com/containers/common/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
@ -76,7 +76,7 @@ func createNetworkFromCNIConfigList(conf *libcni.NetworkConfigList, confPath str
|
|||
network.Options["vlan"] = strconv.Itoa(bridge.Vlan)
|
||||
}
|
||||
|
||||
err = convertIPAMConfToNetwork(&network, bridge.IPAM, confPath)
|
||||
err = convertIPAMConfToNetwork(&network, &bridge.IPAM, confPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ func createNetworkFromCNIConfigList(conf *libcni.NetworkConfigList, confPath str
|
|||
network.Options["mode"] = vlan.Mode
|
||||
}
|
||||
|
||||
err = convertIPAMConfToNetwork(&network, vlan.IPAM, confPath)
|
||||
err = convertIPAMConfToNetwork(&network, &vlan.IPAM, confPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ func findPluginByName(plugins []*libcni.NetworkConfig, name string) bool {
|
|||
|
||||
// convertIPAMConfToNetwork converts A cni IPAMConfig to libpod network subnets.
|
||||
// It returns an array of subnets and an extra bool if dhcp is configured.
|
||||
func convertIPAMConfToNetwork(network *types.Network, ipam ipamConfig, confPath string) error {
|
||||
func convertIPAMConfToNetwork(network *types.Network, ipam *ipamConfig, confPath string) error {
|
||||
if ipam.PluginType == types.DHCPIPAMDriver {
|
||||
network.IPAMOptions["driver"] = types.DHCPIPAMDriver
|
||||
return nil
|
||||
|
@ -256,11 +256,11 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
|
|||
case "mode":
|
||||
switch network.Driver {
|
||||
case types.MacVLANNetworkDriver:
|
||||
if !pkgutil.StringInSlice(v, []string{"", "bridge", "private", "vepa", "passthru"}) {
|
||||
if !pkgutil.StringInSlice(v, types.ValidMacVLANModes) {
|
||||
return nil, "", errors.Errorf("unknown macvlan mode %q", v)
|
||||
}
|
||||
case types.IPVLANNetworkDriver:
|
||||
if !pkgutil.StringInSlice(v, []string{"", "l2", "l3", "l3s"}) {
|
||||
if !pkgutil.StringInSlice(v, types.ValidIPVLANModes) {
|
||||
return nil, "", errors.Errorf("unknown ipvlan mode %q", v)
|
||||
}
|
||||
default:
|
||||
|
@ -288,7 +288,7 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
|
|||
|
||||
switch network.Driver {
|
||||
case types.BridgeNetworkDriver:
|
||||
bridge := newHostLocalBridge(network.NetworkInterface, isGateway, ipMasq, mtu, vlan, ipamConf)
|
||||
bridge := newHostLocalBridge(network.NetworkInterface, isGateway, ipMasq, mtu, vlan, &ipamConf)
|
||||
plugins = append(plugins, bridge, newPortMapPlugin(), newFirewallPlugin(), newTuningPlugin())
|
||||
// if we find the dnsname plugin we add configuration for it
|
||||
if hasDNSNamePlugin(n.cniPluginDirs) && network.DNSEnabled {
|
||||
|
@ -297,10 +297,10 @@ func (n *cniNetwork) createCNIConfigListFromNetwork(network *types.Network, writ
|
|||
}
|
||||
|
||||
case types.MacVLANNetworkDriver:
|
||||
plugins = append(plugins, newVLANPlugin(types.MacVLANNetworkDriver, network.NetworkInterface, vlanPluginMode, mtu, ipamConf))
|
||||
plugins = append(plugins, newVLANPlugin(types.MacVLANNetworkDriver, network.NetworkInterface, vlanPluginMode, mtu, &ipamConf))
|
||||
|
||||
case types.IPVLANNetworkDriver:
|
||||
plugins = append(plugins, newVLANPlugin(types.IPVLANNetworkDriver, network.NetworkInterface, vlanPluginMode, mtu, ipamConf))
|
||||
plugins = append(plugins, newVLANPlugin(types.IPVLANNetworkDriver, network.NetworkInterface, vlanPluginMode, mtu, &ipamConf))
|
||||
|
||||
default:
|
||||
return nil, "", errors.Errorf("driver %q is not supported by cni", network.Driver)
|
|
@ -30,7 +30,7 @@ import (
|
|||
|
||||
"github.com/containernetworking/cni/pkg/invoke"
|
||||
"github.com/containernetworking/cni/pkg/version"
|
||||
"github.com/containers/podman/v3/pkg/rootless"
|
||||
"github.com/containers/storage/pkg/unshare"
|
||||
)
|
||||
|
||||
type cniExec struct {
|
||||
|
@ -75,7 +75,7 @@ func (e *cniExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData [
|
|||
// by conmon and thus not have XDG_RUNTIME_DIR set to same value as podman run.
|
||||
// Because of it dnsname will not find the config files and cannot correctly cleanup.
|
||||
// To fix this we should also unset XDG_RUNTIME_DIR for the cni plugins as rootful.
|
||||
if !rootless.IsRootless() {
|
||||
if !unshare.IsRootless() {
|
||||
c.Env = append(c.Env, "XDG_RUNTIME_DIR=")
|
||||
}
|
||||
|
||||
|
@ -87,7 +87,7 @@ func (e *cniExec) ExecPlugin(ctx context.Context, pluginPath string, stdinData [
|
|||
}
|
||||
|
||||
// annotatePluginError parses the common cni plugin error json.
|
||||
func annotatePluginError(err error, plugin string, stdout []byte, stderr []byte) error {
|
||||
func annotatePluginError(err error, plugin string, stdout, stderr []byte) error {
|
||||
pluginName := filepath.Base(plugin)
|
||||
emsg := cniPluginError{
|
||||
plugin: pluginName,
|
|
@ -7,7 +7,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -133,7 +133,7 @@ func newNcList(name, version string, labels, options map[string]string) ncList {
|
|||
}
|
||||
|
||||
// newHostLocalBridge creates a new LocalBridge for host-local
|
||||
func newHostLocalBridge(name string, isGateWay, ipMasq bool, mtu int, vlan int, ipamConf ipamConfig) *hostLocalBridge {
|
||||
func newHostLocalBridge(name string, isGateWay, ipMasq bool, mtu, vlan int, ipamConf *ipamConfig) *hostLocalBridge {
|
||||
caps := make(map[string]bool)
|
||||
caps["ips"] = true
|
||||
bridge := hostLocalBridge{
|
||||
|
@ -144,7 +144,7 @@ func newHostLocalBridge(name string, isGateWay, ipMasq bool, mtu int, vlan int,
|
|||
MTU: mtu,
|
||||
HairpinMode: true,
|
||||
Vlan: vlan,
|
||||
IPAM: ipamConf,
|
||||
IPAM: *ipamConf,
|
||||
}
|
||||
// if we use host-local set the ips cap to ensure we can set static ips via runtime config
|
||||
if ipamConf.PluginType == types.HostLocalIPAMDriver {
|
||||
|
@ -255,10 +255,10 @@ func hasDNSNamePlugin(paths []string) bool {
|
|||
}
|
||||
|
||||
// newVLANPlugin creates a macvlanconfig with a given device name
|
||||
func newVLANPlugin(pluginType, device, mode string, mtu int, ipam ipamConfig) VLANConfig {
|
||||
func newVLANPlugin(pluginType, device, mode string, mtu int, ipam *ipamConfig) VLANConfig {
|
||||
m := VLANConfig{
|
||||
PluginType: pluginType,
|
||||
IPAM: ipam,
|
||||
IPAM: *ipam,
|
||||
}
|
||||
if mtu > 0 {
|
||||
m.MTU = mtu
|
|
@ -6,10 +6,9 @@ import (
|
|||
"net"
|
||||
"os"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
internalutil "github.com/containers/podman/v3/libpod/network/internal/util"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
pkgutil "github.com/containers/podman/v3/pkg/util"
|
||||
internalutil "github.com/containers/common/libnetwork/internal/util"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
pkgutil "github.com/containers/common/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/vishvananda/netlink"
|
||||
|
@ -17,6 +16,7 @@ import (
|
|||
|
||||
// NetworkCreate will take a partial filled Network and fill the
|
||||
// missing fields. It creates the Network and returns the full Network.
|
||||
// nolint:gocritic
|
||||
func (n *cniNetwork) NetworkCreate(net types.Network) (types.Network, error) {
|
||||
n.lock.Lock()
|
||||
defer n.lock.Unlock()
|
||||
|
@ -24,7 +24,7 @@ func (n *cniNetwork) NetworkCreate(net types.Network) (types.Network, error) {
|
|||
if err != nil {
|
||||
return types.Network{}, err
|
||||
}
|
||||
network, err := n.networkCreate(net, false)
|
||||
network, err := n.networkCreate(&net, false)
|
||||
if err != nil {
|
||||
return types.Network{}, err
|
||||
}
|
||||
|
@ -35,7 +35,7 @@ func (n *cniNetwork) NetworkCreate(net types.Network) (types.Network, error) {
|
|||
|
||||
// networkCreate will fill out the given network struct and return the new network entry.
|
||||
// If defaultNet is true it will not validate against used subnets and it will not write the cni config to disk.
|
||||
func (n *cniNetwork) networkCreate(newNetwork types.Network, defaultNet bool) (*network, error) {
|
||||
func (n *cniNetwork) networkCreate(newNetwork *types.Network, defaultNet bool) (*network, error) {
|
||||
// if no driver is set use the default one
|
||||
if newNetwork.Driver == "" {
|
||||
newNetwork.Driver = types.DefaultNetworkDriver
|
||||
|
@ -44,10 +44,10 @@ func (n *cniNetwork) networkCreate(newNetwork types.Network, defaultNet bool) (*
|
|||
// FIXME: Should we use a different type for network create without the ID field?
|
||||
// the caller is not allowed to set a specific ID
|
||||
if newNetwork.ID != "" {
|
||||
return nil, errors.Wrap(define.ErrInvalidArg, "ID can not be set for network create")
|
||||
return nil, errors.Wrap(types.ErrInvalidArg, "ID can not be set for network create")
|
||||
}
|
||||
|
||||
err := internalutil.CommonNetworkCreate(n, &newNetwork)
|
||||
err := internalutil.CommonNetworkCreate(n, newNetwork)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -69,20 +69,20 @@ func (n *cniNetwork) networkCreate(newNetwork types.Network, defaultNet bool) (*
|
|||
|
||||
switch newNetwork.Driver {
|
||||
case types.BridgeNetworkDriver:
|
||||
err = internalutil.CreateBridge(n, &newNetwork, usedNetworks)
|
||||
err = internalutil.CreateBridge(n, newNetwork, usedNetworks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case types.MacVLANNetworkDriver, types.IPVLANNetworkDriver:
|
||||
err = createIPMACVLAN(&newNetwork)
|
||||
err = createIPMACVLAN(newNetwork)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
default:
|
||||
return nil, errors.Wrapf(define.ErrInvalidArg, "unsupported driver %s", newNetwork.Driver)
|
||||
return nil, errors.Wrapf(types.ErrInvalidArg, "unsupported driver %s", newNetwork.Driver)
|
||||
}
|
||||
|
||||
err = internalutil.ValidateSubnets(&newNetwork, usedNetworks)
|
||||
err = internalutil.ValidateSubnets(newNetwork, usedNetworks)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -96,11 +96,11 @@ func (n *cniNetwork) networkCreate(newNetwork types.Network, defaultNet bool) (*
|
|||
newNetwork.DNSEnabled = false
|
||||
}
|
||||
|
||||
cniConf, path, err := n.createCNIConfigListFromNetwork(&newNetwork, !defaultNet)
|
||||
cniConf, path, err := n.createCNIConfigListFromNetwork(newNetwork, !defaultNet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &network{cniNet: cniConf, libpodNet: &newNetwork, filename: path}, nil
|
||||
return &network{cniNet: cniConf, libpodNet: newNetwork, filename: path}, nil
|
||||
}
|
||||
|
||||
// NetworkRemove will remove the Network with the given name or ID.
|
||||
|
@ -196,7 +196,7 @@ func createIPMACVLAN(network *types.Network) error {
|
|||
return err
|
||||
}
|
||||
if !pkgutil.StringInSlice(network.NetworkInterface, interfaceNames) {
|
||||
return errors.Errorf("parent interface %s does not exists", network.NetworkInterface)
|
||||
return errors.Errorf("parent interface %s does not exist", network.NetworkInterface)
|
||||
}
|
||||
}
|
||||
if len(network.Subnets) == 0 {
|
|
@ -7,12 +7,12 @@ import (
|
|||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/containernetworking/cni/libcni"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/storage/pkg/lockfile"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -64,16 +64,13 @@ type InitConfig struct {
|
|||
|
||||
// IsMachine describes whenever podman runs in a podman machine environment.
|
||||
IsMachine bool
|
||||
|
||||
// LockFile is the path to lock file.
|
||||
LockFile string
|
||||
}
|
||||
|
||||
// NewCNINetworkInterface creates the ContainerNetwork interface for the CNI backend.
|
||||
// Note: The networks are not loaded from disk until a method is called.
|
||||
func NewCNINetworkInterface(conf InitConfig) (types.ContainerNetwork, error) {
|
||||
func NewCNINetworkInterface(conf *InitConfig) (types.ContainerNetwork, error) {
|
||||
// TODO: consider using a shared memory lock
|
||||
lock, err := lockfile.GetLockfile(conf.LockFile)
|
||||
lock, err := lockfile.GetLockfile(filepath.Join(conf.CNIConfigDir, "cni.lock"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -112,6 +109,11 @@ func (n *cniNetwork) Drivers() []string {
|
|||
return []string{types.BridgeNetworkDriver, types.MacVLANNetworkDriver, types.IPVLANNetworkDriver}
|
||||
}
|
||||
|
||||
// DefaultNetworkName will return the default cni network name.
|
||||
func (n *cniNetwork) DefaultNetworkName() string {
|
||||
return n.defaultNetwork
|
||||
}
|
||||
|
||||
func (n *cniNetwork) loadNetworks() error {
|
||||
// check the mod time of the config dir
|
||||
f, err := os.Stat(n.cniConfigDir)
|
||||
|
@ -145,8 +147,8 @@ func (n *cniNetwork) loadNetworks() error {
|
|||
continue
|
||||
}
|
||||
|
||||
if !define.NameRegex.MatchString(conf.Name) {
|
||||
logrus.Warnf("CNI config list %s has invalid name, skipping: %v", file, define.RegexError)
|
||||
if !types.NameRegex.MatchString(conf.Name) {
|
||||
logrus.Warnf("CNI config list %s has invalid name, skipping: %v", file, types.RegexError)
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -204,7 +206,7 @@ func (n *cniNetwork) createDefaultNetwork() (*network, error) {
|
|||
{Subnet: n.defaultSubnet},
|
||||
},
|
||||
}
|
||||
return n.networkCreate(net, true)
|
||||
return n.networkCreate(&net, true)
|
||||
}
|
||||
|
||||
// getNetwork will lookup a network by name or ID. It returns an
|
||||
|
@ -235,7 +237,7 @@ func (n *cniNetwork) getNetwork(nameOrID string) (*network, error) {
|
|||
if net != nil {
|
||||
return net, nil
|
||||
}
|
||||
return nil, errors.Wrapf(define.ErrNoSuchNetwork, "unable to find network with name or ID %s", nameOrID)
|
||||
return nil, errors.Wrapf(types.ErrNoSuchNetwork, "unable to find network with name or ID %s", nameOrID)
|
||||
}
|
||||
|
||||
// getNetworkIDFromName creates a network ID from the name. It is just the
|
15
libpod/network/cni/run.go → vendor/github.com/containers/common/libnetwork/cni/run.go
generated
vendored
15
libpod/network/cni/run.go → vendor/github.com/containers/common/libnetwork/cni/run.go
generated
vendored
|
@ -12,9 +12,8 @@ import (
|
|||
cnitypes "github.com/containernetworking/cni/pkg/types"
|
||||
types040 "github.com/containernetworking/cni/pkg/types/040"
|
||||
"github.com/containernetworking/plugins/pkg/ns"
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/internal/util"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/common/libnetwork/internal/util"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
@ -70,8 +69,9 @@ func (n *cniNetwork) Setup(namespacePath string, options types.SetupOptions) (ma
|
|||
|
||||
results := make(map[string]types.StatusBlock, len(options.Networks))
|
||||
for name, netOpts := range options.Networks {
|
||||
netOpts := netOpts
|
||||
network := n.networks[name]
|
||||
rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, netOpts)
|
||||
rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, &netOpts)
|
||||
|
||||
// If we have more than one static ip we need parse the ips via runtime config,
|
||||
// make sure to add the ips capability to the first plugin otherwise it doesn't get the ips
|
||||
|
@ -158,7 +158,7 @@ func CNIResultToStatus(res cnitypes.Result) (types.StatusBlock, error) {
|
|||
return result, nil
|
||||
}
|
||||
|
||||
func getRuntimeConfig(netns, conName, conID, networkName string, ports []cniPortMapEntry, opts types.PerNetworkOptions) *libcni.RuntimeConf {
|
||||
func getRuntimeConfig(netns, conName, conID, networkName string, ports []cniPortMapEntry, opts *types.PerNetworkOptions) *libcni.RuntimeConf {
|
||||
rt := &libcni.RuntimeConf{
|
||||
ContainerID: conID,
|
||||
NetNS: netns,
|
||||
|
@ -231,7 +231,8 @@ func (n *cniNetwork) teardown(namespacePath string, options types.TeardownOption
|
|||
|
||||
var multiErr *multierror.Error
|
||||
for name, netOpts := range options.Networks {
|
||||
rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, netOpts)
|
||||
netOpts := netOpts
|
||||
rt := getRuntimeConfig(namespacePath, options.ContainerName, options.ContainerID, name, ports, &netOpts)
|
||||
|
||||
cniConfList, newRt, err := getCachedNetworkConfig(n.cniConf, name, rt)
|
||||
if err == nil {
|
||||
|
@ -240,7 +241,7 @@ func (n *cniNetwork) teardown(namespacePath string, options types.TeardownOption
|
|||
logrus.Warnf("Failed to load cached network config: %v, falling back to loading network %s from disk", err, name)
|
||||
network := n.networks[name]
|
||||
if network == nil {
|
||||
multiErr = multierror.Append(multiErr, errors.Wrapf(define.ErrNoSuchNetwork, "network %s", name))
|
||||
multiErr = multierror.Append(multiErr, errors.Wrapf(types.ErrNoSuchNetwork, "network %s", name))
|
||||
continue
|
||||
}
|
||||
cniConfList = network.cniNet
|
|
@ -3,10 +3,9 @@ package util
|
|||
import (
|
||||
"net"
|
||||
|
||||
"github.com/containers/podman/v3/libpod/define"
|
||||
"github.com/containers/podman/v3/libpod/network/types"
|
||||
"github.com/containers/podman/v3/libpod/network/util"
|
||||
pkgutil "github.com/containers/podman/v3/pkg/util"
|
||||
"github.com/containers/common/libnetwork/types"
|
||||
"github.com/containers/common/libnetwork/util"
|
||||
pkgutil "github.com/containers/common/pkg/util"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
|
@ -16,8 +15,8 @@ func CreateBridge(n NetUtil, network *types.Network, usedNetworks []*net.IPNet)
|
|||
if pkgutil.StringInSlice(network.NetworkInterface, bridges) {
|
||||
return errors.Errorf("bridge name %s already in use", network.NetworkInterface)
|
||||
}
|
||||
if !define.NameRegex.MatchString(network.NetworkInterface) {
|
||||
return errors.Wrapf(define.RegexError, "bridge name %s invalid", network.NetworkInterface)
|
||||
if !types.NameRegex.MatchString(network.NetworkInterface) {
|
||||
return errors.Wrapf(types.RegexError, "bridge name %s invalid", network.NetworkInterface)
|
||||
}
|
||||
} else {
|
||||
var err error
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue