2 * firewall3 - 3rd OpenWrt UCI firewall implementation
4 * Copyright (C) 2013 Jo-Philipp Wich <jo@mein.io>
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)
48 snprintf(m->m->u.user.name, sizeof(m->m->u.user.name), "%s",
49 m->real_name ? m->real_name : m->name);
53 fw3_xt_has_match_parse(struct xtables_match *m)
55 return (m->parse || m->x6_parse);
59 fw3_xt_free_match_udata(struct xtables_match *m)
64 m->udata = fw3_alloc(m->udata_size);
69 fw3_xt_merge_match_options(struct xtables_globals *g, struct xtables_match *m)
72 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
73 m->x6_options, &m->option_offset);
76 g->opts = xtables_merge_options(g->orig_opts, g->opts,
77 m->extra_opts, &m->option_offset);
81 static inline const char *
82 fw3_xt_get_target_name(struct xtables_target *t)
85 return t->alias(t->t);
87 return t->t->u.user.name;
91 fw3_xt_set_target_name(struct xtables_target *t, const char *name)
93 snprintf(t->t->u.user.name, sizeof(t->t->u.user.name), "%s",
94 t->real_name ? t->real_name : name);
98 fw3_xt_has_target_parse(struct xtables_target *t)
100 return (t->parse || t->x6_parse);
104 fw3_xt_free_target_udata(struct xtables_target *t)
109 t->udata = fw3_alloc(t->udata_size);
114 fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
117 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
118 t->x6_options, &t->option_offset);
120 g->opts = xtables_merge_options(g->orig_opts, g->opts,
121 t->extra_opts, &t->option_offset);
125 fw3_xt_print_matches(void *ip, struct xtables_rule_match *matches)
127 struct xtables_rule_match *rm;
128 struct xtables_match *m;
130 for (rm = matches; rm; rm = rm->next)
133 printf(" -m %s", fw3_xt_get_match_name(m));
141 fw3_xt_print_target(void *ip, struct xtables_target *target)
145 printf(" -j %s", fw3_xt_get_target_name(target));
148 target->save(ip, target->t);