Add abstract fw3_xt_print_matches() and fw3_xt_print_target() functions since the...
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 4 Jun 2013 10:53:51 +0000 (12:53 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 4 Jun 2013 10:54:32 +0000 (12:54 +0200)
iptables.c
xtables-10.h
xtables-5.h

index 4ae88750d0df42ff1826bdcbd80d44791389f73d..87673ef01aa2f8273fb3d9063bb44643dda9b67a 100644 (file)
@@ -1082,10 +1082,6 @@ rule_print4(struct ipt_entry *e)
 static void
 rule_print(struct fw3_ipt_rule *r, const char *chain)
 {
-       struct xtables_rule_match *rm;
-       struct xtables_match *m;
-       struct xtables_target *t;
-
        debug(r->h, "-A %s", chain);
 
 #ifndef DISABLE_IPV6
@@ -1095,23 +1091,8 @@ rule_print(struct fw3_ipt_rule *r, const char *chain)
 #endif
                rule_print4(&r->e);
 
-       for (rm = r->matches; rm; rm = rm->next)
-       {
-               m = rm->match;
-               printf(" -m %s", fw3_xt_get_match_name(m));
-
-               if (m->save)
-                       m->save(&r->e.ip, m->m);
-       }
-
-       if (r->target)
-       {
-               t = r->target;
-               printf(" -j %s", fw3_xt_get_target_name(t));
-
-               if (t->save)
-                       t->save(&r->e.ip, t->t);
-       }
+       fw3_xt_print_matches(&r->e.ip, r->matches);
+       fw3_xt_print_target(&r->e.ip, r->target);
 
        printf("\n");
 }
index 2372b8c402178ed78c3d680e8c9f0d81d9c3e25c..edd3d3a73b24f68ba58cedc111ecef8d248e31fc 100644 (file)
@@ -125,4 +125,32 @@ fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
                                                t->extra_opts, &t->option_offset);
 }
 
+static inline void
+fw3_xt_print_matches(void *ip, struct xtables_match **matches)
+{
+       struct xtables_rule_match *rm;
+       struct xtables_match *m;
+
+       for (rm = matches; rm; rm = rm->next)
+       {
+               m = rm->match;
+               printf(" -m %s", fw3_xt_get_match_name(m));
+
+               if (m->save)
+                       m->save(ip, m->m);
+       }
+}
+
+static inline void
+fw3_xt_print_target(void *ip, struct xtables_target *target)
+{
+       if (target)
+       {
+               printf(" -j %s", fw3_xt_get_target_name(target));
+
+               if (target->save)
+                       target->save(ip, target->t);
+       }
+}
+
 #endif
index 1ae833453d50ced889d9ce800f0811a26a9f84b4..352250025b57784ce05a08f659ac4be04abf4ec1 100644 (file)
@@ -88,6 +88,36 @@ fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
        g->opts = xtables_merge_options(g->opts, t->extra_opts, &t->option_offset);
 }
 
+static inline void
+fw3_xt_print_matches(void *ip, struct xtables_match **matches)
+{
+       struct xtables_rule_match *rm;
+       struct xtables_match *m;
+
+       printf(" ");
+
+       for (rm = matches; rm; rm = rm->next)
+       {
+               m = rm->match;
+               printf("-m %s ", fw3_xt_get_match_name(m));
+
+               if (m->save)
+                       m->save(ip, m->m);
+       }
+}
+
+static inline void
+fw3_xt_print_target(void *ip, struct xtables_target *target)
+{
+       if (target)
+       {
+               printf("-j %s ", fw3_xt_get_target_name(target));
+
+               if (target->save)
+                       target->save(ip, target->t);
+       }
+}
+
 
 /* xtables api addons */