0001
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
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042 DCCP_ACTIVE_CLOSEREQ = TCP_FIN_WAIT1,
0043 DCCP_PASSIVE_CLOSE = TCP_CLOSE_WAIT,
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,
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
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
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
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264 struct dccp_sock {
0265
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