Skip to content

Commit

Permalink
Validate that the bridge option is supported
Browse files Browse the repository at this point in the history
Thanks Luap99 for the validation suggestion

Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Dec 1, 2020
1 parent de2b15f commit db70e91
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
26 changes: 19 additions & 7 deletions libpod/network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,26 @@ func createBridge(name string, options entities.NetworkCreateOptions, runtimeCon
ipMasq = false
}

mtu, err := parseMTU(options.Options["mtu"])
if err != nil {
return "", err
}
var mtu int
var vlan int
for k, v := range options.Options {
var err error
switch k {
case "mtu":
mtu, err = parseMTU(v)
if err != nil {
return "", err
}

vlan, err := parseVlan(options.Options["vlan"])
if err != nil {
return "", err
case "vlan":
vlan, err = parseVlan(v)
if err != nil {
return "", err
}

default:
return "", errors.Errorf("unsupported option %s", k)
}
}

// obtain host bridge name
Expand Down
7 changes: 7 additions & 0 deletions test/e2e/network_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,4 +355,11 @@ var _ = Describe("Podman network create", func() {
Expect(nc.OutputToString()).To(ContainSubstring(`"vlan": 9`))
})

It("podman network create with invalid option", func() {
net := "invalid-test"
nc := podmanTest.Podman([]string{"network", "create", "--opt", "foo=bar", net})
nc.WaitWithDefaultTimeout()
Expect(nc).To(ExitWithError())
})

})

0 comments on commit db70e91

Please sign in to comment.