4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2011, Joyent Inc. All rights reserved.
25 * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright (c) 2013, 2017 by Delphix. All rights reserved.
27 * Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
28 */
29 /* Copyright (c) 1990 Mentat Inc. */
30
31 #include <sys/types.h>
32 #include <sys/stream.h>
33 #include <sys/strsun.h>
34 #include <sys/strsubr.h>
35 #include <sys/stropts.h>
36 #include <sys/strlog.h>
37 #define _SUN_TPI_VERSION 2
38 #include <sys/tihdr.h>
39 #include <sys/timod.h>
40 #include <sys/ddi.h>
41 #include <sys/sunddi.h>
42 #include <sys/suntpi.h>
43 #include <sys/xti_inet.h>
44 #include <sys/cmn_err.h>
4317 ASSERT(cr != NULL);
4318
4319 if (tcp->tcp_state >= TCPS_BOUND) {
4320 if ((tcp->tcp_state == TCPS_BOUND ||
4321 tcp->tcp_state == TCPS_LISTEN) && backlog > 0) {
4322 /*
4323 * Handle listen() increasing backlog.
4324 * This is more "liberal" then what the TPI spec
4325 * requires but is needed to avoid a t_unbind
4326 * when handling listen() since the port number
4327 * might be "stolen" between the unbind and bind.
4328 */
4329 goto do_listen;
4330 }
4331 if (connp->conn_debug) {
4332 (void) strlog(TCP_MOD_ID, 0, 1, SL_ERROR|SL_TRACE,
4333 "tcp_listen: bad state, %d", tcp->tcp_state);
4334 }
4335 return (-TOUTSTATE);
4336 } else {
4337 if (sa == NULL) {
4338 sin6_t addr;
4339 sin_t *sin;
4340 sin6_t *sin6;
4341
4342 ASSERT(IPCL_IS_NONSTR(connp));
4343 /* Do an implicit bind: Request for a generic port. */
4344 if (connp->conn_family == AF_INET) {
4345 len = sizeof (sin_t);
4346 sin = (sin_t *)&addr;
4347 *sin = sin_null;
4348 sin->sin_family = AF_INET;
4349 } else {
4350 ASSERT(connp->conn_family == AF_INET6);
4351 len = sizeof (sin6_t);
4352 sin6 = (sin6_t *)&addr;
4353 *sin6 = sin6_null;
4354 sin6->sin6_family = AF_INET6;
4355 }
4356 sa = (struct sockaddr *)&addr;
4357 }
4358
4359 error = tcp_bind_check(connp, sa, len, cr,
4360 bind_to_req_port_only);
4361 if (error)
|
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright 2019 Joyent, Inc.
25 * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
26 * Copyright (c) 2013, 2017 by Delphix. All rights reserved.
27 * Copyright 2014, OmniTI Computer Consulting, Inc. All rights reserved.
28 */
29 /* Copyright (c) 1990 Mentat Inc. */
30
31 #include <sys/types.h>
32 #include <sys/stream.h>
33 #include <sys/strsun.h>
34 #include <sys/strsubr.h>
35 #include <sys/stropts.h>
36 #include <sys/strlog.h>
37 #define _SUN_TPI_VERSION 2
38 #include <sys/tihdr.h>
39 #include <sys/timod.h>
40 #include <sys/ddi.h>
41 #include <sys/sunddi.h>
42 #include <sys/suntpi.h>
43 #include <sys/xti_inet.h>
44 #include <sys/cmn_err.h>
4317 ASSERT(cr != NULL);
4318
4319 if (tcp->tcp_state >= TCPS_BOUND) {
4320 if ((tcp->tcp_state == TCPS_BOUND ||
4321 tcp->tcp_state == TCPS_LISTEN) && backlog > 0) {
4322 /*
4323 * Handle listen() increasing backlog.
4324 * This is more "liberal" then what the TPI spec
4325 * requires but is needed to avoid a t_unbind
4326 * when handling listen() since the port number
4327 * might be "stolen" between the unbind and bind.
4328 */
4329 goto do_listen;
4330 }
4331 if (connp->conn_debug) {
4332 (void) strlog(TCP_MOD_ID, 0, 1, SL_ERROR|SL_TRACE,
4333 "tcp_listen: bad state, %d", tcp->tcp_state);
4334 }
4335 return (-TOUTSTATE);
4336 } else {
4337 sin6_t addr;
4338 sin_t *sin;
4339 sin6_t *sin6;
4340
4341 if (sa == NULL) {
4342 ASSERT(IPCL_IS_NONSTR(connp));
4343 /* Do an implicit bind: Request for a generic port. */
4344 if (connp->conn_family == AF_INET) {
4345 len = sizeof (sin_t);
4346 sin = (sin_t *)&addr;
4347 *sin = sin_null;
4348 sin->sin_family = AF_INET;
4349 } else {
4350 ASSERT(connp->conn_family == AF_INET6);
4351 len = sizeof (sin6_t);
4352 sin6 = (sin6_t *)&addr;
4353 *sin6 = sin6_null;
4354 sin6->sin6_family = AF_INET6;
4355 }
4356 sa = (struct sockaddr *)&addr;
4357 }
4358
4359 error = tcp_bind_check(connp, sa, len, cr,
4360 bind_to_req_port_only);
4361 if (error)
|