]>
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');
20 description
=> "dns api server",
24 description
=> "reverse dns api server",
27 type
=> 'string', format
=> 'dns-name',
28 description
=> "dns domain zone ex: mydomain.com",
35 nodes
=> { optional
=> 1},
36 mtu
=> { optional
=> 1 },
37 dns
=> { optional
=> 1 },
38 reversedns
=> { optional
=> 1 },
39 dnszone
=> { optional
=> 1 },
40 ipam
=> { optional
=> 0 },
44 # Plugin implementation
45 sub generate_sdn_config
{
46 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $controller_cfg, $subnet_cfg, $interfaces_config, $config) = @_;
48 return $config if$config->{$vnetid}; # nothing to do
50 my $ipv4 = $vnet->{ipv4
};
51 my $ipv6 = $vnet->{ipv6
};
52 my $mac = $vnet->{mac
};
53 my $alias = $vnet->{alias
};
54 my $mtu = $plugin_config->{mtu
} if $plugin_config->{mtu
};
57 my @iface_config = ();
60 my $subnets = PVE
::Network
::SDN
::Vnets
::get_subnets
($vnetid, 1);
61 foreach my $subnetid (sort keys %{$subnets}) {
62 my $subnet = $subnets->{$subnetid};
63 my $cidr = $subnet->{cidr
};
64 my $mask = $subnet->{mask
};
66 my $gateway = $subnet->{gateway
};
68 push @iface_config, "address $gateway" if !defined($address->{$gateway});
69 $address->{$gateway} = 1;
71 #add route for /32 pointtopoint
72 push @iface_config, "up ip route add $cidr dev $vnetid" if $mask == 32;
73 if ($subnet->{snat
}) {
74 #find outgoing interface
75 my ($outip, $outiface) = PVE
::Network
::SDN
::Zones
::Plugin
::get_local_route_ip
('8.8.8.8');
76 if ($outip && $outiface) {
77 #use snat, faster than masquerade
78 push @iface_config, "post-up iptables -t nat -A POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip";
79 push @iface_config, "post-down iptables -t nat -D POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip";
80 #add conntrack zone once on outgoing interface
81 push @iface_config, "post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1";
82 push @iface_config, "post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1";
87 push @iface_config, "hwaddress $mac" if $mac;
88 push @iface_config, "bridge_ports none";
89 push @iface_config, "bridge_stp off";
90 push @iface_config, "bridge_fd 0";
91 if ($vnet->{vlanaware
}) {
92 push @iface_config, "bridge-vlan-aware yes";
93 push @iface_config, "bridge-vids 2-4094";
95 push @iface_config, "mtu $mtu" if $mtu;
96 push @iface_config, "alias $alias" if $alias;
98 push @{$config->{$vnetid}}, @iface_config;
104 my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
107 my $ifaces = [ $vnetid ];
109 foreach my $iface (@{$ifaces}) {
110 if (!$status->{$iface}->{status
}) {
111 push @$err_msg, "missing $iface";
112 } elsif ($status->{$iface}->{status
} ne 'pass') {
113 push @$err_msg, "error iface $iface";
120 sub vnet_update_hook
{
121 my ($class, $vnet_cfg, $vnetid, $zone_cfg) = @_;
123 my $vnet = $vnet_cfg->{ids
}->{$vnetid};
124 my $tag = $vnet->{tag
};
126 raise_param_exc
({ tag
=> "vlan tag is not allowed on simple zone"}) if defined($tag);
128 if (!defined($vnet->{mac
})) {
129 my $dc = PVE
::Cluster
::cfs_read_file
('datacenter.cfg');
130 $vnet->{mac
} = PVE
::Tools
::random_ether_addr
($dc->{mac_prefix
});