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