Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* AF_RXRPC internal definitions
0003  *
0004  * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
0005  * Written by David Howells (dhowells@redhat.com)
0006  */
0007 
0008 #include <linux/atomic.h>
0009 #include <linux/seqlock.h>
0010 #include <linux/win_minmax.h>
0011 #include <net/net_namespace.h>
0012 #include <net/netns/generic.h>
0013 #include <net/sock.h>
0014 #include <net/af_rxrpc.h>
0015 #include <keys/rxrpc-type.h>
0016 #include "protocol.h"
0017 
0018 #define FCRYPT_BSIZE 8
0019 struct rxrpc_crypt {
0020     union {
0021         u8  x[FCRYPT_BSIZE];
0022         __be32  n[2];
0023     };
0024 } __attribute__((aligned(8)));
0025 
0026 #define rxrpc_queue_work(WS)    queue_work(rxrpc_workqueue, (WS))
0027 #define rxrpc_queue_delayed_work(WS,D)  \
0028     queue_delayed_work(rxrpc_workqueue, (WS), (D))
0029 
0030 struct key_preparsed_payload;
0031 struct rxrpc_connection;
0032 
0033 /*
0034  * Mark applied to socket buffers in skb->mark.  skb->priority is used
0035  * to pass supplementary information.
0036  */
0037 enum rxrpc_skb_mark {
0038     RXRPC_SKB_MARK_REJECT_BUSY, /* Reject with BUSY */
0039     RXRPC_SKB_MARK_REJECT_ABORT,    /* Reject with ABORT (code in skb->priority) */
0040 };
0041 
0042 /*
0043  * sk_state for RxRPC sockets
0044  */
0045 enum {
0046     RXRPC_UNBOUND = 0,
0047     RXRPC_CLIENT_UNBOUND,       /* Unbound socket used as client */
0048     RXRPC_CLIENT_BOUND,     /* client local address bound */
0049     RXRPC_SERVER_BOUND,     /* server local address bound */
0050     RXRPC_SERVER_BOUND2,        /* second server local address bound */
0051     RXRPC_SERVER_LISTENING,     /* server listening for connections */
0052     RXRPC_SERVER_LISTEN_DISABLED,   /* server listening disabled */
0053     RXRPC_CLOSE,            /* socket is being closed */
0054 };
0055 
0056 /*
0057  * Per-network namespace data.
0058  */
0059 struct rxrpc_net {
0060     struct proc_dir_entry   *proc_net;  /* Subdir in /proc/net */
0061     u32         epoch;      /* Local epoch for detecting local-end reset */
0062     struct list_head    calls;      /* List of calls active in this namespace */
0063     spinlock_t      call_lock;  /* Lock for ->calls */
0064     atomic_t        nr_calls;   /* Count of allocated calls */
0065 
0066     atomic_t        nr_conns;
0067     struct list_head    conn_proc_list; /* List of conns in this namespace for proc */
0068     struct list_head    service_conns;  /* Service conns in this namespace */
0069     rwlock_t        conn_lock;  /* Lock for ->conn_proc_list, ->service_conns */
0070     struct work_struct  service_conn_reaper;
0071     struct timer_list   service_conn_reap_timer;
0072 
0073     bool            live;
0074 
0075     bool            kill_all_client_conns;
0076     atomic_t        nr_client_conns;
0077     spinlock_t      client_conn_cache_lock; /* Lock for ->*_client_conns */
0078     spinlock_t      client_conn_discard_lock; /* Prevent multiple discarders */
0079     struct list_head    idle_client_conns;
0080     struct work_struct  client_conn_reaper;
0081     struct timer_list   client_conn_reap_timer;
0082 
0083     struct hlist_head   local_endpoints;
0084     struct mutex        local_mutex;    /* Lock for ->local_endpoints */
0085 
0086     DECLARE_HASHTABLE   (peer_hash, 10);
0087     spinlock_t      peer_hash_lock; /* Lock for ->peer_hash */
0088 
0089 #define RXRPC_KEEPALIVE_TIME 20 /* NAT keepalive time in seconds */
0090     u8          peer_keepalive_cursor;
0091     time64_t        peer_keepalive_base;
0092     struct list_head    peer_keepalive[32];
0093     struct list_head    peer_keepalive_new;
0094     struct timer_list   peer_keepalive_timer;
0095     struct work_struct  peer_keepalive_work;
0096 };
0097 
0098 /*
0099  * Service backlog preallocation.
0100  *
0101  * This contains circular buffers of preallocated peers, connections and calls
0102  * for incoming service calls and their head and tail pointers.  This allows
0103  * calls to be set up in the data_ready handler, thereby avoiding the need to
0104  * shuffle packets around so much.
0105  */
0106 struct rxrpc_backlog {
0107     unsigned short      peer_backlog_head;
0108     unsigned short      peer_backlog_tail;
0109     unsigned short      conn_backlog_head;
0110     unsigned short      conn_backlog_tail;
0111     unsigned short      call_backlog_head;
0112     unsigned short      call_backlog_tail;
0113 #define RXRPC_BACKLOG_MAX   32
0114     struct rxrpc_peer   *peer_backlog[RXRPC_BACKLOG_MAX];
0115     struct rxrpc_connection *conn_backlog[RXRPC_BACKLOG_MAX];
0116     struct rxrpc_call   *call_backlog[RXRPC_BACKLOG_MAX];
0117 };
0118 
0119 /*
0120  * RxRPC socket definition
0121  */
0122 struct rxrpc_sock {
0123     /* WARNING: sk has to be the first member */
0124     struct sock     sk;
0125     rxrpc_notify_new_call_t notify_new_call; /* Func to notify of new call */
0126     rxrpc_discard_new_call_t discard_new_call; /* Func to discard a new call */
0127     struct rxrpc_local  *local;     /* local endpoint */
0128     struct rxrpc_backlog    *backlog;   /* Preallocation for services */
0129     spinlock_t      incoming_lock;  /* Incoming call vs service shutdown lock */
0130     struct list_head    sock_calls; /* List of calls owned by this socket */
0131     struct list_head    to_be_accepted; /* calls awaiting acceptance */
0132     struct list_head    recvmsg_q;  /* Calls awaiting recvmsg's attention  */
0133     rwlock_t        recvmsg_lock;   /* Lock for recvmsg_q */
0134     struct key      *key;       /* security for this socket */
0135     struct key      *securities;    /* list of server security descriptors */
0136     struct rb_root      calls;      /* User ID -> call mapping */
0137     unsigned long       flags;
0138 #define RXRPC_SOCK_CONNECTED        0   /* connect_srx is set */
0139     rwlock_t        call_lock;  /* lock for calls */
0140     u32         min_sec_level;  /* minimum security level */
0141 #define RXRPC_SECURITY_MAX  RXRPC_SECURITY_ENCRYPT
0142     bool            exclusive;  /* Exclusive connection for a client socket */
0143     u16         second_service; /* Additional service bound to the endpoint */
0144     struct {
0145         /* Service upgrade information */
0146         u16     from;       /* Service ID to upgrade (if not 0) */
0147         u16     to;     /* service ID to upgrade to */
0148     } service_upgrade;
0149     sa_family_t     family;     /* Protocol family created with */
0150     struct sockaddr_rxrpc   srx;        /* Primary Service/local addresses */
0151     struct sockaddr_rxrpc   connect_srx;    /* Default client address from connect() */
0152 };
0153 
0154 #define rxrpc_sk(__sk) container_of((__sk), struct rxrpc_sock, sk)
0155 
0156 /*
0157  * CPU-byteorder normalised Rx packet header.
0158  */
0159 struct rxrpc_host_header {
0160     u32     epoch;      /* client boot timestamp */
0161     u32     cid;        /* connection and channel ID */
0162     u32     callNumber; /* call ID (0 for connection-level packets) */
0163     u32     seq;        /* sequence number of pkt in call stream */
0164     u32     serial;     /* serial number of pkt sent to network */
0165     u8      type;       /* packet type */
0166     u8      flags;      /* packet flags */
0167     u8      userStatus; /* app-layer defined status */
0168     u8      securityIndex;  /* security protocol ID */
0169     union {
0170         u16 _rsvd;      /* reserved */
0171         u16 cksum;      /* kerberos security checksum */
0172     };
0173     u16     serviceId;  /* service ID */
0174 } __packed;
0175 
0176 /*
0177  * RxRPC socket buffer private variables
0178  * - max 48 bytes (struct sk_buff::cb)
0179  */
0180 struct rxrpc_skb_priv {
0181     atomic_t    nr_ring_pins;       /* Number of rxtx ring pins */
0182     u8      nr_subpackets;      /* Number of subpackets */
0183     u8      rx_flags;       /* Received packet flags */
0184 #define RXRPC_SKB_INCL_LAST 0x01        /* - Includes last packet */
0185 #define RXRPC_SKB_TX_BUFFER 0x02        /* - Is transmit buffer */
0186     union {
0187         int     remain;     /* amount of space remaining for next write */
0188 
0189         /* List of requested ACKs on subpackets */
0190         unsigned long   rx_req_ack[(RXRPC_MAX_NR_JUMBO + BITS_PER_LONG - 1) /
0191                        BITS_PER_LONG];
0192     };
0193 
0194     struct rxrpc_host_header hdr;       /* RxRPC packet header from this packet */
0195 };
0196 
0197 #define rxrpc_skb(__skb) ((struct rxrpc_skb_priv *) &(__skb)->cb)
0198 
0199 /*
0200  * RxRPC security module interface
0201  */
0202 struct rxrpc_security {
0203     const char      *name;      /* name of this service */
0204     u8          security_index; /* security type provided */
0205     u32         no_key_abort;   /* Abort code indicating no key */
0206 
0207     /* Initialise a security service */
0208     int (*init)(void);
0209 
0210     /* Clean up a security service */
0211     void (*exit)(void);
0212 
0213     /* Parse the information from a server key */
0214     int (*preparse_server_key)(struct key_preparsed_payload *);
0215 
0216     /* Clean up the preparse buffer after parsing a server key */
0217     void (*free_preparse_server_key)(struct key_preparsed_payload *);
0218 
0219     /* Destroy the payload of a server key */
0220     void (*destroy_server_key)(struct key *);
0221 
0222     /* Describe a server key */
0223     void (*describe_server_key)(const struct key *, struct seq_file *);
0224 
0225     /* initialise a connection's security */
0226     int (*init_connection_security)(struct rxrpc_connection *,
0227                     struct rxrpc_key_token *);
0228 
0229     /* Work out how much data we can store in a packet, given an estimate
0230      * of the amount of data remaining.
0231      */
0232     int (*how_much_data)(struct rxrpc_call *, size_t,
0233                  size_t *, size_t *, size_t *);
0234 
0235     /* impose security on a packet */
0236     int (*secure_packet)(struct rxrpc_call *, struct sk_buff *, size_t);
0237 
0238     /* verify the security on a received packet */
0239     int (*verify_packet)(struct rxrpc_call *, struct sk_buff *,
0240                  unsigned int, unsigned int, rxrpc_seq_t, u16);
0241 
0242     /* Free crypto request on a call */
0243     void (*free_call_crypto)(struct rxrpc_call *);
0244 
0245     /* Locate the data in a received packet that has been verified. */
0246     void (*locate_data)(struct rxrpc_call *, struct sk_buff *,
0247                 unsigned int *, unsigned int *);
0248 
0249     /* issue a challenge */
0250     int (*issue_challenge)(struct rxrpc_connection *);
0251 
0252     /* respond to a challenge */
0253     int (*respond_to_challenge)(struct rxrpc_connection *,
0254                     struct sk_buff *,
0255                     u32 *);
0256 
0257     /* verify a response */
0258     int (*verify_response)(struct rxrpc_connection *,
0259                    struct sk_buff *,
0260                    u32 *);
0261 
0262     /* clear connection security */
0263     void (*clear)(struct rxrpc_connection *);
0264 };
0265 
0266 /*
0267  * RxRPC local transport endpoint description
0268  * - owned by a single AF_RXRPC socket
0269  * - pointed to by transport socket struct sk_user_data
0270  */
0271 struct rxrpc_local {
0272     struct rcu_head     rcu;
0273     atomic_t        active_users;   /* Number of users of the local endpoint */
0274     refcount_t      ref;        /* Number of references to the structure */
0275     struct rxrpc_net    *rxnet;     /* The network ns in which this resides */
0276     struct hlist_node   link;
0277     struct socket       *socket;    /* my UDP socket */
0278     struct work_struct  processor;
0279     struct rxrpc_sock __rcu *service;   /* Service(s) listening on this endpoint */
0280     struct rw_semaphore defrag_sem; /* control re-enablement of IP DF bit */
0281     struct sk_buff_head reject_queue;   /* packets awaiting rejection */
0282     struct sk_buff_head event_queue;    /* endpoint event packets awaiting processing */
0283     struct rb_root      client_bundles; /* Client connection bundles by socket params */
0284     spinlock_t      client_bundles_lock; /* Lock for client_bundles */
0285     spinlock_t      lock;       /* access lock */
0286     rwlock_t        services_lock;  /* lock for services list */
0287     int         debug_id;   /* debug ID for printks */
0288     bool            dead;
0289     bool            service_closed; /* Service socket closed */
0290     struct sockaddr_rxrpc   srx;        /* local address */
0291 };
0292 
0293 /*
0294  * RxRPC remote transport endpoint definition
0295  * - matched by local endpoint, remote port, address and protocol type
0296  */
0297 struct rxrpc_peer {
0298     struct rcu_head     rcu;        /* This must be first */
0299     refcount_t      ref;
0300     unsigned long       hash_key;
0301     struct hlist_node   hash_link;
0302     struct rxrpc_local  *local;
0303     struct hlist_head   error_targets;  /* targets for net error distribution */
0304     struct rb_root      service_conns;  /* Service connections */
0305     struct list_head    keepalive_link; /* Link in net->peer_keepalive[] */
0306     time64_t        last_tx_at; /* Last time packet sent here */
0307     seqlock_t       service_conn_lock;
0308     spinlock_t      lock;       /* access lock */
0309     unsigned int        if_mtu;     /* interface MTU for this peer */
0310     unsigned int        mtu;        /* network MTU for this peer */
0311     unsigned int        maxdata;    /* data size (MTU - hdrsize) */
0312     unsigned short      hdrsize;    /* header size (IP + UDP + RxRPC) */
0313     int         debug_id;   /* debug ID for printks */
0314     struct sockaddr_rxrpc   srx;        /* remote address */
0315 
0316     /* calculated RTT cache */
0317 #define RXRPC_RTT_CACHE_SIZE 32
0318     spinlock_t      rtt_input_lock; /* RTT lock for input routine */
0319     ktime_t         rtt_last_req;   /* Time of last RTT request */
0320     unsigned int        rtt_count;  /* Number of samples we've got */
0321 
0322     u32         srtt_us;    /* smoothed round trip time << 3 in usecs */
0323     u32         mdev_us;    /* medium deviation         */
0324     u32         mdev_max_us;    /* maximal mdev for the last rtt period */
0325     u32         rttvar_us;  /* smoothed mdev_max            */
0326     u32         rto_j;      /* Retransmission timeout in jiffies */
0327     u8          backoff;    /* Backoff timeout */
0328 
0329     u8          cong_cwnd;  /* Congestion window size */
0330 };
0331 
0332 /*
0333  * Keys for matching a connection.
0334  */
0335 struct rxrpc_conn_proto {
0336     union {
0337         struct {
0338             u32 epoch;      /* epoch of this connection */
0339             u32 cid;        /* connection ID */
0340         };
0341         u64     index_key;
0342     };
0343 };
0344 
0345 struct rxrpc_conn_parameters {
0346     struct rxrpc_local  *local;     /* Representation of local endpoint */
0347     struct rxrpc_peer   *peer;      /* Remote endpoint */
0348     struct key      *key;       /* Security details */
0349     bool            exclusive;  /* T if conn is exclusive */
0350     bool            upgrade;    /* T if service ID can be upgraded */
0351     u16         service_id; /* Service ID for this connection */
0352     u32         security_level; /* Security level selected */
0353 };
0354 
0355 /*
0356  * Bits in the connection flags.
0357  */
0358 enum rxrpc_conn_flag {
0359     RXRPC_CONN_HAS_IDR,     /* Has a client conn ID assigned */
0360     RXRPC_CONN_IN_SERVICE_CONNS,    /* Conn is in peer->service_conns */
0361     RXRPC_CONN_DONT_REUSE,      /* Don't reuse this connection */
0362     RXRPC_CONN_PROBING_FOR_UPGRADE, /* Probing for service upgrade */
0363     RXRPC_CONN_FINAL_ACK_0,     /* Need final ACK for channel 0 */
0364     RXRPC_CONN_FINAL_ACK_1,     /* Need final ACK for channel 1 */
0365     RXRPC_CONN_FINAL_ACK_2,     /* Need final ACK for channel 2 */
0366     RXRPC_CONN_FINAL_ACK_3,     /* Need final ACK for channel 3 */
0367 };
0368 
0369 #define RXRPC_CONN_FINAL_ACK_MASK ((1UL << RXRPC_CONN_FINAL_ACK_0) |    \
0370                    (1UL << RXRPC_CONN_FINAL_ACK_1) |    \
0371                    (1UL << RXRPC_CONN_FINAL_ACK_2) |    \
0372                    (1UL << RXRPC_CONN_FINAL_ACK_3))
0373 
0374 /*
0375  * Events that can be raised upon a connection.
0376  */
0377 enum rxrpc_conn_event {
0378     RXRPC_CONN_EV_CHALLENGE,    /* Send challenge packet */
0379 };
0380 
0381 /*
0382  * The connection protocol state.
0383  */
0384 enum rxrpc_conn_proto_state {
0385     RXRPC_CONN_UNUSED,      /* Connection not yet attempted */
0386     RXRPC_CONN_CLIENT,      /* Client connection */
0387     RXRPC_CONN_SERVICE_PREALLOC,    /* Service connection preallocation */
0388     RXRPC_CONN_SERVICE_UNSECURED,   /* Service unsecured connection */
0389     RXRPC_CONN_SERVICE_CHALLENGING, /* Service challenging for security */
0390     RXRPC_CONN_SERVICE,     /* Service secured connection */
0391     RXRPC_CONN_REMOTELY_ABORTED,    /* Conn aborted by peer */
0392     RXRPC_CONN_LOCALLY_ABORTED, /* Conn aborted locally */
0393     RXRPC_CONN__NR_STATES
0394 };
0395 
0396 /*
0397  * RxRPC client connection bundle.
0398  */
0399 struct rxrpc_bundle {
0400     struct rxrpc_conn_parameters params;
0401     refcount_t      ref;
0402     unsigned int        debug_id;
0403     bool            try_upgrade;    /* True if the bundle is attempting upgrade */
0404     bool            alloc_conn; /* True if someone's getting a conn */
0405     short           alloc_error;    /* Error from last conn allocation */
0406     spinlock_t      channel_lock;
0407     struct rb_node      local_node; /* Node in local->client_conns */
0408     struct list_head    waiting_calls;  /* Calls waiting for channels */
0409     unsigned long       avail_chans;    /* Mask of available channels */
0410     struct rxrpc_connection *conns[4];  /* The connections in the bundle (max 4) */
0411 };
0412 
0413 /*
0414  * RxRPC connection definition
0415  * - matched by { local, peer, epoch, conn_id, direction }
0416  * - each connection can only handle four simultaneous calls
0417  */
0418 struct rxrpc_connection {
0419     struct rxrpc_conn_proto proto;
0420     struct rxrpc_conn_parameters params;
0421 
0422     refcount_t      ref;
0423     struct rcu_head     rcu;
0424     struct list_head    cache_link;
0425 
0426     unsigned char       act_chans;  /* Mask of active channels */
0427     struct rxrpc_channel {
0428         unsigned long       final_ack_at;   /* Time at which to issue final ACK */
0429         struct rxrpc_call __rcu *call;      /* Active call */
0430         unsigned int        call_debug_id;  /* call->debug_id */
0431         u32         call_id;    /* ID of current call */
0432         u32         call_counter;   /* Call ID counter */
0433         u32         last_call;  /* ID of last call */
0434         u8          last_type;  /* Type of last packet */
0435         union {
0436             u32     last_seq;
0437             u32     last_abort;
0438         };
0439     } channels[RXRPC_MAXCALLS];
0440 
0441     struct timer_list   timer;      /* Conn event timer */
0442     struct work_struct  processor;  /* connection event processor */
0443     struct rxrpc_bundle *bundle;    /* Client connection bundle */
0444     struct rb_node      service_node;   /* Node in peer->service_conns */
0445     struct list_head    proc_link;  /* link in procfs list */
0446     struct list_head    link;       /* link in master connection list */
0447     struct sk_buff_head rx_queue;   /* received conn-level packets */
0448 
0449     const struct rxrpc_security *security;  /* applied security module */
0450     union {
0451         struct {
0452             struct crypto_sync_skcipher *cipher;    /* encryption handle */
0453             struct rxrpc_crypt csum_iv; /* packet checksum base */
0454             u32 nonce;      /* response re-use preventer */
0455         } rxkad;
0456     };
0457     unsigned long       flags;
0458     unsigned long       events;
0459     unsigned long       idle_timestamp; /* Time at which last became idle */
0460     spinlock_t      state_lock; /* state-change lock */
0461     enum rxrpc_conn_proto_state state;  /* current state of connection */
0462     u32         abort_code; /* Abort code of connection abort */
0463     int         debug_id;   /* debug ID for printks */
0464     atomic_t        serial;     /* packet serial number counter */
0465     unsigned int        hi_serial;  /* highest serial number received */
0466     u32         service_id; /* Service ID, possibly upgraded */
0467     u8          security_ix;    /* security type */
0468     u8          out_clientflag; /* RXRPC_CLIENT_INITIATED if we are client */
0469     u8          bundle_shift;   /* Index into bundle->avail_chans */
0470     short           error;      /* Local error code */
0471 };
0472 
0473 static inline bool rxrpc_to_server(const struct rxrpc_skb_priv *sp)
0474 {
0475     return sp->hdr.flags & RXRPC_CLIENT_INITIATED;
0476 }
0477 
0478 static inline bool rxrpc_to_client(const struct rxrpc_skb_priv *sp)
0479 {
0480     return !rxrpc_to_server(sp);
0481 }
0482 
0483 /*
0484  * Flags in call->flags.
0485  */
0486 enum rxrpc_call_flag {
0487     RXRPC_CALL_RELEASED,        /* call has been released - no more message to userspace */
0488     RXRPC_CALL_HAS_USERID,      /* has a user ID attached */
0489     RXRPC_CALL_IS_SERVICE,      /* Call is service call */
0490     RXRPC_CALL_EXPOSED,     /* The call was exposed to the world */
0491     RXRPC_CALL_RX_LAST,     /* Received the last packet (at rxtx_top) */
0492     RXRPC_CALL_TX_LAST,     /* Last packet in Tx buffer (at rxtx_top) */
0493     RXRPC_CALL_SEND_PING,       /* A ping will need to be sent */
0494     RXRPC_CALL_RETRANS_TIMEOUT, /* Retransmission due to timeout occurred */
0495     RXRPC_CALL_BEGAN_RX_TIMER,  /* We began the expect_rx_by timer */
0496     RXRPC_CALL_RX_HEARD,        /* The peer responded at least once to this call */
0497     RXRPC_CALL_RX_UNDERRUN,     /* Got data underrun */
0498     RXRPC_CALL_DISCONNECTED,    /* The call has been disconnected */
0499     RXRPC_CALL_KERNEL,      /* The call was made by the kernel */
0500     RXRPC_CALL_UPGRADE,     /* Service upgrade was requested for the call */
0501 };
0502 
0503 /*
0504  * Events that can be raised on a call.
0505  */
0506 enum rxrpc_call_event {
0507     RXRPC_CALL_EV_ACK,      /* need to generate ACK */
0508     RXRPC_CALL_EV_ABORT,        /* need to generate abort */
0509     RXRPC_CALL_EV_RESEND,       /* Tx resend required */
0510     RXRPC_CALL_EV_PING,     /* Ping send required */
0511     RXRPC_CALL_EV_EXPIRED,      /* Expiry occurred */
0512     RXRPC_CALL_EV_ACK_LOST,     /* ACK may be lost, send ping */
0513 };
0514 
0515 /*
0516  * The states that a call can be in.
0517  */
0518 enum rxrpc_call_state {
0519     RXRPC_CALL_UNINITIALISED,
0520     RXRPC_CALL_CLIENT_AWAIT_CONN,   /* - client waiting for connection to become available */
0521     RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
0522     RXRPC_CALL_CLIENT_AWAIT_REPLY,  /* - client awaiting reply */
0523     RXRPC_CALL_CLIENT_RECV_REPLY,   /* - client receiving reply phase */
0524     RXRPC_CALL_SERVER_PREALLOC, /* - service preallocation */
0525     RXRPC_CALL_SERVER_SECURING, /* - server securing request connection */
0526     RXRPC_CALL_SERVER_RECV_REQUEST, /* - server receiving request */
0527     RXRPC_CALL_SERVER_ACK_REQUEST,  /* - server pending ACK of request */
0528     RXRPC_CALL_SERVER_SEND_REPLY,   /* - server sending reply */
0529     RXRPC_CALL_SERVER_AWAIT_ACK,    /* - server awaiting final ACK */
0530     RXRPC_CALL_COMPLETE,        /* - call complete */
0531     NR__RXRPC_CALL_STATES
0532 };
0533 
0534 /*
0535  * Call completion condition (state == RXRPC_CALL_COMPLETE).
0536  */
0537 enum rxrpc_call_completion {
0538     RXRPC_CALL_SUCCEEDED,       /* - Normal termination */
0539     RXRPC_CALL_REMOTELY_ABORTED,    /* - call aborted by peer */
0540     RXRPC_CALL_LOCALLY_ABORTED, /* - call aborted locally on error or close */
0541     RXRPC_CALL_LOCAL_ERROR,     /* - call failed due to local error */
0542     RXRPC_CALL_NETWORK_ERROR,   /* - call terminated by network error */
0543     NR__RXRPC_CALL_COMPLETIONS
0544 };
0545 
0546 /*
0547  * Call Tx congestion management modes.
0548  */
0549 enum rxrpc_congest_mode {
0550     RXRPC_CALL_SLOW_START,
0551     RXRPC_CALL_CONGEST_AVOIDANCE,
0552     RXRPC_CALL_PACKET_LOSS,
0553     RXRPC_CALL_FAST_RETRANSMIT,
0554     NR__RXRPC_CONGEST_MODES
0555 };
0556 
0557 /*
0558  * RxRPC call definition
0559  * - matched by { connection, call_id }
0560  */
0561 struct rxrpc_call {
0562     struct rcu_head     rcu;
0563     struct rxrpc_connection *conn;      /* connection carrying call */
0564     struct rxrpc_peer   *peer;      /* Peer record for remote address */
0565     struct rxrpc_sock __rcu *socket;    /* socket responsible */
0566     struct rxrpc_net    *rxnet;     /* Network namespace to which call belongs */
0567     const struct rxrpc_security *security;  /* applied security module */
0568     struct mutex        user_mutex; /* User access mutex */
0569     unsigned long       ack_at;     /* When deferred ACK needs to happen */
0570     unsigned long       ack_lost_at;    /* When ACK is figured as lost */
0571     unsigned long       resend_at;  /* When next resend needs to happen */
0572     unsigned long       ping_at;    /* When next to send a ping */
0573     unsigned long       keepalive_at;   /* When next to send a keepalive ping */
0574     unsigned long       expect_rx_by;   /* When we expect to get a packet by */
0575     unsigned long       expect_req_by;  /* When we expect to get a request DATA packet by */
0576     unsigned long       expect_term_by; /* When we expect call termination by */
0577     u32         next_rx_timo;   /* Timeout for next Rx packet (jif) */
0578     u32         next_req_timo;  /* Timeout for next Rx request packet (jif) */
0579     struct skcipher_request *cipher_req;    /* Packet cipher request buffer */
0580     struct timer_list   timer;      /* Combined event timer */
0581     struct work_struct  processor;  /* Event processor */
0582     rxrpc_notify_rx_t   notify_rx;  /* kernel service Rx notification function */
0583     struct list_head    link;       /* link in master call list */
0584     struct list_head    chan_wait_link; /* Link in conn->bundle->waiting_calls */
0585     struct hlist_node   error_link; /* link in error distribution list */
0586     struct list_head    accept_link;    /* Link in rx->acceptq */
0587     struct list_head    recvmsg_link;   /* Link in rx->recvmsg_q */
0588     struct list_head    sock_link;  /* Link in rx->sock_calls */
0589     struct rb_node      sock_node;  /* Node in rx->calls */
0590     struct sk_buff      *tx_pending;    /* Tx socket buffer being filled */
0591     wait_queue_head_t   waitq;      /* Wait queue for channel or Tx */
0592     s64         tx_total_len;   /* Total length left to be transmitted (or -1) */
0593     __be32          crypto_buf[2];  /* Temporary packet crypto buffer */
0594     unsigned long       user_call_ID;   /* user-defined call ID */
0595     unsigned long       flags;
0596     unsigned long       events;
0597     spinlock_t      lock;
0598     spinlock_t      notify_lock;    /* Kernel notification lock */
0599     rwlock_t        state_lock; /* lock for state transition */
0600     u32         abort_code; /* Local/remote abort code */
0601     int         error;      /* Local error incurred */
0602     enum rxrpc_call_state   state;      /* current state of call */
0603     enum rxrpc_call_completion completion;  /* Call completion condition */
0604     refcount_t      ref;
0605     u16         service_id; /* service ID */
0606     u8          security_ix;    /* Security type */
0607     enum rxrpc_interruptibility interruptibility; /* At what point call may be interrupted */
0608     u32         call_id;    /* call ID on connection  */
0609     u32         cid;        /* connection ID plus channel index */
0610     int         debug_id;   /* debug ID for printks */
0611     unsigned short      rx_pkt_offset;  /* Current recvmsg packet offset */
0612     unsigned short      rx_pkt_len; /* Current recvmsg packet len */
0613     bool            rx_pkt_last;    /* Current recvmsg packet is last */
0614 
0615     /* Rx/Tx circular buffer, depending on phase.
0616      *
0617      * In the Rx phase, packets are annotated with 0 or the number of the
0618      * segment of a jumbo packet each buffer refers to.  There can be up to
0619      * 47 segments in a maximum-size UDP packet.
0620      *
0621      * In the Tx phase, packets are annotated with which buffers have been
0622      * acked.
0623      */
0624 #define RXRPC_RXTX_BUFF_SIZE    64
0625 #define RXRPC_RXTX_BUFF_MASK    (RXRPC_RXTX_BUFF_SIZE - 1)
0626 #define RXRPC_INIT_RX_WINDOW_SIZE 63
0627     struct sk_buff      **rxtx_buffer;
0628     u8          *rxtx_annotations;
0629 #define RXRPC_TX_ANNO_ACK   0
0630 #define RXRPC_TX_ANNO_UNACK 1
0631 #define RXRPC_TX_ANNO_NAK   2
0632 #define RXRPC_TX_ANNO_RETRANS   3
0633 #define RXRPC_TX_ANNO_MASK  0x03
0634 #define RXRPC_TX_ANNO_LAST  0x04
0635 #define RXRPC_TX_ANNO_RESENT    0x08
0636 
0637 #define RXRPC_RX_ANNO_SUBPACKET 0x3f        /* Subpacket number in jumbogram */
0638 #define RXRPC_RX_ANNO_VERIFIED  0x80        /* Set if verified and decrypted */
0639     rxrpc_seq_t     tx_hard_ack;    /* Dead slot in buffer; the first transmitted but
0640                          * not hard-ACK'd packet follows this.
0641                          */
0642     rxrpc_seq_t     tx_top;     /* Highest Tx slot allocated. */
0643     u16         tx_backoff; /* Delay to insert due to Tx failure */
0644 
0645     /* TCP-style slow-start congestion control [RFC5681].  Since the SMSS
0646      * is fixed, we keep these numbers in terms of segments (ie. DATA
0647      * packets) rather than bytes.
0648      */
0649 #define RXRPC_TX_SMSS       RXRPC_JUMBO_DATALEN
0650     u8          cong_cwnd;  /* Congestion window size */
0651     u8          cong_extra; /* Extra to send for congestion management */
0652     u8          cong_ssthresh;  /* Slow-start threshold */
0653     enum rxrpc_congest_mode cong_mode:8;    /* Congestion management mode */
0654     u8          cong_dup_acks;  /* Count of ACKs showing missing packets */
0655     u8          cong_cumul_acks; /* Cumulative ACK count */
0656     ktime_t         cong_tstamp;    /* Last time cwnd was changed */
0657 
0658     rxrpc_seq_t     rx_hard_ack;    /* Dead slot in buffer; the first received but not
0659                          * consumed packet follows this.
0660                          */
0661     rxrpc_seq_t     rx_top;     /* Highest Rx slot allocated. */
0662     rxrpc_seq_t     rx_expect_next; /* Expected next packet sequence number */
0663     rxrpc_serial_t      rx_serial;  /* Highest serial received for this call */
0664     u8          rx_winsize; /* Size of Rx window */
0665     u8          tx_winsize; /* Maximum size of Tx window */
0666     bool            tx_phase;   /* T if transmission phase, F if receive phase */
0667     u8          nr_jumbo_bad;   /* Number of jumbo dups/exceeds-windows */
0668 
0669     spinlock_t      input_lock; /* Lock for packet input to this call */
0670 
0671     /* Receive-phase ACK management (ACKs we send). */
0672     u8          ackr_reason;    /* reason to ACK */
0673     rxrpc_serial_t      ackr_serial;    /* serial of packet being ACK'd */
0674     rxrpc_seq_t     ackr_highest_seq; /* Higest sequence number received */
0675     atomic_t        ackr_nr_unacked; /* Number of unacked packets */
0676     atomic_t        ackr_nr_consumed; /* Number of packets needing hard ACK */
0677 
0678     /* RTT management */
0679     rxrpc_serial_t      rtt_serial[4];  /* Serial number of DATA or PING sent */
0680     ktime_t         rtt_sent_at[4]; /* Time packet sent */
0681     unsigned long       rtt_avail;  /* Mask of available slots in bits 0-3,
0682                          * Mask of pending samples in 8-11 */
0683 #define RXRPC_CALL_RTT_AVAIL_MASK   0xf
0684 #define RXRPC_CALL_RTT_PEND_SHIFT   8
0685 
0686     /* Transmission-phase ACK management (ACKs we've received). */
0687     ktime_t         acks_latest_ts; /* Timestamp of latest ACK received */
0688     rxrpc_seq_t     acks_first_seq; /* first sequence number received */
0689     rxrpc_seq_t     acks_prev_seq;  /* Highest previousPacket received */
0690     rxrpc_seq_t     acks_lowest_nak; /* Lowest NACK in the buffer (or ==tx_hard_ack) */
0691     rxrpc_seq_t     acks_lost_top;  /* tx_top at the time lost-ack ping sent */
0692     rxrpc_serial_t      acks_lost_ping; /* Serial number of probe ACK */
0693 };
0694 
0695 /*
0696  * Summary of a new ACK and the changes it made to the Tx buffer packet states.
0697  */
0698 struct rxrpc_ack_summary {
0699     u8          ack_reason;
0700     u8          nr_acks;        /* Number of ACKs in packet */
0701     u8          nr_nacks;       /* Number of NACKs in packet */
0702     u8          nr_new_acks;        /* Number of new ACKs in packet */
0703     u8          nr_new_nacks;       /* Number of new NACKs in packet */
0704     u8          nr_rot_new_acks;    /* Number of rotated new ACKs */
0705     bool            new_low_nack;       /* T if new low NACK found */
0706     bool            retrans_timeo;      /* T if reTx due to timeout happened */
0707     u8          flight_size;        /* Number of unreceived transmissions */
0708     /* Place to stash values for tracing */
0709     enum rxrpc_congest_mode mode:8;
0710     u8          cwnd;
0711     u8          ssthresh;
0712     u8          dup_acks;
0713     u8          cumulative_acks;
0714 };
0715 
0716 /*
0717  * sendmsg() cmsg-specified parameters.
0718  */
0719 enum rxrpc_command {
0720     RXRPC_CMD_SEND_DATA,        /* send data message */
0721     RXRPC_CMD_SEND_ABORT,       /* request abort generation */
0722     RXRPC_CMD_REJECT_BUSY,      /* [server] reject a call as busy */
0723     RXRPC_CMD_CHARGE_ACCEPT,    /* [server] charge accept preallocation */
0724 };
0725 
0726 struct rxrpc_call_params {
0727     s64         tx_total_len;   /* Total Tx data length (if send data) */
0728     unsigned long       user_call_ID;   /* User's call ID */
0729     struct {
0730         u32     hard;       /* Maximum lifetime (sec) */
0731         u32     idle;       /* Max time since last data packet (msec) */
0732         u32     normal;     /* Max time since last call packet (msec) */
0733     } timeouts;
0734     u8          nr_timeouts;    /* Number of timeouts specified */
0735     bool            kernel;     /* T if kernel is making the call */
0736     enum rxrpc_interruptibility interruptibility; /* How is interruptible is the call? */
0737 };
0738 
0739 struct rxrpc_send_params {
0740     struct rxrpc_call_params call;
0741     u32         abort_code; /* Abort code to Tx (if abort) */
0742     enum rxrpc_command  command : 8;    /* The command to implement */
0743     bool            exclusive;  /* Shared or exclusive call */
0744     bool            upgrade;    /* If the connection is upgradeable */
0745 };
0746 
0747 #include <trace/events/rxrpc.h>
0748 
0749 /*
0750  * af_rxrpc.c
0751  */
0752 extern atomic_t rxrpc_n_tx_skbs, rxrpc_n_rx_skbs;
0753 extern struct workqueue_struct *rxrpc_workqueue;
0754 
0755 /*
0756  * call_accept.c
0757  */
0758 int rxrpc_service_prealloc(struct rxrpc_sock *, gfp_t);
0759 void rxrpc_discard_prealloc(struct rxrpc_sock *);
0760 struct rxrpc_call *rxrpc_new_incoming_call(struct rxrpc_local *,
0761                        struct rxrpc_sock *,
0762                        struct sk_buff *);
0763 void rxrpc_accept_incoming_calls(struct rxrpc_local *);
0764 int rxrpc_user_charge_accept(struct rxrpc_sock *, unsigned long);
0765 
0766 /*
0767  * call_event.c
0768  */
0769 void rxrpc_propose_ACK(struct rxrpc_call *, u8, u32, bool, bool,
0770                enum rxrpc_propose_ack_trace);
0771 void rxrpc_process_call(struct work_struct *);
0772 
0773 void rxrpc_reduce_call_timer(struct rxrpc_call *call,
0774                  unsigned long expire_at,
0775                  unsigned long now,
0776                  enum rxrpc_timer_trace why);
0777 
0778 void rxrpc_delete_call_timer(struct rxrpc_call *call);
0779 
0780 /*
0781  * call_object.c
0782  */
0783 extern const char *const rxrpc_call_states[];
0784 extern const char *const rxrpc_call_completions[];
0785 extern unsigned int rxrpc_max_call_lifetime;
0786 extern struct kmem_cache *rxrpc_call_jar;
0787 
0788 struct rxrpc_call *rxrpc_find_call_by_user_ID(struct rxrpc_sock *, unsigned long);
0789 struct rxrpc_call *rxrpc_alloc_call(struct rxrpc_sock *, gfp_t, unsigned int);
0790 struct rxrpc_call *rxrpc_new_client_call(struct rxrpc_sock *,
0791                      struct rxrpc_conn_parameters *,
0792                      struct sockaddr_rxrpc *,
0793                      struct rxrpc_call_params *, gfp_t,
0794                      unsigned int);
0795 void rxrpc_incoming_call(struct rxrpc_sock *, struct rxrpc_call *,
0796              struct sk_buff *);
0797 void rxrpc_release_call(struct rxrpc_sock *, struct rxrpc_call *);
0798 void rxrpc_release_calls_on_socket(struct rxrpc_sock *);
0799 bool __rxrpc_queue_call(struct rxrpc_call *);
0800 bool rxrpc_queue_call(struct rxrpc_call *);
0801 void rxrpc_see_call(struct rxrpc_call *);
0802 bool rxrpc_try_get_call(struct rxrpc_call *call, enum rxrpc_call_trace op);
0803 void rxrpc_get_call(struct rxrpc_call *, enum rxrpc_call_trace);
0804 void rxrpc_put_call(struct rxrpc_call *, enum rxrpc_call_trace);
0805 void rxrpc_cleanup_call(struct rxrpc_call *);
0806 void rxrpc_destroy_all_calls(struct rxrpc_net *);
0807 
0808 static inline bool rxrpc_is_service_call(const struct rxrpc_call *call)
0809 {
0810     return test_bit(RXRPC_CALL_IS_SERVICE, &call->flags);
0811 }
0812 
0813 static inline bool rxrpc_is_client_call(const struct rxrpc_call *call)
0814 {
0815     return !rxrpc_is_service_call(call);
0816 }
0817 
0818 /*
0819  * conn_client.c
0820  */
0821 extern unsigned int rxrpc_reap_client_connections;
0822 extern unsigned long rxrpc_conn_idle_client_expiry;
0823 extern unsigned long rxrpc_conn_idle_client_fast_expiry;
0824 extern struct idr rxrpc_client_conn_ids;
0825 
0826 void rxrpc_destroy_client_conn_ids(void);
0827 struct rxrpc_bundle *rxrpc_get_bundle(struct rxrpc_bundle *);
0828 void rxrpc_put_bundle(struct rxrpc_bundle *);
0829 int rxrpc_connect_call(struct rxrpc_sock *, struct rxrpc_call *,
0830                struct rxrpc_conn_parameters *, struct sockaddr_rxrpc *,
0831                gfp_t);
0832 void rxrpc_expose_client_call(struct rxrpc_call *);
0833 void rxrpc_disconnect_client_call(struct rxrpc_bundle *, struct rxrpc_call *);
0834 void rxrpc_put_client_conn(struct rxrpc_connection *);
0835 void rxrpc_discard_expired_client_conns(struct work_struct *);
0836 void rxrpc_destroy_all_client_connections(struct rxrpc_net *);
0837 void rxrpc_clean_up_local_conns(struct rxrpc_local *);
0838 
0839 /*
0840  * conn_event.c
0841  */
0842 void rxrpc_process_connection(struct work_struct *);
0843 void rxrpc_process_delayed_final_acks(struct rxrpc_connection *, bool);
0844 
0845 /*
0846  * conn_object.c
0847  */
0848 extern unsigned int rxrpc_connection_expiry;
0849 extern unsigned int rxrpc_closed_conn_expiry;
0850 
0851 struct rxrpc_connection *rxrpc_alloc_connection(gfp_t);
0852 struct rxrpc_connection *rxrpc_find_connection_rcu(struct rxrpc_local *,
0853                            struct sk_buff *,
0854                            struct rxrpc_peer **);
0855 void __rxrpc_disconnect_call(struct rxrpc_connection *, struct rxrpc_call *);
0856 void rxrpc_disconnect_call(struct rxrpc_call *);
0857 void rxrpc_kill_connection(struct rxrpc_connection *);
0858 bool rxrpc_queue_conn(struct rxrpc_connection *);
0859 void rxrpc_see_connection(struct rxrpc_connection *);
0860 struct rxrpc_connection *rxrpc_get_connection(struct rxrpc_connection *);
0861 struct rxrpc_connection *rxrpc_get_connection_maybe(struct rxrpc_connection *);
0862 void rxrpc_put_service_conn(struct rxrpc_connection *);
0863 void rxrpc_service_connection_reaper(struct work_struct *);
0864 void rxrpc_destroy_all_connections(struct rxrpc_net *);
0865 
0866 static inline bool rxrpc_conn_is_client(const struct rxrpc_connection *conn)
0867 {
0868     return conn->out_clientflag;
0869 }
0870 
0871 static inline bool rxrpc_conn_is_service(const struct rxrpc_connection *conn)
0872 {
0873     return !rxrpc_conn_is_client(conn);
0874 }
0875 
0876 static inline void rxrpc_put_connection(struct rxrpc_connection *conn)
0877 {
0878     if (!conn)
0879         return;
0880 
0881     if (rxrpc_conn_is_client(conn))
0882         rxrpc_put_client_conn(conn);
0883     else
0884         rxrpc_put_service_conn(conn);
0885 }
0886 
0887 static inline void rxrpc_reduce_conn_timer(struct rxrpc_connection *conn,
0888                        unsigned long expire_at)
0889 {
0890     timer_reduce(&conn->timer, expire_at);
0891 }
0892 
0893 /*
0894  * conn_service.c
0895  */
0896 struct rxrpc_connection *rxrpc_find_service_conn_rcu(struct rxrpc_peer *,
0897                              struct sk_buff *);
0898 struct rxrpc_connection *rxrpc_prealloc_service_connection(struct rxrpc_net *, gfp_t);
0899 void rxrpc_new_incoming_connection(struct rxrpc_sock *, struct rxrpc_connection *,
0900                    const struct rxrpc_security *, struct sk_buff *);
0901 void rxrpc_unpublish_service_conn(struct rxrpc_connection *);
0902 
0903 /*
0904  * input.c
0905  */
0906 int rxrpc_input_packet(struct sock *, struct sk_buff *);
0907 
0908 /*
0909  * insecure.c
0910  */
0911 extern const struct rxrpc_security rxrpc_no_security;
0912 
0913 /*
0914  * key.c
0915  */
0916 extern struct key_type key_type_rxrpc;
0917 
0918 int rxrpc_request_key(struct rxrpc_sock *, sockptr_t , int);
0919 int rxrpc_get_server_data_key(struct rxrpc_connection *, const void *, time64_t,
0920                   u32);
0921 
0922 /*
0923  * local_event.c
0924  */
0925 extern void rxrpc_process_local_events(struct rxrpc_local *);
0926 
0927 /*
0928  * local_object.c
0929  */
0930 struct rxrpc_local *rxrpc_lookup_local(struct net *, const struct sockaddr_rxrpc *);
0931 struct rxrpc_local *rxrpc_get_local(struct rxrpc_local *);
0932 struct rxrpc_local *rxrpc_get_local_maybe(struct rxrpc_local *);
0933 void rxrpc_put_local(struct rxrpc_local *);
0934 struct rxrpc_local *rxrpc_use_local(struct rxrpc_local *);
0935 void rxrpc_unuse_local(struct rxrpc_local *);
0936 void rxrpc_queue_local(struct rxrpc_local *);
0937 void rxrpc_destroy_all_locals(struct rxrpc_net *);
0938 
0939 static inline bool __rxrpc_unuse_local(struct rxrpc_local *local)
0940 {
0941     return atomic_dec_return(&local->active_users) == 0;
0942 }
0943 
0944 static inline bool __rxrpc_use_local(struct rxrpc_local *local)
0945 {
0946     return atomic_fetch_add_unless(&local->active_users, 1, 0) != 0;
0947 }
0948 
0949 /*
0950  * misc.c
0951  */
0952 extern unsigned int rxrpc_max_backlog __read_mostly;
0953 extern unsigned long rxrpc_requested_ack_delay;
0954 extern unsigned long rxrpc_soft_ack_delay;
0955 extern unsigned long rxrpc_idle_ack_delay;
0956 extern unsigned int rxrpc_rx_window_size;
0957 extern unsigned int rxrpc_rx_mtu;
0958 extern unsigned int rxrpc_rx_jumbo_max;
0959 
0960 extern const s8 rxrpc_ack_priority[];
0961 
0962 /*
0963  * net_ns.c
0964  */
0965 extern unsigned int rxrpc_net_id;
0966 extern struct pernet_operations rxrpc_net_ops;
0967 
0968 static inline struct rxrpc_net *rxrpc_net(struct net *net)
0969 {
0970     return net_generic(net, rxrpc_net_id);
0971 }
0972 
0973 /*
0974  * output.c
0975  */
0976 int rxrpc_send_ack_packet(struct rxrpc_call *, bool, rxrpc_serial_t *);
0977 int rxrpc_send_abort_packet(struct rxrpc_call *);
0978 int rxrpc_send_data_packet(struct rxrpc_call *, struct sk_buff *, bool);
0979 void rxrpc_reject_packets(struct rxrpc_local *);
0980 void rxrpc_send_keepalive(struct rxrpc_peer *);
0981 
0982 /*
0983  * peer_event.c
0984  */
0985 void rxrpc_encap_err_rcv(struct sock *sk, struct sk_buff *skb, unsigned int udp_offset);
0986 void rxrpc_error_report(struct sock *);
0987 void rxrpc_peer_keepalive_worker(struct work_struct *);
0988 
0989 /*
0990  * peer_object.c
0991  */
0992 struct rxrpc_peer *rxrpc_lookup_peer_rcu(struct rxrpc_local *,
0993                      const struct sockaddr_rxrpc *);
0994 struct rxrpc_peer *rxrpc_lookup_peer(struct rxrpc_sock *, struct rxrpc_local *,
0995                      struct sockaddr_rxrpc *, gfp_t);
0996 struct rxrpc_peer *rxrpc_alloc_peer(struct rxrpc_local *, gfp_t);
0997 void rxrpc_new_incoming_peer(struct rxrpc_sock *, struct rxrpc_local *,
0998                  struct rxrpc_peer *);
0999 void rxrpc_destroy_all_peers(struct rxrpc_net *);
1000 struct rxrpc_peer *rxrpc_get_peer(struct rxrpc_peer *);
1001 struct rxrpc_peer *rxrpc_get_peer_maybe(struct rxrpc_peer *);
1002 void rxrpc_put_peer(struct rxrpc_peer *);
1003 void rxrpc_put_peer_locked(struct rxrpc_peer *);
1004 
1005 /*
1006  * proc.c
1007  */
1008 extern const struct seq_operations rxrpc_call_seq_ops;
1009 extern const struct seq_operations rxrpc_connection_seq_ops;
1010 extern const struct seq_operations rxrpc_peer_seq_ops;
1011 extern const struct seq_operations rxrpc_local_seq_ops;
1012 
1013 /*
1014  * recvmsg.c
1015  */
1016 void rxrpc_notify_socket(struct rxrpc_call *);
1017 bool __rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
1018 bool rxrpc_set_call_completion(struct rxrpc_call *, enum rxrpc_call_completion, u32, int);
1019 bool __rxrpc_call_completed(struct rxrpc_call *);
1020 bool rxrpc_call_completed(struct rxrpc_call *);
1021 bool __rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
1022 bool rxrpc_abort_call(const char *, struct rxrpc_call *, rxrpc_seq_t, u32, int);
1023 int rxrpc_recvmsg(struct socket *, struct msghdr *, size_t, int);
1024 
1025 /*
1026  * Abort a call due to a protocol error.
1027  */
1028 static inline bool __rxrpc_abort_eproto(struct rxrpc_call *call,
1029                     struct sk_buff *skb,
1030                     const char *eproto_why,
1031                     const char *why,
1032                     u32 abort_code)
1033 {
1034     struct rxrpc_skb_priv *sp = rxrpc_skb(skb);
1035 
1036     trace_rxrpc_rx_eproto(call, sp->hdr.serial, eproto_why);
1037     return rxrpc_abort_call(why, call, sp->hdr.seq, abort_code, -EPROTO);
1038 }
1039 
1040 #define rxrpc_abort_eproto(call, skb, eproto_why, abort_why, abort_code) \
1041     __rxrpc_abort_eproto((call), (skb), tracepoint_string(eproto_why), \
1042                  (abort_why), (abort_code))
1043 
1044 /*
1045  * rtt.c
1046  */
1047 void rxrpc_peer_add_rtt(struct rxrpc_call *, enum rxrpc_rtt_rx_trace, int,
1048             rxrpc_serial_t, rxrpc_serial_t, ktime_t, ktime_t);
1049 unsigned long rxrpc_get_rto_backoff(struct rxrpc_peer *, bool);
1050 void rxrpc_peer_init_rtt(struct rxrpc_peer *);
1051 
1052 /*
1053  * rxkad.c
1054  */
1055 #ifdef CONFIG_RXKAD
1056 extern const struct rxrpc_security rxkad;
1057 #endif
1058 
1059 /*
1060  * security.c
1061  */
1062 int __init rxrpc_init_security(void);
1063 const struct rxrpc_security *rxrpc_security_lookup(u8);
1064 void rxrpc_exit_security(void);
1065 int rxrpc_init_client_conn_security(struct rxrpc_connection *);
1066 const struct rxrpc_security *rxrpc_get_incoming_security(struct rxrpc_sock *,
1067                              struct sk_buff *);
1068 struct key *rxrpc_look_up_server_security(struct rxrpc_connection *,
1069                       struct sk_buff *, u32, u32);
1070 
1071 /*
1072  * sendmsg.c
1073  */
1074 int rxrpc_do_sendmsg(struct rxrpc_sock *, struct msghdr *, size_t);
1075 
1076 /*
1077  * server_key.c
1078  */
1079 extern struct key_type key_type_rxrpc_s;
1080 
1081 int rxrpc_server_keyring(struct rxrpc_sock *, sockptr_t, int);
1082 
1083 /*
1084  * skbuff.c
1085  */
1086 void rxrpc_kernel_data_consumed(struct rxrpc_call *, struct sk_buff *);
1087 void rxrpc_packet_destructor(struct sk_buff *);
1088 void rxrpc_new_skb(struct sk_buff *, enum rxrpc_skb_trace);
1089 void rxrpc_see_skb(struct sk_buff *, enum rxrpc_skb_trace);
1090 void rxrpc_eaten_skb(struct sk_buff *, enum rxrpc_skb_trace);
1091 void rxrpc_get_skb(struct sk_buff *, enum rxrpc_skb_trace);
1092 void rxrpc_free_skb(struct sk_buff *, enum rxrpc_skb_trace);
1093 void rxrpc_purge_queue(struct sk_buff_head *);
1094 
1095 /*
1096  * sysctl.c
1097  */
1098 #ifdef CONFIG_SYSCTL
1099 extern int __init rxrpc_sysctl_init(void);
1100 extern void rxrpc_sysctl_exit(void);
1101 #else
1102 static inline int __init rxrpc_sysctl_init(void) { return 0; }
1103 static inline void rxrpc_sysctl_exit(void) {}
1104 #endif
1105 
1106 /*
1107  * utils.c
1108  */
1109 int rxrpc_extract_addr_from_skb(struct sockaddr_rxrpc *, struct sk_buff *);
1110 
1111 static inline bool before(u32 seq1, u32 seq2)
1112 {
1113         return (s32)(seq1 - seq2) < 0;
1114 }
1115 static inline bool before_eq(u32 seq1, u32 seq2)
1116 {
1117         return (s32)(seq1 - seq2) <= 0;
1118 }
1119 static inline bool after(u32 seq1, u32 seq2)
1120 {
1121         return (s32)(seq1 - seq2) > 0;
1122 }
1123 static inline bool after_eq(u32 seq1, u32 seq2)
1124 {
1125         return (s32)(seq1 - seq2) >= 0;
1126 }
1127 
1128 /*
1129  * debug tracing
1130  */
1131 extern unsigned int rxrpc_debug;
1132 
1133 #define dbgprintk(FMT,...) \
1134     printk("[%-6.6s] "FMT"\n", current->comm ,##__VA_ARGS__)
1135 
1136 #define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1137 #define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1138 #define kdebug(FMT,...) dbgprintk("    "FMT ,##__VA_ARGS__)
1139 #define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
1140 #define knet(FMT,...)   dbgprintk("@@@ "FMT ,##__VA_ARGS__)
1141 
1142 
1143 #if defined(__KDEBUG)
1144 #define _enter(FMT,...) kenter(FMT,##__VA_ARGS__)
1145 #define _leave(FMT,...) kleave(FMT,##__VA_ARGS__)
1146 #define _debug(FMT,...) kdebug(FMT,##__VA_ARGS__)
1147 #define _proto(FMT,...) kproto(FMT,##__VA_ARGS__)
1148 #define _net(FMT,...)   knet(FMT,##__VA_ARGS__)
1149 
1150 #elif defined(CONFIG_AF_RXRPC_DEBUG)
1151 #define RXRPC_DEBUG_KENTER  0x01
1152 #define RXRPC_DEBUG_KLEAVE  0x02
1153 #define RXRPC_DEBUG_KDEBUG  0x04
1154 #define RXRPC_DEBUG_KPROTO  0x08
1155 #define RXRPC_DEBUG_KNET    0x10
1156 
1157 #define _enter(FMT,...)                 \
1158 do {                            \
1159     if (unlikely(rxrpc_debug & RXRPC_DEBUG_KENTER)) \
1160         kenter(FMT,##__VA_ARGS__);      \
1161 } while (0)
1162 
1163 #define _leave(FMT,...)                 \
1164 do {                            \
1165     if (unlikely(rxrpc_debug & RXRPC_DEBUG_KLEAVE)) \
1166         kleave(FMT,##__VA_ARGS__);      \
1167 } while (0)
1168 
1169 #define _debug(FMT,...)                 \
1170 do {                            \
1171     if (unlikely(rxrpc_debug & RXRPC_DEBUG_KDEBUG)) \
1172         kdebug(FMT,##__VA_ARGS__);      \
1173 } while (0)
1174 
1175 #define _proto(FMT,...)                 \
1176 do {                            \
1177     if (unlikely(rxrpc_debug & RXRPC_DEBUG_KPROTO)) \
1178         kproto(FMT,##__VA_ARGS__);      \
1179 } while (0)
1180 
1181 #define _net(FMT,...)                   \
1182 do {                            \
1183     if (unlikely(rxrpc_debug & RXRPC_DEBUG_KNET))   \
1184         knet(FMT,##__VA_ARGS__);        \
1185 } while (0)
1186 
1187 #else
1188 #define _enter(FMT,...) no_printk("==> %s("FMT")",__func__ ,##__VA_ARGS__)
1189 #define _leave(FMT,...) no_printk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
1190 #define _debug(FMT,...) no_printk("    "FMT ,##__VA_ARGS__)
1191 #define _proto(FMT,...) no_printk("### "FMT ,##__VA_ARGS__)
1192 #define _net(FMT,...)   no_printk("@@@ "FMT ,##__VA_ARGS__)
1193 #endif
1194 
1195 /*
1196  * debug assertion checking
1197  */
1198 #if 1 // defined(__KDEBUGALL)
1199 
1200 #define ASSERT(X)                       \
1201 do {                                \
1202     if (unlikely(!(X))) {                   \
1203         pr_err("Assertion failed\n");           \
1204         BUG();                      \
1205     }                           \
1206 } while (0)
1207 
1208 #define ASSERTCMP(X, OP, Y)                     \
1209 do {                                    \
1210     __typeof__(X) _x = (X);                     \
1211     __typeof__(Y) _y = (__typeof__(X))(Y);              \
1212     if (unlikely(!(_x OP _y))) {                    \
1213         pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1214                (unsigned long)_x, (unsigned long)_x, #OP,   \
1215                (unsigned long)_y, (unsigned long)_y);       \
1216         BUG();                          \
1217     }                               \
1218 } while (0)
1219 
1220 #define ASSERTIF(C, X)                      \
1221 do {                                \
1222     if (unlikely((C) && !(X))) {                \
1223         pr_err("Assertion failed\n");           \
1224         BUG();                      \
1225     }                           \
1226 } while (0)
1227 
1228 #define ASSERTIFCMP(C, X, OP, Y)                    \
1229 do {                                    \
1230     __typeof__(X) _x = (X);                     \
1231     __typeof__(Y) _y = (__typeof__(X))(Y);              \
1232     if (unlikely((C) && !(_x OP _y))) {             \
1233         pr_err("Assertion failed - %lu(0x%lx) %s %lu(0x%lx) is false\n", \
1234                (unsigned long)_x, (unsigned long)_x, #OP,   \
1235                (unsigned long)_y, (unsigned long)_y);       \
1236         BUG();                          \
1237     }                               \
1238 } while (0)
1239 
1240 #else
1241 
1242 #define ASSERT(X)               \
1243 do {                        \
1244 } while (0)
1245 
1246 #define ASSERTCMP(X, OP, Y)         \
1247 do {                        \
1248 } while (0)
1249 
1250 #define ASSERTIF(C, X)              \
1251 do {                        \
1252 } while (0)
1253 
1254 #define ASSERTIFCMP(C, X, OP, Y)        \
1255 do {                        \
1256 } while (0)
1257 
1258 #endif /* __KDEBUGALL */