xref: /xnu-11417.121.6/bsd/net/kpi_protocol.h (revision a1e26a70f38d1d7daa7b49b258e2f8538ad81650)
1*a1e26a70SApple OSS Distributions /*
2*a1e26a70SApple OSS Distributions  * Copyright (c) 2008-2016 Apple Inc. All rights reserved.
3*a1e26a70SApple OSS Distributions  *
4*a1e26a70SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*a1e26a70SApple OSS Distributions  *
6*a1e26a70SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*a1e26a70SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*a1e26a70SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*a1e26a70SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*a1e26a70SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*a1e26a70SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*a1e26a70SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*a1e26a70SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*a1e26a70SApple OSS Distributions  *
15*a1e26a70SApple OSS Distributions  * Please obtain a copy of the License at
16*a1e26a70SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*a1e26a70SApple OSS Distributions  *
18*a1e26a70SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*a1e26a70SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*a1e26a70SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*a1e26a70SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*a1e26a70SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*a1e26a70SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*a1e26a70SApple OSS Distributions  * limitations under the License.
25*a1e26a70SApple OSS Distributions  *
26*a1e26a70SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*a1e26a70SApple OSS Distributions  */
28*a1e26a70SApple OSS Distributions /*!
29*a1e26a70SApple OSS Distributions  *       @header kpi_protocol.h
30*a1e26a70SApple OSS Distributions  *       This header defines an API to interact with protocols in the kernel.
31*a1e26a70SApple OSS Distributions  *       The KPIs in this header file can be used to interact with protocols
32*a1e26a70SApple OSS Distributions  *       that already exist in the stack. These KPIs can be used to support
33*a1e26a70SApple OSS Distributions  *       existing protocols over media types that are not natively supported
34*a1e26a70SApple OSS Distributions  *       in the kernel, such as ATM.
35*a1e26a70SApple OSS Distributions  */
36*a1e26a70SApple OSS Distributions 
37*a1e26a70SApple OSS Distributions #ifndef __KPI_PROTOCOL__
38*a1e26a70SApple OSS Distributions #define __KPI_PROTOCOL__
39*a1e26a70SApple OSS Distributions #include <sys/kernel_types.h>
40*a1e26a70SApple OSS Distributions #include <net/kpi_interface.h>
41*a1e26a70SApple OSS Distributions 
42*a1e26a70SApple OSS Distributions #ifndef PRIVATE
43*a1e26a70SApple OSS Distributions #include <Availability.h>
44*a1e26a70SApple OSS Distributions #define __NKE_API_DEPRECATED __API_DEPRECATED("Network Kernel Extension KPI is deprecated", macos(10.4, 10.15.4))
45*a1e26a70SApple OSS Distributions #else
46*a1e26a70SApple OSS Distributions #define __NKE_API_DEPRECATED
47*a1e26a70SApple OSS Distributions #endif /* PRIVATE */
48*a1e26a70SApple OSS Distributions 
49*a1e26a70SApple OSS Distributions __BEGIN_DECLS
50*a1e26a70SApple OSS Distributions 
51*a1e26a70SApple OSS Distributions /******************************************************************************/
52*a1e26a70SApple OSS Distributions /* Protocol input/inject                                                      */
53*a1e26a70SApple OSS Distributions /******************************************************************************/
54*a1e26a70SApple OSS Distributions 
55*a1e26a70SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
56*a1e26a70SApple OSS Distributions /*!
57*a1e26a70SApple OSS Distributions  *       @typedef protocol_input_handler
58*a1e26a70SApple OSS Distributions  *       @discussion protocol_input_handler is called to input a packet. If
59*a1e26a70SApple OSS Distributions  *               your protocol has specified a global lock, the lock will be held
60*a1e26a70SApple OSS Distributions  *               when this funciton is called.
61*a1e26a70SApple OSS Distributions  *       @pararm protocol The protocol this packet is intended for.
62*a1e26a70SApple OSS Distributions  *       @param packet The packet that should be input.
63*a1e26a70SApple OSS Distributions  */
64*a1e26a70SApple OSS Distributions typedef void (*proto_input_handler)(protocol_family_t protocol, mbuf_t packet);
65*a1e26a70SApple OSS Distributions 
66*a1e26a70SApple OSS Distributions /*!
67*a1e26a70SApple OSS Distributions  *       @typedef proto_input_detached_handler
68*a1e26a70SApple OSS Distributions  *       @discussion proto_input_detached_handler is called to notify the
69*a1e26a70SApple OSS Distributions  *               protocol that it has been detached. When this function is
70*a1e26a70SApple OSS Distributions  *               called, the proto_input_handler will not be called again, making
71*a1e26a70SApple OSS Distributions  *               it safe to unload.
72*a1e26a70SApple OSS Distributions  *       @pararm protocol The protocol detached.
73*a1e26a70SApple OSS Distributions  */
74*a1e26a70SApple OSS Distributions typedef void (*proto_input_detached_handler)(protocol_family_t protocol);
75*a1e26a70SApple OSS Distributions 
76*a1e26a70SApple OSS Distributions /*!
77*a1e26a70SApple OSS Distributions  *       @function proto_register_input
78*a1e26a70SApple OSS Distributions  *       @discussion Allows the caller to specify the functions called when a
79*a1e26a70SApple OSS Distributions  *               packet for a protocol is received.
80*a1e26a70SApple OSS Distributions  *       @param protocol The protocol family these functions will receive
81*a1e26a70SApple OSS Distributions  *               packets for.
82*a1e26a70SApple OSS Distributions  *       @param input The function called when a packet is input.
83*a1e26a70SApple OSS Distributions  *       @param chains Input function supports packet chains.
84*a1e26a70SApple OSS Distributions  *       @result A errno error on failure.
85*a1e26a70SApple OSS Distributions  */
86*a1e26a70SApple OSS Distributions extern errno_t proto_register_input(protocol_family_t protocol,
87*a1e26a70SApple OSS Distributions     proto_input_handler input, proto_input_detached_handler detached,
88*a1e26a70SApple OSS Distributions     int chains);
89*a1e26a70SApple OSS Distributions 
90*a1e26a70SApple OSS Distributions /*!
91*a1e26a70SApple OSS Distributions  *       @function proto_unregister_input
92*a1e26a70SApple OSS Distributions  *       @discussion Allows the caller to unregister the input and inject
93*a1e26a70SApple OSS Distributions  *               functions for a protocol. The input/inject functions may not be
94*a1e26a70SApple OSS Distributions  *               unregistered immediately if there is a chance they are in use.
95*a1e26a70SApple OSS Distributions  *               To notify the owner when the functions are no longer in use, the
96*a1e26a70SApple OSS Distributions  *               proto_detached_handler function will be called. It is not safe
97*a1e26a70SApple OSS Distributions  *               to unload until the proto_detached_handler is called.
98*a1e26a70SApple OSS Distributions  *       @param protocol The protocol family these functions will receive
99*a1e26a70SApple OSS Distributions  *               packets for.
100*a1e26a70SApple OSS Distributions  */
101*a1e26a70SApple OSS Distributions extern void proto_unregister_input(protocol_family_t protocol);
102*a1e26a70SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
103*a1e26a70SApple OSS Distributions 
104*a1e26a70SApple OSS Distributions /*!
105*a1e26a70SApple OSS Distributions  *       @function proto_input
106*a1e26a70SApple OSS Distributions  *       @discussion Inputs a packet on the specified protocol from the input
107*a1e26a70SApple OSS Distributions  *               path.
108*a1e26a70SApple OSS Distributions  *       @param protocol The protocol of the packet.
109*a1e26a70SApple OSS Distributions  *       @param packet The first packet in a chain of packets to be input.
110*a1e26a70SApple OSS Distributions  *       @result A errno error on failure. Unless proto_input returns zero,
111*a1e26a70SApple OSS Distributions  *               the caller is responsible for freeing the mbuf.
112*a1e26a70SApple OSS Distributions  */
113*a1e26a70SApple OSS Distributions extern errno_t proto_input(protocol_family_t protocol, mbuf_t packet)
114*a1e26a70SApple OSS Distributions __NKE_API_DEPRECATED;
115*a1e26a70SApple OSS Distributions 
116*a1e26a70SApple OSS Distributions /*!
117*a1e26a70SApple OSS Distributions  *       @function proto_inject
118*a1e26a70SApple OSS Distributions  *       @discussion Injects a packet on the specified protocol from
119*a1e26a70SApple OSS Distributions  *               anywhere. To avoid recursion, the protocol may need to queue the
120*a1e26a70SApple OSS Distributions  *               packet to be handled later.
121*a1e26a70SApple OSS Distributions  *       @param protocol The protocol of the packet.
122*a1e26a70SApple OSS Distributions  *       @param packet The first packet in a chain of packets to be injected.
123*a1e26a70SApple OSS Distributions  *       @result A errno error on failure. Unless proto_inject returns zero,
124*a1e26a70SApple OSS Distributions  *               the caller is responsible for freeing the mbuf.
125*a1e26a70SApple OSS Distributions  */
126*a1e26a70SApple OSS Distributions extern errno_t proto_inject(protocol_family_t protocol, mbuf_t packet)
127*a1e26a70SApple OSS Distributions __NKE_API_DEPRECATED;
128*a1e26a70SApple OSS Distributions 
129*a1e26a70SApple OSS Distributions 
130*a1e26a70SApple OSS Distributions /******************************************************************************/
131*a1e26a70SApple OSS Distributions /* Protocol plumbing                                                          */
132*a1e26a70SApple OSS Distributions /******************************************************************************/
133*a1e26a70SApple OSS Distributions 
134*a1e26a70SApple OSS Distributions /*!
135*a1e26a70SApple OSS Distributions  *       @typedef proto_plumb_handler
136*a1e26a70SApple OSS Distributions  *       @discussion proto_plumb_handler is called to attach a protocol to an
137*a1e26a70SApple OSS Distributions  *               interface. A typical protocol plumb function would fill out an
138*a1e26a70SApple OSS Distributions  *               ifnet_attach_proto_param and call ifnet_attach_protocol.
139*a1e26a70SApple OSS Distributions  *       @param ifp The interface the protocol should be attached to.
140*a1e26a70SApple OSS Distributions  *       @param protocol The protocol that should be attached to the
141*a1e26a70SApple OSS Distributions  *               interface.
142*a1e26a70SApple OSS Distributions  *       @result
143*a1e26a70SApple OSS Distributions  *               A non-zero value of the attach failed.
144*a1e26a70SApple OSS Distributions  */
145*a1e26a70SApple OSS Distributions typedef errno_t (*proto_plumb_handler)(ifnet_t ifp, protocol_family_t protocol);
146*a1e26a70SApple OSS Distributions 
147*a1e26a70SApple OSS Distributions /*!
148*a1e26a70SApple OSS Distributions  *       @typedef proto_unplumb_handler
149*a1e26a70SApple OSS Distributions  *       @discussion proto_unplumb_handler is called to detach a protocol
150*a1e26a70SApple OSS Distributions  *               from an interface. A typical unplumb function would call
151*a1e26a70SApple OSS Distributions  *               ifnet_detach_protocol and perform any necessary cleanup.
152*a1e26a70SApple OSS Distributions  *       @param ifp The interface the protocol should be detached from.
153*a1e26a70SApple OSS Distributions  *       @param protocol The protocol that should be detached from the
154*a1e26a70SApple OSS Distributions  *               interface.
155*a1e26a70SApple OSS Distributions  */
156*a1e26a70SApple OSS Distributions typedef void (*proto_unplumb_handler)(ifnet_t ifp, protocol_family_t protocol);
157*a1e26a70SApple OSS Distributions 
158*a1e26a70SApple OSS Distributions /*!
159*a1e26a70SApple OSS Distributions  *       @function proto_register_plumber
160*a1e26a70SApple OSS Distributions  *       @discussion Allows the caller to specify the functions called when a
161*a1e26a70SApple OSS Distributions  *               protocol is attached to an interface belonging to the specified
162*a1e26a70SApple OSS Distributions  *               family and when that protocol is detached.
163*a1e26a70SApple OSS Distributions  *       @param proto_fam The protocol family these plumbing functions will
164*a1e26a70SApple OSS Distributions  *               handle.
165*a1e26a70SApple OSS Distributions  *       @param if_fam The interface family these plumbing functions will
166*a1e26a70SApple OSS Distributions  *               handle.
167*a1e26a70SApple OSS Distributions  *       @param plumb The function to call to attach the protocol to an
168*a1e26a70SApple OSS Distributions  *               interface.
169*a1e26a70SApple OSS Distributions  *       @param unplumb The function to call to detach the protocol to an
170*a1e26a70SApple OSS Distributions  *               interface, may be NULL in which case ifnet_detach_protocol will
171*a1e26a70SApple OSS Distributions  *               be used to detach the protocol.
172*a1e26a70SApple OSS Distributions  *       @result A non-zero value of the attach failed.
173*a1e26a70SApple OSS Distributions  */
174*a1e26a70SApple OSS Distributions extern errno_t proto_register_plumber(protocol_family_t proto_fam,
175*a1e26a70SApple OSS Distributions     ifnet_family_t if_fam, proto_plumb_handler plumb,
176*a1e26a70SApple OSS Distributions     proto_unplumb_handler unplumb)
177*a1e26a70SApple OSS Distributions __NKE_API_DEPRECATED;
178*a1e26a70SApple OSS Distributions 
179*a1e26a70SApple OSS Distributions /*!
180*a1e26a70SApple OSS Distributions  *       @function proto_unregister_plumber
181*a1e26a70SApple OSS Distributions  *       @discussion Unregisters a previously registered plumbing function.
182*a1e26a70SApple OSS Distributions  *       @param proto_fam The protocol family these plumbing functions
183*a1e26a70SApple OSS Distributions  *               handle.
184*a1e26a70SApple OSS Distributions  *       @param if_fam The interface family these plumbing functions handle.
185*a1e26a70SApple OSS Distributions  */
186*a1e26a70SApple OSS Distributions extern void proto_unregister_plumber(protocol_family_t proto_fam,
187*a1e26a70SApple OSS Distributions     ifnet_family_t if_fam)
188*a1e26a70SApple OSS Distributions __NKE_API_DEPRECATED;
189*a1e26a70SApple OSS Distributions 
190*a1e26a70SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
191*a1e26a70SApple OSS Distributions /*
192*a1e26a70SApple OSS Distributions  *       @function proto_plumb
193*a1e26a70SApple OSS Distributions  *       @discussion Plumbs a protocol to an actual interface.  This will find
194*a1e26a70SApple OSS Distributions  *               a registered protocol module and call its attach function.
195*a1e26a70SApple OSS Distributions  *               The module will typically call dlil_attach_protocol() with the
196*a1e26a70SApple OSS Distributions  *               appropriate parameters.
197*a1e26a70SApple OSS Distributions  *       @param protocol_family The protocol family.
198*a1e26a70SApple OSS Distributions  *       @param ifp The interface to plumb the protocol to.
199*a1e26a70SApple OSS Distributions  *       @result 0: No error.
200*a1e26a70SApple OSS Distributions  *               ENOENT: No module was registered.
201*a1e26a70SApple OSS Distributions  *               Other: Error returned by the attach_proto function
202*a1e26a70SApple OSS Distributions  */
203*a1e26a70SApple OSS Distributions extern errno_t proto_plumb(protocol_family_t protocol_family, ifnet_t ifp);
204*a1e26a70SApple OSS Distributions 
205*a1e26a70SApple OSS Distributions /*
206*a1e26a70SApple OSS Distributions  *       @function proto_unplumb
207*a1e26a70SApple OSS Distributions  *       @discussion Unplumbs a protocol from an interface.  This will find
208*a1e26a70SApple OSS Distributions  *               a registered protocol module and call its detach function.
209*a1e26a70SApple OSS Distributions  *               The module will typically call dlil_detach_protocol() with
210*a1e26a70SApple OSS Distributions  *               the appropriate parameters.  If no module is found, this
211*a1e26a70SApple OSS Distributions  *               function will call dlil_detach_protocol directly().
212*a1e26a70SApple OSS Distributions  *       @param protocol_family The protocol family.
213*a1e26a70SApple OSS Distributions  *       @param ifp The interface to unplumb the protocol from.
214*a1e26a70SApple OSS Distributions  *       @result 0: No error.
215*a1e26a70SApple OSS Distributions  *               ENOENT: No module was registered.
216*a1e26a70SApple OSS Distributions  *               Other: Error returned by the attach_proto function
217*a1e26a70SApple OSS Distributions  */
218*a1e26a70SApple OSS Distributions extern errno_t proto_unplumb(protocol_family_t protocol_family, ifnet_t ifp);
219*a1e26a70SApple OSS Distributions 
220*a1e26a70SApple OSS Distributions __private_extern__ void
221*a1e26a70SApple OSS Distributions proto_kpi_init(void);
222*a1e26a70SApple OSS Distributions 
223*a1e26a70SApple OSS Distributions #endif /* BSD_KERNEL_PRIVATE */
224*a1e26a70SApple OSS Distributions __END_DECLS
225*a1e26a70SApple OSS Distributions 
226*a1e26a70SApple OSS Distributions #undef __NKE_API_DEPRECATED
227*a1e26a70SApple OSS Distributions #endif /* __KPI_PROTOCOL__ */
228