2 * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 @header kpi_protocol.h
32 This header defines an API to interact with protocols in the kernel.
33 The KPIs in this header file can be used to interact with protocols
34 that already exist in the stack. These KPIs can be used to support
35 existing protocols over media types that are not natively supported
36 in the kernel, such as ATM.
39 #ifndef __KPI_PROTOCOL__
40 #define __KPI_PROTOCOL__
41 #include <sys/kernel_types.h>
42 #include <net/kpi_interface.h>
47 /****************************************************************************/
48 /* Protocol input/inject */
49 /****************************************************************************/
53 @typedef protocol_input_handler
54 @discussion protocol_input_handler is called to input a packet. If
55 your protocol has specified a global lock, the lock will be held
56 when this funciton is called.
57 @pararm protocol The protocol this packet is intended for.
58 @param packet The packet that should be input.
60 typedef void (*proto_input_handler
)(protocol_family_t protocol
, mbuf_t packet
);
63 @typedef proto_input_detached_handler
64 @discussion proto_input_detached_handler is called to notify the
65 protocol that it has been detached. When this function is
66 called, the proto_input_handler will not be called again, making
68 @pararm protocol The protocol detached.
70 typedef void (*proto_input_detached_handler
)(protocol_family_t protocol
);
73 @function proto_register_input
74 @discussion Allows the caller to specify the functions called when a
75 packet for a protocol is received.
76 @param protocol The protocol family these functions will receive
78 @param input The function called when a packet is input.
79 @result A errno error on failure.
81 errno_t
proto_register_input(protocol_family_t protocol
, proto_input_handler input
,
82 proto_input_detached_handler detached
);
85 @function proto_unregister_input
86 @discussion Allows the caller to unregister the input and inject
87 functions for a protocol. The input/inject functions may not be
88 unregistered immediately if there is a chance they are in use.
89 To notify the owner when the functions are no longer in use, the
90 proto_detached_handler function will be called. It is not safe
91 to unload until the proto_detached_handler is called.
92 @param protocol The protocol family these functions will receive
94 @param input The function called when a packet is input.
95 @param inject The function to called when a packet is injected (not
96 on the normal input path).
97 @result A errno error on failure.
99 void proto_unregister_input(protocol_family_t protocol
);
103 @function proto_input
104 @discussion Inputs a packet on the specified protocol from the input
106 @param protocol The protocol of the packet.
107 @param packet The first packet in a chain of packets to be input.
108 @result A errno error on failure. Unless proto_input returns zero,
109 the caller is responsible for freeing the mbuf.
111 errno_t
proto_input(protocol_family_t protocol
, mbuf_t packet
);
114 @function proto_inject
115 @discussion Injects a packet on the specified protocol from
116 anywhere. To avoid recursion, the protocol may need to queue the
117 packet to be handled later.
118 @param protocol The protocol of the packet.
119 @param packet The first packet in a chain of packets to be injected.
120 @result A errno error on failure. Unless proto_inject returns zero,
121 the caller is responsible for freeing the mbuf.
123 errno_t
proto_inject(protocol_family_t protocol
, mbuf_t packet
);
126 /****************************************************************************/
127 /* Protocol plumbing */
128 /****************************************************************************/
131 @typedef proto_plumb_handler
132 @discussion proto_plumb_handler is called to attach a protocol to an
133 interface. A typical protocol plumb function would fill out an
134 ifnet_attach_proto_param and call ifnet_attach_protocol.
135 @param ifp The interface the protocol should be attached to.
136 @param protocol_family The protocol that should be attached to the
139 A non-zero value of the attach failed.
141 typedef errno_t (*proto_plumb_handler
)(ifnet_t ifp
, protocol_family_t protocol
);
144 @typedef proto_unplumb_handler
145 @discussion proto_unplumb_handler is called to detach a protocol
146 from an interface. A typical unplumb function would call
147 ifnet_detach_protocol and perform any necessary cleanup.
148 @param ifp The interface the protocol should be detached from.
149 @param protocol_family The protocol that should be detached from the
152 typedef void (*proto_unplumb_handler
)(ifnet_t ifp
, protocol_family_t protocol
);
155 @function proto_register_plumber
156 @discussion Allows the caller to specify the functions called when a protocol
157 is attached to an interface belonging to the specified family and when
158 that protocol is detached.
159 @param proto_fam The protocol family these plumbing functions will
161 @param if_fam The interface family these plumbing functions will
163 @param plumb The function to call to attach the protocol to an
165 @param unplumb The function to call to detach the protocol to an
166 interface, may be NULL in which case ifnet_detach_protocol will
167 be used to detach the protocol.
168 @result A non-zero value of the attach failed.
170 errno_t
proto_register_plumber(protocol_family_t proto_fam
, ifnet_family_t if_fam
,
171 proto_plumb_handler plumb
, proto_unplumb_handler unplumb
);
174 @function proto_unregister_plumber
175 @discussion Unregisters a previously registered plumbing function.
176 @param proto_fam The protocol family these plumbing functions
178 @param if_fam The interface family these plumbing functions handle.
180 void proto_unregister_plumber(protocol_family_t proto_fam
, ifnet_family_t if_fam
);