#include <linux/types.h>
#include <linux/string.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/capability.h>
#include <linux/pagemap.h>
#include <linux/errno.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/net.h>
#include <linux/mm.h>
#include <linux/un.h>
#include <linux/udp.h>
#include <linux/tcp.h>
#include <linux/sunrpc/clnt.h>
#include <linux/sunrpc/addr.h>
#include <linux/sunrpc/sched.h>
#include <linux/sunrpc/svcsock.h>
#include <linux/sunrpc/xprtsock.h>
#include <linux/file.h>
#ifdef CONFIG_SUNRPC_BACKCHANNEL
#include <linux/sunrpc/bc_xprt.h>
#endif
#include <net/sock.h>
#include <net/checksum.h>
#include <net/udp.h>
#include <net/tcp.h>
#include <net/tls_prot.h>
#include <net/handshake.h>
#include <linux/bvec.h>
#include <linux/highmem.h>
#include <linux/uio.h>
#include <linux/sched/mm.h>
#include <trace/events/sock.h>
#include <trace/events/sunrpc.h>
#include "socklib.h"
#include "sunrpc.h"
static void xs_close(struct rpc_xprt *xprt);
static void xs_reset_srcport(struct sock_xprt *transport);
static void xs_set_srcport(struct sock_xprt *transport, struct socket *sock);
static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
struct socket *sock);
static unsigned int xprt_udp_slot_table_entries = …;
static unsigned int xprt_tcp_slot_table_entries = …;
static unsigned int xprt_max_tcp_slot_table_entries = …;
static unsigned int xprt_min_resvport = …;
static unsigned int xprt_max_resvport = …;
#define XS_TCP_LINGER_TO …
static unsigned int xs_tcp_fin_timeout __read_mostly = …;
static unsigned int min_slot_table_size = …;
static unsigned int max_slot_table_size = …;
static unsigned int max_tcp_slot_table_limit = …;
static unsigned int xprt_min_resvport_limit = …;
static unsigned int xprt_max_resvport_limit = …;
static struct ctl_table_header *sunrpc_table_header;
static struct xprt_class xs_local_transport;
static struct xprt_class xs_udp_transport;
static struct xprt_class xs_tcp_transport;
static struct xprt_class xs_tcp_tls_transport;
static struct xprt_class xs_bc_tcp_transport;
static struct ctl_table xs_tunables_table[] = …;
#define XS_BIND_TO …
#define XS_UDP_REEST_TO …
#define XS_TCP_INIT_REEST_TO …
#define XS_IDLE_DISC_TO …
#define XS_TLS_HANDSHAKE_TO …
#if IS_ENABLED(CONFIG_SUNRPC_DEBUG)
# undef RPC_DEBUG_DATA
#define RPCDBG_FACILITY …
#endif
#ifdef RPC_DEBUG_DATA
static void xs_pktdump(char *msg, u32 *packet, unsigned int count)
{
u8 *buf = (u8 *) packet;
int j;
dprintk("RPC: %s\n", msg);
for (j = 0; j < count && j < 128; j += 4) {
if (!(j & 31)) {
if (j)
dprintk("\n");
dprintk("0x%04x ", j);
}
dprintk("%02x%02x%02x%02x ",
buf[j], buf[j+1], buf[j+2], buf[j+3]);
}
dprintk("\n");
}
#else
static inline void xs_pktdump(char *msg, u32 *packet, unsigned int count)
{ … }
#endif
static inline struct rpc_xprt *xprt_from_sock(struct sock *sk)
{ … }
static inline struct sockaddr *xs_addr(struct rpc_xprt *xprt)
{ … }
static inline struct sockaddr_un *xs_addr_un(struct rpc_xprt *xprt)
{ … }
static inline struct sockaddr_in *xs_addr_in(struct rpc_xprt *xprt)
{ … }
static inline struct sockaddr_in6 *xs_addr_in6(struct rpc_xprt *xprt)
{ … }
static void xs_format_common_peer_addresses(struct rpc_xprt *xprt)
{ … }
static void xs_format_common_peer_ports(struct rpc_xprt *xprt)
{ … }
static void xs_format_peer_addresses(struct rpc_xprt *xprt,
const char *protocol,
const char *netid)
{ … }
static void xs_update_peer_port(struct rpc_xprt *xprt)
{ … }
static void xs_free_peer_addresses(struct rpc_xprt *xprt)
{ … }
static size_t
xs_alloc_sparse_pages(struct xdr_buf *buf, size_t want, gfp_t gfp)
{ … }
static int
xs_sock_process_cmsg(struct socket *sock, struct msghdr *msg,
struct cmsghdr *cmsg, int ret)
{ … }
static int
xs_sock_recv_cmsg(struct socket *sock, struct msghdr *msg, int flags)
{ … }
static ssize_t
xs_sock_recvmsg(struct socket *sock, struct msghdr *msg, int flags, size_t seek)
{ … }
static ssize_t
xs_read_kvec(struct socket *sock, struct msghdr *msg, int flags,
struct kvec *kvec, size_t count, size_t seek)
{ … }
static ssize_t
xs_read_bvec(struct socket *sock, struct msghdr *msg, int flags,
struct bio_vec *bvec, unsigned long nr, size_t count,
size_t seek)
{ … }
static ssize_t
xs_read_discard(struct socket *sock, struct msghdr *msg, int flags,
size_t count)
{ … }
#if ARCH_IMPLEMENTS_FLUSH_DCACHE_PAGE
static void
xs_flush_bvec(const struct bio_vec *bvec, size_t count, size_t seek)
{
struct bvec_iter bi = {
.bi_size = count,
};
struct bio_vec bv;
bvec_iter_advance(bvec, &bi, seek & PAGE_MASK);
for_each_bvec(bv, bvec, bi, bi)
flush_dcache_page(bv.bv_page);
}
#else
static inline void
xs_flush_bvec(const struct bio_vec *bvec, size_t count, size_t seek)
{ … }
#endif
static ssize_t
xs_read_xdr_buf(struct socket *sock, struct msghdr *msg, int flags,
struct xdr_buf *buf, size_t count, size_t seek, size_t *read)
{ … }
static void
xs_read_header(struct sock_xprt *transport, struct xdr_buf *buf)
{ … }
static bool
xs_read_stream_request_done(struct sock_xprt *transport)
{ … }
static void
xs_read_stream_check_eor(struct sock_xprt *transport,
struct msghdr *msg)
{ … }
static ssize_t
xs_read_stream_request(struct sock_xprt *transport, struct msghdr *msg,
int flags, struct rpc_rqst *req)
{ … }
static size_t
xs_read_stream_headersize(bool isfrag)
{ … }
static ssize_t
xs_read_stream_header(struct sock_xprt *transport, struct msghdr *msg,
int flags, size_t want, size_t seek)
{ … }
#if defined(CONFIG_SUNRPC_BACKCHANNEL)
static ssize_t
xs_read_stream_call(struct sock_xprt *transport, struct msghdr *msg, int flags)
{ … }
#else
static ssize_t
xs_read_stream_call(struct sock_xprt *transport, struct msghdr *msg, int flags)
{
return -ESHUTDOWN;
}
#endif
static ssize_t
xs_read_stream_reply(struct sock_xprt *transport, struct msghdr *msg, int flags)
{ … }
static ssize_t
xs_read_stream(struct sock_xprt *transport, int flags)
{ … }
static __poll_t xs_poll_socket(struct sock_xprt *transport)
{ … }
static bool xs_poll_socket_readable(struct sock_xprt *transport)
{ … }
static void xs_poll_check_readable(struct sock_xprt *transport)
{ … }
static void xs_stream_data_receive(struct sock_xprt *transport)
{ … }
static void xs_stream_data_receive_workfn(struct work_struct *work)
{ … }
static void
xs_stream_reset_connect(struct sock_xprt *transport)
{ … }
static void
xs_stream_start_connect(struct sock_xprt *transport)
{ … }
#define XS_SENDMSG_FLAGS …
static int xs_nospace(struct rpc_rqst *req, struct sock_xprt *transport)
{ … }
static int xs_sock_nospace(struct rpc_rqst *req)
{ … }
static int xs_stream_nospace(struct rpc_rqst *req, bool vm_wait)
{ … }
static int xs_stream_prepare_request(struct rpc_rqst *req, struct xdr_buf *buf)
{ … }
static void xs_stream_abort_send_request(struct rpc_rqst *req)
{ … }
static bool
xs_send_request_was_aborted(struct sock_xprt *transport, struct rpc_rqst *req)
{ … }
static rpc_fraghdr
xs_stream_record_marker(struct xdr_buf *xdr)
{ … }
static int xs_local_send_request(struct rpc_rqst *req)
{ … }
static int xs_udp_send_request(struct rpc_rqst *req)
{ … }
static int xs_tcp_send_request(struct rpc_rqst *req)
{ … }
static void xs_save_old_callbacks(struct sock_xprt *transport, struct sock *sk)
{ … }
static void xs_restore_old_callbacks(struct sock_xprt *transport, struct sock *sk)
{ … }
static void xs_sock_reset_state_flags(struct rpc_xprt *xprt)
{ … }
static void xs_run_error_worker(struct sock_xprt *transport, unsigned int nr)
{ … }
static void xs_sock_reset_connection_flags(struct rpc_xprt *xprt)
{ … }
static void xs_error_report(struct sock *sk)
{ … }
static void xs_reset_transport(struct sock_xprt *transport)
{ … }
static void xs_close(struct rpc_xprt *xprt)
{ … }
static void xs_inject_disconnect(struct rpc_xprt *xprt)
{ … }
static void xs_xprt_free(struct rpc_xprt *xprt)
{ … }
static void xs_destroy(struct rpc_xprt *xprt)
{ … }
static void xs_udp_data_read_skb(struct rpc_xprt *xprt,
struct sock *sk,
struct sk_buff *skb)
{ … }
static void xs_udp_data_receive(struct sock_xprt *transport)
{ … }
static void xs_udp_data_receive_workfn(struct work_struct *work)
{ … }
static void xs_data_ready(struct sock *sk)
{ … }
static void xs_tcp_force_close(struct rpc_xprt *xprt)
{ … }
#if defined(CONFIG_SUNRPC_BACKCHANNEL)
static size_t xs_tcp_bc_maxpayload(struct rpc_xprt *xprt)
{ … }
#endif
static void xs_local_state_change(struct sock *sk)
{ … }
static void xs_tcp_state_change(struct sock *sk)
{ … }
static void xs_write_space(struct sock *sk)
{ … }
static void xs_udp_write_space(struct sock *sk)
{ … }
static void xs_tcp_write_space(struct sock *sk)
{ … }
static void xs_udp_do_set_buffer_size(struct rpc_xprt *xprt)
{ … }
static void xs_udp_set_buffer_size(struct rpc_xprt *xprt, size_t sndsize, size_t rcvsize)
{ … }
static void xs_udp_timer(struct rpc_xprt *xprt, struct rpc_task *task)
{ … }
static int xs_get_random_port(void)
{ … }
static unsigned short xs_sock_getport(struct socket *sock)
{ … }
static void xs_set_port(struct rpc_xprt *xprt, unsigned short port)
{ … }
static void xs_reset_srcport(struct sock_xprt *transport)
{ … }
static void xs_set_srcport(struct sock_xprt *transport, struct socket *sock)
{ … }
static int xs_get_srcport(struct sock_xprt *transport)
{ … }
static unsigned short xs_sock_srcport(struct rpc_xprt *xprt)
{ … }
static int xs_sock_srcaddr(struct rpc_xprt *xprt, char *buf, size_t buflen)
{ … }
static unsigned short xs_next_srcport(struct sock_xprt *transport, unsigned short port)
{ … }
static int xs_bind(struct sock_xprt *transport, struct socket *sock)
{ … }
static void xs_local_rpcbind(struct rpc_task *task)
{ … }
static void xs_local_set_port(struct rpc_xprt *xprt, unsigned short port)
{ … }
#ifdef CONFIG_DEBUG_LOCK_ALLOC
static struct lock_class_key xs_key[3];
static struct lock_class_key xs_slock_key[3];
static inline void xs_reclassify_socketu(struct socket *sock)
{ … }
static inline void xs_reclassify_socket4(struct socket *sock)
{ … }
static inline void xs_reclassify_socket6(struct socket *sock)
{ … }
static inline void xs_reclassify_socket(int family, struct socket *sock)
{ … }
#else
static inline void xs_reclassify_socket(int family, struct socket *sock)
{
}
#endif
static void xs_dummy_setup_socket(struct work_struct *work)
{ … }
static struct socket *xs_create_sock(struct rpc_xprt *xprt,
struct sock_xprt *transport, int family, int type,
int protocol, bool reuseport)
{ … }
static int xs_local_finish_connecting(struct rpc_xprt *xprt,
struct socket *sock)
{ … }
static int xs_local_setup_socket(struct sock_xprt *transport)
{ … }
static void xs_local_connect(struct rpc_xprt *xprt, struct rpc_task *task)
{ … }
#if IS_ENABLED(CONFIG_SUNRPC_SWAP)
static void xs_set_memalloc(struct rpc_xprt *xprt)
{ … }
static int
xs_enable_swap(struct rpc_xprt *xprt)
{ … }
static void
xs_disable_swap(struct rpc_xprt *xprt)
{ … }
#else
static void xs_set_memalloc(struct rpc_xprt *xprt)
{
}
static int
xs_enable_swap(struct rpc_xprt *xprt)
{
return -EINVAL;
}
static void
xs_disable_swap(struct rpc_xprt *xprt)
{
}
#endif
static void xs_udp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
{ … }
static void xs_udp_setup_socket(struct work_struct *work)
{ … }
static void xs_tcp_shutdown(struct rpc_xprt *xprt)
{ … }
static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,
struct socket *sock)
{ … }
static void xs_tcp_do_set_connect_timeout(struct rpc_xprt *xprt,
unsigned long connect_timeout)
{ … }
static void xs_tcp_set_connect_timeout(struct rpc_xprt *xprt,
unsigned long connect_timeout,
unsigned long reconnect_timeout)
{ … }
static int xs_tcp_finish_connecting(struct rpc_xprt *xprt, struct socket *sock)
{ … }
static void xs_tcp_setup_socket(struct work_struct *work)
{ … }
static int xs_tcp_tls_finish_connecting(struct rpc_xprt *lower_xprt,
struct sock_xprt *upper_transport)
{ … }
static void xs_tls_handshake_done(void *data, int status, key_serial_t peerid)
{ … }
static int xs_tls_handshake_sync(struct rpc_xprt *lower_xprt, struct xprtsec_parms *xprtsec)
{ … }
static void xs_tcp_tls_setup_socket(struct work_struct *work)
{ … }
static void xs_connect(struct rpc_xprt *xprt, struct rpc_task *task)
{ … }
static void xs_wake_disconnect(struct sock_xprt *transport)
{ … }
static void xs_wake_write(struct sock_xprt *transport)
{ … }
static void xs_wake_error(struct sock_xprt *transport)
{ … }
static void xs_wake_pending(struct sock_xprt *transport)
{ … }
static void xs_error_handle(struct work_struct *work)
{ … }
static void xs_local_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
{ … }
static void xs_udp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
{ … }
static void xs_tcp_print_stats(struct rpc_xprt *xprt, struct seq_file *seq)
{ … }
static int bc_malloc(struct rpc_task *task)
{ … }
static void bc_free(struct rpc_task *task)
{ … }
static int bc_sendto(struct rpc_rqst *req)
{ … }
static int bc_send_request(struct rpc_rqst *req)
{ … }
static void bc_close(struct rpc_xprt *xprt)
{ … }
static void bc_destroy(struct rpc_xprt *xprt)
{ … }
static const struct rpc_xprt_ops xs_local_ops = …;
static const struct rpc_xprt_ops xs_udp_ops = …;
static const struct rpc_xprt_ops xs_tcp_ops = …;
static const struct rpc_xprt_ops bc_tcp_ops = …;
static int xs_init_anyaddr(const int family, struct sockaddr *sap)
{ … }
static struct rpc_xprt *xs_setup_xprt(struct xprt_create *args,
unsigned int slot_table_size,
unsigned int max_slot_table_size)
{ … }
static const struct rpc_timeout xs_local_default_timeout = …;
static struct rpc_xprt *xs_setup_local(struct xprt_create *args)
{ … }
static const struct rpc_timeout xs_udp_default_timeout = …;
static struct rpc_xprt *xs_setup_udp(struct xprt_create *args)
{ … }
static const struct rpc_timeout xs_tcp_default_timeout = …;
static struct rpc_xprt *xs_setup_tcp(struct xprt_create *args)
{ … }
static struct rpc_xprt *xs_setup_tcp_tls(struct xprt_create *args)
{ … }
static struct rpc_xprt *xs_setup_bc_tcp(struct xprt_create *args)
{ … }
static struct xprt_class xs_local_transport = …;
static struct xprt_class xs_udp_transport = …;
static struct xprt_class xs_tcp_transport = …;
static struct xprt_class xs_tcp_tls_transport = …;
static struct xprt_class xs_bc_tcp_transport = …;
int init_socket_xprt(void)
{ … }
void cleanup_socket_xprt(void)
{ … }
static int param_set_portnr(const char *val, const struct kernel_param *kp)
{ … }
static const struct kernel_param_ops param_ops_portnr = …;
#define param_check_portnr(name, p) …
module_param_named(min_resvport, xprt_min_resvport, portnr, 0644);
module_param_named(max_resvport, xprt_max_resvport, portnr, 0644);
static int param_set_slot_table_size(const char *val,
const struct kernel_param *kp)
{ … }
static const struct kernel_param_ops param_ops_slot_table_size = …;
#define param_check_slot_table_size(name, p) …
static int param_set_max_slot_table_size(const char *val,
const struct kernel_param *kp)
{ … }
static const struct kernel_param_ops param_ops_max_slot_table_size = …;
#define param_check_max_slot_table_size(name, p) …
module_param_named(tcp_slot_table_entries, xprt_tcp_slot_table_entries,
slot_table_size, 0644);
module_param_named(tcp_max_slot_table_entries, xprt_max_tcp_slot_table_entries,
max_slot_table_size, 0644);
module_param_named(udp_slot_table_entries, xprt_udp_slot_table_entries,
slot_table_size, 0644);