summaryrefslogtreecommitdiff
path: root/libpod/network/netavark/network.go
diff options
context:
space:
mode:
authorPaul Holzinger <pholzing@redhat.com>2021-10-20 15:55:22 +0200
committerPaul Holzinger <pholzing@redhat.com>2021-11-11 16:25:19 +0100
commit4febe557692aeec8ca9d9b9cdc732772ba7d5876 (patch)
tree0d8bd9c4d3809ca099315fb2437ece00690260be /libpod/network/netavark/network.go
parenteaae29462880aa0fb17e8d448cc79519e070e64f (diff)
downloadpodman-4febe557692aeec8ca9d9b9cdc732772ba7d5876.tar.gz
podman-4febe557692aeec8ca9d9b9cdc732772ba7d5876.tar.bz2
podman-4febe557692aeec8ca9d9b9cdc732772ba7d5876.zip
netavark IPAM assignment
Add a new boltdb to handle IPAM assignment. The db structure is the following: Each network has their own bucket with the network name as bucket key. Inside the network bucket there is an ID bucket which maps the container ID (key) to a json array of ip addresses (value). The network bucket also has a bucket for each subnet, the subnet is used as key. Inside the subnet bucket an ip is used as key and the container ID as value. The db should be stored on a tmpfs to ensure we always have a clean state after a reboot. Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/network/netavark/network.go')
-rw-r--r--libpod/network/netavark/network.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/libpod/network/netavark/network.go b/libpod/network/netavark/network.go
index aa7dc8183..cd6db4f58 100644
--- a/libpod/network/netavark/network.go
+++ b/libpod/network/netavark/network.go
@@ -13,6 +13,7 @@ import (
"github.com/containers/podman/v3/libpod/define"
"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"
"github.com/containers/storage/pkg/lockfile"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@@ -30,6 +31,9 @@ type netavarkNetwork struct {
// defaultSubnet is the default subnet for the default network.
defaultSubnet types.IPNet
+ // ipamDBPath is the path to the ip allocation bolt db
+ ipamDBPath string
+
// isMachine describes whenever podman runs in a podman machine environment.
isMachine bool
@@ -50,6 +54,10 @@ type InitConfig struct {
// NetavarkBinary is the path to the netavark binary.
NetavarkBinary string
+ // IPAMDBPath is the path to the ipam database. This should be on a tmpfs.
+ // If empty defaults to XDG_RUNTIME_DIR/netavark/ipam.db or /run/netavark/ipam.db as root.
+ IPAMDBPath string
+
// DefaultNetwork is the name for the default network.
DefaultNetwork string
// DefaultSubnet is the default subnet for the default network.
@@ -85,9 +93,27 @@ func NewNetworkInterface(conf InitConfig) (types.ContainerNetwork, error) {
return nil, errors.Wrap(err, "failed to parse default subnet")
}
+ ipamdbPath := conf.IPAMDBPath
+ if ipamdbPath == "" {
+ runDir, err := pkgutil.GetRuntimeDir()
+ if err != nil {
+ return nil, err
+ }
+ // as root runtimeDir is empty so use /run
+ if runDir == "" {
+ runDir = "/run"
+ }
+ ipamdbPath = filepath.Join(runDir, "netavark")
+ if err := os.MkdirAll(ipamdbPath, 0700); err != nil {
+ return nil, errors.Wrap(err, "failed to create ipam db path")
+ }
+ ipamdbPath = filepath.Join(ipamdbPath, "ipam.db")
+ }
+
n := &netavarkNetwork{
networkConfigDir: conf.NetworkConfigDir,
netavarkBinary: conf.NetavarkBinary,
+ ipamDBPath: ipamdbPath,
defaultNetwork: defaultNetworkName,
defaultSubnet: defaultNet,
isMachine: conf.IsMachine,