Project

General

Profile

hub-gluon.sh

Sven Eckelmann, 02/23/2019 10:57 PM

Download (1.12 KB)

 
1
#! /bin/sh
2
USER="$(whoami)"
3
BRIDGE=br0
4
ETH=enp8s0
5
VXLAN=vx_mesh_lan
6
# calculated on gluon node via: lua -lgluon.util -e 'print(tonumber(gluon.util.domain_seed_bytes("gluon-mesh-vxlan", 3), 16))'
7
VXLAN_ID=12094920
8

    
9

    
10
xor2() {
11
        echo -n "${1:0:1}"
12
        echo -n "${1:1:1}" | tr '0123456789abcdef' '23016745ab89efcd'
13
}
14

    
15
interface_linklocal() {
16
        local macaddr="$(cat /sys/class/net/"${ETH}"/address)"
17
        local oldIFS="$IFS"; IFS=':'; set -- $macaddr; IFS="$oldIFS"
18

    
19
        echo "fe80::$(xor2 "$1")$2:$3ff:fe$4:$5$6"
20
}
21

    
22
sudo ip link add "${BRIDGE}" type bridge
23
for i in `seq 1 5`; do
24
	sudo ip tuntap add dev tap$i mode tap user "$USER"
25
	sudo ip link set tap$i up
26
	sudo ip link set tap$i master "${BRIDGE}"
27
done
28

    
29
sudo ip link set "${BRIDGE}" up
30

    
31
sudo ip addr add "$(interface_linklocal)"/64 dev "$ETH"
32
sudo ip link del "${VXLAN}"
33
sudo ip -6 link add "${VXLAN}" type vxlan \
34
   id "${VXLAN_ID}" \
35
   dstport 4789 \
36
   local "$(interface_linklocal)" \
37
   group ff02::15c \
38
   dev "${ETH}" \
39
   udp6zerocsumtx udp6zerocsumrx \
40
   ttl 1
41

    
42
sudo ip link set "${VXLAN}" up master "${BRIDGE}"
43
sudo ip addr replace 192.168.2.1/24 dev "${BRIDGE}"