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 }
↓ open down ↓ |
247 lines elided |
↑ open up ↑ |
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 -done:
331 334 squeue_synch_exit(connp);
332 335
333 336 return ((error == 0) ? EINPROGRESS : error);
334 337 }
335 338
336 339 /* ARGSUSED3 */
337 340 int
338 341 tcp_getpeername(sock_lower_handle_t proto_handle, struct sockaddr *addr,
339 342 socklen_t *addrlenp, cred_t *cr)
340 343 {
341 344 conn_t *connp = (conn_t *)proto_handle;
342 345 tcp_t *tcp = connp->conn_tcp;
343 346
344 347 /* All Solaris components should pass a cred for this operation. */
345 348 ASSERT(cr != NULL);
346 349
347 350 ASSERT(tcp != NULL);
348 351 if (tcp->tcp_state < TCPS_SYN_RCVD)
349 352 return (ENOTCONN);
350 353
351 354 return (conn_getpeername(connp, addr, addrlenp));
352 355 }
353 356
354 357 /* ARGSUSED3 */
355 358 int
356 359 tcp_getsockname(sock_lower_handle_t proto_handle, struct sockaddr *addr,
357 360 socklen_t *addrlenp, cred_t *cr)
358 361 {
359 362 conn_t *connp = (conn_t *)proto_handle;
360 363
361 364 /* All Solaris components should pass a cred for this operation. */
362 365 ASSERT(cr != NULL);
363 366
364 367 return (conn_getsockname(connp, addr, addrlenp));
365 368 }
366 369
367 370 /* returns UNIX error, the optlen is a value-result arg */
368 371 static int
369 372 tcp_getsockopt(sock_lower_handle_t proto_handle, int level, int option_name,
370 373 void *optvalp, socklen_t *optlen, cred_t *cr)
371 374 {
372 375 conn_t *connp = (conn_t *)proto_handle;
373 376 int error;
374 377 t_uscalar_t max_optbuf_len;
375 378 void *optvalp_buf;
376 379 int len;
377 380
378 381 ASSERT(connp->conn_upper_handle != NULL);
379 382
380 383 error = proto_opt_check(level, option_name, *optlen, &max_optbuf_len,
381 384 tcp_opt_obj.odb_opt_des_arr,
382 385 tcp_opt_obj.odb_opt_arr_cnt,
383 386 B_FALSE, B_TRUE, cr);
384 387 if (error != 0) {
385 388 if (error < 0) {
386 389 error = proto_tlitosyserr(-error);
387 390 }
388 391 return (error);
389 392 }
390 393
391 394 optvalp_buf = kmem_alloc(max_optbuf_len, KM_SLEEP);
392 395
393 396 error = squeue_synch_enter(connp, NULL);
394 397 if (error == ENOMEM) {
395 398 kmem_free(optvalp_buf, max_optbuf_len);
396 399 return (ENOMEM);
397 400 }
398 401
399 402 len = tcp_opt_get(connp, level, option_name, optvalp_buf);
400 403 squeue_synch_exit(connp);
401 404
402 405 if (len == -1) {
403 406 kmem_free(optvalp_buf, max_optbuf_len);
404 407 return (EINVAL);
405 408 }
406 409
407 410 /*
408 411 * update optlen and copy option value
409 412 */
410 413 t_uscalar_t size = MIN(len, *optlen);
411 414
412 415 bcopy(optvalp_buf, optvalp, size);
413 416 bcopy(&size, optlen, sizeof (size));
414 417
415 418 kmem_free(optvalp_buf, max_optbuf_len);
416 419 return (0);
417 420 }
418 421
419 422 static int
420 423 tcp_setsockopt(sock_lower_handle_t proto_handle, int level, int option_name,
421 424 const void *optvalp, socklen_t optlen, cred_t *cr)
422 425 {
423 426 conn_t *connp = (conn_t *)proto_handle;
424 427 int error;
425 428
426 429 ASSERT(connp->conn_upper_handle != NULL);
427 430 /*
428 431 * Entering the squeue synchronously can result in a context switch,
429 432 * which can cause a rather sever performance degradation. So we try to
430 433 * handle whatever options we can without entering the squeue.
431 434 */
432 435 if (level == IPPROTO_TCP) {
433 436 switch (option_name) {
434 437 case TCP_NODELAY:
435 438 if (optlen != sizeof (int32_t))
436 439 return (EINVAL);
437 440 mutex_enter(&connp->conn_tcp->tcp_non_sq_lock);
438 441 connp->conn_tcp->tcp_naglim = *(int *)optvalp ? 1 :
439 442 connp->conn_tcp->tcp_mss;
440 443 mutex_exit(&connp->conn_tcp->tcp_non_sq_lock);
441 444 return (0);
442 445 default:
443 446 break;
444 447 }
445 448 }
446 449
447 450 error = squeue_synch_enter(connp, NULL);
448 451 if (error == ENOMEM) {
449 452 return (ENOMEM);
450 453 }
451 454
452 455 error = proto_opt_check(level, option_name, optlen, NULL,
453 456 tcp_opt_obj.odb_opt_des_arr,
454 457 tcp_opt_obj.odb_opt_arr_cnt,
455 458 B_TRUE, B_FALSE, cr);
456 459
457 460 if (error != 0) {
458 461 if (error < 0) {
459 462 error = proto_tlitosyserr(-error);
460 463 }
461 464 squeue_synch_exit(connp);
462 465 return (error);
463 466 }
464 467
465 468 error = tcp_opt_set(connp, SETFN_OPTCOM_NEGOTIATE, level, option_name,
466 469 optlen, (uchar_t *)optvalp, (uint_t *)&optlen, (uchar_t *)optvalp,
467 470 NULL, cr);
468 471 squeue_synch_exit(connp);
469 472
470 473 ASSERT(error >= 0);
471 474
472 475 return (error);
473 476 }
474 477
475 478 /* ARGSUSED */
476 479 static int
477 480 tcp_sendmsg(sock_lower_handle_t proto_handle, mblk_t *mp, struct nmsghdr *msg,
478 481 cred_t *cr)
479 482 {
480 483 tcp_t *tcp;
481 484 uint32_t msize;
482 485 conn_t *connp = (conn_t *)proto_handle;
483 486 int32_t tcpstate;
484 487
485 488 /* All Solaris components should pass a cred for this operation. */
486 489 ASSERT(cr != NULL);
487 490
488 491 ASSERT(connp->conn_ref >= 2);
489 492 ASSERT(connp->conn_upper_handle != NULL);
490 493
491 494 if (msg->msg_controllen != 0) {
492 495 freemsg(mp);
493 496 return (EOPNOTSUPP);
494 497 }
495 498
496 499 switch (DB_TYPE(mp)) {
497 500 case M_DATA:
498 501 tcp = connp->conn_tcp;
499 502 ASSERT(tcp != NULL);
500 503
501 504 tcpstate = tcp->tcp_state;
502 505 if (tcpstate < TCPS_ESTABLISHED) {
503 506 freemsg(mp);
504 507 /*
505 508 * We return ENOTCONN if the endpoint is trying to
506 509 * connect or has never been connected, and EPIPE if it
507 510 * has been disconnected. The connection id helps us
508 511 * distinguish between the last two cases.
509 512 */
510 513 return ((tcpstate == TCPS_SYN_SENT) ? ENOTCONN :
511 514 ((tcp->tcp_connid > 0) ? EPIPE : ENOTCONN));
512 515 } else if (tcpstate > TCPS_CLOSE_WAIT) {
513 516 freemsg(mp);
514 517 return (EPIPE);
515 518 }
516 519
517 520 msize = msgdsize(mp);
518 521
519 522 mutex_enter(&tcp->tcp_non_sq_lock);
520 523 tcp->tcp_squeue_bytes += msize;
521 524 /*
522 525 * Squeue Flow Control
523 526 */
524 527 if (TCP_UNSENT_BYTES(tcp) > connp->conn_sndbuf) {
525 528 tcp_setqfull(tcp);
526 529 }
527 530 mutex_exit(&tcp->tcp_non_sq_lock);
528 531
529 532 /*
530 533 * The application may pass in an address in the msghdr, but
531 534 * we ignore the address on connection-oriented sockets.
532 535 * Just like BSD this code does not generate an error for
533 536 * TCP (a CONNREQUIRED socket) when sending to an address
534 537 * passed in with sendto/sendmsg. Instead the data is
535 538 * delivered on the connection as if no address had been
536 539 * supplied.
537 540 */
538 541 CONN_INC_REF(connp);
539 542
540 543 if (msg->msg_flags & MSG_OOB) {
541 544 SQUEUE_ENTER_ONE(connp->conn_sqp, mp, tcp_output_urgent,
542 545 connp, NULL, tcp_squeue_flag, SQTAG_TCP_OUTPUT);
543 546 } else {
544 547 SQUEUE_ENTER_ONE(connp->conn_sqp, mp, tcp_output,
545 548 connp, NULL, tcp_squeue_flag, SQTAG_TCP_OUTPUT);
546 549 }
547 550
548 551 return (0);
549 552
550 553 default:
551 554 ASSERT(0);
552 555 }
553 556
554 557 freemsg(mp);
555 558 return (0);
556 559 }
557 560
558 561 /* ARGSUSED */
559 562 static int
560 563 tcp_shutdown(sock_lower_handle_t proto_handle, int how, cred_t *cr)
561 564 {
562 565 conn_t *connp = (conn_t *)proto_handle;
563 566 tcp_t *tcp = connp->conn_tcp;
564 567
565 568 ASSERT(connp->conn_upper_handle != NULL);
566 569
567 570 /* All Solaris components should pass a cred for this operation. */
568 571 ASSERT(cr != NULL);
569 572
570 573 /*
571 574 * X/Open requires that we check the connected state.
572 575 */
573 576 if (tcp->tcp_state < TCPS_SYN_SENT)
574 577 return (ENOTCONN);
575 578
576 579 /* shutdown the send side */
577 580 if (how != SHUT_RD) {
578 581 mblk_t *bp;
579 582
580 583 bp = allocb_wait(0, BPRI_HI, STR_NOSIG, NULL);
581 584 CONN_INC_REF(connp);
582 585 SQUEUE_ENTER_ONE(connp->conn_sqp, bp, tcp_shutdown_output,
583 586 connp, NULL, SQ_NODRAIN, SQTAG_TCP_SHUTDOWN_OUTPUT);
584 587
585 588 (*connp->conn_upcalls->su_opctl)(connp->conn_upper_handle,
586 589 SOCK_OPCTL_SHUT_SEND, 0);
587 590 }
588 591
589 592 /* shutdown the recv side */
590 593 if (how != SHUT_WR)
591 594 (*connp->conn_upcalls->su_opctl)(connp->conn_upper_handle,
592 595 SOCK_OPCTL_SHUT_RECV, 0);
593 596
594 597 return (0);
595 598 }
596 599
597 600 static void
598 601 tcp_clr_flowctrl(sock_lower_handle_t proto_handle)
599 602 {
600 603 conn_t *connp = (conn_t *)proto_handle;
601 604 tcp_t *tcp = connp->conn_tcp;
602 605 mblk_t *mp;
603 606 int error;
604 607
605 608 ASSERT(connp->conn_upper_handle != NULL);
606 609
607 610 /*
608 611 * If tcp->tcp_rsrv_mp == NULL, it means that tcp_clr_flowctrl()
609 612 * is currently running.
610 613 */
611 614 mutex_enter(&tcp->tcp_rsrv_mp_lock);
612 615 if ((mp = tcp->tcp_rsrv_mp) == NULL) {
613 616 mutex_exit(&tcp->tcp_rsrv_mp_lock);
614 617 return;
615 618 }
616 619 tcp->tcp_rsrv_mp = NULL;
617 620 mutex_exit(&tcp->tcp_rsrv_mp_lock);
618 621
619 622 error = squeue_synch_enter(connp, mp);
620 623 ASSERT(error == 0);
621 624
622 625 mutex_enter(&tcp->tcp_rsrv_mp_lock);
623 626 tcp->tcp_rsrv_mp = mp;
624 627 mutex_exit(&tcp->tcp_rsrv_mp_lock);
625 628
626 629 if (tcp->tcp_fused) {
627 630 tcp_fuse_backenable(tcp);
628 631 } else {
629 632 tcp->tcp_rwnd = connp->conn_rcvbuf;
630 633 /*
631 634 * Send back a window update immediately if TCP is above
632 635 * ESTABLISHED state and the increase of the rcv window
633 636 * that the other side knows is at least 1 MSS after flow
634 637 * control is lifted.
635 638 */
636 639 if (tcp->tcp_state >= TCPS_ESTABLISHED &&
637 640 tcp_rwnd_reopen(tcp) == TH_ACK_NEEDED) {
638 641 tcp_xmit_ctl(NULL, tcp,
639 642 (tcp->tcp_swnd == 0) ? tcp->tcp_suna :
640 643 tcp->tcp_snxt, tcp->tcp_rnxt, TH_ACK);
641 644 }
642 645 }
643 646
644 647 squeue_synch_exit(connp);
645 648 }
646 649
647 650 /* ARGSUSED */
648 651 static int
649 652 tcp_ioctl(sock_lower_handle_t proto_handle, int cmd, intptr_t arg,
650 653 int mode, int32_t *rvalp, cred_t *cr)
651 654 {
652 655 conn_t *connp = (conn_t *)proto_handle;
653 656 int error;
654 657
655 658 ASSERT(connp->conn_upper_handle != NULL);
656 659
657 660 /* All Solaris components should pass a cred for this operation. */
658 661 ASSERT(cr != NULL);
659 662
660 663 /*
661 664 * If we don't have a helper stream then create one.
662 665 * ip_create_helper_stream takes care of locking the conn_t,
663 666 * so this check for NULL is just a performance optimization.
664 667 */
665 668 if (connp->conn_helper_info == NULL) {
666 669 tcp_stack_t *tcps = connp->conn_tcp->tcp_tcps;
667 670
668 671 /*
669 672 * Create a helper stream for non-STREAMS socket.
670 673 */
671 674 error = ip_create_helper_stream(connp, tcps->tcps_ldi_ident);
672 675 if (error != 0) {
673 676 ip0dbg(("tcp_ioctl: create of IP helper stream "
674 677 "failed %d\n", error));
675 678 return (error);
676 679 }
677 680 }
678 681
679 682 switch (cmd) {
680 683 case ND_SET:
681 684 case ND_GET:
682 685 case _SIOCSOCKFALLBACK:
683 686 case TCP_IOC_ABORT_CONN:
684 687 case TI_GETPEERNAME:
685 688 case TI_GETMYNAME:
686 689 ip1dbg(("tcp_ioctl: cmd 0x%x on non streams socket",
687 690 cmd));
688 691 error = EINVAL;
689 692 break;
690 693 default:
691 694 /*
692 695 * If the conn is not closing, pass on to IP using
693 696 * helper stream. Bump the ioctlref to prevent tcp_close
694 697 * from closing the rq/wq out from underneath the ioctl
695 698 * if it ends up queued or aborted/interrupted.
696 699 */
697 700 mutex_enter(&connp->conn_lock);
698 701 if (connp->conn_state_flags & (CONN_CLOSING)) {
699 702 mutex_exit(&connp->conn_lock);
700 703 error = EINVAL;
701 704 break;
702 705 }
703 706 CONN_INC_IOCTLREF_LOCKED(connp);
704 707 error = ldi_ioctl(connp->conn_helper_info->iphs_handle,
705 708 cmd, arg, mode, cr, rvalp);
706 709 CONN_DEC_IOCTLREF(connp);
707 710 break;
708 711 }
709 712 return (error);
710 713 }
711 714
712 715 /* ARGSUSED */
713 716 static int
714 717 tcp_close(sock_lower_handle_t proto_handle, int flags, cred_t *cr)
715 718 {
716 719 conn_t *connp = (conn_t *)proto_handle;
717 720
718 721 ASSERT(connp->conn_upper_handle != NULL);
719 722
720 723 /* All Solaris components should pass a cred for this operation. */
721 724 ASSERT(cr != NULL);
722 725
723 726 tcp_close_common(connp, flags);
724 727
725 728 ip_free_helper_stream(connp);
726 729
727 730 /*
728 731 * Drop IP's reference on the conn. This is the last reference
729 732 * on the connp if the state was less than established. If the
730 733 * connection has gone into timewait state, then we will have
731 734 * one ref for the TCP and one more ref (total of two) for the
732 735 * classifier connected hash list (a timewait connections stays
733 736 * in connected hash till closed).
734 737 *
735 738 * We can't assert the references because there might be other
736 739 * transient reference places because of some walkers or queued
737 740 * packets in squeue for the timewait state.
738 741 */
739 742 CONN_DEC_REF(connp);
740 743
741 744 /*
742 745 * EINPROGRESS tells sockfs to wait for a 'closed' upcall before
743 746 * freeing the socket.
744 747 */
↓ open down ↓ |
404 lines elided |
↑ open up ↑ |
745 748 return (EINPROGRESS);
746 749 }
747 750
748 751 /* ARGSUSED */
749 752 sock_lower_handle_t
750 753 tcp_create(int family, int type, int proto, sock_downcalls_t **sock_downcalls,
751 754 uint_t *smodep, int *errorp, int flags, cred_t *credp)
752 755 {
753 756 conn_t *connp;
754 757 boolean_t isv6 = family == AF_INET6;
758 +
755 759 if (type != SOCK_STREAM || (family != AF_INET && family != AF_INET6) ||
756 760 (proto != 0 && proto != IPPROTO_TCP)) {
757 761 *errorp = EPROTONOSUPPORT;
758 762 return (NULL);
759 763 }
760 764
761 765 connp = tcp_create_common(credp, isv6, B_TRUE, errorp);
762 766 if (connp == NULL) {
763 767 return (NULL);
764 768 }
765 769
766 770 /*
767 771 * 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
772 + * by ipcl_conn_create. Also make the conn_t globally
773 + * visible to walkers.
770 774 */
771 775 mutex_enter(&connp->conn_lock);
772 776 CONN_INC_REF_LOCKED(connp);
773 777 ASSERT(connp->conn_ref == 2);
774 778 connp->conn_state_flags &= ~CONN_INCIPIENT;
775 779
776 780 connp->conn_flags |= IPCL_NONSTR;
777 781 mutex_exit(&connp->conn_lock);
778 782
779 783 ASSERT(errorp != NULL);
780 784 *errorp = 0;
781 785 *sock_downcalls = &sock_tcp_downcalls;
782 786 *smodep = SM_CONNREQUIRED | SM_EXDATA | SM_ACCEPTSUPP |
783 787 SM_SENDFILESUPP;
784 788
785 789 return ((sock_lower_handle_t)connp);
786 790 }
787 791
788 792 /*
789 793 * tcp_fallback
790 794 *
791 795 * A direct socket is falling back to using STREAMS. The queue
792 796 * that is being passed down was created using tcp_open() with
793 797 * the SO_FALLBACK flag set. As a result, the queue is not
794 798 * associated with a conn, and the q_ptrs instead contain the
795 799 * dev and minor area that should be used.
796 800 *
797 801 * The 'issocket' flag indicates whether the FireEngine
798 802 * optimizations should be used. The common case would be that
799 803 * optimizations are enabled, and they might be subsequently
800 804 * disabled using the _SIOCSOCKFALLBACK ioctl.
801 805 */
802 806
803 807 /*
804 808 * An active connection is falling back to TPI. Gather all the information
805 809 * required by the STREAM head and TPI sonode and send it up.
806 810 */
807 811 static void
808 812 tcp_fallback_noneager(tcp_t *tcp, mblk_t *stropt_mp, queue_t *q,
809 813 boolean_t issocket, so_proto_quiesced_cb_t quiesced_cb,
810 814 sock_quiesce_arg_t *arg)
811 815 {
812 816 conn_t *connp = tcp->tcp_connp;
813 817 struct stroptions *stropt;
814 818 struct T_capability_ack tca;
815 819 struct sockaddr_in6 laddr, faddr;
816 820 socklen_t laddrlen, faddrlen;
817 821 short opts;
818 822 int error;
819 823 mblk_t *mp, *mpnext;
820 824
821 825 connp->conn_dev = (dev_t)RD(q)->q_ptr;
822 826 connp->conn_minor_arena = WR(q)->q_ptr;
823 827
824 828 RD(q)->q_ptr = WR(q)->q_ptr = connp;
825 829
826 830 connp->conn_rq = RD(q);
827 831 connp->conn_wq = WR(q);
828 832
829 833 WR(q)->q_qinfo = &tcp_sock_winit;
830 834
831 835 if (!issocket)
832 836 tcp_use_pure_tpi(tcp);
833 837
834 838 /*
835 839 * free the helper stream
836 840 */
837 841 ip_free_helper_stream(connp);
838 842
839 843 /*
840 844 * Notify the STREAM head about options
841 845 */
842 846 DB_TYPE(stropt_mp) = M_SETOPTS;
843 847 stropt = (struct stroptions *)stropt_mp->b_rptr;
844 848 stropt_mp->b_wptr += sizeof (struct stroptions);
845 849 stropt->so_flags = SO_HIWAT | SO_WROFF | SO_MAXBLK;
846 850
847 851 stropt->so_wroff = connp->conn_ht_iphc_len + (tcp->tcp_loopback ? 0 :
848 852 tcp->tcp_tcps->tcps_wroff_xtra);
849 853 if (tcp->tcp_snd_sack_ok)
850 854 stropt->so_wroff += TCPOPT_MAX_SACK_LEN;
851 855 stropt->so_hiwat = connp->conn_rcvbuf;
852 856 stropt->so_maxblk = tcp_maxpsz_set(tcp, B_FALSE);
853 857
854 858 putnext(RD(q), stropt_mp);
855 859
856 860 /*
857 861 * Collect the information needed to sync with the sonode
858 862 */
859 863 tcp_do_capability_ack(tcp, &tca, TC1_INFO|TC1_ACCEPTOR_ID);
860 864
861 865 laddrlen = faddrlen = sizeof (sin6_t);
862 866 (void) tcp_getsockname((sock_lower_handle_t)connp,
863 867 (struct sockaddr *)&laddr, &laddrlen, CRED());
864 868 error = tcp_getpeername((sock_lower_handle_t)connp,
865 869 (struct sockaddr *)&faddr, &faddrlen, CRED());
866 870 if (error != 0)
867 871 faddrlen = 0;
868 872
869 873 opts = 0;
870 874 if (connp->conn_oobinline)
871 875 opts |= SO_OOBINLINE;
872 876 if (connp->conn_ixa->ixa_flags & IXAF_DONTROUTE)
873 877 opts |= SO_DONTROUTE;
874 878
875 879 /*
876 880 * Notify the socket that the protocol is now quiescent,
877 881 * and it's therefore safe move data from the socket
878 882 * to the stream head.
879 883 */
880 884 mp = (*quiesced_cb)(connp->conn_upper_handle, arg, &tca,
881 885 (struct sockaddr *)&laddr, laddrlen,
882 886 (struct sockaddr *)&faddr, faddrlen, opts);
883 887
884 888 while (mp != NULL) {
885 889 mpnext = mp->b_next;
886 890 tcp->tcp_rcv_list = mp->b_next;
887 891 mp->b_next = NULL;
888 892 putnext(q, mp);
889 893 mp = mpnext;
890 894 }
891 895 ASSERT(tcp->tcp_rcv_last_head == NULL);
892 896 ASSERT(tcp->tcp_rcv_last_tail == NULL);
893 897 ASSERT(tcp->tcp_rcv_cnt == 0);
894 898
895 899 /*
896 900 * All eagers in q0 are marked as being non-STREAM, so they will
897 901 * make su_newconn upcalls when the handshake completes, which
898 902 * will fail (resulting in the conn being closed). So we just blow
899 903 * off everything in q0 instead of waiting for the inevitable.
900 904 */
901 905 if (tcp->tcp_conn_req_cnt_q0 != 0)
902 906 tcp_eager_cleanup(tcp, B_TRUE);
903 907 }
904 908
905 909 /*
906 910 * An eager is falling back to TPI. All we have to do is send
907 911 * up a T_CONN_IND.
908 912 */
909 913 static void
910 914 tcp_fallback_eager(tcp_t *eager, boolean_t issocket,
911 915 so_proto_quiesced_cb_t quiesced_cb, sock_quiesce_arg_t *arg)
912 916 {
913 917 conn_t *connp = eager->tcp_connp;
914 918 tcp_t *listener = eager->tcp_listener;
915 919 mblk_t *mp;
916 920
917 921 ASSERT(listener != NULL);
918 922
919 923 /*
920 924 * Notify the socket that the protocol is now quiescent,
921 925 * and it's therefore safe move data from the socket
922 926 * to tcp's rcv queue.
923 927 */
924 928 mp = (*quiesced_cb)(connp->conn_upper_handle, arg, NULL, NULL, 0,
925 929 NULL, 0, 0);
926 930
927 931 if (mp != NULL) {
928 932 ASSERT(eager->tcp_rcv_cnt == 0);
929 933
930 934 eager->tcp_rcv_list = mp;
931 935 eager->tcp_rcv_cnt = msgdsize(mp);
932 936 while (mp->b_next != NULL) {
933 937 mp = mp->b_next;
934 938 eager->tcp_rcv_cnt += msgdsize(mp);
935 939 }
936 940 eager->tcp_rcv_last_head = mp;
937 941 while (mp->b_cont)
938 942 mp = mp->b_cont;
939 943 eager->tcp_rcv_last_tail = mp;
940 944 if (eager->tcp_rcv_cnt > eager->tcp_rwnd)
941 945 eager->tcp_rwnd = 0;
942 946 else
943 947 eager->tcp_rwnd -= eager->tcp_rcv_cnt;
944 948 }
945 949
946 950 if (!issocket)
947 951 eager->tcp_issocket = B_FALSE;
948 952 /*
949 953 * The stream for this eager does not yet exist, so mark it as
950 954 * being detached.
951 955 */
952 956 eager->tcp_detached = B_TRUE;
953 957 eager->tcp_hard_binding = B_TRUE;
954 958 connp->conn_rq = listener->tcp_connp->conn_rq;
955 959 connp->conn_wq = listener->tcp_connp->conn_wq;
956 960
957 961 /* Send up the connection indication */
958 962 mp = eager->tcp_conn.tcp_eager_conn_ind;
959 963 ASSERT(mp != NULL);
960 964 eager->tcp_conn.tcp_eager_conn_ind = NULL;
961 965
962 966 /*
963 967 * TLI/XTI applications will get confused by
964 968 * sending eager as an option since it violates
965 969 * the option semantics. So remove the eager as
966 970 * option since TLI/XTI app doesn't need it anyway.
967 971 */
968 972 if (!issocket) {
969 973 struct T_conn_ind *conn_ind;
970 974
971 975 conn_ind = (struct T_conn_ind *)mp->b_rptr;
972 976 conn_ind->OPT_length = 0;
973 977 conn_ind->OPT_offset = 0;
974 978 }
975 979
976 980 /*
977 981 * Sockfs guarantees that the listener will not be closed
978 982 * during fallback. So we can safely use the listener's queue.
979 983 */
980 984 putnext(listener->tcp_connp->conn_rq, mp);
981 985 }
982 986
983 987
984 988 int
985 989 tcp_fallback(sock_lower_handle_t proto_handle, queue_t *q,
986 990 boolean_t direct_sockfs, so_proto_quiesced_cb_t quiesced_cb,
987 991 sock_quiesce_arg_t *arg)
988 992 {
989 993 tcp_t *tcp;
990 994 conn_t *connp = (conn_t *)proto_handle;
991 995 int error;
992 996 mblk_t *stropt_mp;
993 997 mblk_t *ordrel_mp;
994 998
995 999 tcp = connp->conn_tcp;
996 1000
997 1001 stropt_mp = allocb_wait(sizeof (struct stroptions), BPRI_HI, STR_NOSIG,
998 1002 NULL);
999 1003
1000 1004 /* Pre-allocate the T_ordrel_ind mblk. */
1001 1005 ASSERT(tcp->tcp_ordrel_mp == NULL);
1002 1006 ordrel_mp = allocb_wait(sizeof (struct T_ordrel_ind), BPRI_HI,
1003 1007 STR_NOSIG, NULL);
1004 1008 ordrel_mp->b_datap->db_type = M_PROTO;
1005 1009 ((struct T_ordrel_ind *)ordrel_mp->b_rptr)->PRIM_type = T_ORDREL_IND;
1006 1010 ordrel_mp->b_wptr += sizeof (struct T_ordrel_ind);
1007 1011
1008 1012 /*
1009 1013 * Enter the squeue so that no new packets can come in
1010 1014 */
1011 1015 error = squeue_synch_enter(connp, NULL);
1012 1016 if (error != 0) {
1013 1017 /* failed to enter, free all the pre-allocated messages. */
1014 1018 freeb(stropt_mp);
1015 1019 freeb(ordrel_mp);
1016 1020 return (ENOMEM);
1017 1021 }
1018 1022
1019 1023 /*
1020 1024 * Both endpoints must be of the same type (either STREAMS or
1021 1025 * non-STREAMS) for fusion to be enabled. So if we are fused,
1022 1026 * we have to unfuse.
1023 1027 */
1024 1028 if (tcp->tcp_fused)
1025 1029 tcp_unfuse(tcp);
1026 1030
1027 1031 if (tcp->tcp_listener != NULL) {
1028 1032 /* The eager will deal with opts when accept() is called */
1029 1033 freeb(stropt_mp);
1030 1034 tcp_fallback_eager(tcp, direct_sockfs, quiesced_cb, arg);
1031 1035 } else {
1032 1036 tcp_fallback_noneager(tcp, stropt_mp, q, direct_sockfs,
1033 1037 quiesced_cb, arg);
1034 1038 }
1035 1039
1036 1040 /*
1037 1041 * No longer a direct socket
1038 1042 *
1039 1043 * Note that we intentionally leave the upper_handle and upcalls
1040 1044 * intact, since eagers may still be using them.
1041 1045 */
1042 1046 connp->conn_flags &= ~IPCL_NONSTR;
1043 1047 tcp->tcp_ordrel_mp = ordrel_mp;
1044 1048
1045 1049 /*
1046 1050 * There should be atleast two ref's (IP + TCP)
1047 1051 */
1048 1052 ASSERT(connp->conn_ref >= 2);
1049 1053 squeue_synch_exit(connp);
1050 1054
1051 1055 return (0);
1052 1056 }
1053 1057
1054 1058 /*
1055 1059 * Notifies a non-STREAMS based listener about a new connection. This
1056 1060 * function is executed on the *eager*'s squeue once the 3 way handshake
1057 1061 * has completed. Note that the behavior differs from STREAMS, where the
1058 1062 * T_CONN_IND is sent up by tcp_send_conn_ind() while on the *listener*'s
1059 1063 * squeue.
1060 1064 *
1061 1065 * Returns B_TRUE if the notification succeeded and an upper handle was
1062 1066 * obtained. `tcp' should be closed on failure.
1063 1067 */
1064 1068 boolean_t
1065 1069 tcp_newconn_notify(tcp_t *tcp, ip_recv_attr_t *ira)
1066 1070 {
1067 1071 tcp_t *listener = tcp->tcp_listener;
1068 1072 conn_t *lconnp = listener->tcp_connp;
1069 1073 conn_t *econnp = tcp->tcp_connp;
1070 1074 tcp_t *tail;
1071 1075 ipaddr_t *addr_cache;
1072 1076 sock_upper_handle_t upper;
1073 1077 struct sock_proto_props sopp;
1074 1078
1075 1079 mutex_enter(&listener->tcp_eager_lock);
1076 1080 /*
1077 1081 * Take the eager out, if it is in the list of droppable eagers
1078 1082 * as we are here because the 3W handshake is over.
1079 1083 */
1080 1084 MAKE_UNDROPPABLE(tcp);
1081 1085 /*
1082 1086 * The eager already has an extra ref put in tcp_input_data
1083 1087 * so that it stays till accept comes back even though it
1084 1088 * might get into TCPS_CLOSED as a result of a TH_RST etc.
1085 1089 */
1086 1090 ASSERT(listener->tcp_conn_req_cnt_q0 > 0);
1087 1091 listener->tcp_conn_req_cnt_q0--;
1088 1092 listener->tcp_conn_req_cnt_q++;
1089 1093
1090 1094 /* Move from SYN_RCVD to ESTABLISHED list */
1091 1095 tcp->tcp_eager_next_q0->tcp_eager_prev_q0 = tcp->tcp_eager_prev_q0;
1092 1096 tcp->tcp_eager_prev_q0->tcp_eager_next_q0 = tcp->tcp_eager_next_q0;
1093 1097 tcp->tcp_eager_prev_q0 = NULL;
1094 1098 tcp->tcp_eager_next_q0 = NULL;
1095 1099
1096 1100 /*
1097 1101 * Insert at end of the queue because connections are accepted
1098 1102 * in chronological order. Leaving the older connections at front
1099 1103 * of the queue helps reducing search time.
1100 1104 */
1101 1105 tail = listener->tcp_eager_last_q;
1102 1106 if (tail != NULL)
1103 1107 tail->tcp_eager_next_q = tcp;
1104 1108 else
1105 1109 listener->tcp_eager_next_q = tcp;
1106 1110 listener->tcp_eager_last_q = tcp;
1107 1111 tcp->tcp_eager_next_q = NULL;
1108 1112
1109 1113 /* we have timed out before */
1110 1114 if (tcp->tcp_syn_rcvd_timeout != 0) {
1111 1115 tcp->tcp_syn_rcvd_timeout = 0;
1112 1116 listener->tcp_syn_rcvd_timeout--;
1113 1117 if (listener->tcp_syn_defense &&
1114 1118 listener->tcp_syn_rcvd_timeout <=
1115 1119 (listener->tcp_tcps->tcps_conn_req_max_q0 >> 5) &&
1116 1120 10*MINUTES < TICK_TO_MSEC(ddi_get_lbolt64() -
1117 1121 listener->tcp_last_rcv_lbolt)) {
1118 1122 /*
1119 1123 * Turn off the defense mode if we
1120 1124 * believe the SYN attack is over.
1121 1125 */
1122 1126 listener->tcp_syn_defense = B_FALSE;
1123 1127 if (listener->tcp_ip_addr_cache) {
1124 1128 kmem_free((void *)listener->tcp_ip_addr_cache,
1125 1129 IP_ADDR_CACHE_SIZE * sizeof (ipaddr_t));
1126 1130 listener->tcp_ip_addr_cache = NULL;
1127 1131 }
1128 1132 }
1129 1133 }
1130 1134 addr_cache = (ipaddr_t *)(listener->tcp_ip_addr_cache);
1131 1135 if (addr_cache != NULL) {
1132 1136 /*
1133 1137 * We have finished a 3-way handshake with this
1134 1138 * remote host. This proves the IP addr is good.
1135 1139 * Cache it!
1136 1140 */
1137 1141 addr_cache[IP_ADDR_CACHE_HASH(tcp->tcp_connp->conn_faddr_v4)] =
1138 1142 tcp->tcp_connp->conn_faddr_v4;
1139 1143 }
1140 1144 mutex_exit(&listener->tcp_eager_lock);
1141 1145
1142 1146 /*
1143 1147 * Notify the ULP about the newconn. It is guaranteed that no
1144 1148 * tcp_accept() call will be made for the eager if the
1145 1149 * notification fails.
1146 1150 */
1147 1151 if ((upper = (*lconnp->conn_upcalls->su_newconn)
1148 1152 (lconnp->conn_upper_handle, (sock_lower_handle_t)econnp,
1149 1153 &sock_tcp_downcalls, ira->ira_cred, ira->ira_cpid,
1150 1154 &econnp->conn_upcalls)) == NULL) {
1151 1155 return (B_FALSE);
1152 1156 }
1153 1157 econnp->conn_upper_handle = upper;
1154 1158
1155 1159 tcp->tcp_detached = B_FALSE;
1156 1160 tcp->tcp_hard_binding = B_FALSE;
1157 1161 tcp->tcp_tconnind_started = B_TRUE;
1158 1162
1159 1163 if (econnp->conn_keepalive) {
1160 1164 tcp->tcp_ka_last_intrvl = 0;
1161 1165 tcp->tcp_ka_tid = TCP_TIMER(tcp, tcp_keepalive_timer,
1162 1166 tcp->tcp_ka_interval);
1163 1167 }
1164 1168
1165 1169 /* Update the necessary parameters */
1166 1170 tcp_get_proto_props(tcp, &sopp);
1167 1171
1168 1172 (*econnp->conn_upcalls->su_set_proto_props)
1169 1173 (econnp->conn_upper_handle, &sopp);
1170 1174
1171 1175 return (B_TRUE);
1172 1176 }
↓ open down ↓ |
393 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX