From 10c29029361e169441374eca06b4c283f5f6c7cf Mon Sep 17 00:00:00 2001 From: Fabian Freyer Date: Sun, 1 Oct 2017 01:47:52 +0000 Subject: [PATCH] More verbose error messages for bridge handling --- lib/vagrant-bhyve/action/create_bridge.rb | 2 +- lib/vagrant-bhyve/action/create_tap.rb | 3 ++- lib/vagrant-bhyve/driver.rb | 11 ++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/vagrant-bhyve/action/create_bridge.rb b/lib/vagrant-bhyve/action/create_bridge.rb index 1a07dbc..b009ab1 100644 --- a/lib/vagrant-bhyve/action/create_bridge.rb +++ b/lib/vagrant-bhyve/action/create_bridge.rb @@ -21,7 +21,7 @@ def call(env) bridge_list = %w(vagrant_bhyve_default_bridge) # The bridge name is used as created bridge device's description bridge_list.each do |bridge| - @driver.create_network_device(bridge, "bridge") + @driver.create_network_device(bridge, "bridge", @ui) @driver.enable_nat(bridge, @ui) end @app.call(env) diff --git a/lib/vagrant-bhyve/action/create_tap.rb b/lib/vagrant-bhyve/action/create_tap.rb index e8041dc..a087c47 100644 --- a/lib/vagrant-bhyve/action/create_tap.rb +++ b/lib/vagrant-bhyve/action/create_tap.rb @@ -13,6 +13,7 @@ def initialize(app, env) def call(env) @machine = env[:machine] @driver = @machine.provider.driver + @ui = env[:ui] env[:ui].detail I18n.t('vagrant_bhyve.action.vm.boot.create_tap') vm_name = @driver.get_attr('vm_name') @@ -20,7 +21,7 @@ def call(env) tap_list = [tap_name] # The switch name is used as created bridge device's description tap_list.each do |tap| - @driver.create_network_device(tap, "tap") + @driver.create_network_device(tap, "tap", @ui) end @app.call(env) end diff --git a/lib/vagrant-bhyve/driver.rb b/lib/vagrant-bhyve/driver.rb index 7be6522..6832e17 100644 --- a/lib/vagrant-bhyve/driver.rb +++ b/lib/vagrant-bhyve/driver.rb @@ -168,7 +168,7 @@ def check_or_create_default_pfconf(ui) end end - def create_network_device(device_name, device_type) + def create_network_device(device_name, device_type, ui) return if device_name.length == 0 # Check whether the bridge has been created @@ -189,12 +189,17 @@ def create_network_device(device_name, device_type) # with the bridge mtu = execute(false, "ifconfig #{bridge} | head -n1 | awk '{print $NF}'") execute(false, "#{@sudo} ifconfig #{interface_name} mtu #{mtu}") if mtu.length != 0 and mtu != '1500' - execute(false, "#{@sudo} ifconfig #{bridge} addm #{interface_name}") + if execute(true, "ifconfig #{bridge} | grep -q \"member: #{interface_name}\"") != 0 + execute(false, "#{@sudo} ifconfig #{bridge} addm #{interface_name}") + else + ui.warn "#{interface_name} is already a member of #{bridge}" + end + # Setup VM-specific pf rules id = get_attr('id') pf_conf = @data_dir.join('pf.conf') pf_conf.open('w') do |f| - f.puts "set skip on #{interface_name}" + f.puts "pass quick on #{interface_name}" end check_or_create_default_pfconf(ui) execute(false, "#{@sudo} pfctl -a 'vagrant/#{id}' -f #{pf_conf.to_s}")