summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorzhangguanzhang <zhangguanzhang@qq.com>2020-08-09 22:05:26 +0800
committerMatthew Heon <matthew.heon@pm.me>2020-08-20 12:16:52 -0400
commit09bd563e2bc544aa987e90c5d831f146198eebb5 (patch)
treef551c06e19fbc8e2136bafc43c119fb8b9946633 /pkg
parentc22ea20bf6f12ccf289a48cc185d5159ce7fdaf4 (diff)
downloadpodman-09bd563e2bc544aa987e90c5d831f146198eebb5.tar.gz
podman-09bd563e2bc544aa987e90c5d831f146198eebb5.tar.bz2
podman-09bd563e2bc544aa987e90c5d831f146198eebb5.zip
Add parameter verification for api creation network
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
Diffstat (limited to 'pkg')
-rw-r--r--pkg/network/network.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/pkg/network/network.go b/pkg/network/network.go
index 37f3f721a..4da6bc969 100644
--- a/pkg/network/network.go
+++ b/pkg/network/network.go
@@ -137,6 +137,15 @@ func networkIntersect(n1, n2 *net.IPNet) bool {
// ValidateUserNetworkIsAvailable returns via an error if a network is available
// to be used
func ValidateUserNetworkIsAvailable(config *config.Config, userNet *net.IPNet) error {
+ if len(userNet.IP) == 0 || len(userNet.Mask) == 0 {
+ return errors.Errorf("network %s's ip or mask cannot be empty", userNet.String())
+ }
+
+ ones, bit := userNet.Mask.Size()
+ if ones == 0 || bit == 0 {
+ return errors.Errorf("network %s's mask is invalid", userNet.String())
+ }
+
networks, err := GetNetworksFromFilesystem(config)
if err != nil {
return err