]>
git.saurik.com Git - apple/xnu.git/blob - bsd/netinet6/ip6_fw.h
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1993 Daniel Boulet
32 * Copyright (c) 1994 Ugen J.S.Antsilevich
34 * Redistribution and use in source forms, with and without modification,
35 * are permitted provided that this entire comment appears intact.
37 * Redistribution in binary form may occur without any restrictions.
38 * Obviously, it would be nice if you gave credit where credit is due
39 * but requiring it would be too onerous.
41 * This software is provided ``AS IS'' without any warranties of any kind.
47 #include <sys/appleapiopts.h>
51 #define IPV6_FW_CURRENT_API_VERSION 20 /* Version of this API */
55 * This union structure identifies an interface, either explicitly
56 * by name or implicitly by IP address. The flags IP_FW_F_IIFNAME
57 * and IP_FW_F_OIFNAME say how to interpret this structure. An
58 * interface unit number of -1 matches any unit number, while an
59 * IP address of 0.0.0.0 indicates matches any interface.
61 * The receive and transmit interfaces are only compared against the
62 * the packet if the corresponding bit (IP_FW_F_IIFACE or IP_FW_F_OIFACE)
63 * is set. Note some packets lack a receive or transmit interface
64 * (in which case the missing "interface" never matches).
68 struct in6_addr fu_via_ip6
; /* Specified by IPv6 address */
69 struct { /* Specified by interface name */
70 #define IP6FW_IFNLEN IFNAMSIZ
71 char name
[IP6FW_IFNLEN
];
72 short unit
; /* -1 means match any unit */
77 * Format of an IP firewall descriptor
79 * fw_src, fw_dst, fw_smsk, fw_dmsk are always stored in network byte order.
80 * fw_flg and fw_n*p are stored in host byte order (of course).
81 * Port numbers are stored in HOST byte order.
82 * Warning: setsockopt() will fail if sizeof(struct ip_fw) > MLEN (108)
86 u_int32_t version
; /* Version of this structure. Should always be */
87 /* set to IP6_FW_CURRENT_API_VERSION by clients. */
88 void *context
; /* Context that is usable by user processes to */
89 /* identify this rule. */
90 u_long fw_pcnt
,fw_bcnt
; /* Packet and byte counters */
91 struct in6_addr fw_src
, fw_dst
; /* Source and destination IPv6 addr */
92 struct in6_addr fw_smsk
, fw_dmsk
; /* Mask for src and dest IPv6 addr */
93 u_short fw_number
; /* Rule number */
94 u_short fw_flg
; /* Flags word */
95 #define IPV6_FW_MAX_PORTS 10 /* A reasonable maximum */
96 u_int fw_ipflg
; /* IP flags word */
97 u_short fw_pts
[IPV6_FW_MAX_PORTS
]; /* Array of port numbers to match */
98 u_char fw_ip6opt
,fw_ip6nopt
; /* IPv6 options set/unset */
99 u_char fw_tcpf
,fw_tcpnf
; /* TCP flags set/unset */
100 #define IPV6_FW_ICMPTYPES_DIM (256 / (sizeof(unsigned) * 8))
101 unsigned fw_icmp6types
[IPV6_FW_ICMPTYPES_DIM
]; /* ICMP types bitmap */
102 long timestamp
; /* timestamp (tv_sec) of last match */
103 union ip6_fw_if fw_in_if
, fw_out_if
;/* Incoming and outgoing interfaces */
105 u_short fu_divert_port
; /* Divert/tee port (options IP6DIVERT) */
106 u_short fu_skipto_rule
; /* SKIPTO command rule number */
107 u_short fu_reject_code
; /* REJECT response code */
109 u_char fw_prot
; /* IPv6 protocol */
110 u_char fw_nports
; /* N'of src ports and # of dst ports */
111 /* in ports array (dst ports follow */
112 /* src ports; max of 10 ports in all; */
113 /* count of 0 means match all ports) */
116 #define IPV6_FW_GETNSRCP(rule) ((rule)->fw_nports & 0x0f)
117 #define IPV6_FW_SETNSRCP(rule, n) do { \
118 (rule)->fw_nports &= ~0x0f; \
119 (rule)->fw_nports |= (n); \
121 #define IPV6_FW_GETNDSTP(rule) ((rule)->fw_nports >> 4)
122 #define IPV6_FW_SETNDSTP(rule, n) do { \
123 (rule)->fw_nports &= ~0xf0; \
124 (rule)->fw_nports |= (n) << 4;\
127 #define fw_divert_port fw_un.fu_divert_port
128 #define fw_skipto_rule fw_un.fu_skipto_rule
129 #define fw_reject_code fw_un.fu_reject_code
131 struct ip6_fw_chain
{
132 LIST_ENTRY(ip6_fw_chain
) chain
;
137 * Values for "flags" field .
139 #define IPV6_FW_F_IN 0x0001 /* Check inbound packets */
140 #define IPV6_FW_F_OUT 0x0002 /* Check outbound packets */
141 #define IPV6_FW_F_IIFACE 0x0004 /* Apply inbound interface test */
142 #define IPV6_FW_F_OIFACE 0x0008 /* Apply outbound interface test */
144 #define IPV6_FW_F_COMMAND 0x0070 /* Mask for type of chain entry: */
145 #define IPV6_FW_F_DENY 0x0000 /* This is a deny rule */
146 #define IPV6_FW_F_REJECT 0x0010 /* Deny and send a response packet */
147 #define IPV6_FW_F_ACCEPT 0x0020 /* This is an accept rule */
148 #define IPV6_FW_F_COUNT 0x0030 /* This is a count rule */
149 #define IPV6_FW_F_DIVERT 0x0040 /* This is a divert rule */
150 #define IPV6_FW_F_TEE 0x0050 /* This is a tee rule */
151 #define IPV6_FW_F_SKIPTO 0x0060 /* This is a skipto rule */
153 #define IPV6_FW_F_PRN 0x0080 /* Print if this rule matches */
155 #define IPV6_FW_F_SRNG 0x0100 /* The first two src ports are a min *
156 * and max range (stored in host byte *
159 #define IPV6_FW_F_DRNG 0x0200 /* The first two dst ports are a min *
160 * and max range (stored in host byte *
163 #define IPV6_FW_F_IIFNAME 0x0400 /* In interface by name/unit (not IP) */
164 #define IPV6_FW_F_OIFNAME 0x0800 /* Out interface by name/unit (not IP) */
166 #define IPV6_FW_F_INVSRC 0x1000 /* Invert sense of src check */
167 #define IPV6_FW_F_INVDST 0x2000 /* Invert sense of dst check */
169 #define IPV6_FW_F_FRAG 0x4000 /* Fragment */
171 #define IPV6_FW_F_ICMPBIT 0x8000 /* ICMP type bitmap is valid */
173 #define IPV6_FW_F_MASK 0xFFFF /* All possible flag bits mask */
176 * Flags for the 'fw_ipflg' field, for comparing values of ip and its protocols. */
177 #define IPV6_FW_IF_TCPEST 0x00000020 /* established TCP connection */
178 #define IPV6_FW_IF_TCPMSK 0x00000020 /* mask of all TCP values */
181 * For backwards compatibility with rules specifying "via iface" but
182 * not restricted to only "in" or "out" packets, we define this combination
183 * of bits to represent this configuration.
186 #define IF6_FW_F_VIAHACK (IPV6_FW_F_IN|IPV6_FW_F_OUT|IPV6_FW_F_IIFACE|IPV6_FW_F_OIFACE)
189 * Definitions for REJECT response codes.
190 * Values less than 256 correspond to ICMP unreachable codes.
192 #define IPV6_FW_REJECT_RST 0x0100 /* TCP packets: send RST */
195 * Definitions for IPv6 option names.
197 #define IPV6_FW_IP6OPT_HOPOPT 0x01
198 #define IPV6_FW_IP6OPT_ROUTE 0x02
199 #define IPV6_FW_IP6OPT_FRAG 0x04
200 #define IPV6_FW_IP6OPT_ESP 0x08
201 #define IPV6_FW_IP6OPT_AH 0x10
202 #define IPV6_FW_IP6OPT_NONXT 0x20
203 #define IPV6_FW_IP6OPT_OPTS 0x40
206 * Definitions for TCP flags.
208 #define IPV6_FW_TCPF_FIN TH_FIN
209 #define IPV6_FW_TCPF_SYN TH_SYN
210 #define IPV6_FW_TCPF_RST TH_RST
211 #define IPV6_FW_TCPF_PSH TH_PUSH
212 #define IPV6_FW_TCPF_ACK TH_ACK
213 #define IPV6_FW_TCPF_URG TH_URG
216 * Main firewall chains definitions and global var's definitions.
218 #ifdef KERNEL_PRIVATE
220 #define M_IP6FW M_IPFW
224 * Function definitions.
226 void ip6_fw_init(void);
231 typedef int ip6_fw_chk_t(struct ip6_hdr
**, struct ifnet
*,
232 u_short
*, struct mbuf
**);
233 typedef int ip6_fw_ctl_t(struct sockopt
*);
234 extern ip6_fw_chk_t
*ip6_fw_chk_ptr
;
235 extern ip6_fw_ctl_t
*ip6_fw_ctl_ptr
;
236 extern int ip6_fw_enable
;
238 #endif /* KERNEL_PRIVATE */
240 #endif /* _IP6_FW_H */