]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/commitdiff
ipblocklist-functions.pl: Add parser of dshield.
authorTim FitzGeorge <ipfr@tfitzgeorge.me.uk>
Fri, 4 Mar 2022 21:10:29 +0000 (22:10 +0100)
committerStefan Schantl <stefan.schantl@ipfire.org>
Thu, 7 Jul 2022 15:26:13 +0000 (17:26 +0200)
This vendor has a different list format and therefore requires an
own parser.

Signed-off-by: Tim FitzGeorge <ipfr@tfitzgeorge.me.uk>
Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
config/cfgroot/ipblocklist-functions.pl

index 9e862bb0ec67176a7f0d277b4f28cde945cf0ced..9420fc948ce6a9e35ae07bc64ff79e2e24e69445 100644 (file)
@@ -278,4 +278,40 @@ sub parse_ip_or_net_list( $ ) {
        # Return the grabbed address.
        return $1;
 }
+
+#
+## sub parse_dshield( line )
+##
+## Parses an input line removing comments.
+##
+## The format is:
+## Start Addrs   End Addrs   Netmask   Nb Attacks   Network Name   Country   email
+## We're only interested in the start address and netmask.
+##
+## Parameters:
+##   line  The line to parse
+##
+## Returns:
+##   Either and IP Address or a null string
+#
+sub parse_dshield( $ ) {
+       my ($line) = @_;
+
+       # Skip coments.
+       return "" if ($line =~ m/^\s*#/);
+
+       $line =~ s/#.*$//;
+
+       #          |Start addrs                |   |End Addrs                |   |Mask
+       $line =~ m|(\d+\.\d+\.\d+\.\d+(?:/\d+)?)\s+\d+\.\d+\.\d+\.\d+(?:/\d+)?\s+(\d+)|;
+
+       # Return nothing if no start address could be grabbed.
+       return unless ($1);
+
+       # Add /32 as prefix for single addresses and return it.
+       return "$1/32" unless ($2);
+
+       # Return the obtained network.
+       return "$1/$2";
+}
 1;