diff --git a/cmd/packer-sdc/internal/renderdocs/docs-partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx b/cmd/packer-sdc/internal/renderdocs/docs-partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx index 83f8a4c20..adfff7435 100644 --- a/cmd/packer-sdc/internal/renderdocs/docs-partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx +++ b/cmd/packer-sdc/internal/renderdocs/docs-partials/packer-plugin-sdk/multistep/commonsteps/HTTPConfig-not-required.mdx @@ -34,4 +34,6 @@ - `http_bind_address` (string) - This is the bind address for the HTTP server. Defaults to 0.0.0.0 so that it will work with any network interface. +- `http_only_ipv4` (bool) - If true the HTTP server will only be bound to an IPv4 interface + diff --git a/multistep/commonsteps/http_config.go b/multistep/commonsteps/http_config.go index c5577f370..b84c14ef8 100644 --- a/multistep/commonsteps/http_config.go +++ b/multistep/commonsteps/http_config.go @@ -58,6 +58,8 @@ type HTTPConfig struct { // interface with a non-loopback address. Either `http_bind_address` or // `http_interface` can be specified. HTTPInterface string `mapstructure:"http_interface" undocumented:"true"` + // If true the HTTP server will only be bound to an IPv4 interface + HTTPOnlyIPv4 bool `mapstructure:"http_only_ipv4"` } func (c *HTTPConfig) Prepare(ctx *interpolate.Context) []error { diff --git a/multistep/commonsteps/step_http_server.go b/multistep/commonsteps/step_http_server.go index 43462aac6..78e12cff6 100644 --- a/multistep/commonsteps/step_http_server.go +++ b/multistep/commonsteps/step_http_server.go @@ -20,11 +20,12 @@ import ( func HTTPServerFromHTTPConfig(cfg *HTTPConfig) *StepHTTPServer { return &StepHTTPServer{ - HTTPDir: cfg.HTTPDir, - HTTPContent: cfg.HTTPContent, - HTTPPortMin: cfg.HTTPPortMin, - HTTPPortMax: cfg.HTTPPortMax, - HTTPAddress: cfg.HTTPAddress, + HTTPDir: cfg.HTTPDir, + HTTPContent: cfg.HTTPContent, + HTTPPortMin: cfg.HTTPPortMin, + HTTPPortMax: cfg.HTTPPortMax, + HTTPAddress: cfg.HTTPAddress, + HTTPOnlyIPv4: cfg.HTTPOnlyIPv4, } } @@ -40,11 +41,12 @@ func HTTPServerFromHTTPConfig(cfg *HTTPConfig) *StepHTTPServer { // // http_port int - The port the HTTP server started on. type StepHTTPServer struct { - HTTPDir string - HTTPContent map[string]string - HTTPPortMin int - HTTPPortMax int - HTTPAddress string + HTTPDir string + HTTPContent map[string]string + HTTPPortMin int + HTTPPortMax int + HTTPAddress string + HTTPOnlyIPv4 bool l *net.Listener } @@ -102,11 +104,15 @@ func (s *StepHTTPServer) Run(ctx context.Context, state multistep.StateBag) mult // Find an available TCP port for our HTTP server var err error + network := "tcp" + if s.HTTPOnlyIPv4 { + network = "tcp4" + } s.l, err = net.ListenRangeConfig{ Min: s.HTTPPortMin, Max: s.HTTPPortMax, Addr: s.HTTPAddress, - Network: "tcp", + Network: network, }.Listen(ctx) if err != nil {