Home | History | Annotate | Download | only in netfilter_ipv6
      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 IP6 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 _IP6_TABLES_H
     16 #define _IP6_TABLES_H
     17 
     18 #include <linux/types.h>
     19 
     20 #include <linux/netfilter_ipv6.h>
     21 
     22 #include <linux/netfilter/x_tables.h>
     23 
     24 #define IP6T_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
     25 #define IP6T_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
     26 #define ip6t_match xt_match
     27 #define ip6t_target xt_target
     28 #define ip6t_table xt_table
     29 #define ip6t_get_revision xt_get_revision
     30 #define ip6t_entry_match xt_entry_match
     31 #define ip6t_entry_target xt_entry_target
     32 #define ip6t_standard_target xt_standard_target
     33 #define ip6t_error_target xt_error_target
     34 #define ip6t_counters xt_counters
     35 #define IP6T_CONTINUE XT_CONTINUE
     36 #define IP6T_RETURN XT_RETURN
     37 
     38 /* Pre-iptables-1.4.0 */
     39 #include <linux/netfilter/xt_tcpudp.h>
     40 #define ip6t_tcp xt_tcp
     41 #define ip6t_udp xt_udp
     42 #define IP6T_TCP_INV_SRCPT	XT_TCP_INV_SRCPT
     43 #define IP6T_TCP_INV_DSTPT	XT_TCP_INV_DSTPT
     44 #define IP6T_TCP_INV_FLAGS	XT_TCP_INV_FLAGS
     45 #define IP6T_TCP_INV_OPTION	XT_TCP_INV_OPTION
     46 #define IP6T_TCP_INV_MASK	XT_TCP_INV_MASK
     47 #define IP6T_UDP_INV_SRCPT	XT_UDP_INV_SRCPT
     48 #define IP6T_UDP_INV_DSTPT	XT_UDP_INV_DSTPT
     49 #define IP6T_UDP_INV_MASK	XT_UDP_INV_MASK
     50 
     51 #define ip6t_counters_info xt_counters_info
     52 #define IP6T_STANDARD_TARGET XT_STANDARD_TARGET
     53 #define IP6T_ERROR_TARGET XT_ERROR_TARGET
     54 #define IP6T_MATCH_ITERATE(e, fn, args...) \
     55 	XT_MATCH_ITERATE(struct ip6t_entry, e, fn, ## args)
     56 #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
     57 	XT_ENTRY_ITERATE(struct ip6t_entry, entries, size, fn, ## args)
     58 
     59 /* Yes, Virginia, you have to zero the padding. */
     60 struct ip6t_ip6 {
     61 	/* Source and destination IP6 addr */
     62 	struct in6_addr src, dst;
     63 	/* Mask for src and dest IP6 addr */
     64 	struct in6_addr smsk, dmsk;
     65 	char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
     66 	unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
     67 
     68 	/* Upper protocol number
     69 	 * - The allowed value is 0 (any) or protocol number of last parsable
     70 	 *   header, which is 50 (ESP), 59 (No Next Header), 135 (MH), or
     71 	 *   the non IPv6 extension headers.
     72 	 * - The protocol numbers of IPv6 extension headers except of ESP and
     73 	 *   MH do not match any packets.
     74 	 * - You also need to set IP6T_FLAGS_PROTO to "flags" to check protocol.
     75 	 */
     76 	__u16 proto;
     77 	/* TOS to match iff flags & IP6T_F_TOS */
     78 	__u8 tos;
     79 
     80 	/* Flags word */
     81 	__u8 flags;
     82 	/* Inverse flags */
     83 	__u8 invflags;
     84 };
     85 
     86 /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
     87 #define IP6T_F_PROTO		0x01	/* Set if rule cares about upper
     88 					   protocols */
     89 #define IP6T_F_TOS		0x02	/* Match the TOS. */
     90 #define IP6T_F_GOTO		0x04	/* Set if jump is a goto */
     91 #define IP6T_F_MASK		0x07	/* All possible flag bits mask. */
     92 
     93 /* Values for "inv" field in struct ip6t_ip6. */
     94 #define IP6T_INV_VIA_IN		0x01	/* Invert the sense of IN IFACE. */
     95 #define IP6T_INV_VIA_OUT		0x02	/* Invert the sense of OUT IFACE */
     96 #define IP6T_INV_TOS		0x04	/* Invert the sense of TOS. */
     97 #define IP6T_INV_SRCIP		0x08	/* Invert the sense of SRC IP. */
     98 #define IP6T_INV_DSTIP		0x10	/* Invert the sense of DST OP. */
     99 #define IP6T_INV_FRAG		0x20	/* Invert the sense of FRAG. */
    100 #define IP6T_INV_PROTO		XT_INV_PROTO
    101 #define IP6T_INV_MASK		0x7F	/* All possible flag bits mask. */
    102 
    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 */
    106 struct ip6t_entry {
    107 	struct ip6t_ip6 ipv6;
    108 
    109 	/* Mark with fields that we care about. */
    110 	unsigned int nfcache;
    111 
    112 	/* Size of ipt_entry + matches */
    113 	__u16 target_offset;
    114 	/* Size of ipt_entry + matches + target */
    115 	__u16 next_offset;
    116 
    117 	/* Back pointer */
    118 	unsigned int comefrom;
    119 
    120 	/* Packet and byte counters. */
    121 	struct xt_counters counters;
    122 
    123 	/* The matches (if any), then the target. */
    124 	unsigned char elems[0];
    125 };
    126 
    127 /* Standard entry */
    128 struct ip6t_standard {
    129 	struct ip6t_entry entry;
    130 	struct xt_standard_target target;
    131 };
    132 
    133 struct ip6t_error {
    134 	struct ip6t_entry entry;
    135 	struct xt_error_target target;
    136 };
    137 
    138 #define IP6T_ENTRY_INIT(__size)						       \
    139 {									       \
    140 	.target_offset	= sizeof(struct ip6t_entry),			       \
    141 	.next_offset	= (__size),					       \
    142 }
    143 
    144 #define IP6T_STANDARD_INIT(__verdict)					       \
    145 {									       \
    146 	.entry		= IP6T_ENTRY_INIT(sizeof(struct ip6t_standard)),       \
    147 	.target		= XT_TARGET_INIT(XT_STANDARD_TARGET,		       \
    148 					 sizeof(struct xt_standard_target)),   \
    149 	.target.verdict	= -(__verdict) - 1,				       \
    150 }
    151 
    152 #define IP6T_ERROR_INIT							       \
    153 {									       \
    154 	.entry		= IP6T_ENTRY_INIT(sizeof(struct ip6t_error)),	       \
    155 	.target		= XT_TARGET_INIT(XT_ERROR_TARGET,		       \
    156 					 sizeof(struct xt_error_target)),      \
    157 	.target.errorname = "ERROR",					       \
    158 }
    159 
    160 /*
    161  * New IP firewall options for [gs]etsockopt at the RAW IP level.
    162  * Unlike BSD Linux inherits IP options so you don't have to use
    163  * a raw socket for this. Instead we check rights in the calls.
    164  *
    165  * ATTENTION: check linux/in6.h before adding new number here.
    166  */
    167 #define IP6T_BASE_CTL			64
    168 
    169 #define IP6T_SO_SET_REPLACE		(IP6T_BASE_CTL)
    170 #define IP6T_SO_SET_ADD_COUNTERS	(IP6T_BASE_CTL + 1)
    171 #define IP6T_SO_SET_MAX			IP6T_SO_SET_ADD_COUNTERS
    172 
    173 #define IP6T_SO_GET_INFO		(IP6T_BASE_CTL)
    174 #define IP6T_SO_GET_ENTRIES		(IP6T_BASE_CTL + 1)
    175 #define IP6T_SO_GET_REVISION_MATCH	(IP6T_BASE_CTL + 4)
    176 #define IP6T_SO_GET_REVISION_TARGET	(IP6T_BASE_CTL + 5)
    177 #define IP6T_SO_GET_MAX			IP6T_SO_GET_REVISION_TARGET
    178 
    179 /* obtain original address if REDIRECT'd connection */
    180 #define IP6T_SO_ORIGINAL_DST            80
    181 
    182 /* ICMP matching stuff */
    183 struct ip6t_icmp {
    184 	__u8 type;				/* type to match */
    185 	__u8 code[2];				/* range of code */
    186 	__u8 invflags;				/* Inverse flags */
    187 };
    188 
    189 /* Values for "inv" field for struct ipt_icmp. */
    190 #define IP6T_ICMP_INV	0x01	/* Invert the sense of type/code test */
    191 
    192 /* The argument to IP6T_SO_GET_INFO */
    193 struct ip6t_getinfo {
    194 	/* Which table: caller fills this in. */
    195 	char name[XT_TABLE_MAXNAMELEN];
    196 
    197 	/* Kernel fills these in. */
    198 	/* Which hook entry points are valid: bitmask */
    199 	unsigned int valid_hooks;
    200 
    201 	/* Hook entry points: one per netfilter hook. */
    202 	unsigned int hook_entry[NF_INET_NUMHOOKS];
    203 
    204 	/* Underflow points. */
    205 	unsigned int underflow[NF_INET_NUMHOOKS];
    206 
    207 	/* Number of entries */
    208 	unsigned int num_entries;
    209 
    210 	/* Size of entries. */
    211 	unsigned int size;
    212 };
    213 
    214 /* The argument to IP6T_SO_SET_REPLACE. */
    215 struct ip6t_replace {
    216 	/* Which table. */
    217 	char name[XT_TABLE_MAXNAMELEN];
    218 
    219 	/* Which hook entry points are valid: bitmask.  You can't
    220            change this. */
    221 	unsigned int valid_hooks;
    222 
    223 	/* Number of entries */
    224 	unsigned int num_entries;
    225 
    226 	/* Total size of new entries */
    227 	unsigned int size;
    228 
    229 	/* Hook entry points. */
    230 	unsigned int hook_entry[NF_INET_NUMHOOKS];
    231 
    232 	/* Underflow points. */
    233 	unsigned int underflow[NF_INET_NUMHOOKS];
    234 
    235 	/* Information about old entries: */
    236 	/* Number of counters (must be equal to current number of entries). */
    237 	unsigned int num_counters;
    238 	/* The old entries' counters. */
    239 	struct xt_counters *counters;
    240 
    241 	/* The entries (hang off end: not really an array). */
    242 	struct ip6t_entry entries[0];
    243 };
    244 
    245 /* The argument to IP6T_SO_GET_ENTRIES. */
    246 struct ip6t_get_entries {
    247 	/* Which table: user fills this in. */
    248 	char name[XT_TABLE_MAXNAMELEN];
    249 
    250 	/* User fills this in: total entry size. */
    251 	unsigned int size;
    252 
    253 	/* The entries. */
    254 	struct ip6t_entry entrytable[0];
    255 };
    256 
    257 /* Helper functions */
    258 static __inline__ struct xt_entry_target *
    259 ip6t_get_target(struct ip6t_entry *e)
    260 {
    261 	return (void *)e + e->target_offset;
    262 }
    263 
    264 /*
    265  *	Main firewall chains definitions and global var's definitions.
    266  */
    267 
    268 #endif /* _IP6_TABLES_H */
    269