summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulo Alcantara <paulo@paulo.ac>2018-05-19 19:22:01 -0300
committerPaulo Alcantara <paulo@paulo.ac>2018-05-19 19:22:01 -0300
commit574386fb31b6a90313d35faa4bbc5ad24f34bd51 (patch)
tree57f87396f738becd711d109eda3d97349fe8eafb
parentde819838a7c346aca78055e7967e0003be9fe12a (diff)
downloadvmhtool-574386fb31b6a90313d35faa4bbc5ad24f34bd51.tar.gz
vmhtool-574386fb31b6a90313d35faa4bbc5ad24f34bd51.tar.xz
vmhtool-574386fb31b6a90313d35faa4bbc5ad24f34bd51.zip
Allow setting up ip addresses for tap devs.
Signed-off-by: Paulo Alcantara <paulo@paulo.ac>
-rwxr-xr-xvmhelper15
1 files changed, 12 insertions, 3 deletions
diff --git a/vmhelper b/vmhelper
index bb636ec..4209ef7 100755
--- a/vmhelper
+++ b/vmhelper
@@ -85,7 +85,8 @@ my %vm_conf_opts = (
BRIDGE_IFACE => 'br0',
BRIDGE_CFG_METHOD => 'auto',
BRIDGE_IP_ADDR => '',
- BRIDGE_GW_ADDR => ''
+ BRIDGE_GW_ADDR => '',
+ TAP_IP_ADDR => '0.0.0.0'
);
sub in2opts {
@@ -120,6 +121,9 @@ sub gen_conf {
print " bridge gateway (default auto): ";
in2opts('BRIDGE_GW_ADDR');
+ } else {
+ print " tap ip addr (default $vm_conf_opts{'TAP_IP_ADDR'}): ";
+ in2opts('TAP_IP_ADDR');
}
print $f "$_ = $vm_conf_opts{$_}\n" for (keys %vm_conf_opts);
@@ -204,7 +208,6 @@ sub is_net_iface_created {
sub create_bridge_dev {
system("sudo //usr/sbin/brctl addbr $bridge_iface");
- system("sudo /bin/ip addr flush dev $host_iface");
system("sudo /usr/sbin/brctl addif $bridge_iface $host_iface");
if ($vm_conf_opts{'BRIDGE_CFG_METHOD'} eq 'static') {
@@ -244,8 +247,14 @@ sub create_tap_dev {
destroy_tap_dev();
die "failed to create tap dev: $ret";
}
+ } else {
+ my $ipaddr = !$vm_conf_opts{'TAP_IP_ADDR'} ? "0.0.0.0/24" : "$vm_conf_opts{'TAP_IP_ADDR'}/24";
+ if (system("sudo /bin/ip addr add $ipaddr dev $tap_iface")) {
+ $ret = $?;
+ destroy_tap_dev();
+ die "failed to create tap dev: $ret";
+ }
}
-
if (system("sudo /bin/ip link set dev $tap_iface up")) {
$ret = $?;
destroy_tap_dev();