Print this page
WIP to help bringup NAT flows
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/inet/udp_impl.h
+++ new/usr/src/uts/common/inet/udp_impl.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright 2015, Joyent, Inc.
24 24 */
25 25
26 26 #ifndef _UDP_IMPL_H
27 27 #define _UDP_IMPL_H
28 28
29 29 /*
30 30 * UDP implementation private declarations. These interfaces are
31 31 * used to build the IP module and are not meant to be accessed
32 32 * by any modules except IP itself. They are undocumented and are
33 33 * subject to change without notice.
34 34 */
35 35
36 36 #ifdef __cplusplus
37 37 extern "C" {
38 38 #endif
39 39
40 40 #ifdef _KERNEL
41 41
42 42 #include <sys/int_types.h>
43 43 #include <sys/netstack.h>
44 44
45 45 #include <netinet/in.h>
46 46 #include <netinet/ip6.h>
47 47
48 48 #include <inet/common.h>
49 49 #include <inet/ip.h>
50 50 #include <inet/optcom.h>
51 51 #include <inet/tunables.h>
52 52
53 53 #define UDP_MOD_ID 5607
54 54
55 55 /*
56 56 * Bind hash list size and hash function. It has to be a power of 2 for
57 57 * hashing.
58 58 */
59 59 #define UDP_BIND_FANOUT_SIZE 512
60 60 #define UDP_BIND_HASH(lport, size) \
61 61 ((ntohs((uint16_t)lport)) & (size - 1))
62 62
63 63 /* UDP bind fanout hash structure. */
64 64 typedef struct udp_fanout_s {
65 65 struct udp_s *uf_udp;
66 66 kmutex_t uf_lock;
67 67 #if defined(_LP64) || defined(_I32LPx)
68 68 char uf_pad[48];
69 69 #else
70 70 char uf_pad[56];
71 71 #endif
72 72 } udp_fanout_t;
73 73
74 74 /* Kstats */
75 75 typedef struct udp_stat { /* Class "net" kstats */
76 76 kstat_named_t udp_sock_fallback;
77 77 kstat_named_t udp_out_opt;
78 78 kstat_named_t udp_out_err_notconn;
79 79 kstat_named_t udp_out_err_output;
80 80 kstat_named_t udp_out_err_tudr;
81 81 #ifdef DEBUG
82 82 kstat_named_t udp_data_conn;
83 83 kstat_named_t udp_data_notconn;
84 84 kstat_named_t udp_out_lastdst;
85 85 kstat_named_t udp_out_diffdst;
86 86 kstat_named_t udp_out_ipv6;
87 87 kstat_named_t udp_out_mapped;
88 88 kstat_named_t udp_out_ipv4;
89 89 #endif
90 90 } udp_stat_t;
91 91
92 92 /*
93 93 * This struct contains only the counter part of udp_stat_t. It is used
94 94 * in udp_stats_cpu_t instead of udp_stat_t to save memory space.
95 95 */
96 96 typedef struct {
97 97 uint64_t udp_sock_fallback;
98 98 uint64_t udp_out_opt;
99 99 uint64_t udp_out_err_notconn;
100 100 uint64_t udp_out_err_output;
101 101 uint64_t udp_out_err_tudr;
102 102 #ifdef DEBUG
103 103 uint64_t udp_data_conn;
104 104 uint64_t udp_data_notconn;
105 105 uint64_t udp_out_lastdst;
106 106 uint64_t udp_out_diffdst;
107 107 uint64_t udp_out_ipv6;
108 108 uint64_t udp_out_mapped;
109 109 uint64_t udp_out_ipv4;
110 110 #endif
111 111 } udp_stat_counter_t;
112 112
113 113 /* Per CPU stats: UDP MIB2 and UDP kstat. */
114 114 typedef struct {
115 115 mib2_udp_t udp_sc_mib;
116 116 udp_stat_counter_t udp_sc_stats;
117 117 } udp_stats_cpu_t;
118 118
119 119 #define UDP_NUM_EPRIV_PORTS 64
120 120
121 121 /* Default buffer size and flow control wake up threshold. */
122 122 #define UDP_RECV_HIWATER (56 * 1024)
123 123 #define UDP_RECV_LOWATER 128
124 124 #define UDP_XMIT_HIWATER (56 * 1024)
125 125 #define UDP_XMIT_LOWATER 1024
126 126
127 127 /*
128 128 * UDP stack instances
129 129 */
130 130 struct udp_stack {
131 131 netstack_t *us_netstack; /* Common netstack */
132 132
133 133 uint_t us_bind_fanout_size;
134 134 udp_fanout_t *us_bind_fanout;
135 135
136 136 int us_num_epriv_ports;
137 137 in_port_t us_epriv_ports[UDP_NUM_EPRIV_PORTS];
138 138 kmutex_t us_epriv_port_lock;
139 139
140 140 /* Hint not protected by any lock */
141 141 in_port_t us_next_port_to_try;
142 142
143 143 /* UDP tunables table */
144 144 struct mod_prop_info_s *us_propinfo_tbl;
145 145
146 146 kstat_t *us_mibkp; /* kstats exporting mib data */
147 147 kstat_t *us_kstat;
148 148
149 149 /*
150 150 * The smallest anonymous port in the priviledged port range which UDP
151 151 * looks for free port. Use in the option UDP_ANONPRIVBIND.
152 152 */
153 153 in_port_t us_min_anonpriv_port;
154 154
155 155 ldi_ident_t us_ldi_ident;
156 156
157 157 udp_stats_cpu_t **us_sc;
158 158 int us_sc_cnt;
159 159 };
160 160
161 161 typedef struct udp_stack udp_stack_t;
162 162
163 163 /* Internal udp control structure, one per open stream */
164 164 typedef struct udp_s {
165 165 /*
166 166 * The addresses and ports in the conn_t and udp_state are protected by
167 167 * conn_lock and the fanout lock i.e. uf_lock. Need both locks to change
168 168 * the fields, either lock is sufficient for reading the field.
169 169 * conn_lock also protects the content of udp_t.
170 170 */
171 171 uint32_t udp_state; /* TPI state */
172 172
173 173 ip_pkt_t udp_recv_ipp; /* Used for IPv4 options received */
174 174
175 175 /* Written to only once at the time of opening the endpoint */
176 176 conn_t *udp_connp;
177 177
178 178 uint32_t
179 179 udp_issocket : 1, /* socket mode; sockfs is on top */
180 180 udp_nat_t_endpoint : 1, /* UDP_NAT_T_ENDPOINT option */
181 181 udp_rcvhdr : 1, /* UDP_RCVHDR option */
182 182 udp_vxlanhash: 1, /* UDP_SRCPORT_HASH option */
183 183 /* Because there's only VXLAN, cheat */
184 184 /* and only use a single bit */
185 185 udp_snd_to_conn: 1, /* UDP_SND_TO_CONNECTED option */
186 186
187 187 udp_pad_to_bit_31 : 27;
188 188
189 189 /* Following 2 fields protected by the uf_lock */
190 190 struct udp_s *udp_bind_hash; /* Bind hash chain */
191 191 struct udp_s **udp_ptpbhn; /* Pointer to previous bind hash next. */
192 192
193 193 kmutex_t udp_recv_lock; /* recv lock */
194 194 size_t udp_rcv_disply_hiwat; /* user's view of rcvbuf */
195 195 size_t udp_rcv_hiwat; /* receive high watermark */
196 196
197 197 /* Set at open time and never changed */
198 198 udp_stack_t *udp_us; /* Stack instance for zone */
199 199
200 200 int udp_delayed_error;
201 201 mblk_t *udp_fallback_queue_head;
202 202 mblk_t *udp_fallback_queue_tail;
203 203 struct sockaddr_storage udp_delayed_addr;
204 204 } udp_t;
205 205
206 206 /* UDP Protocol header aligned */
207 207 typedef struct udpahdr_s {
208 208 in_port_t uha_src_port; /* Source port */
209 209 in_port_t uha_dst_port; /* Destination port */
210 210 uint16_t uha_length; /* UDP length */
211 211 uint16_t uha_checksum; /* UDP checksum */
212 212 } udpha_t;
213 213
214 214 #define us_wroff_extra us_propinfo_tbl[0].prop_cur_uval
215 215 #define us_ipv4_ttl us_propinfo_tbl[1].prop_cur_uval
216 216 #define us_ipv6_hoplimit us_propinfo_tbl[2].prop_cur_uval
217 217 #define us_smallest_nonpriv_port us_propinfo_tbl[3].prop_cur_uval
218 218 #define us_do_checksum us_propinfo_tbl[4].prop_cur_bval
219 219 #define us_smallest_anon_port us_propinfo_tbl[5].prop_cur_uval
220 220 #define us_largest_anon_port us_propinfo_tbl[6].prop_cur_uval
221 221 #define us_xmit_hiwat us_propinfo_tbl[7].prop_cur_uval
222 222 #define us_xmit_lowat us_propinfo_tbl[8].prop_cur_uval
223 223 #define us_recv_hiwat us_propinfo_tbl[9].prop_cur_uval
224 224 #define us_max_buf us_propinfo_tbl[10].prop_cur_uval
225 225 #define us_pmtu_discovery us_propinfo_tbl[11].prop_cur_bval
226 226 #define us_sendto_ignerr us_propinfo_tbl[12].prop_cur_bval
227 227
228 228 #define UDPS_BUMP_MIB(us, x) \
229 229 BUMP_MIB(&(us)->us_sc[CPU->cpu_seqid]->udp_sc_mib, x)
230 230
231 231 #define UDP_STAT(us, x) ((us)->us_sc[CPU->cpu_seqid]->udp_sc_stats.x++)
232 232 #define UDP_STAT_UPDATE(us, x, n) \
233 233 ((us)->us->sc[CPU->cpu_seqid]->udp_sc_stats.x.value.ui64 += (n))
234 234 #ifdef DEBUG
235 235 #define UDP_DBGSTAT(us, x) UDP_STAT(us, x)
236 236 #else
237 237 #define UDP_DBGSTAT(us, x)
238 238 #endif /* DEBUG */
239 239
240 240 extern int udp_opt_default(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
241 241 extern int udp_tpi_opt_get(queue_t *, t_scalar_t, t_scalar_t, uchar_t *);
242 242 extern int udp_tpi_opt_set(queue_t *, uint_t, int, int, uint_t, uchar_t *,
243 243 uint_t *, uchar_t *, void *, cred_t *);
244 244 extern mblk_t *udp_snmp_get(queue_t *, mblk_t *, boolean_t);
245 245 extern int udp_snmp_set(queue_t *, t_scalar_t, t_scalar_t, uchar_t *, int);
246 246 extern void udp_ddi_g_init(void);
247 247 extern void udp_ddi_g_destroy(void);
248 248 extern void udp_output(conn_t *connp, mblk_t *mp, struct sockaddr *addr,
|
↓ open down ↓ |
248 lines elided |
↑ open up ↑ |
249 249 socklen_t addrlen);
250 250 extern void udp_wput(queue_t *, mblk_t *);
251 251
252 252 extern void *udp_kstat_init(netstackid_t stackid);
253 253 extern void udp_kstat_fini(netstackid_t stackid, kstat_t *ksp);
254 254 extern void *udp_kstat2_init(netstackid_t stackid);
255 255 extern void udp_kstat2_fini(netstackid_t, kstat_t *);
256 256
257 257 extern void udp_stack_cpu_add(udp_stack_t *, processorid_t);
258 258
259 +extern in_port_t udp_update_next_port(udp_t *, in_port_t, boolean_t);
260 +
259 261 /*
260 262 * Object to represent database of options to search passed to
261 263 * {sock,tpi}optcom_req() interface routine to take care of option
262 264 * management and associated methods.
263 265 */
264 266 extern optdb_obj_t udp_opt_obj;
265 267 extern uint_t udp_max_optsize;
266 268
267 269 extern sock_lower_handle_t udp_create(int, int, int, sock_downcalls_t **,
268 270 uint_t *, int *, int, cred_t *);
269 271 extern int udp_fallback(sock_lower_handle_t, queue_t *, boolean_t,
270 272 so_proto_quiesced_cb_t, sock_quiesce_arg_t *);
271 273
272 274 extern sock_downcalls_t sock_udp_downcalls;
273 275
274 276 #endif /* _KERNEL */
275 277
276 278 #ifdef __cplusplus
277 279 }
278 280 #endif
279 281
280 282 #endif /* _UDP_IMPL_H */
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX