blob: 7ea557b7c6b15aa15bf326622ce3ba400f389fa5 [file] [log] [blame]
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -07001#ifndef _ACKVEC_H
2#define _ACKVEC_H
3/*
4 * net/dccp/ackvec.h
5 *
6 * An implementation of the DCCP protocol
7 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 */
13
Gerrit Renkerb20a9c22008-11-23 16:02:31 -080014#include <linux/dccp.h>
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070015#include <linux/compiler.h>
Arnaldo Carvalho de Melob8bda9d2007-08-19 17:17:25 -070016#include <linux/ktime.h>
Andrea Bittau02bcf282006-03-20 17:19:55 -080017#include <linux/list.h>
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070018#include <linux/types.h>
19
Andrea Bittaubdf13d22006-11-24 13:02:42 -020020/* We can spread an ack vector across multiple options */
Gerrit Renkerb20a9c22008-11-23 16:02:31 -080021#define DCCP_MAX_ACKVEC_LEN (DCCP_SINGLE_OPT_MAXLEN * 2)
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070022
Gerrit Renker361a5c12009-02-27 22:38:28 +000023/* Estimated minimum average Ack Vector length - used for updating MPS */
24#define DCCPAV_MIN_OPTLEN 16
25
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070026#define DCCP_ACKVEC_STATE_RECEIVED 0
27#define DCCP_ACKVEC_STATE_ECN_MARKED (1 << 6)
28#define DCCP_ACKVEC_STATE_NOT_RECEIVED (3 << 6)
29
30#define DCCP_ACKVEC_STATE_MASK 0xC0 /* 11000000 */
31#define DCCP_ACKVEC_LEN_MASK 0x3F /* 00111111 */
32
33/** struct dccp_ackvec - ack vector
34 *
Gerrit Renker0e64e942006-10-24 16:17:51 -070035 * This data structure is the one defined in RFC 4340, Appendix A.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070036 *
Gerrit Renkera47c5102007-12-30 04:19:31 -080037 * @av_buf_head - circular buffer head
38 * @av_buf_tail - circular buffer tail
39 * @av_buf_ackno - ack # of the most recent packet acknowledgeable in the
40 * buffer (i.e. %av_buf_head)
41 * @av_buf_nonce - the one-bit sum of the ECN Nonces on all packets acked
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070042 * by the buffer with State 0
43 *
44 * Additionally, the HC-Receiver must keep some information about the
45 * Ack Vectors it has recently sent. For each packet sent carrying an
46 * Ack Vector, it remembers four variables:
47 *
Gerrit Renkera47c5102007-12-30 04:19:31 -080048 * @av_records - list of dccp_ackvec_record
49 * @av_ack_nonce - the one-bit sum of the ECN Nonces for all State 0.
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070050 *
Gerrit Renkera47c5102007-12-30 04:19:31 -080051 * @av_time - the time in usecs
52 * @av_buf - circular buffer of acknowledgeable packets
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070053 */
54struct dccp_ackvec {
Gerrit Renkera47c5102007-12-30 04:19:31 -080055 u64 av_buf_ackno;
56 struct list_head av_records;
57 ktime_t av_time;
58 u16 av_buf_head;
59 u16 av_vec_len;
60 u8 av_buf_nonce;
61 u8 av_ack_nonce;
62 u8 av_buf[DCCP_MAX_ACKVEC_LEN];
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070063};
64
Andrea Bittau02bcf282006-03-20 17:19:55 -080065/** struct dccp_ackvec_record - ack vector record
66 *
67 * ACK vector record as defined in Appendix A of spec.
68 *
Gerrit Renkera47c5102007-12-30 04:19:31 -080069 * The list is sorted by avr_ack_seqno
Andrea Bittau02bcf282006-03-20 17:19:55 -080070 *
Gerrit Renkera47c5102007-12-30 04:19:31 -080071 * @avr_node - node in av_records
72 * @avr_ack_seqno - sequence number of the packet this record was sent on
73 * @avr_ack_ackno - sequence number being acknowledged
74 * @avr_ack_ptr - pointer into av_buf where this record starts
75 * @avr_ack_nonce - av_ack_nonce at the time this record was sent
76 * @avr_sent_len - lenght of the record in av_buf
Andrea Bittau02bcf282006-03-20 17:19:55 -080077 */
78struct dccp_ackvec_record {
Gerrit Renkera47c5102007-12-30 04:19:31 -080079 struct list_head avr_node;
80 u64 avr_ack_seqno;
81 u64 avr_ack_ackno;
82 u16 avr_ack_ptr;
83 u16 avr_sent_len;
84 u8 avr_ack_nonce;
Andrea Bittau02bcf282006-03-20 17:19:55 -080085};
86
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070087struct sock;
88struct sk_buff;
89
Arnaldo Carvalho de Melo9b07ef52006-03-20 17:16:17 -080090extern int dccp_ackvec_init(void);
91extern void dccp_ackvec_exit(void);
92
Arnaldo Carvalho de Melo7400d782006-03-20 17:15:42 -080093extern struct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -070094extern void dccp_ackvec_free(struct dccp_ackvec *av);
95
96extern int dccp_ackvec_add(struct dccp_ackvec *av, const struct sock *sk,
97 const u64 ackno, const u8 state);
98
99extern void dccp_ackvec_check_rcv_ackno(struct dccp_ackvec *av,
100 struct sock *sk, const u64 ackno);
101extern int dccp_ackvec_parse(struct sock *sk, const struct sk_buff *skb,
Andrea Bittaubdf13d22006-11-24 13:02:42 -0200102 u64 *ackno, const u8 opt,
103 const u8 *value, const u8 len);
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700104
105extern int dccp_insert_option_ackvec(struct sock *sk, struct sk_buff *skb);
106
107static inline int dccp_ackvec_pending(const struct dccp_ackvec *av)
108{
Gerrit Renkera47c5102007-12-30 04:19:31 -0800109 return av->av_vec_len;
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700110}
Arnaldo Carvalho de Meloae31c332005-09-18 00:17:51 -0700111#endif /* _ACKVEC_H */