xref: /openbmc/linux/net/rxrpc/ar-internal.h (revision c54e43d7)
117926a79SDavid Howells /* AF_RXRPC internal definitions
217926a79SDavid Howells  *
317926a79SDavid Howells  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
417926a79SDavid Howells  * Written by David Howells (dhowells@redhat.com)
517926a79SDavid Howells  *
617926a79SDavid Howells  * This program is free software; you can redistribute it and/or
717926a79SDavid Howells  * modify it under the terms of the GNU General Public License
817926a79SDavid Howells  * as published by the Free Software Foundation; either version
917926a79SDavid Howells  * 2 of the License, or (at your option) any later version.
1017926a79SDavid Howells  */
1117926a79SDavid Howells 
12be6e6707SDavid Howells #include <linux/atomic.h>
138496af50SDavid Howells #include <linux/seqlock.h>
142baec2c3SDavid Howells #include <net/net_namespace.h>
152baec2c3SDavid Howells #include <net/netns/generic.h>
16e0e4d82fSDavid Howells #include <net/sock.h>
17be6e6707SDavid Howells #include <net/af_rxrpc.h>
18ddc6c70fSDavid Howells #include "protocol.h"
1917926a79SDavid Howells 
2017926a79SDavid Howells #if 0
2117926a79SDavid Howells #define CHECK_SLAB_OKAY(X)				     \
2217926a79SDavid Howells 	BUG_ON(atomic_read((X)) >> (sizeof(atomic_t) - 2) == \
2317926a79SDavid Howells 	       (POISON_FREE << 8 | POISON_FREE))
2417926a79SDavid Howells #else
2517926a79SDavid Howells #define CHECK_SLAB_OKAY(X) do {} while (0)
2617926a79SDavid Howells #endif
2717926a79SDavid Howells 
2817926a79SDavid Howells #define FCRYPT_BSIZE 8
2917926a79SDavid Howells struct rxrpc_crypt {
3017926a79SDavid Howells 	union {
3117926a79SDavid Howells 		u8	x[FCRYPT_BSIZE];
3291e916cfSAl Viro 		__be32	n[2];
3317926a79SDavid Howells 	};
3417926a79SDavid Howells } __attribute__((aligned(8)));
3517926a79SDavid Howells 
36651350d1SDavid Howells #define rxrpc_queue_work(WS)	queue_work(rxrpc_workqueue, (WS))
37651350d1SDavid Howells #define rxrpc_queue_delayed_work(WS,D)	\
38651350d1SDavid Howells 	queue_delayed_work(rxrpc_workqueue, (WS), (D))
39651350d1SDavid Howells 
40cc8feb8eSDavid Howells struct rxrpc_connection;
41cc8feb8eSDavid Howells 
4217926a79SDavid Howells /*
43d001648eSDavid Howells  * Mark applied to socket buffers.
44d001648eSDavid Howells  */
45d001648eSDavid Howells enum rxrpc_skb_mark {
46d001648eSDavid Howells 	RXRPC_SKB_MARK_DATA,		/* data message */
47d001648eSDavid Howells 	RXRPC_SKB_MARK_FINAL_ACK,	/* final ACK received message */
48d001648eSDavid Howells 	RXRPC_SKB_MARK_BUSY,		/* server busy message */
49d001648eSDavid Howells 	RXRPC_SKB_MARK_REMOTE_ABORT,	/* remote abort message */
50d001648eSDavid Howells 	RXRPC_SKB_MARK_LOCAL_ABORT,	/* local abort message */
51d001648eSDavid Howells 	RXRPC_SKB_MARK_NET_ERROR,	/* network error message */
52d001648eSDavid Howells 	RXRPC_SKB_MARK_LOCAL_ERROR,	/* local error message */
53d001648eSDavid Howells 	RXRPC_SKB_MARK_NEW_CALL,	/* local error message */
54d001648eSDavid Howells };
55d001648eSDavid Howells 
56d001648eSDavid Howells /*
5717926a79SDavid Howells  * sk_state for RxRPC sockets
5817926a79SDavid Howells  */
5917926a79SDavid Howells enum {
602341e077SDavid Howells 	RXRPC_UNBOUND = 0,
612341e077SDavid Howells 	RXRPC_CLIENT_UNBOUND,		/* Unbound socket used as client */
6217926a79SDavid Howells 	RXRPC_CLIENT_BOUND,		/* client local address bound */
6317926a79SDavid Howells 	RXRPC_SERVER_BOUND,		/* server local address bound */
6428036f44SDavid Howells 	RXRPC_SERVER_BOUND2,		/* second server local address bound */
6517926a79SDavid Howells 	RXRPC_SERVER_LISTENING,		/* server listening for connections */
66210f0353SDavid Howells 	RXRPC_SERVER_LISTEN_DISABLED,	/* server listening disabled */
6717926a79SDavid Howells 	RXRPC_CLOSE,			/* socket is being closed */
6817926a79SDavid Howells };
6917926a79SDavid Howells 
7017926a79SDavid Howells /*
712baec2c3SDavid Howells  * Per-network namespace data.
722baec2c3SDavid Howells  */
732baec2c3SDavid Howells struct rxrpc_net {
742baec2c3SDavid Howells 	struct proc_dir_entry	*proc_net;	/* Subdir in /proc/net */
752baec2c3SDavid Howells 	u32			epoch;		/* Local epoch for detecting local-end reset */
762baec2c3SDavid Howells 	struct list_head	calls;		/* List of calls active in this namespace */
772baec2c3SDavid Howells 	rwlock_t		call_lock;	/* Lock for ->calls */
78d3be4d24SDavid Howells 	atomic_t		nr_calls;	/* Count of allocated calls */
792baec2c3SDavid Howells 
8031f5f9a1SDavid Howells 	atomic_t		nr_conns;
812baec2c3SDavid Howells 	struct list_head	conn_proc_list;	/* List of conns in this namespace for proc */
822baec2c3SDavid Howells 	struct list_head	service_conns;	/* Service conns in this namespace */
832baec2c3SDavid Howells 	rwlock_t		conn_lock;	/* Lock for ->conn_proc_list, ->service_conns */
843d18cbb7SDavid Howells 	struct work_struct	service_conn_reaper;
853d18cbb7SDavid Howells 	struct timer_list	service_conn_reap_timer;
862baec2c3SDavid Howells 
872baec2c3SDavid Howells 	unsigned int		nr_client_conns;
882baec2c3SDavid Howells 	unsigned int		nr_active_client_conns;
892baec2c3SDavid Howells 	bool			kill_all_client_conns;
90f859ab61SDavid Howells 	bool			live;
912baec2c3SDavid Howells 	spinlock_t		client_conn_cache_lock; /* Lock for ->*_client_conns */
922baec2c3SDavid Howells 	spinlock_t		client_conn_discard_lock; /* Prevent multiple discarders */
932baec2c3SDavid Howells 	struct list_head	waiting_client_conns;
942baec2c3SDavid Howells 	struct list_head	active_client_conns;
952baec2c3SDavid Howells 	struct list_head	idle_client_conns;
963d18cbb7SDavid Howells 	struct work_struct	client_conn_reaper;
973d18cbb7SDavid Howells 	struct timer_list	client_conn_reap_timer;
982baec2c3SDavid Howells 
992baec2c3SDavid Howells 	struct list_head	local_endpoints;
1002baec2c3SDavid Howells 	struct mutex		local_mutex;	/* Lock for ->local_endpoints */
1012baec2c3SDavid Howells 
1022baec2c3SDavid Howells 	DECLARE_HASHTABLE	(peer_hash, 10);
103ace45becSDavid Howells 	spinlock_t		peer_hash_lock;	/* Lock for ->peer_hash */
104ace45becSDavid Howells 
105ace45becSDavid Howells #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */
106ace45becSDavid Howells 	u8			peer_keepalive_cursor;
107ace45becSDavid Howells 	ktime_t			peer_keepalive_base;
108ace45becSDavid Howells 	struct hlist_head	peer_keepalive[RXRPC_KEEPALIVE_TIME + 1];
109ace45becSDavid Howells 	struct hlist_head	peer_keepalive_new;
110ace45becSDavid Howells 	struct timer_list	peer_keepalive_timer;
111ace45becSDavid Howells 	struct work_struct	peer_keepalive_work;
1122baec2c3SDavid Howells };
1132baec2c3SDavid Howells 
1142baec2c3SDavid Howells /*
11500e90712SDavid Howells  * Service backlog preallocation.
11600e90712SDavid Howells  *
11700e90712SDavid Howells  * This contains circular buffers of preallocated peers, connections and calls
11800e90712SDavid Howells  * for incoming service calls and their head and tail pointers.  This allows
11900e90712SDavid Howells  * calls to be set up in the data_ready handler, thereby avoiding the need to
12000e90712SDavid Howells  * shuffle packets around so much.
12100e90712SDavid Howells  */
12200e90712SDavid Howells struct rxrpc_backlog {
12300e90712SDavid Howells 	unsigned short		peer_backlog_head;
12400e90712SDavid Howells 	unsigned short		peer_backlog_tail;
12500e90712SDavid Howells 	unsigned short		conn_backlog_head;
12600e90712SDavid Howells 	unsigned short		conn_backlog_tail;
12700e90712SDavid Howells 	unsigned short		call_backlog_head;
12800e90712SDavid Howells 	unsigned short		call_backlog_tail;
12900e90712SDavid Howells #define RXRPC_BACKLOG_MAX	32
13000e90712SDavid Howells 	struct rxrpc_peer	*peer_backlog[RXRPC_BACKLOG_MAX];
13100e90712SDavid Howells 	struct rxrpc_connection	*conn_backlog[RXRPC_BACKLOG_MAX];
13200e90712SDavid Howells 	struct rxrpc_call	*call_backlog[RXRPC_BACKLOG_MAX];
13300e90712SDavid Howells };
13400e90712SDavid Howells 
13500e90712SDavid Howells /*
13617926a79SDavid Howells  * RxRPC socket definition
13717926a79SDavid Howells  */
13817926a79SDavid Howells struct rxrpc_sock {
13917926a79SDavid Howells 	/* WARNING: sk has to be the first member */
14017926a79SDavid Howells 	struct sock		sk;
141d001648eSDavid Howells 	rxrpc_notify_new_call_t	notify_new_call; /* Func to notify of new call */
14200e90712SDavid Howells 	rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
14317926a79SDavid Howells 	struct rxrpc_local	*local;		/* local endpoint */
14400e90712SDavid Howells 	struct rxrpc_backlog	*backlog;	/* Preallocation for services */
145248f219cSDavid Howells 	spinlock_t		incoming_lock;	/* Incoming call vs service shutdown lock */
146248f219cSDavid Howells 	struct list_head	sock_calls;	/* List of calls owned by this socket */
147248f219cSDavid Howells 	struct list_head	to_be_accepted;	/* calls awaiting acceptance */
148248f219cSDavid Howells 	struct list_head	recvmsg_q;	/* Calls awaiting recvmsg's attention  */
149248f219cSDavid Howells 	rwlock_t		recvmsg_lock;	/* Lock for recvmsg_q */
15017926a79SDavid Howells 	struct key		*key;		/* security for this socket */
15117926a79SDavid Howells 	struct key		*securities;	/* list of server security descriptors */
15200e90712SDavid Howells 	struct rb_root		calls;		/* User ID -> call mapping */
15317926a79SDavid Howells 	unsigned long		flags;
1542341e077SDavid Howells #define RXRPC_SOCK_CONNECTED		0	/* connect_srx is set */
15517926a79SDavid Howells 	rwlock_t		call_lock;	/* lock for calls */
15617926a79SDavid Howells 	u32			min_sec_level;	/* minimum security level */
15717926a79SDavid Howells #define RXRPC_SECURITY_MAX	RXRPC_SECURITY_ENCRYPT
158cc8feb8eSDavid Howells 	bool			exclusive;	/* Exclusive connection for a client socket */
15928036f44SDavid Howells 	u16			second_service;	/* Additional service bound to the endpoint */
1604722974dSDavid Howells 	struct {
1614722974dSDavid Howells 		/* Service upgrade information */
1624722974dSDavid Howells 		u16		from;		/* Service ID to upgrade (if not 0) */
1634722974dSDavid Howells 		u16		to;		/* service ID to upgrade to */
1644722974dSDavid Howells 	} service_upgrade;
165cc8feb8eSDavid Howells 	sa_family_t		family;		/* Protocol family created with */
1664722974dSDavid Howells 	struct sockaddr_rxrpc	srx;		/* Primary Service/local addresses */
1672341e077SDavid Howells 	struct sockaddr_rxrpc	connect_srx;	/* Default client address from connect() */
16817926a79SDavid Howells };
16917926a79SDavid Howells 
17017926a79SDavid Howells #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
17117926a79SDavid Howells 
17217926a79SDavid Howells /*
1730d12f8a4SDavid Howells  * CPU-byteorder normalised Rx packet header.
1740d12f8a4SDavid Howells  */
1750d12f8a4SDavid Howells struct rxrpc_host_header {
1760d12f8a4SDavid Howells 	u32		epoch;		/* client boot timestamp */
1770d12f8a4SDavid Howells 	u32		cid;		/* connection and channel ID */
1780d12f8a4SDavid Howells 	u32		callNumber;	/* call ID (0 for connection-level packets) */
1790d12f8a4SDavid Howells 	u32		seq;		/* sequence number of pkt in call stream */
1800d12f8a4SDavid Howells 	u32		serial;		/* serial number of pkt sent to network */
1810d12f8a4SDavid Howells 	u8		type;		/* packet type */
1820d12f8a4SDavid Howells 	u8		flags;		/* packet flags */
1830d12f8a4SDavid Howells 	u8		userStatus;	/* app-layer defined status */
1840d12f8a4SDavid Howells 	u8		securityIndex;	/* security protocol ID */
1850d12f8a4SDavid Howells 	union {
1860d12f8a4SDavid Howells 		u16	_rsvd;		/* reserved */
1870d12f8a4SDavid Howells 		u16	cksum;		/* kerberos security checksum */
1880d12f8a4SDavid Howells 	};
1890d12f8a4SDavid Howells 	u16		serviceId;	/* service ID */
1900d12f8a4SDavid Howells } __packed;
1910d12f8a4SDavid Howells 
1920d12f8a4SDavid Howells /*
19317926a79SDavid Howells  * RxRPC socket buffer private variables
19417926a79SDavid Howells  * - max 48 bytes (struct sk_buff::cb)
19517926a79SDavid Howells  */
19617926a79SDavid Howells struct rxrpc_skb_priv {
197248f219cSDavid Howells 	union {
198248f219cSDavid Howells 		u8		nr_jumbo;	/* Number of jumbo subpackets */
199248f219cSDavid Howells 	};
20017926a79SDavid Howells 	union {
20117926a79SDavid Howells 		int		remain;		/* amount of space remaining for next write */
20217926a79SDavid Howells 	};
20317926a79SDavid Howells 
2040d12f8a4SDavid Howells 	struct rxrpc_host_header hdr;		/* RxRPC packet header from this packet */
20517926a79SDavid Howells };
20617926a79SDavid Howells 
20717926a79SDavid Howells #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
20817926a79SDavid Howells 
20917926a79SDavid Howells /*
21017926a79SDavid Howells  * RxRPC security module interface
21117926a79SDavid Howells  */
21217926a79SDavid Howells struct rxrpc_security {
21317926a79SDavid Howells 	const char		*name;		/* name of this service */
21417926a79SDavid Howells 	u8			security_index;	/* security type provided */
21517926a79SDavid Howells 
216648af7fcSDavid Howells 	/* Initialise a security service */
217648af7fcSDavid Howells 	int (*init)(void);
218648af7fcSDavid Howells 
219648af7fcSDavid Howells 	/* Clean up a security service */
220648af7fcSDavid Howells 	void (*exit)(void);
221648af7fcSDavid Howells 
22217926a79SDavid Howells 	/* initialise a connection's security */
22317926a79SDavid Howells 	int (*init_connection_security)(struct rxrpc_connection *);
22417926a79SDavid Howells 
22517926a79SDavid Howells 	/* prime a connection's packet security */
226a263629dSHerbert Xu 	int (*prime_packet_security)(struct rxrpc_connection *);
22717926a79SDavid Howells 
22817926a79SDavid Howells 	/* impose security on a packet */
229a263629dSHerbert Xu 	int (*secure_packet)(struct rxrpc_call *,
23017926a79SDavid Howells 			     struct sk_buff *,
23117926a79SDavid Howells 			     size_t,
23217926a79SDavid Howells 			     void *);
23317926a79SDavid Howells 
23417926a79SDavid Howells 	/* verify the security on a received packet */
2355a42976dSDavid Howells 	int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
236248f219cSDavid Howells 			     unsigned int, unsigned int, rxrpc_seq_t, u16);
237248f219cSDavid Howells 
238248f219cSDavid Howells 	/* Locate the data in a received packet that has been verified. */
239248f219cSDavid Howells 	void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
240248f219cSDavid Howells 			    unsigned int *, unsigned int *);
24117926a79SDavid Howells 
24217926a79SDavid Howells 	/* issue a challenge */
24317926a79SDavid Howells 	int (*issue_challenge)(struct rxrpc_connection *);
24417926a79SDavid Howells 
24517926a79SDavid Howells 	/* respond to a challenge */
24617926a79SDavid Howells 	int (*respond_to_challenge)(struct rxrpc_connection *,
24717926a79SDavid Howells 				    struct sk_buff *,
24817926a79SDavid Howells 				    u32 *);
24917926a79SDavid Howells 
25017926a79SDavid Howells 	/* verify a response */
25117926a79SDavid Howells 	int (*verify_response)(struct rxrpc_connection *,
25217926a79SDavid Howells 			       struct sk_buff *,
25317926a79SDavid Howells 			       u32 *);
25417926a79SDavid Howells 
25517926a79SDavid Howells 	/* clear connection security */
25617926a79SDavid Howells 	void (*clear)(struct rxrpc_connection *);
25717926a79SDavid Howells };
25817926a79SDavid Howells 
25917926a79SDavid Howells /*
2604f95dd78SDavid Howells  * RxRPC local transport endpoint description
2614f95dd78SDavid Howells  * - owned by a single AF_RXRPC socket
2624f95dd78SDavid Howells  * - pointed to by transport socket struct sk_user_data
26317926a79SDavid Howells  */
26417926a79SDavid Howells struct rxrpc_local {
2654f95dd78SDavid Howells 	struct rcu_head		rcu;
2664f95dd78SDavid Howells 	atomic_t		usage;
2672baec2c3SDavid Howells 	struct rxrpc_net	*rxnet;		/* The network ns in which this resides */
2684f95dd78SDavid Howells 	struct list_head	link;
26917926a79SDavid Howells 	struct socket		*socket;	/* my UDP socket */
2704f95dd78SDavid Howells 	struct work_struct	processor;
2711e9e5c95SDavid Howells 	struct rxrpc_sock __rcu	*service;	/* Service(s) listening on this endpoint */
27217926a79SDavid Howells 	struct rw_semaphore	defrag_sem;	/* control re-enablement of IP DF bit */
27317926a79SDavid Howells 	struct sk_buff_head	reject_queue;	/* packets awaiting rejection */
27444ba0698SDavid Howells 	struct sk_buff_head	event_queue;	/* endpoint event packets awaiting processing */
275999b69f8SDavid Howells 	struct rb_root		client_conns;	/* Client connections by socket params */
276999b69f8SDavid Howells 	spinlock_t		client_conns_lock; /* Lock for client_conns */
27717926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
27817926a79SDavid Howells 	rwlock_t		services_lock;	/* lock for services list */
27917926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
2804f95dd78SDavid Howells 	bool			dead;
281f859ab61SDavid Howells 	bool			service_closed;	/* Service socket closed */
28217926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* local address */
28317926a79SDavid Howells };
28417926a79SDavid Howells 
28517926a79SDavid Howells /*
28617926a79SDavid Howells  * RxRPC remote transport endpoint definition
287be6e6707SDavid Howells  * - matched by local endpoint, remote port, address and protocol type
28817926a79SDavid Howells  */
28917926a79SDavid Howells struct rxrpc_peer {
290be6e6707SDavid Howells 	struct rcu_head		rcu;		/* This must be first */
291be6e6707SDavid Howells 	atomic_t		usage;
292be6e6707SDavid Howells 	unsigned long		hash_key;
293be6e6707SDavid Howells 	struct hlist_node	hash_link;
294be6e6707SDavid Howells 	struct rxrpc_local	*local;
295f66d7490SDavid Howells 	struct hlist_head	error_targets;	/* targets for net error distribution */
296f66d7490SDavid Howells 	struct work_struct	error_distributor;
297aa390bbeSDavid Howells 	struct rb_root		service_conns;	/* Service connections */
298ace45becSDavid Howells 	struct hlist_node	keepalive_link;	/* Link in net->peer_keepalive[] */
299ace45becSDavid Howells 	time64_t		last_tx_at;	/* Last time packet sent here */
3008496af50SDavid Howells 	seqlock_t		service_conn_lock;
30117926a79SDavid Howells 	spinlock_t		lock;		/* access lock */
30295c96174SEric Dumazet 	unsigned int		if_mtu;		/* interface MTU for this peer */
30395c96174SEric Dumazet 	unsigned int		mtu;		/* network MTU for this peer */
30495c96174SEric Dumazet 	unsigned int		maxdata;	/* data size (MTU - hdrsize) */
30517926a79SDavid Howells 	unsigned short		hdrsize;	/* header size (IP + UDP + RxRPC) */
30617926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
307f66d7490SDavid Howells 	int			error_report;	/* Net (+0) or local (+1000000) to distribute */
308f66d7490SDavid Howells #define RXRPC_LOCAL_ERROR_OFFSET 1000000
30917926a79SDavid Howells 	struct sockaddr_rxrpc	srx;		/* remote address */
31017926a79SDavid Howells 
31117926a79SDavid Howells 	/* calculated RTT cache */
31217926a79SDavid Howells #define RXRPC_RTT_CACHE_SIZE 32
3130d4b103cSDavid Howells 	ktime_t			rtt_last_req;	/* Time of last RTT request */
314cf1a6474SDavid Howells 	u64			rtt;		/* Current RTT estimate (in nS) */
315cf1a6474SDavid Howells 	u64			rtt_sum;	/* Sum of cache contents */
316cf1a6474SDavid Howells 	u64			rtt_cache[RXRPC_RTT_CACHE_SIZE]; /* Determined RTT cache */
317cf1a6474SDavid Howells 	u8			rtt_cursor;	/* next entry at which to insert */
318cf1a6474SDavid Howells 	u8			rtt_usage;	/* amount of cache actually used */
319f7aec129SDavid Howells 
320f7aec129SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
32117926a79SDavid Howells };
32217926a79SDavid Howells 
32317926a79SDavid Howells /*
32419ffa01cSDavid Howells  * Keys for matching a connection.
32519ffa01cSDavid Howells  */
32619ffa01cSDavid Howells struct rxrpc_conn_proto {
327e8d70ce1SDavid Howells 	union {
328e8d70ce1SDavid Howells 		struct {
32919ffa01cSDavid Howells 			u32	epoch;		/* epoch of this connection */
33019ffa01cSDavid Howells 			u32	cid;		/* connection ID */
331e8d70ce1SDavid Howells 		};
332e8d70ce1SDavid Howells 		u64		index_key;
33319ffa01cSDavid Howells 	};
33419ffa01cSDavid Howells };
33519ffa01cSDavid Howells 
33619ffa01cSDavid Howells struct rxrpc_conn_parameters {
33719ffa01cSDavid Howells 	struct rxrpc_local	*local;		/* Representation of local endpoint */
33819ffa01cSDavid Howells 	struct rxrpc_peer	*peer;		/* Remote endpoint */
33919ffa01cSDavid Howells 	struct key		*key;		/* Security details */
34019ffa01cSDavid Howells 	bool			exclusive;	/* T if conn is exclusive */
3414e255721SDavid Howells 	bool			upgrade;	/* T if service ID can be upgraded */
34219ffa01cSDavid Howells 	u16			service_id;	/* Service ID for this connection */
34319ffa01cSDavid Howells 	u32			security_level;	/* Security level selected */
34419ffa01cSDavid Howells };
34519ffa01cSDavid Howells 
34619ffa01cSDavid Howells /*
347bba304dbSDavid Howells  * Bits in the connection flags.
348bba304dbSDavid Howells  */
349bba304dbSDavid Howells enum rxrpc_conn_flag {
350bba304dbSDavid Howells 	RXRPC_CONN_HAS_IDR,		/* Has a client conn ID assigned */
351001c1122SDavid Howells 	RXRPC_CONN_IN_SERVICE_CONNS,	/* Conn is in peer->service_conns */
352001c1122SDavid Howells 	RXRPC_CONN_IN_CLIENT_CONNS,	/* Conn is in local->client_conns */
35345025bceSDavid Howells 	RXRPC_CONN_EXPOSED,		/* Conn has extra ref for exposure */
35445025bceSDavid Howells 	RXRPC_CONN_DONT_REUSE,		/* Don't reuse this connection */
35545025bceSDavid Howells 	RXRPC_CONN_COUNTED,		/* Counted by rxrpc_nr_client_conns */
3564e255721SDavid Howells 	RXRPC_CONN_PROBING_FOR_UPGRADE,	/* Probing for service upgrade */
3573136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_0,		/* Need final ACK for channel 0 */
3583136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_1,		/* Need final ACK for channel 1 */
3593136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_2,		/* Need final ACK for channel 2 */
3603136ef49SDavid Howells 	RXRPC_CONN_FINAL_ACK_3,		/* Need final ACK for channel 3 */
361bba304dbSDavid Howells };
362bba304dbSDavid Howells 
3633136ef49SDavid Howells #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) |	\
3643136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_1) |	\
3653136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_2) |	\
3663136ef49SDavid Howells 				   (1UL << RXRPC_CONN_FINAL_ACK_3))
3673136ef49SDavid Howells 
368bba304dbSDavid Howells /*
369bba304dbSDavid Howells  * Events that can be raised upon a connection.
370bba304dbSDavid Howells  */
371bba304dbSDavid Howells enum rxrpc_conn_event {
372bba304dbSDavid Howells 	RXRPC_CONN_EV_CHALLENGE,	/* Send challenge packet */
373bba304dbSDavid Howells };
374bba304dbSDavid Howells 
375bba304dbSDavid Howells /*
37645025bceSDavid Howells  * The connection cache state.
37745025bceSDavid Howells  */
37845025bceSDavid Howells enum rxrpc_conn_cache_state {
37945025bceSDavid Howells 	RXRPC_CONN_CLIENT_INACTIVE,	/* Conn is not yet listed */
38045025bceSDavid Howells 	RXRPC_CONN_CLIENT_WAITING,	/* Conn is on wait list, waiting for capacity */
38145025bceSDavid Howells 	RXRPC_CONN_CLIENT_ACTIVE,	/* Conn is on active list, doing calls */
3824e255721SDavid Howells 	RXRPC_CONN_CLIENT_UPGRADE,	/* Conn is on active list, probing for upgrade */
38345025bceSDavid Howells 	RXRPC_CONN_CLIENT_CULLED,	/* Conn is culled and delisted, doing calls */
38445025bceSDavid Howells 	RXRPC_CONN_CLIENT_IDLE,		/* Conn is on idle list, doing mostly nothing */
385363deeabSDavid Howells 	RXRPC_CONN__NR_CACHE_STATES
38645025bceSDavid Howells };
38745025bceSDavid Howells 
38845025bceSDavid Howells /*
389bba304dbSDavid Howells  * The connection protocol state.
390bba304dbSDavid Howells  */
391bba304dbSDavid Howells enum rxrpc_conn_proto_state {
392bba304dbSDavid Howells 	RXRPC_CONN_UNUSED,		/* Connection not yet attempted */
393bba304dbSDavid Howells 	RXRPC_CONN_CLIENT,		/* Client connection */
39400e90712SDavid Howells 	RXRPC_CONN_SERVICE_PREALLOC,	/* Service connection preallocation */
395bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_UNSECURED,	/* Service unsecured connection */
396bba304dbSDavid Howells 	RXRPC_CONN_SERVICE_CHALLENGING,	/* Service challenging for security */
397bba304dbSDavid Howells 	RXRPC_CONN_SERVICE,		/* Service secured connection */
398bba304dbSDavid Howells 	RXRPC_CONN_REMOTELY_ABORTED,	/* Conn aborted by peer */
399bba304dbSDavid Howells 	RXRPC_CONN_LOCALLY_ABORTED,	/* Conn aborted locally */
400bba304dbSDavid Howells 	RXRPC_CONN__NR_STATES
401bba304dbSDavid Howells };
402bba304dbSDavid Howells 
403bba304dbSDavid Howells /*
40417926a79SDavid Howells  * RxRPC connection definition
405aa390bbeSDavid Howells  * - matched by { local, peer, epoch, conn_id, direction }
40617926a79SDavid Howells  * - each connection can only handle four simultaneous calls
40717926a79SDavid Howells  */
40817926a79SDavid Howells struct rxrpc_connection {
40919ffa01cSDavid Howells 	struct rxrpc_conn_proto	proto;
41019ffa01cSDavid Howells 	struct rxrpc_conn_parameters params;
41119ffa01cSDavid Howells 
41245025bceSDavid Howells 	atomic_t		usage;
41345025bceSDavid Howells 	struct rcu_head		rcu;
41445025bceSDavid Howells 	struct list_head	cache_link;
415a1399f8bSDavid Howells 
41645025bceSDavid Howells 	spinlock_t		channel_lock;
41745025bceSDavid Howells 	unsigned char		active_chans;	/* Mask of active channels */
41845025bceSDavid Howells #define RXRPC_ACTIVE_CHANS_MASK	((1 << RXRPC_MAXCALLS) - 1)
41945025bceSDavid Howells 	struct list_head	waiting_calls;	/* Calls waiting for channels */
420a1399f8bSDavid Howells 	struct rxrpc_channel {
4213136ef49SDavid Howells 		unsigned long		final_ack_at;	/* Time at which to issue final ACK */
422a1399f8bSDavid Howells 		struct rxrpc_call __rcu	*call;		/* Active call */
423a1399f8bSDavid Howells 		u32			call_id;	/* ID of current call */
424a1399f8bSDavid Howells 		u32			call_counter;	/* Call ID counter */
425a1399f8bSDavid Howells 		u32			last_call;	/* ID of last call */
42618bfeba5SDavid Howells 		u8			last_type;	/* Type of last packet */
42718bfeba5SDavid Howells 		union {
42818bfeba5SDavid Howells 			u32		last_seq;
42918bfeba5SDavid Howells 			u32		last_abort;
43018bfeba5SDavid Howells 		};
431a1399f8bSDavid Howells 	} channels[RXRPC_MAXCALLS];
432999b69f8SDavid Howells 
4333136ef49SDavid Howells 	struct timer_list	timer;		/* Conn event timer */
43417926a79SDavid Howells 	struct work_struct	processor;	/* connection event processor */
435999b69f8SDavid Howells 	union {
436999b69f8SDavid Howells 		struct rb_node	client_node;	/* Node in local->client_conns */
437aa390bbeSDavid Howells 		struct rb_node	service_node;	/* Node in peer->service_conns */
438999b69f8SDavid Howells 	};
4394d028b2cSDavid Howells 	struct list_head	proc_link;	/* link in procfs list */
44017926a79SDavid Howells 	struct list_head	link;		/* link in master connection list */
44117926a79SDavid Howells 	struct sk_buff_head	rx_queue;	/* received conn-level packets */
442648af7fcSDavid Howells 	const struct rxrpc_security *security;	/* applied security module */
44317926a79SDavid Howells 	struct key		*server_key;	/* security for this service */
4441afe593bSHerbert Xu 	struct crypto_skcipher	*cipher;	/* encryption handle */
44517926a79SDavid Howells 	struct rxrpc_crypt	csum_iv;	/* packet checksum base */
4464a3388c8SDavid Howells 	unsigned long		flags;
44717926a79SDavid Howells 	unsigned long		events;
448f51b4480SDavid Howells 	unsigned long		idle_timestamp;	/* Time at which last became idle */
44917926a79SDavid Howells 	spinlock_t		state_lock;	/* state-change lock */
450cf13258fSDavid Howells 	enum rxrpc_conn_cache_state cache_state;
451cf13258fSDavid Howells 	enum rxrpc_conn_proto_state state;	/* current state of connection */
452dc44b3a0SDavid Howells 	u32			local_abort;	/* local abort code */
453dc44b3a0SDavid Howells 	u32			remote_abort;	/* remote abort code */
45417926a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
45517926a79SDavid Howells 	atomic_t		serial;		/* packet serial number counter */
456563ea7d5SDavid Howells 	unsigned int		hi_serial;	/* highest serial number received */
45717926a79SDavid Howells 	u32			security_nonce;	/* response re-use preventer */
45868d6d1aeSDavid Howells 	u16			service_id;	/* Service ID, possibly upgraded */
4595a924b89SDavid Howells 	u8			size_align;	/* data size alignment (for security) */
4605a924b89SDavid Howells 	u8			security_size;	/* security header size */
46117926a79SDavid Howells 	u8			security_ix;	/* security type */
46217926a79SDavid Howells 	u8			out_clientflag;	/* RXRPC_CLIENT_INITIATED if we are client */
46317926a79SDavid Howells };
46417926a79SDavid Howells 
46517926a79SDavid Howells /*
4665b8848d1SDavid Howells  * Flags in call->flags.
4675b8848d1SDavid Howells  */
4685b8848d1SDavid Howells enum rxrpc_call_flag {
4695b8848d1SDavid Howells 	RXRPC_CALL_RELEASED,		/* call has been released - no more message to userspace */
4705b8848d1SDavid Howells 	RXRPC_CALL_HAS_USERID,		/* has a user ID attached */
471dabe5a79SDavid Howells 	RXRPC_CALL_IS_SERVICE,		/* Call is service call */
47245025bceSDavid Howells 	RXRPC_CALL_EXPOSED,		/* The call was exposed to the world */
473248f219cSDavid Howells 	RXRPC_CALL_RX_LAST,		/* Received the last packet (at rxtx_top) */
474248f219cSDavid Howells 	RXRPC_CALL_TX_LAST,		/* Last packet in Tx buffer (at rxtx_top) */
475c038a58cSDavid Howells 	RXRPC_CALL_TX_LASTQ,		/* Last packet has been queued */
476a5af7e1fSDavid Howells 	RXRPC_CALL_SEND_PING,		/* A ping will need to be sent */
4778e83134dSDavid Howells 	RXRPC_CALL_PINGING,		/* Ping in process */
47857494343SDavid Howells 	RXRPC_CALL_RETRANS_TIMEOUT,	/* Retransmission due to timeout occurred */
479c54e43d7SDavid Howells 	RXRPC_CALL_BEGAN_RX_TIMER,	/* We began the expect_rx_by timer */
4805b8848d1SDavid Howells };
4815b8848d1SDavid Howells 
4825b8848d1SDavid Howells /*
4835b8848d1SDavid Howells  * Events that can be raised on a call.
4845b8848d1SDavid Howells  */
4855b8848d1SDavid Howells enum rxrpc_call_event {
4864c198ad1SDavid Howells 	RXRPC_CALL_EV_ACK,		/* need to generate ACK */
4874c198ad1SDavid Howells 	RXRPC_CALL_EV_ABORT,		/* need to generate abort */
4884c198ad1SDavid Howells 	RXRPC_CALL_EV_RESEND,		/* Tx resend required */
489a5af7e1fSDavid Howells 	RXRPC_CALL_EV_PING,		/* Ping send required */
490a158bdd3SDavid Howells 	RXRPC_CALL_EV_EXPIRED,		/* Expiry occurred */
491bd1fdf8cSDavid Howells 	RXRPC_CALL_EV_ACK_LOST,		/* ACK may be lost, send ping */
4925b8848d1SDavid Howells };
4935b8848d1SDavid Howells 
4945b8848d1SDavid Howells /*
4955b8848d1SDavid Howells  * The states that a call can be in.
4965b8848d1SDavid Howells  */
4975b8848d1SDavid Howells enum rxrpc_call_state {
498999b69f8SDavid Howells 	RXRPC_CALL_UNINITIALISED,
499999b69f8SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_CONN,	/* - client waiting for connection to become available */
5005b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_SEND_REQUEST,	/* - client sending request phase */
5015b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_AWAIT_REPLY,	/* - client awaiting reply */
5025b8848d1SDavid Howells 	RXRPC_CALL_CLIENT_RECV_REPLY,	/* - client receiving reply phase */
50300e90712SDavid Howells 	RXRPC_CALL_SERVER_PREALLOC,	/* - service preallocation */
5045b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SECURING,	/* - server securing request connection */
5055b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACCEPTING,	/* - server accepting request */
5065b8848d1SDavid Howells 	RXRPC_CALL_SERVER_RECV_REQUEST,	/* - server receiving request */
5075b8848d1SDavid Howells 	RXRPC_CALL_SERVER_ACK_REQUEST,	/* - server pending ACK of request */
5085b8848d1SDavid Howells 	RXRPC_CALL_SERVER_SEND_REPLY,	/* - server sending reply */
5095b8848d1SDavid Howells 	RXRPC_CALL_SERVER_AWAIT_ACK,	/* - server awaiting final ACK */
510f5c17aaeSDavid Howells 	RXRPC_CALL_COMPLETE,		/* - call complete */
511f5c17aaeSDavid Howells 	NR__RXRPC_CALL_STATES
512f5c17aaeSDavid Howells };
513f5c17aaeSDavid Howells 
514f5c17aaeSDavid Howells /*
51557494343SDavid Howells  * Call Tx congestion management modes.
51657494343SDavid Howells  */
51757494343SDavid Howells enum rxrpc_congest_mode {
51857494343SDavid Howells 	RXRPC_CALL_SLOW_START,
51957494343SDavid Howells 	RXRPC_CALL_CONGEST_AVOIDANCE,
52057494343SDavid Howells 	RXRPC_CALL_PACKET_LOSS,
52157494343SDavid Howells 	RXRPC_CALL_FAST_RETRANSMIT,
52257494343SDavid Howells 	NR__RXRPC_CONGEST_MODES
52357494343SDavid Howells };
52457494343SDavid Howells 
52557494343SDavid Howells /*
52617926a79SDavid Howells  * RxRPC call definition
52717926a79SDavid Howells  * - matched by { connection, call_id }
52817926a79SDavid Howells  */
52917926a79SDavid Howells struct rxrpc_call {
530dee46364SDavid Howells 	struct rcu_head		rcu;
53117926a79SDavid Howells 	struct rxrpc_connection	*conn;		/* connection carrying call */
532df5d8bf7SDavid Howells 	struct rxrpc_peer	*peer;		/* Peer record for remote address */
5338d94aa38SDavid Howells 	struct rxrpc_sock __rcu	*socket;	/* socket responsible */
534d3be4d24SDavid Howells 	struct rxrpc_net	*rxnet;		/* Network namespace to which call belongs */
535540b1c48SDavid Howells 	struct mutex		user_mutex;	/* User access mutex */
536a158bdd3SDavid Howells 	unsigned long		ack_at;		/* When deferred ACK needs to happen */
537bd1fdf8cSDavid Howells 	unsigned long		ack_lost_at;	/* When ACK is figured as lost */
538a158bdd3SDavid Howells 	unsigned long		resend_at;	/* When next resend needs to happen */
539a158bdd3SDavid Howells 	unsigned long		ping_at;	/* When next to send a ping */
540415f44e4SDavid Howells 	unsigned long		keepalive_at;	/* When next to send a keepalive ping */
541a158bdd3SDavid Howells 	unsigned long		expect_rx_by;	/* When we expect to get a packet by */
542a158bdd3SDavid Howells 	unsigned long		expect_req_by;	/* When we expect to get a request DATA packet by */
543a158bdd3SDavid Howells 	unsigned long		expect_term_by;	/* When we expect call termination by */
544a158bdd3SDavid Howells 	u32			next_rx_timo;	/* Timeout for next Rx packet (jif) */
545a158bdd3SDavid Howells 	u32			next_req_timo;	/* Timeout for next Rx request packet (jif) */
546248f219cSDavid Howells 	struct timer_list	timer;		/* Combined event timer */
547248f219cSDavid Howells 	struct work_struct	processor;	/* Event processor */
548d001648eSDavid Howells 	rxrpc_notify_rx_t	notify_rx;	/* kernel service Rx notification function */
54917926a79SDavid Howells 	struct list_head	link;		/* link in master call list */
55045025bceSDavid Howells 	struct list_head	chan_wait_link;	/* Link in conn->waiting_calls */
551f66d7490SDavid Howells 	struct hlist_node	error_link;	/* link in error distribution list */
552248f219cSDavid Howells 	struct list_head	accept_link;	/* Link in rx->acceptq */
553248f219cSDavid Howells 	struct list_head	recvmsg_link;	/* Link in rx->recvmsg_q */
554248f219cSDavid Howells 	struct list_head	sock_link;	/* Link in rx->sock_calls */
555248f219cSDavid Howells 	struct rb_node		sock_node;	/* Node in rx->calls */
55617926a79SDavid Howells 	struct sk_buff		*tx_pending;	/* Tx socket buffer being filled */
55745025bceSDavid Howells 	wait_queue_head_t	waitq;		/* Wait queue for channel or Tx */
558e754eba6SDavid Howells 	s64			tx_total_len;	/* Total length left to be transmitted (or -1) */
559a263629dSHerbert Xu 	__be32			crypto_buf[2];	/* Temporary packet crypto buffer */
56017926a79SDavid Howells 	unsigned long		user_call_ID;	/* user-defined call ID */
56117926a79SDavid Howells 	unsigned long		flags;
56217926a79SDavid Howells 	unsigned long		events;
56317926a79SDavid Howells 	spinlock_t		lock;
56420acbd9aSDavid Howells 	spinlock_t		notify_lock;	/* Kernel notification lock */
56517926a79SDavid Howells 	rwlock_t		state_lock;	/* lock for state transition */
566f5c17aaeSDavid Howells 	u32			abort_code;	/* Local/remote abort code */
567f5c17aaeSDavid Howells 	int			error;		/* Local error incurred */
568cf13258fSDavid Howells 	enum rxrpc_call_state	state;		/* current state of call */
569cf13258fSDavid Howells 	enum rxrpc_call_completion completion;	/* Call completion condition */
57017926a79SDavid Howells 	atomic_t		usage;
571dabe5a79SDavid Howells 	u16			service_id;	/* service ID */
572278ac0cdSDavid Howells 	u8			security_ix;	/* Security type */
573dabe5a79SDavid Howells 	u32			call_id;	/* call ID on connection  */
574dabe5a79SDavid Howells 	u32			cid;		/* connection ID plus channel index */
575dabe5a79SDavid Howells 	int			debug_id;	/* debug ID for printks */
5768e83134dSDavid Howells 	unsigned short		rx_pkt_offset;	/* Current recvmsg packet offset */
5778e83134dSDavid Howells 	unsigned short		rx_pkt_len;	/* Current recvmsg packet len */
57817926a79SDavid Howells 
579248f219cSDavid Howells 	/* Rx/Tx circular buffer, depending on phase.
580248f219cSDavid Howells 	 *
581248f219cSDavid Howells 	 * In the Rx phase, packets are annotated with 0 or the number of the
582248f219cSDavid Howells 	 * segment of a jumbo packet each buffer refers to.  There can be up to
583248f219cSDavid Howells 	 * 47 segments in a maximum-size UDP packet.
584248f219cSDavid Howells 	 *
585248f219cSDavid Howells 	 * In the Tx phase, packets are annotated with which buffers have been
586248f219cSDavid Howells 	 * acked.
58717926a79SDavid Howells 	 */
588248f219cSDavid Howells #define RXRPC_RXTX_BUFF_SIZE	64
589248f219cSDavid Howells #define RXRPC_RXTX_BUFF_MASK	(RXRPC_RXTX_BUFF_SIZE - 1)
59075e42126SDavid Howells #define RXRPC_INIT_RX_WINDOW_SIZE 32
591248f219cSDavid Howells 	struct sk_buff		**rxtx_buffer;
592248f219cSDavid Howells 	u8			*rxtx_annotations;
593248f219cSDavid Howells #define RXRPC_TX_ANNO_ACK	0
594248f219cSDavid Howells #define RXRPC_TX_ANNO_UNACK	1
595248f219cSDavid Howells #define RXRPC_TX_ANNO_NAK	2
596248f219cSDavid Howells #define RXRPC_TX_ANNO_RETRANS	3
597f07373eaSDavid Howells #define RXRPC_TX_ANNO_MASK	0x03
59870790dbeSDavid Howells #define RXRPC_TX_ANNO_LAST	0x04
59970790dbeSDavid Howells #define RXRPC_TX_ANNO_RESENT	0x08
60070790dbeSDavid Howells 
601248f219cSDavid Howells #define RXRPC_RX_ANNO_JUMBO	0x3f		/* Jumbo subpacket number + 1 if not zero */
602248f219cSDavid Howells #define RXRPC_RX_ANNO_JLAST	0x40		/* Set if last element of a jumbo packet */
603248f219cSDavid Howells #define RXRPC_RX_ANNO_VERIFIED	0x80		/* Set if verified and decrypted */
604248f219cSDavid Howells 	rxrpc_seq_t		tx_hard_ack;	/* Dead slot in buffer; the first transmitted but
605248f219cSDavid Howells 						 * not hard-ACK'd packet follows this.
606248f219cSDavid Howells 						 */
607248f219cSDavid Howells 	rxrpc_seq_t		tx_top;		/* Highest Tx slot allocated. */
60857494343SDavid Howells 
60957494343SDavid Howells 	/* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
61057494343SDavid Howells 	 * is fixed, we keep these numbers in terms of segments (ie. DATA
61157494343SDavid Howells 	 * packets) rather than bytes.
61257494343SDavid Howells 	 */
61357494343SDavid Howells #define RXRPC_TX_SMSS		RXRPC_JUMBO_DATALEN
61457494343SDavid Howells 	u8			cong_cwnd;	/* Congestion window size */
61557494343SDavid Howells 	u8			cong_extra;	/* Extra to send for congestion management */
61657494343SDavid Howells 	u8			cong_ssthresh;	/* Slow-start threshold */
61757494343SDavid Howells 	enum rxrpc_congest_mode	cong_mode:8;	/* Congestion management mode */
61857494343SDavid Howells 	u8			cong_dup_acks;	/* Count of ACKs showing missing packets */
61957494343SDavid Howells 	u8			cong_cumul_acks; /* Cumulative ACK count */
62057494343SDavid Howells 	ktime_t			cong_tstamp;	/* Last time cwnd was changed */
62157494343SDavid Howells 
622248f219cSDavid Howells 	rxrpc_seq_t		rx_hard_ack;	/* Dead slot in buffer; the first received but not
623248f219cSDavid Howells 						 * consumed packet follows this.
624248f219cSDavid Howells 						 */
625248f219cSDavid Howells 	rxrpc_seq_t		rx_top;		/* Highest Rx slot allocated. */
626248f219cSDavid Howells 	rxrpc_seq_t		rx_expect_next;	/* Expected next packet sequence number */
627248f219cSDavid Howells 	u8			rx_winsize;	/* Size of Rx window */
628248f219cSDavid Howells 	u8			tx_winsize;	/* Maximum size of Tx window */
62971f3ca40SDavid Howells 	bool			tx_phase;	/* T if transmission phase, F if receive phase */
63075e42126SDavid Howells 	u8			nr_jumbo_bad;	/* Number of jumbo dups/exceeds-windows */
63117926a79SDavid Howells 
63217926a79SDavid Howells 	/* receive-phase ACK management */
6334e36a95eSDavid Howells 	u8			ackr_reason;	/* reason to ACK */
634563ea7d5SDavid Howells 	u16			ackr_skew;	/* skew on packet being ACK'd */
6350d12f8a4SDavid Howells 	rxrpc_serial_t		ackr_serial;	/* serial of packet being ACK'd */
636248f219cSDavid Howells 	rxrpc_seq_t		ackr_prev_seq;	/* previous sequence number received */
637805b21b9SDavid Howells 	rxrpc_seq_t		ackr_consumed;	/* Highest packet shown consumed */
638805b21b9SDavid Howells 	rxrpc_seq_t		ackr_seen;	/* Highest packet shown seen */
639a5af7e1fSDavid Howells 
640a5af7e1fSDavid Howells 	/* ping management */
641a5af7e1fSDavid Howells 	rxrpc_serial_t		ping_serial;	/* Last ping sent */
642a5af7e1fSDavid Howells 	ktime_t			ping_time;	/* Time last ping sent */
64317926a79SDavid Howells 
644248f219cSDavid Howells 	/* transmission-phase ACK management */
64557494343SDavid Howells 	ktime_t			acks_latest_ts;	/* Timestamp of latest ACK received */
646248f219cSDavid Howells 	rxrpc_serial_t		acks_latest;	/* serial number of latest ACK received */
64731a1b989SDavid Howells 	rxrpc_seq_t		acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
648bd1fdf8cSDavid Howells 	rxrpc_seq_t		acks_lost_top;	/* tx_top at the time lost-ack ping sent */
649bd1fdf8cSDavid Howells 	rxrpc_serial_t		acks_lost_ping;	/* Serial number of probe ACK */
65031a1b989SDavid Howells };
65131a1b989SDavid Howells 
65231a1b989SDavid Howells /*
65357494343SDavid Howells  * Summary of a new ACK and the changes it made to the Tx buffer packet states.
65431a1b989SDavid Howells  */
65531a1b989SDavid Howells struct rxrpc_ack_summary {
65631a1b989SDavid Howells 	u8			ack_reason;
65731a1b989SDavid Howells 	u8			nr_acks;		/* Number of ACKs in packet */
65831a1b989SDavid Howells 	u8			nr_nacks;		/* Number of NACKs in packet */
65931a1b989SDavid Howells 	u8			nr_new_acks;		/* Number of new ACKs in packet */
66031a1b989SDavid Howells 	u8			nr_new_nacks;		/* Number of new NACKs in packet */
66131a1b989SDavid Howells 	u8			nr_rot_new_acks;	/* Number of rotated new ACKs */
66231a1b989SDavid Howells 	bool			new_low_nack;		/* T if new low NACK found */
66357494343SDavid Howells 	bool			retrans_timeo;		/* T if reTx due to timeout happened */
66457494343SDavid Howells 	u8			flight_size;		/* Number of unreceived transmissions */
66557494343SDavid Howells 	/* Place to stash values for tracing */
66657494343SDavid Howells 	enum rxrpc_congest_mode	mode:8;
66757494343SDavid Howells 	u8			cwnd;
66857494343SDavid Howells 	u8			ssthresh;
66957494343SDavid Howells 	u8			dup_acks;
67057494343SDavid Howells 	u8			cumulative_acks;
67117926a79SDavid Howells };
67217926a79SDavid Howells 
67348124178SDavid Howells /*
67448124178SDavid Howells  * sendmsg() cmsg-specified parameters.
67548124178SDavid Howells  */
67648124178SDavid Howells enum rxrpc_command {
67748124178SDavid Howells 	RXRPC_CMD_SEND_DATA,		/* send data message */
67848124178SDavid Howells 	RXRPC_CMD_SEND_ABORT,		/* request abort generation */
67948124178SDavid Howells 	RXRPC_CMD_ACCEPT,		/* [server] accept incoming call */
68048124178SDavid Howells 	RXRPC_CMD_REJECT_BUSY,		/* [server] reject a call as busy */
68148124178SDavid Howells };
68248124178SDavid Howells 
68348124178SDavid Howells struct rxrpc_call_params {
68448124178SDavid Howells 	s64			tx_total_len;	/* Total Tx data length (if send data) */
68548124178SDavid Howells 	unsigned long		user_call_ID;	/* User's call ID */
68648124178SDavid Howells 	struct {
68748124178SDavid Howells 		u32		hard;		/* Maximum lifetime (sec) */
68848124178SDavid Howells 		u32		idle;		/* Max time since last data packet (msec) */
68948124178SDavid Howells 		u32		normal;		/* Max time since last call packet (msec) */
69048124178SDavid Howells 	} timeouts;
69148124178SDavid Howells 	u8			nr_timeouts;	/* Number of timeouts specified */
69248124178SDavid Howells };
69348124178SDavid Howells 
69448124178SDavid Howells struct rxrpc_send_params {
69548124178SDavid Howells 	struct rxrpc_call_params call;
69648124178SDavid Howells 	u32			abort_code;	/* Abort code to Tx (if abort) */
69748124178SDavid Howells 	enum rxrpc_command	command : 8;	/* The command to implement */
69848124178SDavid Howells 	bool			exclusive;	/* Shared or exclusive call */
69948124178SDavid Howells 	bool			upgrade;	/* If the connection is upgradeable */
70048124178SDavid Howells };
70148124178SDavid Howells 
702df844fd4SDavid Howells #include <trace/events/rxrpc.h>
703df844fd4SDavid Howells 
70417926a79SDavid Howells /*
705651350d1SDavid Howells  * af_rxrpc.c
70617926a79SDavid Howells  */
70771f3ca40SDavid Howells extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
708651350d1SDavid Howells extern struct workqueue_struct *rxrpc_workqueue;
70917926a79SDavid Howells 
71017926a79SDavid Howells /*
7110d81a51aSDavid Howells  * call_accept.c
71217926a79SDavid Howells  */
71300e90712SDavid Howells int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
71400e90712SDavid Howells void rxrpc_discard_prealloc(struct rxrpc_sock *);
715248f219cSDavid Howells struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
716248f219cSDavid Howells 					   struct rxrpc_connection *,
717248f219cSDavid Howells 					   struct sk_buff *);
7184f95dd78SDavid Howells void rxrpc_accept_incoming_calls(struct rxrpc_local *);
719d001648eSDavid Howells struct rxrpc_call *rxrpc_accept_call(struct rxrpc_sock *, unsigned long,
720d001648eSDavid Howells 				     rxrpc_notify_rx_t);
721c1b1203dSJoe Perches int rxrpc_reject_call(struct rxrpc_sock *);
72217926a79SDavid Howells 
72317926a79SDavid Howells /*
7240d81a51aSDavid Howells  * call_event.c
72517926a79SDavid Howells  */
7269c7ad434SDavid Howells void rxrpc_propose_ACK(struct rxrpc_call *, u8, u16, u32, bool, bool,
7279c7ad434SDavid Howells 		       enum rxrpc_propose_ack_trace);
728c1b1203dSJoe Perches void rxrpc_process_call(struct work_struct *);
72917926a79SDavid Howells 
730a158bdd3SDavid Howells static inline void rxrpc_reduce_call_timer(struct rxrpc_call *call,
731a158bdd3SDavid Howells 					   unsigned long expire_at,
732a158bdd3SDavid Howells 					   unsigned long now,
733a158bdd3SDavid Howells 					   enum rxrpc_timer_trace why)
734a158bdd3SDavid Howells {
735a158bdd3SDavid Howells 	trace_rxrpc_timer(call, why, now);
736a158bdd3SDavid Howells 	timer_reduce(&call->timer, expire_at);
737a158bdd3SDavid Howells }
738a158bdd3SDavid Howells 
73917926a79SDavid Howells /*
7400d81a51aSDavid Howells  * call_object.c
74117926a79SDavid Howells  */
742f5c17aaeSDavid Howells extern const char *const rxrpc_call_states[];
743f5c17aaeSDavid Howells extern const char *const rxrpc_call_completions[];
744dad8aff7SDavid Howells extern unsigned int rxrpc_max_call_lifetime;
74517926a79SDavid Howells extern struct kmem_cache *rxrpc_call_jar;
74617926a79SDavid Howells 
7472341e077SDavid Howells struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
748a25e21f0SDavid Howells struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
7492341e077SDavid Howells struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
75019ffa01cSDavid Howells 					 struct rxrpc_conn_parameters *,
751999b69f8SDavid Howells 					 struct sockaddr_rxrpc *,
752a25e21f0SDavid Howells 					 struct rxrpc_call_params *, gfp_t,
753a25e21f0SDavid Howells 					 unsigned int);
754c038a58cSDavid Howells int rxrpc_retry_client_call(struct rxrpc_sock *,
755c038a58cSDavid Howells 			    struct rxrpc_call *,
756c038a58cSDavid Howells 			    struct rxrpc_conn_parameters *,
757c038a58cSDavid Howells 			    struct sockaddr_rxrpc *,
758c038a58cSDavid Howells 			    gfp_t);
759248f219cSDavid Howells void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
76042886ffeSDavid Howells 			 struct sk_buff *);
7618d94aa38SDavid Howells void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
762c038a58cSDavid Howells int rxrpc_prepare_call_for_retry(struct rxrpc_sock *, struct rxrpc_call *);
763c1b1203dSJoe Perches void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
7648d94aa38SDavid Howells bool __rxrpc_queue_call(struct rxrpc_call *);
7658d94aa38SDavid Howells bool rxrpc_queue_call(struct rxrpc_call *);
766e34d4234SDavid Howells void rxrpc_see_call(struct rxrpc_call *);
767fff72429SDavid Howells void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
768fff72429SDavid Howells void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
76900e90712SDavid Howells void rxrpc_cleanup_call(struct rxrpc_call *);
7702baec2c3SDavid Howells void rxrpc_destroy_all_calls(struct rxrpc_net *);
77117926a79SDavid Howells 
772dabe5a79SDavid Howells static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
773dabe5a79SDavid Howells {
774dabe5a79SDavid Howells 	return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
775dabe5a79SDavid Howells }
776dabe5a79SDavid Howells 
777dabe5a79SDavid Howells static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
778dabe5a79SDavid Howells {
779dabe5a79SDavid Howells 	return !rxrpc_is_service_call(call);
780dabe5a79SDavid Howells }
781dabe5a79SDavid Howells 
78217926a79SDavid Howells /*
783f5c17aaeSDavid Howells  * Transition a call to the complete state.
784f5c17aaeSDavid Howells  */
785f5c17aaeSDavid Howells static inline bool __rxrpc_set_call_completion(struct rxrpc_call *call,
786f5c17aaeSDavid Howells 					       enum rxrpc_call_completion compl,
787f5c17aaeSDavid Howells 					       u32 abort_code,
788f5c17aaeSDavid Howells 					       int error)
789f5c17aaeSDavid Howells {
790f5c17aaeSDavid Howells 	if (call->state < RXRPC_CALL_COMPLETE) {
791f5c17aaeSDavid Howells 		call->abort_code = abort_code;
792f5c17aaeSDavid Howells 		call->error = error;
793f5c17aaeSDavid Howells 		call->completion = compl,
794f5c17aaeSDavid Howells 		call->state = RXRPC_CALL_COMPLETE;
7951bae5d22SDavid Howells 		trace_rxrpc_call_complete(call);
796c0d058c2SDavid Howells 		wake_up(&call->waitq);
797f5c17aaeSDavid Howells 		return true;
798f5c17aaeSDavid Howells 	}
799f5c17aaeSDavid Howells 	return false;
800f5c17aaeSDavid Howells }
801f5c17aaeSDavid Howells 
802f5c17aaeSDavid Howells static inline bool rxrpc_set_call_completion(struct rxrpc_call *call,
803f5c17aaeSDavid Howells 					     enum rxrpc_call_completion compl,
804f5c17aaeSDavid Howells 					     u32 abort_code,
805f5c17aaeSDavid Howells 					     int error)
806f5c17aaeSDavid Howells {
807e8d6bbb0SDavid Howells 	bool ret;
808f5c17aaeSDavid Howells 
809f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
810f5c17aaeSDavid Howells 	ret = __rxrpc_set_call_completion(call, compl, abort_code, error);
811f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
812f5c17aaeSDavid Howells 	return ret;
813f5c17aaeSDavid Howells }
814f5c17aaeSDavid Howells 
815f5c17aaeSDavid Howells /*
816f5c17aaeSDavid Howells  * Record that a call successfully completed.
817f5c17aaeSDavid Howells  */
818e8d6bbb0SDavid Howells static inline bool __rxrpc_call_completed(struct rxrpc_call *call)
819f5c17aaeSDavid Howells {
820e8d6bbb0SDavid Howells 	return __rxrpc_set_call_completion(call, RXRPC_CALL_SUCCEEDED, 0, 0);
821f5c17aaeSDavid Howells }
822f5c17aaeSDavid Howells 
823e8d6bbb0SDavid Howells static inline bool rxrpc_call_completed(struct rxrpc_call *call)
824f5c17aaeSDavid Howells {
825e8d6bbb0SDavid Howells 	bool ret;
826e8d6bbb0SDavid Howells 
827f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
828e8d6bbb0SDavid Howells 	ret = __rxrpc_call_completed(call);
829f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
830e8d6bbb0SDavid Howells 	return ret;
831f5c17aaeSDavid Howells }
832f5c17aaeSDavid Howells 
833f5c17aaeSDavid Howells /*
834f5c17aaeSDavid Howells  * Record that a call is locally aborted.
835f5c17aaeSDavid Howells  */
8365a42976dSDavid Howells static inline bool __rxrpc_abort_call(const char *why, struct rxrpc_call *call,
8375a42976dSDavid Howells 				      rxrpc_seq_t seq,
838f5c17aaeSDavid Howells 				      u32 abort_code, int error)
839f5c17aaeSDavid Howells {
840a25e21f0SDavid Howells 	trace_rxrpc_abort(call->debug_id, why, call->cid, call->call_id, seq,
8415a42976dSDavid Howells 			  abort_code, error);
842248f219cSDavid Howells 	return __rxrpc_set_call_completion(call, RXRPC_CALL_LOCALLY_ABORTED,
843248f219cSDavid Howells 					   abort_code, error);
844f5c17aaeSDavid Howells }
845f5c17aaeSDavid Howells 
8465a42976dSDavid Howells static inline bool rxrpc_abort_call(const char *why, struct rxrpc_call *call,
8475a42976dSDavid Howells 				    rxrpc_seq_t seq, u32 abort_code, int error)
848f5c17aaeSDavid Howells {
849f5c17aaeSDavid Howells 	bool ret;
850f5c17aaeSDavid Howells 
851f5c17aaeSDavid Howells 	write_lock_bh(&call->state_lock);
8525a42976dSDavid Howells 	ret = __rxrpc_abort_call(why, call, seq, abort_code, error);
853f5c17aaeSDavid Howells 	write_unlock_bh(&call->state_lock);
854f5c17aaeSDavid Howells 	return ret;
855f5c17aaeSDavid Howells }
856f5c17aaeSDavid Howells 
857f5c17aaeSDavid Howells /*
858fb46f6eeSDavid Howells  * Abort a call due to a protocol error.
859fb46f6eeSDavid Howells  */
860fb46f6eeSDavid Howells static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
861fb46f6eeSDavid Howells 					struct sk_buff *skb,
862fb46f6eeSDavid Howells 					const char *eproto_why,
863fb46f6eeSDavid Howells 					const char *why,
864fb46f6eeSDavid Howells 					u32 abort_code)
865fb46f6eeSDavid Howells {
866fb46f6eeSDavid Howells 	struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
867fb46f6eeSDavid Howells 
868fb46f6eeSDavid Howells 	trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
869fb46f6eeSDavid Howells 	return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
870fb46f6eeSDavid Howells }
871fb46f6eeSDavid Howells 
872fb46f6eeSDavid Howells #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
873fb46f6eeSDavid Howells 	__rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
874fb46f6eeSDavid Howells 			     (abort_why), (abort_code))
875fb46f6eeSDavid Howells 
876fb46f6eeSDavid Howells /*
8774a3388c8SDavid Howells  * conn_client.c
8784a3388c8SDavid Howells  */
87945025bceSDavid Howells extern unsigned int rxrpc_max_client_connections;
88045025bceSDavid Howells extern unsigned int rxrpc_reap_client_connections;
881a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_expiry;
882a158bdd3SDavid Howells extern unsigned long rxrpc_conn_idle_client_fast_expiry;
8834a3388c8SDavid Howells extern struct idr rxrpc_client_conn_ids;
8844a3388c8SDavid Howells 
885eb9b9d22SDavid Howells void rxrpc_destroy_client_conn_ids(void);
886c6d2b8d7SDavid Howells int rxrpc_connect_call(struct rxrpc_call *, struct rxrpc_conn_parameters *,
887c6d2b8d7SDavid Howells 		       struct sockaddr_rxrpc *, gfp_t);
88845025bceSDavid Howells void rxrpc_expose_client_call(struct rxrpc_call *);
88945025bceSDavid Howells void rxrpc_disconnect_client_call(struct rxrpc_call *);
89045025bceSDavid Howells void rxrpc_put_client_conn(struct rxrpc_connection *);
8912baec2c3SDavid Howells void rxrpc_discard_expired_client_conns(struct work_struct *);
8922baec2c3SDavid Howells void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
8934a3388c8SDavid Howells 
8944a3388c8SDavid Howells /*
8950d81a51aSDavid Howells  * conn_event.c
8960d81a51aSDavid Howells  */
8970d81a51aSDavid Howells void rxrpc_process_connection(struct work_struct *);
8980d81a51aSDavid Howells 
8990d81a51aSDavid Howells /*
9000d81a51aSDavid Howells  * conn_object.c
90117926a79SDavid Howells  */
902dad8aff7SDavid Howells extern unsigned int rxrpc_connection_expiry;
903f859ab61SDavid Howells extern unsigned int rxrpc_closed_conn_expiry;
90417926a79SDavid Howells 
905c6d2b8d7SDavid Howells struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
9068496af50SDavid Howells struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
907aa390bbeSDavid Howells 						   struct sk_buff *);
90845025bceSDavid Howells void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
909999b69f8SDavid Howells void rxrpc_disconnect_call(struct rxrpc_call *);
91045025bceSDavid Howells void rxrpc_kill_connection(struct rxrpc_connection *);
911363deeabSDavid Howells bool rxrpc_queue_conn(struct rxrpc_connection *);
912363deeabSDavid Howells void rxrpc_see_connection(struct rxrpc_connection *);
913363deeabSDavid Howells void rxrpc_get_connection(struct rxrpc_connection *);
914363deeabSDavid Howells struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
915363deeabSDavid Howells void rxrpc_put_service_conn(struct rxrpc_connection *);
9162baec2c3SDavid Howells void rxrpc_service_connection_reaper(struct work_struct *);
9172baec2c3SDavid Howells void rxrpc_destroy_all_connections(struct rxrpc_net *);
91817926a79SDavid Howells 
91919ffa01cSDavid Howells static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
92019ffa01cSDavid Howells {
92119ffa01cSDavid Howells 	return conn->out_clientflag;
92219ffa01cSDavid Howells }
92319ffa01cSDavid Howells 
92419ffa01cSDavid Howells static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
92519ffa01cSDavid Howells {
926e8d70ce1SDavid Howells 	return !rxrpc_conn_is_client(conn);
92719ffa01cSDavid Howells }
92819ffa01cSDavid Howells 
929f51b4480SDavid Howells static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
930f51b4480SDavid Howells {
93145025bceSDavid Howells 	if (!conn)
93245025bceSDavid Howells 		return;
93345025bceSDavid Howells 
934363deeabSDavid Howells 	if (rxrpc_conn_is_client(conn))
93545025bceSDavid Howells 		rxrpc_put_client_conn(conn);
936363deeabSDavid Howells 	else
937363deeabSDavid Howells 		rxrpc_put_service_conn(conn);
9385acbee46SDavid Howells }
9395acbee46SDavid Howells 
9403136ef49SDavid Howells static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
9413136ef49SDavid Howells 					   unsigned long expire_at)
9423136ef49SDavid Howells {
9433136ef49SDavid Howells 	timer_reduce(&conn->timer, expire_at);
9443136ef49SDavid Howells }
9453136ef49SDavid Howells 
94617926a79SDavid Howells /*
9477877a4a4SDavid Howells  * conn_service.c
9487877a4a4SDavid Howells  */
9498496af50SDavid Howells struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
9508496af50SDavid Howells 						     struct sk_buff *);
9512baec2c3SDavid Howells struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
9524722974dSDavid Howells void rxrpc_new_incoming_connection(struct rxrpc_sock *,
9534722974dSDavid Howells 				   struct rxrpc_connection *, struct sk_buff *);
954001c1122SDavid Howells void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
9557877a4a4SDavid Howells 
9567877a4a4SDavid Howells /*
9570d81a51aSDavid Howells  * input.c
95817926a79SDavid Howells  */
959676d2369SDavid S. Miller void rxrpc_data_ready(struct sock *);
96017926a79SDavid Howells 
96117926a79SDavid Howells /*
9620d81a51aSDavid Howells  * insecure.c
96317926a79SDavid Howells  */
9640d81a51aSDavid Howells extern const struct rxrpc_security rxrpc_no_security;
96517926a79SDavid Howells 
96617926a79SDavid Howells /*
9670d81a51aSDavid Howells  * key.c
96817926a79SDavid Howells  */
96917926a79SDavid Howells extern struct key_type key_type_rxrpc;
97017926a79SDavid Howells extern struct key_type key_type_rxrpc_s;
97117926a79SDavid Howells 
972c1b1203dSJoe Perches int rxrpc_request_key(struct rxrpc_sock *, char __user *, int);
973c1b1203dSJoe Perches int rxrpc_server_keyring(struct rxrpc_sock *, char __user *, int);
97410674a03SBaolin Wang int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
975c1b1203dSJoe Perches 			      u32);
97617926a79SDavid Howells 
97717926a79SDavid Howells /*
97887563616SDavid Howells  * local_event.c
97987563616SDavid Howells  */
9804f95dd78SDavid Howells extern void rxrpc_process_local_events(struct rxrpc_local *);
98187563616SDavid Howells 
98287563616SDavid Howells /*
9830d81a51aSDavid Howells  * local_object.c
98417926a79SDavid Howells  */
9852baec2c3SDavid Howells struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
98609d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *);
98709d2bf59SDavid Howells struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *);
98809d2bf59SDavid Howells void rxrpc_put_local(struct rxrpc_local *);
98909d2bf59SDavid Howells void rxrpc_queue_local(struct rxrpc_local *);
9902baec2c3SDavid Howells void rxrpc_destroy_all_locals(struct rxrpc_net *);
991e0e4d82fSDavid Howells 
992e0e4d82fSDavid Howells /*
9938e688d9cSDavid Howells  * misc.c
9948e688d9cSDavid Howells  */
9950e119b41SDavid Howells extern unsigned int rxrpc_max_backlog __read_mostly;
996a158bdd3SDavid Howells extern unsigned long rxrpc_requested_ack_delay;
997a158bdd3SDavid Howells extern unsigned long rxrpc_soft_ack_delay;
998a158bdd3SDavid Howells extern unsigned long rxrpc_idle_ack_delay;
9998e688d9cSDavid Howells extern unsigned int rxrpc_rx_window_size;
10008e688d9cSDavid Howells extern unsigned int rxrpc_rx_mtu;
10018e688d9cSDavid Howells extern unsigned int rxrpc_rx_jumbo_max;
1002a158bdd3SDavid Howells extern unsigned long rxrpc_resend_timeout;
10038e688d9cSDavid Howells 
10048e688d9cSDavid Howells extern const s8 rxrpc_ack_priority[];
10058e688d9cSDavid Howells 
10068e688d9cSDavid Howells /*
10072baec2c3SDavid Howells  * net_ns.c
10082baec2c3SDavid Howells  */
10092baec2c3SDavid Howells extern unsigned int rxrpc_net_id;
10102baec2c3SDavid Howells extern struct pernet_operations rxrpc_net_ops;
10112baec2c3SDavid Howells 
10122baec2c3SDavid Howells static inline struct rxrpc_net *rxrpc_net(struct net *net)
10132baec2c3SDavid Howells {
10142baec2c3SDavid Howells 	return net_generic(net, rxrpc_net_id);
10152baec2c3SDavid Howells }
10162baec2c3SDavid Howells 
10172baec2c3SDavid Howells /*
10180d81a51aSDavid Howells  * output.c
10190d81a51aSDavid Howells  */
1020bd1fdf8cSDavid Howells int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *);
102126cb02aaSDavid Howells int rxrpc_send_abort_packet(struct rxrpc_call *);
1022a1767077SDavid Howells int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
1023248f219cSDavid Howells void rxrpc_reject_packets(struct rxrpc_local *);
1024ace45becSDavid Howells void rxrpc_send_keepalive(struct rxrpc_peer *);
10250d81a51aSDavid Howells 
10260d81a51aSDavid Howells /*
1027abe89ef0SDavid Howells  * peer_event.c
10280d81a51aSDavid Howells  */
1029abe89ef0SDavid Howells void rxrpc_error_report(struct sock *);
1030f66d7490SDavid Howells void rxrpc_peer_error_distributor(struct work_struct *);
1031cf1a6474SDavid Howells void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace,
1032cf1a6474SDavid Howells 			rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
1033ace45becSDavid Howells void rxrpc_peer_keepalive_worker(struct work_struct *);
10340d81a51aSDavid Howells 
10350d81a51aSDavid Howells /*
10360d81a51aSDavid Howells  * peer_object.c
10370d81a51aSDavid Howells  */
1038be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
1039be6e6707SDavid Howells 					 const struct sockaddr_rxrpc *);
1040be6e6707SDavid Howells struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_local *,
1041be6e6707SDavid Howells 				     struct sockaddr_rxrpc *, gfp_t);
1042be6e6707SDavid Howells struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
1043248f219cSDavid Howells struct rxrpc_peer *rxrpc_lookup_incoming_peer(struct rxrpc_local *,
1044248f219cSDavid Howells 					      struct rxrpc_peer *);
104517226f12SDavid Howells void rxrpc_destroy_all_peers(struct rxrpc_net *);
10461159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *);
10471159d4b4SDavid Howells struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *);
10481159d4b4SDavid Howells void rxrpc_put_peer(struct rxrpc_peer *);
10491159d4b4SDavid Howells void __rxrpc_queue_peer_error(struct rxrpc_peer *);
10500d81a51aSDavid Howells 
10510d81a51aSDavid Howells /*
10520d81a51aSDavid Howells  * proc.c
10530d81a51aSDavid Howells  */
10540d81a51aSDavid Howells extern const struct file_operations rxrpc_call_seq_fops;
10550d81a51aSDavid Howells extern const struct file_operations rxrpc_connection_seq_fops;
10560d81a51aSDavid Howells 
10570d81a51aSDavid Howells /*
10580d81a51aSDavid Howells  * recvmsg.c
10590d81a51aSDavid Howells  */
1060248f219cSDavid Howells void rxrpc_notify_socket(struct rxrpc_call *);
10610d81a51aSDavid Howells int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
10620d81a51aSDavid Howells 
10630d81a51aSDavid Howells /*
1064648af7fcSDavid Howells  * rxkad.c
1065648af7fcSDavid Howells  */
1066648af7fcSDavid Howells #ifdef CONFIG_RXKAD
1067648af7fcSDavid Howells extern const struct rxrpc_security rxkad;
1068648af7fcSDavid Howells #endif
1069648af7fcSDavid Howells 
1070648af7fcSDavid Howells /*
10710d81a51aSDavid Howells  * security.c
10720d81a51aSDavid Howells  */
10730d81a51aSDavid Howells int __init rxrpc_init_security(void);
10740d81a51aSDavid Howells void rxrpc_exit_security(void);
10750d81a51aSDavid Howells int rxrpc_init_client_conn_security(struct rxrpc_connection *);
10760d81a51aSDavid Howells int rxrpc_init_server_conn_security(struct rxrpc_connection *);
10770d81a51aSDavid Howells 
10780d81a51aSDavid Howells /*
10790b58b8a1SDavid Howells  * sendmsg.c
10800b58b8a1SDavid Howells  */
10810b58b8a1SDavid Howells int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
10820b58b8a1SDavid Howells 
10830b58b8a1SDavid Howells /*
10840d81a51aSDavid Howells  * skbuff.c
10850d81a51aSDavid Howells  */
1086d001648eSDavid Howells void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
10870d81a51aSDavid Howells void rxrpc_packet_destructor(struct sk_buff *);
108871f3ca40SDavid Howells void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
108971f3ca40SDavid Howells void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
109071f3ca40SDavid Howells void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
109171f3ca40SDavid Howells void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
109271f3ca40SDavid Howells void rxrpc_lose_skb(struct sk_buff *, enum rxrpc_skb_trace);
1093df844fd4SDavid Howells void rxrpc_purge_queue(struct sk_buff_head *);
10940d81a51aSDavid Howells 
10950d81a51aSDavid Howells /*
10965873c083SDavid Howells  * sysctl.c
10975873c083SDavid Howells  */
10985873c083SDavid Howells #ifdef CONFIG_SYSCTL
10995873c083SDavid Howells extern int __init rxrpc_sysctl_init(void);
11005873c083SDavid Howells extern void rxrpc_sysctl_exit(void);
11015873c083SDavid Howells #else
11025873c083SDavid Howells static inline int __init rxrpc_sysctl_init(void) { return 0; }
11035873c083SDavid Howells static inline void rxrpc_sysctl_exit(void) {}
11045873c083SDavid Howells #endif
11055873c083SDavid Howells 
11065873c083SDavid Howells /*
1107be6e6707SDavid Howells  * utils.c
1108be6e6707SDavid Howells  */
11097b674e39SDavid Howells int rxrpc_extract_addr_from_skb(struct rxrpc_local *, struct sockaddr_rxrpc *,
11107b674e39SDavid Howells 				struct sk_buff *);
1111be6e6707SDavid Howells 
1112248f219cSDavid Howells static inline bool before(u32 seq1, u32 seq2)
1113248f219cSDavid Howells {
1114248f219cSDavid Howells         return (s32)(seq1 - seq2) < 0;
1115248f219cSDavid Howells }
1116248f219cSDavid Howells static inline bool before_eq(u32 seq1, u32 seq2)
1117248f219cSDavid Howells {
1118248f219cSDavid Howells         return (s32)(seq1 - seq2) <= 0;
1119248f219cSDavid Howells }
1120248f219cSDavid Howells static inline bool after(u32 seq1, u32 seq2)
1121248f219cSDavid Howells {
1122248f219cSDavid Howells         return (s32)(seq1 - seq2) > 0;
1123248f219cSDavid Howells }
1124248f219cSDavid Howells static inline bool after_eq(u32 seq1, u32 seq2)
1125248f219cSDavid Howells {
1126248f219cSDavid Howells         return (s32)(seq1 - seq2) >= 0;
1127248f219cSDavid Howells }
1128248f219cSDavid Howells 
1129be6e6707SDavid Howells /*
113017926a79SDavid Howells  * debug tracing
113117926a79SDavid Howells  */
113295c96174SEric Dumazet extern unsigned int rxrpc_debug;
113317926a79SDavid Howells 
113417926a79SDavid Howells #define dbgprintk(FMT,...) \
11359f389f4bSSven Schnelle 	printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
113617926a79SDavid Howells 
11370dc47877SHarvey Harrison #define kenter(FMT,...)	dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
11380dc47877SHarvey Harrison #define kleave(FMT,...)	dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
113917926a79SDavid Howells #define kdebug(FMT,...)	dbgprintk("    "FMT ,##__VA_ARGS__)
114017926a79SDavid Howells #define kproto(FMT,...)	dbgprintk("### "FMT ,##__VA_ARGS__)
114117926a79SDavid Howells #define knet(FMT,...)	dbgprintk("@@@ "FMT ,##__VA_ARGS__)
114217926a79SDavid Howells 
114317926a79SDavid Howells 
114417926a79SDavid Howells #if defined(__KDEBUG)
114517926a79SDavid Howells #define _enter(FMT,...)	kenter(FMT,##__VA_ARGS__)
114617926a79SDavid Howells #define _leave(FMT,...)	kleave(FMT,##__VA_ARGS__)
114717926a79SDavid Howells #define _debug(FMT,...)	kdebug(FMT,##__VA_ARGS__)
114817926a79SDavid Howells #define _proto(FMT,...)	kproto(FMT,##__VA_ARGS__)
114917926a79SDavid Howells #define _net(FMT,...)	knet(FMT,##__VA_ARGS__)
115017926a79SDavid Howells 
115117926a79SDavid Howells #elif defined(CONFIG_AF_RXRPC_DEBUG)
115217926a79SDavid Howells #define RXRPC_DEBUG_KENTER	0x01
115317926a79SDavid Howells #define RXRPC_DEBUG_KLEAVE	0x02
115417926a79SDavid Howells #define RXRPC_DEBUG_KDEBUG	0x04
115517926a79SDavid Howells #define RXRPC_DEBUG_KPROTO	0x08
115617926a79SDavid Howells #define RXRPC_DEBUG_KNET	0x10
115717926a79SDavid Howells 
115817926a79SDavid Howells #define _enter(FMT,...)					\
115917926a79SDavid Howells do {							\
116017926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER))	\
116117926a79SDavid Howells 		kenter(FMT,##__VA_ARGS__);		\
116217926a79SDavid Howells } while (0)
116317926a79SDavid Howells 
116417926a79SDavid Howells #define _leave(FMT,...)					\
116517926a79SDavid Howells do {							\
116617926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE))	\
116717926a79SDavid Howells 		kleave(FMT,##__VA_ARGS__);		\
116817926a79SDavid Howells } while (0)
116917926a79SDavid Howells 
117017926a79SDavid Howells #define _debug(FMT,...)					\
117117926a79SDavid Howells do {							\
117217926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG))	\
117317926a79SDavid Howells 		kdebug(FMT,##__VA_ARGS__);		\
117417926a79SDavid Howells } while (0)
117517926a79SDavid Howells 
117617926a79SDavid Howells #define _proto(FMT,...)					\
117717926a79SDavid Howells do {							\
117817926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO))	\
117917926a79SDavid Howells 		kproto(FMT,##__VA_ARGS__);		\
118017926a79SDavid Howells } while (0)
118117926a79SDavid Howells 
118217926a79SDavid Howells #define _net(FMT,...)					\
118317926a79SDavid Howells do {							\
118417926a79SDavid Howells 	if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))	\
118517926a79SDavid Howells 		knet(FMT,##__VA_ARGS__);		\
118617926a79SDavid Howells } while (0)
118717926a79SDavid Howells 
118817926a79SDavid Howells #else
118912fdff3fSDavid Howells #define _enter(FMT,...)	no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
119012fdff3fSDavid Howells #define _leave(FMT,...)	no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
119112fdff3fSDavid Howells #define _debug(FMT,...)	no_printk("    "FMT ,##__VA_ARGS__)
119212fdff3fSDavid Howells #define _proto(FMT,...)	no_printk("### "FMT ,##__VA_ARGS__)
119312fdff3fSDavid Howells #define _net(FMT,...)	no_printk("@@@ "FMT ,##__VA_ARGS__)
119417926a79SDavid Howells #endif
119517926a79SDavid Howells 
119617926a79SDavid Howells /*
119717926a79SDavid Howells  * debug assertion checking
119817926a79SDavid Howells  */
119917926a79SDavid Howells #if 1 // defined(__KDEBUGALL)
120017926a79SDavid Howells 
120117926a79SDavid Howells #define ASSERT(X)						\
120217926a79SDavid Howells do {								\
120317926a79SDavid Howells 	if (unlikely(!(X))) {					\
12049b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
120517926a79SDavid Howells 		BUG();						\
120617926a79SDavid Howells 	}							\
120717926a79SDavid Howells } while (0)
120817926a79SDavid Howells 
120917926a79SDavid Howells #define ASSERTCMP(X, OP, Y)						\
121017926a79SDavid Howells do {									\
1211cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1212cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12139b6d5398SJoe Perches 	if (unlikely(!(_x OP _y))) {					\
12149b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1215cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1216cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
121717926a79SDavid Howells 		BUG();							\
121817926a79SDavid Howells 	}								\
121917926a79SDavid Howells } while (0)
122017926a79SDavid Howells 
122117926a79SDavid Howells #define ASSERTIF(C, X)						\
122217926a79SDavid Howells do {								\
122317926a79SDavid Howells 	if (unlikely((C) && !(X))) {				\
12249b6d5398SJoe Perches 		pr_err("Assertion failed\n");			\
122517926a79SDavid Howells 		BUG();						\
122617926a79SDavid Howells 	}							\
122717926a79SDavid Howells } while (0)
122817926a79SDavid Howells 
122917926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)					\
123017926a79SDavid Howells do {									\
1231cf13258fSDavid Howells 	__typeof__(X) _x = (X);						\
1232cf13258fSDavid Howells 	__typeof__(Y) _y = (__typeof__(X))(Y);				\
12339b6d5398SJoe Perches 	if (unlikely((C) && !(_x OP _y))) {				\
12349b6d5398SJoe Perches 		pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1235cf13258fSDavid Howells 		       (unsigned long)_x, (unsigned long)_x, #OP,	\
1236cf13258fSDavid Howells 		       (unsigned long)_y, (unsigned long)_y);		\
123717926a79SDavid Howells 		BUG();							\
123817926a79SDavid Howells 	}								\
123917926a79SDavid Howells } while (0)
124017926a79SDavid Howells 
124117926a79SDavid Howells #else
124217926a79SDavid Howells 
124317926a79SDavid Howells #define ASSERT(X)				\
124417926a79SDavid Howells do {						\
124517926a79SDavid Howells } while (0)
124617926a79SDavid Howells 
124717926a79SDavid Howells #define ASSERTCMP(X, OP, Y)			\
124817926a79SDavid Howells do {						\
124917926a79SDavid Howells } while (0)
125017926a79SDavid Howells 
125117926a79SDavid Howells #define ASSERTIF(C, X)				\
125217926a79SDavid Howells do {						\
125317926a79SDavid Howells } while (0)
125417926a79SDavid Howells 
125517926a79SDavid Howells #define ASSERTIFCMP(C, X, OP, Y)		\
125617926a79SDavid Howells do {						\
125717926a79SDavid Howells } while (0)
125817926a79SDavid Howells 
125917926a79SDavid Howells #endif /* __KDEBUGALL */
1260