From 98f1df47a149e5109a3f132be9fffbf41cce9805 Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sat, 27 Jul 2013 20:58:33 -0300 Subject: [PATCH] Do not attach forwarded ports to host's 127.0.0.1 by default This is enough for us to bump to 0.5.0 and to close #76 --- CHANGELOG.md | 9 ++++++++- Gemfile.lock | 2 +- lib/vagrant-lxc/action/forward_ports.rb | 6 +++--- lib/vagrant-lxc/version.rb | 2 +- spec/unit/action/forward_ports_spec.rb | 19 +++++++++++++++---- 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a5d60be..0bb6bfd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,11 @@ -## [0.4.1](https://github.com/fgrehm/vagrant-lxc/compare/v0.4.0...master) (unreleased) +## [0.5.0](https://github.com/fgrehm/vagrant-lxc/compare/v0.4.0...master) (unreleased) + +BACKWARDS INCOMPATIBILITIES: + + - To align with Vagrant's core behaviour, forwarded ports are no longer attached + to 127.0.0.1 and `redir`'s `--laddr` parameter is skipped in case the `:host_ip` + config is not provided, that means `redir` will listen on connections coming + from any of the host's IPs. FEATURES: diff --git a/Gemfile.lock b/Gemfile.lock index 5b55f16..3af2f74 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -25,7 +25,7 @@ GIT PATH remote: . specs: - vagrant-lxc (0.4.1.dev) + vagrant-lxc (0.5.0.dev) GEM remote: https://rubygems.org/ diff --git a/lib/vagrant-lxc/action/forward_ports.rb b/lib/vagrant-lxc/action/forward_ports.rb index 7a29c41..75084ff 100644 --- a/lib/vagrant-lxc/action/forward_ports.rb +++ b/lib/vagrant-lxc/action/forward_ports.rb @@ -48,7 +48,7 @@ module Vagrant message_attributes)) redir_pid = redirect_port( - fp[:host_ip] || "127.0.0.1", + fp[:host_ip], fp[:host], fp[:guest_ip] || @env[:machine].provider.driver.assigned_ip, fp[:guest] @@ -72,8 +72,8 @@ module Vagrant end def redirect_port(host_ip, host_port, guest_ip, guest_port) - host_ip = "--laddr=#{host_ip}" unless host_ip.empty? - redir_cmd = "sudo redir #{host_ip} --lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} 2>/dev/null" + host_ip = "--laddr=#{host_ip} " if host_ip + redir_cmd = "redir #{host_ip}--lport=#{host_port} --caddr=#{guest_ip} --cport=#{guest_port} 2>/dev/null" @logger.debug "Forwarding port with `#{redir_cmd}`" spawn redir_cmd diff --git a/lib/vagrant-lxc/version.rb b/lib/vagrant-lxc/version.rb index b7d699a..ea533bc 100644 --- a/lib/vagrant-lxc/version.rb +++ b/lib/vagrant-lxc/version.rb @@ -1,5 +1,5 @@ module Vagrant module LXC - VERSION = "0.4.1.dev" + VERSION = "0.5.0.dev" end end diff --git a/spec/unit/action/forward_ports_spec.rb b/spec/unit/action/forward_ports_spec.rb index 118464e..76f08d0 100644 --- a/spec/unit/action/forward_ports_spec.rb +++ b/spec/unit/action/forward_ports_spec.rb @@ -9,13 +9,15 @@ describe Vagrant::LXC::Action::ForwardPorts do let(:env) { {machine: machine, ui: double(info: true)} } let(:machine) { double(:machine) } let!(:data_dir) { Pathname.new(Dir.mktmpdir) } - let(:networks) { [[:other_config, {}], [:forwarded_port, {guest: guest_port, host: host_port}]] } - let(:host_port) { 8080 } - let(:guest_port) { 80 } let(:provider) { instance_double('Vagrant::LXC::Provider', driver: driver) } let(:driver) { instance_double('Vagrant::LXC::Driver', assigned_ip: container_ip) } + let(:host_ip) { '127.0.0.1' } + let(:host_port) { 8080 } + let(:guest_port) { 80 } let(:container_ip) { '10.0.1.234' } let(:pid) { 'a-pid' } + let(:forward_conf) { {guest: guest_port, host: host_port, host_ip: host_ip} } + let(:networks) { [[:other_config, {}], [:forwarded_port, forward_conf]] } subject { described_class.new(app, env) } @@ -33,7 +35,16 @@ describe Vagrant::LXC::Action::ForwardPorts do subject.stub(system: true) subject.call(env) subject.should have_received(:spawn).with( - "sudo redir --laddr=127.0.0.1 --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null" + "redir --laddr=#{host_ip} --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null" + ) + end + + it 'skips --laddr parameter if host_ip is nil' do + forward_conf.delete(:host_ip) + subject.stub(system: true) + subject.call(env) + subject.should have_received(:spawn).with( + "redir --lport=#{host_port} --caddr=#{container_ip} --cport=#{guest_port} 2>/dev/null" ) end