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