From e43dff6452cc6bbf0bb437f39a32b17c864eb37d Mon Sep 17 00:00:00 2001 From: Ivan Pepelnjak Date: Wed, 25 Mar 2026 17:22:49 +0100 Subject: [PATCH] Use bgp.advertise attribute in global Junos BGP advertise policy * We have to generate per-AF route-filter-list (thank you, Juniper) * The per-AF route-filter-lists are used in bgp-advertise policy statement instead of interface/static/... matches * This will also work with the bgp.advertise attribute once #3236 is merged --- netsim/ansible/templates/bgp/junos.policy.j2 | 41 +++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/netsim/ansible/templates/bgp/junos.policy.j2 b/netsim/ansible/templates/bgp/junos.policy.j2 index 06f44b3638..b96fb19373 100644 --- a/netsim/ansible/templates/bgp/junos.policy.j2 +++ b/netsim/ansible/templates/bgp/junos.policy.j2 @@ -27,11 +27,17 @@ policy-options { policy-options { - route-filter-list bgp-announce { -{% for pfx in bgp.originate|default([]) %} - {{ pfx|ansible.utils.ipaddr('0') }} exact; -{% endfor %} +{% for bgp_af in af %} +{% for pfx in bgp.advertise|default([]) if bgp_af in pfx %} +{% if loop.first %} + route-filter-list bgp-announce-{{ bgp_af }} { +{% endif %} + {{ pfx[bgp_af] }} exact; +{% if loop.last %} } +{% endif %} +{% endfor %} +{% endfor %} {% for af in ('ipv4','ipv6') %} {% for nh in ['ebgp','all'] %} @@ -53,32 +59,21 @@ policy-options { {% endfor %} policy-statement bgp-advertise { - term advertise { - from { - protocol direct; - interface [ - {% if bgp.advertise_loopback %} lo0.0 {% endif %} - {%- for l in interfaces if l.bgp.advertise|default("") and not 'vrf' in l %} - {{ l.ifname }} - {% endfor %} ]; - } - then { - community add x-route-permit-mark; - next policy; - } - } - - term originate { +{% for bgp_af in af %} +{% for pfx in bgp.advertise|default([]) if bgp_af in pfx %} +{% if loop.first %} + term advertise-{{ bgp_af }} { from { - protocol static; - route-filter-list bgp-announce; + route-filter-list bgp-announce-{{ bgp_af }}; } then { community add x-route-permit-mark; next policy; } } - +{% endif %} +{% endfor %} +{% endfor %} } policy-statement bgp-redistribute {