#!/bin/sh

if [ $# -ne 3 ]; then
    echo "$0 brid dev ip"
    echo "f.g. $0 100 vxlan100 fd00:/64"
    echo "Missing arguments" >&2
    exit 1
fi

brid=$1; shift
dev=$1; shift
ip=$1; shift
bridge=br${brid}

sysctl net.ipv6.conf.all.forwarding=1 > /dev/null

if ! ip link show $bridge > /dev/null 2> /dev/null; then
    ip link add name $bridge type bridge
    ip link set $bridge up
    ip link set $dev master $bridge
    ip address add $ip dev $bridge
fi

echo $bridge