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_5_H
20 #define __FW3_XTABLES_5_H
22 static inline const char *
23 fw3_xt_get_match_name(struct xtables_match *m)
25 return m->m->u.user.name;
29 fw3_xt_set_match_name(struct xtables_match *m)
31 strcpy(m->m->u.user.name, m->name);
35 fw3_xt_has_match_parse(struct xtables_match *m)
41 fw3_xt_free_match_udata(struct xtables_match *m)
47 fw3_xt_merge_match_options(struct xtables_globals *g, struct xtables_match *m)
49 g->opts = xtables_merge_options(g->opts, m->extra_opts, &m->option_offset);
53 static inline const char *
54 fw3_xt_get_target_name(struct xtables_target *t)
56 return t->t->u.user.name;
60 fw3_xt_set_target_name(struct xtables_target *t, const char *name)
62 strcpy(t->t->u.user.name, name);
66 fw3_xt_has_target_parse(struct xtables_target *t)
72 fw3_xt_free_target_udata(struct xtables_target *t)
78 fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
80 g->opts = xtables_merge_options(g->opts, t->extra_opts, &t->option_offset);
84 /* xtables api addons */
87 xtables_option_mpcall(unsigned int c, char **argv, bool invert,
88 struct xtables_match *m, void *fw)
91 m->parse(c - m->option_offset, argv, invert, &m->mflags, fw, &m->m);
95 xtables_option_mfcall(struct xtables_match *m)
98 m->final_check(m->mflags);
102 xtables_option_tpcall(unsigned int c, char **argv, bool invert,
103 struct xtables_target *t, void *fw)
106 t->parse(c - t->option_offset, argv, invert, &t->tflags, fw, &t->t);
110 xtables_option_tfcall(struct xtables_target *t)
113 t->final_check(t->tflags);
117 xtables_rule_matches_free(struct xtables_rule_match **matches)
119 struct xtables_rule_match *mp, *tmp;
121 for (mp = *matches; mp;)
131 if (mp->match == mp->match->next)
145 xtables_ipmask_to_cidr(const struct in_addr *mask)
150 for (m = ntohl(mask->s_addr), bits = 0; m & 0x80000000; m <<= 1)
157 xtables_ip6mask_to_cidr(const struct in6_addr *mask)
162 a = ntohl(mask->s6_addr32[0]);
163 b = ntohl(mask->s6_addr32[1]);
164 c = ntohl(mask->s6_addr32[2]);
165 d = ntohl(mask->s6_addr32[3]);
167 while (a & 0x80000000U)