1 | #!/bin/bash
|
---|
2 | # innotek VirtualBox
|
---|
3 | # VirtualBox VNIC setup script for Solaris hosts with Crossbow.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2007 innotek GmbH
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | # available from http://www.virtualbox.org. This file is free software;
|
---|
9 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | # General Public License (GPL) as published by the Free Software
|
---|
11 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | #
|
---|
15 |
|
---|
16 | if [ -z "$1" ]; then
|
---|
17 | echo "Missing MAC address."
|
---|
18 | echo
|
---|
19 | echo "Usage: $0 macaddress [vnicname]"
|
---|
20 | echo " A new VNIC is created if no vnicname is provided."
|
---|
21 | exit 1
|
---|
22 | fi
|
---|
23 |
|
---|
24 | mac=$1
|
---|
25 | # Create the VNIC if required
|
---|
26 | if [ -z "$2" ]; then
|
---|
27 | # Try obtain a physical NIC that is currently active
|
---|
28 | phys_nic=`/usr/sbin/dladm show-dev | /usr/bin/awk 'NF==7 && $3=="up" { print $1 }'`
|
---|
29 | if [ -z "$phys_nic" ]; then
|
---|
30 | # Failed to get a currently active NIC, get the first available NIC.
|
---|
31 | phys_nic=`/usr/sbin/dladm show-link | /usr/bin/nawk '/legacy/ {next} {print $1; exit}'`
|
---|
32 | if [ -z "$phys_nic" ]; then
|
---|
33 | # Failed to get any NICs!
|
---|
34 | echo "Failed to get a physical NIC to bind to."
|
---|
35 | exit 1
|
---|
36 | fi
|
---|
37 | fi
|
---|
38 |
|
---|
39 | # To use a specific physical NIC, replace $phys_nic with the name of the NIC.
|
---|
40 | vnic_id=`/usr/lib/vna $phys_nic $mac`
|
---|
41 | if [ $? != 0 ]; then
|
---|
42 | exit 1
|
---|
43 | fi
|
---|
44 | vnic_name=vnic${vnic_id}
|
---|
45 | else
|
---|
46 | vnic_name=$2
|
---|
47 | vnic_id=${vnic_name##*[a-z]}
|
---|
48 | fi
|
---|
49 |
|
---|
50 | if [ ${vnic_id} -lt 10 ]; then
|
---|
51 | host_ip="192.168.1.10${vnic_id}"
|
---|
52 | guest_ip="192.168.1.20${vnic_id}"
|
---|
53 | elif [ ${vnic_id} -lt 256 ]; then
|
---|
54 | host_ip="192.168.1.${vnic_id}"
|
---|
55 | guest_ip="192.168.2.${vnic_id}"
|
---|
56 | elif [ ${vnic_id} -gt 899 ]; then
|
---|
57 | let "temp_id = $vnic_id % 900"
|
---|
58 | host_ip="192.168.1.10${temp_id}"
|
---|
59 | guest_ip="192.168.1.20${temp_id}"
|
---|
60 | else
|
---|
61 | # VNIC ID is probably off the scale!
|
---|
62 | host_ip="192.168.1.10"
|
---|
63 | guest_ip="192.168.1.20"
|
---|
64 | fi
|
---|
65 |
|
---|
66 | netmask="255.255.255.0"
|
---|
67 |
|
---|
68 | if [ -z "$2" ]; then
|
---|
69 | /sbin/ifconfig $vnic_name plumb
|
---|
70 | /sbin/ifconfig $vnic_name $host_ip destination $guest_ip netmask $netmask up
|
---|
71 | #else
|
---|
72 | # Do existing VNIC configuration here if needed...
|
---|
73 | fi
|
---|
74 |
|
---|
75 | echo "$vnic_name"
|
---|
76 | exit 0
|
---|
77 |
|
---|