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