1 /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 /* AF_RXRPC internal definitions 3 * 4 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. 5 * Written by David Howells (dhowells@redhat.com) 6 */ 7 8 #include <linux/atomic.h> 9 #include <linux/seqlock.h> 10 #include <linux/win_minmax.h> 11 #include <net/net_namespace.h> 12 #include <net/netns/generic.h> 13 #include <net/sock.h> 14 #include <net/af_rxrpc.h> 15 #include <keys/rxrpc-type.h> 16 #include "protocol.h" 17 18 #define FCRYPT_BSIZE 8 19 struct rxrpc_crypt { 20 union { 21 u8 x[FCRYPT_BSIZE]; 22 __be32 n[2]; 23 }; 24 } __attribute__((aligned(8))); 25 26 #define rxrpc_queue_work(WS) queue_work(rxrpc_workqueue, (WS)) 27 #define rxrpc_queue_delayed_work(WS,D) \ 28 queue_delayed_work(rxrpc_workqueue, (WS), (D)) 29 30 struct key_preparsed_payload; 31 struct rxrpc_connection; 32 33 /* 34 * Mark applied to socket buffers in skb->mark. skb->priority is used 35 * to pass supplementary information. 36 */ 37 enum rxrpc_skb_mark { 38 RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */ 39 RXRPC_SKB_MARK_REJECT_ABORT, /* Reject with ABORT (code in skb->priority) */ 40 }; 41 42 /* 43 * sk_state for RxRPC sockets 44 */ 45 enum { 46 RXRPC_UNBOUND = 0, 47 RXRPC_CLIENT_UNBOUND, /* Unbound socket used as client */ 48 RXRPC_CLIENT_BOUND, /* client local address bound */ 49 RXRPC_SERVER_BOUND, /* server local address bound */ 50 RXRPC_SERVER_BOUND2, /* second server local address bound */ 51 RXRPC_SERVER_LISTENING, /* server listening for connections */ 52 RXRPC_SERVER_LISTEN_DISABLED, /* server listening disabled */ 53 RXRPC_CLOSE, /* socket is being closed */ 54 }; 55 56 /* 57 * Per-network namespace data. 58 */ 59 struct rxrpc_net { 60 struct proc_dir_entry *proc_net; /* Subdir in /proc/net */ 61 u32 epoch; /* Local epoch for detecting local-end reset */ 62 struct list_head calls; /* List of calls active in this namespace */ 63 spinlock_t call_lock; /* Lock for ->calls */ 64 atomic_t nr_calls; /* Count of allocated calls */ 65 66 atomic_t nr_conns; 67 struct list_head conn_proc_list; /* List of conns in this namespace for proc */ 68 struct list_head service_conns; /* Service conns in this namespace */ 69 rwlock_t conn_lock; /* Lock for ->conn_proc_list, ->service_conns */ 70 struct work_struct service_conn_reaper; 71 struct timer_list service_conn_reap_timer; 72 73 bool live; 74 75 bool kill_all_client_conns; 76 atomic_t nr_client_conns; 77 spinlock_t client_conn_cache_lock; /* Lock for ->*_client_conns */ 78 spinlock_t client_conn_discard_lock; /* Prevent multiple discarders */ 79 struct list_head idle_client_conns; 80 struct work_struct client_conn_reaper; 81 struct timer_list client_conn_reap_timer; 82 83 struct hlist_head local_endpoints; 84 struct mutex local_mutex; /* Lock for ->local_endpoints */ 85 86 DECLARE_HASHTABLE (peer_hash, 10); 87 spinlock_t peer_hash_lock; /* Lock for ->peer_hash */ 88 89 #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */ 90 u8 peer_keepalive_cursor; 91 time64_t peer_keepalive_base; 92 struct list_head peer_keepalive[32]; 93 struct list_head peer_keepalive_new; 94 struct timer_list peer_keepalive_timer; 95 struct work_struct peer_keepalive_work; 96 97 atomic_t stat_tx_data; 98 atomic_t stat_tx_data_retrans; 99 atomic_t stat_tx_data_send; 100 atomic_t stat_tx_data_send_frag; 101 atomic_t stat_rx_data; 102 atomic_t stat_rx_data_reqack; 103 atomic_t stat_rx_data_jumbo; 104 105 atomic_t stat_tx_ack_fill; 106 atomic_t stat_tx_ack_send; 107 atomic_t stat_tx_ack_skip; 108 atomic_t stat_tx_acks[256]; 109 atomic_t stat_rx_acks[256]; 110 }; 111 112 /* 113 * Service backlog preallocation. 114 * 115 * This contains circular buffers of preallocated peers, connections and calls 116 * for incoming service calls and their head and tail pointers. This allows 117 * calls to be set up in the data_ready handler, thereby avoiding the need to 118 * shuffle packets around so much. 119 */ 120 struct rxrpc_backlog { 121 unsigned short peer_backlog_head; 122 unsigned short peer_backlog_tail; 123 unsigned short conn_backlog_head; 124 unsigned short conn_backlog_tail; 125 unsigned short call_backlog_head; 126 unsigned short call_backlog_tail; 127 #define RXRPC_BACKLOG_MAX 32 128 struct rxrpc_peer *peer_backlog[RXRPC_BACKLOG_MAX]; 129 struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX]; 130 struct rxrpc_call *call_backlog[RXRPC_BACKLOG_MAX]; 131 }; 132 133 /* 134 * RxRPC socket definition 135 */ 136 struct rxrpc_sock { 137 /* WARNING: sk has to be the first member */ 138 struct sock sk; 139 rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */ 140 rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */ 141 struct rxrpc_local *local; /* local endpoint */ 142 struct rxrpc_backlog *backlog; /* Preallocation for services */ 143 spinlock_t incoming_lock; /* Incoming call vs service shutdown lock */ 144 struct list_head sock_calls; /* List of calls owned by this socket */ 145 struct list_head to_be_accepted; /* calls awaiting acceptance */ 146 struct list_head recvmsg_q; /* Calls awaiting recvmsg's attention */ 147 rwlock_t recvmsg_lock; /* Lock for recvmsg_q */ 148 struct key *key; /* security for this socket */ 149 struct key *securities; /* list of server security descriptors */ 150 struct rb_root calls; /* User ID -> call mapping */ 151 unsigned long flags; 152 #define RXRPC_SOCK_CONNECTED 0 /* connect_srx is set */ 153 rwlock_t call_lock; /* lock for calls */ 154 u32 min_sec_level; /* minimum security level */ 155 #define RXRPC_SECURITY_MAX RXRPC_SECURITY_ENCRYPT 156 bool exclusive; /* Exclusive connection for a client socket */ 157 u16 second_service; /* Additional service bound to the endpoint */ 158 struct { 159 /* Service upgrade information */ 160 u16 from; /* Service ID to upgrade (if not 0) */ 161 u16 to; /* service ID to upgrade to */ 162 } service_upgrade; 163 sa_family_t family; /* Protocol family created with */ 164 struct sockaddr_rxrpc srx; /* Primary Service/local addresses */ 165 struct sockaddr_rxrpc connect_srx; /* Default client address from connect() */ 166 }; 167 168 #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk) 169 170 /* 171 * CPU-byteorder normalised Rx packet header. 172 */ 173 struct rxrpc_host_header { 174 u32 epoch; /* client boot timestamp */ 175 u32 cid; /* connection and channel ID */ 176 u32 callNumber; /* call ID (0 for connection-level packets) */ 177 u32 seq; /* sequence number of pkt in call stream */ 178 u32 serial; /* serial number of pkt sent to network */ 179 u8 type; /* packet type */ 180 u8 flags; /* packet flags */ 181 u8 userStatus; /* app-layer defined status */ 182 u8 securityIndex; /* security protocol ID */ 183 union { 184 u16 _rsvd; /* reserved */ 185 u16 cksum; /* kerberos security checksum */ 186 }; 187 u16 serviceId; /* service ID */ 188 } __packed; 189 190 /* 191 * RxRPC socket buffer private variables 192 * - max 48 bytes (struct sk_buff::cb) 193 */ 194 struct rxrpc_skb_priv { 195 atomic_t nr_ring_pins; /* Number of rxtx ring pins */ 196 u8 nr_subpackets; /* Number of subpackets */ 197 u8 rx_flags; /* Received packet flags */ 198 #define RXRPC_SKB_INCL_LAST 0x01 /* - Includes last packet */ 199 #define RXRPC_SKB_TX_BUFFER 0x02 /* - Is transmit buffer */ 200 union { 201 int remain; /* amount of space remaining for next write */ 202 203 /* List of requested ACKs on subpackets */ 204 unsigned long rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) / 205 BITS_PER_LONG]; 206 }; 207 208 struct rxrpc_host_header hdr; /* RxRPC packet header from this packet */ 209 }; 210 211 #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb) 212 213 /* 214 * RxRPC security module interface 215 */ 216 struct rxrpc_security { 217 const char *name; /* name of this service */ 218 u8 security_index; /* security type provided */ 219 u32 no_key_abort; /* Abort code indicating no key */ 220 221 /* Initialise a security service */ 222 int (*init)(void); 223 224 /* Clean up a security service */ 225 void (*exit)(void); 226 227 /* Parse the information from a server key */ 228 int (*preparse_server_key)(struct key_preparsed_payload *); 229 230 /* Clean up the preparse buffer after parsing a server key */ 231 void (*free_preparse_server_key)(struct key_preparsed_payload *); 232 233 /* Destroy the payload of a server key */ 234 void (*destroy_server_key)(struct key *); 235 236 /* Describe a server key */ 237 void (*describe_server_key)(const struct key *, struct seq_file *); 238 239 /* initialise a connection's security */ 240 int (*init_connection_security)(struct rxrpc_connection *, 241 struct rxrpc_key_token *); 242 243 /* Work out how much data we can store in a packet, given an estimate 244 * of the amount of data remaining. 245 */ 246 int (*how_much_data)(struct rxrpc_call *, size_t, 247 size_t *, size_t *, size_t *); 248 249 /* impose security on a packet */ 250 int (*secure_packet)(struct rxrpc_call *, struct sk_buff *, size_t); 251 252 /* verify the security on a received packet */ 253 int (*verify_packet)(struct rxrpc_call *, struct sk_buff *, 254 unsigned int, unsigned int, rxrpc_seq_t, u16); 255 256 /* Free crypto request on a call */ 257 void (*free_call_crypto)(struct rxrpc_call *); 258 259 /* Locate the data in a received packet that has been verified. */ 260 void (*locate_data)(struct rxrpc_call *, struct sk_buff *, 261 unsigned int *, unsigned int *); 262 263 /* issue a challenge */ 264 int (*issue_challenge)(struct rxrpc_connection *); 265 266 /* respond to a challenge */ 267 int (*respond_to_challenge)(struct rxrpc_connection *, 268 struct sk_buff *, 269 u32 *); 270 271 /* verify a response */ 272 int (*verify_response)(struct rxrpc_connection *, 273 struct sk_buff *, 274 u32 *); 275 276 /* clear connection security */ 277 void (*clear)(struct rxrpc_connection *); 278 }; 279 280 /* 281 * RxRPC local transport endpoint description 282 * - owned by a single AF_RXRPC socket 283 * - pointed to by transport socket struct sk_user_data 284 */ 285 struct rxrpc_local { 286 struct rcu_head rcu; 287 atomic_t active_users; /* Number of users of the local endpoint */ 288 refcount_t ref; /* Number of references to the structure */ 289 struct rxrpc_net *rxnet; /* The network ns in which this resides */ 290 struct hlist_node link; 291 struct socket *socket; /* my UDP socket */ 292 struct work_struct processor; 293 struct rxrpc_sock __rcu *service; /* Service(s) listening on this endpoint */ 294 struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */ 295 struct sk_buff_head reject_queue; /* packets awaiting rejection */ 296 struct sk_buff_head event_queue; /* endpoint event packets awaiting processing */ 297 struct rb_root client_bundles; /* Client connection bundles by socket params */ 298 spinlock_t client_bundles_lock; /* Lock for client_bundles */ 299 spinlock_t lock; /* access lock */ 300 rwlock_t services_lock; /* lock for services list */ 301 int debug_id; /* debug ID for printks */ 302 bool dead; 303 bool service_closed; /* Service socket closed */ 304 struct sockaddr_rxrpc srx; /* local address */ 305 }; 306 307 /* 308 * RxRPC remote transport endpoint definition 309 * - matched by local endpoint, remote port, address and protocol type 310 */ 311 struct rxrpc_peer { 312 struct rcu_head rcu; /* This must be first */ 313 refcount_t ref; 314 unsigned long hash_key; 315 struct hlist_node hash_link; 316 struct rxrpc_local *local; 317 struct hlist_head error_targets; /* targets for net error distribution */ 318 struct rb_root service_conns; /* Service connections */ 319 struct list_head keepalive_link; /* Link in net->peer_keepalive[] */ 320 time64_t last_tx_at; /* Last time packet sent here */ 321 seqlock_t service_conn_lock; 322 spinlock_t lock; /* access lock */ 323 unsigned int if_mtu; /* interface MTU for this peer */ 324 unsigned int mtu; /* network MTU for this peer */ 325 unsigned int maxdata; /* data size (MTU - hdrsize) */ 326 unsigned short hdrsize; /* header size (IP + UDP + RxRPC) */ 327 int debug_id; /* debug ID for printks */ 328 struct sockaddr_rxrpc srx; /* remote address */ 329 330 /* calculated RTT cache */ 331 #define RXRPC_RTT_CACHE_SIZE 32 332 spinlock_t rtt_input_lock; /* RTT lock for input routine */ 333 ktime_t rtt_last_req; /* Time of last RTT request */ 334 unsigned int rtt_count; /* Number of samples we've got */ 335 336 u32 srtt_us; /* smoothed round trip time << 3 in usecs */ 337 u32 mdev_us; /* medium deviation */ 338 u32 mdev_max_us; /* maximal mdev for the last rtt period */ 339 u32 rttvar_us; /* smoothed mdev_max */ 340 u32 rto_j; /* Retransmission timeout in jiffies */ 341 u8 backoff; /* Backoff timeout */ 342 343 u8 cong_cwnd; /* Congestion window size */ 344 }; 345 346 /* 347 * Keys for matching a connection. 348 */ 349 struct rxrpc_conn_proto { 350 union { 351 struct { 352 u32 epoch; /* epoch of this connection */ 353 u32 cid; /* connection ID */ 354 }; 355 u64 index_key; 356 }; 357 }; 358 359 struct rxrpc_conn_parameters { 360 struct rxrpc_local *local; /* Representation of local endpoint */ 361 struct rxrpc_peer *peer; /* Remote endpoint */ 362 struct key *key; /* Security details */ 363 bool exclusive; /* T if conn is exclusive */ 364 bool upgrade; /* T if service ID can be upgraded */ 365 u16 service_id; /* Service ID for this connection */ 366 u32 security_level; /* Security level selected */ 367 }; 368 369 /* 370 * Bits in the connection flags. 371 */ 372 enum rxrpc_conn_flag { 373 RXRPC_CONN_HAS_IDR, /* Has a client conn ID assigned */ 374 RXRPC_CONN_IN_SERVICE_CONNS, /* Conn is in peer->service_conns */ 375 RXRPC_CONN_DONT_REUSE, /* Don't reuse this connection */ 376 RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */ 377 RXRPC_CONN_FINAL_ACK_0, /* Need final ACK for channel 0 */ 378 RXRPC_CONN_FINAL_ACK_1, /* Need final ACK for channel 1 */ 379 RXRPC_CONN_FINAL_ACK_2, /* Need final ACK for channel 2 */ 380 RXRPC_CONN_FINAL_ACK_3, /* Need final ACK for channel 3 */ 381 }; 382 383 #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) | \ 384 (1UL << RXRPC_CONN_FINAL_ACK_1) | \ 385 (1UL << RXRPC_CONN_FINAL_ACK_2) | \ 386 (1UL << RXRPC_CONN_FINAL_ACK_3)) 387 388 /* 389 * Events that can be raised upon a connection. 390 */ 391 enum rxrpc_conn_event { 392 RXRPC_CONN_EV_CHALLENGE, /* Send challenge packet */ 393 }; 394 395 /* 396 * The connection protocol state. 397 */ 398 enum rxrpc_conn_proto_state { 399 RXRPC_CONN_UNUSED, /* Connection not yet attempted */ 400 RXRPC_CONN_CLIENT, /* Client connection */ 401 RXRPC_CONN_SERVICE_PREALLOC, /* Service connection preallocation */ 402 RXRPC_CONN_SERVICE_UNSECURED, /* Service unsecured connection */ 403 RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */ 404 RXRPC_CONN_SERVICE, /* Service secured connection */ 405 RXRPC_CONN_REMOTELY_ABORTED, /* Conn aborted by peer */ 406 RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */ 407 RXRPC_CONN__NR_STATES 408 }; 409 410 /* 411 * RxRPC client connection bundle. 412 */ 413 struct rxrpc_bundle { 414 struct rxrpc_conn_parameters params; 415 refcount_t ref; 416 unsigned int debug_id; 417 bool try_upgrade; /* True if the bundle is attempting upgrade */ 418 bool alloc_conn; /* True if someone's getting a conn */ 419 short alloc_error; /* Error from last conn allocation */ 420 spinlock_t channel_lock; 421 struct rb_node local_node; /* Node in local->client_conns */ 422 struct list_head waiting_calls; /* Calls waiting for channels */ 423 unsigned long avail_chans; /* Mask of available channels */ 424 struct rxrpc_connection *conns[4]; /* The connections in the bundle (max 4) */ 425 }; 426 427 /* 428 * RxRPC connection definition 429 * - matched by { local, peer, epoch, conn_id, direction } 430 * - each connection can only handle four simultaneous calls 431 */ 432 struct rxrpc_connection { 433 struct rxrpc_conn_proto proto; 434 struct rxrpc_conn_parameters params; 435 436 refcount_t ref; 437 struct rcu_head rcu; 438 struct list_head cache_link; 439 440 unsigned char act_chans; /* Mask of active channels */ 441 struct rxrpc_channel { 442 unsigned long final_ack_at; /* Time at which to issue final ACK */ 443 struct rxrpc_call __rcu *call; /* Active call */ 444 unsigned int call_debug_id; /* call->debug_id */ 445 u32 call_id; /* ID of current call */ 446 u32 call_counter; /* Call ID counter */ 447 u32 last_call; /* ID of last call */ 448 u8 last_type; /* Type of last packet */ 449 union { 450 u32 last_seq; 451 u32 last_abort; 452 }; 453 } channels[RXRPC_MAXCALLS]; 454 455 struct timer_list timer; /* Conn event timer */ 456 struct work_struct processor; /* connection event processor */ 457 struct rxrpc_bundle *bundle; /* Client connection bundle */ 458 struct rb_node service_node; /* Node in peer->service_conns */ 459 struct list_head proc_link; /* link in procfs list */ 460 struct list_head link; /* link in master connection list */ 461 struct sk_buff_head rx_queue; /* received conn-level packets */ 462 463 const struct rxrpc_security *security; /* applied security module */ 464 union { 465 struct { 466 struct crypto_sync_skcipher *cipher; /* encryption handle */ 467 struct rxrpc_crypt csum_iv; /* packet checksum base */ 468 u32 nonce; /* response re-use preventer */ 469 } rxkad; 470 }; 471 unsigned long flags; 472 unsigned long events; 473 unsigned long idle_timestamp; /* Time at which last became idle */ 474 spinlock_t state_lock; /* state-change lock */ 475 enum rxrpc_conn_proto_state state; /* current state of connection */ 476 u32 abort_code; /* Abort code of connection abort */ 477 int debug_id; /* debug ID for printks */ 478 atomic_t serial; /* packet serial number counter */ 479 unsigned int hi_serial; /* highest serial number received */ 480 u32 service_id; /* Service ID, possibly upgraded */ 481 u8 security_ix; /* security type */ 482 u8 out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */ 483 u8 bundle_shift; /* Index into bundle->avail_chans */ 484 short error; /* Local error code */ 485 }; 486 487 static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp) 488 { 489 return sp->hdr.flags & RXRPC_CLIENT_INITIATED; 490 } 491 492 static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp) 493 { 494 return !rxrpc_to_server(sp); 495 } 496 497 /* 498 * Flags in call->flags. 499 */ 500 enum rxrpc_call_flag { 501 RXRPC_CALL_RELEASED, /* call has been released - no more message to userspace */ 502 RXRPC_CALL_HAS_USERID, /* has a user ID attached */ 503 RXRPC_CALL_IS_SERVICE, /* Call is service call */ 504 RXRPC_CALL_EXPOSED, /* The call was exposed to the world */ 505 RXRPC_CALL_RX_LAST, /* Received the last packet (at rxtx_top) */ 506 RXRPC_CALL_TX_LAST, /* Last packet in Tx buffer (at rxtx_top) */ 507 RXRPC_CALL_SEND_PING, /* A ping will need to be sent */ 508 RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */ 509 RXRPC_CALL_BEGAN_RX_TIMER, /* We began the expect_rx_by timer */ 510 RXRPC_CALL_RX_HEARD, /* The peer responded at least once to this call */ 511 RXRPC_CALL_RX_UNDERRUN, /* Got data underrun */ 512 RXRPC_CALL_DISCONNECTED, /* The call has been disconnected */ 513 RXRPC_CALL_KERNEL, /* The call was made by the kernel */ 514 RXRPC_CALL_UPGRADE, /* Service upgrade was requested for the call */ 515 }; 516 517 /* 518 * Events that can be raised on a call. 519 */ 520 enum rxrpc_call_event { 521 RXRPC_CALL_EV_ACK, /* need to generate ACK */ 522 RXRPC_CALL_EV_ABORT, /* need to generate abort */ 523 RXRPC_CALL_EV_RESEND, /* Tx resend required */ 524 RXRPC_CALL_EV_PING, /* Ping send required */ 525 RXRPC_CALL_EV_EXPIRED, /* Expiry occurred */ 526 RXRPC_CALL_EV_ACK_LOST, /* ACK may be lost, send ping */ 527 }; 528 529 /* 530 * The states that a call can be in. 531 */ 532 enum rxrpc_call_state { 533 RXRPC_CALL_UNINITIALISED, 534 RXRPC_CALL_CLIENT_AWAIT_CONN, /* - client waiting for connection to become available */ 535 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */ 536 RXRPC_CALL_CLIENT_AWAIT_REPLY, /* - client awaiting reply */ 537 RXRPC_CALL_CLIENT_RECV_REPLY, /* - client receiving reply phase */ 538 RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */ 539 RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */ 540 RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */ 541 RXRPC_CALL_SERVER_ACK_REQUEST, /* - server pending ACK of request */ 542 RXRPC_CALL_SERVER_SEND_REPLY, /* - server sending reply */ 543 RXRPC_CALL_SERVER_AWAIT_ACK, /* - server awaiting final ACK */ 544 RXRPC_CALL_COMPLETE, /* - call complete */ 545 NR__RXRPC_CALL_STATES 546 }; 547 548 /* 549 * Call completion condition (state == RXRPC_CALL_COMPLETE). 550 */ 551 enum rxrpc_call_completion { 552 RXRPC_CALL_SUCCEEDED, /* - Normal termination */ 553 RXRPC_CALL_REMOTELY_ABORTED, /* - call aborted by peer */ 554 RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */ 555 RXRPC_CALL_LOCAL_ERROR, /* - call failed due to local error */ 556 RXRPC_CALL_NETWORK_ERROR, /* - call terminated by network error */ 557 NR__RXRPC_CALL_COMPLETIONS 558 }; 559 560 /* 561 * Call Tx congestion management modes. 562 */ 563 enum rxrpc_congest_mode { 564 RXRPC_CALL_SLOW_START, 565 RXRPC_CALL_CONGEST_AVOIDANCE, 566 RXRPC_CALL_PACKET_LOSS, 567 RXRPC_CALL_FAST_RETRANSMIT, 568 NR__RXRPC_CONGEST_MODES 569 }; 570 571 /* 572 * RxRPC call definition 573 * - matched by { connection, call_id } 574 */ 575 struct rxrpc_call { 576 struct rcu_head rcu; 577 struct rxrpc_connection *conn; /* connection carrying call */ 578 struct rxrpc_peer *peer; /* Peer record for remote address */ 579 struct rxrpc_sock __rcu *socket; /* socket responsible */ 580 struct rxrpc_net *rxnet; /* Network namespace to which call belongs */ 581 const struct rxrpc_security *security; /* applied security module */ 582 struct mutex user_mutex; /* User access mutex */ 583 unsigned long ack_at; /* When deferred ACK needs to happen */ 584 unsigned long ack_lost_at; /* When ACK is figured as lost */ 585 unsigned long resend_at; /* When next resend needs to happen */ 586 unsigned long ping_at; /* When next to send a ping */ 587 unsigned long keepalive_at; /* When next to send a keepalive ping */ 588 unsigned long expect_rx_by; /* When we expect to get a packet by */ 589 unsigned long expect_req_by; /* When we expect to get a request DATA packet by */ 590 unsigned long expect_term_by; /* When we expect call termination by */ 591 u32 next_rx_timo; /* Timeout for next Rx packet (jif) */ 592 u32 next_req_timo; /* Timeout for next Rx request packet (jif) */ 593 struct skcipher_request *cipher_req; /* Packet cipher request buffer */ 594 struct timer_list timer; /* Combined event timer */ 595 struct work_struct processor; /* Event processor */ 596 rxrpc_notify_rx_t notify_rx; /* kernel service Rx notification function */ 597 struct list_head link; /* link in master call list */ 598 struct list_head chan_wait_link; /* Link in conn->bundle->waiting_calls */ 599 struct hlist_node error_link; /* link in error distribution list */ 600 struct list_head accept_link; /* Link in rx->acceptq */ 601 struct list_head recvmsg_link; /* Link in rx->recvmsg_q */ 602 struct list_head sock_link; /* Link in rx->sock_calls */ 603 struct rb_node sock_node; /* Node in rx->calls */ 604 struct sk_buff *tx_pending; /* Tx socket buffer being filled */ 605 wait_queue_head_t waitq; /* Wait queue for channel or Tx */ 606 s64 tx_total_len; /* Total length left to be transmitted (or -1) */ 607 __be32 crypto_buf[2]; /* Temporary packet crypto buffer */ 608 unsigned long user_call_ID; /* user-defined call ID */ 609 unsigned long flags; 610 unsigned long events; 611 spinlock_t lock; 612 spinlock_t notify_lock; /* Kernel notification lock */ 613 rwlock_t state_lock; /* lock for state transition */ 614 u32 abort_code; /* Local/remote abort code */ 615 int error; /* Local error incurred */ 616 enum rxrpc_call_state state; /* current state of call */ 617 enum rxrpc_call_completion completion; /* Call completion condition */ 618 refcount_t ref; 619 u16 service_id; /* service ID */ 620 u8 security_ix; /* Security type */ 621 enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */ 622 u32 call_id; /* call ID on connection */ 623 u32 cid; /* connection ID plus channel index */ 624 int debug_id; /* debug ID for printks */ 625 unsigned short rx_pkt_offset; /* Current recvmsg packet offset */ 626 unsigned short rx_pkt_len; /* Current recvmsg packet len */ 627 bool rx_pkt_last; /* Current recvmsg packet is last */ 628 629 /* Rx/Tx circular buffer, depending on phase. 630 * 631 * In the Rx phase, packets are annotated with 0 or the number of the 632 * segment of a jumbo packet each buffer refers to. There can be up to 633 * 47 segments in a maximum-size UDP packet. 634 * 635 * In the Tx phase, packets are annotated with which buffers have been 636 * acked. 637 */ 638 #define RXRPC_RXTX_BUFF_SIZE 64 639 #define RXRPC_RXTX_BUFF_MASK (RXRPC_RXTX_BUFF_SIZE - 1) 640 #define RXRPC_INIT_RX_WINDOW_SIZE 63 641 struct sk_buff **rxtx_buffer; 642 u8 *rxtx_annotations; 643 #define RXRPC_TX_ANNO_ACK 0 644 #define RXRPC_TX_ANNO_UNACK 1 645 #define RXRPC_TX_ANNO_NAK 2 646 #define RXRPC_TX_ANNO_RETRANS 3 647 #define RXRPC_TX_ANNO_MASK 0x03 648 #define RXRPC_TX_ANNO_LAST 0x04 649 #define RXRPC_TX_ANNO_RESENT 0x08 650 651 #define RXRPC_RX_ANNO_SUBPACKET 0x3f /* Subpacket number in jumbogram */ 652 #define RXRPC_RX_ANNO_VERIFIED 0x80 /* Set if verified and decrypted */ 653 rxrpc_seq_t tx_hard_ack; /* Dead slot in buffer; the first transmitted but 654 * not hard-ACK'd packet follows this. 655 */ 656 rxrpc_seq_t tx_top; /* Highest Tx slot allocated. */ 657 u16 tx_backoff; /* Delay to insert due to Tx failure */ 658 659 /* TCP-style slow-start congestion control [RFC5681]. Since the SMSS 660 * is fixed, we keep these numbers in terms of segments (ie. DATA 661 * packets) rather than bytes. 662 */ 663 #define RXRPC_TX_SMSS RXRPC_JUMBO_DATALEN 664 u8 cong_cwnd; /* Congestion window size */ 665 u8 cong_extra; /* Extra to send for congestion management */ 666 u8 cong_ssthresh; /* Slow-start threshold */ 667 enum rxrpc_congest_mode cong_mode:8; /* Congestion management mode */ 668 u8 cong_dup_acks; /* Count of ACKs showing missing packets */ 669 u8 cong_cumul_acks; /* Cumulative ACK count */ 670 ktime_t cong_tstamp; /* Last time cwnd was changed */ 671 672 rxrpc_seq_t rx_hard_ack; /* Dead slot in buffer; the first received but not 673 * consumed packet follows this. 674 */ 675 rxrpc_seq_t rx_top; /* Highest Rx slot allocated. */ 676 rxrpc_seq_t rx_expect_next; /* Expected next packet sequence number */ 677 rxrpc_serial_t rx_serial; /* Highest serial received for this call */ 678 u8 rx_winsize; /* Size of Rx window */ 679 u8 tx_winsize; /* Maximum size of Tx window */ 680 bool tx_phase; /* T if transmission phase, F if receive phase */ 681 u8 nr_jumbo_bad; /* Number of jumbo dups/exceeds-windows */ 682 683 spinlock_t input_lock; /* Lock for packet input to this call */ 684 685 /* Receive-phase ACK management (ACKs we send). */ 686 u8 ackr_reason; /* reason to ACK */ 687 rxrpc_serial_t ackr_serial; /* serial of packet being ACK'd */ 688 rxrpc_seq_t ackr_highest_seq; /* Higest sequence number received */ 689 atomic_t ackr_nr_unacked; /* Number of unacked packets */ 690 atomic_t ackr_nr_consumed; /* Number of packets needing hard ACK */ 691 692 /* RTT management */ 693 rxrpc_serial_t rtt_serial[4]; /* Serial number of DATA or PING sent */ 694 ktime_t rtt_sent_at[4]; /* Time packet sent */ 695 unsigned long rtt_avail; /* Mask of available slots in bits 0-3, 696 * Mask of pending samples in 8-11 */ 697 #define RXRPC_CALL_RTT_AVAIL_MASK 0xf 698 #define RXRPC_CALL_RTT_PEND_SHIFT 8 699 700 /* Transmission-phase ACK management (ACKs we've received). */ 701 ktime_t acks_latest_ts; /* Timestamp of latest ACK received */ 702 rxrpc_seq_t acks_first_seq; /* first sequence number received */ 703 rxrpc_seq_t acks_prev_seq; /* Highest previousPacket received */ 704 rxrpc_seq_t acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */ 705 rxrpc_seq_t acks_lost_top; /* tx_top at the time lost-ack ping sent */ 706 rxrpc_serial_t acks_lost_ping; /* Serial number of probe ACK */ 707 rxrpc_serial_t acks_highest_serial; /* Highest serial number ACK'd */ 708 }; 709 710 /* 711 * Summary of a new ACK and the changes it made to the Tx buffer packet states. 712 */ 713 struct rxrpc_ack_summary { 714 u8 ack_reason; 715 u8 nr_acks; /* Number of ACKs in packet */ 716 u8 nr_nacks; /* Number of NACKs in packet */ 717 u8 nr_new_acks; /* Number of new ACKs in packet */ 718 u8 nr_new_nacks; /* Number of new NACKs in packet */ 719 u8 nr_rot_new_acks; /* Number of rotated new ACKs */ 720 bool new_low_nack; /* T if new low NACK found */ 721 bool retrans_timeo; /* T if reTx due to timeout happened */ 722 u8 flight_size; /* Number of unreceived transmissions */ 723 /* Place to stash values for tracing */ 724 enum rxrpc_congest_mode mode:8; 725 u8 cwnd; 726 u8 ssthresh; 727 u8 dup_acks; 728 u8 cumulative_acks; 729 }; 730 731 /* 732 * sendmsg() cmsg-specified parameters. 733 */ 734 enum rxrpc_command { 735 RXRPC_CMD_SEND_DATA, /* send data message */ 736 RXRPC_CMD_SEND_ABORT, /* request abort generation */ 737 RXRPC_CMD_REJECT_BUSY, /* [server] reject a call as busy */ 738 RXRPC_CMD_CHARGE_ACCEPT, /* [server] charge accept preallocation */ 739 }; 740 741 struct rxrpc_call_params { 742 s64 tx_total_len; /* Total Tx data length (if send data) */ 743 unsigned long user_call_ID; /* User's call ID */ 744 struct { 745 u32 hard; /* Maximum lifetime (sec) */ 746 u32 idle; /* Max time since last data packet (msec) */ 747 u32 normal; /* Max time since last call packet (msec) */ 748 } timeouts; 749 u8 nr_timeouts; /* Number of timeouts specified */ 750 bool kernel; /* T if kernel is making the call */ 751 enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */ 752 }; 753 754 struct rxrpc_send_params { 755 struct rxrpc_call_params call; 756 u32 abort_code; /* Abort code to Tx (if abort) */ 757 enum rxrpc_command command : 8; /* The command to implement */ 758 bool exclusive; /* Shared or exclusive call */ 759 bool upgrade; /* If the connection is upgradeable */ 760 }; 761 762 #include <trace/events/rxrpc.h> 763 764 /* 765 * af_rxrpc.c 766 */ 767 extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs; 768 extern struct workqueue_struct *rxrpc_workqueue; 769 770 /* 771 * call_accept.c 772 */ 773 int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t); 774 void rxrpc_discard_prealloc(struct rxrpc_sock *); 775 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *, 776 struct rxrpc_sock *, 777 struct sk_buff *); 778 void rxrpc_accept_incoming_calls(struct rxrpc_local *); 779 int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long); 780 781 /* 782 * call_event.c 783 */ 784 void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool, 785 enum rxrpc_propose_ack_trace); 786 void rxrpc_process_call(struct work_struct *); 787 788 void rxrpc_reduce_call_timer(struct rxrpc_call *call, 789 unsigned long expire_at, 790 unsigned long now, 791 enum rxrpc_timer_trace why); 792 793 void rxrpc_delete_call_timer(struct rxrpc_call *call); 794 795 /* 796 * call_object.c 797 */ 798 extern const char *const rxrpc_call_states[]; 799 extern const char *const rxrpc_call_completions[]; 800 extern struct kmem_cache *rxrpc_call_jar; 801 802 struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long); 803 struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int); 804 struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *, 805 struct rxrpc_conn_parameters *, 806 struct sockaddr_rxrpc *, 807 struct rxrpc_call_params *, gfp_t, 808 unsigned int); 809 void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *, 810 struct sk_buff *); 811 void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *); 812 void rxrpc_release_calls_on_socket(struct rxrpc_sock *); 813 bool __rxrpc_queue_call(struct rxrpc_call *); 814 bool rxrpc_queue_call(struct rxrpc_call *); 815 void rxrpc_see_call(struct rxrpc_call *); 816 bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op); 817 void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace); 818 void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace); 819 void rxrpc_cleanup_call(struct rxrpc_call *); 820 void rxrpc_destroy_all_calls(struct rxrpc_net *); 821 822 static inline bool rxrpc_is_service_call(const struct rxrpc_call *call) 823 { 824 return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags); 825 } 826 827 static inline bool rxrpc_is_client_call(const struct rxrpc_call *call) 828 { 829 return !rxrpc_is_service_call(call); 830 } 831 832 /* 833 * conn_client.c 834 */ 835 extern unsigned int rxrpc_reap_client_connections; 836 extern unsigned long rxrpc_conn_idle_client_expiry; 837 extern unsigned long rxrpc_conn_idle_client_fast_expiry; 838 extern struct idr rxrpc_client_conn_ids; 839 840 void rxrpc_destroy_client_conn_ids(void); 841 struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *); 842 void rxrpc_put_bundle(struct rxrpc_bundle *); 843 int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *, 844 struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *, 845 gfp_t); 846 void rxrpc_expose_client_call(struct rxrpc_call *); 847 void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *); 848 void rxrpc_put_client_conn(struct rxrpc_connection *); 849 void rxrpc_discard_expired_client_conns(struct work_struct *); 850 void rxrpc_destroy_all_client_connections(struct rxrpc_net *); 851 void rxrpc_clean_up_local_conns(struct rxrpc_local *); 852 853 /* 854 * conn_event.c 855 */ 856 void rxrpc_process_connection(struct work_struct *); 857 void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool); 858 859 /* 860 * conn_object.c 861 */ 862 extern unsigned int rxrpc_connection_expiry; 863 extern unsigned int rxrpc_closed_conn_expiry; 864 865 struct rxrpc_connection *rxrpc_alloc_connection(gfp_t); 866 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *, 867 struct sk_buff *, 868 struct rxrpc_peer **); 869 void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *); 870 void rxrpc_disconnect_call(struct rxrpc_call *); 871 void rxrpc_kill_connection(struct rxrpc_connection *); 872 bool rxrpc_queue_conn(struct rxrpc_connection *); 873 void rxrpc_see_connection(struct rxrpc_connection *); 874 struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *); 875 struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *); 876 void rxrpc_put_service_conn(struct rxrpc_connection *); 877 void rxrpc_service_connection_reaper(struct work_struct *); 878 void rxrpc_destroy_all_connections(struct rxrpc_net *); 879 880 static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn) 881 { 882 return conn->out_clientflag; 883 } 884 885 static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn) 886 { 887 return !rxrpc_conn_is_client(conn); 888 } 889 890 static inline void rxrpc_put_connection(struct rxrpc_connection *conn) 891 { 892 if (!conn) 893 return; 894 895 if (rxrpc_conn_is_client(conn)) 896 rxrpc_put_client_conn(conn); 897 else 898 rxrpc_put_service_conn(conn); 899 } 900 901 static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn, 902 unsigned long expire_at) 903 { 904 timer_reduce(&conn->timer, expire_at); 905 } 906 907 /* 908 * conn_service.c 909 */ 910 struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *, 911 struct sk_buff *); 912 struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t); 913 void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *, 914 const struct rxrpc_security *, struct sk_buff *); 915 void rxrpc_unpublish_service_conn(struct rxrpc_connection *); 916 917 /* 918 * input.c 919 */ 920 int rxrpc_input_packet(struct sock *, struct sk_buff *); 921 922 /* 923 * insecure.c 924 */ 925 extern const struct rxrpc_security rxrpc_no_security; 926 927 /* 928 * key.c 929 */ 930 extern struct key_type key_type_rxrpc; 931 932 int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int); 933 int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t, 934 u32); 935 936 /* 937 * local_event.c 938 */ 939 extern void rxrpc_process_local_events(struct rxrpc_local *); 940 941 /* 942 * local_object.c 943 */ 944 struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *); 945 struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *); 946 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *); 947 void rxrpc_put_local(struct rxrpc_local *); 948 struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *); 949 void rxrpc_unuse_local(struct rxrpc_local *); 950 void rxrpc_queue_local(struct rxrpc_local *); 951 void rxrpc_destroy_all_locals(struct rxrpc_net *); 952 953 static inline bool __rxrpc_unuse_local(struct rxrpc_local *local) 954 { 955 return atomic_dec_return(&local->active_users) == 0; 956 } 957 958 static inline bool __rxrpc_use_local(struct rxrpc_local *local) 959 { 960 return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0; 961 } 962 963 /* 964 * misc.c 965 */ 966 extern unsigned int rxrpc_max_backlog __read_mostly; 967 extern unsigned long rxrpc_requested_ack_delay; 968 extern unsigned long rxrpc_soft_ack_delay; 969 extern unsigned long rxrpc_idle_ack_delay; 970 extern unsigned int rxrpc_rx_window_size; 971 extern unsigned int rxrpc_rx_mtu; 972 extern unsigned int rxrpc_rx_jumbo_max; 973 974 extern const s8 rxrpc_ack_priority[]; 975 976 /* 977 * net_ns.c 978 */ 979 extern unsigned int rxrpc_net_id; 980 extern struct pernet_operations rxrpc_net_ops; 981 982 static inline struct rxrpc_net *rxrpc_net(struct net *net) 983 { 984 return net_generic(net, rxrpc_net_id); 985 } 986 987 /* 988 * output.c 989 */ 990 int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *); 991 int rxrpc_send_abort_packet(struct rxrpc_call *); 992 int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool); 993 void rxrpc_reject_packets(struct rxrpc_local *); 994 void rxrpc_send_keepalive(struct rxrpc_peer *); 995 996 /* 997 * peer_event.c 998 */ 999 void rxrpc_encap_err_rcv(struct sock *sk, struct sk_buff *skb, unsigned int udp_offset); 1000 void rxrpc_error_report(struct sock *); 1001 void rxrpc_peer_keepalive_worker(struct work_struct *); 1002 1003 /* 1004 * peer_object.c 1005 */ 1006 struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *, 1007 const struct sockaddr_rxrpc *); 1008 struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *, 1009 struct sockaddr_rxrpc *, gfp_t); 1010 struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t); 1011 void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *, 1012 struct rxrpc_peer *); 1013 void rxrpc_destroy_all_peers(struct rxrpc_net *); 1014 struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *); 1015 struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *); 1016 void rxrpc_put_peer(struct rxrpc_peer *); 1017 void rxrpc_put_peer_locked(struct rxrpc_peer *); 1018 1019 /* 1020 * proc.c 1021 */ 1022 extern const struct seq_operations rxrpc_call_seq_ops; 1023 extern const struct seq_operations rxrpc_connection_seq_ops; 1024 extern const struct seq_operations rxrpc_peer_seq_ops; 1025 extern const struct seq_operations rxrpc_local_seq_ops; 1026 1027 /* 1028 * recvmsg.c 1029 */ 1030 void rxrpc_notify_socket(struct rxrpc_call *); 1031 bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); 1032 bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int); 1033 bool __rxrpc_call_completed(struct rxrpc_call *); 1034 bool rxrpc_call_completed(struct rxrpc_call *); 1035 bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 1036 bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int); 1037 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int); 1038 1039 /* 1040 * Abort a call due to a protocol error. 1041 */ 1042 static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call, 1043 struct sk_buff *skb, 1044 const char *eproto_why, 1045 const char *why, 1046 u32 abort_code) 1047 { 1048 struct rxrpc_skb_priv *sp = rxrpc_skb(skb); 1049 1050 trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why); 1051 return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO); 1052 } 1053 1054 #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \ 1055 __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \ 1056 (abort_why), (abort_code)) 1057 1058 /* 1059 * rtt.c 1060 */ 1061 void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int, 1062 rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t); 1063 unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool); 1064 void rxrpc_peer_init_rtt(struct rxrpc_peer *); 1065 1066 /* 1067 * rxkad.c 1068 */ 1069 #ifdef CONFIG_RXKAD 1070 extern const struct rxrpc_security rxkad; 1071 #endif 1072 1073 /* 1074 * security.c 1075 */ 1076 int __init rxrpc_init_security(void); 1077 const struct rxrpc_security *rxrpc_security_lookup(u8); 1078 void rxrpc_exit_security(void); 1079 int rxrpc_init_client_conn_security(struct rxrpc_connection *); 1080 const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *, 1081 struct sk_buff *); 1082 struct key *rxrpc_look_up_server_security(struct rxrpc_connection *, 1083 struct sk_buff *, u32, u32); 1084 1085 /* 1086 * sendmsg.c 1087 */ 1088 int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t); 1089 1090 /* 1091 * server_key.c 1092 */ 1093 extern struct key_type key_type_rxrpc_s; 1094 1095 int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int); 1096 1097 /* 1098 * skbuff.c 1099 */ 1100 void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *); 1101 void rxrpc_packet_destructor(struct sk_buff *); 1102 void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace); 1103 void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace); 1104 void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace); 1105 void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace); 1106 void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace); 1107 void rxrpc_purge_queue(struct sk_buff_head *); 1108 1109 /* 1110 * stats.c 1111 */ 1112 int rxrpc_stats_show(struct seq_file *seq, void *v); 1113 int rxrpc_stats_clear(struct file *file, char *buf, size_t size); 1114 1115 #define rxrpc_inc_stat(rxnet, s) atomic_inc(&(rxnet)->s) 1116 #define rxrpc_dec_stat(rxnet, s) atomic_dec(&(rxnet)->s) 1117 1118 /* 1119 * sysctl.c 1120 */ 1121 #ifdef CONFIG_SYSCTL 1122 extern int __init rxrpc_sysctl_init(void); 1123 extern void rxrpc_sysctl_exit(void); 1124 #else 1125 static inline int __init rxrpc_sysctl_init(void) { return 0; } 1126 static inline void rxrpc_sysctl_exit(void) {} 1127 #endif 1128 1129 /* 1130 * utils.c 1131 */ 1132 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *); 1133 1134 static inline bool before(u32 seq1, u32 seq2) 1135 { 1136 return (s32)(seq1 - seq2) < 0; 1137 } 1138 static inline bool before_eq(u32 seq1, u32 seq2) 1139 { 1140 return (s32)(seq1 - seq2) <= 0; 1141 } 1142 static inline bool after(u32 seq1, u32 seq2) 1143 { 1144 return (s32)(seq1 - seq2) > 0; 1145 } 1146 static inline bool after_eq(u32 seq1, u32 seq2) 1147 { 1148 return (s32)(seq1 - seq2) >= 0; 1149 } 1150 1151 /* 1152 * debug tracing 1153 */ 1154 extern unsigned int rxrpc_debug; 1155 1156 #define dbgprintk(FMT,...) \ 1157 printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__) 1158 1159 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 1160 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 1161 #define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__) 1162 #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__) 1163 #define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__) 1164 1165 1166 #if defined(__KDEBUG) 1167 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__) 1168 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__) 1169 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__) 1170 #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__) 1171 #define _net(FMT,...) knet(FMT,##__VA_ARGS__) 1172 1173 #elif defined(CONFIG_AF_RXRPC_DEBUG) 1174 #define RXRPC_DEBUG_KENTER 0x01 1175 #define RXRPC_DEBUG_KLEAVE 0x02 1176 #define RXRPC_DEBUG_KDEBUG 0x04 1177 #define RXRPC_DEBUG_KPROTO 0x08 1178 #define RXRPC_DEBUG_KNET 0x10 1179 1180 #define _enter(FMT,...) \ 1181 do { \ 1182 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \ 1183 kenter(FMT,##__VA_ARGS__); \ 1184 } while (0) 1185 1186 #define _leave(FMT,...) \ 1187 do { \ 1188 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \ 1189 kleave(FMT,##__VA_ARGS__); \ 1190 } while (0) 1191 1192 #define _debug(FMT,...) \ 1193 do { \ 1194 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \ 1195 kdebug(FMT,##__VA_ARGS__); \ 1196 } while (0) 1197 1198 #define _proto(FMT,...) \ 1199 do { \ 1200 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \ 1201 kproto(FMT,##__VA_ARGS__); \ 1202 } while (0) 1203 1204 #define _net(FMT,...) \ 1205 do { \ 1206 if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET)) \ 1207 knet(FMT,##__VA_ARGS__); \ 1208 } while (0) 1209 1210 #else 1211 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__) 1212 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__) 1213 #define _debug(FMT,...) no_printk(" "FMT ,##__VA_ARGS__) 1214 #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__) 1215 #define _net(FMT,...) no_printk("@@@ "FMT ,##__VA_ARGS__) 1216 #endif 1217 1218 /* 1219 * debug assertion checking 1220 */ 1221 #if 1 // defined(__KDEBUGALL) 1222 1223 #define ASSERT(X) \ 1224 do { \ 1225 if (unlikely(!(X))) { \ 1226 pr_err("Assertion failed\n"); \ 1227 BUG(); \ 1228 } \ 1229 } while (0) 1230 1231 #define ASSERTCMP(X, OP, Y) \ 1232 do { \ 1233 __typeof__(X) _x = (X); \ 1234 __typeof__(Y) _y = (__typeof__(X))(Y); \ 1235 if (unlikely(!(_x OP _y))) { \ 1236 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1237 (unsigned long)_x, (unsigned long)_x, #OP, \ 1238 (unsigned long)_y, (unsigned long)_y); \ 1239 BUG(); \ 1240 } \ 1241 } while (0) 1242 1243 #define ASSERTIF(C, X) \ 1244 do { \ 1245 if (unlikely((C) && !(X))) { \ 1246 pr_err("Assertion failed\n"); \ 1247 BUG(); \ 1248 } \ 1249 } while (0) 1250 1251 #define ASSERTIFCMP(C, X, OP, Y) \ 1252 do { \ 1253 __typeof__(X) _x = (X); \ 1254 __typeof__(Y) _y = (__typeof__(X))(Y); \ 1255 if (unlikely((C) && !(_x OP _y))) { \ 1256 pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \ 1257 (unsigned long)_x, (unsigned long)_x, #OP, \ 1258 (unsigned long)_y, (unsigned long)_y); \ 1259 BUG(); \ 1260 } \ 1261 } while (0) 1262 1263 #else 1264 1265 #define ASSERT(X) \ 1266 do { \ 1267 } while (0) 1268 1269 #define ASSERTCMP(X, OP, Y) \ 1270 do { \ 1271 } while (0) 1272 1273 #define ASSERTIF(C, X) \ 1274 do { \ 1275 } while (0) 1276 1277 #define ASSERTIFCMP(C, X, OP, Y) \ 1278 do { \ 1279 } while (0) 1280 1281 #endif /* __KDEBUGALL */ 1282