1/*
2 * Copyright (c) 2008-2013 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#ifdef BSD_KERNEL_PRIVATE
68/*
69 * Divert socket definitions.
70 */
71
72/* 32-bit unique unsigned value used to identify a module */
73
74struct divert_tag {
75 u_int32_t info; /* port & flags */
76 u_int16_t cookie; /* ipfw rule number */
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{
85 return ((struct divert_tag *)(mtag+1))->cookie;
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,
91 KERNEL_TAG_TYPE_DIVERT, NULL);
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{
101 return ((struct divert_tag *)(mtag+1))->info;
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,
107 KERNEL_TAG_TYPE_DIVERT, NULL);
108 return mtag ? divert_info(mtag) : 0;
109}
110
111extern void div_init(struct protosw *, struct domain *);
112extern void div_input(struct mbuf *, int);
113lck_mtx_t *
114 div_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);
118extern struct pr_usrreqs div_usrreqs;
119
120#endif /* BSD_KERNEL_PRIVATE */
121#endif /* IPDIVERT */
122#endif /* _NETINET_IP_DIVERT_H_ */
123