As "require" is evaluated on module load only once, we either have
it or not, so move it to the top to avoid code duplication
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
use POSIX qw(ECONNREFUSED);
use Socket qw(NI_NUMERICHOST NI_NUMERICSERV);
use POSIX qw(ECONNREFUSED);
use Socket qw(NI_NUMERICHOST NI_NUMERICSERV);
+my $have_sdn;
+eval {
+ require PVE::Network::SDN::Zones;
+ $have_sdn = 1;
+};
+
# host network related utility functions
our $PHYSICAL_NIC_RE = qr/(?:eth\d+|en[^:.]+|ib\d+)/;
# host network related utility functions
our $PHYSICAL_NIC_RE = qr/(?:eth\d+|en[^:.]+|ib\d+)/;
sub tap_create {
my ($iface, $bridge) = @_;
sub tap_create {
my ($iface, $bridge) = @_;
- my $have_sdn;
- eval {
- require PVE::Network::SDN::Zones;
- $have_sdn = 1;
- };
-
if ($have_sdn) {
my ($bridgesdn, undef) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;
if ($have_sdn) {
my ($bridgesdn, undef) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;
sub veth_create {
my ($veth, $vethpeer, $bridge, $mac) = @_;
sub veth_create {
my ($veth, $vethpeer, $bridge, $mac) = @_;
- my $have_sdn;
- eval {
- require PVE::Network::SDN::Zones;
- $have_sdn = 1;
- };
-
if ($have_sdn) {
my ($bridgesdn, undef) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;
if ($have_sdn) {
my ($bridgesdn, undef) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;
sub tap_plug {
my ($iface, $bridge, $tag, $firewall, $trunks, $rate) = @_;
sub tap_plug {
my ($iface, $bridge, $tag, $firewall, $trunks, $rate) = @_;
- my $have_sdn;
- eval {
- require PVE::Network::SDN::Zones;
- $have_sdn = 1;
- };
-
if ($have_sdn) {
my ($bridgesdn, $tag) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;
if ($have_sdn) {
my ($bridgesdn, $tag) = PVE::Network::SDN::Zones::get_bridge_vlan($bridge);
$bridge = $bridgesdn if $bridgesdn;