bird: add IPv6 support

This commit is contained in:
jeltz 2022-12-21 18:43:00 +01:00
parent 618cad720a
commit 99ba67f074
Signed by: jeltz
GPG key ID: 800882B66C0C3326

View file

@ -1,4 +1,4 @@
{{ ansible_managed | comment }}
P{{ ansible_managed | comment }}
log syslog all;
@ -113,81 +113,112 @@ protocol ospf v3 ospf6 {
}
{% for session in bird__bgp_sessions %}
protocol bgp {{ session.name }} {
local as {{ session.local.as }};
source address {{ session.local.address }};
neighbor {{ session.remote.address }} as {{ session.remote.as }};
ipv4 {
import filter {
{% for pref in session.import.local_pref | default([]) %}
{% for local_address in session.local.address %}
{%
set networks =
pref.prefix
| product("+" if pref.sub else "")
| map("join")
| join(", ")
set version =
local_address
| ansible.utils.ipaddr(query="version")
%}
{% set operator = '!~' if pref.negate | default(False) else '~' %}
if (net {{ operator }} [ {{ networks }} ]) then {
{%
set remote_address =
session.remote.address
| ansible.utils.ipaddr(version=version)
| first
%}
protocol bgp bgp_{{ session.name }}{{ version }} {
local {{ local_address }} as {{ session.local.as }};
neighbor {{ remote_address }} as {{ session.remote.as }};
{{ "ipv4" if version == 4 else "ipv6" }} {
import filter {
{% for pref in session.import.local_pref | default([]) %}
{%
set networks =
pref.prefix
| default([])
| ansible.utils.ipaddr(version=version)
| map("suffix", pref.sub
| default(False)
| ternary("+", ""))
%}
{% set operator = pref.negate | default(False) | ternary("!~", "~") %}
{% if networks %}
if net {{ operator }} [ {{ networks | join(", ") }} ] then {
bgp_local_pref = {{ pref.pref | int }};
}
{% endfor %}
{% if session.import.accept == "all" %}
accept;
{% else %}
{% for accept in session.import.accept | default([]) %}
{%
set networks =
accept.prefix
| product("+" if accept.sub else "")
| map("join")
| join(", ")
%}
{% set operator = '!~' if accept.negate | default(False) else '~' %}
if (net {{ operator }} [ {{ networks }} ]) then accept;
{% endif %}
{% endfor %}
{% if session.import.accept == "all" %}
accept;
{% else %}
{% for accept in session.import.accept | default([]) %}
{%
set networks =
accept.prefix
| default([])
| ansible.utils.ipaddr(version=version)
| map("suffix", accept.sub
| default(False)
| ternary("+", ""))
%}
{% set operator = accept.negate | default(False) | ternary("!~", "~") %}
{% if networks %}
if net {{ operator }} [ {{ networks | join(",") }} ] then accept;
{% endif %}
{% endfor %}
reject;
{% endif %}
{% endif %}
};
export filter {
{% for prepend in session.export.as_prepend | default([]) %}
{%
set networks =
prepend.prefix
| product("+" if prepend.sub else "")
| map("join")
| join(", ")
%}
{% set operator = '!~' if prepend.negate | default(False) else '~' %}
if (net {{ operator }} [ {{ networks }} ]) then {
{% for _ in range(prepend.size) %}
bgp_path.prepend({{ session.local.as }});
{% endfor %}
}
{% endfor %}
{% if session.export.accept == "all" %}
accept;
{% else %}
{% for accept in session.export.accept | default([]) %}
{% for prepend in session.export.as_prepend | default([]) %}
{%
set networks =
accept.prefix
| product("+" if accept.sub else "")
| map("join")
| join(", ")
prepend.prefix
| default([])
| ansible.utils.ipaddr(version=version)
| map("suffix", prepend.sub
| default(False)
| ternary("+", ""))
%}
{% set operator = '!~' if accept.negate | default(False) else '~' %}
if (net {{ operator }} [ {{ networks }} ]) then accept;
{% set operator = prepend.negate | default(False) | ternary("!~", "~") %}
{% if networks %}
if net {{ operator }} [ {{ networks | join(", ") }} ] then {
{% for _ in range(prepend.size) %}
bgp_path.prepend({{ session.local.as }});
{% endfor %}
}
{% endif %}
{% endfor %}
{% if session.export.accept == "all" %}
accept;
{% else %}
{% for accept in session.export.accept | default([]) %}
{%
set networks =
accept.prefix
| default([])
| ansible.utils.ipaddr(version=version)
| map("suffix", accept.sub
| default(False)
| ternary("+", ""))
%}
{% set operator = accept.negate | default(False) | ternary("!~", "~") %}
{% if networks %}
if net {{ operator }} [ {{ networks | join(", ") }} ] then accept;
{% endif %}
{% endfor %}
reject;
{% endif %}
{% endif %}
};
};
}
{% endfor %}
{% endfor %}
{% if bird__radv_interfaces %}