]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/ndrv.h
0a0cd4fa3626bc6e9b5c2f95b5da7d24387ecece
[apple/xnu.git] / bsd / net / ndrv.h
1 /*
2 * Copyright (c) 2006 Apple Computer, Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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. 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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /* Copyright (c) 1997, 1998 Apple Computer, Inc. All Rights Reserved */
31 /*
32 * @(#)ndrv.h 1.1 (MacOSX) 6/10/43
33 * Justin Walker - 970604
34 */
35 #include <net/dlil.h>
36
37 #ifndef _NET_NDRV_H
38 #define _NET_NDRV_H
39 #include <sys/appleapiopts.h>
40
41
42 struct sockaddr_ndrv
43 {
44 unsigned char snd_len;
45 unsigned char snd_family;
46 unsigned char snd_name[IFNAMSIZ]; /* from if.h */
47 };
48
49 /*
50 * Support for user-mode protocol handlers
51 */
52
53 #define NDRV_DEMUXTYPE_ETHERTYPE 4
54 #define NDRV_DEMUXTYPE_SAP 5
55 #define NDRV_DEMUXTYPE_SNAP 6
56
57 #define NDRVPROTO_NDRV 0
58
59 /*
60 * Struct: ndrv_demux_desc
61 * Purpose:
62 * To uniquely identify a packet based on its low-level framing information.
63 *
64 * Fields:
65 * type : type of protocol in data field, must be understood by
66 * the interface family of the interface the socket is bound to
67 * length : length of protocol data in "data" field
68 * data : union of framing-specific data, in network byte order
69 * ether_type : ethernet type in network byte order, assuming
70 * ethernet type II framing
71 * sap : first 3 bytes of sap header, network byte order
72 * snap : first 5 bytes of snap header, network byte order
73 * other : up to 28 bytes of protocol data for different protocol type
74 *
75 * Examples:
76 * 1) 802.1x uses ether_type 0x888e, so the descriptor would be set as:
77 * struct ndrv_demux_desc desc;
78 * desc.type = NDRV_DEMUXTYPE_ETHERTYPE
79 * desc.length = sizeof(unsigned short);
80 * desc.ether_type = htons(0x888e);
81 * 2) AppleTalk uses SNAP 0x080007809B
82 * struct ndrv_demux_desc desc;
83 * desc.type = NDRV_DEMUXTYPE_SNAP;
84 * desc.length = 5;
85 * desc.data.snap[0] = 08;
86 * desc.data.snap[1] = 00;
87 * desc.data.snap[2] = 07;
88 * desc.data.snap[3] = 80;
89 * desc.data.snap[4] = 9B;
90 */
91 struct ndrv_demux_desc
92 {
93 u_int16_t type;
94 u_int16_t length;
95 union
96 {
97 u_int16_t ether_type;
98 u_int8_t sap[3];
99 u_int8_t snap[5];
100 u_int8_t other[28];
101 } data;
102 };
103
104 #define NDRV_PROTOCOL_DESC_VERS 1
105
106 /*
107 * Struct: ndrv_protocol_desc
108 * Purpose:
109 * Used to "bind" an NDRV socket so that packets that match
110 * given protocol demux descriptions can be received:
111 * Field:
112 * version : must be NDRV_PROTOCOL_DESC_VERS
113 * protocol_family : unique identifier for this protocol
114 * demux_count : number of demux_list descriptors in demux_list
115 * demux_list : pointer to array of demux descriptors
116 */
117 struct ndrv_protocol_desc
118 {
119 u_int32_t version;
120 u_int32_t protocol_family;
121 u_int32_t demux_count;
122 struct ndrv_demux_desc* demux_list;
123 };
124
125 #define SOL_NDRVPROTO NDRVPROTO_NDRV /* Use this socket level */
126 #define NDRV_DELDMXSPEC 0x02 /* Delete the registered protocol */
127 #define NDRV_SETDMXSPEC 0x04 /* Set the protocol spec */
128 #define NDRV_ADDMULTICAST 0x05 /* Add a physical multicast address */
129 #define NDRV_DELMULTICAST 0x06 /* Delete a phyiscal multicast */
130
131 /*
132 * SOL_NDRVPROTO - use this for the socket level when calling setsocketopt
133 * NDRV_DELDMXSPEC - removes the registered protocol and all related demuxes
134 * NDRV_SETDMXSPEC - set the protocol to receive, use struct ndrv_protocol_desc
135 * as the parameter.
136 * NDRV_ADDMULTICAST - Enable reception of a phyiscal multicast address, use
137 * a sockaddr of the appropriate type for the media in use.
138 * NDRV_DELMULTICAST - Disable reception of a phyiscal multicast address, use
139 * a sockaddr of the appropriate type for the media in use.
140 *
141 * When adding multicasts, the multicasts are ref counted. If the multicast is
142 * already registered in the kernel, the count will be bumped. When deleting
143 * the multicast, the count is decremented. If the count reaches zero the
144 * multicast is removed. If your process is killed, PF_NDRV will unregister
145 * the mulitcasts you've added. You can only delete multicasts you've added
146 * on the same socket.
147 *
148 * If the interface goes away while your socket is open, your protocol is
149 * immediately detached and sending/receiving is disabled on the socket.
150 * If you need a chance to do something, please file a bug and we can give
151 * you a second or two.
152 */
153
154 #endif /* _NET_NDRV_H */