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:
parent
796d58af9e
commit
46864de1d7
7 changed files with 50 additions and 36 deletions
|
@ -14,8 +14,8 @@ const (
|
||||||
type Configuration struct {
|
type Configuration struct {
|
||||||
BridgeName string
|
BridgeName string
|
||||||
AddressIPv4 *net.IPNet
|
AddressIPv4 *net.IPNet
|
||||||
FixedCIDR string
|
FixedCIDR *net.IPNet
|
||||||
FixedCIDRv6 string
|
FixedCIDRv6 *net.IPNet
|
||||||
EnableIPv6 bool
|
EnableIPv6 bool
|
||||||
EnableIPTables bool
|
EnableIPTables bool
|
||||||
EnableIPForwarding bool
|
EnableIPForwarding bool
|
||||||
|
@ -75,11 +75,11 @@ func Create(config *Configuration) (libnetwork.Network, error) {
|
||||||
|
|
||||||
// Setup the bridge to allocate containers IPv4 addresses in the
|
// Setup the bridge to allocate containers IPv4 addresses in the
|
||||||
// specified subnet.
|
// specified subnet.
|
||||||
{config.FixedCIDR != "", SetupFixedCIDRv4},
|
{config.FixedCIDR != nil, SetupFixedCIDRv4},
|
||||||
|
|
||||||
// Setup the bridge to allocate containers global IPv6 addresses in the
|
// Setup the bridge to allocate containers global IPv6 addresses in the
|
||||||
// specified subnet.
|
// specified subnet.
|
||||||
{config.FixedCIDRv6 != "", SetupFixedCIDRv6},
|
{config.FixedCIDRv6 != nil, SetupFixedCIDRv6},
|
||||||
|
|
||||||
// Setup IPTables.
|
// Setup IPTables.
|
||||||
{config.EnableIPTables, SetupIPTables},
|
{config.EnableIPTables, SetupIPTables},
|
||||||
|
|
|
@ -30,3 +30,19 @@ func NewInterface(config *Configuration) *Interface {
|
||||||
func (i *Interface) Exists() bool {
|
func (i *Interface) Exists() bool {
|
||||||
return i.Link != nil
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -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 {
|
func SetupIPTables(i *Interface) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
16
libnetwork/bridge/setup_fixedcidrv4.go
Normal file
16
libnetwork/bridge/setup_fixedcidrv4.go
Normal 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)
|
||||||
|
}
|
11
libnetwork/bridge/setup_fixedcidrv6.go
Normal file
11
libnetwork/bridge/setup_fixedcidrv6.go
Normal 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)
|
||||||
|
}
|
|
@ -52,7 +52,7 @@ func SetupBridgeIPv4(i *Interface) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func electBridgeIPv4(config *Configuration) (*net.IPNet, 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 {
|
if config.AddressIPv4 != nil {
|
||||||
return 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))
|
lastIP := make([]byte, len(netIP), len(netIP))
|
||||||
|
|
||||||
for i := 0; i < len(netIP); i++ {
|
for i := 0; i < len(netIP); i++ {
|
||||||
lastIP[i] = netIP[i] | ^network.Mask[i]
|
lastIP[i] = netIP[i] | ^network.Mask[i]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
package bridge
|
package bridge
|
||||||
|
|
||||||
import (
|
import "fmt"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/vishvananda/netlink"
|
|
||||||
)
|
|
||||||
|
|
||||||
func SetupVerifyConfiguredAddresses(i *Interface) error {
|
func SetupVerifyConfiguredAddresses(i *Interface) error {
|
||||||
// Fetch a single IPv4 and a slice of IPv6 addresses from the bridge.
|
// 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 {
|
if err != nil {
|
||||||
return err
|
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)
|
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
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue