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