Fix compatibility with older libiptc/libip6tc
[project/firewall3.git] / xtables-10.h
1 /*
2 * firewall3 - 3rd OpenWrt UCI firewall implementation
3 *
4 * Copyright (C) 2013 Jo-Philipp Wich <jow@openwrt.org>
5 *
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.
9 *
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.
17 */
18
19 #ifndef __FW3_XTABLES_10_H
20 #define __FW3_XTABLES_10_H
21
22 static inline const char *
23 fw3_xt_get_match_name(struct xtables_match *m)
24 {
25 if (m->alias)
26 return m->alias(m->m);
27
28 return m->m->u.user.name;
29 }
30
31 static inline void
32 fw3_xt_set_match_name(struct xtables_match *m)
33 {
34 if (m->real_name)
35 strcpy(m->m->u.user.name, m->real_name);
36 else
37 strcpy(m->m->u.user.name, m->name);
38 }
39
40 static inline bool
41 fw3_xt_has_match_parse(struct xtables_match *m)
42 {
43 return (m->parse || m->x6_parse);
44 }
45
46 static inline void
47 fw3_xt_free_match_udata(struct xtables_match *m)
48 {
49 if (m->udata_size)
50 {
51 free(m->udata);
52 m->udata = fw3_alloc(m->udata_size);
53 }
54 }
55
56 static inline void
57 fw3_xt_merge_match_options(struct xtables_globals *g, struct xtables_match *m)
58 {
59 if (m->x6_options)
60 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
61 m->x6_options, &m->option_offset);
62
63 if (m->extra_opts)
64 g->opts = xtables_merge_options(g->orig_opts, g->opts,
65 m->extra_opts, &m->option_offset);
66 }
67
68
69 static inline const char *
70 fw3_xt_get_target_name(struct xtables_target *t)
71 {
72 if (t->alias)
73 return t->alias(t->t);
74
75 return t->t->u.user.name;
76 }
77
78 static inline void
79 fw3_xt_set_target_name(struct xtables_target *t, const char *name)
80 {
81 if (t->real_name)
82 strcpy(t->t->u.user.name, t->real_name);
83 else
84 strcpy(t->t->u.user.name, name);
85 }
86
87 static inline bool
88 fw3_xt_has_target_parse(struct xtables_target *t)
89 {
90 return (t->parse || t->x6_parse);
91 }
92
93 static inline void
94 fw3_xt_free_target_udata(struct xtables_target *t)
95 {
96 if (t->udata_size)
97 {
98 free(t->udata);
99 t->udata = fw3_alloc(t->udata_size);
100 }
101 }
102
103 static inline void
104 fw3_xt_merge_target_options(struct xtables_globals *g, struct xtables_target *t)
105 {
106 if (t->x6_options)
107 g->opts = xtables_options_xfrm(g->orig_opts, g->opts,
108 t->x6_options, &t->option_offset);
109 else
110 g->opts = xtables_merge_options(g->orig_opts, g->opts,
111 t->extra_opts, &t->option_offset);
112 }
113
114 #endif