From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 4F1458B17A for ; Wed, 24 Aug 2022 10:56:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 439327C70 for ; Wed, 24 Aug 2022 10:56:59 +0200 (CEST) Received: from bastionodiso.odiso.net (bastionodiso.odiso.net [IPv6:2a0a:1580:2000::2d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Wed, 24 Aug 2022 10:56:57 +0200 (CEST) Received: from kvmformation3.odiso.net (formationkvm3.odiso.net [10.3.94.12]) by bastionodiso.odiso.net (Postfix) with ESMTP id 26EA49E7B; Wed, 24 Aug 2022 10:56:51 +0200 (CEST) Received: by kvmformation3.odiso.net (Postfix, from userid 0) id 0FD331E0359; Wed, 24 Aug 2022 10:56:51 +0200 (CEST) From: Alexandre Derumier To: pve-devel@lists.proxmox.com Date: Wed, 24 Aug 2022 10:56:45 +0200 Message-Id: <20220824085646.561337-3-aderumier@odiso.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220824085646.561337-1-aderumier@odiso.com> References: <20220824085646.561337-1-aderumier@odiso.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.024 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% HEADER_FROM_DIFFERENT_DOMAINS 0.249 From and EnvelopeFrom 2nd level mail domains are different KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.001 Envelope sender has no MX or A DNS records SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH pve-network 2/3] frr: add a local config parser and merge with generated config X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 24 Aug 2022 08:56:59 -0000 some users with very specific config want to be able to add custom local config and merge it with generated config Signed-off-by: Alexandre Derumier --- PVE/Network/SDN/Controllers/EvpnPlugin.pm | 95 ++++++++++++++++++++--- 1 file changed, 86 insertions(+), 9 deletions(-) diff --git a/PVE/Network/SDN/Controllers/EvpnPlugin.pm b/PVE/Network/SDN/Controllers/EvpnPlugin.pm index 15b268b..2bc10f5 100644 --- a/PVE/Network/SDN/Controllers/EvpnPlugin.pm +++ b/PVE/Network/SDN/Controllers/EvpnPlugin.pm @@ -376,6 +376,28 @@ sub generate_frr_routemap { } } } + +sub generate_frr_accesslist { + my ($final_config, $accesslists) = @_; + + my @config = (); + + for my $id (sort keys %$accesslists) { + + my $accesslist = $accesslists->{$id}; + + for my $seq (sort keys %$accesslist) { + my $rule = $accesslist->{$seq}; + push @config, "access-list $id seq $seq $rule"; + } + } + + if(@config > 0) { + push @{$final_config}, "!"; + push @{$final_config}, @config; + } +} + sub generate_controller_rawconfig { my ($class, $plugin_config, $config) = @_; @@ -390,18 +412,14 @@ sub generate_controller_rawconfig { push @{$final_config}, "!"; if (-e "/etc/frr/frr.conf.local") { - generate_frr_recurse($final_config, $config->{frr}->{vrf}, "vrf", 1); - generate_frr_routemap($final_config, $config->{frr_routemap}); - push @{$final_config}, "!"; - my $local_conf = file_get_contents("/etc/frr/frr.conf.local"); - chomp ($local_conf); - push @{$final_config}, $local_conf; - } else { - generate_frr_recurse($final_config, $config->{frr}, undef, 0); - generate_frr_routemap($final_config, $config->{frr_routemap}); + parse_merge_frr_local_config($config, $local_conf); } + generate_frr_recurse($final_config, $config->{frr}, undef, 0); + generate_frr_accesslist($final_config, $config->{frr_access_list}); + generate_frr_routemap($final_config, $config->{frr_routemap}); + push @{$final_config}, "!"; push @{$final_config}, "line vty"; push @{$final_config}, "!"; @@ -412,6 +430,65 @@ sub generate_controller_rawconfig { return $rawconfig; } +sub parse_merge_frr_local_config { + my ($config, $local_conf) = @_; + + my $section = \$config->{""}; + my $router = undef; + my $routemap = undef; + my $routemap_config = (); + my $routemap_action = undef; + + while ($local_conf =~ /^\s*(.+?)\s*$/gm) { + my $line = $1; + $line =~ s/^\s+|\s+$//g; + + if ($line =~ m/^router (.+)$/) { + $router = $1; + $section = \$config->{'frr'}->{'router'}->{$router}->{""}; + next; + } elsif ($line =~ m/^vrf (.+)$/) { + $section = \$config->{'frr'}->{'vrf'}->{$1}; + next; + } elsif ($line =~ m/address-family (.+)$/) { + $section = \$config->{'frr'}->{'router'}->{$router}->{'address-family'}->{$1}; + next; + } elsif ($line =~ m/^route-map (.+) (permit|deny) (\d+)/) { + $routemap = $1; + $routemap_config = (); + $routemap_action = $2; + $section = \$config->{'frr_routemap'}->{$routemap}; + next; + } elsif ($line =~ m/^access-list (.+) seq (\d+) (.+)$/) { + $config->{'frr_access_list'}->{$1}->{$2} = $3; + next; + } elsif($line =~ m/^exit-address-family$/) { + next; + } elsif($line =~ m/^exit$/) { + if($router) { + $section = \$config->{''}; + $router = undef; + } elsif($routemap) { + push(@{$$section}, { rule => $routemap_config, action => $routemap_action }); + $section = \$config->{''}; + $routemap = undef; + $routemap_action = undef; + $routemap_config = (); + } + next; + } elsif($line =~ m/!/) { + next; + } + + next if !$section; + if($routemap) { + push(@{$routemap_config}, $line); + } else { + push(@{$$section}, $line); + } + } +} + sub write_controller_config { my ($class, $plugin_config, $config) = @_; -- 2.30.2