summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorzhangguanzhang <zhangguanzhang@qq.com>2020-08-09 22:05:26 +0800
committerzhangguanzhang <zhangguanzhang@qq.com>2020-08-12 09:38:16 +0800
commitd45bd6e29ab16b9811dfb2e520a49ed7baebda98 (patch)
treeae7b78db3c129ac848f062e8e203cf867ad1bcbb /pkg
parent6d3075a6c79a6e761c183e0d5e6aa239fad21b63 (diff)
downloadpodman-d45bd6e29ab16b9811dfb2e520a49ed7baebda98.tar.gz
podman-d45bd6e29ab16b9811dfb2e520a49ed7baebda98.tar.bz2
podman-d45bd6e29ab16b9811dfb2e520a49ed7baebda98.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 b24c72f5f..db625da56 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