Print this page
tcp: maybe related to 721fffe3
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/inet/tcp/tcp_socket.c
+++ new/usr/src/uts/common/inet/tcp/tcp_socket.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
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 /*
23 23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 26 /* This file contains all TCP kernel socket related functions. */
27 27
28 28 #include <sys/types.h>
29 29 #include <sys/strlog.h>
30 30 #include <sys/policy.h>
31 31 #include <sys/sockio.h>
32 32 #include <sys/strsubr.h>
33 33 #include <sys/strsun.h>
34 34 #include <sys/squeue_impl.h>
35 35 #include <sys/squeue.h>
36 36 #define _SUN_TPI_VERSION 2
37 37 #include <sys/tihdr.h>
38 38 #include <sys/timod.h>
39 39 #include <sys/tpicommon.h>
40 40 #include <sys/socketvar.h>
41 41
42 42 #include <inet/common.h>
43 43 #include <inet/proto_set.h>
44 44 #include <inet/ip.h>
45 45 #include <inet/tcp.h>
46 46 #include <inet/tcp_impl.h>
↓ open down ↓ |
46 lines elided |
↑ open up ↑ |
47 47
48 48 static void tcp_activate(sock_lower_handle_t, sock_upper_handle_t,
49 49 sock_upcalls_t *, int, cred_t *);
50 50 static int tcp_accept(sock_lower_handle_t, sock_lower_handle_t,
51 51 sock_upper_handle_t, cred_t *);
52 52 static int tcp_bind(sock_lower_handle_t, struct sockaddr *,
53 53 socklen_t, cred_t *);
54 54 static int tcp_listen(sock_lower_handle_t, int, cred_t *);
55 55 static int tcp_connect(sock_lower_handle_t, const struct sockaddr *,
56 56 socklen_t, sock_connid_t *, cred_t *);
57 +static int tcp_getpeername(sock_lower_handle_t, struct sockaddr *,
58 + socklen_t *, cred_t *);
59 +static int tcp_getsockname(sock_lower_handle_t, struct sockaddr *,
60 + socklen_t *, cred_t *);
57 61 static int tcp_getsockopt(sock_lower_handle_t, int, int, void *,
58 62 socklen_t *, cred_t *);
59 63 static int tcp_setsockopt(sock_lower_handle_t, int, int, const void *,
60 64 socklen_t, cred_t *);
61 65 static int tcp_sendmsg(sock_lower_handle_t, mblk_t *, struct nmsghdr *,
62 - cred_t *cr);
66 + cred_t *);
63 67 static int tcp_shutdown(sock_lower_handle_t, int, cred_t *);
64 68 static void tcp_clr_flowctrl(sock_lower_handle_t);
65 69 static int tcp_ioctl(sock_lower_handle_t, int, intptr_t, int, int32_t *,
66 70 cred_t *);
67 71 static int tcp_close(sock_lower_handle_t, int, cred_t *);
68 72
69 73 sock_downcalls_t sock_tcp_downcalls = {
70 74 tcp_activate,
71 75 tcp_accept,
72 76 tcp_bind,
73 77 tcp_listen,
74 78 tcp_connect,
75 79 tcp_getpeername,
76 80 tcp_getsockname,
77 81 tcp_getsockopt,
78 82 tcp_setsockopt,
79 83 tcp_sendmsg,
80 84 NULL,
81 85 NULL,
82 86 NULL,
83 87 tcp_shutdown,
84 88 tcp_clr_flowctrl,
85 89 tcp_ioctl,
86 90 tcp_close,
87 91 };
88 92
89 93 /* ARGSUSED */
90 94 static void
91 95 tcp_activate(sock_lower_handle_t proto_handle, sock_upper_handle_t sock_handle,
92 96 sock_upcalls_t *sock_upcalls, int flags, cred_t *cr)
93 97 {
94 98 conn_t *connp = (conn_t *)proto_handle;
95 99 struct sock_proto_props sopp;
96 100 extern struct module_info tcp_rinfo;
97 101
98 102 ASSERT(connp->conn_upper_handle == NULL);
99 103
100 104 /* All Solaris components should pass a cred for this operation. */
101 105 ASSERT(cr != NULL);
102 106
103 107 sopp.sopp_flags = SOCKOPT_RCVHIWAT | SOCKOPT_RCVLOWAT |
104 108 SOCKOPT_MAXPSZ | SOCKOPT_MAXBLK | SOCKOPT_RCVTIMER |
105 109 SOCKOPT_RCVTHRESH | SOCKOPT_MAXADDRLEN | SOCKOPT_MINPSZ;
106 110
107 111 sopp.sopp_rxhiwat = SOCKET_RECVHIWATER;
108 112 sopp.sopp_rxlowat = SOCKET_RECVLOWATER;
109 113 sopp.sopp_maxpsz = INFPSZ;
110 114 sopp.sopp_maxblk = INFPSZ;
111 115 sopp.sopp_rcvtimer = SOCKET_TIMER_INTERVAL;
112 116 sopp.sopp_rcvthresh = SOCKET_RECVHIWATER >> 3;
113 117 sopp.sopp_maxaddrlen = sizeof (sin6_t);
114 118 sopp.sopp_minpsz = (tcp_rinfo.mi_minpsz == 1) ? 0 :
115 119 tcp_rinfo.mi_minpsz;
116 120
117 121 connp->conn_upcalls = sock_upcalls;
118 122 connp->conn_upper_handle = sock_handle;
119 123
120 124 ASSERT(connp->conn_rcvbuf != 0 &&
121 125 connp->conn_rcvbuf == connp->conn_tcp->tcp_rwnd);
122 126 (*sock_upcalls->su_set_proto_props)(sock_handle, &sopp);
123 127 }
124 128
125 129 /*ARGSUSED*/
126 130 static int
127 131 tcp_accept(sock_lower_handle_t lproto_handle,
128 132 sock_lower_handle_t eproto_handle, sock_upper_handle_t sock_handle,
129 133 cred_t *cr)
130 134 {
131 135 conn_t *lconnp, *econnp;
132 136 tcp_t *listener, *eager;
133 137
134 138 /*
135 139 * KSSL can move a socket from one listener to another, in which
136 140 * case `lproto_handle' points to the new listener. To ensure that
137 141 * the original listener is used the information is obtained from
138 142 * the eager.
139 143 */
140 144 econnp = (conn_t *)eproto_handle;
141 145 eager = econnp->conn_tcp;
142 146 ASSERT(IPCL_IS_NONSTR(econnp));
143 147 ASSERT(eager->tcp_listener != NULL);
144 148 listener = eager->tcp_listener;
145 149 lconnp = (conn_t *)listener->tcp_connp;
146 150 ASSERT(listener->tcp_state == TCPS_LISTEN);
147 151 ASSERT(lconnp->conn_upper_handle != NULL);
148 152
149 153 /*
150 154 * It is possible for the accept thread to race with the thread that
151 155 * made the su_newconn upcall in tcp_newconn_notify. Both
152 156 * tcp_newconn_notify and tcp_accept require that conn_upper_handle
153 157 * and conn_upcalls be set before returning, so they both write to
154 158 * them. However, we're guaranteed that the value written is the same
155 159 * for both threads.
156 160 */
157 161 ASSERT(econnp->conn_upper_handle == NULL ||
158 162 econnp->conn_upper_handle == sock_handle);
159 163 ASSERT(econnp->conn_upcalls == NULL ||
160 164 econnp->conn_upcalls == lconnp->conn_upcalls);
161 165 econnp->conn_upper_handle = sock_handle;
162 166 econnp->conn_upcalls = lconnp->conn_upcalls;
163 167
164 168 ASSERT(econnp->conn_netstack ==
165 169 listener->tcp_connp->conn_netstack);
166 170 ASSERT(eager->tcp_tcps == listener->tcp_tcps);
167 171
168 172 /*
169 173 * We should have a minimum of 2 references on the conn at this
170 174 * point. One for TCP and one for the newconn notification
171 175 * (which is now taken over by IP). In the normal case we would
172 176 * also have another reference (making a total of 3) for the conn
173 177 * being in the classifier hash list. However the eager could have
174 178 * received an RST subsequently and tcp_closei_local could have
175 179 * removed the eager from the classifier hash list, hence we can't
176 180 * assert that reference.
177 181 */
178 182 ASSERT(econnp->conn_ref >= 2);
179 183
180 184 mutex_enter(&listener->tcp_eager_lock);
181 185 /*
182 186 * Non-STREAMS listeners never defer the notification of new
183 187 * connections.
184 188 */
185 189 ASSERT(!listener->tcp_eager_prev_q0->tcp_conn_def_q0);
186 190 tcp_eager_unlink(eager);
187 191 mutex_exit(&listener->tcp_eager_lock);
188 192 CONN_DEC_REF(listener->tcp_connp);
189 193
190 194 return ((eager->tcp_state < TCPS_ESTABLISHED) ? ECONNABORTED : 0);
191 195 }
192 196
193 197 static int
194 198 tcp_bind(sock_lower_handle_t proto_handle, struct sockaddr *sa,
195 199 socklen_t len, cred_t *cr)
196 200 {
197 201 int error;
198 202 conn_t *connp = (conn_t *)proto_handle;
199 203
200 204 /* All Solaris components should pass a cred for this operation. */
201 205 ASSERT(cr != NULL);
202 206 ASSERT(connp->conn_upper_handle != NULL);
203 207
204 208 error = squeue_synch_enter(connp, NULL);
205 209 if (error != 0) {
206 210 /* failed to enter */
207 211 return (ENOSR);
208 212 }
209 213
210 214 /* binding to a NULL address really means unbind */
211 215 if (sa == NULL) {
212 216 if (connp->conn_tcp->tcp_state < TCPS_LISTEN)
213 217 error = tcp_do_unbind(connp);
214 218 else
215 219 error = EINVAL;
216 220 } else {
217 221 error = tcp_do_bind(connp, sa, len, cr, B_TRUE);
218 222 }
219 223
220 224 squeue_synch_exit(connp);
221 225
222 226 if (error < 0) {
223 227 if (error == -TOUTSTATE)
224 228 error = EINVAL;
225 229 else
226 230 error = proto_tlitosyserr(-error);
227 231 }
228 232
229 233 return (error);
230 234 }
231 235
232 236 /* ARGSUSED */
233 237 static int
234 238 tcp_listen(sock_lower_handle_t proto_handle, int backlog, cred_t *cr)
235 239 {
236 240 conn_t *connp = (conn_t *)proto_handle;
237 241 tcp_t *tcp = connp->conn_tcp;
238 242 int error;
239 243
240 244 ASSERT(connp->conn_upper_handle != NULL);
241 245
242 246 /* All Solaris components should pass a cred for this operation. */
243 247 ASSERT(cr != NULL);
244 248
245 249 error = squeue_synch_enter(connp, NULL);
246 250 if (error != 0) {
247 251 /* failed to enter */
248 252 return (ENOBUFS);
249 253 }
250 254
251 255 error = tcp_do_listen(connp, NULL, 0, backlog, cr, B_FALSE);
252 256 if (error == 0) {
253 257 /*
254 258 * sockfs needs to know what's the maximum number of socket
255 259 * that can be queued on the listener.
256 260 */
257 261 (*connp->conn_upcalls->su_opctl)(connp->conn_upper_handle,
258 262 SOCK_OPCTL_ENAB_ACCEPT,
259 263 (uintptr_t)(tcp->tcp_conn_req_max +
260 264 tcp->tcp_tcps->tcps_conn_req_max_q0));
261 265 } else if (error < 0) {
262 266 if (error == -TOUTSTATE)
263 267 error = EINVAL;
264 268 else
265 269 error = proto_tlitosyserr(-error);
266 270 }
267 271 squeue_synch_exit(connp);
268 272 return (error);
269 273 }
270 274
271 275 static int
272 276 tcp_connect(sock_lower_handle_t proto_handle, const struct sockaddr *sa,
273 277 socklen_t len, sock_connid_t *id, cred_t *cr)
274 278 {
275 279 conn_t *connp = (conn_t *)proto_handle;
276 280 int error;
277 281
278 282 ASSERT(connp->conn_upper_handle != NULL);
279 283
280 284 /* All Solaris components should pass a cred for this operation. */
281 285 ASSERT(cr != NULL);
282 286
283 287 error = proto_verify_ip_addr(connp->conn_family, sa, len);
284 288 if (error != 0) {
285 289 return (error);
286 290 }
287 291
288 292 error = squeue_synch_enter(connp, NULL);
289 293 if (error != 0) {
290 294 /* failed to enter */
291 295 return (ENOSR);
292 296 }
293 297
294 298 /*
295 299 * TCP supports quick connect, so no need to do an implicit bind
296 300 */
297 301 error = tcp_do_connect(connp, sa, len, cr, curproc->p_pid);
298 302 if (error == 0) {
299 303 *id = connp->conn_tcp->tcp_connid;
300 304 } else if (error < 0) {
301 305 if (error == -TOUTSTATE) {
302 306 switch (connp->conn_tcp->tcp_state) {
303 307 case TCPS_SYN_SENT:
304 308 error = EALREADY;
305 309 break;
306 310 case TCPS_ESTABLISHED:
307 311 error = EISCONN;
308 312 break;
309 313 case TCPS_LISTEN:
310 314 error = EOPNOTSUPP;
311 315 break;
312 316 default:
313 317 error = EINVAL;
314 318 break;
315 319 }
316 320 } else {
317 321 error = proto_tlitosyserr(-error);
318 322 }
319 323 }
320 324
321 325 if (connp->conn_tcp->tcp_loopback) {
322 326 struct sock_proto_props sopp;
323 327
324 328 sopp.sopp_flags = SOCKOPT_LOOPBACK;
325 329 sopp.sopp_loopback = B_TRUE;
326 330
327 331 (*connp->conn_upcalls->su_set_proto_props)(
328 332 connp->conn_upper_handle, &sopp);
329 333 }
330 334 done:
331 335 squeue_synch_exit(connp);
332 336
333 337 return ((error == 0) ? EINPROGRESS : error);
334 338 }
335 339
336 340 /* ARGSUSED3 */
337 341 int
338 342 tcp_getpeername(sock_lower_handle_t proto_handle, struct sockaddr *addr,
339 343 socklen_t *addrlenp, cred_t *cr)
340 344 {
341 345 conn_t *connp = (conn_t *)proto_handle;
342 346 tcp_t *tcp = connp->conn_tcp;
343 347
344 348 /* All Solaris components should pass a cred for this operation. */
345 349 ASSERT(cr != NULL);
346 350
347 351 ASSERT(tcp != NULL);
348 352 if (tcp->tcp_state < TCPS_SYN_RCVD)
349 353 return (ENOTCONN);
350 354
351 355 return (conn_getpeername(connp, addr, addrlenp));
352 356 }
353 357
354 358 /* ARGSUSED3 */
355 359 int
356 360 tcp_getsockname(sock_lower_handle_t proto_handle, struct sockaddr *addr,
357 361 socklen_t *addrlenp, cred_t *cr)
358 362 {
359 363 conn_t *connp = (conn_t *)proto_handle;
360 364
361 365 /* All Solaris components should pass a cred for this operation. */
362 366 ASSERT(cr != NULL);
363 367
364 368 return (conn_getsockname(connp, addr, addrlenp));
365 369 }
366 370
367 371 /* returns UNIX error, the optlen is a value-result arg */
368 372 static int
369 373 tcp_getsockopt(sock_lower_handle_t proto_handle, int level, int option_name,
370 374 void *optvalp, socklen_t *optlen, cred_t *cr)
371 375 {
372 376 conn_t *connp = (conn_t *)proto_handle;
373 377 int error;
374 378 t_uscalar_t max_optbuf_len;
375 379 void *optvalp_buf;
376 380 int len;
377 381
378 382 ASSERT(connp->conn_upper_handle != NULL);
379 383
380 384 error = proto_opt_check(level, option_name, *optlen, &max_optbuf_len,
381 385 tcp_opt_obj.odb_opt_des_arr,
382 386 tcp_opt_obj.odb_opt_arr_cnt,
383 387 B_FALSE, B_TRUE, cr);
384 388 if (error != 0) {
385 389 if (error < 0) {
386 390 error = proto_tlitosyserr(-error);
387 391 }
388 392 return (error);
389 393 }
390 394
391 395 optvalp_buf = kmem_alloc(max_optbuf_len, KM_SLEEP);
392 396
393 397 error = squeue_synch_enter(connp, NULL);
394 398 if (error == ENOMEM) {
395 399 kmem_free(optvalp_buf, max_optbuf_len);
396 400 return (ENOMEM);
397 401 }
398 402
399 403 len = tcp_opt_get(connp, level, option_name, optvalp_buf);
400 404 squeue_synch_exit(connp);
401 405
402 406 if (len == -1) {
403 407 kmem_free(optvalp_buf, max_optbuf_len);
404 408 return (EINVAL);
405 409 }
406 410
407 411 /*
408 412 * update optlen and copy option value
409 413 */
410 414 t_uscalar_t size = MIN(len, *optlen);
411 415
412 416 bcopy(optvalp_buf, optvalp, size);
413 417 bcopy(&size, optlen, sizeof (size));
414 418
415 419 kmem_free(optvalp_buf, max_optbuf_len);
416 420 return (0);
417 421 }
418 422
419 423 static int
420 424 tcp_setsockopt(sock_lower_handle_t proto_handle, int level, int option_name,
421 425 const void *optvalp, socklen_t optlen, cred_t *cr)
422 426 {
423 427 conn_t *connp = (conn_t *)proto_handle;
424 428 int error;
425 429
426 430 ASSERT(connp->conn_upper_handle != NULL);
427 431 /*
428 432 * Entering the squeue synchronously can result in a context switch,
429 433 * which can cause a rather sever performance degradation. So we try to
430 434 * handle whatever options we can without entering the squeue.
431 435 */
432 436 if (level == IPPROTO_TCP) {
433 437 switch (option_name) {
434 438 case TCP_NODELAY:
435 439 if (optlen != sizeof (int32_t))
436 440 return (EINVAL);
437 441 mutex_enter(&connp->conn_tcp->tcp_non_sq_lock);
438 442 connp->conn_tcp->tcp_naglim = *(int *)optvalp ? 1 :
439 443 connp->conn_tcp->tcp_mss;
440 444 mutex_exit(&connp->conn_tcp->tcp_non_sq_lock);
441 445 return (0);
442 446 default:
443 447 break;
444 448 }
445 449 }
446 450
447 451 error = squeue_synch_enter(connp, NULL);
448 452 if (error == ENOMEM) {
449 453 return (ENOMEM);
450 454 }
451 455
452 456 error = proto_opt_check(level, option_name, optlen, NULL,
453 457 tcp_opt_obj.odb_opt_des_arr,
454 458 tcp_opt_obj.odb_opt_arr_cnt,
455 459 B_TRUE, B_FALSE, cr);
456 460
457 461 if (error != 0) {
458 462 if (error < 0) {
459 463 error = proto_tlitosyserr(-error);
460 464 }
461 465 squeue_synch_exit(connp);
462 466 return (error);
463 467 }
464 468
465 469 error = tcp_opt_set(connp, SETFN_OPTCOM_NEGOTIATE, level, option_name,
466 470 optlen, (uchar_t *)optvalp, (uint_t *)&optlen, (uchar_t *)optvalp,
467 471 NULL, cr);
468 472 squeue_synch_exit(connp);
469 473
470 474 ASSERT(error >= 0);
471 475
472 476 return (error);
473 477 }
474 478
475 479 /* ARGSUSED */
476 480 static int
477 481 tcp_sendmsg(sock_lower_handle_t proto_handle, mblk_t *mp, struct nmsghdr *msg,
478 482 cred_t *cr)
479 483 {
480 484 tcp_t *tcp;
481 485 uint32_t msize;
482 486 conn_t *connp = (conn_t *)proto_handle;
483 487 int32_t tcpstate;
484 488
485 489 /* All Solaris components should pass a cred for this operation. */
486 490 ASSERT(cr != NULL);
487 491
488 492 ASSERT(connp->conn_ref >= 2);
489 493 ASSERT(connp->conn_upper_handle != NULL);
490 494
491 495 if (msg->msg_controllen != 0) {
492 496 freemsg(mp);
493 497 return (EOPNOTSUPP);
494 498 }
495 499
496 500 switch (DB_TYPE(mp)) {
497 501 case M_DATA:
498 502 tcp = connp->conn_tcp;
499 503 ASSERT(tcp != NULL);
500 504
501 505 tcpstate = tcp->tcp_state;
502 506 if (tcpstate < TCPS_ESTABLISHED) {
503 507 freemsg(mp);
504 508 /*
505 509 * We return ENOTCONN if the endpoint is trying to
506 510 * connect or has never been connected, and EPIPE if it
507 511 * has been disconnected. The connection id helps us
508 512 * distinguish between the last two cases.
509 513 */
510 514 return ((tcpstate == TCPS_SYN_SENT) ? ENOTCONN :
511 515 ((tcp->tcp_connid > 0) ? EPIPE : ENOTCONN));
512 516 } else if (tcpstate > TCPS_CLOSE_WAIT) {
513 517 freemsg(mp);
514 518 return (EPIPE);
515 519 }
516 520
517 521 msize = msgdsize(mp);
518 522
519 523 mutex_enter(&tcp->tcp_non_sq_lock);
520 524 tcp->tcp_squeue_bytes += msize;
521 525 /*
522 526 * Squeue Flow Control
523 527 */
524 528 if (TCP_UNSENT_BYTES(tcp) > connp->conn_sndbuf) {
525 529 tcp_setqfull(tcp);
526 530 }
527 531 mutex_exit(&tcp->tcp_non_sq_lock);
528 532
529 533 /*
530 534 * The application may pass in an address in the msghdr, but
531 535 * we ignore the address on connection-oriented sockets.
532 536 * Just like BSD this code does not generate an error for
533 537 * TCP (a CONNREQUIRED socket) when sending to an address
534 538 * passed in with sendto/sendmsg. Instead the data is
535 539 * delivered on the connection as if no address had been
536 540 * supplied.
537 541 */
538 542 CONN_INC_REF(connp);
539 543
540 544 if (msg->msg_flags & MSG_OOB) {
541 545 SQUEUE_ENTER_ONE(connp->conn_sqp, mp, tcp_output_urgent,
542 546 connp, NULL, tcp_squeue_flag, SQTAG_TCP_OUTPUT);
543 547 } else {
544 548 SQUEUE_ENTER_ONE(connp->conn_sqp, mp, tcp_output,
545 549 connp, NULL, tcp_squeue_flag, SQTAG_TCP_OUTPUT);
546 550 }
547 551
548 552 return (0);
549 553
550 554 default:
551 555 ASSERT(0);
552 556 }
553 557
554 558 freemsg(mp);
555 559 return (0);
556 560 }
557 561
558 562 /* ARGSUSED */
559 563 static int
560 564 tcp_shutdown(sock_lower_handle_t proto_handle, int how, cred_t *cr)
561 565 {
562 566 conn_t *connp = (conn_t *)proto_handle;
563 567 tcp_t *tcp = connp->conn_tcp;
564 568
565 569 ASSERT(connp->conn_upper_handle != NULL);
566 570
567 571 /* All Solaris components should pass a cred for this operation. */
568 572 ASSERT(cr != NULL);
569 573
570 574 /*
571 575 * X/Open requires that we check the connected state.
572 576 */
573 577 if (tcp->tcp_state < TCPS_SYN_SENT)
574 578 return (ENOTCONN);
575 579
576 580 /* shutdown the send side */
577 581 if (how != SHUT_RD) {
578 582 mblk_t *bp;
579 583
580 584 bp = allocb_wait(0, BPRI_HI, STR_NOSIG, NULL);
581 585 CONN_INC_REF(connp);
582 586 SQUEUE_ENTER_ONE(connp->conn_sqp, bp, tcp_shutdown_output,
583 587 connp, NULL, SQ_NODRAIN, SQTAG_TCP_SHUTDOWN_OUTPUT);
584 588
585 589 (*connp->conn_upcalls->su_opctl)(connp->conn_upper_handle,
586 590 SOCK_OPCTL_SHUT_SEND, 0);
587 591 }
588 592
589 593 /* shutdown the recv side */
590 594 if (how != SHUT_WR)
591 595 (*connp->conn_upcalls->su_opctl)(connp->conn_upper_handle,
592 596 SOCK_OPCTL_SHUT_RECV, 0);
593 597
594 598 return (0);
595 599 }
596 600
597 601 static void
598 602 tcp_clr_flowctrl(sock_lower_handle_t proto_handle)
599 603 {
600 604 conn_t *connp = (conn_t *)proto_handle;
601 605 tcp_t *tcp = connp->conn_tcp;
602 606 mblk_t *mp;
603 607 int error;
604 608
605 609 ASSERT(connp->conn_upper_handle != NULL);
606 610
607 611 /*
608 612 * If tcp->tcp_rsrv_mp == NULL, it means that tcp_clr_flowctrl()
609 613 * is currently running.
610 614 */
611 615 mutex_enter(&tcp->tcp_rsrv_mp_lock);
612 616 if ((mp = tcp->tcp_rsrv_mp) == NULL) {
613 617 mutex_exit(&tcp->tcp_rsrv_mp_lock);
614 618 return;
615 619 }
616 620 tcp->tcp_rsrv_mp = NULL;
617 621 mutex_exit(&tcp->tcp_rsrv_mp_lock);
618 622
619 623 error = squeue_synch_enter(connp, mp);
620 624 ASSERT(error == 0);
621 625
622 626 mutex_enter(&tcp->tcp_rsrv_mp_lock);
623 627 tcp->tcp_rsrv_mp = mp;
624 628 mutex_exit(&tcp->tcp_rsrv_mp_lock);
625 629
626 630 if (tcp->tcp_fused) {
627 631 tcp_fuse_backenable(tcp);
628 632 } else {
629 633 tcp->tcp_rwnd = connp->conn_rcvbuf;
630 634 /*
631 635 * Send back a window update immediately if TCP is above
632 636 * ESTABLISHED state and the increase of the rcv window
633 637 * that the other side knows is at least 1 MSS after flow
634 638 * control is lifted.
635 639 */
636 640 if (tcp->tcp_state >= TCPS_ESTABLISHED &&
637 641 tcp_rwnd_reopen(tcp) == TH_ACK_NEEDED) {
638 642 tcp_xmit_ctl(NULL, tcp,
639 643 (tcp->tcp_swnd == 0) ? tcp->tcp_suna :
640 644 tcp->tcp_snxt, tcp->tcp_rnxt, TH_ACK);
641 645 }
642 646 }
643 647
644 648 squeue_synch_exit(connp);
645 649 }
646 650
647 651 /* ARGSUSED */
648 652 static int
649 653 tcp_ioctl(sock_lower_handle_t proto_handle, int cmd, intptr_t arg,
650 654 int mode, int32_t *rvalp, cred_t *cr)
651 655 {
652 656 conn_t *connp = (conn_t *)proto_handle;
653 657 int error;
654 658
655 659 ASSERT(connp->conn_upper_handle != NULL);
656 660
657 661 /* All Solaris components should pass a cred for this operation. */
658 662 ASSERT(cr != NULL);
659 663
660 664 /*
661 665 * If we don't have a helper stream then create one.
662 666 * ip_create_helper_stream takes care of locking the conn_t,
663 667 * so this check for NULL is just a performance optimization.
664 668 */
665 669 if (connp->conn_helper_info == NULL) {
666 670 tcp_stack_t *tcps = connp->conn_tcp->tcp_tcps;
667 671
668 672 /*
669 673 * Create a helper stream for non-STREAMS socket.
670 674 */
671 675 error = ip_create_helper_stream(connp, tcps->tcps_ldi_ident);
672 676 if (error != 0) {
673 677 ip0dbg(("tcp_ioctl: create of IP helper stream "
674 678 "failed %d\n", error));
675 679 return (error);
676 680 }
677 681 }
678 682
679 683 switch (cmd) {
680 684 case ND_SET:
681 685 case ND_GET:
682 686 case _SIOCSOCKFALLBACK:
683 687 case TCP_IOC_ABORT_CONN:
684 688 case TI_GETPEERNAME:
685 689 case TI_GETMYNAME:
686 690 ip1dbg(("tcp_ioctl: cmd 0x%x on non streams socket",
687 691 cmd));
688 692 error = EINVAL;
689 693 break;
690 694 default:
691 695 /*
692 696 * If the conn is not closing, pass on to IP using
693 697 * helper stream. Bump the ioctlref to prevent tcp_close
694 698 * from closing the rq/wq out from underneath the ioctl
695 699 * if it ends up queued or aborted/interrupted.
696 700 */
697 701 mutex_enter(&connp->conn_lock);
698 702 if (connp->conn_state_flags & (CONN_CLOSING)) {
699 703 mutex_exit(&connp->conn_lock);
700 704 error = EINVAL;
701 705 break;
702 706 }
703 707 CONN_INC_IOCTLREF_LOCKED(connp);
704 708 error = ldi_ioctl(connp->conn_helper_info->iphs_handle,
705 709 cmd, arg, mode, cr, rvalp);
706 710 CONN_DEC_IOCTLREF(connp);
707 711 break;
708 712 }
709 713 return (error);
710 714 }
711 715
712 716 /* ARGSUSED */
713 717 static int
714 718 tcp_close(sock_lower_handle_t proto_handle, int flags, cred_t *cr)
715 719 {
716 720 conn_t *connp = (conn_t *)proto_handle;
717 721
718 722 ASSERT(connp->conn_upper_handle != NULL);
719 723
720 724 /* All Solaris components should pass a cred for this operation. */
721 725 ASSERT(cr != NULL);
722 726
723 727 tcp_close_common(connp, flags);
724 728
725 729 ip_free_helper_stream(connp);
726 730
727 731 /*
728 732 * Drop IP's reference on the conn. This is the last reference
729 733 * on the connp if the state was less than established. If the
730 734 * connection has gone into timewait state, then we will have
731 735 * one ref for the TCP and one more ref (total of two) for the
732 736 * classifier connected hash list (a timewait connections stays
733 737 * in connected hash till closed).
734 738 *
735 739 * We can't assert the references because there might be other
736 740 * transient reference places because of some walkers or queued
737 741 * packets in squeue for the timewait state.
738 742 */
739 743 CONN_DEC_REF(connp);
740 744
741 745 /*
742 746 * EINPROGRESS tells sockfs to wait for a 'closed' upcall before
743 747 * freeing the socket.
744 748 */
↓ open down ↓ |
672 lines elided |
↑ open up ↑ |
745 749 return (EINPROGRESS);
746 750 }
747 751
748 752 /* ARGSUSED */
749 753 sock_lower_handle_t
750 754 tcp_create(int family, int type, int proto, sock_downcalls_t **sock_downcalls,
751 755 uint_t *smodep, int *errorp, int flags, cred_t *credp)
752 756 {
753 757 conn_t *connp;
754 758 boolean_t isv6 = family == AF_INET6;
759 +
755 760 if (type != SOCK_STREAM || (family != AF_INET && family != AF_INET6) ||
756 761 (proto != 0 && proto != IPPROTO_TCP)) {
757 762 *errorp = EPROTONOSUPPORT;
758 763 return (NULL);
759 764 }
760 765
761 766 connp = tcp_create_common(credp, isv6, B_TRUE, errorp);
762 767 if (connp == NULL) {
763 768 return (NULL);
764 769 }
765 770
766 771 /*
767 772 * Put the ref for TCP. Ref for IP was already put
768 - * by ipcl_conn_create. Also Make the conn_t globally
769 - * visible to walkers
773 + * by ipcl_conn_create. Also make the conn_t globally
774 + * visible to walkers.
770 775 */
771 776 mutex_enter(&connp->conn_lock);
772 777 CONN_INC_REF_LOCKED(connp);
773 778 ASSERT(connp->conn_ref == 2);
774 779 connp->conn_state_flags &= ~CONN_INCIPIENT;
775 780
776 781 connp->conn_flags |= IPCL_NONSTR;
777 782 mutex_exit(&connp->conn_lock);
778 783
779 784 ASSERT(errorp != NULL);
780 785 *errorp = 0;
781 786 *sock_downcalls = &sock_tcp_downcalls;
782 787 *smodep = SM_CONNREQUIRED | SM_EXDATA | SM_ACCEPTSUPP |
783 788 SM_SENDFILESUPP;
784 789
785 790 return ((sock_lower_handle_t)connp);
786 791 }
787 792
788 793 /*
789 794 * tcp_fallback
790 795 *
791 796 * A direct socket is falling back to using STREAMS. The queue
792 797 * that is being passed down was created using tcp_open() with
793 798 * the SO_FALLBACK flag set. As a result, the queue is not
794 799 * associated with a conn, and the q_ptrs instead contain the
795 800 * dev and minor area that should be used.
796 801 *
797 802 * The 'issocket' flag indicates whether the FireEngine
798 803 * optimizations should be used. The common case would be that
799 804 * optimizations are enabled, and they might be subsequently
800 805 * disabled using the _SIOCSOCKFALLBACK ioctl.
801 806 */
802 807
803 808 /*
804 809 * An active connection is falling back to TPI. Gather all the information
805 810 * required by the STREAM head and TPI sonode and send it up.
806 811 */
807 812 static void
808 813 tcp_fallback_noneager(tcp_t *tcp, mblk_t *stropt_mp, queue_t *q,
809 814 boolean_t issocket, so_proto_quiesced_cb_t quiesced_cb,
810 815 sock_quiesce_arg_t *arg)
811 816 {
812 817 conn_t *connp = tcp->tcp_connp;
813 818 struct stroptions *stropt;
814 819 struct T_capability_ack tca;
815 820 struct sockaddr_in6 laddr, faddr;
816 821 socklen_t laddrlen, faddrlen;
817 822 short opts;
818 823 int error;
819 824 mblk_t *mp, *mpnext;
820 825
821 826 connp->conn_dev = (dev_t)RD(q)->q_ptr;
822 827 connp->conn_minor_arena = WR(q)->q_ptr;
823 828
824 829 RD(q)->q_ptr = WR(q)->q_ptr = connp;
825 830
826 831 connp->conn_rq = RD(q);
827 832 connp->conn_wq = WR(q);
828 833
829 834 WR(q)->q_qinfo = &tcp_sock_winit;
830 835
831 836 if (!issocket)
832 837 tcp_use_pure_tpi(tcp);
833 838
834 839 /*
835 840 * free the helper stream
836 841 */
837 842 ip_free_helper_stream(connp);
838 843
839 844 /*
840 845 * Notify the STREAM head about options
841 846 */
842 847 DB_TYPE(stropt_mp) = M_SETOPTS;
843 848 stropt = (struct stroptions *)stropt_mp->b_rptr;
844 849 stropt_mp->b_wptr += sizeof (struct stroptions);
845 850 stropt->so_flags = SO_HIWAT | SO_WROFF | SO_MAXBLK;
846 851
847 852 stropt->so_wroff = connp->conn_ht_iphc_len + (tcp->tcp_loopback ? 0 :
848 853 tcp->tcp_tcps->tcps_wroff_xtra);
849 854 if (tcp->tcp_snd_sack_ok)
850 855 stropt->so_wroff += TCPOPT_MAX_SACK_LEN;
851 856 stropt->so_hiwat = connp->conn_rcvbuf;
852 857 stropt->so_maxblk = tcp_maxpsz_set(tcp, B_FALSE);
853 858
854 859 putnext(RD(q), stropt_mp);
855 860
856 861 /*
857 862 * Collect the information needed to sync with the sonode
858 863 */
859 864 tcp_do_capability_ack(tcp, &tca, TC1_INFO|TC1_ACCEPTOR_ID);
860 865
861 866 laddrlen = faddrlen = sizeof (sin6_t);
862 867 (void) tcp_getsockname((sock_lower_handle_t)connp,
863 868 (struct sockaddr *)&laddr, &laddrlen, CRED());
864 869 error = tcp_getpeername((sock_lower_handle_t)connp,
865 870 (struct sockaddr *)&faddr, &faddrlen, CRED());
866 871 if (error != 0)
867 872 faddrlen = 0;
868 873
869 874 opts = 0;
870 875 if (connp->conn_oobinline)
871 876 opts |= SO_OOBINLINE;
872 877 if (connp->conn_ixa->ixa_flags & IXAF_DONTROUTE)
873 878 opts |= SO_DONTROUTE;
874 879
875 880 /*
876 881 * Notify the socket that the protocol is now quiescent,
877 882 * and it's therefore safe move data from the socket
878 883 * to the stream head.
879 884 */
880 885 mp = (*quiesced_cb)(connp->conn_upper_handle, arg, &tca,
881 886 (struct sockaddr *)&laddr, laddrlen,
882 887 (struct sockaddr *)&faddr, faddrlen, opts);
883 888
884 889 while (mp != NULL) {
885 890 mpnext = mp->b_next;
886 891 tcp->tcp_rcv_list = mp->b_next;
887 892 mp->b_next = NULL;
888 893 putnext(q, mp);
889 894 mp = mpnext;
890 895 }
891 896 ASSERT(tcp->tcp_rcv_last_head == NULL);
892 897 ASSERT(tcp->tcp_rcv_last_tail == NULL);
893 898 ASSERT(tcp->tcp_rcv_cnt == 0);
894 899
895 900 /*
896 901 * All eagers in q0 are marked as being non-STREAM, so they will
897 902 * make su_newconn upcalls when the handshake completes, which
898 903 * will fail (resulting in the conn being closed). So we just blow
899 904 * off everything in q0 instead of waiting for the inevitable.
900 905 */
901 906 if (tcp->tcp_conn_req_cnt_q0 != 0)
902 907 tcp_eager_cleanup(tcp, B_TRUE);
903 908 }
904 909
905 910 /*
906 911 * An eager is falling back to TPI. All we have to do is send
907 912 * up a T_CONN_IND.
908 913 */
909 914 static void
910 915 tcp_fallback_eager(tcp_t *eager, boolean_t issocket,
911 916 so_proto_quiesced_cb_t quiesced_cb, sock_quiesce_arg_t *arg)
912 917 {
913 918 conn_t *connp = eager->tcp_connp;
914 919 tcp_t *listener = eager->tcp_listener;
915 920 mblk_t *mp;
916 921
917 922 ASSERT(listener != NULL);
918 923
919 924 /*
920 925 * Notify the socket that the protocol is now quiescent,
921 926 * and it's therefore safe move data from the socket
922 927 * to tcp's rcv queue.
923 928 */
924 929 mp = (*quiesced_cb)(connp->conn_upper_handle, arg, NULL, NULL, 0,
925 930 NULL, 0, 0);
926 931
927 932 if (mp != NULL) {
928 933 ASSERT(eager->tcp_rcv_cnt == 0);
929 934
930 935 eager->tcp_rcv_list = mp;
931 936 eager->tcp_rcv_cnt = msgdsize(mp);
932 937 while (mp->b_next != NULL) {
933 938 mp = mp->b_next;
934 939 eager->tcp_rcv_cnt += msgdsize(mp);
935 940 }
936 941 eager->tcp_rcv_last_head = mp;
937 942 while (mp->b_cont)
938 943 mp = mp->b_cont;
939 944 eager->tcp_rcv_last_tail = mp;
940 945 if (eager->tcp_rcv_cnt > eager->tcp_rwnd)
941 946 eager->tcp_rwnd = 0;
942 947 else
943 948 eager->tcp_rwnd -= eager->tcp_rcv_cnt;
944 949 }
945 950
946 951 if (!issocket)
947 952 eager->tcp_issocket = B_FALSE;
948 953 /*
949 954 * The stream for this eager does not yet exist, so mark it as
950 955 * being detached.
951 956 */
952 957 eager->tcp_detached = B_TRUE;
953 958 eager->tcp_hard_binding = B_TRUE;
954 959 connp->conn_rq = listener->tcp_connp->conn_rq;
955 960 connp->conn_wq = listener->tcp_connp->conn_wq;
956 961
957 962 /* Send up the connection indication */
958 963 mp = eager->tcp_conn.tcp_eager_conn_ind;
959 964 ASSERT(mp != NULL);
960 965 eager->tcp_conn.tcp_eager_conn_ind = NULL;
961 966
962 967 /*
963 968 * TLI/XTI applications will get confused by
964 969 * sending eager as an option since it violates
965 970 * the option semantics. So remove the eager as
966 971 * option since TLI/XTI app doesn't need it anyway.
967 972 */
968 973 if (!issocket) {
969 974 struct T_conn_ind *conn_ind;
970 975
971 976 conn_ind = (struct T_conn_ind *)mp->b_rptr;
972 977 conn_ind->OPT_length = 0;
973 978 conn_ind->OPT_offset = 0;
974 979 }
975 980
976 981 /*
977 982 * Sockfs guarantees that the listener will not be closed
978 983 * during fallback. So we can safely use the listener's queue.
979 984 */
980 985 putnext(listener->tcp_connp->conn_rq, mp);
981 986 }
982 987
983 988
984 989 int
985 990 tcp_fallback(sock_lower_handle_t proto_handle, queue_t *q,
986 991 boolean_t direct_sockfs, so_proto_quiesced_cb_t quiesced_cb,
987 992 sock_quiesce_arg_t *arg)
988 993 {
989 994 tcp_t *tcp;
990 995 conn_t *connp = (conn_t *)proto_handle;
991 996 int error;
992 997 mblk_t *stropt_mp;
993 998 mblk_t *ordrel_mp;
994 999
995 1000 tcp = connp->conn_tcp;
996 1001
997 1002 stropt_mp = allocb_wait(sizeof (struct stroptions), BPRI_HI, STR_NOSIG,
998 1003 NULL);
999 1004
1000 1005 /* Pre-allocate the T_ordrel_ind mblk. */
1001 1006 ASSERT(tcp->tcp_ordrel_mp == NULL);
1002 1007 ordrel_mp = allocb_wait(sizeof (struct T_ordrel_ind), BPRI_HI,
1003 1008 STR_NOSIG, NULL);
1004 1009 ordrel_mp->b_datap->db_type = M_PROTO;
1005 1010 ((struct T_ordrel_ind *)ordrel_mp->b_rptr)->PRIM_type = T_ORDREL_IND;
1006 1011 ordrel_mp->b_wptr += sizeof (struct T_ordrel_ind);
1007 1012
1008 1013 /*
1009 1014 * Enter the squeue so that no new packets can come in
1010 1015 */
1011 1016 error = squeue_synch_enter(connp, NULL);
1012 1017 if (error != 0) {
1013 1018 /* failed to enter, free all the pre-allocated messages. */
1014 1019 freeb(stropt_mp);
1015 1020 freeb(ordrel_mp);
1016 1021 return (ENOMEM);
1017 1022 }
1018 1023
1019 1024 /*
1020 1025 * Both endpoints must be of the same type (either STREAMS or
1021 1026 * non-STREAMS) for fusion to be enabled. So if we are fused,
1022 1027 * we have to unfuse.
1023 1028 */
1024 1029 if (tcp->tcp_fused)
1025 1030 tcp_unfuse(tcp);
1026 1031
1027 1032 if (tcp->tcp_listener != NULL) {
1028 1033 /* The eager will deal with opts when accept() is called */
1029 1034 freeb(stropt_mp);
1030 1035 tcp_fallback_eager(tcp, direct_sockfs, quiesced_cb, arg);
1031 1036 } else {
1032 1037 tcp_fallback_noneager(tcp, stropt_mp, q, direct_sockfs,
1033 1038 quiesced_cb, arg);
1034 1039 }
1035 1040
1036 1041 /*
1037 1042 * No longer a direct socket
1038 1043 *
1039 1044 * Note that we intentionally leave the upper_handle and upcalls
1040 1045 * intact, since eagers may still be using them.
1041 1046 */
1042 1047 connp->conn_flags &= ~IPCL_NONSTR;
1043 1048 tcp->tcp_ordrel_mp = ordrel_mp;
1044 1049
1045 1050 /*
1046 1051 * There should be atleast two ref's (IP + TCP)
1047 1052 */
1048 1053 ASSERT(connp->conn_ref >= 2);
1049 1054 squeue_synch_exit(connp);
1050 1055
1051 1056 return (0);
1052 1057 }
1053 1058
1054 1059 /*
1055 1060 * Notifies a non-STREAMS based listener about a new connection. This
1056 1061 * function is executed on the *eager*'s squeue once the 3 way handshake
1057 1062 * has completed. Note that the behavior differs from STREAMS, where the
1058 1063 * T_CONN_IND is sent up by tcp_send_conn_ind() while on the *listener*'s
1059 1064 * squeue.
1060 1065 *
1061 1066 * Returns B_TRUE if the notification succeeded and an upper handle was
1062 1067 * obtained. `tcp' should be closed on failure.
1063 1068 */
1064 1069 boolean_t
1065 1070 tcp_newconn_notify(tcp_t *tcp, ip_recv_attr_t *ira)
1066 1071 {
1067 1072 tcp_t *listener = tcp->tcp_listener;
1068 1073 conn_t *lconnp = listener->tcp_connp;
1069 1074 conn_t *econnp = tcp->tcp_connp;
1070 1075 tcp_t *tail;
1071 1076 ipaddr_t *addr_cache;
1072 1077 sock_upper_handle_t upper;
1073 1078 struct sock_proto_props sopp;
1074 1079
1075 1080 mutex_enter(&listener->tcp_eager_lock);
1076 1081 /*
1077 1082 * Take the eager out, if it is in the list of droppable eagers
1078 1083 * as we are here because the 3W handshake is over.
1079 1084 */
1080 1085 MAKE_UNDROPPABLE(tcp);
1081 1086 /*
1082 1087 * The eager already has an extra ref put in tcp_input_data
1083 1088 * so that it stays till accept comes back even though it
1084 1089 * might get into TCPS_CLOSED as a result of a TH_RST etc.
1085 1090 */
1086 1091 ASSERT(listener->tcp_conn_req_cnt_q0 > 0);
1087 1092 listener->tcp_conn_req_cnt_q0--;
1088 1093 listener->tcp_conn_req_cnt_q++;
1089 1094
1090 1095 /* Move from SYN_RCVD to ESTABLISHED list */
1091 1096 tcp->tcp_eager_next_q0->tcp_eager_prev_q0 = tcp->tcp_eager_prev_q0;
1092 1097 tcp->tcp_eager_prev_q0->tcp_eager_next_q0 = tcp->tcp_eager_next_q0;
1093 1098 tcp->tcp_eager_prev_q0 = NULL;
1094 1099 tcp->tcp_eager_next_q0 = NULL;
1095 1100
1096 1101 /*
1097 1102 * Insert at end of the queue because connections are accepted
1098 1103 * in chronological order. Leaving the older connections at front
1099 1104 * of the queue helps reducing search time.
1100 1105 */
1101 1106 tail = listener->tcp_eager_last_q;
1102 1107 if (tail != NULL)
1103 1108 tail->tcp_eager_next_q = tcp;
1104 1109 else
1105 1110 listener->tcp_eager_next_q = tcp;
1106 1111 listener->tcp_eager_last_q = tcp;
1107 1112 tcp->tcp_eager_next_q = NULL;
1108 1113
1109 1114 /* we have timed out before */
1110 1115 if (tcp->tcp_syn_rcvd_timeout != 0) {
1111 1116 tcp->tcp_syn_rcvd_timeout = 0;
1112 1117 listener->tcp_syn_rcvd_timeout--;
1113 1118 if (listener->tcp_syn_defense &&
1114 1119 listener->tcp_syn_rcvd_timeout <=
1115 1120 (listener->tcp_tcps->tcps_conn_req_max_q0 >> 5) &&
1116 1121 10*MINUTES < TICK_TO_MSEC(ddi_get_lbolt64() -
1117 1122 listener->tcp_last_rcv_lbolt)) {
1118 1123 /*
1119 1124 * Turn off the defense mode if we
1120 1125 * believe the SYN attack is over.
1121 1126 */
1122 1127 listener->tcp_syn_defense = B_FALSE;
1123 1128 if (listener->tcp_ip_addr_cache) {
1124 1129 kmem_free((void *)listener->tcp_ip_addr_cache,
1125 1130 IP_ADDR_CACHE_SIZE * sizeof (ipaddr_t));
1126 1131 listener->tcp_ip_addr_cache = NULL;
1127 1132 }
1128 1133 }
1129 1134 }
1130 1135 addr_cache = (ipaddr_t *)(listener->tcp_ip_addr_cache);
1131 1136 if (addr_cache != NULL) {
1132 1137 /*
1133 1138 * We have finished a 3-way handshake with this
1134 1139 * remote host. This proves the IP addr is good.
1135 1140 * Cache it!
1136 1141 */
1137 1142 addr_cache[IP_ADDR_CACHE_HASH(tcp->tcp_connp->conn_faddr_v4)] =
1138 1143 tcp->tcp_connp->conn_faddr_v4;
1139 1144 }
1140 1145 mutex_exit(&listener->tcp_eager_lock);
1141 1146
1142 1147 /*
1143 1148 * Notify the ULP about the newconn. It is guaranteed that no
1144 1149 * tcp_accept() call will be made for the eager if the
1145 1150 * notification fails.
1146 1151 */
1147 1152 if ((upper = (*lconnp->conn_upcalls->su_newconn)
1148 1153 (lconnp->conn_upper_handle, (sock_lower_handle_t)econnp,
1149 1154 &sock_tcp_downcalls, ira->ira_cred, ira->ira_cpid,
1150 1155 &econnp->conn_upcalls)) == NULL) {
1151 1156 return (B_FALSE);
1152 1157 }
1153 1158 econnp->conn_upper_handle = upper;
1154 1159
1155 1160 tcp->tcp_detached = B_FALSE;
1156 1161 tcp->tcp_hard_binding = B_FALSE;
1157 1162 tcp->tcp_tconnind_started = B_TRUE;
1158 1163
1159 1164 if (econnp->conn_keepalive) {
1160 1165 tcp->tcp_ka_last_intrvl = 0;
1161 1166 tcp->tcp_ka_tid = TCP_TIMER(tcp, tcp_keepalive_timer,
1162 1167 tcp->tcp_ka_interval);
1163 1168 }
1164 1169
1165 1170 /* Update the necessary parameters */
1166 1171 tcp_get_proto_props(tcp, &sopp);
1167 1172
1168 1173 (*econnp->conn_upcalls->su_set_proto_props)
1169 1174 (econnp->conn_upper_handle, &sopp);
1170 1175
1171 1176 return (B_TRUE);
1172 1177 }
↓ open down ↓ |
393 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX