]>
git.proxmox.com Git - pve-network.git/blob - PVE/Network/SDN/Zones/SimplePlugin.pm
1 package PVE
::Network
::SDN
::Zones
::SimplePlugin
;
5 use PVE
::Network
::SDN
::Zones
::Plugin
;
6 use PVE
::Exception
qw(raise raise_param_exc);
10 use base
('PVE::Network::SDN::Zones::Plugin');
18 nodes
=> { optional
=> 1},
19 mtu
=> { optional
=> 1 }
23 # Plugin implementation
24 sub generate_sdn_config
{
25 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
27 return $config if$config->{$vnetid}; # nothing to do
29 my $ipv4 = $vnet->{ipv4
};
30 my $ipv6 = $vnet->{ipv6
};
31 my $mac = $vnet->{mac
};
32 my $alias = $vnet->{alias
};
33 my $mtu = $plugin_config->{mtu
} if $plugin_config->{mtu
};
36 my @iface_config = ();
39 my $subnets = PVE
::Network
::SDN
::Vnets
::get_subnets
($vnetid);
40 foreach my $subnetid (sort keys %{$subnets}) {
41 my $subnet = $subnets->{$subnetid};
42 my $cidr = $subnetid =~ s/-/\//r
;
43 my $gateway = $subnet->{gateway
};
45 push @iface_config, "address $gateway" if !defined($address->{$gateway});
46 $address->{$gateway} = 1;
48 #add route for /32 pointtopoint
49 my ($ip, $mask) = split(/\//, $cidr);
50 push @iface_config, "up ip route add $cidr dev $vnetid" if $mask == 32;
53 push @iface_config, "hwaddress $mac" if $mac;
54 push @iface_config, "bridge_ports none";
55 push @iface_config, "bridge_stp off";
56 push @iface_config, "bridge_fd 0";
57 if ($vnet->{vlanaware
}) {
58 push @iface_config, "bridge-vlan-aware yes";
59 push @iface_config, "bridge-vids 2-4094";
61 push @iface_config, "mtu $mtu" if $mtu;
62 push @iface_config, "alias $alias" if $alias;
64 push @{$config->{$vnetid}}, @iface_config;
70 my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
73 my $ifaces = [ $vnetid ];
75 foreach my $iface (@{$ifaces}) {
76 if (!$status->{$iface}->{status
}) {
77 push @$err_msg, "missing $iface";
78 } elsif ($status->{$iface}->{status
} ne 'pass') {
79 push @$err_msg, "error iface $iface";
86 sub vnet_update_hook
{
87 my ($class, $vnet) = @_;
89 raise_param_exc
({ tag
=> "vlan tag is not allowed on simple bridge"}) if defined($vnet->{tag
});
91 if (!defined($vnet->{mac
})) {
92 my $dc = PVE
::Cluster
::cfs_read_file
('datacenter.cfg');
93 $vnet->{mac
} = PVE
::Tools
::random_ether_addr
($dc->{mac_prefix
});