about summary refs log tree commit diff stats
path: root/tools/conf/etc/rc.d/blan
blob: 56d1809cd3e9bb090ff00acb02291261f341c18b (plain) (blame)
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
#!/bin/sh
#
# /etc/rc.d/net: start/stop network interface
#

DEV="br0"
PHY="enp8s0"

ADDR=10.0.0.1
NET=10.0.0.0
MASK=24

# one tap for each cpu core
NTAPS=$((`/usr/bin/nproc`))

case $1 in
    start)
        /sbin/ip link add name ${DEV} type bridge
        /sbin/ip addr add ${ADDR}/${MASK} dev ${DEV} broadcast +
        /sbin/ip link set dev ${DEV} up
        /bin/sleep 0.2s

        /sbin/ip link set dev ${PHY} down
        /bin/sleep 0.1s
        /sbin/ip route flush dev ${PHY}
        /sbin/ip addr flush dev ${PHY}
        /sbin/ip link set dev ${PHY} up
        /bin/sleep 0.2s

        /sbin/ip link set dev ${PHY} master ${DEV}
        #/sbin/ip route add default via ${GW}

        for i in `/usr/bin/seq $NTAPS`
        do
            TAP="tap$i"
            echo "Setting up ${TAP} tap interface."
            /sbin/ip tuntap add ${TAP} mode tap group kvm
            /sbin/ip link set ${TAP} up
            /bin/sleep 0.2s
            /sbin/ip link set ${TAP} master ${DEV}
        done

        exit 0
        ;;
    stop)

        for i in `/usr/bin/seq $NTAPS`
        do
            TAP="tap$i"
            echo "Deleting ${TAP} tap interface."
            /sbin/ip link del ${TAP}
        done

        /sbin/ip link set dev ${DEV} down
        /sbin/ip route flush dev ${DEV}
        /sbin/ip link del ${DEV}
        exit 0
        ;;
    restart)
        $0 stop
        $0 start
        ;;
    *)
        echo "Usage: $0 [start|stop|restart]"
        ;;
esac

# End of file