Skip to content

Commit 4b9dc64

Browse files
committed
Honor enableIPv6 network flag on IP allocation
- If the flag is not set, do not query IPAM driver for IPv6 pool/addresses even if they are passed Signed-off-by: Alessandro Boch <[email protected]>
1 parent dfc83a6 commit 4b9dc64

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

libnetwork/network.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ func (n *network) UnmarshalJSON(b []byte) (err error) {
469469
if v, ok := netMap["inDelete"]; ok {
470470
n.inDelete = v.(bool)
471471
}
472+
// Reconcile old networks with the recently added `--ipv6` flag
473+
if !n.enableIPv6 {
474+
n.enableIPv6 = len(n.ipamV6Info) > 0
475+
}
472476
return nil
473477
}
474478

@@ -752,7 +756,7 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
752756
ep.ipamOptions[netlabel.MacAddress] = ep.iface.mac.String()
753757
}
754758

755-
if err = ep.assignAddress(ipam.driver, true, !n.postIPv6); err != nil {
759+
if err = ep.assignAddress(ipam.driver, true, n.enableIPv6 && !n.postIPv6); err != nil {
756760
return nil, err
757761
}
758762
defer func() {
@@ -772,7 +776,7 @@ func (n *network) CreateEndpoint(name string, options ...EndpointOption) (Endpoi
772776
}
773777
}()
774778

775-
if err = ep.assignAddress(ipam.driver, false, n.postIPv6); err != nil {
779+
if err = ep.assignAddress(ipam.driver, false, n.enableIPv6 && n.postIPv6); err != nil {
776780
return nil, err
777781
}
778782

@@ -1006,6 +1010,10 @@ func (n *network) ipamAllocate() error {
10061010
}
10071011
}()
10081012

1013+
if !n.enableIPv6 {
1014+
return nil
1015+
}
1016+
10091017
return n.ipamAllocateVersion(6, ipam)
10101018
}
10111019

@@ -1126,7 +1134,7 @@ func (n *network) ipamReleaseVersion(ipVer int, ipam ipamapi.Ipam) {
11261134
return
11271135
}
11281136

1129-
if *infoList == nil {
1137+
if len(*infoList) == 0 {
11301138
return
11311139
}
11321140

0 commit comments

Comments
 (0)