]> git.proxmox.com Git - pve-common.git/blobdiff - src/PVE/INotify.pm
fix #5141: network parser: fix accidental RE result re-use
[pve-common.git] / src / PVE / INotify.pm
index fb5116f6f61d0e088d138c6b24f5b7f534b617d6..643229567df5e7707868fb03b52305f02e45a42e 100644 (file)
@@ -25,7 +25,7 @@ use PVE::Tools;
 
 use base 'Exporter';
 
-our @EXPORT_OK = qw(read_file write_file register_file);
+our @EXPORT_OK = qw(read_file write_file register_file nodename);
 
 my $ccache;
 my $ccachemap;
@@ -500,13 +500,10 @@ sub inotify_init {
 }
 
 my $cached_nodename;
-
 sub nodename {
-
     return $cached_nodename if $cached_nodename;
 
     my ($sysname, $nodename) = POSIX::uname();
-
     $nodename =~ s/\..*$//; # strip domain part, if any
 
     die "unable to read node name\n" if !$nodename;
@@ -884,7 +881,7 @@ sub __read_etc_network_interfaces {
        'bridge-fd' => 'bridge_fd',
        'bridge-stp' => 'bridge_stp',
        'bridge-ports' => 'bridge_ports',
-       'bridge-vids' => 'bridge_vids'
+       'bridge-vids' => 'bridge_vids',
     };
 
     my $line;
@@ -904,12 +901,16 @@ sub __read_etc_network_interfaces {
     SECTION: while (defined ($line = <$fh>)) {
        chomp ($line);
        next if $line =~ m/^\s*#/;
-       next if $line =~ m/^\s*(allow-hotplug)\s+(.*)$/;
 
-       if ($line =~ m/^\s*(auto|allow-ovs)\s+(.*)$/) {
+       if ($line =~ m/^\s*(allow-auto|auto|allow-ovs)\s+(.*)$/) {
 
            $ifaces->{$_}->{autostart} = 1 for split (/\s+/, $2);
 
+       } elsif ($line =~ m/^\s*(allow-hotplug)\s+(.*)$/) {
+
+           # FIXME: handle those differently? auto makes it required on-boot, vs. best-effort
+           $ifaces->{$_}->{autostart} = 1 for split (/\s+/, $2);
+
        } elsif ($line =~ m/^\s*iface\s+(\S+)\s+(inet6?)\s+(\S+)\s*$/) {
            my $i = $1;
            my $family = $2;
@@ -949,6 +950,7 @@ sub __read_etc_network_interfaces {
                        'bridge-arp-nd-suppress' => 1,
                        'bridge-unicast-flood' => 1,
                        'bridge-multicast-flood' => 1,
+                       'bridge-disable-mac-learning' => 1,
                        'bond_miimon' => 1,
                        'bond_xmit_hash_policy' => 1,
                        'bond-primary' => 1,
@@ -1028,7 +1030,7 @@ sub __read_etc_network_interfaces {
        };
     }
 
-    foreach my $iface (keys %$ifaces) {
+    foreach my $iface (sort keys %$ifaces) {
        my $d = $ifaces->{$iface};
        $d->{type} = 'unknown';
        if ($iface =~ m/^bond\d+$/) {
@@ -1071,16 +1073,27 @@ sub __read_etc_network_interfaces {
                $ifaces->{$1}->{exists} = 0;
                $d->{exists} = 0;
            }
-       } elsif ($iface =~ m/^(\S+)\.(\d+)$/ || $d->{'vlan-raw-device'}) {
+       } elsif ($iface =~ m/^(\S+)\.(\d+)$/) {
            $d->{type} = 'vlan';
 
            my ($dev, $id) = ($1, $2);
            $d->{'vlan-raw-device'} = $dev if defined($dev) && !$d->{'vlan-raw-device'};
+           $d->{'vlan-id'} = $id if $id; # VLAN id 0 is not valid, so truthy check it is
 
-           if (!$id && $iface =~ m/^vlan(\d+)$/) { # VLAN id 0 is not valid, so truthy check it is
-               $id = $1;
+           my $raw_iface = $d->{'vlan-raw-device'};
+
+           if (defined ($ifaces->{$raw_iface})) {
+               $d->{exists} = $ifaces->{$raw_iface}->{exists};
+           } else {
+               $ifaces->{$raw_iface}->{exists} = 0;
+               $d->{exists} = 0;
+           }
+       } elsif ($d->{'vlan-raw-device'}) {
+           $d->{type} = 'vlan';
+
+           if ($iface =~ m/^vlan(\d+)$/) {
+               $d->{'vlan-id'} = $1 if $1; # VLAN id 0 is not valid, so truthy check it is
            }
-           $d->{'vlan-id'} = $id if $id;
 
            my $raw_iface = $d->{'vlan-raw-device'};
 
@@ -1266,7 +1279,7 @@ sub __interface_to_string {
        }
        $done->{bridge_fd} = 1;
 
-       ifdefined($d->{bridge_vlan_aware})) {
+       if (defined($d->{bridge_vlan_aware})) {
            $raw .= "\tbridge-vlan-aware yes\n";
            my $vlans = defined($d->{bridge_vids}) ? $d->{bridge_vids} : "2-4094";
            $raw .= "\tbridge-vids $vlans\n";
@@ -1276,6 +1289,7 @@ sub __interface_to_string {
 
        $raw .= "\tmtu $d->{mtu}\n" if $d->{mtu};
        $done->{mtu} = 1;
+       $done->{'bridge-disable-mac-learning'} = 1;
 
     } elsif ($d->{type} eq 'bond') {
 
@@ -1766,82 +1780,4 @@ sub read_iscsi_initiatorname {
 register_file('initiatorname', "/etc/iscsi/initiatorname.iscsi",
              \&read_iscsi_initiatorname);
 
-sub read_apt_auth {
-    my ($filename, $fd) = @_;
-
-    local $/;
-
-    my $raw = defined($fd) ? <$fd> : '';
-
-    $raw =~ s/^\s+//;
-
-
-    my @tokens = split(/\s+/, $raw);
-
-    my $data = {};
-
-    my $machine;
-    while (defined(my $tok = shift @tokens)) {
-
-       $machine = shift @tokens if $tok eq 'machine';
-       next if !$machine;
-       $data->{$machine} = {} if !$data->{$machine};
-
-       $data->{$machine}->{login} = shift @tokens if $tok eq 'login';
-       $data->{$machine}->{password} = shift @tokens if $tok eq 'password';
-    };
-
-    return $data;
-}
-
-my $format_apt_auth_data = sub {
-    my $data = shift;
-
-    my $raw = '';
-
-    # sort longer entries first, so machine definitions with higher granularity are preferred
-    for my $machine (sort { length($b) <=> length($a) || $a cmp $b} keys %$data) {
-       my $d = $data->{$machine};
-       next if !defined($d); # allow "deleting" set entries
-
-       $raw .= "machine $machine\n";
-       $raw .= " login $d->{login}\n" if $d->{login};
-       $raw .= " password $d->{password}\n" if $d->{password};
-       $raw .= "\n";
-    }
-
-    return $raw;
-};
-
-sub write_apt_auth {
-    my ($filename, $fh, $data) = @_;
-
-    my $raw = $format_apt_auth_data->($data);
-
-    die "write failed: $!" unless print $fh "$raw\n";
-
-    return $data;
-}
-
-sub update_apt_auth {
-    my ($filename, $fh, $data) = @_;
-
-    my $orig = read_apt_auth($filename, $fh);
-
-    foreach my $machine (keys %$data) {
-       $orig->{$machine} = $data->{$machine};
-    }
-
-    return $format_apt_auth_data->($orig);
-}
-
-register_file(
-    'apt-auth',
-    "/etc/apt/auth.conf",
-    \&read_apt_auth,
-    \&write_apt_auth,
-    \&update_apt_auth,
-    perm => 0640,
-);
-
 1;