From 9a4dbd82acab47a44ebb5a2fa8fc597ef3d23d4c Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Sun, 15 Nov 2026 18:40:49 +1100 Subject: [PATCH] frrouting: exclude prefixes from connected redistribution (#575) The frr.conf template cannot filter `redistribute connected` except for k8s CIDRs, so a puppet run on prodnxsr0020 drops its hand-written default-route filter and leaks the WAN default route into OSPF. - add `frrouting::ospf_connected_exclude` to render a REDIST-BLOCK prefix-list and CONNECTED-EXCLUDE-REDIST route-map on `redistribute connected` - fail when combined with `ospf_exclude_k8s_enable` - exclude `0.0.0.0/0` on prodnxsr0020 Reviewed-on: https://git.unkin.net/unkin/puppet-prod/pulls/575 Co-authored-by: unkin-agent Co-committed-by: unkin-agent --- hieradata/nodes/prodnxsr0020.main.unkin.net.yaml | 2 ++ modules/frrouting/manifests/init.pp | 5 +++++ modules/frrouting/templates/frr.conf.erb | 14 ++++++++++++++ 3 files changed, 21 insertions(+) diff --git a/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml b/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml index 4d58a76..43308fe 100644 --- a/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml +++ b/hieradata/nodes/prodnxsr0020.main.unkin.net.yaml @@ -43,3 +43,5 @@ frrouting::ospfd_interfaces: area: 0.0.0.0 frrouting::ospf_preferred_source_enable: true frrouting::ospf_preferred_source: "%{hiera('networking_loopback1_ip')}" +frrouting::ospf_connected_exclude: + - 0.0.0.0/0 diff --git a/modules/frrouting/manifests/init.pp b/modules/frrouting/manifests/init.pp index 53d5d85..daf451a 100644 --- a/modules/frrouting/manifests/init.pp +++ b/modules/frrouting/manifests/init.pp @@ -19,6 +19,7 @@ class frrouting ( Boolean $ospf_exclude_k8s_enable = false, Optional[Stdlib::IP::Address::V4::CIDR] $k8s_cluster_cidr = undef, # pod/cluster CIDR (e.g. 10.42.0.0/16) Optional[Stdlib::IP::Address::V4::CIDR] $k8s_service_cidr = undef, # service CIDR (e.g. 10.43.0.0/16) + Array[Stdlib::IP::Address::V4::CIDR] $ospf_connected_exclude = [], # exact-match prefixes kept out of redistribute connected ) { # sanity check @@ -26,6 +27,10 @@ class frrouting ( warning('frrouting: ospf_exclude_k8s_enable is true but no k8s_*_cidr provided; nothing will be filtered.') } + if $ospf_exclude_k8s_enable and !empty($ospf_connected_exclude) { + fail('frrouting: ospf_exclude_k8s_enable and ospf_connected_exclude are mutually exclusive.') + } + $daemons_defaults = { 'bgpd' => false, 'ospfd' => true, diff --git a/modules/frrouting/templates/frr.conf.erb b/modules/frrouting/templates/frr.conf.erb index eeee416..a1ba416 100644 --- a/modules/frrouting/templates/frr.conf.erb +++ b/modules/frrouting/templates/frr.conf.erb @@ -27,6 +27,18 @@ exit route-map CONNECTED-NON-K8S permit 100 exit <% end -%> +<% if @ospf_connected_exclude.any? -%> +! Do not redistribute default route +<% @ospf_connected_exclude.each_with_index do |prefix, i| -%> +ip prefix-list REDIST-BLOCK seq <%= (i + 1) * 5 %> permit <%= prefix %> +<% end -%> + +route-map CONNECTED-EXCLUDE-REDIST deny 5 + match ip address prefix-list REDIST-BLOCK +exit +route-map CONNECTED-EXCLUDE-REDIST permit 100 +exit +<% end -%> router ospf ospf router-id <%= @ospfd_router_id %> @@ -34,6 +46,8 @@ router ospf <% @ospfd_redistribute.each do |type| -%> <% if @ospf_exclude_k8s_enable && type == 'connected' && (@k8s_cluster_cidr || @k8s_service_cidr) -%> redistribute connected route-map CONNECTED-NON-K8S +<% elsif type == 'connected' && @ospf_connected_exclude.any? -%> + redistribute connected route-map CONNECTED-EXCLUDE-REDIST <% else -%> redistribute <%= type %> <% end -%>