Skip to content

Commit 729a86d

Browse files
committed
add user-mode networking option on hyperv
it adds a flag to enable user-mode networking on hyperv. While on other OS/hypervisor user-mode is always enabled, on WSL podman code supports both cases. For this reason, it adds a constraint check on Win to prevent users from using the user-mode-networking flag when the provider is not hyperv Signed-off-by: lstocchi <[email protected]>
1 parent 30dedee commit 729a86d

File tree

13 files changed

+341
-91
lines changed

13 files changed

+341
-91
lines changed

cmd/macadam/init.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ var (
3232
ValidArgsFunction: completion.AutocompleteNone,
3333
}
3434

35-
initOptsFromFlags = define.InitOptions{}
36-
// initOptionalFlags = InitOptionalFlags{}
35+
initOptsFromFlags = define.InitOptions{}
36+
initOptionalFlags = InitOptionalFlags{}
3737
defaultMachineName = "macadam"
3838
// now bool
3939
)
@@ -82,6 +82,10 @@ func init() {
8282
flags.StringSliceVarP(&initOptsFromFlags.CloudInitPaths, CloudInitPathFlagName, "", []string{}, "Path to user-data, meta-data and network-config cloud-init configuration files")
8383
_ = initCmd.RegisterFlagCompletionFunc(CloudInitPathFlagName, completion.AutocompleteDefault)
8484

85+
userModeNetFlagName := "user-mode-networking"
86+
flags.BoolVar(&initOptionalFlags.UserModeNetworking, userModeNetFlagName, false,
87+
"Whether this machine should use user-mode networking, routing traffic through a host user-space process (Hyperv-only, requires --provider=hyperv)")
88+
8589
/* flags := initCmd.Flags()
8690
cfg := registry.PodmanConfig()
8791
@@ -142,11 +146,7 @@ func init() {
142146
_ = initCmd.RegisterFlagCompletionFunc(IgnitionPathFlagName, completion.AutocompleteDefault)
143147
144148
rootfulFlagName := "rootful"
145-
flags.BoolVar(&initOpts.Rootful, rootfulFlagName, false, "Whether this machine should prefer rootful container execution")
146-
147-
userModeNetFlagName := "user-mode-networking"
148-
flags.BoolVar(&initOptionalFlags.UserModeNetworking, userModeNetFlagName, false,
149-
"Whether this machine should use user-mode networking, routing traffic through a host user-space process") */
149+
flags.BoolVar(&initOpts.Rootful, rootfulFlagName, false, "Whether this machine should prefer rootful container execution") */
150150
}
151151

152152
func initMachine(cmd *cobra.Command, args []string) error {
@@ -155,7 +155,7 @@ func initMachine(cmd *cobra.Command, args []string) error {
155155
return err
156156
}
157157

158-
if err := preflights.RunPreflights(vmProvider); err != nil {
158+
if err := preflights.RunPreflights(vmProvider, initOptionalFlags.UserModeNetworking); err != nil {
159159
slog.Error(err.Error())
160160
os.Exit(1)
161161
}
@@ -215,6 +215,7 @@ func initMachine(cmd *cobra.Command, args []string) error {
215215
HasReadyUnit: false,
216216
ForwardSockets: false,
217217
}
218+
initOpts.UserModeNetworking = &initOptionalFlags.UserModeNetworking
218219
/*
219220
_, _, err = shim.VMExists(machineName, []vmconfigs.VMProvider{provider})
220221
if err == nil {

cmd/macadam/preflight.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ func preflight(_ *cobra.Command, args []string) error {
2929
if err != nil {
3030
return err
3131
}
32-
return preflights.RunPreflights(vmProvider)
32+
return preflights.RunPreflights(vmProvider, false)
3333
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,6 @@ require (
191191
tags.cncf.io/container-device-interface/specs-go v1.0.0 // indirect
192192
)
193193

194-
replace github.com/containers/podman/v5 => github.com/cfergeau/podman/v5 v5.0.0-20250924155458-168a7bca9bee
194+
replace github.com/containers/podman/v5 => github.com/cfergeau/podman/v5 v5.0.0-20251015161310-92f0af92dc3e
195195

196196
replace github.com/crc-org/machine => github.com/cfergeau/machine v0.0.0-20241127155529-1b8b9b8d1078

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UF
3333
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
3434
github.com/cfergeau/machine v0.0.0-20241127155529-1b8b9b8d1078 h1:KpgRncgq6ZiWDnLe6R58dJjd6QSuU7RDqRrpl11Dxcg=
3535
github.com/cfergeau/machine v0.0.0-20241127155529-1b8b9b8d1078/go.mod h1:trWeQimjfE3dJ8qWOxI4ePtYm13aecK42bf01s6h/Nc=
36-
github.com/cfergeau/podman/v5 v5.0.0-20250924155458-168a7bca9bee h1:FZnjrAe2f40Y+lbGTzs48fwPI5q3zM4PyiTOlVLLtMM=
37-
github.com/cfergeau/podman/v5 v5.0.0-20250924155458-168a7bca9bee/go.mod h1:/M4sKOScoXIFFAfLURDYibSSBDcx67Q+Mi9tdT5guV0=
36+
github.com/cfergeau/podman/v5 v5.0.0-20251015161310-92f0af92dc3e h1:CVsF1j6brKiUWio1eN2lZ+75sZWoUX15eCogz0vkr04=
37+
github.com/cfergeau/podman/v5 v5.0.0-20251015161310-92f0af92dc3e/go.mod h1:/M4sKOScoXIFFAfLURDYibSSBDcx67Q+Mi9tdT5guV0=
3838
github.com/checkpoint-restore/checkpointctl v1.3.0 h1:bNz5b6s+lxFdG5ZGDba3qSkBtXDDTCG2494dfAbQJ4E=
3939
github.com/checkpoint-restore/checkpointctl v1.3.0/go.mod h1:dqZH4wDvbjnsqFGK2LdUDk21yFQ1dCAtzgRMlG44KDM=
4040
github.com/checkpoint-restore/go-criu/v7 v7.2.0 h1:qGiWA4App1gGlEfIJ68WR9jbezV9J7yZdjzglezcqKo=

pkg/preflights/preflights.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ import (
1212
"github.com/containers/podman/v5/pkg/machine/vmconfigs"
1313
)
1414

15-
func RunPreflights(provider vmconfigs.VMProvider) error {
16-
if err := checkGvproxyVersion(provider); err != nil {
15+
func RunPreflights(provider vmconfigs.VMProvider, userModeNetworking bool) error {
16+
if err := validateOptions(provider, userModeNetworking); err != nil {
17+
return err
18+
}
19+
20+
if err := checkGvproxyVersion(provider, userModeNetworking); err != nil {
1721
return fmt.Errorf("invalid gvproxy binary: %w", err)
1822
}
1923

@@ -28,10 +32,17 @@ func RunPreflights(provider vmconfigs.VMProvider) error {
2832
return nil
2933
}
3034

35+
func validateOptions(provider vmconfigs.VMProvider, userModeNetworking bool) error {
36+
if provider.VMType() == define.WSLVirt && userModeNetworking {
37+
return fmt.Errorf("user-mode networking is not supported on WSL. Please run the command without the --user-mode-networking flag")
38+
}
39+
return nil
40+
}
41+
3142
// macadam/podman needs a gvproxy version which supports the --services
3243
// argument
33-
func checkGvproxyVersion(provider vmconfigs.VMProvider) error {
34-
if provider.VMType() == define.WSLVirt || provider.VMType() == define.HyperVVirt {
44+
func checkGvproxyVersion(provider vmconfigs.VMProvider, userModeNetworking bool) error {
45+
if provider.VMType() == define.WSLVirt || (provider.VMType() == define.HyperVVirt && !userModeNetworking) {
3546
return nil
3647
}
3748
if err := checkBinaryArg(machine.ForwarderBinaryName, "-services"); err != nil {

vendor/github.com/containers/podman/v5/pkg/domain/infra/abi/play_linux.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/podman/v5/pkg/domain/infra/abi/play_unsupported.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/podman/v5/pkg/machine/cloudinit/cloudinit.go

Lines changed: 24 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containers/podman/v5/pkg/machine/cloudinit/cloudinit_unix.go

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)