summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
Diffstat (limited to 'data')
-rw-r--r--data/configd-include.json1
-rw-r--r--data/templates/frr/static.frr.tmpl38
-rw-r--r--data/templates/frr/static_routes_macro.j215
-rw-r--r--data/templates/frr/vrf.frr.tmpl34
4 files changed, 61 insertions, 27 deletions
diff --git a/data/configd-include.json b/data/configd-include.json
index c0263127a..d2789e285 100644
--- a/data/configd-include.json
+++ b/data/configd-include.json
@@ -39,6 +39,7 @@
"protocols_ospfv3.py",
"protocols_pim.py",
"protocols_rip.py",
+"protocols_static.py",
"protocols_static_multicast.py",
"protocols_vrf.py",
"salt-minion.py",
diff --git a/data/templates/frr/static.frr.tmpl b/data/templates/frr/static.frr.tmpl
new file mode 100644
index 000000000..bb0ec80a5
--- /dev/null
+++ b/data/templates/frr/static.frr.tmpl
@@ -0,0 +1,38 @@
+{% from 'frr/static_routes_macro.j2' import static_routes %}
+!
+{# IPv4 routing #}
+{% if route is defined and route is not none %}
+{% for prefix, prefix_config in route.items() %}
+{{ static_routes('ip', prefix, prefix_config) }}
+{%- endfor -%}
+{% endif %}
+!
+{# IPv6 routing #}
+{% if route6 is defined and route6 is not none %}
+{% for prefix, prefix_config in route6.items() %}
+{{ static_routes('ipv6', prefix, prefix_config) }}
+{%- endfor -%}
+{% endif %}
+!
+{# Policy route tables #}
+{% if table is defined and table is not none %}
+{% for table_id, table_config in table.items() %}
+{% if table_config.route is defined and table_config.route is not none %}
+{% for prefix, prefix_config in table_config.route.items() %}
+{{ static_routes('ip', prefix, prefix_config, table_id) }}
+{%- endfor -%}
+{% endif %}
+!
+{% if table_config.route6 is defined and table_config.route6 is not none %}
+{% for prefix, prefix_config in table_config.route6.items() %}
+{{ static_routes('ipv6', prefix, prefix_config, table_id) }}
+{%- endfor -%}
+{% endif %}
+!
+{% endfor %}
+{% endif %}
+!
+{% if route_map is defined and route_map is not none %}
+ip protocol static route-map {{ route_map }}
+!
+{% endif %}
diff --git a/data/templates/frr/static_routes_macro.j2 b/data/templates/frr/static_routes_macro.j2
new file mode 100644
index 000000000..aadb2805e
--- /dev/null
+++ b/data/templates/frr/static_routes_macro.j2
@@ -0,0 +1,15 @@
+{% macro static_routes(ip_ipv6, prefix, prefix_config, table=None) %}
+{% if prefix_config.blackhole is defined %}
+{{ ip_ipv6 }} route {{ prefix }} blackhole {{ prefix_config.blackhole.distance if prefix_config.blackhole.distance is defined }} {{ 'tag ' + prefix_config.blackhole.tag if prefix_config.blackhole.tag is defined }} {{ 'table ' + table if table is defined and table is not none }}
+{% endif %}
+{% if prefix_config.interface is defined and prefix_config.interface is not none %}
+{% for interface, interface_config in prefix_config.interface.items() if interface_config.disable is not defined %}
+{{ ip_ipv6 }} route {{ prefix }} {{ interface }} {{ interface_config.distance if interface_config.distance is defined }} {{ 'nexthop-vrf ' + interface_config.vrf if interface_config.vrf is defined }} {{ 'table ' + table if table is defined and table is not none }}
+{% endfor %}
+{% endif %}
+{% if prefix_config.next_hop is defined and prefix_config.next_hop is not none %}
+{% for next_hop, next_hop_config in prefix_config.next_hop.items() if next_hop_config.disable is not defined %}
+{{ ip_ipv6 }} route {{ prefix }} {{ next_hop }} {{ next_hop_config.interface if next_hop_config.interface is defined }} {{ next_hop_config.distance if next_hop_config.distance is defined }} {{ 'nexthop-vrf ' + next_hop_config.vrf if next_hop_config.vrf is defined }} {{ 'table ' + table if table is defined and table is not none }}
+{% endfor %}
+{% endif %}
+{% endmacro %}
diff --git a/data/templates/frr/vrf.frr.tmpl b/data/templates/frr/vrf.frr.tmpl
index 1cb055962..0c8726908 100644
--- a/data/templates/frr/vrf.frr.tmpl
+++ b/data/templates/frr/vrf.frr.tmpl
@@ -1,3 +1,4 @@
+{% from 'frr/static_routes_macro.j2' import static_routes %}
!
{% if vrf is defined and vrf is not none %}
{% for vrf_name, vrf_config in vrf.items() %}
@@ -5,36 +6,15 @@ vrf {{ vrf_name }}
{% if vrf_config.static is defined and vrf_config.static is not none %}
{# IPv4 routes #}
{% if vrf_config.static.route is defined and vrf_config.static.route is not none %}
-{% for route, route_config in vrf_config.static.route.items() %}
-{% if route_config.blackhole is defined %}
- ip route {{ route }} blackhole {{ route_config.blackhole.distance if route_config.blackhole.distance is defined }}
-{% elif route_config.interface is defined and route_config.interface is not none %}
-{% for interface, interface_config in route_config.interface.items() if interface_config.disable is not defined %}
- ip route {{ route }} {{ interface }} {{ interface_config.distance if interface_config.distance is defined }} {{ 'nexthop-vrf ' + interface_config.vrf if interface_config.vrf is defined }}
-{% endfor %}
-{% elif route_config.next_hop is defined and route_config.next_hop is not none %}
-{% for next_hop, next_hop_config in route_config.next_hop.items() if next_hop_config.disable is not defined %}
- ip route {{ route }} {{ next_hop }} {{ next_hop_config.interface if next_hop_config.interface is defined }} {{ next_hop_config.distance if next_hop_config.distance is defined }} {{ 'nexthop-vrf ' + next_hop_config.vrf if next_hop_config.vrf is defined }}
-{% endfor %}
-{% endif %}
-{% endfor %}
+{% for prefix, prefix_config in vrf_config.static.route.items() %}
+ {{ static_routes('ip', prefix, prefix_config) }}
+{%- endfor -%}
{% endif %}
{# IPv6 routes #}
{% if vrf_config.static.route6 is defined and vrf_config.static.route6 is not none %}
-{% for route, route_config in vrf_config.static.route6.items() %}
-{% if route_config.blackhole is defined %}
- ipv6 route {{ route }} blackhole {{ route_config.blackhole.distance if route_config.blackhole.distance is defined }}
-{% elif route_config.interface is defined and route_config.interface is not none %}
-{% for interface, interface_config in route_config.interface.items() if interface_config.disable is not defined %}
- ipv6 route {{ route }} {{ interface }} {{ interface_config.distance if interface_config.distance is defined }} {{ 'nexthop-vrf ' + interface_config.vrf if interface_config.vrf is defined }}
-{% endfor %}
-{% elif route_config.next_hop is defined and route_config.next_hop is not none %}
-{% for next_hop, next_hop_config in route_config.next_hop.items() if next_hop_config.disable is not defined %}
- ipv6 route {{ route }} {{ next_hop }} {{ next_hop_config.interface if next_hop_config.interface is defined }} {{ next_hop_config.distance if next_hop_config.distance is defined }} {{ 'nexthop-vrf ' + next_hop_config.vrf if next_hop_config.vrf is defined }}
-{% endfor %}
-{% endif %}
-
-{% endfor %}
+{% for prefix, prefix_config in vrf_config.static.route6.items() %}
+ {{ static_routes('ipv6', prefix, prefix_config) }}
+{%- endfor -%}
{% endif %}
{% endif %}
{% endfor %}