Add missing libip6t_REJECT initialization
[project/firewall3.git] / iptables.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_IPTABLES_H
20 #define __FW3_IPTABLES_H
21
22 #include <libiptc/libiptc.h>
23 #include <libiptc/libip6tc.h>
24 #include <xtables.h>
25
26 #include <unistd.h>
27 #include <getopt.h>
28 #include <sys/utsname.h>
29
30 #include "options.h"
31
32
33 extern struct xtables_match *xtables_pending_matches;
34 extern struct xtables_target *xtables_pending_targets;
35
36 /* libext.a interface */
37 void libip6t_icmp6_init(void);
38 void libip6t_LOG_init(void);
39 void libip6t_REJECT_init(void);
40 void libipt_DNAT_init(void);
41 void libipt_icmp_init(void);
42 void libipt_LOG_init(void);
43 void libipt_MASQUERADE_init(void);
44 void libipt_REDIRECT_init(void);
45 void libipt_REJECT_init(void);
46 void libipt_SNAT_init(void);
47 void libxt_comment_init(void);
48 void libxt_conntrack_init(void);
49 void libxt_CT_init(void);
50 void libxt_limit_init(void);
51 void libxt_mac_init(void);
52 void libxt_mark_init(void);
53 void libxt_MARK_init(void);
54 void libxt_set_init(void);
55 void libxt_SET_init(void);
56 void libxt_standard_init(void);
57 void libxt_TCPMSS_init(void);
58 void libxt_tcp_init(void);
59 void libxt_time_init(void);
60 void libxt_udp_init(void);
61
62 /* Required by certain extensions like SNAT and DNAT */
63 extern int kernel_version;
64 void get_kernel_version(void);
65
66 struct fw3_ipt_handle {
67 enum fw3_family family;
68 enum fw3_table table;
69 struct xtc_handle *handle;
70 };
71
72 struct fw3_ipt_rule {
73 struct fw3_ipt_handle *h;
74
75 union {
76 struct ipt_entry e;
77 struct ip6t_entry e6;
78 };
79
80 struct xtables_rule_match *matches;
81 struct xtables_target *target;
82
83 int argc;
84 char **argv;
85
86 uint32_t protocol;
87 bool protocol_loaded;
88 };
89
90 struct fw3_ipt_handle *fw3_ipt_open(enum fw3_family family,
91 enum fw3_table table);
92
93 void fw3_ipt_set_policy(struct fw3_ipt_handle *h, const char *chain,
94 enum fw3_flag policy);
95
96 void fw3_ipt_delete_chain(struct fw3_ipt_handle *h, const char *chain);
97 void fw3_ipt_delete_rules(struct fw3_ipt_handle *h, const char *target);
98
99 void fw3_ipt_create_chain(struct fw3_ipt_handle *h, const char *fmt, ...);
100
101 void fw3_ipt_flush(struct fw3_ipt_handle *h);
102
103 void fw3_ipt_commit(struct fw3_ipt_handle *h);
104
105 struct fw3_ipt_rule *fw3_ipt_rule_new(struct fw3_ipt_handle *h);
106
107 void fw3_ipt_rule_proto(struct fw3_ipt_rule *r, struct fw3_protocol *proto);
108
109 void fw3_ipt_rule_in_out(struct fw3_ipt_rule *r,
110 struct fw3_device *in, struct fw3_device *out);
111
112 void fw3_ipt_rule_src_dest(struct fw3_ipt_rule *r,
113 struct fw3_address *src, struct fw3_address *dest);
114
115 void fw3_ipt_rule_sport_dport(struct fw3_ipt_rule *r,
116 struct fw3_port *sp, struct fw3_port *dp);
117
118 void fw3_ipt_rule_mac(struct fw3_ipt_rule *r, struct fw3_mac *mac);
119
120 void fw3_ipt_rule_icmptype(struct fw3_ipt_rule *r, struct fw3_icmptype *icmp);
121
122 void fw3_ipt_rule_limit(struct fw3_ipt_rule *r, struct fw3_limit *limit);
123
124 void fw3_ipt_rule_ipset(struct fw3_ipt_rule *r, struct fw3_ipset *ipset,
125 bool invert);
126
127 void fw3_ipt_rule_time(struct fw3_ipt_rule *r, struct fw3_time *time);
128
129 void fw3_ipt_rule_mark(struct fw3_ipt_rule *r, struct fw3_mark *mark);
130
131 void fw3_ipt_rule_comment(struct fw3_ipt_rule *r, const char *fmt, ...);
132
133 void fw3_ipt_rule_extra(struct fw3_ipt_rule *r, const char *extra);
134
135 void fw3_ipt_rule_addarg(struct fw3_ipt_rule *r, bool inv,
136 const char *k, const char *v);
137
138 struct fw3_ipt_rule * fw3_ipt_rule_create(struct fw3_ipt_handle *handle,
139 struct fw3_protocol *proto,
140 struct fw3_device *in,
141 struct fw3_device *out,
142 struct fw3_address *src,
143 struct fw3_address *dest);
144
145 void fw3_ipt_rule_append(struct fw3_ipt_rule *r, const char *fmt, ...);
146
147 static inline void
148 fw3_ipt_rule_target(struct fw3_ipt_rule *r, const char *fmt, ...)
149 {
150 va_list ap;
151 char buf[32];
152
153 va_start(ap, fmt);
154 vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
155 va_end(ap);
156
157 fw3_ipt_rule_addarg(r, false, "-j", buf);
158 }
159
160 #endif