]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/kpi_protocol.h
c24727f0d1991e66bc4976f647c96eb599281e72
[apple/xnu.git] / bsd / net / kpi_protocol.h
1 /*
2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*!
24 @header kpi_protocol.h
25 This header defines an API to interact with protocols in the kernel.
26 The KPIs in this header file can be used to interact with protocols
27 that already exist in the stack. These KPIs can be used to support
28 existing protocols over media types that are not natively supported
29 in the kernel, such as ATM.
30 */
31
32 #ifndef __KPI_PROTOCOL__
33 #define __KPI_PROTOCOL__
34 #include <sys/kernel_types.h>
35 #include <net/kpi_interface.h>
36
37
38 __BEGIN_DECLS
39
40 /****************************************************************************/
41 /* Protocol input/inject */
42 /****************************************************************************/
43
44 #ifdef KERNEL_PRIVATE
45 /*!
46 @typedef protocol_input_handler
47 @discussion protocol_input_handler is called to input a packet. If
48 your protocol has specified a global lock, the lock will be held
49 when this funciton is called.
50 @pararm protocol The protocol this packet is intended for.
51 @param packet The packet that should be input.
52 */
53 typedef void (*proto_input_handler)(protocol_family_t protocol, mbuf_t packet);
54
55 /*!
56 @typedef proto_input_detached_handler
57 @discussion proto_input_detached_handler is called to notify the
58 protocol that it has been detached. When this function is
59 called, the proto_input_handler will not be called again, making
60 it safe to unload.
61 @pararm protocol The protocol detached.
62 */
63 typedef void (*proto_input_detached_handler)(protocol_family_t protocol);
64
65 /*!
66 @function proto_register_input
67 @discussion Allows the caller to specify the functions called when a
68 packet for a protocol is received.
69 @param protocol The protocol family these functions will receive
70 packets for.
71 @param input The function called when a packet is input.
72 @result A errno error on failure.
73 */
74 errno_t proto_register_input(protocol_family_t protocol, proto_input_handler input,
75 proto_input_detached_handler detached);
76
77 /*!
78 @function proto_unregister_input
79 @discussion Allows the caller to unregister the input and inject
80 functions for a protocol. The input/inject functions may not be
81 unregistered immediately if there is a chance they are in use.
82 To notify the owner when the functions are no longer in use, the
83 proto_detached_handler function will be called. It is not safe
84 to unload until the proto_detached_handler is called.
85 @param protocol The protocol family these functions will receive
86 packets for.
87 @param input The function called when a packet is input.
88 @param inject The function to called when a packet is injected (not
89 on the normal input path).
90 @result A errno error on failure.
91 */
92 void proto_unregister_input(protocol_family_t protocol);
93 #endif
94
95 /*!
96 @function proto_input
97 @discussion Inputs a packet on the specified protocol from the input
98 path.
99 @param protocol The protocol of the packet.
100 @param packet The first packet in a chain of packets to be input.
101 @result A errno error on failure. Unless proto_input returns zero,
102 the caller is responsible for freeing the mbuf.
103 */
104 errno_t proto_input(protocol_family_t protocol, mbuf_t packet);
105
106 /*!
107 @function proto_inject
108 @discussion Injects a packet on the specified protocol from
109 anywhere. To avoid recursion, the protocol may need to queue the
110 packet to be handled later.
111 @param protocol The protocol of the packet.
112 @param packet The first packet in a chain of packets to be injected.
113 @result A errno error on failure. Unless proto_inject returns zero,
114 the caller is responsible for freeing the mbuf.
115 */
116 errno_t proto_inject(protocol_family_t protocol, mbuf_t packet);
117
118
119 /****************************************************************************/
120 /* Protocol plumbing */
121 /****************************************************************************/
122
123 /*!
124 @typedef proto_plumb_handler
125 @discussion proto_plumb_handler is called to attach a protocol to an
126 interface. A typical protocol plumb function would fill out an
127 ifnet_attach_proto_param and call ifnet_attach_protocol.
128 @param ifp The interface the protocol should be attached to.
129 @param protocol_family The protocol that should be attached to the
130 interface.
131 @result
132 A non-zero value of the attach failed.
133 */
134 typedef errno_t (*proto_plumb_handler)(ifnet_t ifp, protocol_family_t protocol);
135
136 /*!
137 @typedef proto_unplumb_handler
138 @discussion proto_unplumb_handler is called to detach a protocol
139 from an interface. A typical unplumb function would call
140 ifnet_detach_protocol and perform any necessary cleanup.
141 @param ifp The interface the protocol should be detached from.
142 @param protocol_family The protocol that should be detached from the
143 interface.
144 */
145 typedef void (*proto_unplumb_handler)(ifnet_t ifp, protocol_family_t protocol);
146
147 /*!
148 @function proto_register_plumber
149 @discussion Allows the caller to specify the functions called when a protocol
150 is attached to an interface belonging to the specified family and when
151 that protocol is detached.
152 @param proto_fam The protocol family these plumbing functions will
153 handle.
154 @param if_fam The interface family these plumbing functions will
155 handle.
156 @param plumb The function to call to attach the protocol to an
157 interface.
158 @param unplumb The function to call to detach the protocol to an
159 interface, may be NULL in which case ifnet_detach_protocol will
160 be used to detach the protocol.
161 @result A non-zero value of the attach failed.
162 */
163 errno_t proto_register_plumber(protocol_family_t proto_fam, ifnet_family_t if_fam,
164 proto_plumb_handler plumb, proto_unplumb_handler unplumb);
165
166 /*!
167 @function proto_unregister_plumber
168 @discussion Unregisters a previously registered plumbing function.
169 @param proto_fam The protocol family these plumbing functions
170 handle.
171 @param if_fam The interface family these plumbing functions handle.
172 */
173 void proto_unregister_plumber(protocol_family_t proto_fam, ifnet_family_t if_fam);
174
175 __END_DECLS
176
177 #endif