xref: /titanic_41/usr/src/uts/common/inet/udp_impl.h (revision 99ebb4ca412cb0a19d77a3899a87c055b9c30fa8)
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  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_UDP_IMPL_H
27 #define	_UDP_IMPL_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 /*
32  * UDP implementation private declarations.  These interfaces are
33  * used to build the IP module and are not meant to be accessed
34  * by any modules except IP itself.  They are undocumented and are
35  * subject to change without notice.
36  */
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 #ifdef _KERNEL
43 
44 #include <sys/int_types.h>
45 
46 #include <netinet/in.h>
47 #include <netinet/ip6.h>
48 
49 #include <inet/common.h>
50 #include <inet/ip.h>
51 #include <inet/optcom.h>
52 
53 #define	UDP_MOD_ID		5607
54 
55 /* udp_mode. UDP_MT_HOT and UDP_SQUEUE are stable modes. Rest are transient */
56 typedef enum {
57 	UDP_MT_HOT = 0,			/* UDP endpoint is MT HOT */
58 	UDP_MT_QUEUED = 1,		/* Messages enqueued in udp_mphead */
59 	UDP_QUEUED_SQUEUE = 2,		/* Messages enqueued in conn_sqp */
60 	UDP_SQUEUE = 3			/* Single threaded using squeues */
61 } udp_mode_t;
62 
63 /* Internal udp control structure, one per open stream */
64 typedef	struct udp_s {
65 	uint32_t	udp_state;	/* TPI state */
66 	in_port_t	udp_port;	/* Port bound to this stream */
67 	in_port_t	udp_dstport;	/* Connected port */
68 	in6_addr_t	udp_v6src;	/* Source address of this stream */
69 	in6_addr_t	udp_bound_v6src; /* Explicitly bound address */
70 	in6_addr_t	udp_v6dst;	/* Connected destination */
71 	uint32_t	udp_flowinfo;	/* Connected flow id and tclass */
72 	uint32_t	udp_max_hdr_len; /* For write offset in stream head */
73 	sa_family_t	udp_family;	/* Family from socket() call */
74 	/*
75 	 * IP format that packets transmitted from this struct should use.
76 	 * Value can be IP4_VERSION or IPV6_VERSION.
77 	 */
78 	ushort_t	udp_ipversion;
79 	uint32_t	udp_ip_snd_options_len; /* Len of IPv4 options */
80 	uchar_t		*udp_ip_snd_options;    /* Ptr to IPv4 options */
81 	uint32_t	udp_ip_rcv_options_len; /* Len of IPv4 options recvd */
82 	uchar_t		*udp_ip_rcv_options;    /* Ptr to IPv4 options recvd */
83 	uchar_t		udp_multicast_ttl;	/* IP*_MULTICAST_TTL/HOPS */
84 	ipaddr_t	udp_multicast_if_addr;  /* IP_MULTICAST_IF option */
85 	uint_t		udp_multicast_if_index;	/* IPV6_MULTICAST_IF option */
86 	int		udp_bound_if;		/* IP*_BOUND_IF option */
87 	int		udp_xmit_if;		/* IP_XMIT_IF option */
88 	conn_t		*udp_connp;
89 	uint32_t
90 		udp_debug : 1,		/* SO_DEBUG "socket" option. */
91 		udp_dontroute : 1,	/* SO_DONTROUTE "socket" option. */
92 		udp_broadcast : 1,	/* SO_BROADCAST "socket" option. */
93 		udp_useloopback : 1,	/* SO_USELOOPBACK "socket" option */
94 
95 		udp_reuseaddr : 1,	/* SO_REUSEADDR "socket" option. */
96 		udp_dgram_errind : 1,	/* SO_DGRAM_ERRIND option */
97 		udp_recvdstaddr : 1,	/* IP_RECVDSTADDR option */
98 		udp_recvopts : 1,	/* IP_RECVOPTS option */
99 
100 		udp_discon_pending : 1,	/* T_DISCON_REQ in progress */
101 		udp_unspec_source : 1,	/* IP*_UNSPEC_SRC option */
102 		udp_ipv6_recvpktinfo : 1,	/* IPV6_RECVPKTINFO option  */
103 		udp_ipv6_recvhoplimit : 1,	/* IPV6_RECVHOPLIMIT option */
104 
105 		udp_ipv6_recvhopopts : 1,	/* IPV6_RECVHOPOPTS option */
106 		udp_ipv6_recvdstopts : 1,	/* IPV6_RECVDSTOPTS option */
107 		udp_ipv6_recvrthdr : 1,		/* IPV6_RECVRTHDR option */
108 		udp_ipv6_recvtclass : 1,	/* IPV6_RECVTCLASS */
109 
110 		udp_ipv6_recvpathmtu : 1,	/* IPV6_RECVPATHMTU */
111 		udp_anon_priv_bind : 1,
112 		udp_exclbind : 1,	/* ``exclusive'' binding */
113 		udp_recvif : 1,		/* IP_RECVIF option */
114 
115 		udp_recvslla : 1,	/* IP_RECVSLLA option */
116 		udp_recvttl : 1,	/* IP_RECVTTL option */
117 		udp_recvucred : 1,	/* IP_RECVUCRED option */
118 		udp_old_ipv6_recvdstopts : 1,	/* old form of IPV6_DSTOPTS */
119 
120 		udp_ipv6_recvrthdrdstopts : 1,	/* IPV6_RECVRTHDRDSTOPTS */
121 		udp_rcvhdr : 1,		/* UDP_RCVHDR option */
122 		udp_issocket : 1,	/* socket mode */
123 		udp_direct_sockfs : 1,	/* direct calls to/from sockfs */
124 
125 		udp_timestamp : 1,	/* SO_TIMESTAMP "socket" option */
126 		udp_anon_mlp : 1,		/* SO_ANON_MLP */
127 		udp_mac_exempt : 1,		/* SO_MAC_EXEMPT */
128 		udp_pad_to_bit_31 : 1;
129 
130 	uint8_t		udp_type_of_service;	/* IP_TOS option */
131 	uint8_t		udp_ttl;		/* TTL or hoplimit */
132 
133 	ip6_pkt_t	udp_sticky_ipp;		/* Sticky options */
134 	uint8_t		*udp_sticky_hdrs;	/* Prebuilt IPv6 hdrs */
135 	uint_t		udp_sticky_hdrs_len;	/* Incl. ip6h and any ip6i */
136 	struct udp_s	*udp_bind_hash; /* Bind hash chain */
137 	struct udp_s	**udp_ptpbhn; /* Pointer to previous bind hash next. */
138 	udp_mode_t	udp_mode;	/* Current mode of operation */
139 	mblk_t		*udp_mphead;	/* Head of the queued operations */
140 	mblk_t		*udp_mptail;	/* Tail of the queued operations */
141 	uint_t		udp_mpcount;	/* Number of messages in the queue */
142 	uint_t		udp_reader_count; /* Number of reader threads */
143 	uint_t		udp_squeue_count; /* Number of messages in conn_sqp */
144 
145 	kmutex_t	udp_drain_lock;		/* lock for udp_rcv_list */
146 	boolean_t	udp_drain_qfull;	/* drain queue is full */
147 	mblk_t		*udp_rcv_list_head;	/* b_next chain of mblks */
148 	mblk_t		*udp_rcv_list_tail;	/* last mblk in chain */
149 	uint_t		udp_rcv_cnt;		/* total data in rcv_list */
150 	uint_t		udp_rcv_msgcnt;		/* total messages in rcv_list */
151 	size_t		udp_rcv_hiwat;		/* receive high watermark */
152 	uint_t		udp_label_len;		/* length of security label */
153 	uint_t		udp_label_len_v6;	/* len of v6 security label */
154 	in6_addr_t 	udp_v6lastdst;		/* most recent destination */
155 } udp_t;
156 
157 /* UDP Protocol header */
158 /* UDP Protocol header aligned */
159 typedef	struct udpahdr_s {
160 	in_port_t	uha_src_port;		/* Source port */
161 	in_port_t	uha_dst_port;		/* Destination port */
162 	uint16_t	uha_length;		/* UDP length */
163 	uint16_t	uha_checksum;		/* UDP checksum */
164 } udpha_t;
165 
166 /* Named Dispatch Parameter Management Structure */
167 typedef struct udpparam_s {
168 	uint32_t udp_param_min;
169 	uint32_t udp_param_max;
170 	uint32_t udp_param_value;
171 	char	*udp_param_name;
172 } udpparam_t;
173 
174 extern udpparam_t udp_param_arr[];
175 
176 #define	udp_wroff_extra			udp_param_arr[0].udp_param_value
177 #define	udp_ipv4_ttl			udp_param_arr[1].udp_param_value
178 #define	udp_ipv6_hoplimit		udp_param_arr[2].udp_param_value
179 #define	udp_smallest_nonpriv_port	udp_param_arr[3].udp_param_value
180 #define	udp_do_checksum			udp_param_arr[4].udp_param_value
181 #define	udp_smallest_anon_port		udp_param_arr[5].udp_param_value
182 #define	udp_largest_anon_port		udp_param_arr[6].udp_param_value
183 #define	udp_xmit_hiwat			udp_param_arr[7].udp_param_value
184 #define	udp_xmit_lowat			udp_param_arr[8].udp_param_value
185 #define	udp_recv_hiwat			udp_param_arr[9].udp_param_value
186 #define	udp_max_buf			udp_param_arr[10].udp_param_value
187 #define	udp_ndd_get_info_interval	udp_param_arr[11].udp_param_value
188 
189 /* Kstats */
190 typedef struct {				/* Class "net" kstats */
191 	kstat_named_t	udp_ip_send;
192 	kstat_named_t	udp_ip_ire_send;
193 	kstat_named_t	udp_ire_null;
194 	kstat_named_t	udp_drain;
195 	kstat_named_t	udp_sock_fallback;
196 	kstat_named_t	udp_rrw_busy;
197 	kstat_named_t	udp_rrw_msgcnt;
198 	kstat_named_t	udp_out_sw_cksum;
199 	kstat_named_t	udp_out_sw_cksum_bytes;
200 	kstat_named_t	udp_out_opt;
201 	kstat_named_t	udp_out_err_notconn;
202 	kstat_named_t	udp_out_err_output;
203 	kstat_named_t	udp_out_err_tudr;
204 	kstat_named_t	udp_in_pktinfo;
205 	kstat_named_t	udp_in_recvdstaddr;
206 	kstat_named_t	udp_in_recvopts;
207 	kstat_named_t	udp_in_recvif;
208 	kstat_named_t	udp_in_recvslla;
209 	kstat_named_t	udp_in_recvucred;
210 	kstat_named_t	udp_in_recvttl;
211 	kstat_named_t	udp_in_recvhopopts;
212 	kstat_named_t	udp_in_recvhoplimit;
213 	kstat_named_t	udp_in_recvdstopts;
214 	kstat_named_t	udp_in_recvrtdstopts;
215 	kstat_named_t	udp_in_recvrthdr;
216 	kstat_named_t	udp_in_recvpktinfo;
217 	kstat_named_t	udp_in_recvtclass;
218 	kstat_named_t	udp_in_timestamp;
219 #ifdef DEBUG
220 	kstat_named_t	udp_data_conn;
221 	kstat_named_t	udp_data_notconn;
222 #endif
223 } udp_stat_t;
224 
225 extern udp_stat_t	udp_statistics;
226 
227 #define	UDP_STAT(x)		(udp_statistics.x.value.ui64++)
228 #define	UDP_STAT_UPDATE(x, n)	(udp_statistics.x.value.ui64 += (n))
229 #ifdef DEBUG
230 #define	UDP_DBGSTAT(x)		UDP_STAT(x)
231 #else
232 #define	UDP_DBGSTAT(x)
233 #endif /* DEBUG */
234 
235 extern major_t	UDP6_MAJ;
236 
237 extern int	udp_opt_default(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
238 extern int	udp_opt_get(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
239 extern int	udp_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *,
240 		    uint_t *, uchar_t *, void *, cred_t *, mblk_t *);
241 extern int	udp_snmp_get(queue_t *, mblk_t *);
242 extern int	udp_snmp_set(queue_t *, t_scalar_t, t_scalar_t, uchar_t *, int);
243 extern void	udp_close_free(conn_t *);
244 extern void	udp_quiesce_conn(conn_t *);
245 extern void	udp_ddi_init(void);
246 extern void	udp_ddi_destroy(void);
247 extern void	udp_resume_bind(conn_t *, mblk_t *);
248 extern void	udp_conn_recv(conn_t *, mblk_t *);
249 extern boolean_t udp_compute_checksum(void);
250 extern void	udp_wput_data(queue_t *, mblk_t *, struct sockaddr *,
251 		    socklen_t);
252 
253 extern int	udp_opt_default(queue_t *q, t_scalar_t level, t_scalar_t name,
254     uchar_t *ptr);
255 extern int	udp_opt_get(queue_t *q, t_scalar_t level, t_scalar_t name,
256     uchar_t *ptr);
257 extern int	udp_opt_set(queue_t *q, uint_t optset_context,
258     int level, int name, uint_t inlen, uchar_t *invalp, uint_t *outlenp,
259     uchar_t *outvalp, void *thisdg_attrs, cred_t *cr, mblk_t *mblk);
260 
261 /*
262  * Object to represent database of options to search passed to
263  * {sock,tpi}optcom_req() interface routine to take care of option
264  * management and associated methods.
265  */
266 extern optdb_obj_t	udp_opt_obj;
267 extern uint_t		udp_max_optsize;
268 
269 #endif	/*  _KERNEL */
270 
271 #ifdef	__cplusplus
272 }
273 #endif
274 
275 #endif	/* _UDP_IMPL_H */
276