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
This commit is contained in:
Fabio Rehm 2013-07-27 20:58:33 -03:00
parent 2dbfd23915
commit 98f1df47a1
5 changed files with 28 additions and 10 deletions

View file

@ -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:

View file

@ -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/

View file

@ -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

View file

@ -1,5 +1,5 @@
module Vagrant
module LXC
VERSION = "0.4.1.dev"
VERSION = "0.5.0.dev"
end
end

View file

@ -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