#!/bin/bash

BRIDGE="{{ l2_bridge_name }}"

BRCTL=`which brctl`
IP=`which ip`

BRIDGE_ADDR="{{ l2_bridge_ipaddr }}/{{ l2_bridge_ipmask }}"
L2_EXT_IF="{{ l2_iface }}"
L2_STCP="{{ tap_iface_name }}"

# Create bridge
${BRCTL} addbr ${BRIDGE}

# Assign address to the bridge - for debug purposes
${IP} address add ${BRIDGE_ADDR} dev ${BRIDGE}

# Put corresponding interfaces to the bridge
${IP} link set dev ${L2_EXT_IF} master ${BRIDGE}
${IP} link set dev ${L2_STCP} master ${BRIDGE}

# Bring links UP
${IP} link set dev ${L2_EXT_IF} up
${IP} link set dev ${L2_STCP} up
${IP} link set dev ${BRIDGE} up