]> git.saurik.com Git - apple/xnu.git/blame - bsd/netinet/ip_divert.h
xnu-6153.81.5.tar.gz
[apple/xnu.git] / bsd / netinet / ip_divert.h
CommitLineData
b0d623f7 1/*
39236c6e 2 * Copyright (c) 2008-2013 Apple Inc. All rights reserved.
b0d623f7
A
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
b0d623f7
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 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.
0a7de745 14 *
b0d623f7
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
b0d623f7
A
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.
0a7de745 25 *
b0d623f7
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
91447636
A
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_
0a7de745 64#define _NETINET_IP_DIVERT_H_
91447636
A
65
66#if IPDIVERT
39236c6e 67#ifdef BSD_KERNEL_PRIVATE
91447636
A
68/*
69 * Divert socket definitions.
70 */
71
72/* 32-bit unique unsigned value used to identify a module */
73
74struct divert_tag {
0a7de745
A
75 u_int32_t info; /* port & flags */
76 u_int16_t cookie; /* ipfw rule number */
91447636
A
77};
78
79/*
80 * Return the divert cookie associated with the mbuf; if any.
81 */
82static __inline u_int16_t
83divert_cookie(struct m_tag *mtag)
84{
0a7de745 85 return ((struct divert_tag *)(mtag + 1))->cookie;
91447636
A
86}
87static __inline u_int16_t
88divert_find_cookie(struct mbuf *m)
89{
90 struct m_tag *mtag = m_tag_locate(m, KERNEL_MODULE_TAG_ID,
0a7de745 91 KERNEL_TAG_TYPE_DIVERT, NULL);
91447636
A
92 return mtag ? divert_cookie(mtag) : 0;
93}
94
95/*
96 * Return the divert info associated with the mbuf; if any.
97 */
98static __inline u_int32_t
99divert_info(struct m_tag *mtag)
100{
0a7de745 101 return ((struct divert_tag *)(mtag + 1))->info;
91447636
A
102}
103static __inline u_int32_t
104divert_find_info(struct mbuf *m)
105{
106 struct m_tag *mtag = m_tag_locate(m, KERNEL_MODULE_TAG_ID,
0a7de745 107 KERNEL_TAG_TYPE_DIVERT, NULL);
91447636
A
108 return mtag ? divert_info(mtag) : 0;
109}
110
0a7de745
A
111extern void div_init(struct protosw *, struct domain *);
112extern void div_input(struct mbuf *, int);
113lck_mtx_t *
114div_getlock(struct socket *, int );
115int div_unlock(struct socket *, int, void *);
116int div_lock(struct socket *, int, void *);
117extern void divert_packet(struct mbuf *m, int incoming, int port, int rule);
91447636
A
118extern struct pr_usrreqs div_usrreqs;
119
39236c6e 120#endif /* BSD_KERNEL_PRIVATE */
91447636
A
121#endif /* IPDIVERT */
122#endif /* _NETINET_IP_DIVERT_H_ */