xref: /titanic_51/usr/src/uts/common/inet/sockmods/netpacket/packet.h (revision 8808ac5dae118369991f158b6ab736cb2691ecde)
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 (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
24  * Copyright 2015 Joyent, Inc. All rights reserved.
25  */
26 
27 #ifndef _PACKET_H
28 #define	_PACKET_H
29 
30 #include <sys/socket_impl.h>
31 #include <net/if_arp.h>
32 #include <net/bpf.h>
33 
34 /*
35  * With which we do the reverse of what it libpcap does....
36  */
37 #define	PACKET_OUTGOING		LINUX_SLL_OUTGOING
38 #define	PACKET_HOST		LINUX_SLL_HOST
39 #define	PACKET_BROADCAST	LINUX_SLL_BROADCAST
40 #define	PACKET_MULTICAST	LINUX_SLL_MULTICAST
41 #define	PACKET_OTHERHOST	LINUX_SLL_OTHERHOST
42 
43 #define	PACKET_STATISTICS_SHORT	1
44 #define	PACKET_ADD_MEMBERSHIP	2
45 #define	PACKET_DROP_MEMBERSHIP	3
46 #define	PACKET_AUXDATA		4
47 #define	PACKET_STATISTICS	5
48 
49 
50 struct packet_mreq {
51 	uint32_t	mr_ifindex;
52 	uint16_t	mr_type;
53 	uint16_t	mr_alen;
54 	uint8_t		mr_address[8];
55 };
56 
57 #define	PACKET_MR_MULTICAST	1
58 #define	PACKET_MR_PROMISC	2
59 #define	PACKET_MR_ALLMULTI	3
60 
61 typedef enum tpkt_status_e {
62 	TP_STATUS_KERNEL,
63 	TP_STATUS_USER,
64 	TP_STATUS_COPY,
65 	TP_STATUS_LOSING,
66 	TP_STATUS_CSUMNOTREADY
67 } tpkt_status_t;
68 
69 struct tpacket_auxdata {		/* tp_macoff/tp_netoff ?? */
70 	tpkt_status_t	tp_status;
71 	uint32_t	tp_len;
72 	uint32_t	tp_snaplen;
73 	uint16_t	tp_macoff;
74 	uint16_t	tp_netoff;
75 	uint16_t	tp_vlan_vci;
76 };
77 
78 struct tpacket_hdr {			/* tp_macoff/tp_netoff ?? */
79 	uint64_t	tp_status;
80 	uint32_t	tp_len;
81 	uint32_t	tp_snaplen;
82 	uint16_t	tp_macoff;
83 	uint16_t	tp_netoff;
84 	uint32_t	tp_sec;
85 	uint32_t	tp_usec;
86 };
87 
88 struct tpacket2_hdr {			/* tp_macoff/tp_netoff ?? */
89 	tpkt_status_t	tp_status;
90 	uint32_t	tp_len;
91 	uint32_t	tp_snaplen;
92 	uint16_t	tp_macoff;
93 	uint16_t	tp_netoff;
94 	uint32_t	tp_sec;
95 	uint32_t	tp_nsec;
96 	uint16_t	tp_vlan_tci;
97 };
98 
99 struct tpacket_stats {
100 	uint32_t	tp_packets;
101 	uint32_t	tp_drops;
102 };
103 
104 struct tpacket_stats_short {
105 	uint16_t	tp_packets;
106 	uint16_t	tp_drops;
107 };
108 
109 struct sock_filter {			/* Fields named from bpf_insn */
110 	uint16_t	code;
111 	uint8_t		jt;
112 	uint8_t		jf;
113 	uint32_t	k;
114 };
115 
116 struct sock_fprog {
117 	uint16_t		len;
118 	struct sock_filter	*filter;
119 };
120 
121 /*
122  * Linux ARPHRD_ symbols needed...
123  *
124  * The numbers above 50000 are because their real value is unknown from
125  * libpcap's source, so a number has been chosen that is unlikely to be
126  * confused with the real one on Linux. Those that are already found in
127  * Solaris inside <net/if_arp.h> may have a different value to that found
128  * in Linux but it should be used instead as the Solaris value originates
129  * from the IANA whereas the Linux values seem to ignore it.
130  */
131 /* ARPHRD_AX25				see <net/if_arp.h> */
132 /* ARPHRD_CHAOS				see <net/if_arp.h> */
133 #define	ARPHRD_CSLIP			50005
134 #define	ARPHRD_CSLIP6			50006
135 #define	ARPHRD_DLCI			15
136 /* ARPHRD_EETHER			see <net/if_arp.h> */
137 /* ARPHRD_ETHER				see <net/if_arp.h> */
138 #define	ARPHRD_FCAL			785
139 #define	ARPHRD_FCFABRIC			787
140 #define	ARPHRD_FCPL			786
141 #define	ARPHRD_FCPP			784
142 #define	ARPHRD_FRAD			770
143 #define	ARPHRD_FDDI			774
144 /* ARPHRD_IEEE802			see <net/if_arp.h> */
145 #define	ARPHRD_IEEE802_TR		800
146 #define	ARPHRD_IEEE80211		801
147 #define	ARPHRD_IEEE80211_PRISM		802
148 #define	ARPHRD_IEEE80211_RADIOTAP	803
149 #define	ARPHRD_IRDA			783
150 #define	ARPHRD_LAPD			8445
151 #define	ARPHRD_LOCALTLK			50010
152 #define	ARPHRD_LOOPBACK			50011
153 /* ARPHRD_METRICOM			see <net/if_arp.h> */
154 #define	ARPHRD_PRONET			50013
155 #define	ARPHRD_PPP			50014
156 #define	ARPHRD_RAWHDLC			518
157 #define	ARPHRD_SIT			776
158 #define	ARPHRD_SLIP6			50015
159 #define	ARPHRD_SLIP			50016
160 /* ARPHRD_TUNNEL			see <net/if_arp.h> */
161 
162 #define	ETH_P_ALL			0
163 #define	ETH_P_802_2			0xaa	/* LSAP_SAP */
164 #define	ETH_P_803_3			0
165 #define	ETH_P_IP			0x800
166 #define	ETH_P_ARP			0x806
167 #define	ETH_P_IPV6			0x86dd
168 
169 #ifdef _KERNEL
170 /*
171  * PFP socket structure.
172  */
173 typedef struct pfpsock {
174 	struct bpf_program		ps_bpf;
175 	krwlock_t			ps_bpflock;
176 	sock_upper_handle_t		ps_upper;
177 	sock_upcalls_t			*ps_upcalls;
178 	mac_handle_t			ps_mh;
179 	mac_client_handle_t		ps_mch;
180 	mac_promisc_handle_t		ps_phd;
181 	int				ps_type;
182 	int				ps_proto;
183 	uint_t				ps_max_sdu;
184 	boolean_t			ps_bound;
185 	mac_client_promisc_type_t	ps_promisc;
186 	boolean_t			ps_auxdata;
187 	struct tpacket_stats		ps_stats;
188 	struct sockaddr			ps_sock;
189 	datalink_id_t			ps_linkid;
190 	kmutex_t			ps_lock;
191 	boolean_t			ps_flow_ctrld;
192 	ulong_t				ps_flow_ctrl_drops;
193 	timespec_t			ps_timestamp;
194 	size_t				ps_rcvbuf;
195 } pfpsock_t;
196 
197 typedef struct pfp_kstats_s {
198 	kstat_named_t	kp_recv_mac_hdr_fail;
199 	kstat_named_t	kp_recv_bad_proto;
200 	kstat_named_t	kp_recv_alloc_fail;
201 	kstat_named_t	kp_recv_ok;
202 	kstat_named_t	kp_recv_fail;
203 	kstat_named_t	kp_recv_filtered;
204 	kstat_named_t	kp_recv_flow_cntrld;
205 	kstat_named_t	kp_send_unbound;
206 	kstat_named_t	kp_send_failed;
207 	kstat_named_t	kp_send_too_big;
208 	kstat_named_t	kp_send_alloc_fail;
209 	kstat_named_t	kp_send_uiomove_fail;
210 	kstat_named_t	kp_send_no_memory;
211 	kstat_named_t	kp_send_open_fail;
212 	kstat_named_t	kp_send_wrong_family;
213 	kstat_named_t	kp_send_short_msg;
214 	kstat_named_t	kp_send_ok;
215 } pfp_kstats_t;
216 #endif /* _KERNEL */
217 
218 #endif /* _PACKET_H */
219