diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index f60eb4b04..336ee0c47 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -156,6 +156,7 @@ module VagrantPlugins # @param [Hash] options Options for the network. def network(type, options=nil) options ||= {} + options[:protocol] ||= "tcp" if !options[:id] default_id = nil @@ -163,7 +164,7 @@ module VagrantPlugins if type == :forwarded_port # For forwarded ports, set the default ID to the # host port so that host ports overwrite each other. - default_id = options[:host].to_s + (options[:protocol] || "tcp").to_s + default_id = "#{options[:protocol]}#{options[:host]}" end options[:id] = default_id || SecureRandom.uuid @@ -383,7 +384,7 @@ module VagrantPlugins # Validate networks has_fp_port_error = false - fp_host_ports_and_protocol = Set.new + fp_used = Set.new valid_network_types = [:forwarded_port, :private_network, :public_network] networks.each do |type, options| @@ -399,12 +400,14 @@ module VagrantPlugins end if options[:host] - if fp_host_ports_and_protocol.include?(options[:host].to_s + (options[:protocol] || "tcp").to_s) + key = "#{options[:protocol]}#{options[:host]}" + if fp_used.include?(key) errors << I18n.t("vagrant.config.vm.network_fp_host_not_unique", - :host => options[:host].to_s + (options[:protocol] || "tcp").to_s) + :host => options[:host].to_s, + :protocol => options[:protocol].to_s) end - fp_host_ports_and_protocol.add(options[:host].to_s + (options[:protocol] || "tcp").to_s) + fp_used.add(key) end end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 87ae36e00..26a121cae 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -661,6 +661,7 @@ en: An IP is required for a private network. network_fp_host_not_unique: |- Forwarded port '%{host}' (host port) is declared multiple times + with the protocol '%{protocol}'. network_fp_requires_ports: |- Forwarded port definitions require a "host" and "guest" value network_type_invalid: |-