{% if bgp_mynet|default(false) %}
define mynet6 = {{ bgp_mynet }};
{% endif %}
define tnet = {{ tnet }};
define tnet_link = {{ tnet_link }};

log syslog all;

debug protocols all;

function is_tnet()
{
  return net ~ tnet && ! (net ~ tnet_link);
}

protocol device {
}
{% if bgp_mynet_if|default(False) %}

protocol direct {
  interface "{{ bgp_mynet_if }}";
  ipv6 {
    import all;
  };
}
{% endif %}

protocol kernel kernel6 {
  ipv6 {
    import none;
    export filter {
{% if bgp_mynet|default(false) %}
      if net ~ mynet6 then reject "is mynet, reject";
{% endif %}
      if is_tnet() then accept "is tnet, accept";
      reject "not tnet";
    };
  };
}
{% for peer in peers %}

protocol bgp {{ peer.name }} {
  local    as {{ bgp_as }};
  neighbor {{ peer.ip }} as {{ peer.as }};

  password "trygvis";

  ipv6 {
    next hop self;
    import filter {
      if is_tnet() then accept "from {{ peer.name }}, import accept";
      reject "from {{ peer.name }}, invalid tnet";
    };
    import keep filtered;
    export filter {
      if is_tnet() then accept "from {{ peer.name }}, export accept";
      reject "from {{ peer.name }}, invalid tnet";
    };
  };
}
{% endfor %}
{% if bgp_radv %}

protocol radv {{ bgp_radv_if }} {
  ipv6 {
    import all;
    export all;
  };

  interface "{{ bgp_radv_if }}" {
    max ra interval 600; # 10 for debugging
    default lifetime 0; # No not use this as a default gateway
    default preference low;

    prefix ::/0 {
      #autonomous off; # So do not autoconfigure any IP
    };
  };
}
{% endif %}