hashicorp / vagrant

Vagrant is a tool for building and distributing development environments.
https://www.vagrantup.com
Other
26.26k stars 4.43k forks source link

Vagrant 1.8.5 - udp port forwarding #7765

Closed o-alex closed 6 years ago

o-alex commented 8 years ago

Vagrant version

Vagrant 1.8.5

Host operating system

CentOS Linux 7

Guest operating system

Ubuntu 14.04.5 LTS

Vagrantfile

Vagrant.configure("2") do |c|
  if Vagrant.has_plugin?("vagrant-omnibus")
    c.omnibus.chef_version = "12.4.3"
  end
  if Vagrant.has_plugin?("vagrant-cachier")
    c.omnibus.cache_packages = true
    c.cache.scope = :machine
    c.cache.auto_detect = false
    c.cache.enable :apt
    c.cache.enable :gem
  end
  c.vm.box = "opscode-ubuntu-14.04"
  c.vm.box_url = "https://atlas.hashicorp.com/ubuntu/boxes/trusty64/versions/20150924.0.0/providers/virtualbox.box"
  c.vm.hostname = "default-ubuntu-1404.vagrantup.com"

# Ssh port on vagrant
  c.vm.network(:forwarded_port, {:guest=>22, :host=>22100})
# udp ports
  c.vm.network(:forwarded_port, {:guest=>40100, :host=>40100, :protocol=>"udp"})
  c.vm.network(:forwarded_port, {:guest=>40200, :host=>40200, :protocol=>"udp"})
  c.vm.network(:forwarded_port, {:guest=>40300, :host=>40300, :protocol=>"udp"})
# tcp port
  c.vm.network(:forwarded_port, {:guest=>40400, :host=>40400})

  c.vm.provider :virtualbox do |p|
    p.customize ["modifyvm", :id, "--memory", "13500"]
    p.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
    p.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
    p.customize ["modifyvm", :id, "--nictype1", "virtio"]
    p.customize ["modifyvm", :id, "--cpus", "2"]
  end

   c.vm.provision :chef_solo do |chef|
     chef.cookbooks_path = "cookbooks"
     chef.json = {
     "vagrant" => "true",
     }
  end

Expected behavior

Ports 40100,40200,40300 have udp traffic forwarded to same port from guest to host. Outgoing traffic(originating from guest) on guest port 40100 is expected to be forwarded to host port 40100 and then further to the destination. Also any incoming traffic coming to host port 40100 is expected to be forwarded to guest port 40100.

Actual behavior

If first traffic through forwarded udp port is outgoing, the mapping is not created correctly and a random host port is assigned. Example: outgoing traffic through guest port 40100 is forwarded through random host port to the destination. If first traffic through forwarded udp port is incoming, the mapping works correctly Example: if no traffic is going outside on lets say 40200 and the first traffic through the port is incoming traffic (outside to host to guest on port 40200) the mapping works correctly even for future outgoing traffic.

vagrant port -debug shows:

DEBUG virtualbox_5_1:   - [1, "udp40100", 40100, 
DEBUG virtualbox_5_1:   - [1, "udp40200", 40200, 
DEBUG virtualbox_5_1:   - [1, "udp40300", 40300, 

Steps to reproduce

The testing is done with simple netcat and wireshark

  1. Spin up a vagrant instance with the Vagrantfile above
  2. Outgoing traffic from vagrant to remote On remote machine: nc -lu On vagrant guest nc -u -p 40100

wireshark on remote machine shows incoming package on random port instead of 40100

  1. Incoming traffic first, then outgoing traffic On vagrant guest: nc -lu 40200 On remote machine: nc -u 40200

Incoming traffic works as expected and after this, the outgoing traffic also works as expected:

On remote machine: nc -lu On vagrant guest nc -u -p 40200

Wireshark shows traffic correctly coming from host port 40200

chrisroberts commented 6 years ago

Hi there,

Thanks for reporting this bug. I'm sure this was a real issue when originally reported (our fault for not looking sooner!) but there have been multiple Vagrant releases since the original report. I'm going to close this issue now and request you reopen the issue if you're still experiencing this problem. I'm sorry this wasn't looked at earlier :frowning_face:

Cheers!

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.