1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

WIP - Fixed CIDR v4 and v6

Signed-off-by: Arnaud Porterie <arnaud.porterie@docker.com>
This commit is contained in:
Arnaud Porterie 2015-02-22 21:32:48 -08:00
parent 796d58af9e
commit 46864de1d7
7 changed files with 50 additions and 36 deletions

View file

@ -14,8 +14,8 @@ const (
type Configuration struct {
BridgeName string
AddressIPv4 *net.IPNet
FixedCIDR string
FixedCIDRv6 string
FixedCIDR *net.IPNet
FixedCIDRv6 *net.IPNet
EnableIPv6 bool
EnableIPTables bool
EnableIPForwarding bool
@ -75,11 +75,11 @@ func Create(config *Configuration) (libnetwork.Network, error) {
// Setup the bridge to allocate containers IPv4 addresses in the
// specified subnet.
{config.FixedCIDR != "", SetupFixedCIDRv4},
{config.FixedCIDR != nil, SetupFixedCIDRv4},
// Setup the bridge to allocate containers global IPv6 addresses in the
// specified subnet.
{config.FixedCIDRv6 != "", SetupFixedCIDRv6},
{config.FixedCIDRv6 != nil, SetupFixedCIDRv6},
// Setup IPTables.
{config.EnableIPTables, SetupIPTables},

View file

@ -30,3 +30,19 @@ func NewInterface(config *Configuration) *Interface {
func (i *Interface) Exists() bool {
return i.Link != nil
}
// Addresses returns a single IPv4 address and all IPv6 addresses for the
// bridge interface.
func (i *Interface) Addresses() (netlink.Addr, []netlink.Addr, error) {
v4addr, err := netlink.AddrList(i.Link, netlink.FAMILY_V4)
if err != nil {
return netlink.Addr{}, nil, err
}
v6addr, err := netlink.AddrList(i.Link, netlink.FAMILY_V6)
if err != nil {
return netlink.Addr{}, nil, err
}
return v4addr[0], v6addr, nil
}

View file

@ -26,14 +26,6 @@ func (b *BridgeSetup) QueueStep(step SetupStep) {
//---------------------------------------------------------------------------//
func SetupFixedCIDRv4(i *Interface) error {
return nil
}
func SetupFixedCIDRv6(i *Interface) error {
return nil
}
func SetupIPTables(i *Interface) error {
return nil
}

View file

@ -0,0 +1,16 @@
package bridge
import (
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/networkdriver/ipallocator"
)
func SetupFixedCIDRv4(i *Interface) error {
addrv4, _, err := i.Addresses()
if err != nil {
return err
}
log.Debugf("Using IPv4 subnet: %v", i.Config.FixedCIDR)
return ipallocator.RegisterSubnet(addrv4.IPNet, i.Config.FixedCIDR)
}

View file

@ -0,0 +1,11 @@
package bridge
import (
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/daemon/networkdriver/ipallocator"
)
func SetupFixedCIDRv6(i *Interface) error {
log.Debugf("Using IPv6 subnet: %v", i.Config.FixedCIDRv6)
return ipallocator.RegisterSubnet(i.Config.FixedCIDRv6, i.Config.FixedCIDRv6)
}

View file

@ -52,7 +52,7 @@ func SetupBridgeIPv4(i *Interface) error {
}
func electBridgeIPv4(config *Configuration) (*net.IPNet, error) {
// Use the requested IPv4 IP and mark when available.
// Use the requested IPv4 CIDR when available.
if config.AddressIPv4 != nil {
return config.AddressIPv4, nil
}
@ -128,7 +128,6 @@ func networkRange(network *net.IPNet) (net.IP, net.IP) {
}
lastIP := make([]byte, len(netIP), len(netIP))
for i := 0; i < len(netIP); i++ {
lastIP[i] = netIP[i] | ^network.Mask[i]
}

View file

@ -1,14 +1,10 @@
package bridge
import (
"fmt"
"github.com/vishvananda/netlink"
)
import "fmt"
func SetupVerifyConfiguredAddresses(i *Interface) error {
// Fetch a single IPv4 and a slice of IPv6 addresses from the bridge.
addrv4, addrsv6, err := getInterfaceAddresses(i.Link)
addrv4, addrsv6, err := i.Addresses()
if err != nil {
return err
}
@ -28,19 +24,3 @@ func SetupVerifyConfiguredAddresses(i *Interface) error {
return fmt.Errorf("Bridge IPv6 addresses do not match the expected bridge configuration %s", BridgeIPv6)
}
func getInterfaceAddresses(iface netlink.Link) (netlink.Addr, []netlink.Addr, error) {
v4addr, err := netlink.AddrList(iface, netlink.FAMILY_V4)
if err != nil {
return netlink.Addr{}, nil, err
}
v6addr, err := netlink.AddrList(iface, netlink.FAMILY_V6)
if err != nil {
return netlink.Addr{}, nil, err
}
// We only return the first IPv4 address, and the complete slice of IPv6
// addresses.
return v4addr[0], v6addr, nil
}