xref: /titanic_50/usr/src/uts/common/inet/udp_impl.h (revision a307732568c3d861c38b0342ae32434226d10e94)
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 (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef	_UDP_IMPL_H
26 #define	_UDP_IMPL_H
27 
28 /*
29  * UDP implementation private declarations.  These interfaces are
30  * used to build the IP module and are not meant to be accessed
31  * by any modules except IP itself.  They are undocumented and are
32  * subject to change without notice.
33  */
34 
35 #ifdef	__cplusplus
36 extern "C" {
37 #endif
38 
39 #ifdef _KERNEL
40 
41 #include <sys/int_types.h>
42 #include <sys/netstack.h>
43 
44 #include <netinet/in.h>
45 #include <netinet/ip6.h>
46 
47 #include <inet/common.h>
48 #include <inet/ip.h>
49 #include <inet/optcom.h>
50 #include <inet/tunables.h>
51 
52 #define	UDP_MOD_ID		5607
53 
54 /*
55  * Bind hash list size and hash function.  It has to be a power of 2 for
56  * hashing.
57  */
58 #define	UDP_BIND_FANOUT_SIZE	512
59 #define	UDP_BIND_HASH(lport, size) \
60 	((ntohs((uint16_t)lport)) & (size - 1))
61 
62 /* UDP bind fanout hash structure. */
63 typedef struct udp_fanout_s {
64 	struct udp_s *uf_udp;
65 	kmutex_t uf_lock;
66 #if defined(_LP64) || defined(_I32LPx)
67 	char	uf_pad[48];
68 #else
69 	char	uf_pad[56];
70 #endif
71 } udp_fanout_t;
72 
73 /* Kstats */
74 typedef struct udp_stat {			/* Class "net" kstats */
75 	kstat_named_t	udp_sock_fallback;
76 	kstat_named_t	udp_out_opt;
77 	kstat_named_t	udp_out_err_notconn;
78 	kstat_named_t	udp_out_err_output;
79 	kstat_named_t	udp_out_err_tudr;
80 #ifdef DEBUG
81 	kstat_named_t	udp_data_conn;
82 	kstat_named_t	udp_data_notconn;
83 	kstat_named_t	udp_out_lastdst;
84 	kstat_named_t	udp_out_diffdst;
85 	kstat_named_t	udp_out_ipv6;
86 	kstat_named_t	udp_out_mapped;
87 	kstat_named_t	udp_out_ipv4;
88 #endif
89 
90 } udp_stat_t;
91 
92 #define	UDP_NUM_EPRIV_PORTS	64
93 
94 /* Default buffer size and flow control wake up threshold. */
95 #define	UDP_RECV_HIWATER	(56 * 1024)
96 #define	UDP_RECV_LOWATER	128
97 #define	UDP_XMIT_HIWATER	(56 * 1024)
98 #define	UDP_XMIT_LOWATER	1024
99 
100 /*
101  * UDP stack instances
102  */
103 struct udp_stack {
104 	netstack_t	*us_netstack;	/* Common netstack */
105 
106 	uint_t		us_bind_fanout_size;
107 	udp_fanout_t	*us_bind_fanout;
108 
109 	int		us_num_epriv_ports;
110 	in_port_t	us_epriv_ports[UDP_NUM_EPRIV_PORTS];
111 	kmutex_t	us_epriv_port_lock;
112 
113 	/* Hint not protected by any lock */
114 	in_port_t	us_next_port_to_try;
115 
116 	/* UDP tunables table */
117 	struct mod_prop_info_s	*us_propinfo_tbl;
118 
119 	kstat_t		*us_mibkp;	/* kstats exporting mib data */
120 	kstat_t		*us_kstat;
121 	udp_stat_t	us_statistics;
122 
123 	mib2_udp_t	us_udp_mib;	/* SNMP fixed size info */
124 
125 /*
126  * The smallest anonymous port in the priviledged port range which UDP
127  * looks for free port.  Use in the option UDP_ANONPRIVBIND.
128  */
129 	in_port_t	us_min_anonpriv_port;
130 
131 	ldi_ident_t	us_ldi_ident;
132 };
133 
134 typedef struct udp_stack udp_stack_t;
135 
136 /* Internal udp control structure, one per open stream */
137 typedef	struct udp_s {
138 	/*
139 	 * The addresses and ports in the conn_t and udp_state are protected by
140 	 * conn_lock and the fanout lock i.e. uf_lock. Need both locks to change
141 	 * the fields, either lock is sufficient for reading the field.
142 	 * conn_lock also protects the content of udp_t.
143 	 */
144 	uint32_t	udp_state;	/* TPI state */
145 
146 	ip_pkt_t	udp_recv_ipp;	/* Used for IPv4 options received */
147 
148 	/* Written to only once at the time of opening the endpoint */
149 	conn_t		*udp_connp;
150 
151 	uint32_t
152 		udp_issocket : 1,	/* socket mode; sockfs is on top */
153 		udp_nat_t_endpoint : 1,	/* UDP_NAT_T_ENDPOINT option */
154 		udp_rcvhdr : 1,		/* UDP_RCVHDR option */
155 
156 		udp_pad_to_bit_31 : 29;
157 
158 	/* Following 2 fields protected by the uf_lock */
159 	struct udp_s	*udp_bind_hash; /* Bind hash chain */
160 	struct udp_s	**udp_ptpbhn; /* Pointer to previous bind hash next. */
161 
162 	kmutex_t	udp_recv_lock;		/* recv lock */
163 	size_t		udp_rcv_disply_hiwat;	/* user's view of rcvbuf */
164 	size_t		udp_rcv_hiwat;		/* receive high watermark */
165 
166 	/* Set at open time and never changed */
167 	udp_stack_t	*udp_us;		/* Stack instance for zone */
168 
169 	int		udp_delayed_error;
170 	mblk_t		*udp_fallback_queue_head;
171 	mblk_t		*udp_fallback_queue_tail;
172 	struct sockaddr_storage	udp_delayed_addr;
173 } udp_t;
174 
175 /* UDP Protocol header aligned */
176 typedef	struct udpahdr_s {
177 	in_port_t	uha_src_port;		/* Source port */
178 	in_port_t	uha_dst_port;		/* Destination port */
179 	uint16_t	uha_length;		/* UDP length */
180 	uint16_t	uha_checksum;		/* UDP checksum */
181 } udpha_t;
182 
183 #define	us_wroff_extra			us_propinfo_tbl[0].prop_cur_uval
184 #define	us_ipv4_ttl			us_propinfo_tbl[1].prop_cur_uval
185 #define	us_ipv6_hoplimit		us_propinfo_tbl[2].prop_cur_uval
186 #define	us_smallest_nonpriv_port	us_propinfo_tbl[3].prop_cur_uval
187 #define	us_do_checksum			us_propinfo_tbl[4].prop_cur_bval
188 #define	us_smallest_anon_port		us_propinfo_tbl[5].prop_cur_uval
189 #define	us_largest_anon_port		us_propinfo_tbl[6].prop_cur_uval
190 #define	us_xmit_hiwat			us_propinfo_tbl[7].prop_cur_uval
191 #define	us_xmit_lowat			us_propinfo_tbl[8].prop_cur_uval
192 #define	us_recv_hiwat			us_propinfo_tbl[9].prop_cur_uval
193 #define	us_max_buf			us_propinfo_tbl[10].prop_cur_uval
194 #define	us_pmtu_discovery		us_propinfo_tbl[11].prop_cur_bval
195 #define	us_sendto_ignerr		us_propinfo_tbl[12].prop_cur_bval
196 
197 #define	UDP_STAT(us, x)		((us)->us_statistics.x.value.ui64++)
198 #define	UDP_STAT_UPDATE(us, x, n)	\
199 			((us)->us_statistics.x.value.ui64 += (n))
200 #ifdef DEBUG
201 #define	UDP_DBGSTAT(us, x)	UDP_STAT(us, x)
202 #else
203 #define	UDP_DBGSTAT(us, x)
204 #endif /* DEBUG */
205 
206 extern int	udp_opt_default(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
207 extern int	udp_tpi_opt_get(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
208 extern int	udp_tpi_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *,
209 		    uint_t *, uchar_t *, void *, cred_t *);
210 extern mblk_t	*udp_snmp_get(queue_t *, mblk_t *);
211 extern int	udp_snmp_set(queue_t *, t_scalar_t, t_scalar_t, uchar_t *, int);
212 extern void	udp_ddi_g_init(void);
213 extern void	udp_ddi_g_destroy(void);
214 extern void	udp_output(conn_t *connp, mblk_t *mp, struct sockaddr *addr,
215 		    socklen_t addrlen);
216 extern void	udp_wput(queue_t *, mblk_t *);
217 
218 /*
219  * Object to represent database of options to search passed to
220  * {sock,tpi}optcom_req() interface routine to take care of option
221  * management and associated methods.
222  */
223 extern optdb_obj_t	udp_opt_obj;
224 extern uint_t		udp_max_optsize;
225 
226 extern sock_lower_handle_t udp_create(int, int, int, sock_downcalls_t **,
227     uint_t *, int *, int, cred_t *);
228 extern int udp_fallback(sock_lower_handle_t, queue_t *, boolean_t,
229     so_proto_quiesced_cb_t, sock_quiesce_arg_t *);
230 
231 extern sock_downcalls_t sock_udp_downcalls;
232 
233 #endif	/*  _KERNEL */
234 
235 #ifdef	__cplusplus
236 }
237 #endif
238 
239 #endif	/* _UDP_IMPL_H */
240