Skip to content

Commit fc702eb

Browse files
committed
Fixed IP information not displayed properly in docker network inspect
Signed-off-by: msabansal <sabansal@microsoft.com>
1 parent 080bedd commit fc702eb

4 files changed

Lines changed: 20 additions & 7 deletions

File tree

drivers/windows/windows.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,11 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Dat
186186

187187
for _, ipData := range ipV4Data {
188188
subnet := hcsshim.Subnet{
189-
AddressPrefix: ipData.Pool.String(),
190-
GatewayAddress: ipData.Gateway.IP.String(),
189+
AddressPrefix: ipData.Pool.String(),
190+
}
191+
192+
if ipData.Gateway != nil {
193+
subnet.GatewayAddress = ipData.Gateway.IP.String()
191194
}
192195

193196
subnets = append(subnets, subnet)

endpoint.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -957,9 +957,13 @@ func (ep *endpoint) releaseAddress() {
957957
log.Warnf("Failed to retrieve ipam driver to release interface address on delete of endpoint %s (%s): %v", ep.Name(), ep.ID(), err)
958958
return
959959
}
960-
if err := ipam.ReleaseAddress(ep.iface.v4PoolID, ep.iface.addr.IP); err != nil {
961-
log.Warnf("Failed to release ip address %s on delete of endpoint %s (%s): %v", ep.iface.addr.IP, ep.Name(), ep.ID(), err)
960+
961+
if ep.iface.addr != nil {
962+
if err := ipam.ReleaseAddress(ep.iface.v4PoolID, ep.iface.addr.IP); err != nil {
963+
log.Warnf("Failed to release ip address %s on delete of endpoint %s (%s): %v", ep.iface.addr.IP, ep.Name(), ep.ID(), err)
964+
}
962965
}
966+
963967
if ep.iface.addrv6 != nil && ep.iface.addrv6.IP.IsGlobalUnicast() {
964968
if err := ipam.ReleaseAddress(ep.iface.v6PoolID, ep.iface.addrv6.IP); err != nil {
965969
log.Warnf("Failed to release ip address %s on delete of endpoint %s (%s): %v", ep.iface.addrv6.IP, ep.Name(), ep.ID(), err)

ipams/windowsipam/windowsipam.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
log "github.com/Sirupsen/logrus"
77
"github.com/docker/libnetwork/discoverapi"
88
"github.com/docker/libnetwork/ipamapi"
9+
"github.com/docker/libnetwork/netlabel"
910
"github.com/docker/libnetwork/types"
1011
)
1112

@@ -64,14 +65,19 @@ func (a *allocator) ReleasePool(poolID string) error {
6465
// RequestAddress returns an address from the specified pool ID.
6566
// Always allocate the 0.0.0.0/32 ip if no preferred address was specified
6667
func (a *allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) {
67-
log.Debugf("RequestAddress(%s, %v, %v) %s", poolID, prefAddress, opts, opts["RequestAddressType"])
68+
log.Debugf("RequestAddress(%s, %v, %v)", poolID, prefAddress, opts)
6869
_, ipNet, err := net.ParseCIDR(poolID)
6970

7071
if err != nil {
7172
return nil, nil, err
7273
}
73-
if prefAddress == nil {
74+
75+
// TODO Windows: Remove this once the bug in docker daemon is fixed
76+
// that causes it to throw an exception on nil gateway
77+
if opts[ipamapi.RequestAddressType] == netlabel.Gateway {
7478
return ipNet, nil, nil
79+
} else if prefAddress == nil {
80+
return nil, nil, nil
7581
}
7682
return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil
7783
}

ipams/windowsipam/windowsipam_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestWindowsIPAM(t *testing.T) {
5151
t.Fatal(err)
5252
}
5353

54-
if !types.CompareIPNet(ip, requestPool) {
54+
if ip != nil {
5555
t.Fatalf("Unexpected data returned. Expected %v . Got: %v ", requestPool, ip)
5656
}
5757

0 commit comments

Comments
 (0)