X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=src%2FPVE%2FINotify.pm;h=643229567df5e7707868fb03b52305f02e45a42e;hb=80ed66dc17a5beb3606f8d4801852df434d723c0;hp=22f27f1ebc695a9b3136ca92ccc7b55f42116bd5;hpb=43997e844e0bf904ae707815afc87225c2c9abdd;p=pve-common.git diff --git a/src/PVE/INotify.pm b/src/PVE/INotify.pm index 22f27f1..6432295 100644 --- a/src/PVE/INotify.pm +++ b/src/PVE/INotify.pm @@ -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,14 +901,15 @@ 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+(.*)$/) { - my @aa = split (/\s+/, $2); + if ($line =~ m/^\s*(allow-auto|auto|allow-ovs)\s+(.*)$/) { - foreach my $a (@aa) { - $ifaces->{$a}->{autostart} = 1; - } + $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; @@ -930,13 +928,7 @@ sub __read_etc_network_interfaces { $f->{comments} = '' if !$f->{comments}; my $comment = decode('UTF-8', $1); $f->{comments} .= "$comment\n"; - } elsif ($line =~ m/^\s*(?:iface\s - |mapping\s - |auto\s - |allow- - |source\s - |source-directory\s - )/x) { + } elsif ($line =~ m/^\s*(?:(?:iface|mapping|auto|source|source-directory)\s|allow-)/) { last; } elsif ($line =~ m/^\s*((\S+)\s+(.+))$/) { my $option = $1; @@ -958,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, @@ -969,9 +962,10 @@ sub __read_etc_network_interfaces { 'vxlan-id' => 1, 'vxlan-svcnodeip' => 1, 'vxlan-physdev' => 1, - 'vxlan-local-tunnelip' => 1 }; + 'vxlan-local-tunnelip' => 1, + }; - if (($id eq 'address') || ($id eq 'netmask') || ($id eq 'broadcast') || ($id eq 'gateway')) { + if ($id eq 'address' || $id eq 'netmask' || $id eq 'broadcast' || $id eq 'gateway') { $f->{$id} = $value; } elsif ($simple_options->{$id}) { $d->{$id} = $value; @@ -998,8 +992,7 @@ sub __read_etc_network_interfaces { } elsif ($id eq 'bond_mode') { # always use names foreach my $bm (keys %$bond_modes) { - my $id = $bond_modes->{$bm}; - if ($id eq $value) { + if ($bond_modes->{$bm} eq $value) { $value = $bm; last; } @@ -1014,7 +1007,7 @@ sub __read_etc_network_interfaces { last; } } - $d->{"$_$suffix"} = $f->{$_} foreach (keys %$f); + $d->{"$_$suffix"} = $f->{$_} for keys $f->%*; last SECTION if !defined($line); redo SECTION; } elsif ($line =~ /\w/) { @@ -1029,13 +1022,15 @@ sub __read_etc_network_interfaces { } if (!$ifaces->{lo}) { - $ifaces->{lo}->{priority} = 1; - $ifaces->{lo}->{method} = 'loopback'; - $ifaces->{lo}->{type} = 'loopback'; - $ifaces->{lo}->{autostart} = 1; + $ifaces->{lo} = { + priority => 1, + method => 'loopback', + type => 'loopback', + autostart => 1, + }; } - foreach my $iface (keys %$ifaces) { + foreach my $iface (sort keys %$ifaces) { my $d = $ifaces->{$iface}; $d->{type} = 'unknown'; if ($iface =~ m/^bond\d+$/) { @@ -1078,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'}; @@ -1238,11 +1244,12 @@ sub __interface_to_string { $raw .= "\tgateway " . $d->{"gateway$suffix"} . "\n" if $d->{"gateway$suffix"}; - my $done = { type => 1, priority => 1, method => 1, active => 1, exists => 1, - comments => 1, autostart => 1, options => 1, - address => 1, netmask => 1, gateway => 1, broadcast => 1, - method6 => 1, families => 1, options6 => 1, comments6 => 1, - address6 => 1, netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1 }; + my $done = { + type => 1, priority => 1, method => 1, active => 1, exists => 1, comments => 1, + autostart => 1, options => 1, address => 1, netmask => 1, gateway => 1, broadcast => 1, + method6 => 1, families => 1, options6 => 1, comments6 => 1, address6 => 1, + netmask6 => 1, gateway6 => 1, broadcast6 => 1, 'uplink-id' => 1, + }; if (!$first_block) { # not printing out options @@ -1259,16 +1266,20 @@ sub __interface_to_string { $raw .= "\tbridge-stp $br_stp\n"; $done->{bridge_stp} = 1; - my $br_fd = defined($d->{bridge_fd}) ? $d->{bridge_fd} : 0; - # 0 is only allowed when STP is disabled - if ($no_stp || ($br_fd >= 2 && $br_fd <= 30)) { - $raw .= "\tbridge-fd $br_fd\n"; - } else { - warn "'$iface': ignoring 'bridge_fd' value '$br_fd', outside of allowed range 2-30\n"; + # NOTE: forwarding delay must be 2 <= FD <= 30 if STP is enabled + if (defined(my $br_fd = $d->{bridge_fd})) { + if ($no_stp || ($br_fd >= 2 && $br_fd <= 30)) { + $raw .= "\tbridge-fd $br_fd\n"; + } else { + # only complain if the user actually set a value, but not for default fallback below + warn "'$iface': ignoring 'bridge_fd' value '$br_fd', outside of allowed range 2-30\n"; + } + } elsif ($no_stp) { + $raw .= "\tbridge-fd 0\n"; } $done->{bridge_fd} = 1; - if( defined($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"; @@ -1278,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') { @@ -1340,8 +1352,7 @@ sub __interface_to_string { $raw .= "\tovs_mtu $d->{mtu}\n" if $d->{mtu}; $done->{mtu} = 1; - } elsif ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' || - $d->{type} eq 'OVSBond') { + } elsif ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' || $d->{type} eq 'OVSBond') { $d->{autostart} = 0; # started by the bridge @@ -1452,8 +1463,7 @@ sub __write_etc_network_interfaces { # delete unused OVS ports foreach my $iface (keys %$ifaces) { my $d = $ifaces->{$iface}; - if ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' || - $d->{type} eq 'OVSBond') { + if ($d->{type} eq 'OVSPort' || $d->{type} eq 'OVSIntPort' || $d->{type} eq 'OVSBond') { my $brname = $used_ports->{$iface}; if (!$brname || !$ifaces->{$brname}) { if ($iface =~ /^$PVE::Network::PHYSICAL_NIC_RE/) { @@ -1482,8 +1492,7 @@ sub __write_etc_network_interfaces { if ($d->{type} eq 'OVSBridge' && $d->{ovs_ports}) { foreach my $p (split (/\s+/, $d->{ovs_ports})) { my $n = $ifaces->{$p}; - die "OVS bridge '$iface' - unable to find port '$p'\n" - if !$n; + die "OVS bridge '$iface' - unable to find port '$p'\n" if !$n; $n->{autostart} = 0; if ($n->{type} eq 'eth') { $n->{type} = 'OVSPort'; @@ -1507,10 +1516,9 @@ sub __write_etc_network_interfaces { foreach my $p (split (/\s+/, $d->{ovs_bonds})) { my $n = $ifaces->{$p}; $n->{autostart} = 1; - die "OVS bond '$iface' - unable to find slave '$p'\n" - if !$n; - die "OVS bond '$iface' - wrong interface type on slave '$p' " . - "('$n->{type}' != 'eth')\n" if $n->{type} ne 'eth'; + die "OVS bond '$iface' - unable to find slave '$p'\n" if !$n; + die "OVS bond '$iface' - wrong interface type on slave '$p' ('$n->{type}' != 'eth')\n" + if $n->{type} ne 'eth'; &$check_mtu($ifaces, $iface, $p); } } @@ -1772,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;