Print this page
11546 Track TCP round-trip time in nanoseconds
Portions contributed by: Cody Peter Mello <cody.mello@joyent.com>
Portions contributed by: Brandon Baker <bbaker@delphix.com>
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/inet/tcp/tcp_opt_data.c
+++ new/usr/src/uts/common/inet/tcp/tcp_opt_data.c
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
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
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) 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
24 + * Copyright 2016 Joyent, Inc.
25 + * Copyright (c) 2016 by Delphix. All rights reserved.
24 26 */
25 27
26 28 #include <sys/types.h>
27 29 #include <sys/stream.h>
28 30 #define _SUN_TPI_VERSION 2
29 31 #include <sys/tihdr.h>
30 32 #include <sys/socket.h>
31 33 #include <sys/xti_xtiopt.h>
32 34 #include <sys/xti_inet.h>
33 35 #include <sys/policy.h>
34 36
35 37 #include <inet/common.h>
36 38 #include <netinet/ip6.h>
37 39 #include <inet/ip.h>
38 40
39 41 #include <netinet/in.h>
40 42 #include <netinet/tcp.h>
41 43 #include <inet/optcom.h>
42 44 #include <inet/proto_set.h>
43 45 #include <inet/tcp_impl.h>
44 46
45 47 static int tcp_opt_default(queue_t *, int, int, uchar_t *);
46 48
47 49 /*
48 50 * Table of all known options handled on a TCP protocol stack.
49 51 *
50 52 * Note: This table contains options processed by both TCP and IP levels
51 53 * and is the superset of options that can be performed on a TCP over IP
52 54 * stack.
53 55 */
54 56 opdes_t tcp_opt_arr[] = {
55 57
56 58 { SO_LINGER, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
57 59 sizeof (struct linger), 0 },
58 60
59 61 { SO_DEBUG, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
60 62 { SO_KEEPALIVE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
61 63 { SO_DONTROUTE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
62 64 { SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
63 65 },
64 66 { SO_BROADCAST, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
65 67 { SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
66 68 { SO_OOBINLINE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
67 69 { SO_TYPE, SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
68 70 { SO_SNDBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
69 71 { SO_RCVBUF, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
70 72 { SO_SNDTIMEO, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
71 73 sizeof (struct timeval), 0 },
72 74 { SO_RCVTIMEO, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
73 75 sizeof (struct timeval), 0 },
74 76 { SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
75 77 },
76 78 { SO_SND_COPYAVOID, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
77 79 { SO_ANON_MLP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
78 80 0 },
79 81 { SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
80 82 0 },
81 83 { SO_MAC_IMPLICIT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
82 84 0 },
83 85 { SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, 0, sizeof (int),
84 86 0 },
85 87 { SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
86 88
87 89 { SO_DOMAIN, SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
88 90
89 91 { SO_PROTOTYPE, SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
90 92
91 93 { TCP_NODELAY, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
92 94 },
93 95 { TCP_MAXSEG, IPPROTO_TCP, OA_R, OA_R, OP_NP, 0, sizeof (uint_t),
94 96 536 },
95 97
96 98 { TCP_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
97 99 OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
98 100
99 101 { TCP_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
100 102 OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
101 103
102 104 { TCP_CONN_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
103 105 OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
104 106
105 107 { TCP_CONN_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
106 108 OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
107 109
108 110 { TCP_RECVDSTADDR, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
109 111 0 },
110 112
111 113 { TCP_ANONPRIVBIND, IPPROTO_TCP, OA_R, OA_RW, OP_PRIVPORT, 0,
112 114 sizeof (int), 0 },
113 115
114 116 { TCP_EXCLBIND, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
115 117 },
116 118
117 119 { TCP_INIT_CWND, IPPROTO_TCP, OA_RW, OA_RW, OP_CONFIG, 0,
118 120 sizeof (int), 0 },
119 121
120 122 { TCP_KEEPALIVE_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0,
121 123 sizeof (int), 0 },
122 124
123 125 { TCP_KEEPIDLE, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
124 126
125 127 { TCP_KEEPCNT, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
126 128
127 129 { TCP_KEEPINTVL, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
128 130
129 131 { TCP_KEEPALIVE_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0,
130 132 sizeof (int), 0 },
131 133
132 134 { TCP_CORK, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
133 135
134 136 { TCP_RTO_INITIAL, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
135 137
136 138 { TCP_RTO_MIN, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
137 139
138 140 { TCP_RTO_MAX, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
139 141
140 142 { TCP_LINGER2, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
141 143
142 144 { IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
143 145 (OP_VARLEN|OP_NODEFAULT),
144 146 IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
145 147 { T_IP_OPTIONS, IPPROTO_IP, OA_RW, OA_RW, OP_NP,
146 148 (OP_VARLEN|OP_NODEFAULT),
147 149 IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
148 150
149 151 { IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
150 152 { T_IP_TOS, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
151 153 { IP_TTL, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
152 154 sizeof (int), -1 /* not initialized */ },
153 155
154 156 { IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_NODEFAULT,
155 157 sizeof (ipsec_req_t), -1 /* not initialized */ },
156 158
157 159 { IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0,
158 160 sizeof (int), 0 /* no ifindex */ },
159 161
160 162 { IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0,
161 163 sizeof (int), 0 },
162 164
163 165 { IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
164 166 sizeof (int), -1 /* not initialized */ },
165 167
166 168 { IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
167 169 sizeof (int), 0 /* no ifindex */ },
168 170
169 171 { IP_DONTFRAG, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
170 172
171 173 { IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0,
172 174 sizeof (in_addr_t), -1 /* not initialized */ },
173 175
174 176 { IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, 0,
175 177 sizeof (int), 0 },
176 178
177 179 { IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
178 180 (OP_NODEFAULT|OP_VARLEN),
179 181 sizeof (struct in6_pktinfo), -1 /* not initialized */ },
180 182 { IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
181 183 OP_NODEFAULT,
182 184 sizeof (sin6_t), -1 /* not initialized */ },
183 185 { IPV6_HOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
184 186 (OP_VARLEN|OP_NODEFAULT), 255*8,
185 187 -1 /* not initialized */ },
186 188 { IPV6_DSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
187 189 (OP_VARLEN|OP_NODEFAULT), 255*8,
188 190 -1 /* not initialized */ },
189 191 { IPV6_RTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
190 192 (OP_VARLEN|OP_NODEFAULT), 255*8,
191 193 -1 /* not initialized */ },
192 194 { IPV6_RTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
193 195 (OP_VARLEN|OP_NODEFAULT), 255*8,
194 196 -1 /* not initialized */ },
195 197 { IPV6_TCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
196 198 OP_NODEFAULT,
197 199 sizeof (int), -1 /* not initialized */ },
198 200 { IPV6_PATHMTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
199 201 OP_NODEFAULT,
200 202 sizeof (struct ip6_mtuinfo), -1 /* not initialized */ },
201 203 { IPV6_DONTFRAG, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
202 204 sizeof (int), 0 },
203 205 { IPV6_USE_MIN_MTU, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
204 206 sizeof (int), 0 },
205 207 { IPV6_V6ONLY, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
206 208 sizeof (int), 0 },
207 209
208 210 /* Enable receipt of ancillary data */
209 211 { IPV6_RECVPKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
210 212 sizeof (int), 0 },
211 213 { IPV6_RECVHOPLIMIT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
212 214 sizeof (int), 0 },
213 215 { IPV6_RECVHOPOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
214 216 sizeof (int), 0 },
215 217 { _OLD_IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
216 218 sizeof (int), 0 },
217 219 { IPV6_RECVDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
218 220 sizeof (int), 0 },
219 221 { IPV6_RECVRTHDR, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
220 222 sizeof (int), 0 },
221 223 { IPV6_RECVRTHDRDSTOPTS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
222 224 sizeof (int), 0 },
223 225 { IPV6_RECVTCLASS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
224 226 sizeof (int), 0 },
225 227
226 228 { IPV6_SEC_OPT, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_NODEFAULT,
227 229 sizeof (ipsec_req_t), -1 /* not initialized */ },
228 230 { IPV6_SRC_PREFERENCES, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
229 231 sizeof (uint32_t), IPV6_PREFER_SRC_DEFAULT },
230 232 };
231 233
232 234 /*
233 235 * Table of all supported levels
234 236 * Note: Some levels (e.g. XTI_GENERIC) may be valid but may not have
235 237 * any supported options so we need this info separately.
236 238 *
237 239 * This is needed only for topmost tpi providers and is used only by
238 240 * XTI interfaces.
239 241 */
240 242 optlevel_t tcp_valid_levels_arr[] = {
241 243 XTI_GENERIC,
242 244 SOL_SOCKET,
243 245 IPPROTO_TCP,
244 246 IPPROTO_IP,
245 247 IPPROTO_IPV6
246 248 };
247 249
248 250
249 251 #define TCP_OPT_ARR_CNT A_CNT(tcp_opt_arr)
250 252 #define TCP_VALID_LEVELS_CNT A_CNT(tcp_valid_levels_arr)
251 253
252 254 uint_t tcp_max_optsize; /* initialized when TCP driver is loaded */
253 255
254 256 /*
255 257 * Initialize option database object for TCP
256 258 *
257 259 * This object represents database of options to search passed to
258 260 * {sock,tpi}optcom_req() interface routine to take care of option
259 261 * management and associated methods.
260 262 */
261 263
262 264 optdb_obj_t tcp_opt_obj = {
263 265 tcp_opt_default, /* TCP default value function pointer */
264 266 tcp_tpi_opt_get, /* TCP get function pointer */
265 267 tcp_tpi_opt_set, /* TCP set function pointer */
266 268 TCP_OPT_ARR_CNT, /* TCP option database count of entries */
267 269 tcp_opt_arr, /* TCP option database */
268 270 TCP_VALID_LEVELS_CNT, /* TCP valid level count of entries */
269 271 tcp_valid_levels_arr /* TCP valid level array */
270 272 };
271 273
272 274 static int tcp_max_init_cwnd = TCP_MAX_INIT_CWND;
273 275
274 276 /*
275 277 * Some TCP options can be "set" by requesting them in the option
276 278 * buffer. This is needed for XTI feature test though we do not
277 279 * allow it in general. We interpret that this mechanism is more
278 280 * applicable to OSI protocols and need not be allowed in general.
279 281 * This routine filters out options for which it is not allowed (most)
280 282 * and lets through those (few) for which it is. [ The XTI interface
281 283 * test suite specifics will imply that any XTI_GENERIC level XTI_* if
282 284 * ever implemented will have to be allowed here ].
283 285 */
284 286 static boolean_t
285 287 tcp_allow_connopt_set(int level, int name)
286 288 {
287 289
288 290 switch (level) {
289 291 case IPPROTO_TCP:
290 292 switch (name) {
291 293 case TCP_NODELAY:
292 294 return (B_TRUE);
293 295 default:
294 296 return (B_FALSE);
295 297 }
296 298 /*NOTREACHED*/
297 299 default:
298 300 return (B_FALSE);
299 301 }
300 302 /*NOTREACHED*/
301 303 }
302 304
303 305 /*
304 306 * This routine gets default values of certain options whose default
305 307 * values are maintained by protocol specific code
306 308 */
307 309 /* ARGSUSED */
308 310 static int
309 311 tcp_opt_default(queue_t *q, int level, int name, uchar_t *ptr)
310 312 {
311 313 int32_t *i1 = (int32_t *)ptr;
312 314 tcp_stack_t *tcps = Q_TO_TCP(q)->tcp_tcps;
313 315
314 316 switch (level) {
315 317 case IPPROTO_TCP:
316 318 switch (name) {
317 319 case TCP_NOTIFY_THRESHOLD:
318 320 *i1 = tcps->tcps_ip_notify_interval;
319 321 break;
320 322 case TCP_ABORT_THRESHOLD:
321 323 *i1 = tcps->tcps_ip_abort_interval;
322 324 break;
323 325 case TCP_CONN_NOTIFY_THRESHOLD:
324 326 *i1 = tcps->tcps_ip_notify_cinterval;
325 327 break;
326 328 case TCP_CONN_ABORT_THRESHOLD:
327 329 *i1 = tcps->tcps_ip_abort_cinterval;
328 330 break;
329 331 default:
330 332 return (-1);
331 333 }
332 334 break;
333 335 case IPPROTO_IP:
334 336 switch (name) {
335 337 case IP_TTL:
336 338 *i1 = tcps->tcps_ipv4_ttl;
337 339 break;
338 340 default:
339 341 return (-1);
340 342 }
341 343 break;
342 344 case IPPROTO_IPV6:
343 345 switch (name) {
344 346 case IPV6_UNICAST_HOPS:
345 347 *i1 = tcps->tcps_ipv6_hoplimit;
346 348 break;
347 349 default:
348 350 return (-1);
349 351 }
350 352 break;
351 353 default:
352 354 return (-1);
353 355 }
354 356 return (sizeof (int));
355 357 }
356 358
357 359 /*
358 360 * TCP routine to get the values of options.
359 361 */
360 362 int
361 363 tcp_opt_get(conn_t *connp, int level, int name, uchar_t *ptr)
362 364 {
363 365 int *i1 = (int *)ptr;
364 366 tcp_t *tcp = connp->conn_tcp;
365 367 conn_opt_arg_t coas;
366 368 int retval;
367 369
368 370 coas.coa_connp = connp;
369 371 coas.coa_ixa = connp->conn_ixa;
370 372 coas.coa_ipp = &connp->conn_xmit_ipp;
371 373 coas.coa_ancillary = B_FALSE;
372 374 coas.coa_changed = 0;
373 375
374 376 switch (level) {
375 377 case SOL_SOCKET:
376 378 switch (name) {
377 379 case SO_SND_COPYAVOID:
378 380 *i1 = tcp->tcp_snd_zcopy_on ?
379 381 SO_SND_COPYAVOID : 0;
380 382 return (sizeof (int));
381 383 case SO_ACCEPTCONN:
382 384 *i1 = (tcp->tcp_state == TCPS_LISTEN);
383 385 return (sizeof (int));
384 386 }
385 387 break;
386 388 case IPPROTO_TCP:
387 389 switch (name) {
388 390 case TCP_NODELAY:
389 391 *i1 = (tcp->tcp_naglim == 1) ? TCP_NODELAY : 0;
390 392 return (sizeof (int));
391 393 case TCP_MAXSEG:
392 394 *i1 = tcp->tcp_mss;
393 395 return (sizeof (int));
394 396 case TCP_NOTIFY_THRESHOLD:
395 397 *i1 = (int)tcp->tcp_first_timer_threshold;
396 398 return (sizeof (int));
397 399 case TCP_ABORT_THRESHOLD:
398 400 *i1 = tcp->tcp_second_timer_threshold;
399 401 return (sizeof (int));
400 402 case TCP_CONN_NOTIFY_THRESHOLD:
401 403 *i1 = tcp->tcp_first_ctimer_threshold;
402 404 return (sizeof (int));
403 405 case TCP_CONN_ABORT_THRESHOLD:
404 406 *i1 = tcp->tcp_second_ctimer_threshold;
405 407 return (sizeof (int));
406 408 case TCP_INIT_CWND:
407 409 *i1 = tcp->tcp_init_cwnd;
408 410 return (sizeof (int));
409 411 case TCP_KEEPALIVE_THRESHOLD:
410 412 *i1 = tcp->tcp_ka_interval;
411 413 return (sizeof (int));
412 414
413 415 /*
414 416 * TCP_KEEPIDLE expects value in seconds, but
415 417 * tcp_ka_interval is in milliseconds.
416 418 */
417 419 case TCP_KEEPIDLE:
418 420 *i1 = tcp->tcp_ka_interval / 1000;
419 421 return (sizeof (int));
420 422 case TCP_KEEPCNT:
421 423 *i1 = tcp->tcp_ka_cnt;
422 424 return (sizeof (int));
423 425
424 426 /*
425 427 * TCP_KEEPINTVL expects value in seconds, but
426 428 * tcp_ka_rinterval is in milliseconds.
427 429 */
428 430 case TCP_KEEPINTVL:
429 431 *i1 = tcp->tcp_ka_rinterval / 1000;
430 432 return (sizeof (int));
431 433 case TCP_KEEPALIVE_ABORT_THRESHOLD:
432 434 *i1 = tcp->tcp_ka_abort_thres;
433 435 return (sizeof (int));
434 436 case TCP_CORK:
435 437 *i1 = tcp->tcp_cork;
436 438 return (sizeof (int));
437 439 case TCP_RTO_INITIAL:
438 440 *i1 = tcp->tcp_rto_initial;
439 441 return (sizeof (uint32_t));
440 442 case TCP_RTO_MIN:
441 443 *i1 = tcp->tcp_rto_min;
442 444 return (sizeof (uint32_t));
443 445 case TCP_RTO_MAX:
444 446 *i1 = tcp->tcp_rto_max;
445 447 return (sizeof (uint32_t));
446 448 case TCP_LINGER2:
447 449 *i1 = tcp->tcp_fin_wait_2_flush_interval / SECONDS;
448 450 return (sizeof (int));
449 451 }
450 452 break;
451 453 case IPPROTO_IP:
452 454 if (connp->conn_family != AF_INET)
453 455 return (-1);
454 456 switch (name) {
455 457 case IP_OPTIONS:
456 458 case T_IP_OPTIONS:
457 459 /* Caller ensures enough space */
458 460 return (ip_opt_get_user(connp, ptr));
459 461 default:
460 462 break;
461 463 }
462 464 break;
463 465
464 466 case IPPROTO_IPV6:
465 467 /*
466 468 * IPPROTO_IPV6 options are only supported for sockets
467 469 * that are using IPv6 on the wire.
468 470 */
469 471 if (connp->conn_ipversion != IPV6_VERSION) {
470 472 return (-1);
471 473 }
472 474 switch (name) {
473 475 case IPV6_PATHMTU:
474 476 if (tcp->tcp_state < TCPS_ESTABLISHED)
475 477 return (-1);
476 478 break;
477 479 }
478 480 break;
479 481 }
480 482 mutex_enter(&connp->conn_lock);
481 483 retval = conn_opt_get(&coas, level, name, ptr);
482 484 mutex_exit(&connp->conn_lock);
483 485 return (retval);
484 486 }
485 487
486 488 /*
487 489 * We declare as 'int' rather than 'void' to satisfy pfi_t arg requirements.
488 490 * Parameters are assumed to be verified by the caller.
489 491 */
490 492 /* ARGSUSED */
491 493 int
492 494 tcp_opt_set(conn_t *connp, uint_t optset_context, int level, int name,
493 495 uint_t inlen, uchar_t *invalp, uint_t *outlenp, uchar_t *outvalp,
494 496 void *thisdg_attrs, cred_t *cr)
495 497 {
496 498 tcp_t *tcp = connp->conn_tcp;
497 499 int *i1 = (int *)invalp;
498 500 boolean_t onoff = (*i1 == 0) ? 0 : 1;
499 501 boolean_t checkonly;
500 502 int reterr;
501 503 tcp_stack_t *tcps = tcp->tcp_tcps;
502 504 conn_opt_arg_t coas;
503 505 uint32_t val = *((uint32_t *)invalp);
504 506
505 507 coas.coa_connp = connp;
506 508 coas.coa_ixa = connp->conn_ixa;
507 509 coas.coa_ipp = &connp->conn_xmit_ipp;
508 510 coas.coa_ancillary = B_FALSE;
509 511 coas.coa_changed = 0;
510 512
511 513 switch (optset_context) {
512 514 case SETFN_OPTCOM_CHECKONLY:
513 515 checkonly = B_TRUE;
514 516 /*
515 517 * Note: Implies T_CHECK semantics for T_OPTCOM_REQ
516 518 * inlen != 0 implies value supplied and
517 519 * we have to "pretend" to set it.
518 520 * inlen == 0 implies that there is no
519 521 * value part in T_CHECK request and just validation
520 522 * done elsewhere should be enough, we just return here.
521 523 */
522 524 if (inlen == 0) {
523 525 *outlenp = 0;
524 526 return (0);
525 527 }
526 528 break;
527 529 case SETFN_OPTCOM_NEGOTIATE:
528 530 checkonly = B_FALSE;
529 531 break;
530 532 case SETFN_UD_NEGOTIATE: /* error on conn-oriented transports ? */
531 533 case SETFN_CONN_NEGOTIATE:
532 534 checkonly = B_FALSE;
533 535 /*
534 536 * Negotiating local and "association-related" options
535 537 * from other (T_CONN_REQ, T_CONN_RES,T_UNITDATA_REQ)
536 538 * primitives is allowed by XTI, but we choose
537 539 * to not implement this style negotiation for Internet
538 540 * protocols (We interpret it is a must for OSI world but
539 541 * optional for Internet protocols) for all options.
540 542 * [ Will do only for the few options that enable test
541 543 * suites that our XTI implementation of this feature
542 544 * works for transports that do allow it ]
543 545 */
544 546 if (!tcp_allow_connopt_set(level, name)) {
545 547 *outlenp = 0;
546 548 return (EINVAL);
547 549 }
548 550 break;
549 551 default:
550 552 /*
551 553 * We should never get here
552 554 */
553 555 *outlenp = 0;
554 556 return (EINVAL);
555 557 }
556 558
557 559 ASSERT((optset_context != SETFN_OPTCOM_CHECKONLY) ||
558 560 (optset_context == SETFN_OPTCOM_CHECKONLY && inlen != 0));
559 561
560 562 /*
561 563 * For TCP, we should have no ancillary data sent down
562 564 * (sendmsg isn't supported for SOCK_STREAM), so thisdg_attrs
563 565 * has to be zero.
564 566 */
565 567 ASSERT(thisdg_attrs == NULL);
566 568
567 569 /*
568 570 * For fixed length options, no sanity check
569 571 * of passed in length is done. It is assumed *_optcom_req()
570 572 * routines do the right thing.
571 573 */
572 574 switch (level) {
573 575 case SOL_SOCKET:
574 576 switch (name) {
575 577 case SO_KEEPALIVE:
576 578 if (checkonly) {
577 579 /* check only case */
578 580 break;
579 581 }
580 582
581 583 if (!onoff) {
582 584 if (connp->conn_keepalive) {
583 585 if (tcp->tcp_ka_tid != 0) {
584 586 (void) TCP_TIMER_CANCEL(tcp,
585 587 tcp->tcp_ka_tid);
586 588 tcp->tcp_ka_tid = 0;
587 589 }
588 590 connp->conn_keepalive = 0;
589 591 }
590 592 break;
591 593 }
592 594 if (!connp->conn_keepalive) {
593 595 /* Crank up the keepalive timer */
594 596 tcp->tcp_ka_last_intrvl = 0;
595 597 tcp->tcp_ka_tid = TCP_TIMER(tcp,
596 598 tcp_keepalive_timer, tcp->tcp_ka_interval);
597 599 connp->conn_keepalive = 1;
598 600 }
599 601 break;
600 602 case SO_SNDBUF: {
601 603 if (*i1 > tcps->tcps_max_buf) {
602 604 *outlenp = 0;
603 605 return (ENOBUFS);
604 606 }
605 607 if (checkonly)
606 608 break;
607 609
608 610 connp->conn_sndbuf = *i1;
609 611 if (tcps->tcps_snd_lowat_fraction != 0) {
610 612 connp->conn_sndlowat = connp->conn_sndbuf /
611 613 tcps->tcps_snd_lowat_fraction;
612 614 }
613 615 (void) tcp_maxpsz_set(tcp, B_TRUE);
614 616 /*
615 617 * If we are flow-controlled, recheck the condition.
616 618 * There are apps that increase SO_SNDBUF size when
617 619 * flow-controlled (EWOULDBLOCK), and expect the flow
618 620 * control condition to be lifted right away.
619 621 */
620 622 mutex_enter(&tcp->tcp_non_sq_lock);
621 623 if (tcp->tcp_flow_stopped &&
622 624 TCP_UNSENT_BYTES(tcp) < connp->conn_sndbuf) {
623 625 tcp_clrqfull(tcp);
624 626 }
625 627 mutex_exit(&tcp->tcp_non_sq_lock);
626 628 *outlenp = inlen;
627 629 return (0);
628 630 }
629 631 case SO_RCVBUF:
630 632 if (*i1 > tcps->tcps_max_buf) {
631 633 *outlenp = 0;
632 634 return (ENOBUFS);
633 635 }
634 636 /* Silently ignore zero */
635 637 if (!checkonly && *i1 != 0) {
636 638 *i1 = MSS_ROUNDUP(*i1, tcp->tcp_mss);
637 639 (void) tcp_rwnd_set(tcp, *i1);
638 640 }
639 641 /*
640 642 * XXX should we return the rwnd here
641 643 * and tcp_opt_get ?
642 644 */
643 645 *outlenp = inlen;
644 646 return (0);
645 647 case SO_SND_COPYAVOID:
646 648 if (!checkonly) {
647 649 if (tcp->tcp_loopback ||
648 650 (onoff != 1) || !tcp_zcopy_check(tcp)) {
649 651 *outlenp = 0;
650 652 return (EOPNOTSUPP);
651 653 }
652 654 tcp->tcp_snd_zcopy_aware = 1;
653 655 }
654 656 *outlenp = inlen;
655 657 return (0);
656 658 }
657 659 break;
658 660 case IPPROTO_TCP:
659 661 switch (name) {
660 662 case TCP_NODELAY:
661 663 if (!checkonly)
662 664 tcp->tcp_naglim = *i1 ? 1 : tcp->tcp_mss;
663 665 break;
664 666 case TCP_NOTIFY_THRESHOLD:
665 667 if (!checkonly)
666 668 tcp->tcp_first_timer_threshold = *i1;
667 669 break;
668 670 case TCP_ABORT_THRESHOLD:
669 671 if (!checkonly)
670 672 tcp->tcp_second_timer_threshold = *i1;
671 673 break;
672 674 case TCP_CONN_NOTIFY_THRESHOLD:
673 675 if (!checkonly)
674 676 tcp->tcp_first_ctimer_threshold = *i1;
675 677 break;
676 678 case TCP_CONN_ABORT_THRESHOLD:
677 679 if (!checkonly)
678 680 tcp->tcp_second_ctimer_threshold = *i1;
679 681 break;
680 682 case TCP_RECVDSTADDR:
681 683 if (tcp->tcp_state > TCPS_LISTEN) {
682 684 *outlenp = 0;
683 685 return (EOPNOTSUPP);
684 686 }
685 687 /* Setting done in conn_opt_set */
686 688 break;
687 689 case TCP_INIT_CWND:
688 690 if (checkonly)
689 691 break;
690 692
691 693 /*
692 694 * Only allow socket with network configuration
693 695 * privilege to set the initial cwnd to be larger
694 696 * than allowed by RFC 3390.
695 697 */
696 698 if (val > MIN(4, MAX(2, 4380 / tcp->tcp_mss))) {
697 699 if ((reterr = secpolicy_ip_config(cr, B_TRUE))
698 700 != 0) {
699 701 *outlenp = 0;
700 702 return (reterr);
701 703 }
702 704 if (val > tcp_max_init_cwnd) {
703 705 *outlenp = 0;
704 706 return (EINVAL);
705 707 }
706 708 }
707 709
708 710 tcp->tcp_init_cwnd = val;
709 711
710 712 /*
711 713 * If the socket is connected, AND no outbound data
712 714 * has been sent, reset the actual cwnd values.
713 715 */
714 716 if (tcp->tcp_state == TCPS_ESTABLISHED &&
715 717 tcp->tcp_iss == tcp->tcp_snxt - 1) {
716 718 tcp->tcp_cwnd =
717 719 MIN(tcp->tcp_rwnd, val * tcp->tcp_mss);
718 720 }
719 721 break;
720 722
721 723 /*
722 724 * TCP_KEEPIDLE is in seconds but TCP_KEEPALIVE_THRESHOLD
723 725 * is in milliseconds. TCP_KEEPIDLE is introduced for
724 726 * compatibility with other Unix flavors.
725 727 * We can fall through TCP_KEEPALIVE_THRESHOLD logic after
726 728 * converting the input to milliseconds.
727 729 */
728 730 case TCP_KEEPIDLE:
729 731 *i1 *= 1000;
730 732 /* FALLTHRU */
731 733
732 734 case TCP_KEEPALIVE_THRESHOLD:
733 735 if (checkonly)
734 736 break;
735 737
736 738 if (*i1 < tcps->tcps_keepalive_interval_low ||
737 739 *i1 > tcps->tcps_keepalive_interval_high) {
738 740 *outlenp = 0;
739 741 return (EINVAL);
740 742 }
741 743 if (*i1 != tcp->tcp_ka_interval) {
742 744 tcp->tcp_ka_interval = *i1;
743 745 /*
744 746 * Check if we need to restart the
745 747 * keepalive timer.
746 748 */
747 749 if (tcp->tcp_ka_tid != 0) {
748 750 ASSERT(connp->conn_keepalive);
749 751 (void) TCP_TIMER_CANCEL(tcp,
750 752 tcp->tcp_ka_tid);
751 753 tcp->tcp_ka_last_intrvl = 0;
752 754 tcp->tcp_ka_tid = TCP_TIMER(tcp,
753 755 tcp_keepalive_timer,
754 756 tcp->tcp_ka_interval);
755 757 }
756 758 }
757 759 break;
758 760
759 761 /*
760 762 * tcp_ka_abort_thres = tcp_ka_rinterval * tcp_ka_cnt.
761 763 * So setting TCP_KEEPCNT or TCP_KEEPINTVL can affect all the
762 764 * three members - tcp_ka_abort_thres, tcp_ka_rinterval and
763 765 * tcp_ka_cnt.
764 766 */
765 767 case TCP_KEEPCNT:
766 768 if (checkonly)
767 769 break;
768 770
769 771 if (*i1 == 0) {
770 772 return (EINVAL);
771 773 } else if (tcp->tcp_ka_rinterval == 0) {
772 774 /*
773 775 * When TCP_KEEPCNT is specified without first
774 776 * specifying a TCP_KEEPINTVL, we infer an
775 777 * interval based on a tunable specific to our
776 778 * stack: the tcp_keepalive_abort_interval.
777 779 * (Or the TCP_KEEPALIVE_ABORT_THRESHOLD, in
778 780 * the unlikely event that that has been set.)
779 781 * Given the abort interval's default value of
780 782 * 480 seconds, low TCP_KEEPCNT values can
781 783 * result in intervals that exceed the default
782 784 * maximum RTO of 60 seconds. Rather than
783 785 * fail in these cases, we (implicitly) clamp
784 786 * the interval at the maximum RTO; if the
785 787 * TCP_KEEPCNT is shortly followed by a
786 788 * TCP_KEEPINTVL (as we expect), the abort
787 789 * threshold will be recalculated correctly --
788 790 * and if a TCP_KEEPINTVL is not forthcoming,
789 791 * keep-alive will at least operate reasonably
790 792 * given the underconfigured state.
791 793 */
792 794 uint32_t interval;
793 795
794 796 interval = tcp->tcp_ka_abort_thres / *i1;
795 797
796 798 if (interval < tcp->tcp_rto_min)
797 799 interval = tcp->tcp_rto_min;
798 800
799 801 if (interval > tcp->tcp_rto_max)
800 802 interval = tcp->tcp_rto_max;
801 803
802 804 tcp->tcp_ka_rinterval = interval;
803 805 } else {
804 806 if ((*i1 * tcp->tcp_ka_rinterval) <
805 807 tcps->tcps_keepalive_abort_interval_low ||
806 808 (*i1 * tcp->tcp_ka_rinterval) >
807 809 tcps->tcps_keepalive_abort_interval_high)
808 810 return (EINVAL);
809 811 tcp->tcp_ka_abort_thres =
810 812 (*i1 * tcp->tcp_ka_rinterval);
811 813 }
812 814 tcp->tcp_ka_cnt = *i1;
813 815 break;
814 816 case TCP_KEEPINTVL:
815 817 /*
816 818 * TCP_KEEPINTVL is specified in seconds, but
817 819 * tcp_ka_rinterval is in milliseconds.
818 820 */
819 821
820 822 if (checkonly)
821 823 break;
822 824
823 825 if ((*i1 * 1000) < tcp->tcp_rto_min ||
824 826 (*i1 * 1000) > tcp->tcp_rto_max)
825 827 return (EINVAL);
826 828
827 829 if (tcp->tcp_ka_cnt == 0) {
828 830 tcp->tcp_ka_cnt =
829 831 tcp->tcp_ka_abort_thres / (*i1 * 1000);
830 832 } else {
831 833 if ((*i1 * tcp->tcp_ka_cnt * 1000) <
832 834 tcps->tcps_keepalive_abort_interval_low ||
833 835 (*i1 * tcp->tcp_ka_cnt * 1000) >
834 836 tcps->tcps_keepalive_abort_interval_high)
835 837 return (EINVAL);
836 838 tcp->tcp_ka_abort_thres =
837 839 (*i1 * tcp->tcp_ka_cnt * 1000);
838 840 }
839 841 tcp->tcp_ka_rinterval = *i1 * 1000;
840 842 break;
841 843 case TCP_KEEPALIVE_ABORT_THRESHOLD:
842 844 if (!checkonly) {
843 845 if (*i1 <
844 846 tcps->tcps_keepalive_abort_interval_low ||
845 847 *i1 >
846 848 tcps->tcps_keepalive_abort_interval_high) {
847 849 *outlenp = 0;
848 850 return (EINVAL);
849 851 }
850 852 tcp->tcp_ka_abort_thres = *i1;
851 853 tcp->tcp_ka_cnt = 0;
852 854 tcp->tcp_ka_rinterval = 0;
853 855 }
854 856 break;
855 857 case TCP_CORK:
856 858 if (!checkonly) {
857 859 /*
858 860 * if tcp->tcp_cork was set and is now
859 861 * being unset, we have to make sure that
860 862 * the remaining data gets sent out. Also
861 863 * unset tcp->tcp_cork so that tcp_wput_data()
↓ open down ↓ |
828 lines elided |
↑ open up ↑ |
862 864 * can send data even if it is less than mss
863 865 */
864 866 if (tcp->tcp_cork && onoff == 0 &&
865 867 tcp->tcp_unsent > 0) {
866 868 tcp->tcp_cork = B_FALSE;
867 869 tcp_wput_data(tcp, NULL, B_FALSE);
868 870 }
869 871 tcp->tcp_cork = onoff;
870 872 }
871 873 break;
872 - case TCP_RTO_INITIAL: {
873 - clock_t rto;
874 -
874 + case TCP_RTO_INITIAL:
875 875 if (checkonly || val == 0)
876 876 break;
877 877
878 878 /*
879 879 * Sanity checks
880 880 *
881 881 * The initial RTO should be bounded by the minimum
882 882 * and maximum RTO. And it should also be smaller
883 883 * than the connect attempt abort timeout. Otherwise,
884 884 * the connection won't be aborted in a period
885 885 * reasonably close to that timeout.
886 886 */
887 887 if (val < tcp->tcp_rto_min || val > tcp->tcp_rto_max ||
888 888 val > tcp->tcp_second_ctimer_threshold ||
889 889 val < tcps->tcps_rexmit_interval_initial_low ||
890 890 val > tcps->tcps_rexmit_interval_initial_high) {
891 891 *outlenp = 0;
892 892 return (EINVAL);
893 893 }
↓ open down ↓ |
9 lines elided |
↑ open up ↑ |
894 894 tcp->tcp_rto_initial = val;
895 895
896 896 /*
897 897 * If TCP has not sent anything, need to re-calculate
898 898 * tcp_rto. Otherwise, this option change does not
899 899 * really affect anything.
900 900 */
901 901 if (tcp->tcp_state >= TCPS_SYN_SENT)
902 902 break;
903 903
904 - tcp->tcp_rtt_sa = tcp->tcp_rto_initial << 2;
905 - tcp->tcp_rtt_sd = tcp->tcp_rto_initial >> 1;
906 - rto = (tcp->tcp_rtt_sa >> 3) + tcp->tcp_rtt_sd +
907 - tcps->tcps_rexmit_interval_extra +
908 - (tcp->tcp_rtt_sa >> 5) +
909 - tcps->tcps_conn_grace_period;
910 - TCP_SET_RTO(tcp, rto);
904 + tcp->tcp_rtt_sa = MSEC2NSEC(tcp->tcp_rto_initial) << 2;
905 + tcp->tcp_rtt_sd = MSEC2NSEC(tcp->tcp_rto_initial) >> 1;
906 + tcp->tcp_rto = tcp_calculate_rto(tcp, tcps,
907 + tcps->tcps_conn_grace_period);
911 908 break;
912 - }
913 909 case TCP_RTO_MIN:
914 910 if (checkonly || val == 0)
915 911 break;
916 912
917 913 if (val < tcps->tcps_rexmit_interval_min_low ||
918 914 val > tcps->tcps_rexmit_interval_min_high ||
919 915 val > tcp->tcp_rto_max) {
920 916 *outlenp = 0;
921 917 return (EINVAL);
922 918 }
923 919 tcp->tcp_rto_min = val;
924 920 if (tcp->tcp_rto < val)
925 921 tcp->tcp_rto = val;
926 922 break;
927 923 case TCP_RTO_MAX:
928 924 if (checkonly || val == 0)
929 925 break;
930 926
931 927 /*
932 928 * Sanity checks
933 929 *
934 930 * The maximum RTO should not be larger than the
935 931 * connection abort timeout. Otherwise, the
936 932 * connection won't be aborted in a period reasonably
937 933 * close to that timeout.
938 934 */
939 935 if (val < tcps->tcps_rexmit_interval_max_low ||
940 936 val > tcps->tcps_rexmit_interval_max_high ||
941 937 val < tcp->tcp_rto_min ||
942 938 val > tcp->tcp_second_timer_threshold) {
943 939 *outlenp = 0;
944 940 return (EINVAL);
945 941 }
946 942 tcp->tcp_rto_max = val;
947 943 if (tcp->tcp_rto > val)
948 944 tcp->tcp_rto = val;
949 945 break;
950 946 case TCP_LINGER2:
951 947 if (checkonly || *i1 == 0)
952 948 break;
953 949
954 950 /*
955 951 * Note that the option value's unit is second. And
956 952 * the value should be bigger than the private
957 953 * parameter tcp_fin_wait_2_flush_interval's lower
958 954 * bound and smaller than the current value of that
959 955 * parameter. It should be smaller than the current
960 956 * value to avoid an app setting TCP_LINGER2 to a big
961 957 * value, causing resource to be held up too long in
962 958 * FIN-WAIT-2 state.
963 959 */
964 960 if (*i1 < 0 ||
965 961 tcps->tcps_fin_wait_2_flush_interval_low/SECONDS >
966 962 *i1 ||
967 963 tcps->tcps_fin_wait_2_flush_interval/SECONDS <
968 964 *i1) {
969 965 *outlenp = 0;
970 966 return (EINVAL);
971 967 }
972 968 tcp->tcp_fin_wait_2_flush_interval = *i1 * SECONDS;
973 969 break;
974 970 default:
975 971 break;
976 972 }
977 973 break;
978 974 case IPPROTO_IP:
979 975 if (connp->conn_family != AF_INET) {
980 976 *outlenp = 0;
981 977 return (EINVAL);
982 978 }
983 979 switch (name) {
984 980 case IP_SEC_OPT:
985 981 /*
986 982 * We should not allow policy setting after
987 983 * we start listening for connections.
988 984 */
989 985 if (tcp->tcp_state == TCPS_LISTEN) {
990 986 return (EINVAL);
991 987 }
992 988 break;
993 989 }
994 990 break;
995 991 case IPPROTO_IPV6:
996 992 /*
997 993 * IPPROTO_IPV6 options are only supported for sockets
998 994 * that are using IPv6 on the wire.
999 995 */
1000 996 if (connp->conn_ipversion != IPV6_VERSION) {
1001 997 *outlenp = 0;
1002 998 return (EINVAL);
1003 999 }
1004 1000
1005 1001 switch (name) {
1006 1002 case IPV6_RECVPKTINFO:
1007 1003 if (!checkonly) {
1008 1004 /* Force it to be sent up with the next msg */
1009 1005 tcp->tcp_recvifindex = 0;
1010 1006 }
1011 1007 break;
1012 1008 case IPV6_RECVTCLASS:
1013 1009 if (!checkonly) {
1014 1010 /* Force it to be sent up with the next msg */
1015 1011 tcp->tcp_recvtclass = 0xffffffffU;
1016 1012 }
1017 1013 break;
1018 1014 case IPV6_RECVHOPLIMIT:
1019 1015 if (!checkonly) {
1020 1016 /* Force it to be sent up with the next msg */
1021 1017 tcp->tcp_recvhops = 0xffffffffU;
1022 1018 }
1023 1019 break;
1024 1020 case IPV6_PKTINFO:
1025 1021 /* This is an extra check for TCP */
1026 1022 if (inlen == sizeof (struct in6_pktinfo)) {
1027 1023 struct in6_pktinfo *pkti;
1028 1024
1029 1025 pkti = (struct in6_pktinfo *)invalp;
1030 1026 /*
1031 1027 * RFC 3542 states that ipi6_addr must be
1032 1028 * the unspecified address when setting the
1033 1029 * IPV6_PKTINFO sticky socket option on a
1034 1030 * TCP socket.
1035 1031 */
1036 1032 if (!IN6_IS_ADDR_UNSPECIFIED(&pkti->ipi6_addr))
1037 1033 return (EINVAL);
1038 1034 }
1039 1035 break;
1040 1036 case IPV6_SEC_OPT:
1041 1037 /*
1042 1038 * We should not allow policy setting after
1043 1039 * we start listening for connections.
1044 1040 */
1045 1041 if (tcp->tcp_state == TCPS_LISTEN) {
1046 1042 return (EINVAL);
1047 1043 }
1048 1044 break;
1049 1045 }
1050 1046 break;
1051 1047 }
1052 1048 reterr = conn_opt_set(&coas, level, name, inlen, invalp,
1053 1049 checkonly, cr);
1054 1050 if (reterr != 0) {
1055 1051 *outlenp = 0;
1056 1052 return (reterr);
1057 1053 }
1058 1054
1059 1055 /*
1060 1056 * Common case of OK return with outval same as inval
1061 1057 */
1062 1058 if (invalp != outvalp) {
1063 1059 /* don't trust bcopy for identical src/dst */
1064 1060 (void) bcopy(invalp, outvalp, inlen);
1065 1061 }
1066 1062 *outlenp = inlen;
1067 1063
1068 1064 if (coas.coa_changed & COA_HEADER_CHANGED) {
1069 1065 /* If we are connected we rebuilt the headers */
1070 1066 if (!IN6_IS_ADDR_UNSPECIFIED(&connp->conn_faddr_v6) &&
1071 1067 !IN6_IS_ADDR_V4MAPPED_ANY(&connp->conn_faddr_v6)) {
1072 1068 reterr = tcp_build_hdrs(tcp);
1073 1069 if (reterr != 0)
1074 1070 return (reterr);
1075 1071 }
1076 1072 }
1077 1073 if (coas.coa_changed & COA_ROUTE_CHANGED) {
1078 1074 in6_addr_t nexthop;
1079 1075
1080 1076 /*
1081 1077 * If we are connected we re-cache the information.
1082 1078 * We ignore errors to preserve BSD behavior.
1083 1079 * Note that we don't redo IPsec policy lookup here
1084 1080 * since the final destination (or source) didn't change.
1085 1081 */
1086 1082 ip_attr_nexthop(&connp->conn_xmit_ipp, connp->conn_ixa,
1087 1083 &connp->conn_faddr_v6, &nexthop);
1088 1084
1089 1085 if (!IN6_IS_ADDR_UNSPECIFIED(&connp->conn_faddr_v6) &&
1090 1086 !IN6_IS_ADDR_V4MAPPED_ANY(&connp->conn_faddr_v6)) {
1091 1087 (void) ip_attr_connect(connp, connp->conn_ixa,
1092 1088 &connp->conn_laddr_v6, &connp->conn_faddr_v6,
1093 1089 &nexthop, connp->conn_fport, NULL, NULL,
1094 1090 IPDF_VERIFY_DST);
1095 1091 }
1096 1092 }
1097 1093 if ((coas.coa_changed & COA_SNDBUF_CHANGED) && !IPCL_IS_NONSTR(connp)) {
1098 1094 connp->conn_wq->q_hiwat = connp->conn_sndbuf;
1099 1095 }
1100 1096 if (coas.coa_changed & COA_WROFF_CHANGED) {
1101 1097 connp->conn_wroff = connp->conn_ht_iphc_allocated +
1102 1098 tcps->tcps_wroff_xtra;
1103 1099 (void) proto_set_tx_wroff(connp->conn_rq, connp,
1104 1100 connp->conn_wroff);
1105 1101 }
1106 1102 if (coas.coa_changed & COA_OOBINLINE_CHANGED) {
1107 1103 if (IPCL_IS_NONSTR(connp))
1108 1104 proto_set_rx_oob_opt(connp, onoff);
1109 1105 }
1110 1106 return (0);
1111 1107 }
↓ open down ↓ |
189 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX