mirror of
https://github.com/podman-container-tools/podman.git
synced 2026-09-03 22:27:52 +00:00
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>
69 lines
1.9 KiB
Go
69 lines
1.9 KiB
Go
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/pkg/errors"
|
|
)
|
|
|
|
func CreateBridge(n NetUtil, network *types.Network, usedNetworks []*net.IPNet) error {
|
|
if network.NetworkInterface != "" {
|
|
bridges := GetBridgeInterfaceNames(n)
|
|
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)
|
|
}
|
|
} else {
|
|
var err error
|
|
network.NetworkInterface, err = GetFreeDeviceName(n)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if network.IPAMOptions["driver"] != types.DHCPIPAMDriver {
|
|
if len(network.Subnets) == 0 {
|
|
freeSubnet, err := GetFreeIPv4NetworkSubnet(usedNetworks)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
network.Subnets = append(network.Subnets, *freeSubnet)
|
|
}
|
|
// ipv6 enabled means dual stack, check if we already have
|
|
// a ipv4 or ipv6 subnet and add one if not.
|
|
if network.IPv6Enabled {
|
|
ipv4 := false
|
|
ipv6 := false
|
|
for _, subnet := range network.Subnets {
|
|
if util.IsIPv6(subnet.Subnet.IP) {
|
|
ipv6 = true
|
|
}
|
|
if util.IsIPv4(subnet.Subnet.IP) {
|
|
ipv4 = true
|
|
}
|
|
}
|
|
if !ipv4 {
|
|
freeSubnet, err := GetFreeIPv4NetworkSubnet(usedNetworks)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
network.Subnets = append(network.Subnets, *freeSubnet)
|
|
}
|
|
if !ipv6 {
|
|
freeSubnet, err := GetFreeIPv6NetworkSubnet(usedNetworks)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
network.Subnets = append(network.Subnets, *freeSubnet)
|
|
}
|
|
}
|
|
network.IPAMOptions["driver"] = types.HostLocalIPAMDriver
|
|
}
|
|
return nil
|
|
}
|