]> git.saurik.com Git - apple/xnu.git/blob - bsd/netinet/ip_divert.h
xnu-1504.9.37.tar.gz
[apple/xnu.git] / bsd / netinet / ip_divert.h
1 /*
2 * Copyright (c) 2008 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 /*-
30 * Copyright (c) 2003 Sam Leffler, Errno Consulting
31 * All rights reserved.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer,
38 * without modification.
39 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
40 * similar to the "NO WARRANTY" disclaimer below ("Disclaimer") and any
41 * redistribution must be conditioned upon including a substantially
42 * similar Disclaimer requirement for further binary redistribution.
43 * 3. Neither the names of the above-listed copyright holders nor the names
44 * of any contributors may be used to endorse or promote products derived
45 * from this software without specific prior written permission.
46 *
47 * NO WARRANTY
48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
49 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
50 * LIMITED TO, THE IMPLIED WARRANTIES OF NONINFRINGEMENT, MERCHANTIBILITY
51 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
52 * THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY,
53 * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
54 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
55 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
56 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
57 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
58 * THE POSSIBILITY OF SUCH DAMAGES.
59 *
60 * $FreeBSD: src/sys/netinet/ip_divert.h,v 1.3 2004/02/25 19:55:28 mlaier Exp $
61 */
62
63 #ifndef _NETINET_IP_DIVERT_H_
64 #define _NETINET_IP_DIVERT_H_
65
66 #if IPDIVERT
67 /*
68 * Divert socket definitions.
69 */
70
71 /* 32-bit unique unsigned value used to identify a module */
72
73 struct divert_tag {
74 u_int32_t info; /* port & flags */
75 u_int16_t cookie; /* ipfw rule number */
76 };
77
78 /*
79 * Return the divert cookie associated with the mbuf; if any.
80 */
81 static __inline u_int16_t
82 divert_cookie(struct m_tag *mtag)
83 {
84 return ((struct divert_tag *)(mtag+1))->cookie;
85 }
86 static __inline u_int16_t
87 divert_find_cookie(struct mbuf *m)
88 {
89 struct m_tag *mtag = m_tag_locate(m, KERNEL_MODULE_TAG_ID,
90 KERNEL_TAG_TYPE_DIVERT, NULL);
91 return mtag ? divert_cookie(mtag) : 0;
92 }
93
94 /*
95 * Return the divert info associated with the mbuf; if any.
96 */
97 static __inline u_int32_t
98 divert_info(struct m_tag *mtag)
99 {
100 return ((struct divert_tag *)(mtag+1))->info;
101 }
102 static __inline u_int32_t
103 divert_find_info(struct mbuf *m)
104 {
105 struct m_tag *mtag = m_tag_locate(m, KERNEL_MODULE_TAG_ID,
106 KERNEL_TAG_TYPE_DIVERT, NULL);
107 return mtag ? divert_info(mtag) : 0;
108 }
109
110 extern void div_init(void) __attribute__((section("__TEXT, initcode")));
111 extern void div_input(struct mbuf *, int);
112 lck_mtx_t *
113 div_getlock(struct socket *, int );
114 int div_unlock(struct socket *, int, void *);
115 int div_lock(struct socket *, int , void *);
116 extern void divert_packet(struct mbuf *m, int incoming, int port, int rule);
117 extern struct pr_usrreqs div_usrreqs;
118
119 #endif /* IPDIVERT */
120 #endif /* _NETINET_IP_DIVERT_H_ */