@@ -556,12 +556,16 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e
556556 netOption [bridge .DefaultBindingIP ] = config .Bridge .DefaultIP .String ()
557557 }
558558
559- ipamV4Conf := libnetwork.IpamConf {}
559+ var (
560+ ipamV4Conf * libnetwork.IpamConf
561+ ipamV6Conf * libnetwork.IpamConf
562+ )
560563
561- ipamV4Conf . AuxAddresses = make (map [string ]string )
564+ ipamV4Conf = & libnetwork. IpamConf { AuxAddresses : make (map [string ]string )}
562565
563- if nw , _ , err := ipamutils .ElectInterfaceAddresses (bridgeName ); err == nil {
564- ipamV4Conf .PreferredPool = nw .String ()
566+ nw , nw6List , err := ipamutils .ElectInterfaceAddresses (bridgeName )
567+ if err == nil {
568+ ipamV4Conf .PreferredPool = types .GetIPNetCanonical (nw ).String ()
565569 hip , _ := types .GetHostPartIP (nw .IP , nw .Mask )
566570 if hip .IsGlobalUnicast () {
567571 ipamV4Conf .Gateway = nw .IP .String ()
@@ -592,10 +596,7 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e
592596 ipamV4Conf .AuxAddresses ["DefaultGatewayIPv4" ] = config .Bridge .DefaultGatewayIPv4 .String ()
593597 }
594598
595- var (
596- ipamV6Conf * libnetwork.IpamConf
597- deferIPv6Alloc bool
598- )
599+ var deferIPv6Alloc bool
599600 if config .Bridge .FixedCIDRv6 != "" {
600601 _ , fCIDRv6 , err := net .ParseCIDR (config .Bridge .FixedCIDRv6 )
601602 if err != nil {
@@ -615,6 +616,16 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e
615616 ipamV6Conf = & libnetwork.IpamConf {AuxAddresses : make (map [string ]string )}
616617 }
617618 ipamV6Conf .PreferredPool = fCIDRv6 .String ()
619+
620+ // In case the --fixed-cidr-v6 is specified and the current docker0 bridge IPv6
621+ // address belongs to the same network, we need to inform libnetwork about it, so
622+ // that it can be reserved with IPAM and it will not be given away to somebody else
623+ for _ , nw6 := range nw6List {
624+ if fCIDRv6 .Contains (nw6 .IP ) {
625+ ipamV6Conf .Gateway = nw6 .IP .String ()
626+ break
627+ }
628+ }
618629 }
619630
620631 if config .Bridge .DefaultGatewayIPv6 != nil {
@@ -624,13 +635,13 @@ func initBridgeDriver(controller libnetwork.NetworkController, config *Config) e
624635 ipamV6Conf .AuxAddresses ["DefaultGatewayIPv6" ] = config .Bridge .DefaultGatewayIPv6 .String ()
625636 }
626637
627- v4Conf := []* libnetwork.IpamConf {& ipamV4Conf }
638+ v4Conf := []* libnetwork.IpamConf {ipamV4Conf }
628639 v6Conf := []* libnetwork.IpamConf {}
629640 if ipamV6Conf != nil {
630641 v6Conf = append (v6Conf , ipamV6Conf )
631642 }
632643 // Initialize default network on "bridge" with the same name
633- _ , err : = controller .NewNetwork ("bridge" , "bridge" ,
644+ _ , err = controller .NewNetwork ("bridge" , "bridge" ,
634645 libnetwork .NetworkOptionGeneric (options.Generic {
635646 netlabel .GenericData : netOption ,
636647 netlabel .EnableIPv6 : config .Bridge .EnableIPv6 ,
0 commit comments