blob: d0da53d96d930cad4d46ad7134d2ee9496aedd5e [file] [log] [blame]
Ben Cheng30692c62013-10-15 18:26:18 -07001/*
2 * 25-Jul-1998 Major changes to allow for ip chain table
3 *
4 * 3-Jan-2000 Named tables to allow packet selection for different uses.
5 */
6
7/*
8 * Format of an IP firewall descriptor
9 *
10 * src, dst, src_mask, dst_mask are always stored in network byte order.
11 * flags are stored in host byte order (of course).
12 * Port numbers are stored in HOST byte order.
13 */
14
15#ifndef _UAPI_IPTABLES_H
16#define _UAPI_IPTABLES_H
17
18#include <linux/types.h>
19#include <linux/compiler.h>
Christopher Ferrisccfaccd2016-08-24 12:11:31 -070020#include <linux/if.h>
Ben Cheng30692c62013-10-15 18:26:18 -070021#include <linux/netfilter_ipv4.h>
22
23#include <linux/netfilter/x_tables.h>
24
25#ifndef __KERNEL__
26#define IPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
27#define IPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
28#define ipt_match xt_match
29#define ipt_target xt_target
30#define ipt_table xt_table
31#define ipt_get_revision xt_get_revision
32#define ipt_entry_match xt_entry_match
33#define ipt_entry_target xt_entry_target
34#define ipt_standard_target xt_standard_target
35#define ipt_error_target xt_error_target
36#define ipt_counters xt_counters
37#define IPT_CONTINUE XT_CONTINUE
38#define IPT_RETURN XT_RETURN
39
40/* This group is older than old (iptables < v1.4.0-rc1~89) */
41#include <linux/netfilter/xt_tcpudp.h>
42#define ipt_udp xt_udp
43#define ipt_tcp xt_tcp
44#define IPT_TCP_INV_SRCPT XT_TCP_INV_SRCPT
45#define IPT_TCP_INV_DSTPT XT_TCP_INV_DSTPT
46#define IPT_TCP_INV_FLAGS XT_TCP_INV_FLAGS
47#define IPT_TCP_INV_OPTION XT_TCP_INV_OPTION
48#define IPT_TCP_INV_MASK XT_TCP_INV_MASK
49#define IPT_UDP_INV_SRCPT XT_UDP_INV_SRCPT
50#define IPT_UDP_INV_DSTPT XT_UDP_INV_DSTPT
51#define IPT_UDP_INV_MASK XT_UDP_INV_MASK
52
53/* The argument to IPT_SO_ADD_COUNTERS. */
54#define ipt_counters_info xt_counters_info
55/* Standard return verdict, or do jump. */
56#define IPT_STANDARD_TARGET XT_STANDARD_TARGET
57/* Error verdict. */
58#define IPT_ERROR_TARGET XT_ERROR_TARGET
59
60/* fn returns 0 to continue iteration */
61#define IPT_MATCH_ITERATE(e, fn, args...) \
62 XT_MATCH_ITERATE(struct ipt_entry, e, fn, ## args)
63
64/* fn returns 0 to continue iteration */
65#define IPT_ENTRY_ITERATE(entries, size, fn, args...) \
66 XT_ENTRY_ITERATE(struct ipt_entry, entries, size, fn, ## args)
67#endif
68
69/* Yes, Virginia, you have to zero the padding. */
70struct ipt_ip {
71 /* Source and destination IP addr */
72 struct in_addr src, dst;
73 /* Mask for src and dest IP addr */
74 struct in_addr smsk, dmsk;
75 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
76 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
77
78 /* Protocol, 0 = ANY */
79 __u16 proto;
80
81 /* Flags word */
82 __u8 flags;
83 /* Inverse flags */
84 __u8 invflags;
85};
86
87/* Values for "flag" field in struct ipt_ip (general ip structure). */
88#define IPT_F_FRAG 0x01 /* Set if rule is a fragment rule */
89#define IPT_F_GOTO 0x02 /* Set if jump is a goto */
90#define IPT_F_MASK 0x03 /* All possible flag bits mask. */
91
92/* Values for "inv" field in struct ipt_ip. */
93#define IPT_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
94#define IPT_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */
95#define IPT_INV_TOS 0x04 /* Invert the sense of TOS. */
96#define IPT_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */
97#define IPT_INV_DSTIP 0x10 /* Invert the sense of DST OP. */
98#define IPT_INV_FRAG 0x20 /* Invert the sense of FRAG. */
99#define IPT_INV_PROTO XT_INV_PROTO
100#define IPT_INV_MASK 0x7F /* All possible flag bits mask. */
101
102/* This structure defines each of the firewall rules. Consists of 3
103 parts which are 1) general IP header stuff 2) match specific
104 stuff 3) the target to perform if the rule matches */
105struct ipt_entry {
106 struct ipt_ip ip;
107
108 /* Mark with fields that we care about. */
109 unsigned int nfcache;
110
111 /* Size of ipt_entry + matches */
112 __u16 target_offset;
113 /* Size of ipt_entry + matches + target */
114 __u16 next_offset;
115
116 /* Back pointer */
117 unsigned int comefrom;
118
119 /* Packet and byte counters. */
120 struct xt_counters counters;
121
122 /* The matches (if any), then the target. */
123 unsigned char elems[0];
124};
125
126/*
127 * New IP firewall options for [gs]etsockopt at the RAW IP level.
128 * Unlike BSD Linux inherits IP options so you don't have to use a raw
129 * socket for this. Instead we check rights in the calls.
130 *
131 * ATTENTION: check linux/in.h before adding new number here.
132 */
133#define IPT_BASE_CTL 64
134
135#define IPT_SO_SET_REPLACE (IPT_BASE_CTL)
136#define IPT_SO_SET_ADD_COUNTERS (IPT_BASE_CTL + 1)
137#define IPT_SO_SET_MAX IPT_SO_SET_ADD_COUNTERS
138
139#define IPT_SO_GET_INFO (IPT_BASE_CTL)
140#define IPT_SO_GET_ENTRIES (IPT_BASE_CTL + 1)
141#define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2)
142#define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3)
143#define IPT_SO_GET_MAX IPT_SO_GET_REVISION_TARGET
144
145/* ICMP matching stuff */
146struct ipt_icmp {
147 __u8 type; /* type to match */
148 __u8 code[2]; /* range of code */
149 __u8 invflags; /* Inverse flags */
150};
151
152/* Values for "inv" field for struct ipt_icmp. */
153#define IPT_ICMP_INV 0x01 /* Invert the sense of type/code test */
154
155/* The argument to IPT_SO_GET_INFO */
156struct ipt_getinfo {
157 /* Which table: caller fills this in. */
158 char name[XT_TABLE_MAXNAMELEN];
159
160 /* Kernel fills these in. */
161 /* Which hook entry points are valid: bitmask */
162 unsigned int valid_hooks;
163
164 /* Hook entry points: one per netfilter hook. */
165 unsigned int hook_entry[NF_INET_NUMHOOKS];
166
167 /* Underflow points. */
168 unsigned int underflow[NF_INET_NUMHOOKS];
169
170 /* Number of entries */
171 unsigned int num_entries;
172
173 /* Size of entries. */
174 unsigned int size;
175};
176
177/* The argument to IPT_SO_SET_REPLACE. */
178struct ipt_replace {
179 /* Which table. */
180 char name[XT_TABLE_MAXNAMELEN];
181
182 /* Which hook entry points are valid: bitmask. You can't
183 change this. */
184 unsigned int valid_hooks;
185
186 /* Number of entries */
187 unsigned int num_entries;
188
189 /* Total size of new entries */
190 unsigned int size;
191
192 /* Hook entry points. */
193 unsigned int hook_entry[NF_INET_NUMHOOKS];
194
195 /* Underflow points. */
196 unsigned int underflow[NF_INET_NUMHOOKS];
197
198 /* Information about old entries: */
199 /* Number of counters (must be equal to current number of entries). */
200 unsigned int num_counters;
201 /* The old entries' counters. */
202 struct xt_counters __user *counters;
203
204 /* The entries (hang off end: not really an array). */
205 struct ipt_entry entries[0];
206};
207
208/* The argument to IPT_SO_GET_ENTRIES. */
209struct ipt_get_entries {
210 /* Which table: user fills this in. */
211 char name[XT_TABLE_MAXNAMELEN];
212
213 /* User fills this in: total entry size. */
214 unsigned int size;
215
216 /* The entries. */
217 struct ipt_entry entrytable[0];
218};
219
220/* Helper functions */
221static __inline__ struct xt_entry_target *
222ipt_get_target(struct ipt_entry *e)
223{
224 return (void *)e + e->target_offset;
225}
226
227/*
228 * Main firewall chains definitions and global var's definitions.
229 */
230#endif /* _UAPI_IPTABLES_H */