Skip to content

Commit

Permalink
More verbose error messages for bridge handling
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianfreyer committed Oct 2, 2017
1 parent d20451e commit 2b47ada
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/vagrant-bhyve/action/create_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion lib/vagrant-bhyve/action/create_tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ 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')
tap_name = "vagrant_bhyve_#{vm_name}"
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
Expand Down
11 changes: 8 additions & 3 deletions lib/vagrant-bhyve/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}")
Expand Down

0 comments on commit 2b47ada

Please sign in to comment.