From 6da14cc1248c6c13da0892d565e2ad68bc39b133 Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Fri, 15 Nov 2019 14:22:35 +0000 Subject: [PATCH] location-query: Add output for ipset Fixes: #12202 Signed-off-by: Michael Tremer --- man/location-query.txt | 1 + src/python/location-query.in | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/man/location-query.txt b/man/location-query.txt index ed6f4e5..ad129ed 100644 --- a/man/location-query.txt +++ b/man/location-query.txt @@ -50,6 +50,7 @@ or countries. directly loaded into other software. The following options are available: + * 'list' (default): Just lists all networks, one per line + * 'ipset': For ipset * 'nftables': For nftables * 'xt_geoip': Returns a list of networks to be loaded into the xt_geoip kernel module diff --git a/src/python/location-query.in b/src/python/location-query.in index 83f23ee..72b7c25 100644 --- a/src/python/location-query.in +++ b/src/python/location-query.in @@ -69,6 +69,17 @@ class OutputFormatter(object): print(network) +class IpsetOutputFormatter(OutputFormatter): + """ + For nftables + """ + def open(self): + print("create %s hash:net family inet hashsize 1024 maxelem 65536" % self.name) + + def network(self, network): + print("add %s %s" % (self.name, network)) + + class NftablesOutputFormatter(OutputFormatter): """ For nftables @@ -102,6 +113,7 @@ class XTGeoIPOutputFormatter(OutputFormatter): class CLI(object): output_formats = { + "ipset" : IpsetOutputFormatter, "list" : OutputFormatter, "nftables" : NftablesOutputFormatter, "xt_geoip" : XTGeoIPOutputFormatter, -- 2.39.2