]> git.proxmox.com Git - pve-firewall.git/blobdiff - src/PVE/Firewall.pm
fix allowed group name length
[pve-firewall.git] / src / PVE / Firewall.pm
index 3ccf95271b66530c81f1663055fe3eecaee6afec..b52d324330e4bf6625ec76029e0eda2903b329af 100644 (file)
@@ -12,6 +12,7 @@ use PVE::JSONSchema qw(register_standard_option get_standard_option);
 use PVE::Cluster;
 use PVE::ProcFSTools;
 use PVE::Tools qw($IPV4RE $IPV6RE);
+use PVE::Network;
 use File::Basename;
 use File::Path;
 use IO::File;
@@ -49,7 +50,7 @@ our $ip_alias_pattern = '[A-Za-z][A-Za-z0-9\-\_]+';
 
 my $max_alias_name_length = 64;
 my $max_ipset_name_length = 64;
-my $max_group_name_length = 20;
+my $max_group_name_length = 18;
 
 PVE::JSONSchema::register_format('IPorCIDR', \&pve_verify_ip_or_cidr);
 sub pve_verify_ip_or_cidr {
@@ -875,24 +876,6 @@ sub get_etc_protocols {
     return $etc_protocols;
 }
 
-my $ipv4_mask_hash_localnet = {
-    '255.255.0.0' => 16,
-    '255.255.128.0' => 17,
-    '255.255.192.0' => 18,
-    '255.255.224.0' => 19,
-    '255.255.240.0' => 20,
-    '255.255.248.0' => 21,
-    '255.255.252.0' => 22,
-    '255.255.254.0' => 23,
-    '255.255.255.0' => 24,
-    '255.255.255.128' => 25,
-    '255.255.255.192' => 26,
-    '255.255.255.224' => 27,
-    '255.255.255.240' => 28,
-    '255.255.255.248' => 29,
-    '255.255.255.252' => 30,
-};
-
 my $__local_network;
 
 sub local_network {
@@ -917,7 +900,7 @@ sub local_network {
            if ($isv6) {
                $mask = $entry->{prefix};
            } else {
-               $mask = $ipv4_mask_hash_localnet->{$entry->{mask}};
+               $mask = $PVE::Network::ipv4_mask_hash_localnet->{$entry->{mask}};
                next if !defined($mask);
            }
            my $cidr = "$entry->{dest}/$mask";
@@ -1124,6 +1107,125 @@ sub copy_list_with_digest {
     return wantarray ? ($res, $digest) : $res;
 }
 
+our $cluster_option_properties = {
+    enable => {
+       description => "Enable or disable the firewall cluster wide.",
+       type => 'integer',
+       minimum => 0,
+       optional => 1,
+    },
+    policy_in => {
+       description => "Input policy.",
+       type => 'string',
+       optional => 1,
+       enum => ['ACCEPT', 'REJECT', 'DROP'],
+    },
+    policy_out => {
+       description => "Output policy.",
+       type => 'string',
+       optional => 1,
+       enum => ['ACCEPT', 'REJECT', 'DROP'],
+    },
+};
+
+our $host_option_properties = {
+    enable => {
+       description => "Enable host firewall rules.",
+       type => 'boolean',
+       optional => 1,
+    },
+    log_level_in =>  get_standard_option('pve-fw-loglevel', {
+       description => "Log level for incoming traffic." }),
+    log_level_out =>  get_standard_option('pve-fw-loglevel', {
+       description => "Log level for outgoing traffic." }),
+    tcp_flags_log_level =>  get_standard_option('pve-fw-loglevel', {
+       description => "Log level for illegal tcp flags filter." }),
+    smurf_log_level =>  get_standard_option('pve-fw-loglevel', {
+       description => "Log level for SMURFS filter." }),
+    nosmurfs => {
+       description => "Enable SMURFS filter.",
+       type => 'boolean',
+       optional => 1,
+    },
+    tcpflags => {
+       description => "Filter illegal combinations of TCP flags.",
+       type => 'boolean',
+       optional => 1,
+    },
+    nf_conntrack_max => {
+       description => "Maximum number of tracked connections.",
+       type => 'integer',
+       optional => 1,
+       minimum => 32768,
+    },
+    nf_conntrack_tcp_timeout_established => {
+       description => "Conntrack established timeout.",
+       type => 'integer',
+       optional => 1,
+       minimum => 7875,
+    },
+    ndp => {
+       description => "Enable NDP.",
+       type => 'boolean',
+       optional => 1,
+    },
+};
+
+our $vm_option_properties = {
+    enable => {
+       description => "Enable/disable firewall rules.",
+       type => 'boolean',
+       optional => 1,
+    },
+    macfilter => {
+       description => "Enable/disable MAC address filter.",
+       type => 'boolean',
+       optional => 1,
+    },
+    dhcp => {
+       description => "Enable DHCP.",
+       type => 'boolean',
+       optional => 1,
+    },
+    ndp => {
+       description => "Enable NDP.",
+       type => 'boolean',
+       optional => 1,
+    },
+    radv => {
+       description => "Allow sending Router Advertisement.",
+       type => 'boolean',
+       optional => 1,
+    },
+    ipfilter => {
+       description => "Enable default IP filters. " .
+          "This is equivalent to adding an empty ipfilter-net<id> ipset " .
+          "for every interface. Such ipsets implicitly contain sane default " .
+          "restrictions such as restricting IPv6 link local addresses to " .
+          "the one derived from the interface's MAC address. For containers " .
+          "the configured IP addresses will be implicitly added.",
+       type => 'boolean',
+       optional => 1,
+    },
+    policy_in => {
+       description => "Input policy.",
+       type => 'string',
+       optional => 1,
+       enum => ['ACCEPT', 'REJECT', 'DROP'],
+    },
+    policy_out => {
+       description => "Output policy.",
+       type => 'string',
+       optional => 1,
+       enum => ['ACCEPT', 'REJECT', 'DROP'],
+    },
+    log_level_in =>  get_standard_option('pve-fw-loglevel', {
+       description => "Log level for incoming traffic." }),
+    log_level_out =>  get_standard_option('pve-fw-loglevel', {
+       description => "Log level for outgoing traffic." }),
+
+};
+
 
 my $addr_list_descr = "This can refer to a single IP address, an IP set ('+ipsetname') or an IP alias definition. You can also specify an address range like '20.34.101.207-201.3.9.99', or a list of IP addresses and networks (entries are separated by comma). Please do not mix IPv4 and IPv6 addresses inside such lists.";
 
@@ -3249,13 +3351,13 @@ sub compile_iptables_filter {
     }
 
     # generate firewall rules for QEMU VMs
-    foreach my $vmid (keys %{$vmdata->{qemu}}) {
+    foreach my $vmid (sort keys %{$vmdata->{qemu}}) {
        eval {
            my $conf = $vmdata->{qemu}->{$vmid};
            my $vmfw_conf = $vmfw_configs->{$vmid};
            return if !$vmfw_conf;
 
-           foreach my $netid (keys %$conf) {
+           foreach my $netid (sort keys %$conf) {
                next if $netid !~ m/^net(\d+)$/;
                my $net = PVE::QemuServer::parse_net($conf->{$netid});
                next if !$net->{firewall};
@@ -3272,14 +3374,14 @@ sub compile_iptables_filter {
     }
 
     # generate firewall rules for LXC containers
-    foreach my $vmid (keys %{$vmdata->{lxc}}) {
+    foreach my $vmid (sort keys %{$vmdata->{lxc}}) {
         eval {
             my $conf = $vmdata->{lxc}->{$vmid};
             my $vmfw_conf = $vmfw_configs->{$vmid};
             return if !$vmfw_conf;
 
             if ($vmfw_conf->{options}->{enable}) {
-               foreach my $netid (keys %$conf) {
+               foreach my $netid (sort keys %$conf) {
                     next if $netid !~ m/^net(\d+)$/;
                     my $net = PVE::LXC::Config->parse_lxc_network($conf->{$netid});
                     next if !$net->{firewall};
@@ -3404,10 +3506,10 @@ sub compile_ipsets {
                    { cidr => $linklocal },
                    { cidr => 'fe80::/10', nomatch => 1 }
                ];
-               if ($net->{ip} =~ m!^($IPV4RE)(?:/\d+)?$!) {
+               if (defined($net->{ip}) && $net->{ip} =~ m!^($IPV4RE)(?:/\d+)?$!) {
                    push @$set, { cidr => $1 };
                }
-               if ($net->{ip6} =~ m!^($IPV6RE)(?:/\d+)?$!) {
+               if (defined($net->{ip6}) && $net->{ip6} =~ m!^($IPV6RE)(?:/\d+)?$!) {
                    push @$set, { cidr => $1 };
                }
            }