Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_DCCP_H
0003 #define _LINUX_DCCP_H
0004 
0005 
0006 #include <linux/in.h>
0007 #include <linux/interrupt.h>
0008 #include <linux/ktime.h>
0009 #include <linux/list.h>
0010 #include <linux/uio.h>
0011 #include <linux/workqueue.h>
0012 
0013 #include <net/inet_connection_sock.h>
0014 #include <net/inet_sock.h>
0015 #include <net/inet_timewait_sock.h>
0016 #include <net/tcp_states.h>
0017 #include <uapi/linux/dccp.h>
0018 
0019 enum dccp_state {
0020     DCCP_OPEN        = TCP_ESTABLISHED,
0021     DCCP_REQUESTING      = TCP_SYN_SENT,
0022     DCCP_LISTEN      = TCP_LISTEN,
0023     DCCP_RESPOND         = TCP_SYN_RECV,
0024     /*
0025      * States involved in closing a DCCP connection:
0026      * 1) ACTIVE_CLOSEREQ is entered by a server sending a CloseReq.
0027      *
0028      * 2) CLOSING can have three different meanings (RFC 4340, 8.3):
0029      *  a. Client has performed active-close, has sent a Close to the server
0030      *     from state OPEN or PARTOPEN, and is waiting for the final Reset
0031      *     (in this case, SOCK_DONE == 1).
0032      *  b. Client is asked to perform passive-close, by receiving a CloseReq
0033      *     in (PART)OPEN state. It sends a Close and waits for final Reset
0034      *     (in this case, SOCK_DONE == 0).
0035      *  c. Server performs an active-close as in (a), keeps TIMEWAIT state.
0036      *
0037      * 3) The following intermediate states are employed to give passively
0038      *    closing nodes a chance to process their unread data:
0039      *    - PASSIVE_CLOSE    (from OPEN => CLOSED) and
0040      *    - PASSIVE_CLOSEREQ (from (PART)OPEN to CLOSING; case (b) above).
0041      */
0042     DCCP_ACTIVE_CLOSEREQ = TCP_FIN_WAIT1,
0043     DCCP_PASSIVE_CLOSE   = TCP_CLOSE_WAIT,  /* any node receiving a Close */
0044     DCCP_CLOSING         = TCP_CLOSING,
0045     DCCP_TIME_WAIT       = TCP_TIME_WAIT,
0046     DCCP_CLOSED      = TCP_CLOSE,
0047     DCCP_NEW_SYN_RECV    = TCP_NEW_SYN_RECV,
0048     DCCP_PARTOPEN        = TCP_MAX_STATES,
0049     DCCP_PASSIVE_CLOSEREQ,          /* clients receiving CloseReq */
0050     DCCP_MAX_STATES
0051 };
0052 
0053 enum {
0054     DCCPF_OPEN        = TCPF_ESTABLISHED,
0055     DCCPF_REQUESTING      = TCPF_SYN_SENT,
0056     DCCPF_LISTEN          = TCPF_LISTEN,
0057     DCCPF_RESPOND         = TCPF_SYN_RECV,
0058     DCCPF_ACTIVE_CLOSEREQ = TCPF_FIN_WAIT1,
0059     DCCPF_CLOSING         = TCPF_CLOSING,
0060     DCCPF_TIME_WAIT       = TCPF_TIME_WAIT,
0061     DCCPF_CLOSED          = TCPF_CLOSE,
0062     DCCPF_NEW_SYN_RECV    = TCPF_NEW_SYN_RECV,
0063     DCCPF_PARTOPEN        = (1 << DCCP_PARTOPEN),
0064 };
0065 
0066 static inline struct dccp_hdr *dccp_hdr(const struct sk_buff *skb)
0067 {
0068     return (struct dccp_hdr *)skb_transport_header(skb);
0069 }
0070 
0071 static inline struct dccp_hdr *dccp_zeroed_hdr(struct sk_buff *skb, int headlen)
0072 {
0073     skb_push(skb, headlen);
0074     skb_reset_transport_header(skb);
0075     return memset(skb_transport_header(skb), 0, headlen);
0076 }
0077 
0078 static inline struct dccp_hdr_ext *dccp_hdrx(const struct dccp_hdr *dh)
0079 {
0080     return (struct dccp_hdr_ext *)((unsigned char *)dh + sizeof(*dh));
0081 }
0082 
0083 static inline unsigned int __dccp_basic_hdr_len(const struct dccp_hdr *dh)
0084 {
0085     return sizeof(*dh) + (dh->dccph_x ? sizeof(struct dccp_hdr_ext) : 0);
0086 }
0087 
0088 static inline unsigned int dccp_basic_hdr_len(const struct sk_buff *skb)
0089 {
0090     const struct dccp_hdr *dh = dccp_hdr(skb);
0091     return __dccp_basic_hdr_len(dh);
0092 }
0093 
0094 static inline __u64 dccp_hdr_seq(const struct dccp_hdr *dh)
0095 {
0096     __u64 seq_nr =  ntohs(dh->dccph_seq);
0097 
0098     if (dh->dccph_x != 0)
0099         seq_nr = (seq_nr << 32) + ntohl(dccp_hdrx(dh)->dccph_seq_low);
0100     else
0101         seq_nr += (u32)dh->dccph_seq2 << 16;
0102 
0103     return seq_nr;
0104 }
0105 
0106 static inline struct dccp_hdr_request *dccp_hdr_request(struct sk_buff *skb)
0107 {
0108     return (struct dccp_hdr_request *)(skb_transport_header(skb) +
0109                        dccp_basic_hdr_len(skb));
0110 }
0111 
0112 static inline struct dccp_hdr_ack_bits *dccp_hdr_ack_bits(const struct sk_buff *skb)
0113 {
0114     return (struct dccp_hdr_ack_bits *)(skb_transport_header(skb) +
0115                         dccp_basic_hdr_len(skb));
0116 }
0117 
0118 static inline u64 dccp_hdr_ack_seq(const struct sk_buff *skb)
0119 {
0120     const struct dccp_hdr_ack_bits *dhack = dccp_hdr_ack_bits(skb);
0121     return ((u64)ntohs(dhack->dccph_ack_nr_high) << 32) + ntohl(dhack->dccph_ack_nr_low);
0122 }
0123 
0124 static inline struct dccp_hdr_response *dccp_hdr_response(struct sk_buff *skb)
0125 {
0126     return (struct dccp_hdr_response *)(skb_transport_header(skb) +
0127                         dccp_basic_hdr_len(skb));
0128 }
0129 
0130 static inline struct dccp_hdr_reset *dccp_hdr_reset(struct sk_buff *skb)
0131 {
0132     return (struct dccp_hdr_reset *)(skb_transport_header(skb) +
0133                      dccp_basic_hdr_len(skb));
0134 }
0135 
0136 static inline unsigned int __dccp_hdr_len(const struct dccp_hdr *dh)
0137 {
0138     return __dccp_basic_hdr_len(dh) +
0139            dccp_packet_hdr_len(dh->dccph_type);
0140 }
0141 
0142 static inline unsigned int dccp_hdr_len(const struct sk_buff *skb)
0143 {
0144     return __dccp_hdr_len(dccp_hdr(skb));
0145 }
0146 
0147 /**
0148  * struct dccp_request_sock  -  represent DCCP-specific connection request
0149  * @dreq_inet_rsk: structure inherited from
0150  * @dreq_iss: initial sequence number, sent on the first Response (RFC 4340, 7.1)
0151  * @dreq_gss: greatest sequence number sent (for retransmitted Responses)
0152  * @dreq_isr: initial sequence number received in the first Request
0153  * @dreq_gsr: greatest sequence number received (for retransmitted Request(s))
0154  * @dreq_service: service code present on the Request (there is just one)
0155  * @dreq_featneg: feature negotiation options for this connection
0156  * The following two fields are analogous to the ones in dccp_sock:
0157  * @dreq_timestamp_echo: last received timestamp to echo (13.1)
0158  * @dreq_timestamp_echo: the time of receiving the last @dreq_timestamp_echo
0159  */
0160 struct dccp_request_sock {
0161     struct inet_request_sock dreq_inet_rsk;
0162     __u64            dreq_iss;
0163     __u64            dreq_gss;
0164     __u64            dreq_isr;
0165     __u64            dreq_gsr;
0166     __be32           dreq_service;
0167     spinlock_t       dreq_lock;
0168     struct list_head     dreq_featneg;
0169     __u32            dreq_timestamp_echo;
0170     __u32            dreq_timestamp_time;
0171 };
0172 
0173 static inline struct dccp_request_sock *dccp_rsk(const struct request_sock *req)
0174 {
0175     return (struct dccp_request_sock *)req;
0176 }
0177 
0178 extern struct inet_timewait_death_row dccp_death_row;
0179 
0180 extern int dccp_parse_options(struct sock *sk, struct dccp_request_sock *dreq,
0181                   struct sk_buff *skb);
0182 
0183 struct dccp_options_received {
0184     u64 dccpor_ndp:48;
0185     u32 dccpor_timestamp;
0186     u32 dccpor_timestamp_echo;
0187     u32 dccpor_elapsed_time;
0188 };
0189 
0190 struct ccid;
0191 
0192 enum dccp_role {
0193     DCCP_ROLE_UNDEFINED,
0194     DCCP_ROLE_LISTEN,
0195     DCCP_ROLE_CLIENT,
0196     DCCP_ROLE_SERVER,
0197 };
0198 
0199 struct dccp_service_list {
0200     __u32   dccpsl_nr;
0201     __be32  dccpsl_list[];
0202 };
0203 
0204 #define DCCP_SERVICE_INVALID_VALUE htonl((__u32)-1)
0205 #define DCCP_SERVICE_CODE_IS_ABSENT     0
0206 
0207 static inline bool dccp_list_has_service(const struct dccp_service_list *sl,
0208                     const __be32 service)
0209 {
0210     if (likely(sl != NULL)) {
0211         u32 i = sl->dccpsl_nr;
0212         while (i--)
0213             if (sl->dccpsl_list[i] == service)
0214                 return true;
0215     }
0216     return false;
0217 }
0218 
0219 struct dccp_ackvec;
0220 
0221 /**
0222  * struct dccp_sock - DCCP socket state
0223  *
0224  * @dccps_swl - sequence number window low
0225  * @dccps_swh - sequence number window high
0226  * @dccps_awl - acknowledgement number window low
0227  * @dccps_awh - acknowledgement number window high
0228  * @dccps_iss - initial sequence number sent
0229  * @dccps_isr - initial sequence number received
0230  * @dccps_osr - first OPEN sequence number received
0231  * @dccps_gss - greatest sequence number sent
0232  * @dccps_gsr - greatest valid sequence number received
0233  * @dccps_gar - greatest valid ack number received on a non-Sync; initialized to %dccps_iss
0234  * @dccps_service - first (passive sock) or unique (active sock) service code
0235  * @dccps_service_list - second .. last service code on passive socket
0236  * @dccps_timestamp_echo - latest timestamp received on a TIMESTAMP option
0237  * @dccps_timestamp_time - time of receiving latest @dccps_timestamp_echo
0238  * @dccps_l_ack_ratio - feature-local Ack Ratio
0239  * @dccps_r_ack_ratio - feature-remote Ack Ratio
0240  * @dccps_l_seq_win - local Sequence Window (influences ack number validity)
0241  * @dccps_r_seq_win - remote Sequence Window (influences seq number validity)
0242  * @dccps_pcslen - sender   partial checksum coverage (via sockopt)
0243  * @dccps_pcrlen - receiver partial checksum coverage (via sockopt)
0244  * @dccps_send_ndp_count - local Send NDP Count feature (7.7.2)
0245  * @dccps_ndp_count - number of Non Data Packets since last data packet
0246  * @dccps_mss_cache - current value of MSS (path MTU minus header sizes)
0247  * @dccps_rate_last - timestamp for rate-limiting DCCP-Sync (RFC 4340, 7.5.4)
0248  * @dccps_featneg - tracks feature-negotiation state (mostly during handshake)
0249  * @dccps_hc_rx_ackvec - rx half connection ack vector
0250  * @dccps_hc_rx_ccid - CCID used for the receiver (or receiving half-connection)
0251  * @dccps_hc_tx_ccid - CCID used for the sender (or sending half-connection)
0252  * @dccps_options_received - parsed set of retrieved options
0253  * @dccps_qpolicy - TX dequeueing policy, one of %dccp_packet_dequeueing_policy
0254  * @dccps_tx_qlen - maximum length of the TX queue
0255  * @dccps_role - role of this sock, one of %dccp_role
0256  * @dccps_hc_rx_insert_options - receiver wants to add options when acking
0257  * @dccps_hc_tx_insert_options - sender wants to add options when sending
0258  * @dccps_server_timewait - server holds timewait state on close (RFC 4340, 8.3)
0259  * @dccps_sync_scheduled - flag which signals "send out-of-band message soon"
0260  * @dccps_xmitlet - tasklet scheduled by the TX CCID to dequeue data packets
0261  * @dccps_xmit_timer - used by the TX CCID to delay sending (rate-based pacing)
0262  * @dccps_syn_rtt - RTT sample from Request/Response exchange (in usecs)
0263  */
0264 struct dccp_sock {
0265     /* inet_connection_sock has to be the first member of dccp_sock */
0266     struct inet_connection_sock dccps_inet_connection;
0267 #define dccps_syn_rtt           dccps_inet_connection.icsk_ack.lrcvtime
0268     __u64               dccps_swl;
0269     __u64               dccps_swh;
0270     __u64               dccps_awl;
0271     __u64               dccps_awh;
0272     __u64               dccps_iss;
0273     __u64               dccps_isr;
0274     __u64               dccps_osr;
0275     __u64               dccps_gss;
0276     __u64               dccps_gsr;
0277     __u64               dccps_gar;
0278     __be32              dccps_service;
0279     __u32               dccps_mss_cache;
0280     struct dccp_service_list    *dccps_service_list;
0281     __u32               dccps_timestamp_echo;
0282     __u32               dccps_timestamp_time;
0283     __u16               dccps_l_ack_ratio;
0284     __u16               dccps_r_ack_ratio;
0285     __u64               dccps_l_seq_win:48;
0286     __u64               dccps_r_seq_win:48;
0287     __u8                dccps_pcslen:4;
0288     __u8                dccps_pcrlen:4;
0289     __u8                dccps_send_ndp_count:1;
0290     __u64               dccps_ndp_count:48;
0291     unsigned long           dccps_rate_last;
0292     struct list_head        dccps_featneg;
0293     struct dccp_ackvec      *dccps_hc_rx_ackvec;
0294     struct ccid         *dccps_hc_rx_ccid;
0295     struct ccid         *dccps_hc_tx_ccid;
0296     struct dccp_options_received    dccps_options_received;
0297     __u8                dccps_qpolicy;
0298     __u32               dccps_tx_qlen;
0299     enum dccp_role          dccps_role:2;
0300     __u8                dccps_hc_rx_insert_options:1;
0301     __u8                dccps_hc_tx_insert_options:1;
0302     __u8                dccps_server_timewait:1;
0303     __u8                dccps_sync_scheduled:1;
0304     struct tasklet_struct       dccps_xmitlet;
0305     struct timer_list       dccps_xmit_timer;
0306 };
0307 
0308 static inline struct dccp_sock *dccp_sk(const struct sock *sk)
0309 {
0310     return (struct dccp_sock *)sk;
0311 }
0312 
0313 static inline const char *dccp_role(const struct sock *sk)
0314 {
0315     switch (dccp_sk(sk)->dccps_role) {
0316     case DCCP_ROLE_UNDEFINED: return "undefined";
0317     case DCCP_ROLE_LISTEN:    return "listen";
0318     case DCCP_ROLE_SERVER:    return "server";
0319     case DCCP_ROLE_CLIENT:    return "client";
0320     }
0321     return NULL;
0322 }
0323 
0324 extern void dccp_syn_ack_timeout(const struct request_sock *req);
0325 
0326 #endif /* _LINUX_DCCP_H */