Discussion:
linktool: host to guest interface link mapper
Petar Bogdanovic
2014-01-20 23:58:09 UTC
Permalink
Hi,

as it is right now, bridged guest interfaces won't adapt any link
changes of their bridged counterparts. Manually setting or unsetting
the "cable connected" checkbox is an option but not a very practical one
if you need to roam often and would like your VM to pick up the change
automatically.

linktool is a small set of simple utilities that can make that process
transparent. It's currently OSX only since it relies on scutil(8) but
that could easily be adjusted in future.

In order to use linktool, copy

http://smokva.net/src/linktool.sh

somewhere, make it executable and add the following line to your
rc.local (or create an equivalent launchd.plist for root):

# linktool, absolute paths only
/path/to/linktool setup /path/to/VirtualBox.app

and that should be it. All VMs that contain bridged interfaces should
automagically adapt any link changes on their next start.


Details for non-TLDR readers:

linktool consists of several helpers that do a smaller part of the whole
job mentioned in the introduction:

$ linktool
usage:
linktool watch host-if [host-if..]
linktool map guest host-if:guest-if[:guest-if..] [host-if:guest-if[:guest-if..]..]
linktool mapper guest
linktool wrapper --startvm guest
linktool seesaw master-host-if slave-host-if
linktool setup vbox-dir vbox-cmd

guest : name or UUID of any VM
host-if : host interface (see ifconfig)
guest-if : guest interface (integer, 1-8)
vbox-dir : path to VirtualBox.app directory
vbox-cmd : name of VirtualBox command

linkwatch uses scutil(8) and watches host interfaces:

$ linktool watch en0 en1
en0:on # initial output
en1:off # initial output
en1:on # link status of en1 changed

linkmap maps host interfaces to guest interfaces:

$ linktool map "My Virtual Machine" en0:1:2
Mapping link status (on): localhost/en0 -> My Virtual Machine/nic1
Mapping link status (on): localhost/en0 -> My Virtual Machine/nic2

linkmapper maps all bridged interfaces of a guest. Its output looks
similar to the output above.

linkwrapper is a wrapper around linkmapper and tries to act like
VirtualBoxVM i.e. it understands the --startvm flag.

linksetup replaces VirtualBoxVM with a plain-text hook that starts
linkwrapper first followed by VirtualBoxVM-$(uname -m). It needs to
run on every boot since VirtualBoxStartup.sh will otherwise persist
(and remove/relink VirtualBoxVM).

linkseesaw doesn't have much to do with linktool or VirtualBox. It
reuses linkwatch, downs the slave interface if the master interface is
up and vice versa.


Issues:

* VBoxHeadless is not supported (shouldn't be hard to add)

* Switching link status doesn't work well with all virtual
network devices. e1000 is the most reliable choice, while
virtio-net mostly works although it sometimes gets stuck
in a state that is only recoverable by unloading and loading
the module (on Linux guests). In that state, showvminfo
reports link status A while ethtool claims link status B.

* Complicated bridging setups (two guest interfaces bridged with
one host interface for example) can be unreliable too. If you
can't get any packets through but tcpdump happily reports arp
traffic.. simplify your setup.


I've been using linktool for all my VMs since about a month and I pretty
much forgot about it.

Comments & questions are welcome.

Thanks,

Petar Bogdanovic
Cliff Scott
2014-01-22 03:10:56 UTC
Permalink
** Reply to message from Petar Bogdanovic <petar-+Dgt6vZh/JqsTnJN9+***@public.gmane.org> on Tue, 21 Jan
2014 00:58:09 +0100

Sounds very useful, however I am very much a newbie regarding stuff at the
command level on the Mac. I come from many years of OS/2 and Windoz. I assume
from what you wrote that the file that I make is named linktool.sh. Did that.
The "sh" extension I understand means it is a script. Ok, but where do I find
rc.local and what is meant by absolute path? Is that Username/... all the way
to the directory where the file and the app is located? The line added to
rc.local is: Path to linktool.sh (space) Setup (space) Path to
VirtualBox.app, Yes?

Thanks for your help.

Cliff
Post by Petar Bogdanovic
Hi,
as it is right now, bridged guest interfaces won't adapt any link
changes of their bridged counterparts. Manually setting or unsetting
the "cable connected" checkbox is an option but not a very practical one
if you need to roam often and would like your VM to pick up the change
automatically.
linktool is a small set of simple utilities that can make that process
transparent. It's currently OSX only since it relies on scutil(8) but
that could easily be adjusted in future.
In order to use linktool, copy
http://smokva.net/src/linktool.sh
somewhere, make it executable and add the following line to your
# linktool, absolute paths only
/path/to/linktool setup /path/to/VirtualBox.app
and that should be it. All VMs that contain bridged interfaces should
automagically adapt any link changes on their next start.
linktool consists of several helpers that do a smaller part of the whole
$ linktool
linktool watch host-if [host-if..]
linktool map guest host-if:guest-if[:guest-if..] [host-if:guest-if[:guest-if..]..]
linktool mapper guest
linktool wrapper --startvm guest
linktool seesaw master-host-if slave-host-if
linktool setup vbox-dir vbox-cmd
guest : name or UUID of any VM
host-if : host interface (see ifconfig)
guest-if : guest interface (integer, 1-8)
vbox-dir : path to VirtualBox.app directory
vbox-cmd : name of VirtualBox command
$ linktool watch en0 en1
en0:on # initial output
en1:off # initial output
en1:on # link status of en1 changed
$ linktool map "My Virtual Machine" en0:1:2
Mapping link status (on): localhost/en0 -> My Virtual Machine/nic1
Mapping link status (on): localhost/en0 -> My Virtual Machine/nic2
linkmapper maps all bridged interfaces of a guest. Its output looks
similar to the output above.
linkwrapper is a wrapper around linkmapper and tries to act like
VirtualBoxVM i.e. it understands the --startvm flag.
linksetup replaces VirtualBoxVM with a plain-text hook that starts
linkwrapper first followed by VirtualBoxVM-$(uname -m). It needs to
run on every boot since VirtualBoxStartup.sh will otherwise persist
(and remove/relink VirtualBoxVM).
linkseesaw doesn't have much to do with linktool or VirtualBox. It
reuses linkwatch, downs the slave interface if the master interface is
up and vice versa.
* VBoxHeadless is not supported (shouldn't be hard to add)
* Switching link status doesn't work well with all virtual
network devices. e1000 is the most reliable choice, while
virtio-net mostly works although it sometimes gets stuck
in a state that is only recoverable by unloading and loading
the module (on Linux guests). In that state, showvminfo
reports link status A while ethtool claims link status B.
* Complicated bridging setups (two guest interfaces bridged with
one host interface for example) can be unreliable too. If you
can't get any packets through but tcpdump happily reports arp
traffic.. simplify your setup.
I've been using linktool for all my VMs since about a month and I pretty
much forgot about it.
Comments & questions are welcome.
Thanks,
Petar Bogdanovic
Petar Bogdanovic
2014-01-22 11:18:51 UTC
Permalink
Post by Cliff Scott
Sounds very useful, however I am very much a newbie regarding stuff at the
command level on the Mac.
I'm sorry, should have thought about that.
Post by Cliff Scott
I assume from what you wrote that the file that I make is named
linktool.sh. Did that. The "sh" extension I understand means it is a
script.
The name of the executable doesn't matter as long as it is executable.
I named my copy `linktool' without `.sh'.
Post by Cliff Scott
Ok, but where do I find rc.local
/etc/rc.local probably doesn't exist yet (see below).
Post by Cliff Scott
and what is meant by absolute path?
``A full path or absolute path is a path that points to the same
location on one file system regardless of the working directory
or combined paths. It is usually written in reference to a root
directory.''

Examples of absolute paths:

/
/etc
/Users/cliff
/Directory with Spaces/foo/bar

Examples of relative paths:

cliff
foo/bar


The following steps should get you going (`$' = shell prompt):


Let's test directories first:

$ ls -d /usr/local/bin
/usr/local/bin

$ ls -d /Applications/VirtualBox.app
/Applications/VirtualBox.app

both commands shouldn't produce any errors.


Next, download linktool.sh as linktool:

$ sudo curl -o /usr/local/bin/linktool http://smokva.net/src/linktool.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 7462 100 7462 0 0 30054 0 --:--:-- --:--:-- --:--:-- 36578


A quick sanity check before executing:

$ shasum /usr/local/bin/linktool
d2eaf56d840184fc23a149153fc00fff0eff35f1 /usr/local/bin/linktool

if the checksum matches, good. If not, something went wrong during the
download or I modified the source in the meantime. :)


Let's make linktool executable

$ sudo chmod +x /usr/local/bin/linktool


and add the one line to /etc/rc.local (that probably doesn't exist yet)

$ sudo sh -c 'echo /usr/local/bin/linktool setup /Applications/VirtualBox.app >>/etc/rc.local'


Finally, reboot and you're done.


HTH and let me know if you have any other questions.

Petar Bogdanovic

Loading...