^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * Copyright (c) 2006, 2018 Oracle and/or its affiliates. All rights reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * This software is available to you under a choice of one of two
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * licenses. You may choose to be licensed under the terms of the GNU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * General Public License (GPL) Version 2, available from the file
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * COPYING in the main directory of this source tree, or the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * OpenIB.org BSD license below:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Redistribution and use in source and binary forms, with or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * without modification, are permitted provided that the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * conditions are met:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * - Redistributions of source code must retain the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * disclaimer.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * - Redistributions in binary form must reproduce the above
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) * copyright notice, this list of conditions and the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * disclaimer in the documentation and/or other materials
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * provided with the distribution.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) * SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #include <linux/in.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) #include <net/tcp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #include <net/addrconf.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) #include "rds.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #include "tcp.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) /* only for info exporting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) static DEFINE_SPINLOCK(rds_tcp_tc_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) static LIST_HEAD(rds_tcp_tc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* rds_tcp_tc_count counts only IPv4 connections.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * rds6_tcp_tc_count counts both IPv4 and IPv6 connections.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) static unsigned int rds_tcp_tc_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static unsigned int rds6_tcp_tc_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) /* Track rds_tcp_connection structs so they can be cleaned up */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) static DEFINE_SPINLOCK(rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) static LIST_HEAD(rds_tcp_conn_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static atomic_t rds_tcp_unloading = ATOMIC_INIT(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) static struct kmem_cache *rds_tcp_conn_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) static int rds_tcp_skbuf_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) void *buffer, size_t *lenp, loff_t *fpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int rds_tcp_min_sndbuf = SOCK_MIN_SNDBUF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int rds_tcp_min_rcvbuf = SOCK_MIN_RCVBUF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static struct ctl_table rds_tcp_sysctl_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define RDS_TCP_SNDBUF 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) .procname = "rds_tcp_sndbuf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* data is per-net pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) .maxlen = sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .mode = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .proc_handler = rds_tcp_skbuf_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .extra1 = &rds_tcp_min_sndbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) #define RDS_TCP_RCVBUF 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) .procname = "rds_tcp_rcvbuf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* data is per-net pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) .maxlen = sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) .mode = 0644,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) .proc_handler = rds_tcp_skbuf_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) .extra1 = &rds_tcp_min_rcvbuf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) u32 rds_tcp_write_seq(struct rds_tcp_connection *tc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* seq# of the last byte of data in tcp send buffer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) return tcp_sk(tc->t_sock->sk)->write_seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) u32 rds_tcp_snd_una(struct rds_tcp_connection *tc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) return tcp_sk(tc->t_sock->sk)->snd_una;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) void rds_tcp_restore_callbacks(struct socket *sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) struct rds_tcp_connection *tc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) rdsdebug("restoring sock %p callbacks from tc %p\n", sock, tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) write_lock_bh(&sock->sk->sk_callback_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /* done under the callback_lock to serialize with write_space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) spin_lock(&rds_tcp_tc_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) list_del_init(&tc->t_list_item);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) rds6_tcp_tc_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) if (!tc->t_cpath->cp_conn->c_isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) rds_tcp_tc_count--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) spin_unlock(&rds_tcp_tc_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) tc->t_sock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) sock->sk->sk_write_space = tc->t_orig_write_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) sock->sk->sk_data_ready = tc->t_orig_data_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) sock->sk->sk_state_change = tc->t_orig_state_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) sock->sk->sk_user_data = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) write_unlock_bh(&sock->sk->sk_callback_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) * rds_tcp_reset_callbacks() switches the to the new sock and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) * returns the existing tc->t_sock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * The only functions that set tc->t_sock are rds_tcp_set_callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * and rds_tcp_reset_callbacks. Send and receive trust that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * it is set. The absence of RDS_CONN_UP bit protects those paths
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * from being called while it isn't set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void rds_tcp_reset_callbacks(struct socket *sock,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) struct rds_conn_path *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct rds_tcp_connection *tc = cp->cp_transport_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct socket *osock = tc->t_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if (!osock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) goto newsock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /* Need to resolve a duelling SYN between peers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * We have an outstanding SYN to this peer, which may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * potentially have transitioned to the RDS_CONN_UP state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) * so we must quiesce any send threads before resetting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * cp_transport_data. We quiesce these threads by setting
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * cp_state to something other than RDS_CONN_UP, and then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * waiting for any existing threads in rds_send_xmit to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) * complete release_in_xmit(). (Subsequent threads entering
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) * rds_send_xmit() will bail on !rds_conn_up().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) * However an incoming syn-ack at this point would end up
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) * marking the conn as RDS_CONN_UP, and would again permit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * rds_send_xmi() threads through, so ideally we would
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) * synchronize on RDS_CONN_UP after lock_sock(), but cannot
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) * do that: waiting on !RDS_IN_XMIT after lock_sock() may
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) * end up deadlocking with tcp_sendmsg(), and the RDS_IN_XMIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) * would not get set. As a result, we set c_state to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) * RDS_CONN_RESETTTING, to ensure that rds_tcp_state_change
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) * cannot mark rds_conn_path_up() in the window before lock_sock()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) atomic_set(&cp->cp_state, RDS_CONN_RESETTING);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) wait_event(cp->cp_waitq, !test_bit(RDS_IN_XMIT, &cp->cp_flags));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) lock_sock(osock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /* reset receive side state for rds_tcp_data_recv() for osock */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) cancel_delayed_work_sync(&cp->cp_send_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) cancel_delayed_work_sync(&cp->cp_recv_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) if (tc->t_tinc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) rds_inc_put(&tc->t_tinc->ti_inc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) tc->t_tinc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) tc->t_tinc_hdr_rem = sizeof(struct rds_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) tc->t_tinc_data_rem = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) rds_tcp_restore_callbacks(osock, tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) release_sock(osock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) sock_release(osock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) newsock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) rds_send_path_reset(cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) lock_sock(sock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) rds_tcp_set_callbacks(sock, cp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) release_sock(sock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) /* Add tc to rds_tcp_tc_list and set tc->t_sock. See comments
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) * above rds_tcp_reset_callbacks for notes about synchronization
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) * with data path
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) void rds_tcp_set_callbacks(struct socket *sock, struct rds_conn_path *cp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct rds_tcp_connection *tc = cp->cp_transport_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) rdsdebug("setting sock %p callbacks to tc %p\n", sock, tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) write_lock_bh(&sock->sk->sk_callback_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /* done under the callback_lock to serialize with write_space */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) spin_lock(&rds_tcp_tc_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) list_add_tail(&tc->t_list_item, &rds_tcp_tc_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) rds6_tcp_tc_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (!tc->t_cpath->cp_conn->c_isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) rds_tcp_tc_count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) spin_unlock(&rds_tcp_tc_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) /* accepted sockets need our listen data ready undone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (sock->sk->sk_data_ready == rds_tcp_listen_data_ready)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) sock->sk->sk_data_ready = sock->sk->sk_user_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) tc->t_sock = sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) tc->t_cpath = cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) tc->t_orig_data_ready = sock->sk->sk_data_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) tc->t_orig_write_space = sock->sk->sk_write_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) tc->t_orig_state_change = sock->sk->sk_state_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) sock->sk->sk_user_data = cp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) sock->sk->sk_data_ready = rds_tcp_data_ready;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) sock->sk->sk_write_space = rds_tcp_write_space;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) sock->sk->sk_state_change = rds_tcp_state_change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) write_unlock_bh(&sock->sk->sk_callback_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) /* Handle RDS_INFO_TCP_SOCKETS socket option. It only returns IPv4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) * connections for backward compatibility.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) static void rds_tcp_tc_info(struct socket *rds_sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) struct rds_info_tcp_socket tsinfo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct rds_tcp_connection *tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) spin_lock_irqsave(&rds_tcp_tc_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) if (len / sizeof(tsinfo) < rds_tcp_tc_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) list_for_each_entry(tc, &rds_tcp_tc_list, t_list_item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct inet_sock *inet = inet_sk(tc->t_sock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) if (tc->t_cpath->cp_conn->c_isv6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) tsinfo.local_addr = inet->inet_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) tsinfo.local_port = inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) tsinfo.peer_addr = inet->inet_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) tsinfo.peer_port = inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) tsinfo.hdr_rem = tc->t_tinc_hdr_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) tsinfo.data_rem = tc->t_tinc_data_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) tsinfo.last_sent_nxt = tc->t_last_sent_nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) tsinfo.last_expected_una = tc->t_last_expected_una;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) tsinfo.last_seen_una = tc->t_last_seen_una;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) tsinfo.tos = tc->t_cpath->cp_conn->c_tos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) rds_info_copy(iter, &tsinfo, sizeof(tsinfo));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) lens->nr = rds_tcp_tc_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) lens->each = sizeof(tsinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) spin_unlock_irqrestore(&rds_tcp_tc_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) /* Handle RDS6_INFO_TCP_SOCKETS socket option. It returns both IPv4 and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) * IPv6 connections. IPv4 connection address is returned in an IPv4 mapped
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) * address.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) static void rds6_tcp_tc_info(struct socket *sock, unsigned int len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) struct rds_info_iterator *iter,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) struct rds_info_lengths *lens)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) struct rds6_info_tcp_socket tsinfo6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct rds_tcp_connection *tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) spin_lock_irqsave(&rds_tcp_tc_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) if (len / sizeof(tsinfo6) < rds6_tcp_tc_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) list_for_each_entry(tc, &rds_tcp_tc_list, t_list_item) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) struct sock *sk = tc->t_sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) struct inet_sock *inet = inet_sk(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) tsinfo6.local_addr = sk->sk_v6_rcv_saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) tsinfo6.local_port = inet->inet_sport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) tsinfo6.peer_addr = sk->sk_v6_daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) tsinfo6.peer_port = inet->inet_dport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) tsinfo6.hdr_rem = tc->t_tinc_hdr_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) tsinfo6.data_rem = tc->t_tinc_data_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) tsinfo6.last_sent_nxt = tc->t_last_sent_nxt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) tsinfo6.last_expected_una = tc->t_last_expected_una;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) tsinfo6.last_seen_una = tc->t_last_seen_una;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) rds_info_copy(iter, &tsinfo6, sizeof(tsinfo6));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) lens->nr = rds6_tcp_tc_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) lens->each = sizeof(tsinfo6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) spin_unlock_irqrestore(&rds_tcp_tc_list_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) int rds_tcp_laddr_check(struct net *net, const struct in6_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) __u32 scope_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) struct net_device *dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) if (ipv6_addr_v4mapped(addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (inet_addr_type(net, addr->s6_addr32[3]) == RTN_LOCAL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) /* If the scope_id is specified, check only those addresses
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) * hosted on the specified interface.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) if (scope_id != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) dev = dev_get_by_index_rcu(net, scope_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) /* scope_id is not valid... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (!dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) ret = ipv6_chk_addr(net, addr, dev, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) static void rds_tcp_conn_free(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) struct rds_tcp_connection *tc = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) rdsdebug("freeing tc %p\n", tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) spin_lock_irqsave(&rds_tcp_conn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) if (!tc->t_tcp_node_detached)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) list_del(&tc->t_tcp_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) spin_unlock_irqrestore(&rds_tcp_conn_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) kmem_cache_free(rds_tcp_conn_slab, tc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static int rds_tcp_conn_alloc(struct rds_connection *conn, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct rds_tcp_connection *tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) for (i = 0; i < RDS_MPATH_WORKERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) tc = kmem_cache_alloc(rds_tcp_conn_slab, gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (!tc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) mutex_init(&tc->t_conn_path_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) tc->t_sock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) tc->t_tinc = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) tc->t_tinc_hdr_rem = sizeof(struct rds_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) tc->t_tinc_data_rem = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) conn->c_path[i].cp_transport_data = tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) tc->t_cpath = &conn->c_path[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) tc->t_tcp_node_detached = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) rdsdebug("rds_conn_path [%d] tc %p\n", i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) conn->c_path[i].cp_transport_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) spin_lock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) for (i = 0; i < RDS_MPATH_WORKERS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) tc = conn->c_path[i].cp_transport_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) tc->t_tcp_node_detached = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) list_add_tail(&tc->t_tcp_node, &rds_tcp_conn_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) spin_unlock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) for (j = 0; j < i; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) rds_tcp_conn_free(conn->c_path[j].cp_transport_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) static bool list_has_conn(struct list_head *list, struct rds_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) struct rds_tcp_connection *tc, *_tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) list_for_each_entry_safe(tc, _tc, list, t_tcp_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) if (tc->t_cpath->cp_conn == conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) static void rds_tcp_set_unloading(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) atomic_set(&rds_tcp_unloading, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) static bool rds_tcp_is_unloading(struct rds_connection *conn)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return atomic_read(&rds_tcp_unloading) != 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static void rds_tcp_destroy_conns(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) struct rds_tcp_connection *tc, *_tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) LIST_HEAD(tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* avoid calling conn_destroy with irqs off */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) spin_lock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) list_move_tail(&tc->t_tcp_node, &tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) spin_unlock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) rds_conn_destroy(tc->t_cpath->cp_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) static void rds_tcp_exit(void);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) static u8 rds_tcp_get_tos_map(u8 tos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) /* all user tos mapped to default 0 for TCP transport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct rds_transport rds_tcp_transport = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) .laddr_check = rds_tcp_laddr_check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) .xmit_path_prepare = rds_tcp_xmit_path_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) .xmit_path_complete = rds_tcp_xmit_path_complete,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) .xmit = rds_tcp_xmit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) .recv_path = rds_tcp_recv_path,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) .conn_alloc = rds_tcp_conn_alloc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) .conn_free = rds_tcp_conn_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) .conn_path_connect = rds_tcp_conn_path_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) .conn_path_shutdown = rds_tcp_conn_path_shutdown,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) .inc_copy_to_user = rds_tcp_inc_copy_to_user,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) .inc_free = rds_tcp_inc_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) .stats_info_copy = rds_tcp_stats_info_copy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) .exit = rds_tcp_exit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) .get_tos_map = rds_tcp_get_tos_map,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) .t_owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) .t_name = "tcp",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) .t_type = RDS_TRANS_TCP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) .t_prefer_loopback = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) .t_mp_capable = 1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) .t_unloading = rds_tcp_is_unloading,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) static unsigned int rds_tcp_netid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /* per-network namespace private data for this module */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) struct rds_tcp_net {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) struct socket *rds_tcp_listen_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) struct work_struct rds_tcp_accept_w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) struct ctl_table_header *rds_tcp_sysctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) struct ctl_table *ctl_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) int sndbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) int rcvbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) /* All module specific customizations to the RDS-TCP socket should be done in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) * rds_tcp_tune() and applied after socket creation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) void rds_tcp_tune(struct socket *sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) struct sock *sk = sock->sk;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) tcp_sock_set_nodelay(sock->sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) lock_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) if (rtn->sndbuf_size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) sk->sk_sndbuf = rtn->sndbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) sk->sk_userlocks |= SOCK_SNDBUF_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (rtn->rcvbuf_size > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) sk->sk_rcvbuf = rtn->rcvbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) sk->sk_userlocks |= SOCK_RCVBUF_LOCK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) release_sock(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) static void rds_tcp_accept_worker(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) struct rds_tcp_net *rtn = container_of(work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) struct rds_tcp_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) rds_tcp_accept_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) while (rds_tcp_accept_one(rtn->rds_tcp_listen_sock) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) void rds_tcp_accept_work(struct sock *sk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) struct net *net = sock_net(sk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) queue_work(rds_wq, &rtn->rds_tcp_accept_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) static __net_init int rds_tcp_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) struct ctl_table *tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) memset(rtn, 0, sizeof(*rtn));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) /* {snd, rcv}buf_size default to 0, which implies we let the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) * stack pick the value, and permit auto-tuning of buffer size.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (net == &init_net) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) tbl = rds_tcp_sysctl_table;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) tbl = kmemdup(rds_tcp_sysctl_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) sizeof(rds_tcp_sysctl_table), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) if (!tbl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) pr_warn("could not set allocate sysctl table\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) rtn->ctl_table = tbl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) tbl[RDS_TCP_SNDBUF].data = &rtn->sndbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) tbl[RDS_TCP_RCVBUF].data = &rtn->rcvbuf_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) rtn->rds_tcp_sysctl = register_net_sysctl(net, "net/rds/tcp", tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) if (!rtn->rds_tcp_sysctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) pr_warn("could not register sysctl\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) if (!rtn->rds_tcp_listen_sock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) pr_warn("could not set up IPv6 listen sock\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) /* Try IPv4 as some systems disable IPv6 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) rtn->rds_tcp_listen_sock = rds_tcp_listen_init(net, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) if (!rtn->rds_tcp_listen_sock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) rtn->rds_tcp_sysctl = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) err = -EAFNOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) INIT_WORK(&rtn->rds_tcp_accept_w, rds_tcp_accept_worker);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) if (net != &init_net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) kfree(tbl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static void rds_tcp_kill_sock(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) struct rds_tcp_connection *tc, *_tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) LIST_HEAD(tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct socket *lsock = rtn->rds_tcp_listen_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) rtn->rds_tcp_listen_sock = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) rds_tcp_listen_stop(lsock, &rtn->rds_tcp_accept_w);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) spin_lock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct net *c_net = read_pnet(&tc->t_cpath->cp_conn->c_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) if (net != c_net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) if (!list_has_conn(&tmp_list, tc->t_cpath->cp_conn)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) list_move_tail(&tc->t_tcp_node, &tmp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) list_del(&tc->t_tcp_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) tc->t_tcp_node_detached = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) spin_unlock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) list_for_each_entry_safe(tc, _tc, &tmp_list, t_tcp_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) rds_conn_destroy(tc->t_cpath->cp_conn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) static void __net_exit rds_tcp_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) rds_tcp_kill_sock(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (rtn->rds_tcp_sysctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) unregister_net_sysctl_table(rtn->rds_tcp_sysctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) if (net != &init_net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) kfree(rtn->ctl_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) static struct pernet_operations rds_tcp_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) .init = rds_tcp_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) .exit = rds_tcp_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) .id = &rds_tcp_netid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) .size = sizeof(struct rds_tcp_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) void *rds_tcp_listen_sock_def_readable(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) struct rds_tcp_net *rtn = net_generic(net, rds_tcp_netid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) struct socket *lsock = rtn->rds_tcp_listen_sock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) if (!lsock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) return lsock->sk->sk_user_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) /* when sysctl is used to modify some kernel socket parameters,this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) * function resets the RDS connections in that netns so that we can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) * restart with new parameters. The assumption is that such reset
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) * events are few and far-between.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) static void rds_tcp_sysctl_reset(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) struct rds_tcp_connection *tc, *_tc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) spin_lock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) list_for_each_entry_safe(tc, _tc, &rds_tcp_conn_list, t_tcp_node) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) struct net *c_net = read_pnet(&tc->t_cpath->cp_conn->c_net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) if (net != c_net || !tc->t_sock)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) /* reconnect with new parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) rds_conn_path_drop(tc->t_cpath, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) spin_unlock_irq(&rds_tcp_conn_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) static int rds_tcp_skbuf_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) void *buffer, size_t *lenp, loff_t *fpos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) struct net *net = current->nsproxy->net_ns;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) err = proc_dointvec_minmax(ctl, write, buffer, lenp, fpos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) pr_warn("Invalid input. Must be >= %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) *(int *)(ctl->extra1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) if (write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) rds_tcp_sysctl_reset(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) static void rds_tcp_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) rds_tcp_set_unloading();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) synchronize_rcu();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) rds_info_deregister_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) rds_info_deregister_func(RDS6_INFO_TCP_SOCKETS, rds6_tcp_tc_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) unregister_pernet_device(&rds_tcp_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) rds_tcp_destroy_conns();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) rds_trans_unregister(&rds_tcp_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) rds_tcp_recv_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) kmem_cache_destroy(rds_tcp_conn_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) module_exit(rds_tcp_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) static int rds_tcp_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) rds_tcp_conn_slab = kmem_cache_create("rds_tcp_connection",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) sizeof(struct rds_tcp_connection),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) 0, 0, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) if (!rds_tcp_conn_slab) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) ret = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) ret = rds_tcp_recv_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) goto out_slab;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) ret = register_pernet_device(&rds_tcp_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) goto out_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) rds_trans_register(&rds_tcp_transport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) rds_info_register_func(RDS_INFO_TCP_SOCKETS, rds_tcp_tc_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) #if IS_ENABLED(CONFIG_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) rds_info_register_func(RDS6_INFO_TCP_SOCKETS, rds6_tcp_tc_info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) out_recv:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) rds_tcp_recv_exit();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) out_slab:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) kmem_cache_destroy(rds_tcp_conn_slab);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) module_init(rds_tcp_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) MODULE_AUTHOR("Oracle Corporation <rds-devel@oss.oracle.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) MODULE_DESCRIPTION("RDS: TCP transport");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) MODULE_LICENSE("Dual BSD/GPL");