Signed-off-by: Chun Chen <ramichen@tencent.com>
@@ -543,6 +543,9 @@ func (d *driver) getNetworks() []*bridgeNetwork {
// Create a new network using bridge plugin
func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Data, ipV6Data []driverapi.IPAMData) error {
+ if len(ipV4Data) == 0 || ipV4Data[0].Pool.String() == "0.0.0.0/0" {
+ return types.BadRequestErrorf("ipv4 pool is empty")
+ }
// Sanity checks
d.Lock()
if _, ok := d.networks[id]; ok {
@@ -63,6 +63,9 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, ipV4Dat
if id == "" {
return fmt.Errorf("invalid network id")
}
// Since we perform lazy configuration make sure we try
// configuring the driver when we enter CreateNetwork
@@ -2356,3 +2356,10 @@ func TestParallel2(t *testing.T) {
func TestParallel3(t *testing.T) {
runParallelTests(t, 3)
+
+func TestNullIpam(t *testing.T) {
+ _, err := controller.NewNetwork(bridgeNetType, "testnetworkinternal", libnetwork.NetworkOptionIpam(ipamapi.NullIPAM, "", nil, nil, nil))
+ if err == nil || err.Error() != "ipv4 pool is empty" {
+ t.Fatal("bridge network should complain empty pool")
+}