41 lines
863 B
Bash
Executable file
41 lines
863 B
Bash
Executable file
#!/usr/bin/perl -p
|
|
# combine ipset save files setting max per a flat file of ipset per row in the form NAME MAX
|
|
#
|
|
#(c)2026 Corwin Brust <corwin@bru.st>
|
|
# You may use this program under the terms of the GNU Public License version three (3) or, at your option, any later version of that license. (GPLv3+)
|
|
#
|
|
# Input is expected on stdin in the same format as output by ipset save
|
|
#
|
|
|
|
BEGIN {
|
|
my $SET_COUNTS = @ARGV
|
|
? shift
|
|
: q(max-counts.txt);
|
|
|
|
open my$FH,q(<),$SET_COUNTS
|
|
or die $!;
|
|
|
|
while(<$FH>) {
|
|
chomp;
|
|
my($k,$v)=split;
|
|
$m{$k}=$v if $k and $v
|
|
}
|
|
}
|
|
|
|
if(/^create (\S+)/) {
|
|
if(exists $h{$1}) {
|
|
$_ = '';
|
|
} elsif(exists $m{$1}) {
|
|
$h{$1} = $1;
|
|
$n = $m{$1};
|
|
s/^(create (\S+).*?hashsize) \d+ (.*)$/$1 $n $3/
|
|
}
|
|
else {
|
|
$_ = ''; # skip create when no max defined
|
|
}
|
|
}
|
|
elsif(/^add (\S+)/)
|
|
{
|
|
$_ = '' unless exists $m{$1};
|
|
}
|
|
|