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