{{ ansible_managed | comment }} log syslog all; router id {{ bird__router_id }}; protocol device { scan time 10; } protocol direct { ipv4; ipv6; } protocol kernel kernel4 { ipv4 { import all; export where source !~ [ RTS_DEVICE, RTS_STATIC ]; }; } protocol kernel kernel6 { ipv6 { import all; export where source !~ [ RTS_DEVICE, RTS_STATIC ]; }; } {% if bird__static_unreachable | ansible.utils.ipv4 %} protocol static unreachable4 { ipv4 { import all; }; {% for route in bird__static_unreachable | ansible.utils.ipv4 %} route {{ route }} unreachable; {% endfor %} } {% endif %} {% if bird__static_unreachable | ansible.utils.ipv6 %} protocol static unreachable6 { ipv6 { import all; }; {% for route in bird__static_unreachable | ansible.utils.ipv6 %} route {{ route }} unreachable; {% endfor %} } {% endif %} {% if bird__ospf_broadcast_interfaces %} protocol ospf v2 ospf4 { ipv4 { import all; export where source ~ [ RTS_STATIC, RTS_DEVICE ]; }; area 0 { {% for network in bird__ospf_stub_networks | ansible.utils.ipv4 %} stubnet {{ network }}; {% endfor %} {% for name, iface in bird__ospf_broadcast_interfaces.items() %} interface {{ name | enquote }} { type broadcast; hello {{ iface.hello | default(bird__ospf_hello) | int }}; retransmit {{ iface.retransmit | default(bird__ospf_retransmit) | int }}; wait {{ iface.wait | default(bird__ospf_wait) | int }}; dead {{ iface.dead | default(bird__ospf_dead) | int }}; }; {% endfor %} {% for name in bird__ospf_stub_interfaces %} interface {{ name | enquote }} { stub; }; {% endfor %} }; } {% endif %} {% if bird__ospf_broadcast_interfaces %} protocol ospf v3 ospf6 { ipv6 { import all; export where source ~ [ RTS_STATIC, RTS_DEVICE ]; }; area 0 { {% for network in bird__ospf_stub_networks | ansible.utils.ipv6 %} stubnet {{ network }}; {% endfor %} {% for name, iface in bird__ospf_broadcast_interfaces.items() %} interface {{ name | enquote }} { type broadcast; hello {{ iface.hello | default(bird__ospf_hello) | int }}; retransmit {{ iface.retransmit | default(bird__ospf_retransmit) | int }}; wait {{ iface.wait | default(bird__ospf_wait) | int }}; dead {{ iface.dead | default(bird__ospf_dead) | int }}; }; {% endfor %} {% for name in bird__ospf_stub_interfaces %} interface {{ name | enquote }} { stub; }; {% endfor %} }; } {% endif %} {% macro bird_filter(filter, last) %} {% 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 %} {% if filter.accept is defined %} {{ filter.accept | ternary("accept", "reject") }}; {% endif %} {% endmacro %} {# FIXME: massive cleanup required #} {% for session in bird__bgp_sessions %} {% for version in [4, 6] %} {% for direction in ["import", "export"] %} filter bgp{{ version }}_{{ direction }}_{{ session.name }} { {% for filter in session[direction] %} {% set negate = filter.negate | default(False) %} {% set networks = filter.prefix | default([]) | ansible.utils.ipaddr(version=version) | map("suffix", filter.sub | default(False) | 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 %} {% if networks %} {% set op = negate | ternary("!~", "~") %} if net {{ op }} [ {{ networks | join(", ") }} ] then { {% elif bgp_protos %} {% set op = negate | ternary("&&", "||") %} if {{ bgp_protos | join(" " + op + " ") }} then { {% endif %} {{ bird_filter(filter) | indent(8) }} } {% else %} {{ bird_filter(filter) | indent(4) }} {% endif %} {% endfor %} } {% endfor %} {% endfor %} {% endfor %} {% for session in bird__bgp_sessions %} {% 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{{ version }}_{{ session.name }} { local {{ local_address }} as {{ session.local.as }}; neighbor {{ remote_address }} as {{ session.remote.as }}; {{ "ipv4" if version == 4 else "ipv6" }} { {% if session.next_hop_self | default(False) %} next hop self; {% endif %} import filter bgp{{ version }}_import_{{ session.name }}; export filter bgp{{ version }}_export_{{ session.name }}; }; } {% endfor %} {% endfor %} {% 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 %} } {% endif %}