Adjust BGP template to only emit a single set for multiple selected items with the same name

This commit is contained in:
Monviech 2026-05-22 11:19:44 +02:00
parent c6024d089c
commit 89437816d7

View file

@ -280,37 +280,48 @@ bgp community-list {{ communitylist.number }} seq {{ communitylist.seqnumber }}
{% for routemap in helpers.sortDictList(OPNsense.quagga.bgp.routemaps.routemap, 'name', 'id' ) %}
{% if routemap.enabled == '1' %}
route-map {{ routemap.name }} {{ routemap.action }} {{ routemap.id }}
{# XXX: Multiple lists that have the same name can be selected (intentionally), but each is stored as unique item. #}
{# The relationship is a bit loose, unique solves part of this issue. Match, Match2 and Match3 are affected. #}
{% if routemap.match|default("") != "" %}
{% set aspath_numbers = [] %}
{% for aspath in routemap.match.split(",") %}
{% set aspath_data = helpers.getUUID(aspath) %}
{% if 'match' in routemap and routemap.match != '' %}
match as-path {{ aspath_data.number }}
{% endif %}
{% do aspath_numbers.append(aspath_data.number) %}
{% endfor %}
{% for aspath_number in aspath_numbers | unique %}
match as-path {{ aspath_number }}
{% endfor %}
{% endif %}
{% if routemap.set|default("") != '' %}
set {{ routemap.set }}
{% endif %}
{% if routemap.match2|default("") != "" %}
{% set ipv4_prefixlist_names = [] %}
{% set ipv6_prefixlist_names = [] %}
{% for prefixlist in routemap.match2.split(",") %}
{% set prefixlist_data = helpers.getUUID(prefixlist) %}
{% if 'match2' in routemap and routemap.match2 != '' and ':' in prefixlist_data.network %}
match ipv6 address prefix-list {{ prefixlist_data.name }}
{% if ':' in prefixlist_data.network %}
{% do ipv6_prefixlist_names.append(prefixlist_data.name) %}
{% else %}
match ip address prefix-list {{ prefixlist_data.name }}
{% do ipv4_prefixlist_names.append(prefixlist_data.name) %}
{% endif %}
{% endfor %}
{% for prefixlist_name in ipv4_prefixlist_names | unique %}
match ip address prefix-list {{ prefixlist_name }}
{% endfor %}
{% for prefixlist_name in ipv6_prefixlist_names | unique %}
match ipv6 address prefix-list {{ prefixlist_name }}
{% endfor %}
{% endif %}
{% if routemap.match3|default("") != "" %}
{% set communitylist_numbers = [] %}
{% for communitylist in routemap.match3.split(",") %}
{% set communitylist_data = helpers.getUUID(communitylist) %}
{% if 'match3' in routemap and routemap.match3 != '' %}
match community {{ communitylist_data.number }}
{% endif %}
{% do communitylist_numbers.append(communitylist_data.number) %}
{% endfor %}
{% for communitylist_number in communitylist_numbers | unique %}
match community {{ communitylist_number }}
{% endfor %}
{% endif %}
{% if routemap.set|default("") != '' and routemap.match2|default("") != '' %}
set {{ routemap.set }}
{% endif %}
{% endif %}
{% endfor %}