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