1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
#!/bin/sh
uname=$(uname)
case ${uname} in
NetBSD ) eth=vioif ; default=netbsd ;;
OpenBSD ) eth=vio ; default=openbsd ;;
FreeBSD ) eth=vtnet ; default=freebsd ;;
esac
run()
{
echo "$@" 1>&2
"$@"
}
ifconfig_eth()
{
local n=$1
local ip4=$2
local ip6=$3
local dad
case ${uname} in
NetBSD ) dad="" ;;
OpenBSD ) dad="-tentative" ;;
FreeBSD ) dad="-auto_linklocal" ;;
esac
run ifconfig ${eth}${n} inet ${ip4}/24
run ifconfig ${eth}${n} inet6 ${dad} ${ip6}/64
}
ifconfig_up()
{
local n=$1
case ${uname} in
NetBSD ) dad="-W 0" ;;
OpenBSD ) dad="" ;;
FreeBSD ) dad="" ;;
esac
run ifconfig ${dad} ${eth}${n} up
}
config_host()
{
local hostname=$1
run hostname ${hostname}
}
mac=$(ifconfig ${eth}1 | grep -o -E '([[:xdigit:]]{1,2}:){5}[[:xdigit:]]{1,2}')
echo mac=$mac 1>&2
case "$mac" in
12:00:00:64:64:23 ) # EAST
config_host east
ifconfig_eth 1 192.1.2.23 2001:db8:1:2::23
ifconfig_eth 2 192.0.2.254 2001:db8:0:2::254
ifconfig_up 1
;;
12:00:00:64:64:45 ) # WEST
config_host west
ifconfig_eth 1 192.1.2.45 2001:db8:1:2::45
ifconfig_eth 2 192.0.1.254 2001:db8:0:1::254
ifconfig_up 1
;;
12:52:49:53:45:01 ) # RISE
config_host rise
#ifconfig_eth 1 198.18.12.12 2001:db8:12::12
ifconfig_eth 1 192.0.2.12 2001:db8:0:2::12
ifconfig_eth 2 198.18.1.12 2001:db8:1::12
ifconfig_up 1
;;
12:00:53:45:54:01 ) # SET
config_host set
#ifconfig_eth 1 198.18.15.15 2001:db8:15::15
ifconfig_eth 1 192.0.1.15 2001:db8:0:1::15
ifconfig_eth 2 198.18.1.15 2001:db8:1::15
ifconfig_up 1
;;
* )
case ${uname} in
NetBSD ) default=netbsd ;;
OpenBSD ) default=openbsd ;;
FreeBSD ) default=freebsd ;;
esac
config_host ${default}
;;
esac
|