]>
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 },
43 # Plugin implementation
44 sub generate_sdn_config
{
45 my ($class, $plugin_config, $zoneid, $vnetid, $vnet, $controller, $subnet_cfg, $interfaces_config, $config) = @_;
47 return $config if$config->{$vnetid}; # nothing to do
49 my $ipv4 = $vnet->{ipv4
};
50 my $ipv6 = $vnet->{ipv6
};
51 my $mac = $vnet->{mac
};
52 my $alias = $vnet->{alias
};
53 my $mtu = $plugin_config->{mtu
} if $plugin_config->{mtu
};
56 my @iface_config = ();
59 my $subnets = PVE
::Network
::SDN
::Vnets
::get_subnets
($vnetid, 1);
60 foreach my $subnetid (sort keys %{$subnets}) {
61 my $subnet = $subnets->{$subnetid};
62 my $cidr = $subnetid =~ s/-/\//r
;
63 my $gateway = $subnet->{gateway
};
65 push @iface_config, "address $gateway" if !defined($address->{$gateway});
66 $address->{$gateway} = 1;
68 #add route for /32 pointtopoint
69 my ($ip, $mask) = split(/\//, $cidr);
70 push @iface_config, "up ip route add $cidr dev $vnetid" if $mask == 32;
71 if ($subnet->{snat
}) {
72 #find outgoing interface
73 my ($outip, $outiface) = PVE
::Network
::SDN
::Zones
::Plugin
::get_local_route_ip
('8.8.8.8');
74 if ($outip && $outiface) {
75 #use snat, faster than masquerade
76 push @iface_config, "post-up iptables -t nat -A POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip";
77 push @iface_config, "post-down iptables -t nat -D POSTROUTING -s '$cidr' -o $outiface -j SNAT --to-source $outip";
78 #add conntrack zone once on outgoing interface
79 push @iface_config, "post-up iptables -t raw -I PREROUTING -i fwbr+ -j CT --zone 1";
80 push @iface_config, "post-down iptables -t raw -D PREROUTING -i fwbr+ -j CT --zone 1";
85 push @iface_config, "hwaddress $mac" if $mac;
86 push @iface_config, "bridge_ports none";
87 push @iface_config, "bridge_stp off";
88 push @iface_config, "bridge_fd 0";
89 if ($vnet->{vlanaware
}) {
90 push @iface_config, "bridge-vlan-aware yes";
91 push @iface_config, "bridge-vids 2-4094";
93 push @iface_config, "mtu $mtu" if $mtu;
94 push @iface_config, "alias $alias" if $alias;
96 push @{$config->{$vnetid}}, @iface_config;
102 my ($class, $plugin_config, $zone, $vnetid, $vnet, $status) = @_;
105 my $ifaces = [ $vnetid ];
107 foreach my $iface (@{$ifaces}) {
108 if (!$status->{$iface}->{status
}) {
109 push @$err_msg, "missing $iface";
110 } elsif ($status->{$iface}->{status
} ne 'pass') {
111 push @$err_msg, "error iface $iface";
118 sub vnet_update_hook
{
119 my ($class, $vnet) = @_;
121 raise_param_exc
({ tag
=> "vlan tag is not allowed on simple bridge"}) if defined($vnet->{tag
});
123 if (!defined($vnet->{mac
})) {
124 my $dc = PVE
::Cluster
::cfs_read_file
('datacenter.cfg');
125 $vnet->{mac
} = PVE
::Tools
::random_ether_addr
($dc->{mac_prefix
});