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