[pve-devel] [RFC firewall 1/8] split parser out of get_etc_protocols
Wolfgang Bumiller
w.bumiller at proxmox.com
Wed Mar 28 10:53:24 CEST 2018
Into a reusable parse_protocol_file.
Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
src/PVE/Firewall.pm | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/PVE/Firewall.pm b/src/PVE/Firewall.pm
index 038d560..d8f05d8 100644
--- a/src/PVE/Firewall.pm
+++ b/src/PVE/Firewall.pm
@@ -876,12 +876,8 @@ sub get_etc_services {
return $etc_services;
}
-my $etc_protocols;
-
-sub get_etc_protocols {
- return $etc_protocols if $etc_protocols;
-
- my $filename = "/etc/protocols";
+sub parse_protocol_file {
+ my ($filename) = @_;
my $fh = IO::File->new($filename, O_RDONLY);
if (!$fh) {
@@ -904,6 +900,16 @@ sub get_etc_protocols {
close($fh);
+ return $protocols;
+}
+
+my $etc_protocols;
+
+sub get_etc_protocols {
+ return $etc_protocols if $etc_protocols;
+
+ my $protocols = parse_protocol_file('/etc/protocols');
+
# add special case for ICMP v6
$protocols->{byid}->{icmpv6}->{name} = "icmpv6";
$protocols->{byname}->{icmpv6} = $protocols->{byid}->{icmpv6};
--
2.11.0
More information about the pve-devel
mailing list