[05/12] rules.pl: Add tiny ipset_restore function.

Message ID 20220214184257.2406-5-stefan.schantl@ipfire.org
State Accepted
Commit 6babb404cc63d6f5c25d64be8e4370b7cb009c2c
Headers
Series [01/12] location-functions.pl: Rename and set the location for exported databases to "/var/lib/location/ipset/". |

Commit Message

Stefan Schantl Feb. 14, 2022, 6:42 p.m. UTC
  This helper function is used to load a previously exported list of
networks for a given country code into the ipset module, so it can be
used for any kind of firewall rules.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
---
 config/firewall/rules.pl | 7 +++++++
 1 file changed, 7 insertions(+)
  

Comments

Peter Müller Feb. 14, 2022, 9:03 p.m. UTC | #1
Reviewed-by: Peter Müller <peter.mueller@ipfire.org>

> This helper function is used to load a previously exported list of
> networks for a given country code into the ipset module, so it can be
> used for any kind of firewall rules.
> 
> Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> ---
>  config/firewall/rules.pl | 7 +++++++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/config/firewall/rules.pl b/config/firewall/rules.pl
> index da01b8775..5b1153b08 100644
> --- a/config/firewall/rules.pl
> +++ b/config/firewall/rules.pl
> @@ -888,3 +888,10 @@ sub firewall_is_in_subnet {
>  
>  	return 0;
>  }
> +
> +sub ipset_restore ($) {
> +	my ($ccode) = @_;
> +
> +	# Run ipset and restore the list of the given country code.
> +	run("$IPSET restore < $Location::Functions::ipset_db_directory/$ccode.ipset4");
> +}
  
Michael Tremer Feb. 15, 2022, 12:41 p.m. UTC | #2
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>

> On 14 Feb 2022, at 18:42, Stefan Schantl <stefan.schantl@ipfire.org> wrote:
> 
> This helper function is used to load a previously exported list of
> networks for a given country code into the ipset module, so it can be
> used for any kind of firewall rules.
> 
> Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
> ---
> config/firewall/rules.pl | 7 +++++++
> 1 file changed, 7 insertions(+)
> 
> diff --git a/config/firewall/rules.pl b/config/firewall/rules.pl
> index da01b8775..5b1153b08 100644
> --- a/config/firewall/rules.pl
> +++ b/config/firewall/rules.pl
> @@ -888,3 +888,10 @@ sub firewall_is_in_subnet {
> 
> 	return 0;
> }
> +
> +sub ipset_restore ($) {
> +	my ($ccode) = @_;
> +
> +	# Run ipset and restore the list of the given country code.
> +	run("$IPSET restore < $Location::Functions::ipset_db_directory/$ccode.ipset4");
> +}
> -- 
> 2.30.2
>
  

Patch

diff --git a/config/firewall/rules.pl b/config/firewall/rules.pl
index da01b8775..5b1153b08 100644
--- a/config/firewall/rules.pl
+++ b/config/firewall/rules.pl
@@ -888,3 +888,10 @@  sub firewall_is_in_subnet {
 
 	return 0;
 }
+
+sub ipset_restore ($) {
+	my ($ccode) = @_;
+
+	# Run ipset and restore the list of the given country code.
+	run("$IPSET restore < $Location::Functions::ipset_db_directory/$ccode.ipset4");
+}