2022-12-21 21:01:47 +01:00
|
|
|
{{ ansible_managed | comment }}
|
2022-09-03 03:44:31 +02:00
|
|
|
|
|
|
|
log syslog all;
|
|
|
|
|
|
|
|
router id {{ bird__router_id }};
|
|
|
|
|
|
|
|
protocol device {
|
|
|
|
scan time 10;
|
|
|
|
}
|
|
|
|
|
2023-09-16 01:24:01 +02:00
|
|
|
{% for name, kernel in bird__kernel.items() %}
|
|
|
|
{% for version in ["ipv4", "ipv6"] %}
|
|
|
|
{% set ipv4 = version == "ipv4" %}
|
|
|
|
protocol kernel {{ name | bird_name(ipv4) }} {
|
|
|
|
{% if kernel.kernel is defined %}
|
|
|
|
kernel table {{ kernel.kernel }};
|
|
|
|
{% endif %}
|
|
|
|
{% if kernel.learn | default(False) %}
|
|
|
|
learn;
|
|
|
|
{% endif %}
|
|
|
|
{% if kernel.persist | default(False) %}
|
|
|
|
persist;
|
|
|
|
{% endif %}
|
|
|
|
{{ version }} {
|
|
|
|
{{ kernel.import
|
|
|
|
| default([])
|
|
|
|
| bird_import(ipv4)
|
|
|
|
| indent(8) }}
|
|
|
|
{% if kernel.limits.import is defined %}
|
|
|
|
import limit {{ kernel.limits.import }};
|
|
|
|
{% endif %}
|
|
|
|
{{ kernel.export
|
|
|
|
| default([])
|
|
|
|
| bird_export(ipv4)
|
|
|
|
| indent(8) }}
|
|
|
|
{% if kernel.limits.export is defined %}
|
|
|
|
export limit {{ kernel.limits.export }};
|
|
|
|
{% endif %}
|
|
|
|
};
|
2022-09-04 07:40:51 +02:00
|
|
|
}
|
2023-09-16 01:24:01 +02:00
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
2022-09-04 07:40:51 +02:00
|
|
|
|
2023-09-16 01:24:01 +02:00
|
|
|
{% if bird__ospf is defined %}
|
|
|
|
{% for version in ["ipv4", "ipv6"] %}
|
|
|
|
{% set ipv4 = version == "ipv4" %}
|
|
|
|
{% set ospf_version = "v2" if ipv4 else "v3" %}
|
|
|
|
protocol ospf {{ ospf_version }} {{ "ospf" | bird_name(ipv4) }} {
|
|
|
|
{{ version }} {
|
|
|
|
{{ bird__ospf.import
|
|
|
|
| default([])
|
|
|
|
| bird_import(ipv4)
|
|
|
|
| indent(8) }}
|
|
|
|
{% if bird__ospf.limits.import is defined %}
|
|
|
|
import limit {{ bird__ospf.limits.import }};
|
|
|
|
{% endif %}
|
|
|
|
{{ bird__ospf.export
|
|
|
|
| default([])
|
|
|
|
| bird_export(ipv4)
|
|
|
|
| indent(8) }}
|
|
|
|
{% if bird__ospf.limits.export is defined %}
|
|
|
|
export limit {{ bird__ospf.limits.export }};
|
|
|
|
{% endif %}
|
|
|
|
};
|
|
|
|
{% for id, area in bird__ospf.areas.items() %}
|
|
|
|
area {{ id }} {
|
|
|
|
{% for iface in area.broadcast | default([]) %}
|
|
|
|
interface {{ iface | enquote }} {
|
|
|
|
type broadcast;
|
|
|
|
hello 2;
|
|
|
|
retransmit 5;
|
|
|
|
wait 10;
|
|
|
|
dead 20;
|
|
|
|
};
|
|
|
|
{% endfor %}
|
|
|
|
{% for iface in area.stub | default([]) %}
|
|
|
|
interface {{ iface | enquote }} { stub; };
|
|
|
|
{% endfor %}
|
2022-09-03 03:44:31 +02:00
|
|
|
};
|
2023-09-16 01:24:01 +02:00
|
|
|
{% endfor %}
|
2022-09-03 03:44:31 +02:00
|
|
|
}
|
2023-09-16 01:24:01 +02:00
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
2022-09-03 03:44:31 +02:00
|
|
|
|
2023-09-16 01:24:01 +02:00
|
|
|
{% for name, bgp in bird__bgp.items() %}
|
|
|
|
{% for version in ["ipv4", "ipv6"] %}
|
|
|
|
{% set ipv4 = version == "ipv4" %}
|
|
|
|
protocol bgp {{ name | bird_name(ipv4) }} {
|
|
|
|
local {{ bgp.local.address
|
|
|
|
| ansible.utils.ipaddr(version)
|
|
|
|
| first }} as {{ bgp.local.as }};
|
|
|
|
neighbor {{ bgp.neighbor.address
|
|
|
|
| ansible.utils.ipaddr(version)
|
|
|
|
| first }} as {{ bgp.neighbor.as }};
|
|
|
|
{{ version }} {
|
|
|
|
{{ bgp.import
|
|
|
|
| default([])
|
|
|
|
| bird_import(ipv4)
|
|
|
|
| indent(8) }}
|
|
|
|
{% if bgp.limits.import is defined %}
|
|
|
|
import limit {{ bgp.limits.import }};
|
|
|
|
{% endif %}
|
|
|
|
{{ bgp.export
|
|
|
|
| default([])
|
|
|
|
| bird_export(ipv4)
|
|
|
|
| indent(8) }}
|
|
|
|
{% if bgp.limits.export is defined %}
|
|
|
|
export limit {{ bgp.limits.export }};
|
|
|
|
{% endif %}
|
2022-09-03 03:44:31 +02:00
|
|
|
};
|
|
|
|
}
|
2023-09-16 01:24:01 +02:00
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
2022-09-03 03:44:31 +02:00
|
|
|
|
2023-09-16 01:24:01 +02:00
|
|
|
{# {% if bird__static_unreachable | ansible.utils.ipv4 %}
|
2022-12-21 16:39:28 +01:00
|
|
|
protocol static unreachable4 {
|
2022-12-21 19:53:40 +01:00
|
|
|
ipv4 {
|
2022-12-22 11:00:37 +01:00
|
|
|
import all;
|
2022-12-21 19:53:40 +01:00
|
|
|
};
|
2022-12-21 16:39:28 +01:00
|
|
|
{% for route in bird__static_unreachable | ansible.utils.ipv4 %}
|
2022-12-21 19:53:40 +01:00
|
|
|
route {{ route }} unreachable;
|
2022-12-21 16:39:28 +01:00
|
|
|
{% endfor %}
|
|
|
|
}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{% if bird__static_unreachable | ansible.utils.ipv6 %}
|
|
|
|
protocol static unreachable6 {
|
2022-12-21 19:53:40 +01:00
|
|
|
ipv6 {
|
2022-12-22 11:00:37 +01:00
|
|
|
import all;
|
2022-12-21 19:53:40 +01:00
|
|
|
};
|
2022-12-21 16:39:28 +01:00
|
|
|
{% for route in bird__static_unreachable | ansible.utils.ipv6 %}
|
2022-12-21 19:53:40 +01:00
|
|
|
route {{ route }} unreachable;
|
2022-12-21 16:39:28 +01:00
|
|
|
{% endfor %}
|
|
|
|
}
|
2023-09-16 01:24:01 +02:00
|
|
|
{% endif %} #}
|
2022-12-21 16:39:28 +01:00
|
|
|
|
2023-09-16 01:24:01 +02:00
|
|
|
{# {% macro bird_filter(filter, last) %}
|
2022-12-22 12:02:56 +01:00
|
|
|
{% if filter.as_prepend is defined %}
|
|
|
|
{% for _ in range(filter.as_prepend.size) %}
|
|
|
|
bgp_path.prepend({{ filter.as_prepend.asn }});
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% if filter.local_pref is defined %}
|
|
|
|
bgp_local_pref = {{ filter.local_pref }};
|
|
|
|
{% endif %}
|
2023-01-07 08:53:44 +01:00
|
|
|
{% if filter.accept is defined %}
|
2022-12-22 12:35:32 +01:00
|
|
|
{{ filter.accept | ternary("accept", "reject") }};
|
2022-12-22 12:02:56 +01:00
|
|
|
{% endif %}
|
2022-12-22 13:12:24 +01:00
|
|
|
{% endmacro %}
|
2022-09-03 03:44:31 +02:00
|
|
|
|
2023-07-05 01:20:47 +02:00
|
|
|
{% for name, session in bird__bgp_sessions.items() %}
|
2022-12-22 12:02:56 +01:00
|
|
|
{% for version in [4, 6] %}
|
|
|
|
{% for direction in ["import", "export"] %}
|
2023-07-05 01:20:47 +02:00
|
|
|
filter bgp{{ version }}_{{ direction }}_{{ name }} {
|
2022-12-22 12:02:56 +01:00
|
|
|
{% for filter in session[direction] %}
|
2023-01-07 08:53:44 +01:00
|
|
|
{% set negate = filter.negate | default(False) %}
|
2022-12-22 12:02:56 +01:00
|
|
|
{% set networks =
|
|
|
|
filter.prefix
|
|
|
|
| default([])
|
|
|
|
| ansible.utils.ipaddr(version=version)
|
|
|
|
| map("suffix", filter.sub
|
|
|
|
| default(False)
|
2023-01-07 08:53:44 +01:00
|
|
|
| ternary("+", ""))
|
|
|
|
| list %}
|
|
|
|
{% set bgp_protos =
|
|
|
|
filter.bgp_proto
|
|
|
|
| default([])
|
|
|
|
| map("format_rev", 'proto {1} "bgp{2}_{0}"',
|
|
|
|
negate | ternary("!=", "="), version)
|
|
|
|
| list %}
|
|
|
|
{% if networks or bgp_protos %}
|
2022-12-22 12:02:56 +01:00
|
|
|
{% if networks %}
|
2023-01-07 08:53:44 +01:00
|
|
|
{% set op = negate | ternary("!~", "~") %}
|
2022-12-22 12:02:56 +01:00
|
|
|
if net {{ op }} [ {{ networks | join(", ") }} ] then {
|
2023-01-07 08:53:44 +01:00
|
|
|
{% elif bgp_protos %}
|
|
|
|
{% set op = negate | ternary("&&", "||") %}
|
|
|
|
if {{ bgp_protos | join(" " + op + " ") }} then {
|
|
|
|
{% endif %}
|
2022-12-22 12:12:01 +01:00
|
|
|
{{ bird_filter(filter) | indent(8) }}
|
2022-12-22 12:02:56 +01:00
|
|
|
}
|
|
|
|
{% else %}
|
2022-12-22 12:12:01 +01:00
|
|
|
{{ bird_filter(filter) | indent(4) }}
|
2022-12-22 12:02:56 +01:00
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
}
|
2022-12-22 13:12:24 +01:00
|
|
|
|
2022-12-22 12:02:56 +01:00
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
{% endfor %}
|
|
|
|
|
2023-07-05 01:20:47 +02:00
|
|
|
{% for name, session in bird__bgp_sessions.items() %}
|
2022-12-22 12:02:56 +01:00
|
|
|
{% 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 %}
|
2023-07-05 01:20:47 +02:00
|
|
|
protocol bgp bgp{{ version }}_{{ name }} {
|
2022-12-21 18:43:00 +01:00
|
|
|
local {{ local_address }} as {{ session.local.as }};
|
|
|
|
neighbor {{ remote_address }} as {{ session.remote.as }};
|
|
|
|
{{ "ipv4" if version == 4 else "ipv6" }} {
|
2023-01-07 08:53:44 +01:00
|
|
|
{% if session.next_hop_self | default(False) %}
|
|
|
|
next hop self;
|
2023-03-26 17:06:34 +02:00
|
|
|
{% endif %}
|
|
|
|
{% if session.direct | default(False) %}
|
|
|
|
direct;
|
2023-01-07 08:53:44 +01:00
|
|
|
{% endif %}
|
2023-07-05 01:20:47 +02:00
|
|
|
import filter bgp{{ version }}_import_{{ name }};
|
|
|
|
export filter bgp{{ version }}_export_{{ name }};
|
2022-12-21 16:39:28 +01:00
|
|
|
};
|
|
|
|
}
|
2022-12-22 12:02:56 +01:00
|
|
|
{% endfor %}
|
2022-12-21 16:39:28 +01:00
|
|
|
{% endfor %}
|
|
|
|
|
2022-09-03 03:44:31 +02:00
|
|
|
{% if bird__radv_interfaces %}
|
|
|
|
protocol radv {
|
|
|
|
{% for name, iface in bird__radv_interfaces.items() %}
|
|
|
|
interface {{ name | enquote }} {
|
|
|
|
max ra interval {{ bird__radv_max_interval | int }};
|
|
|
|
{% for prefix in iface.prefix | default([]) %}
|
|
|
|
prefix {{ prefix | ipaddr }};
|
|
|
|
{% endfor %}
|
|
|
|
{% for domain in iface.domain_search | default([]) %}
|
|
|
|
dnssl {{ domain | enquote }};
|
|
|
|
{% endfor %}
|
|
|
|
};
|
|
|
|
{% endfor %}
|
|
|
|
{% for address in bird__radv_dns_servers %}
|
|
|
|
rdnss {{ address | ipaddr }};
|
|
|
|
{% endfor %}
|
|
|
|
}
|
2023-09-16 01:24:01 +02:00
|
|
|
{% endif %} #}
|