firewall3: remove unnecessary fw3_has_table
authorWenli Looi <wlooi@ucalgary.ca>
Thu, 10 Jun 2021 04:51:06 +0000 (21:51 -0700)
committerRui Salvaterra <rsalvaterra@gmail.com>
Mon, 21 Feb 2022 23:21:09 +0000 (23:21 +0000)
Given that firewall3 already skips the table when fw3_ipt_open fails,
there is no need for fw3_has_table.

Furthermore, /proc/net/ip_tables_names is not reliable under linux
containers (e.g. Docker/LXC/LXD). This patch will remove the need for
existing hacks required for OpenWrt to run on those platforms.

Reviewed-by: Rui Salvaterra <rsalvaterra@gmail.com>
Tested-by: Rui Salvaterra <rsalvaterra@gmail.com>
Tested-by: Ansuel Smith <ansuelsmth@gmail.com>
Signed-off-by: Wenli Looi <wlooi@ucalgary.ca>
main.c
utils.c
utils.h

diff --git a/main.c b/main.c
index 9afeb701edf1b1c3564dcea82da8e9ad248382a2..5985e73b21dd8d06e91525d9efe5e717ecdce952 100644 (file)
--- a/main.c
+++ b/main.c
@@ -195,9 +195,6 @@ stop(bool complete)
 
                for (table = FW3_TABLE_FILTER; table <= FW3_TABLE_RAW; table++)
                {
-                       if (!fw3_has_table(family == FW3_FAMILY_V6, fw3_flag_names[table]))
-                               continue;
-
                        if (!(handle = fw3_ipt_open(family, table)))
                                continue;
 
@@ -279,9 +276,6 @@ start(void)
 
                for (table = FW3_TABLE_FILTER; table <= FW3_TABLE_RAW; table++)
                {
-                       if (!fw3_has_table(family == FW3_FAMILY_V6, fw3_flag_names[table]))
-                               continue;
-
                        if (!(handle = fw3_ipt_open(family, table)))
                                continue;
 
@@ -350,9 +344,6 @@ reload(void)
 
                for (table = FW3_TABLE_FILTER; table <= FW3_TABLE_RAW; table++)
                {
-                       if (!fw3_has_table(family == FW3_FAMILY_V6, fw3_flag_names[table]))
-                               continue;
-
                        if (!(handle = fw3_ipt_open(family, table)))
                                continue;
 
@@ -379,9 +370,6 @@ start:
 
                for (table = FW3_TABLE_FILTER; table <= FW3_TABLE_RAW; table++)
                {
-                       if (!fw3_has_table(family == FW3_FAMILY_V6, fw3_flag_names[table]))
-                               continue;
-
                        if (!(handle = fw3_ipt_open(family, table)))
                                continue;
 
@@ -437,9 +425,6 @@ gc(void)
 
                for (table = FW3_TABLE_FILTER; table <= FW3_TABLE_RAW; table++)
                {
-                       if (!fw3_has_table(family == FW3_FAMILY_V6, fw3_flag_names[table]))
-                               continue;
-
                        if (!(handle = fw3_ipt_open(family, table)))
                                continue;
 
diff --git a/utils.c b/utils.c
index 92e966c20f6ac23806edde02c63d61f32f7af537..faa51a1a589b277421f1e5c16ee35d43eea89d92 100644 (file)
--- a/utils.c
+++ b/utils.c
@@ -339,15 +339,6 @@ file_contains(const char *path, const char *str)
        return seen;
 }
 
-bool
-fw3_has_table(const bool ipv6, const char *table)
-{
-       const char *path = ipv6
-               ? "/proc/net/ip6_tables_names" : "/proc/net/ip_tables_names";
-
-       return file_contains(path, table);
-}
-
 bool
 fw3_has_target(const bool ipv6, const char *target)
 {
diff --git a/utils.h b/utils.h
index 884907da51b22c35a8bb4c7ed893cff2d5801342..5b17a2d75567a2e192a9b95226c1fd0cfbcae024 100644 (file)
--- a/utils.h
+++ b/utils.h
@@ -102,8 +102,6 @@ void fw3_command_close(void);
 void fw3_pr(const char *fmt, ...)
        __attribute__ ((format (printf, 1, 2)));
 
-bool fw3_has_table(const bool ipv6, const char *table);
-
 bool fw3_has_target(const bool ipv6, const char *target);
 
 bool fw3_lock(void);