xref: /illumos-gate/usr/src/uts/common/inet/sockmods/netpacket/packet.h (revision 46b592853d0f4f11781b6b0a7533f267c6aee132)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _PACKET_H
28 #define	_PACKET_H
29 
30 #include <sys/socket_impl.h>
31 #include <net/bpf.h>
32 
33 /*
34  * With which we do the reverse of what it libpcap does....
35  */
36 #define	PACKET_OUTGOING		LINUX_SLL_OUTGOING
37 #define	PACKET_HOST		LINUX_SLL_HOST
38 #define	PACKET_BROADCAST	LINUX_SLL_BROADCAST
39 #define	PACKET_MULTICAST	LINUX_SLL_MULTICAST
40 #define	PACKET_OTHERHOST	LINUX_SLL_OTHERHOST
41 
42 #define	PACKET_STATISTICS	1
43 #define	PACKET_ADD_MEMBERSHIP	2
44 #define	PACKET_DROP_MEMBERSHIP	3
45 #define	PACKET_AUXDATA		4
46 
47 
48 struct packet_mreq {
49 	uint32_t	mr_ifindex;
50 	uint16_t	mr_type;
51 	uint16_t	mr_alen;
52 	uint8_t		mr_address[8];
53 };
54 
55 #define	PACKET_MR_MULTICAST	1
56 #define	PACKET_MR_PROMISC	2
57 #define	PACKET_MR_ALLMULTI	3
58 
59 typedef enum tpkt_status_e {
60 	TP_STATUS_KERNEL,
61 	TP_STATUS_USER,
62 	TP_STATUS_COPY,
63 	TP_STATUS_LOSING,
64 	TP_STATUS_CSUMNOTREADY
65 } tpkt_status_t;
66 
67 struct tpacket_auxdata {		/* tp_macoff/tp_netoff ?? */
68 	tpkt_status_t	tp_status;
69 	uint32_t	tp_len;
70 	uint32_t	tp_snaplen;
71 	uint16_t	tp_macoff;
72 	uint16_t	tp_netoff;
73 	uint16_t	tp_vlan_vci;
74 };
75 
76 struct tpacket_hdr {			/* tp_macoff/tp_netoff ?? */
77 	uint64_t	tp_status;
78 	uint32_t	tp_len;
79 	uint32_t	tp_snaplen;
80 	uint16_t	tp_macoff;
81 	uint16_t	tp_netoff;
82 	uint32_t	tp_sec;
83 	uint32_t	tp_usec;
84 };
85 
86 struct tpacket2_hdr {			/* tp_macoff/tp_netoff ?? */
87 	tpkt_status_t	tp_status;
88 	uint32_t	tp_len;
89 	uint32_t	tp_snaplen;
90 	uint16_t	tp_macoff;
91 	uint16_t	tp_netoff;
92 	uint32_t	tp_sec;
93 	uint32_t	tp_nsec;
94 	uint16_t	tp_vlan_tci;
95 };
96 
97 struct tpacket_stats {
98 	uint16_t	tp_packets;
99 	uint16_t	tp_drops;
100 };
101 
102 struct sock_filter {			/* Fields named from bpf_insn */
103 	uint16_t	code;
104 	uint8_t		jt;
105 	uint8_t		jf;
106 	uint32_t	k;
107 };
108 
109 struct sock_fprog {
110 	uint16_t		len;
111 	struct sock_filter	*filter;
112 };
113 
114 /*
115  * Linux ARPHRD_ symbols needed...
116  *
117  * The numbers above 50000 are because their real value is unknown from
118  * libpcap's source, so a number has been chosen that is unlikely to be
119  * confused with the real one on Linux.
120  */
121 #define	ARPHRD_ADAPT			50001
122 #define	ARPHRD_ARCNET			50002
123 #define	ARPHRD_ATM			19
124 #define	ARPHRD_AX25			50003
125 #define	ARPHRD_CHAOS			50004
126 #define	ARPHRD_CISCO			513
127 #define	ARPHRD_CSLIP			50005
128 #define	ARPHRD_CSLIP6			50006
129 #define	ARPHRD_DLCI			15
130 #define	ARPHRD_EETHER			50007
131 #define	ARPHRD_ETHER			50008
132 #define	ARPHRD_FCAL			785
133 #define	ARPHRD_FCFABRIC			787
134 #define	ARPHRD_FCPL			786
135 #define	ARPHRD_FCPP			784
136 #define	ARPHRD_FRAD			770
137 #define	ARPHRD_FDDI			774
138 #define	ARPHRD_IEEE802			50009
139 #define	ARPHRD_IEEE802_TR		800
140 #define	ARPHRD_IEEE80211		801
141 #define	ARPHRD_IEEE80211_PRISM		802
142 #define	ARPHRD_IEEE80211_RADIOTAP	803
143 #define	ARPHRD_IRDA			783
144 #define	ARPHRD_LAPD			8445
145 #define	ARPHRD_LOCALTLK			50010
146 #define	ARPHRD_LOOPBACK			50011
147 #define	ARPHRD_METRICOM			50012
148 #define	ARPHRD_PRONET			50013
149 #define	ARPHRD_PPP			50014
150 #define	ARPHRD_RAWHDLC			518
151 #define	ARPHRD_SIT			776
152 #define	ARPHRD_SLIP6			50015
153 #define	ARPHRD_SLIP			50016
154 #define	ARPHRD_TUNNEL			50017
155 
156 #ifdef _KERNEL
157 /*
158  * PFP socket structure.
159  */
160 typedef struct pfpsock {
161 	struct bpf_program		ps_bpf;
162 	krwlock_t			ps_bpflock;
163 	sock_upper_handle_t		ps_upper;
164 	sock_upcalls_t			*ps_upcalls;
165 	mac_handle_t			ps_mh;
166 	mac_client_handle_t		ps_mch;
167 	mac_promisc_handle_t		ps_phd;
168 	int				ps_type;
169 	int				ps_proto;
170 	uint_t				ps_max_sdu;
171 	boolean_t			ps_bound;
172 	mac_client_promisc_type_t	ps_promisc;
173 	boolean_t			ps_auxdata;
174 	struct tpacket_stats		ps_stats;
175 	struct sockaddr			ps_sock;
176 	datalink_id_t			ps_linkid;
177 	kmutex_t			ps_lock;
178 	boolean_t			ps_flow_ctrld;
179 	ulong_t				ps_flow_ctrl_drops;
180 } pfpsock_t;
181 
182 typedef struct pfp_kstats_s {
183 	kstat_named_t	kp_recv_mac_hdr_fail;
184 	kstat_named_t	kp_recv_bad_proto;
185 	kstat_named_t	kp_recv_alloc_fail;
186 	kstat_named_t	kp_recv_ok;
187 	kstat_named_t	kp_recv_fail;
188 	kstat_named_t	kp_recv_filtered;
189 	kstat_named_t	kp_recv_flow_cntrld;
190 	kstat_named_t	kp_send_unbound;
191 	kstat_named_t	kp_send_failed;
192 	kstat_named_t	kp_send_too_big;
193 	kstat_named_t	kp_send_alloc_fail;
194 	kstat_named_t	kp_send_uiomove_fail;
195 	kstat_named_t	kp_send_no_memory;
196 	kstat_named_t	kp_send_open_fail;
197 	kstat_named_t	kp_send_wrong_family;
198 	kstat_named_t	kp_send_short_msg;
199 	kstat_named_t	kp_send_ok;
200 } pfp_kstats_t;
201 #endif /* _KERNEL */
202 
203 #endif /* _PACKET_H */
204