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