#
# {{ ansible_managed }}
#

# Variables
define router_id = {{ bgp_loopback_net | ipaddr('net') | ipaddr(magic) | ipaddr('address') }};
define mwu_address = {{ bgp_ipv6_transfer_net | ipaddr('net') | ipaddr(magic) | ipaddr('address') }};
define mwu_as = {{ as_private_mwu }};

# General
timeformat protocol iso long;
router id router_id;

# Functions
function is_default() {
    return net ~ [
        ::/0
    ];
}

function is_ula() {
    return net ~ [
        fc00::/7{48,64}
    ];
}

function is_mwu_self_nets() {
    return net ~ [
{% for mesh in meshes %}
{% for ula in mesh.ipv6_ula %}
        {{ ula | ipaddr('net') }}+{{ "," if not loop.last else "" }}{% endfor %}{{ "," if not loop.last else "" }}
{% endfor %}
    ];
}

# Protocols
protocol device {
    scan time 30;
};

protocol direct mwu_subnets {
{% for mesh in meshes %}
    interface "{{ mesh.id }}br";
{% endfor %}
    import where is_mwu_self_nets();
};

# Templates
template bgp ibgp_mwu {
    local mwu_address as mwu_as;
    import keep filtered on;
    import all;
    export where source = RTS_BGP;
    direct;
    gateway direct;
};

# Include IPv6 MWU peers
include "mwu_ipv6_peers.con?";

# Include IPv6 ICVPN configuration
include "icvpn_ipv6.con?";

# Include IPv6 FFRL configuration
include "ffrl_ipv6.con?";