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 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
24 */
25
26 /*
27 * IP PACKET CLASSIFIER
28 *
29 * The IP packet classifier provides mapping between IP packets and persistent
30 * connection state for connection-oriented protocols. It also provides
31 * interface for managing connection states.
32 *
33 * The connection state is kept in conn_t data structure and contains, among
34 * other things:
35 *
36 * o local/remote address and ports
37 * o Transport protocol
38 * o squeue for the connection (for TCP only)
39 * o reference counter
40 * o Connection state
41 * o hash table linkage
42 * o interface/ire information
43 * o credentials
2728 mib2_socketInfoEntry_t *
2729 conn_get_socket_info(conn_t *connp, mib2_socketInfoEntry_t *sie)
2730 {
2731 vnode_t *vn = NULL;
2732 vattr_t attr;
2733 uint64_t flags = 0;
2734
2735 /*
2736 * If the connection is closing, it is not safe to make an upcall or
2737 * access the stream associated with the connection.
2738 * The callers of this function have a reference on connp itself
2739 * so, as long as it is not closing, it's safe to continue.
2740 */
2741 mutex_enter(&connp->conn_lock);
2742
2743 if ((connp->conn_state_flags & CONN_CLOSING)) {
2744 mutex_exit(&connp->conn_lock);
2745 return (NULL);
2746 }
2747
2748 mutex_exit(&connp->conn_lock);
2749
2750 if (connp->conn_upper_handle != NULL) {
2751 vn = (*connp->conn_upcalls->su_get_vnode)
2752 (connp->conn_upper_handle);
2753 } else if (!IPCL_IS_NONSTR(connp) && connp->conn_rq != NULL) {
2754 vn = STREAM(connp->conn_rq)->sd_pvnode;
2755 if (vn != NULL)
2756 VN_HOLD(vn);
2757 flags |= MIB2_SOCKINFO_STREAM;
2758 }
2759
2760 if (vn == NULL || VOP_GETATTR(vn, &attr, 0, CRED(), NULL) != 0) {
2761 if (vn != NULL)
2762 VN_RELE(vn);
2763 return (NULL);
2764 }
2765
2766 VN_RELE(vn);
2767
2768 bzero(sie, sizeof (*sie));
2769
2770 sie->sie_flags = flags;
2771 sie->sie_inode = attr.va_nodeid;
2772 sie->sie_dev = attr.va_rdev;
2773
2774 return (sie);
2775 }
|
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 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2019 OmniOS Community Edition (OmniOSce) Association.
24 * Copyright 2020 Joyent, Inc.
25 */
26
27 /*
28 * IP PACKET CLASSIFIER
29 *
30 * The IP packet classifier provides mapping between IP packets and persistent
31 * connection state for connection-oriented protocols. It also provides
32 * interface for managing connection states.
33 *
34 * The connection state is kept in conn_t data structure and contains, among
35 * other things:
36 *
37 * o local/remote address and ports
38 * o Transport protocol
39 * o squeue for the connection (for TCP only)
40 * o reference counter
41 * o Connection state
42 * o hash table linkage
43 * o interface/ire information
44 * o credentials
2729 mib2_socketInfoEntry_t *
2730 conn_get_socket_info(conn_t *connp, mib2_socketInfoEntry_t *sie)
2731 {
2732 vnode_t *vn = NULL;
2733 vattr_t attr;
2734 uint64_t flags = 0;
2735
2736 /*
2737 * If the connection is closing, it is not safe to make an upcall or
2738 * access the stream associated with the connection.
2739 * The callers of this function have a reference on connp itself
2740 * so, as long as it is not closing, it's safe to continue.
2741 */
2742 mutex_enter(&connp->conn_lock);
2743
2744 if ((connp->conn_state_flags & CONN_CLOSING)) {
2745 mutex_exit(&connp->conn_lock);
2746 return (NULL);
2747 }
2748
2749 /*
2750 * Continue to hold conn_lock because we don't want to race with an
2751 * in-progress close, which will have set-to-NULL (and destroyed
2752 * upper_handle, aka sonode (and vnode)) BEFORE setting CONN_CLOSING.
2753 */
2754
2755 if (connp->conn_upper_handle != NULL) {
2756 vn = (*connp->conn_upcalls->su_get_vnode)
2757 (connp->conn_upper_handle);
2758 } else if (!IPCL_IS_NONSTR(connp) && connp->conn_rq != NULL) {
2759 vn = STREAM(connp->conn_rq)->sd_pvnode;
2760 if (vn != NULL)
2761 VN_HOLD(vn);
2762 flags |= MIB2_SOCKINFO_STREAM;
2763 }
2764
2765 mutex_exit(&connp->conn_lock);
2766
2767 if (vn == NULL || VOP_GETATTR(vn, &attr, 0, CRED(), NULL) != 0) {
2768 if (vn != NULL)
2769 VN_RELE(vn);
2770 return (NULL);
2771 }
2772
2773 VN_RELE(vn);
2774
2775 bzero(sie, sizeof (*sie));
2776
2777 sie->sie_flags = flags;
2778 sie->sie_inode = attr.va_nodeid;
2779 sie->sie_dev = attr.va_rdev;
2780
2781 return (sie);
2782 }
|