xref: /xnu-12377.41.6/bsd/net/ndrv.h (revision bbb1b6f9e71b8cdde6e5cd6f4841f207dee3d828)
1*bbb1b6f9SApple OSS Distributions /*
2*bbb1b6f9SApple OSS Distributions  * Copyright (c) 2008 Apple Computer, Inc. All rights reserved.
3*bbb1b6f9SApple OSS Distributions  *
4*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*bbb1b6f9SApple OSS Distributions  *
6*bbb1b6f9SApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*bbb1b6f9SApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*bbb1b6f9SApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*bbb1b6f9SApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*bbb1b6f9SApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*bbb1b6f9SApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*bbb1b6f9SApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*bbb1b6f9SApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*bbb1b6f9SApple OSS Distributions  *
15*bbb1b6f9SApple OSS Distributions  * Please obtain a copy of the License at
16*bbb1b6f9SApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*bbb1b6f9SApple OSS Distributions  *
18*bbb1b6f9SApple OSS Distributions  * The Original Code and all software distributed under the License are
19*bbb1b6f9SApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*bbb1b6f9SApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*bbb1b6f9SApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*bbb1b6f9SApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*bbb1b6f9SApple OSS Distributions  * Please see the License for the specific language governing rights and
24*bbb1b6f9SApple OSS Distributions  * limitations under the License.
25*bbb1b6f9SApple OSS Distributions  *
26*bbb1b6f9SApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*bbb1b6f9SApple OSS Distributions  */
28*bbb1b6f9SApple OSS Distributions /* Copyright (c) 1997, 1998 Apple Computer, Inc. All Rights Reserved */
29*bbb1b6f9SApple OSS Distributions /*
30*bbb1b6f9SApple OSS Distributions  *	@(#)ndrv.h	1.1 (MacOSX) 6/10/43
31*bbb1b6f9SApple OSS Distributions  * Justin Walker - 970604
32*bbb1b6f9SApple OSS Distributions  */
33*bbb1b6f9SApple OSS Distributions #include <net/dlil.h>
34*bbb1b6f9SApple OSS Distributions 
35*bbb1b6f9SApple OSS Distributions #ifndef _NET_NDRV_H
36*bbb1b6f9SApple OSS Distributions #define _NET_NDRV_H
37*bbb1b6f9SApple OSS Distributions #include <net/if_var.h>
38*bbb1b6f9SApple OSS Distributions #include <sys/appleapiopts.h>
39*bbb1b6f9SApple OSS Distributions #include <sys/types.h>
40*bbb1b6f9SApple OSS Distributions 
41*bbb1b6f9SApple OSS Distributions 
42*bbb1b6f9SApple OSS Distributions struct sockaddr_ndrv {
43*bbb1b6f9SApple OSS Distributions 	unsigned char snd_len;
44*bbb1b6f9SApple OSS Distributions 	unsigned char snd_family;
45*bbb1b6f9SApple OSS Distributions 	unsigned char snd_name[IFNAMSIZ]; /* from if.h */
46*bbb1b6f9SApple OSS Distributions };
47*bbb1b6f9SApple OSS Distributions 
48*bbb1b6f9SApple OSS Distributions /*
49*bbb1b6f9SApple OSS Distributions  * Support for user-mode protocol handlers
50*bbb1b6f9SApple OSS Distributions  */
51*bbb1b6f9SApple OSS Distributions 
52*bbb1b6f9SApple OSS Distributions #define NDRV_DEMUXTYPE_ETHERTYPE        4
53*bbb1b6f9SApple OSS Distributions #define NDRV_DEMUXTYPE_SAP                      5
54*bbb1b6f9SApple OSS Distributions #define NDRV_DEMUXTYPE_SNAP                     6
55*bbb1b6f9SApple OSS Distributions 
56*bbb1b6f9SApple OSS Distributions #define NDRVPROTO_NDRV                          0
57*bbb1b6f9SApple OSS Distributions 
58*bbb1b6f9SApple OSS Distributions /*
59*bbb1b6f9SApple OSS Distributions  * Struct: ndrv_demux_desc
60*bbb1b6f9SApple OSS Distributions  * Purpose:
61*bbb1b6f9SApple OSS Distributions  *   To uniquely identify a packet based on its low-level framing information.
62*bbb1b6f9SApple OSS Distributions  *
63*bbb1b6f9SApple OSS Distributions  * Fields:
64*bbb1b6f9SApple OSS Distributions  *		type		:	type of protocol in data field, must be understood by
65*bbb1b6f9SApple OSS Distributions  *						the interface family of the interface the socket is bound to
66*bbb1b6f9SApple OSS Distributions  *		length		:       length of protocol data in "data" field
67*bbb1b6f9SApple OSS Distributions  *		data		:	union of framing-specific data, in network byte order
68*bbb1b6f9SApple OSS Distributions  *		ether_type	:	ethernet type in network byte order, assuming
69*bbb1b6f9SApple OSS Distributions  *						ethernet type II framing
70*bbb1b6f9SApple OSS Distributions  *		sap			:	first 3 bytes of sap header, network byte order
71*bbb1b6f9SApple OSS Distributions  *		snap		:	first 5 bytes of snap header, network byte order
72*bbb1b6f9SApple OSS Distributions  *		other		:	up to 28 bytes of protocol data for different protocol type
73*bbb1b6f9SApple OSS Distributions  *
74*bbb1b6f9SApple OSS Distributions  * Examples:
75*bbb1b6f9SApple OSS Distributions  * 1) 802.1x uses ether_type 0x888e, so the descriptor would be set as:
76*bbb1b6f9SApple OSS Distributions  *    struct ndrv_demux_desc desc;
77*bbb1b6f9SApple OSS Distributions  *    desc.type = NDRV_DEMUXTYPE_ETHERTYPE
78*bbb1b6f9SApple OSS Distributions  *	  desc.length = sizeof(unsigned short);
79*bbb1b6f9SApple OSS Distributions  *    desc.ether_type = htons(0x888e);
80*bbb1b6f9SApple OSS Distributions  * 2) AppleTalk uses SNAP 0x080007809B
81*bbb1b6f9SApple OSS Distributions  *    struct ndrv_demux_desc desc;
82*bbb1b6f9SApple OSS Distributions  *    desc.type = NDRV_DEMUXTYPE_SNAP;
83*bbb1b6f9SApple OSS Distributions  *    desc.length = 5;
84*bbb1b6f9SApple OSS Distributions  *    desc.data.snap[0] = 08;
85*bbb1b6f9SApple OSS Distributions  *    desc.data.snap[1] = 00;
86*bbb1b6f9SApple OSS Distributions  *    desc.data.snap[2] = 07;
87*bbb1b6f9SApple OSS Distributions  *    desc.data.snap[3] = 80;
88*bbb1b6f9SApple OSS Distributions  *    desc.data.snap[4] = 9B;
89*bbb1b6f9SApple OSS Distributions  */
90*bbb1b6f9SApple OSS Distributions struct ndrv_demux_desc {
91*bbb1b6f9SApple OSS Distributions 	u_int16_t   type;
92*bbb1b6f9SApple OSS Distributions 	u_int16_t   length;
93*bbb1b6f9SApple OSS Distributions 	union{
94*bbb1b6f9SApple OSS Distributions 		u_int16_t       ether_type;
95*bbb1b6f9SApple OSS Distributions 		u_int8_t        sap[3];
96*bbb1b6f9SApple OSS Distributions 		u_int8_t        snap[5];
97*bbb1b6f9SApple OSS Distributions 		u_int8_t        other[28];
98*bbb1b6f9SApple OSS Distributions 	} data;
99*bbb1b6f9SApple OSS Distributions };
100*bbb1b6f9SApple OSS Distributions 
101*bbb1b6f9SApple OSS Distributions #define NDRV_PROTOCOL_DESC_VERS 1
102*bbb1b6f9SApple OSS Distributions 
103*bbb1b6f9SApple OSS Distributions /*
104*bbb1b6f9SApple OSS Distributions  * Struct: ndrv_protocol_desc
105*bbb1b6f9SApple OSS Distributions  * Purpose:
106*bbb1b6f9SApple OSS Distributions  *   Used to "bind" an NDRV socket so that packets that match
107*bbb1b6f9SApple OSS Distributions  *   given protocol demux descriptions can be received:
108*bbb1b6f9SApple OSS Distributions  * Field:
109*bbb1b6f9SApple OSS Distributions  *	version		:	must be NDRV_PROTOCOL_DESC_VERS
110*bbb1b6f9SApple OSS Distributions  *	protocol_family	:	unique identifier for this protocol
111*bbb1b6f9SApple OSS Distributions  *	demux_count	:	number of demux_list descriptors in demux_list; maximum of 10
112*bbb1b6f9SApple OSS Distributions  *	demux_list	:	pointer to array of demux descriptors
113*bbb1b6f9SApple OSS Distributions  */
114*bbb1b6f9SApple OSS Distributions #ifdef BSD_KERNEL_PRIVATE
115*bbb1b6f9SApple OSS Distributions struct ndrv_protocol_desc_kernel {
116*bbb1b6f9SApple OSS Distributions 	u_int32_t                           version;
117*bbb1b6f9SApple OSS Distributions 	u_int32_t                           protocol_family;
118*bbb1b6f9SApple OSS Distributions 	u_int32_t                           demux_count;
119*bbb1b6f9SApple OSS Distributions 	struct ndrv_demux_desc              *__counted_by(demux_count) demux_list;
120*bbb1b6f9SApple OSS Distributions };
121*bbb1b6f9SApple OSS Distributions #else
122*bbb1b6f9SApple OSS Distributions struct ndrv_protocol_desc {
123*bbb1b6f9SApple OSS Distributions 	u_int32_t                           version;
124*bbb1b6f9SApple OSS Distributions 	u_int32_t                           protocol_family;
125*bbb1b6f9SApple OSS Distributions 	u_int32_t                           demux_count;
126*bbb1b6f9SApple OSS Distributions 	struct ndrv_demux_desc              *demux_list;
127*bbb1b6f9SApple OSS Distributions };
128*bbb1b6f9SApple OSS Distributions #endif
129*bbb1b6f9SApple OSS Distributions 
130*bbb1b6f9SApple OSS Distributions 
131*bbb1b6f9SApple OSS Distributions #ifdef KERNEL_PRIVATE
132*bbb1b6f9SApple OSS Distributions /* LP64 version of ndrv_protocol_desc.  all pointers
133*bbb1b6f9SApple OSS Distributions  * grow when we're dealing with a 64-bit process.
134*bbb1b6f9SApple OSS Distributions  * WARNING - keep in sync with ndrv_protocol_desc
135*bbb1b6f9SApple OSS Distributions  */
136*bbb1b6f9SApple OSS Distributions struct ndrv_protocol_desc64 {
137*bbb1b6f9SApple OSS Distributions 	u_int32_t                           version;
138*bbb1b6f9SApple OSS Distributions 	u_int32_t                           protocol_family;
139*bbb1b6f9SApple OSS Distributions 	u_int32_t                           demux_count;
140*bbb1b6f9SApple OSS Distributions 	user64_addr_t                       demux_list __attribute__((aligned(8)));
141*bbb1b6f9SApple OSS Distributions };
142*bbb1b6f9SApple OSS Distributions 
143*bbb1b6f9SApple OSS Distributions struct ndrv_protocol_desc32 {
144*bbb1b6f9SApple OSS Distributions 	u_int32_t                           version;
145*bbb1b6f9SApple OSS Distributions 	u_int32_t                           protocol_family;
146*bbb1b6f9SApple OSS Distributions 	u_int32_t                           demux_count;
147*bbb1b6f9SApple OSS Distributions 	user32_addr_t                       demux_list;
148*bbb1b6f9SApple OSS Distributions };
149*bbb1b6f9SApple OSS Distributions #endif /* KERNEL_PRIVATE */
150*bbb1b6f9SApple OSS Distributions 
151*bbb1b6f9SApple OSS Distributions #define SOL_NDRVPROTO           NDRVPROTO_NDRV  /* Use this socket level */
152*bbb1b6f9SApple OSS Distributions #define NDRV_DELDMXSPEC         0x02                    /* Delete the registered protocol */
153*bbb1b6f9SApple OSS Distributions #define NDRV_SETDMXSPEC         0x04                    /* Set the protocol spec */
154*bbb1b6f9SApple OSS Distributions #define NDRV_ADDMULTICAST       0x05                    /* Add a physical multicast address */
155*bbb1b6f9SApple OSS Distributions #define NDRV_DELMULTICAST       0x06                    /* Delete a phyiscal multicast */
156*bbb1b6f9SApple OSS Distributions 
157*bbb1b6f9SApple OSS Distributions /*
158*bbb1b6f9SApple OSS Distributions  * SOL_NDRVPROTO - use this for the socket level when calling setsocketopt
159*bbb1b6f9SApple OSS Distributions  * NDRV_DELDMXSPEC - removes the registered protocol and all related demuxes
160*bbb1b6f9SApple OSS Distributions  * NDRV_SETDMXSPEC - set the protocol to receive, use struct ndrv_protocol_desc
161*bbb1b6f9SApple OSS Distributions  *					 as the parameter.
162*bbb1b6f9SApple OSS Distributions  * NDRV_ADDMULTICAST - Enable reception of a phyiscal multicast address, use
163*bbb1b6f9SApple OSS Distributions  *                     a sockaddr of the appropriate type for the media in use.
164*bbb1b6f9SApple OSS Distributions  * NDRV_DELMULTICAST - Disable reception of a phyiscal multicast address, use
165*bbb1b6f9SApple OSS Distributions  *					   a sockaddr of the appropriate type for the media in use.
166*bbb1b6f9SApple OSS Distributions  *
167*bbb1b6f9SApple OSS Distributions  * When adding multicasts, the multicasts are ref counted. If the multicast is
168*bbb1b6f9SApple OSS Distributions  * already registered in the kernel, the count will be bumped. When deleting
169*bbb1b6f9SApple OSS Distributions  * the multicast, the count is decremented. If the count reaches zero the
170*bbb1b6f9SApple OSS Distributions  * multicast is removed. If your process is killed, PF_NDRV will unregister
171*bbb1b6f9SApple OSS Distributions  * the mulitcasts you've added. You can only delete multicasts you've added
172*bbb1b6f9SApple OSS Distributions  * on the same socket.
173*bbb1b6f9SApple OSS Distributions  *
174*bbb1b6f9SApple OSS Distributions  * If the interface goes away while your socket is open, your protocol is
175*bbb1b6f9SApple OSS Distributions  * immediately detached and sending/receiving is disabled on the socket.
176*bbb1b6f9SApple OSS Distributions  * If you need a chance to do something, please file a bug and we can give
177*bbb1b6f9SApple OSS Distributions  * you a second or two.
178*bbb1b6f9SApple OSS Distributions  */
179*bbb1b6f9SApple OSS Distributions 
180*bbb1b6f9SApple OSS Distributions /* Max number of descriptions allowed by default */
181*bbb1b6f9SApple OSS Distributions #define NDRV_DMUX_MAX_DESCR     1024
182*bbb1b6f9SApple OSS Distributions 
183*bbb1b6f9SApple OSS Distributions /*
184*bbb1b6f9SApple OSS Distributions  * sysctl MIB tags at the kern.ipc.nrdv level
185*bbb1b6f9SApple OSS Distributions  */
186*bbb1b6f9SApple OSS Distributions #define NRDV_MULTICAST_ADDRS_PER_SOCK 1 /* to toggle NDRV_DMUX_MAX_DESCR value */
187*bbb1b6f9SApple OSS Distributions 
188*bbb1b6f9SApple OSS Distributions #endif  /* _NET_NDRV_H */
189