Subversion Repositories SvarDOS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
207 mateuszvis 1
/*!\file netinet6/ip6_fw.h
2
 *
3
 */
4
 
5
/*      $FreeBSD: src/sys/netinet6/ip6_fw.h,v 1.12 2002/04/19 04:46:22 suz Exp $        */
6
/*	$KAME: ip6_fw.h,v 1.9 2001/08/01 04:29:57 sumikawa Exp $	*/
7
 
8
/*
9
 * Copyright (C) 1998, 1999, 2000 and 2001 WIDE Project.
10
 * All rights reserved.
11
 *
12
 * Redistribution and use in source and binary forms, with or without
13
 * modification, are permitted provided that the following conditions
14
 * are met:
15
 * 1. Redistributions of source code must retain the above copyright
16
 *    notice, this list of conditions and the following disclaimer.
17
 * 2. Redistributions in binary form must reproduce the above copyright
18
 *    notice, this list of conditions and the following disclaimer in the
19
 *    documentation and/or other materials provided with the distribution.
20
 * 3. Neither the name of the project nor the names of its contributors
21
 *    may be used to endorse or promote products derived from this software
22
 *    without specific prior written permission.
23
 *
24
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
25
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
28
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34
 * SUCH DAMAGE.
35
 */
36
 
37
/*
38
 * Copyright (c) 1993 Daniel Boulet
39
 * Copyright (c) 1994 Ugen J.S.Antsilevich
40
 *
41
 * Redistribution and use in source forms, with and without modification,
42
 * are permitted provided that this entire comment appears intact.
43
 *
44
 * Redistribution in binary form may occur without any restrictions.
45
 * Obviously, it would be nice if you gave credit where credit is due
46
 * but requiring it would be too onerous.
47
 *
48
 * This software is provided ``AS IS'' without any warranties of any kind.
49
 *
50
 */
51
 
52
#ifndef _IP6_FW_H
53
#define _IP6_FW_H
54
 
55
#include <net/if.h>
56
 
57
/*
58
 * This union structure identifies an interface, either explicitly
59
 * by name or implicitly by IP address. The flags IP_FW_F_IIFNAME
60
 * and IP_FW_F_OIFNAME say how to interpret this structure. An
61
 * interface unit number of -1 matches any unit number, while an
62
 * IP address of 0.0.0.0 indicates matches any interface.
63
 *
64
 * The receive and transmit interfaces are only compared against the
65
 * the packet if the corresponding bit (IP_FW_F_IIFACE or IP_FW_F_OIFACE)
66
 * is set. Note some packets lack a receive or transmit interface
67
 * (in which case the missing "interface" never matches).
68
 */
69
 
70
union ip6_fw_if {
71
    struct in6_addr fu_via_ip6;	/* Specified by IPv6 address */
72
    struct {			/* Specified by interface name */
73
#define IP6FW_IFNLEN     IFNAMSIZ
74
	    char  name[IP6FW_IFNLEN];
75
	    short unit;		/* -1 means match any unit */
76
    } fu_via_if;
77
};
78
 
79
/*
80
 * Format of an IP firewall descriptor
81
 *
82
 * fw_src, fw_dst, fw_smsk, fw_dmsk are always stored in network byte order.
83
 * fw_flg and fw_n*p are stored in host byte order (of course).
84
 * Port numbers are stored in HOST byte order.
85
 * Warning: setsockopt() will fail if sizeof(struct ip_fw) > MLEN (108)
86
 */
87
 
88
struct ip6_fw {
89
    u_long fw_pcnt,fw_bcnt;		/* Packet and byte counters */
90
    struct in6_addr fw_src, fw_dst;	/* Source and destination IPv6 addr */
91
    struct in6_addr fw_smsk, fw_dmsk;	/* Mask for src and dest IPv6 addr */
92
    u_short fw_number;			/* Rule number */
93
    u_short fw_flg;			/* Flags word */
94
#define IPV6_FW_MAX_PORTS	10	/* A reasonable maximum */
95
    u_int fw_ipflg;			/* IP flags word */
96
    u_short fw_pts[IPV6_FW_MAX_PORTS];	/* Array of port numbers to match */
97
    u_char fw_ip6opt,fw_ip6nopt;	/* IPv6 options set/unset */
98
    u_char fw_tcpf,fw_tcpnf;		/* TCP flags set/unset */
99
#define IPV6_FW_ICMPTYPES_DIM (256 / (sizeof(unsigned) * 8))
100
    unsigned fw_icmp6types[IPV6_FW_ICMPTYPES_DIM]; /* ICMP types bitmap */
101
    long timestamp;			/* timestamp (tv_sec) of last match */
102
    union ip6_fw_if fw_in_if, fw_out_if;/* Incoming and outgoing interfaces */
103
    union {
104
	u_short fu_divert_port;		/* Divert/tee port (options IP6DIVERT) */
105
	u_short fu_skipto_rule;		/* SKIPTO command rule number */
106
	u_short fu_reject_code;		/* REJECT response code */
107
    } fw_un;
108
    u_char fw_prot;			/* IPv6 protocol */
109
    u_char fw_nports;			/* N'of src ports and # of dst ports */
110
					/* in ports array (dst ports follow */
111
					/* src ports; max of 10 ports in all; */
112
					/* count of 0 means match all ports) */
113
};
114
 
115
#define IPV6_FW_GETNSRCP(rule)		((rule)->fw_nports & 0x0f)
116
#define IPV6_FW_SETNSRCP(rule, n)		do {				\
117
					  (rule)->fw_nports &= ~0x0f;	\
118
					  (rule)->fw_nports |= (n);	\
119
					} while (0)
120
#define IPV6_FW_GETNDSTP(rule)		((rule)->fw_nports >> 4)
121
#define IPV6_FW_SETNDSTP(rule, n)		do {				\
122
					  (rule)->fw_nports &= ~0xf0;	\
123
					  (rule)->fw_nports |= (n) << 4;\
124
					} while (0)
125
 
126
#define fw_divert_port	fw_un.fu_divert_port
127
#define fw_skipto_rule	fw_un.fu_skipto_rule
128
#define fw_reject_code	fw_un.fu_reject_code
129
 
130
struct ip6_fw_chain {
131
        LIST_ENTRY(ip6_fw_chain) chain;
132
        struct ip6_fw    *rule;
133
};
134
 
135
/*
136
 * Values for "flags" field .
137
 */
138
#define IPV6_FW_F_IN	0x0001	/* Check inbound packets		*/
139
#define IPV6_FW_F_OUT	0x0002	/* Check outbound packets		*/
140
#define IPV6_FW_F_IIFACE	0x0004	/* Apply inbound interface test		*/
141
#define IPV6_FW_F_OIFACE	0x0008	/* Apply outbound interface test	*/
142
 
143
#define IPV6_FW_F_COMMAND 0x0070	/* Mask for type of chain entry:	*/
144
#define IPV6_FW_F_DENY	0x0000	/* This is a deny rule			*/
145
#define IPV6_FW_F_REJECT	0x0010	/* Deny and send a response packet	*/
146
#define IPV6_FW_F_ACCEPT	0x0020	/* This is an accept rule		*/
147
#define IPV6_FW_F_COUNT	0x0030	/* This is a count rule			*/
148
#define IPV6_FW_F_DIVERT	0x0040	/* This is a divert rule		*/
149
#define IPV6_FW_F_TEE	0x0050	/* This is a tee rule			*/
150
#define IPV6_FW_F_SKIPTO	0x0060	/* This is a skipto rule		*/
151
 
152
#define IPV6_FW_F_PRN	0x0080	/* Print if this rule matches		*/
153
 
154
#define IPV6_FW_F_SRNG	0x0100	/* The first two src ports are a min	*
155
				 * and max range (stored in host byte	*
156
				 * order).				*/
157
 
158
#define IPV6_FW_F_DRNG	0x0200	/* The first two dst ports are a min	*
159
				 * and max range (stored in host byte	*
160
				 * order).				*/
161
 
162
#define IPV6_FW_F_IIFNAME	0x0400	/* In interface by name/unit (not IP)	*/
163
#define IPV6_FW_F_OIFNAME	0x0800	/* Out interface by name/unit (not IP)	*/
164
 
165
#define IPV6_FW_F_INVSRC	0x1000	/* Invert sense of src check		*/
166
#define IPV6_FW_F_INVDST	0x2000	/* Invert sense of dst check		*/
167
 
168
#define IPV6_FW_F_FRAG	0x4000	/* Fragment				*/
169
 
170
#define IPV6_FW_F_ICMPBIT 0x8000	/* ICMP type bitmap is valid		*/
171
 
172
#define IPV6_FW_F_MASK	0xFFFF	/* All possible flag bits mask		*/
173
 
174
/* 
175
 * Flags for the 'fw_ipflg' field, for comparing values of ip and its protocols. */
176
#define	IPV6_FW_IF_TCPEST 0x00000020	/* established TCP connection	*/
177
#define IPV6_FW_IF_TCPMSK 0x00000020	/* mask of all TCP values */
178
 
179
/*
180
 * For backwards compatibility with rules specifying "via iface" but
181
 * not restricted to only "in" or "out" packets, we define this combination
182
 * of bits to represent this configuration.
183
 */
184
 
185
#define IF6_FW_F_VIAHACK	(IPV6_FW_F_IN|IPV6_FW_F_OUT|IPV6_FW_F_IIFACE|IPV6_FW_F_OIFACE)
186
 
187
/*
188
 * Definitions for REJECT response codes.
189
 * Values less than 256 correspond to ICMP unreachable codes.
190
 */
191
#define IPV6_FW_REJECT_RST	0x0100		/* TCP packets: send RST */
192
 
193
/*
194
 * Definitions for IPv6 option names.
195
 */
196
#define IPV6_FW_IP6OPT_HOPOPT	0x01
197
#define IPV6_FW_IP6OPT_ROUTE	0x02
198
#define IPV6_FW_IP6OPT_FRAG	0x04
199
#define IPV6_FW_IP6OPT_ESP	0x08
200
#define IPV6_FW_IP6OPT_AH	0x10
201
#define IPV6_FW_IP6OPT_NONXT	0x20
202
#define IPV6_FW_IP6OPT_OPTS	0x40
203
 
204
/*
205
 * Definitions for TCP flags.
206
 */
207
#define IPV6_FW_TCPF_FIN	TH_FIN
208
#define IPV6_FW_TCPF_SYN	TH_SYN
209
#define IPV6_FW_TCPF_RST	TH_RST
210
#define IPV6_FW_TCPF_PSH	TH_PUSH
211
#define IPV6_FW_TCPF_ACK	TH_ACK
212
#define IPV6_FW_TCPF_URG	TH_URG
213
 
214
/*
215
 * Main firewall chains definitions and global var's definitions.
216
 */
217
#ifdef _KERNEL
218
 
219
/*
220
 * Function definitions.
221
 */
222
void ip6_fw_init(void);
223
 
224
/* Firewall hooks */
225
struct ip6_hdr;
226
typedef	int ip6_fw_chk_t __P((struct ip6_hdr**, struct ifnet*,
227
				u_short *, struct mbuf**));
228
typedef	int ip6_fw_ctl_t __P((int, struct mbuf**));
229
extern	ip6_fw_chk_t *ip6_fw_chk_ptr;
230
extern	ip6_fw_ctl_t *ip6_fw_ctl_ptr;
231
extern	int ip6_fw_enable;
232
 
233
#endif /* _KERNEL */
234
 
235
#endif /* _IP6_FW_H */