]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet6/ip6_fw.h
xnu-792.12.6.tar.gz
[apple/xnu.git] / bsd / netinet6 / ip6_fw.h
CommitLineData
9bccf70c
A
1/*
2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
3 *
8ad349bb 4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
9bccf70c 5 *
8ad349bb
A
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
9bccf70c 29 */
1c79356b
A
30/*
31 * Copyright (c) 1993 Daniel Boulet
32 * Copyright (c) 1994 Ugen J.S.Antsilevich
33 *
34 * Redistribution and use in source forms, with and without modification,
35 * are permitted provided that this entire comment appears intact.
36 *
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.
40 *
41 * This software is provided ``AS IS'' without any warranties of any kind.
42 *
43 */
44
45#ifndef _IP6_FW_H
46#define _IP6_FW_H
9bccf70c 47#include <sys/appleapiopts.h>
1c79356b
A
48
49#include <net/if.h>
9bccf70c 50
55e303ae 51#define IPV6_FW_CURRENT_API_VERSION 20 /* Version of this API */
9bccf70c 52
1c79356b
A
53
54/*
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.
60 *
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).
65 */
66
67union ip6_fw_if {
68 struct in6_addr fu_via_ip6; /* Specified by IPv6 address */
69 struct { /* Specified by interface name */
9bccf70c
A
70#define IP6FW_IFNLEN IFNAMSIZ
71 char name[IP6FW_IFNLEN];
1c79356b
A
72 short unit; /* -1 means match any unit */
73 } fu_via_if;
74};
75
76/*
77 * Format of an IP firewall descriptor
78 *
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)
83 */
84
85struct ip6_fw {
9bccf70c
A
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. */
1c79356b
A
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 */
9bccf70c 96 u_int fw_ipflg; /* IP flags word */
1c79356b
A
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 */
9bccf70c 100#define IPV6_FW_ICMPTYPES_DIM (256 / (sizeof(unsigned) * 8))
1c79356b
A
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 */
104 union {
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 */
108 } fw_un;
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) */
114};
115
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); \
120 } while (0)
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;\
125 } while (0)
126
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
130
131struct ip6_fw_chain {
132 LIST_ENTRY(ip6_fw_chain) chain;
133 struct ip6_fw *rule;
134};
135
136/*
137 * Values for "flags" field .
138 */
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 */
143
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 */
152
153#define IPV6_FW_F_PRN 0x0080 /* Print if this rule matches */
154
155#define IPV6_FW_F_SRNG 0x0100 /* The first two src ports are a min *
156 * and max range (stored in host byte *
157 * order). */
158
159#define IPV6_FW_F_DRNG 0x0200 /* The first two dst ports are a min *
160 * and max range (stored in host byte *
161 * order). */
162
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) */
165
166#define IPV6_FW_F_INVSRC 0x1000 /* Invert sense of src check */
167#define IPV6_FW_F_INVDST 0x2000 /* Invert sense of dst check */
168
169#define IPV6_FW_F_FRAG 0x4000 /* Fragment */
170
171#define IPV6_FW_F_ICMPBIT 0x8000 /* ICMP type bitmap is valid */
172
173#define IPV6_FW_F_MASK 0xFFFF /* All possible flag bits mask */
174
9bccf70c
A
175/*
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 */
179
1c79356b
A
180/*
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.
184 */
185
186#define IF6_FW_F_VIAHACK (IPV6_FW_F_IN|IPV6_FW_F_OUT|IPV6_FW_F_IIFACE|IPV6_FW_F_OIFACE)
187
188/*
189 * Definitions for REJECT response codes.
190 * Values less than 256 correspond to ICMP unreachable codes.
191 */
192#define IPV6_FW_REJECT_RST 0x0100 /* TCP packets: send RST */
193
194/*
195 * Definitions for IPv6 option names.
196 */
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
204
205/*
206 * Definitions for TCP flags.
207 */
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
1c79356b
A
214
215/*
216 * Main firewall chains definitions and global var's definitions.
217 */
91447636 218#ifdef KERNEL_PRIVATE
9bccf70c
A
219
220#define M_IP6FW M_IPFW
221
1c79356b
A
222
223/*
224 * Function definitions.
225 */
226void ip6_fw_init(void);
227
228/* Firewall hooks */
229struct ip6_hdr;
55e303ae 230struct sockopt;
91447636
A
231typedef int ip6_fw_chk_t(struct ip6_hdr**, struct ifnet*,
232 u_short *, struct mbuf**);
233typedef int ip6_fw_ctl_t(struct sockopt *);
1c79356b
A
234extern ip6_fw_chk_t *ip6_fw_chk_ptr;
235extern ip6_fw_ctl_t *ip6_fw_ctl_ptr;
9bccf70c 236extern int ip6_fw_enable;
1c79356b 237
91447636 238#endif /* KERNEL_PRIVATE */
1c79356b
A
239
240#endif /* _IP6_FW_H */