From: Daniel Wagner <[email protected]>

---
Hi Tomasz,

What do you think about this? Yes I agree the __connman_log_init()
is dirty but we can't really add '-d' because that belongs also
to iptables command set. And enabling __connman_log_init() always
is bit too much in my opinion.

cheers,
daniel

 src/connman.h         |  1 +
 src/iptables.c        | 15 +++++++++++++++
 tools/iptables-test.c | 13 ++++++++++++-
 3 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/src/connman.h b/src/connman.h
index fec3a46..e9c774e 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -790,6 +790,7 @@ int __connman_stats_get(struct connman_service *service,
                                connman_bool_t roaming,
                                struct connman_stats_data *data);
 
+int __connman_iptables_dump(const char *table_name);
 int __connman_iptables_new_chain(const char *table_name,
                                        const char *chain);
 int __connman_iptables_delete_chain(const char *table_name,
diff --git a/src/iptables.c b/src/iptables.c
index 855d89f..7e8d566 100644
--- a/src/iptables.c
+++ b/src/iptables.c
@@ -2045,6 +2045,21 @@ static void cleanup_parse_context(struct parse_context 
*ctx)
        g_free(ctx);
 }
 
+int __connman_iptables_dump(const char *table_name)
+{
+       struct connman_iptables *table;
+
+       DBG("-t %s -L", table_name);
+
+       table = get_table(table_name);
+       if (table == NULL)
+               return -EINVAL;
+
+       dump_table(table);
+
+       return 0;
+}
+
 int __connman_iptables_new_chain(const char *table_name,
                                        const char *chain)
 {
diff --git a/tools/iptables-test.c b/tools/iptables-test.c
index 95d0af4..bef9251 100644
--- a/tools/iptables-test.c
+++ b/tools/iptables-test.c
@@ -34,6 +34,7 @@ enum iptables_command {
        IPTABLES_COMMAND_POLICY,
        IPTABLES_COMMAND_CHAIN_INSERT,
        IPTABLES_COMMAND_CHAIN_DELETE,
+       IPTABLES_COMMAND_DUMP,
        IPTABLES_COMMAND_UNKNOWN,
 };
 
@@ -42,11 +43,12 @@ int main(int argc, char *argv[])
        enum iptables_command cmd = IPTABLES_COMMAND_UNKNOWN;
        char *table = NULL, *chain = NULL, *rule = NULL, *tmp;
        int err, c, i;
+       char *debug;
 
        opterr = 0;
 
        while ((c = getopt_long(argc, argv,
-                               "-A:D:P:N:X:t:", NULL, NULL)) != -1) {
+                               "-A:D:P:N:X:Lt:", NULL, NULL)) != -1) {
                switch (c) {
                case 'A':
                        chain = optarg;
@@ -69,6 +71,9 @@ int main(int argc, char *argv[])
                        chain = optarg;
                        cmd = IPTABLES_COMMAND_CHAIN_DELETE;
                        break;
+               case 'L':
+                       cmd = IPTABLES_COMMAND_DUMP;
+                       break;
                case 't':
                        table = optarg;
                        break;
@@ -89,6 +94,7 @@ out:
 
        __connman_iptables_init();
 
+
        switch (cmd) {
        case IPTABLES_COMMAND_APPEND:
                err = __connman_iptables_append(table, chain, rule);
@@ -105,6 +111,11 @@ out:
        case IPTABLES_COMMAND_CHAIN_DELETE:
                err = __connman_iptables_delete_chain(table, chain);
                break;
+       case IPTABLES_COMMAND_DUMP:
+               __connman_log_init(argv[0], "*", FALSE, FALSE,
+                       "Test itpables", "1");
+               err = __connman_iptables_dump(table);
+               break;
        case IPTABLES_COMMAND_UNKNOWN:
                printf("Missing command\n");
                exit(-EINVAL);
-- 
1.8.1.3.566.gaa39828

_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman

Reply via email to