aboutsummaryrefslogtreecommitdiff
path: root/libpod/network/internal/util/parse.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2021-11-11 19:12:43 +0100
committerGitHub <noreply@github.com>2021-11-11 19:12:43 +0100
commit375ff223f430301edf25ef5a5f03a1ae1e029bef (patch)
tree96993f98fa27d39a93589a93179e7c914746b876 /libpod/network/internal/util/parse.go
parentd5b411c484f9e45c71ad3552b796bd3343ec7a0c (diff)
parent3af19917a1666fc3f29d98f7f0b937eb488f706c (diff)
downloadpodman-375ff223f430301edf25ef5a5f03a1ae1e029bef.tar.gz
podman-375ff223f430301edf25ef5a5f03a1ae1e029bef.tar.bz2
podman-375ff223f430301edf25ef5a5f03a1ae1e029bef.zip
Merge pull request #12131 from Luap99/netavark-interface
Netavark interface
Diffstat (limited to 'libpod/network/internal/util/parse.go')
-rw-r--r--libpod/network/internal/util/parse.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/libpod/network/internal/util/parse.go b/libpod/network/internal/util/parse.go
new file mode 100644
index 000000000..1f68df0bb
--- /dev/null
+++ b/libpod/network/internal/util/parse.go
@@ -0,0 +1,37 @@
+package util
+
+import (
+ "strconv"
+
+ "github.com/pkg/errors"
+)
+
+// ParseMTU parses the mtu option
+func ParseMTU(mtu string) (int, error) {
+ if mtu == "" {
+ return 0, nil // default
+ }
+ m, err := strconv.Atoi(mtu)
+ if err != nil {
+ return 0, err
+ }
+ if m < 0 {
+ return 0, errors.Errorf("mtu %d is less than zero", m)
+ }
+ return m, nil
+}
+
+// ParseVlan parses the vlan option
+func ParseVlan(vlan string) (int, error) {
+ if vlan == "" {
+ return 0, nil // default
+ }
+ v, err := strconv.Atoi(vlan)
+ if err != nil {
+ return 0, err
+ }
+ if v < 0 || v > 4094 {
+ return 0, errors.Errorf("vlan ID %d must be between 0 and 4094", v)
+ }
+ return v, nil
+}