diff mbox series

[firewall3,v2] ipsets: allow commented lines with loadfile

Message ID 20201026062835.1968632-1-dharding@living180.net
State Superseded
Headers show
Series [firewall3,v2] ipsets: allow commented lines with loadfile | expand

Commit Message

Daniel Harding Oct. 26, 2020, 6:28 a.m. UTC
When loading ipset files using the loadfile option, skip lines that
start with '#' (disregarding any leading whitespace).

Signed-off-by: Daniel Harding <dharding@living180.net>
---
 ipsets.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

Comments

Henrique de Moraes Holschuh Oct. 26, 2020, 12:53 p.m. UTC | #1
On 26/10/2020 03:28, Daniel Harding wrote:
> When loading ipset files using the loadfile option, skip lines that
> start with '#' (disregarding any leading whitespace).
> 
> Signed-off-by: Daniel Harding <dharding@living180.net>

Looks good to me, FWLIW.  Thanks for addressing my suggestion!

> ---
>   ipsets.c | 12 ++++++++++--
>   1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/ipsets.c b/ipsets.c
> index 280845b..7af795d 100644
> --- a/ipsets.c
> +++ b/ipsets.c
> @@ -16,6 +16,8 @@
>    * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
>    */
>   
> +#include <ctype.h>
> +
>   #include "ipsets.h"
>   
>   
> @@ -337,6 +339,7 @@ load_file(struct fw3_ipset *ipset)
>   {
>   	FILE *f;
>   	char line[128];
> +	char *p;
>   
>   	if (!ipset->loadfile)
>   		return;
> @@ -350,8 +353,13 @@ load_file(struct fw3_ipset *ipset)
>   		return;
>   	}
>   
> -	while (fgets(line, sizeof(line), f))
> -		fw3_pr("add %s %s", ipset->name, line);
> +	while (fgets(line, sizeof(line), f)) {
> +		p = line;
> +		while (isblank(*p))
> +			p++;
> +		if (*p != '#')
> +			fw3_pr("add %s %s", ipset->name, line);
> +	}
>   
>   	fclose(f);
>   }
>
diff mbox series

Patch

diff --git a/ipsets.c b/ipsets.c
index 280845b..7af795d 100644
--- a/ipsets.c
+++ b/ipsets.c
@@ -16,6 +16,8 @@ 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#include <ctype.h>
+
 #include "ipsets.h"
 
 
@@ -337,6 +339,7 @@  load_file(struct fw3_ipset *ipset)
 {
 	FILE *f;
 	char line[128];
+	char *p;
 
 	if (!ipset->loadfile)
 		return;
@@ -350,8 +353,13 @@  load_file(struct fw3_ipset *ipset)
 		return;
 	}
 
-	while (fgets(line, sizeof(line), f))
-		fw3_pr("add %s %s", ipset->name, line);
+	while (fgets(line, sizeof(line), f)) {
+		p = line;
+		while (isblank(*p))
+			p++;
+		if (*p != '#')
+			fw3_pr("add %s %s", ipset->name, line);
+	}
 
 	fclose(f);
 }