Commit 0fb8acb9 authored by Jan Moskyto Matejka's avatar Jan Moskyto Matejka

Birdlab: hostname fixes, split rc.local to rclib, IPv6 for control interfaces

parent 0e2ffa48
......@@ -10,6 +10,7 @@ ip link add $VIRTCTRL type veth peer name $VIRTUPLINK
ip link set $VIRTCTRL up
ip link set $VIRTUPLINK up
ip addr add 192.168.192.1/18 dev $VIRTCTRL
ip -6 addr add 2001:1488:A001::/64 dev $VIRTCTRL
vsctl add-port $VIRTBR $VIRTUPLINK tag=1
......
......@@ -140,7 +140,7 @@ if [ -n "$HOSTSOCK" ]; then
done
fi
echo -e "hostname $HOSTNAME\nexport HOSTNAME=$HOSTNAME" > $ROOT/nfs/rc/hostname-${HOSTMAC//:}
echo -e "hostname $HOSTNAME\nexport HOSTNAME=$HOSTNAME" > $ROOT/nfs/net/hostname-${HOSTMAC//:}
$ROOT/bin/omapi add $NAME $HOSTMAC $HOSTIP4
......
......@@ -158,11 +158,11 @@ Gre atd2f1 atd2 1.1.2.1/32 atf1 1.1.2.2/32
Gre atd2o1 atd2 1.1.2.3/32 ato1 1.1.2.4/32
Gre atd2n1 atd2 1.1.2.5/32 atn1 1.1.2.6/32
Dummy atd1 atd1 10.55.1.1/30 fd01:55::0/127
Dummy ato1 ato1 10.55.1.5/30 fd01:55::2/127
Dummy atf1 atf1 10.55.1.9/30 fd01:55::4/127
Dummy atn1 atn1 10.55.1.13/30 fd01:55::6/127
Dummy atd2 atd2 10.55.1.17/30 fd01:55::8/127
Dummy atd1 atd1 10.55.1.1/30 fd01:55::1/126
Dummy ato1 ato1 10.55.1.5/30 fd01:55::5/126
Dummy atf1 atf1 10.55.1.9/30 fd01:55::9/126
Dummy atn1 atn1 10.55.1.13/30 fd01:55::13/126
Dummy atd2 atd2 10.55.1.17/30 fd01:55::17/126
Copy mikrotik mpls-auto mpls-e1 mpls-e2 mpls-p1 mpls-p2 mpls-p3 mpls-p4 mpls-c1 mpls-c2
......
......@@ -2,8 +2,7 @@
export PATH=$PATH:/usr/local/bin:/usr/pkg/bin
UNAME=$(uname)
UNAME=${UNAME,,}
. /mnt/nfs/rclib
case $UNAME in
linux)
......@@ -33,189 +32,41 @@ case $UNAME in
;;
esac
declare -a INTERFACES
declare -A IFBYMAC
echo "Ifaces list: $(ifaces)"
function dbg {
echo "D: " "$@"
}
function ifup() {
case $UNAME in
linux)
ip link set $1 up
;;
netbsd|openbsd|freebsd)
ifconfig $1 up
;;
esac
}
function ip4() {
case $UNAME in
linux)
ip addr add $2 dev $1
;;
netbsd|openbsd|freebsd)
ifconfig $1 inet $2
;;
esac
}
for I in $(ifaces); do
NAME=${I%%,*}
MAC=${I##*,}
MAC=${MAC,,}
function ip6() {
case $UNAME in
linux)
ip -6 addr add $2 dev $1
;;
netbsd|openbsd|freebsd)
ifconfig $1 inet6 $2
;;
esac
}
echo "Iface $NAME ($MAC)"
function ip4ptp() {
case $UNAME in
linux)
ip addr add $2 peer $3 dev $1
CIP4=$(ip addr show dev $NAME | sed -nr 's/\s+inet ([^ ]*) brd 192.168.255.255 .*/\1/p' )
if [ -n "$CIP4" ]; then
CIP6DEC=$(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)/[0-9]+#2001:1488:a001::\1:\2/64#')
CIP6HEX=$(printf "2001:1488:a001::ffff:%02x%02x/64" $(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)/[0-9]+#\1 \2#'))
ip6 $NAME $CIP6HEX
ip6 $NAME $CIP6DEC
ip -6 route add default via 2001:1488:a001::1
fi
;;
netbsd|openbsd|freebsd)
ifconfig $1 inet $2 ${3%%/*}
;;
esac
}
function cnt() {
local OUT
if [ ! -r /tmp/${1}count ]; then
OUT=0
else
OUT=$(</tmp/${1}count)
fi
echo $((OUT+1)) > /tmp/${1}count
echo $OUT
}
function grecount() {
cnt gre
}
function locount() {
cnt lo
}
function gre() {
case $UNAME in
linux)
ip tunnel add $1 mode gre remote $3 local $2
ip link set $1 up
echo $1
INTERFACES+=( $1, )
;;
freebsd)
GIF=gre$(grecount)
ifconfig $GIF create
ifconfig $GIF tunnel $2 $3
ifconfig $GIF name $1
echo $1
INTERFACES+=( $1, )
;;
openbsd)
GIF=gre$(grecount)
ifconfig $GIF create
ifconfig $GIF tunnel $2 $3
ifconfig $GIF inet6 eui64 # OpenBSD needs to explicitly add link-local address for IPv6
ifconfig $GIF description $1
echo $GIF
INTERFACES+=( $GIF, )
;;
netbsd)
GIF=gre$(grecount)
ifconfig $GIF create
ifconfig $GIF tunnel $2 $3
echo $GIF
INTERFACES+=( $GIF, )
CIP4=$(ifconfig $NAME | sed -nr 's/[[:space:]]+inet (192.168.[^ ]*) netmask 0x[0-9a-f]+ broadcast 192.168.255.255/\1/p' )
echo "CIP4=$CIP4"
if [ -n "$CIP4" ]; then
CIP6DEC=$(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)#2001:1488:a001::\1:\2/64#')
CIP6HEX=$(printf "2001:1488:a001::ffff:%02x%02x/64" $(echo $CIP4 | sed -r 's#192\.168\.([0-9]+)\.([0-9]+)#\1 \2#'))
echo "CIP6DEC=$CIP6DEC"
echo "CIP6HEX=$CIP6HEX"
ip6 $NAME $CIP6HEX
ip6 $NAME $CIP6DEC
route add -inet6 default 2001:1488:a001::1
fi
;;
esac
}
function dummy() {
case $UNAME in
linux)
ip link add $1 type dummy
ip link set $1 up
echo $1
INTERFACES+=( $1, )
;;
netbsd)
LIF=lo$(locount)
ifconfig $LIF create
echo $LIF
INTERFACES+=( $LIF, )
;;
openbsd)
LIF=lo$(locount)
ifconfig $LIF create
ifconfig $LIF description $1
echo $LIF
INTERFACES+=( $LIF, )
;;
freebsd)
LIF=lo$(locount)
ifconfig $LIF create
ifconfig $LIF name $1
echo $1
INTERFACES+=( $1, )
;;
esac
}
function ifname() {
case $UNAME in
linux)
ip link set $1 name $2
echo $2
;;
freebsd)
ifconfig $1 name $2
echo $2
;;
openbsd)
ifconfig $1 description $2
echo $1
;;
netbsd)
echo $1
;;
esac
}
# Get list of physical interfaces, together with their MACs.
function ifaces() {
case $UNAME in
linux)
( ip link ; echo "0: eof" ) | sed -rn '/^[0-9]/{s/^[0-9]+: //;s/:.*//;x;s/\n /,/;p;}; /ether/{s/.*ether (..:..:..:..:..:..).*/ \1/;H;}' | grep ','
;;
*)
( ifconfig ; echo "eof" ) | sed -rn '/^[a-z]/{s/:.*//;x;s/\n /,/;p;}; /(ether|lladdr|address:)/{s/.*(ether|lladdr|address:) (..:..:..:..:..:..).*/ \2/;H;}' | grep ','
;;
esac
}
for I in $(ifaces); do
NAME=${I%%,*}
MAC=${I##*,}
MAC=${MAC,,}
HOSTNAMEFILE=/mnt/nfs/rc/hostname-${MAC//:}
if [ -f $HOSTNAMEFILE ]; then
. $HOSTNAMEFILE
fi
done
for I in $(ifaces); do
NAME=${I%%,*}
MAC=${I##*,}
MAC=${MAC,,}
IFBYMAC[$MAC]=$NAME
INTERFACES+=( $I )
......
#!/bin/bash
UNAME=$(uname)
UNAME=${UNAME,,}
declare -a INTERFACES
declare -A IFBYMAC
function D() {
echo DBG: "$@" 1>&2
}
function ifup() {
D ifup "$@"
case $UNAME in
linux)
ip link set $1 up
;;
netbsd|openbsd|freebsd)
ifconfig $1 up
;;
esac
}
function ip4() {
D ip4 "$@"
case $UNAME in
linux)
ip addr add $2 dev $1
;;
netbsd|openbsd|freebsd)
ifconfig $1 inet $2
;;
esac
}
function ip6() {
D ip6 "$@"
case $UNAME in
linux)
ip -6 addr add $2 dev $1
;;
netbsd|openbsd|freebsd)
ifconfig $1 inet6 $2
;;
esac
}
function ip4ptp() {
D ip4ptp "$@"
case $UNAME in
linux)
ip addr add $2 peer $3 dev $1
;;
netbsd|openbsd|freebsd)
ifconfig $1 inet $2 ${3%%/*}
;;
esac
}
function cnt() {
D cnt "$@"
local OUT
if [ ! -r /tmp/${1}count ]; then
OUT=16
else
OUT=$(</tmp/${1}count)
fi
echo $((OUT+1)) > /tmp/${1}count
echo $OUT
}
function grecount() {
cnt gre
}
function locount() {
cnt lo
}
function gre() {
D gre "$@"
case $UNAME in
linux)
ip tunnel add $1 mode gre remote $3 local $2
ip link set $1 up
echo $1
INTERFACES+=( $1, )
;;
freebsd)
GIF=gre$(grecount)
ifconfig $GIF create
ifconfig $GIF tunnel $2 $3
ifconfig $GIF name $1
echo $1
INTERFACES+=( $1, )
;;
openbsd)
GIF=gre$(grecount)
ifconfig $GIF create
ifconfig $GIF tunnel $2 $3
ifconfig $GIF inet6 eui64 # OpenBSD needs to explicitly add link-local address for IPv6
ifconfig $GIF description $1
echo $GIF
INTERFACES+=( $GIF, )
;;
netbsd)
GIF=gre$(grecount)
ifconfig $GIF create
ifconfig $GIF tunnel $2 $3
echo $GIF
INTERFACES+=( $GIF, )
;;
esac
}
function dummy() {
D dummy "$@"
case $UNAME in
linux)
ip link add $1 type dummy
ip link set $1 up
echo $1
INTERFACES+=( $1, )
;;
netbsd)
LIF=lo$(locount)
ifconfig $LIF create
echo $LIF
INTERFACES+=( $LIF, )
;;
openbsd)
LIF=lo$(locount)
ifconfig $LIF create
ifconfig $LIF description $1
echo $LIF
INTERFACES+=( $LIF, )
;;
freebsd)
LIF=lo$(locount)
ifconfig $LIF create
ifconfig $LIF name $1
echo $1
INTERFACES+=( $1, )
;;
esac
}
function ifname() {
D ifname "$@"
case $UNAME in
linux)
ip link set $1 name $2
echo $2
;;
freebsd)
ifconfig $1 name $2
echo $2
;;
openbsd)
ifconfig $1 description $2
echo $1
;;
netbsd)
echo $1
;;
esac
}
# Get list of physical interfaces, together with their MACs.
function ifaces() {
D ifaces
case $UNAME in
linux)
( ip link ; echo "0: eof" ) | sed -rn '/^[0-9]/{s/^[0-9]+: //;s/:.*//;x;s/\n /,/;p;}; /ether/{s/.*ether (..:..:..:..:..:..).*/ \1/;H;}' | grep ','
;;
*)
( ifconfig ; echo "eof" ) | sed -rn '/^[a-z]/{s/:.*//;x;s/\n /,/;p;}; /(ether|lladdr|address:)/{s/.*(ether|lladdr|address:) (..:..:..:..:..:..).*/ \2/;H;}' | grep ','
;;
esac
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment