#!/bin/bash
#
set -e # Exit immediately when any command fails
#

# Create VRF tables
{% for vname,vdata in vrfs.items() %}
if [ ! -e /sys/devices/virtual/net/{{vname}} ]; then
ip link add {{vname}} type vrf table {{ vdata.vrfidx }}
fi
ip link set {{vname}} up
{% endfor %}

# Move interfaces and loopbacks to vrfs
{% for i in interfaces if i.vrf is defined %}
sysctl -qw net.ipv6.conf.{{ i.ifname }}.keep_addr_on_down=1
ip link set {{ i.ifname }} master {{ i.vrf }}
{% endfor %}

{% include "frr.frr-config.j2" +%}
exit $?
