xref: /titanic_51/usr/src/uts/common/inet/sockmods/netpacket/packet.h (revision 0d928757379972073af9fb22bdc827b74e8ba6ac)
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  */
25 
26 #ifndef _PACKET_H
27 #define	_PACKET_H
28 
29 #include <sys/socket_impl.h>
30 #include <net/if_arp.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. Those that are already found in
120  * Solaris inside <net/if_arp.h> may have a different value to that found
121  * in Linux but it should be used instead as the Solaris value originates
122  * from the IANA whereas the Linux values seem to ignore it.
123  */
124 /* ARPHRD_AX25				see <net/if_arp.h> */
125 /* ARPHRD_CHAOS				see <net/if_arp.h> */
126 #define	ARPHRD_CSLIP			50005
127 #define	ARPHRD_CSLIP6			50006
128 #define	ARPHRD_DLCI			15
129 /* ARPHRD_EETHER			see <net/if_arp.h> */
130 /* ARPHRD_ETHER				see <net/if_arp.h> */
131 #define	ARPHRD_FCAL			785
132 #define	ARPHRD_FCFABRIC			787
133 #define	ARPHRD_FCPL			786
134 #define	ARPHRD_FCPP			784
135 #define	ARPHRD_FRAD			770
136 #define	ARPHRD_FDDI			774
137 /* ARPHRD_IEEE802			see <net/if_arp.h> */
138 #define	ARPHRD_IEEE802_TR		800
139 #define	ARPHRD_IEEE80211		801
140 #define	ARPHRD_IEEE80211_PRISM		802
141 #define	ARPHRD_IEEE80211_RADIOTAP	803
142 #define	ARPHRD_IRDA			783
143 #define	ARPHRD_LAPD			8445
144 #define	ARPHRD_LOCALTLK			50010
145 #define	ARPHRD_LOOPBACK			50011
146 /* ARPHRD_METRICOM			see <net/if_arp.h> */
147 #define	ARPHRD_PRONET			50013
148 #define	ARPHRD_PPP			50014
149 #define	ARPHRD_RAWHDLC			518
150 #define	ARPHRD_SIT			776
151 #define	ARPHRD_SLIP6			50015
152 #define	ARPHRD_SLIP			50016
153 /* ARPHRD_TUNNEL			see <net/if_arp.h> */
154 
155 #define	ETH_P_ALL			0
156 #define	ETH_P_802_2			0xaa	/* LSAP_SAP */
157 #define	ETH_P_803_3			0
158 #define	ETH_P_IP			0x800
159 #define	ETH_P_ARP			0x806
160 #define	ETH_P_IPV6			0x86dd
161 
162 #ifdef _KERNEL
163 /*
164  * PFP socket structure.
165  */
166 typedef struct pfpsock {
167 	struct bpf_program		ps_bpf;
168 	krwlock_t			ps_bpflock;
169 	sock_upper_handle_t		ps_upper;
170 	sock_upcalls_t			*ps_upcalls;
171 	mac_handle_t			ps_mh;
172 	mac_client_handle_t		ps_mch;
173 	mac_promisc_handle_t		ps_phd;
174 	int				ps_type;
175 	int				ps_proto;
176 	uint_t				ps_max_sdu;
177 	boolean_t			ps_bound;
178 	mac_client_promisc_type_t	ps_promisc;
179 	boolean_t			ps_auxdata;
180 	struct tpacket_stats		ps_stats;
181 	struct sockaddr			ps_sock;
182 	datalink_id_t			ps_linkid;
183 	kmutex_t			ps_lock;
184 	boolean_t			ps_flow_ctrld;
185 	ulong_t				ps_flow_ctrl_drops;
186 } pfpsock_t;
187 
188 typedef struct pfp_kstats_s {
189 	kstat_named_t	kp_recv_mac_hdr_fail;
190 	kstat_named_t	kp_recv_bad_proto;
191 	kstat_named_t	kp_recv_alloc_fail;
192 	kstat_named_t	kp_recv_ok;
193 	kstat_named_t	kp_recv_fail;
194 	kstat_named_t	kp_recv_filtered;
195 	kstat_named_t	kp_recv_flow_cntrld;
196 	kstat_named_t	kp_send_unbound;
197 	kstat_named_t	kp_send_failed;
198 	kstat_named_t	kp_send_too_big;
199 	kstat_named_t	kp_send_alloc_fail;
200 	kstat_named_t	kp_send_uiomove_fail;
201 	kstat_named_t	kp_send_no_memory;
202 	kstat_named_t	kp_send_open_fail;
203 	kstat_named_t	kp_send_wrong_family;
204 	kstat_named_t	kp_send_short_msg;
205 	kstat_named_t	kp_send_ok;
206 } pfp_kstats_t;
207 #endif /* _KERNEL */
208 
209 #endif /* _PACKET_H */
210