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