use PVE::Network;
use PVE::Tools;
use PVE::ProcFSTools;
+use PVE::JSONSchema;
use Clone qw(clone);
use Linux::Inotify2;
use base 'Exporter';
}
}
+ # map address and netmask to cidr
+ if ($d->{address}) {
+ if ($d->{netmask} =~ m/^\d+$/) { # e.g. netmask 20
+ $d->{cidr} = $d->{address} . "/" . $d->{netmask};
+ } elsif ($d->{netmask} &&
+ (my $cidr = PVE::JSONSchema::get_netmask_bits($d->{netmask}))) { # e.g. netmask 255.255.255.0
+ $d->{cidr} = $d->{address} . "/" . $cidr;
+ } elsif ($d->{address} =~ m!^(.*)/(\d+)$!) {
+ $d->{cidr} = $d->{address};
+ $d->{address} = $1;
+ $d->{netmask} = $2;
+ } else {
+ $d->{cidr} = $d->{address};
+ }
+ }
+
+ # map address6 and netmask6 to cidr6
+ if ($d->{address6}) {
+ $d->{cidr6} = $d->{address6};
+ if ($d->{netmask6}) {
+ $d->{cidr6} .= "/" . $d->{netmask6};
+ } elsif ($d->{address6} =~ m!^(.*)/(\d+)$!) {
+ $d->{address6} = $1;
+ $d->{netmask6} = $2;
+ }
+ }
+
$d->{method} = 'manual' if !$d->{method};
$d->{method6} = 'manual' if !$d->{method6};
foreach my $iface (keys %$ifaces) {
my $d = $ifaces->{$iface};
+ delete $d->{cidr};
+ delete $d->{cidr6};
+
my $ports = '';
foreach my $k (qw(bridge_ports ovs_ports slaves ovs_bonds)) {
$ports .= " $d->{$k}" if $d->{$k};
# Please do NOT modify this file directly, unless you know what
# you're doing.
#
-# If you want to manage part of the network configuration manually,
+# If you want to manage parts of the network configuration manually,
# please utilize the 'source' or 'source-directory' directives to do
# so.
-# PVE will preserve these directives, but will NOT its network
+# PVE will preserve these directives, but will NOT read its network
# configuration from sourced files, so do not attempt to move any of
# the PVE managed interfaces into external files!
my $if_type_hash = {
loopback => 100000,
eth => 200000,
+ OVSPort => 200000,
+ OVSIntPort => 200000,
bond => 300000,
bridge => 400000,
+ OVSBridge => 400000,
vxlan => 500000,
};
my $lookup_type_prio = sub {
- my $iface = shift;
+ my ($iface, $ifaces) = @_;
- my $child = 0;
- if ($iface =~ m/^(\S+)(\.|:)\d+$/) {
- $iface = $1;
- $child = 1;
- }
+ my ($rootiface, @rest) = split(/[.:]/, $iface);
+ my $childlevel = scalar(@rest);
+ my $n = $ifaces->{$rootiface};
- my $pri;
- if ($iface eq 'lo') {
- $pri = $if_type_hash->{loopback};
- } elsif ($iface =~ m/^$PVE::Network::PHYSICAL_NIC_RE$/) {
- $pri = $if_type_hash->{eth} + $child;
- } elsif ($iface =~ m/^bond\d+$/) {
- $pri = $if_type_hash->{bond} + $child;
- } elsif ($iface =~ m/^vmbr\d+$/) {
- $pri = $if_type_hash->{bridge} + $child;
- }
+ my $pri = $if_type_hash->{$n->{type}} + $childlevel
+ if $n->{type} && $n->{type} ne 'unknown';
return $pri;
};
foreach my $iface (sort {
my $ref1 = $ifaces->{$a};
my $ref2 = $ifaces->{$b};
- my $tp1 = &$lookup_type_prio($a);
- my $tp2 = &$lookup_type_prio($b);
+ my $tp1 = &$lookup_type_prio($a, $ifaces);
+ my $tp2 = &$lookup_type_prio($b, $ifaces);
# Only recognized types are in relation to each other. If one type
# is unknown then only consider the interfaces' priority attributes.