2 * firewall3 - 3rd OpenWrt UCI firewall implementation
4 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #ifndef __FW3_XTABLES_10_H
20 #define __FW3_XTABLES_10_H
22 extern struct xtables_match *xtables_pending_matches;
23 extern struct xtables_target *xtables_pending_targets;
28 xtables_matches = NULL;
29 xtables_targets = NULL;
31 xtables_pending_matches = NULL;
32 xtables_pending_targets = NULL;
36 static inline const char *
37 fw3_xt_get_match_name(struct xtables_match *m)
40 return m->alias(m->m);
42 return m->m->u.user.name;
46 fw3_xt_set_match_name(struct xtables_match *m)
49 strcpy(m->m->u.user.name, m->real_name);
51 strcpy(m->m->u.user.name, m->name);
55 fw3_xt_has_match_parse(struct xtables_match *m)
57 return (m->parse || m->x6_parse);
61 fw3_xt_free_match_udata(struct xtables_match *m)
66 m->udata = fw3_alloc(m->udata_size);
71 fw3_xt_merge_match_options(struct xtables_globals *g, struct xtables_match *m)
74 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
75 m->x6_options, &m->option_offset);
78 g->opts = xtables_merge_options(g->orig_opts, g->opts,
79 m->extra_opts, &m->option_offset);
83 static inline const char *
84 fw3_xt_get_target_name(struct xtables_target *t)
87 return t->alias(t->t);
89 return t->t->u.user.name;
93 fw3_xt_set_target_name(struct xtables_target *t, const char *name)
96 strcpy(t->t->u.user.name, t->real_name);
98 strcpy(t->t->u.user.name, name);
102 fw3_xt_has_target_parse(struct xtables_target *t)
104 return (t->parse || t->x6_parse);
108 fw3_xt_free_target_udata(struct xtables_target *t)
113 t->udata = fw3_alloc(t->udata_size);
118 fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
121 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
122 t->x6_options, &t->option_offset);
124 g->opts = xtables_merge_options(g->orig_opts, g->opts,
125 t->extra_opts, &t->option_offset);
129 fw3_xt_print_matches(void *ip, struct xtables_rule_match *matches)
131 struct xtables_rule_match *rm;
132 struct xtables_match *m;
134 for (rm = matches; rm; rm = rm->next)
137 printf(" -m %s", fw3_xt_get_match_name(m));
145 fw3_xt_print_target(void *ip, struct xtables_target *target)
149 printf(" -j %s", fw3_xt_get_target_name(target));
152 target->save(ip, target->t);