]> git.proxmox.com Git - pve-firewall.git/commitdiff
split parser out of get_etc_protocols
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 28 Mar 2018 08:53:24 +0000 (10:53 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 28 Mar 2018 09:35:06 +0000 (11:35 +0200)
Into a reusable parse_protocol_file.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Reviewed-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Tested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PVE/Firewall.pm

index 038d560c0ade9a5e76d297d6728e158ced2bf34e..d8f05d85b4efa64958c54965fbc2d2cca671eaae 100644 (file)
@@ -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};