]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/Firewall.pm
parse_protocol_file: support lines without end comments
[pve-firewall.git] / src / PVE / Firewall.pm
index 038d560c0ade9a5e76d297d6728e158ced2bf34e..ac4850744a83571a5aec1340ace98997e0dfb48d 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) {
@@ -896,7 +892,7 @@ sub get_etc_protocols {
        next if $line =~m/^#/;
        next if ($line =~m/^\s*$/);
 
-       if ($line =~ m!^(\S+)\s+(\d+)\s+.*$!) {
+       if ($line =~ m!^(\S+)\s+(\d+)(?:\s+.*)?$!) {
            $protocols->{byid}->{$2}->{name} = $1;
            $protocols->{byname}->{$1} = $protocols->{byid}->{$2};
        }
@@ -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};