From: Jo-Philipp Wich Date: Tue, 4 Jun 2013 10:53:51 +0000 (+0200) Subject: Add abstract fw3_xt_print_matches() and fw3_xt_print_target() functions since the... X-Git-Url: http://git.openwrt.org/?p=project%2Ffirewall3.git;a=commitdiff_plain;h=e7b6234df3d34d82b909f1e7367a89d322f87814 Add abstract fw3_xt_print_matches() and fw3_xt_print_target() functions since the output of ->save differs between xtables 5 and 10... sigh --- diff --git a/iptables.c b/iptables.c index 4ae8875..87673ef 100644 --- a/iptables.c +++ b/iptables.c @@ -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"); } diff --git a/xtables-10.h b/xtables-10.h index 2372b8c..edd3d3a 100644 --- a/xtables-10.h +++ b/xtables-10.h @@ -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 diff --git a/xtables-5.h b/xtables-5.h index 1ae8334..3522500 100644 --- a/xtables-5.h +++ b/xtables-5.h @@ -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 */