sub parse_fw_rule {
my ($prefix, $line, $cluster_conf, $fw_conf, $rule_env, $verbose) = @_;
- chomp $line;
-
my $orig_line = $line;
my $rule = {};
$opt = lc($1);
$value = $2;
} else {
- chomp $line;
die "can't parse option '$line'\n"
}
$opt = lc($1);
$value = int($2);
} else {
- chomp $line;
die "can't parse option '$line'\n"
}
$opt = lc($1);
$value = uc($3);
} else {
- chomp $line;
die "can't parse option '$line'\n"
}
next if $line =~ m/^#/;
next if $line =~ m/^\s*$/;
+ chomp $line;
+
my $linenr = $fh->input_line_number();
my $prefix = "$filename (line $linenr)";
}
};
if (my $err = $@) {
+ chomp $err;
$errors->{cidr} = $err;
}
$entry->{comment} = $comment if $comment;
$entry->{errors} = $errors if $errors;
+ if ($verbose && $errors) {
+ warn "$prefix - errors in ipset '$group': $line\n";
+ foreach my $p (keys %{$errors}) {
+ warn " $p: $errors->{$p}\n";
+ }
+ }
+
push @{$res->{$section}->{$group}}, $entry;
} else {
warn "$prefix: skip line - unknown section\n";
# remove duplicates
my $nethash = {};
foreach my $entry (@$options) {
+ next if $entry->{errors}; # skip entries with errors
eval {
my $cidr = resolve_alias($clusterfw_conf, $fw_conf, $entry->{cidr});
$nethash->{$cidr} = { cidr => $cidr, nomatch => $entry->{nomatch} };
push @{$cluster_conf->{ipset}->{management}}, { cidr => $localnet };
+ return ({}, {}) if !$cluster_conf->{options}->{enable};
+
my $ruleset = {};
ruleset_create_chain($ruleset, "PVEFW-INPUT");
}
foreach my $h (qw(INPUT OUTPUT FORWARD)) {
- if (!$hooks->{$h}) {
- $cmdlist .= "-A $h -j PVEFW-$h\n";
+ my $chain = "PVEFW-$h";
+ if ($ruleset->{$chain} && !$hooks->{$h}) {
+ $cmdlist .= "-A $h -j $chain\n";
}
}
$cmdlist .= "COMMIT\n";
iptables_restore_cmdlist($cmdlist);
+
+ my $ipset_chains = ipset_get_chains();
+
+ $cmdlist = "";
+
+ foreach my $chain (keys %$ipset_chains) {
+ $cmdlist .= "flush $chain\n";
+ $cmdlist .= "destroy $chain\n";
+ }
+
+ ipset_restore_cmdlist($cmdlist) if $cmdlist;
}
sub init {
my $cluster_conf = load_clusterfw_conf();
my $cluster_options = $cluster_conf->{options};
- my $enable = $cluster_options->{enable};
-
- die "Firewall is disabled - cannot start\n" if !$enable;
-
- if (!$enable) {
+ if (!$cluster_options->{enable}) {
PVE::Firewall::remove_pvefw_chains();
return;
}