Skip to content

Commit

Permalink
Fix custom mac address with a custom cni network
Browse files Browse the repository at this point in the history
The cni plugin `tuning` is required to set a custom mac address.
This plugin is configured in the default cni config file which is
packaged with podman but was not included the generated config form
`podman network create`.

Fixes containers#8385

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Paul Holzinger committed Nov 24, 2020
1 parent cd6c4cb commit 9602e29
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libpod/network/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ func (f FirewallConfig) Bytes() ([]byte, error) {
return json.MarshalIndent(f, "", "\t")
}

// TuningConfig describes the tuning plugin
type TuningConfig struct {
PluginType string `json:"type"`
}

// Bytes outputs the configuration as []byte
func (f TuningConfig) Bytes() ([]byte, error) {
return json.MarshalIndent(f, "", "\t")
}

// DNSNameConfig describes the dns container name resolution plugin config
type DNSNameConfig struct {
PluginType string `json:"type"`
Expand Down
1 change: 1 addition & 0 deletions libpod/network/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func createBridge(name string, options entities.NetworkCreateOptions, runtimeCon
plugins = append(plugins, bridge)
plugins = append(plugins, NewPortMapPlugin())
plugins = append(plugins, NewFirewallPlugin())
plugins = append(plugins, NewTuningPlugin())
// if we find the dnsname plugin or are rootless, we add configuration for it
// the rootless-cni-infra container has the dnsname plugin always installed
if (HasDNSNamePlugin(runtimeConfig.Network.CNIPluginDirs) || rootless.IsRootless()) && !options.DisableDNS {
Expand Down
7 changes: 7 additions & 0 deletions libpod/network/netconflist.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ func NewFirewallPlugin() FirewallConfig {
}
}

// NewTuningPlugin creates a generic tuning section
func NewTuningPlugin() TuningConfig {
return TuningConfig{
PluginType: "tuning",
}
}

// NewDNSNamePlugin creates the dnsname config with a given
// domainname
func NewDNSNamePlugin(domainName string) DNSNameConfig {
Expand Down
18 changes: 18 additions & 0 deletions test/e2e/create_staticmac_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/containers/podman/v2/pkg/rootless"
. "github.com/containers/podman/v2/test/utils"
"github.com/containers/storage/pkg/stringid"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -45,4 +46,21 @@ var _ = Describe("Podman run with --mac-address flag", func() {
Expect(result.OutputToString()).To(ContainSubstring("92:d0:c6:0a:29:34"))
}
})

It("Podman run --mac-address with custom network", func() {
net := "n1" + stringid.GenerateNonCryptoID()
session := podmanTest.Podman([]string{"network", "create", net})
session.WaitWithDefaultTimeout()
defer podmanTest.removeCNINetwork(net)
Expect(session.ExitCode()).To(BeZero())

result := podmanTest.Podman([]string{"run", "--network", net, "--mac-address", "92:d0:c6:00:29:34", ALPINE, "ip", "addr"})
result.WaitWithDefaultTimeout()
if rootless.IsRootless() {
Expect(result.ExitCode()).To(Equal(125))
} else {
Expect(result.ExitCode()).To(Equal(0))
Expect(result.OutputToString()).To(ContainSubstring("92:d0:c6:00:29:34"))
}
})
})

0 comments on commit 9602e29

Please sign in to comment.