18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci#ifndef _ACKVEC_H 38c2ecf20Sopenharmony_ci#define _ACKVEC_H 48c2ecf20Sopenharmony_ci/* 58c2ecf20Sopenharmony_ci * net/dccp/ackvec.h 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * An implementation of Ack Vectors for the DCCP protocol 88c2ecf20Sopenharmony_ci * Copyright (c) 2007 University of Aberdeen, Scotland, UK 98c2ecf20Sopenharmony_ci * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@mandriva.com> 108c2ecf20Sopenharmony_ci */ 118c2ecf20Sopenharmony_ci 128c2ecf20Sopenharmony_ci#include <linux/dccp.h> 138c2ecf20Sopenharmony_ci#include <linux/compiler.h> 148c2ecf20Sopenharmony_ci#include <linux/list.h> 158c2ecf20Sopenharmony_ci#include <linux/types.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* 188c2ecf20Sopenharmony_ci * Ack Vector buffer space is static, in multiples of %DCCP_SINGLE_OPT_MAXLEN, 198c2ecf20Sopenharmony_ci * the maximum size of a single Ack Vector. Setting %DCCPAV_NUM_ACKVECS to 1 208c2ecf20Sopenharmony_ci * will be sufficient for most cases of low Ack Ratios, using a value of 2 gives 218c2ecf20Sopenharmony_ci * more headroom if Ack Ratio is higher or when the sender acknowledges slowly. 228c2ecf20Sopenharmony_ci * The maximum value is bounded by the u16 types for indices and functions. 238c2ecf20Sopenharmony_ci */ 248c2ecf20Sopenharmony_ci#define DCCPAV_NUM_ACKVECS 2 258c2ecf20Sopenharmony_ci#define DCCPAV_MAX_ACKVEC_LEN (DCCP_SINGLE_OPT_MAXLEN * DCCPAV_NUM_ACKVECS) 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_ci/* Estimated minimum average Ack Vector length - used for updating MPS */ 288c2ecf20Sopenharmony_ci#define DCCPAV_MIN_OPTLEN 16 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_ci/* Threshold for coping with large bursts of losses */ 318c2ecf20Sopenharmony_ci#define DCCPAV_BURST_THRESH (DCCPAV_MAX_ACKVEC_LEN / 8) 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cienum dccp_ackvec_states { 348c2ecf20Sopenharmony_ci DCCPAV_RECEIVED = 0x00, 358c2ecf20Sopenharmony_ci DCCPAV_ECN_MARKED = 0x40, 368c2ecf20Sopenharmony_ci DCCPAV_RESERVED = 0x80, 378c2ecf20Sopenharmony_ci DCCPAV_NOT_RECEIVED = 0xC0 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci#define DCCPAV_MAX_RUNLEN 0x3F 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_cistatic inline u8 dccp_ackvec_runlen(const u8 *cell) 428c2ecf20Sopenharmony_ci{ 438c2ecf20Sopenharmony_ci return *cell & DCCPAV_MAX_RUNLEN; 448c2ecf20Sopenharmony_ci} 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_cistatic inline u8 dccp_ackvec_state(const u8 *cell) 478c2ecf20Sopenharmony_ci{ 488c2ecf20Sopenharmony_ci return *cell & ~DCCPAV_MAX_RUNLEN; 498c2ecf20Sopenharmony_ci} 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci/** 528c2ecf20Sopenharmony_ci * struct dccp_ackvec - Ack Vector main data structure 538c2ecf20Sopenharmony_ci * 548c2ecf20Sopenharmony_ci * This implements a fixed-size circular buffer within an array and is largely 558c2ecf20Sopenharmony_ci * based on Appendix A of RFC 4340. 568c2ecf20Sopenharmony_ci * 578c2ecf20Sopenharmony_ci * @av_buf: circular buffer storage area 588c2ecf20Sopenharmony_ci * @av_buf_head: head index; begin of live portion in @av_buf 598c2ecf20Sopenharmony_ci * @av_buf_tail: tail index; first index _after_ the live portion in @av_buf 608c2ecf20Sopenharmony_ci * @av_buf_ackno: highest seqno of acknowledgeable packet recorded in @av_buf 618c2ecf20Sopenharmony_ci * @av_tail_ackno: lowest seqno of acknowledgeable packet recorded in @av_buf 628c2ecf20Sopenharmony_ci * @av_buf_nonce: ECN nonce sums, each covering subsequent segments of up to 638c2ecf20Sopenharmony_ci * %DCCP_SINGLE_OPT_MAXLEN cells in the live portion of @av_buf 648c2ecf20Sopenharmony_ci * @av_overflow: if 1 then buf_head == buf_tail indicates buffer wraparound 658c2ecf20Sopenharmony_ci * @av_records: list of %dccp_ackvec_record (Ack Vectors sent previously) 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_cistruct dccp_ackvec { 688c2ecf20Sopenharmony_ci u8 av_buf[DCCPAV_MAX_ACKVEC_LEN]; 698c2ecf20Sopenharmony_ci u16 av_buf_head; 708c2ecf20Sopenharmony_ci u16 av_buf_tail; 718c2ecf20Sopenharmony_ci u64 av_buf_ackno:48; 728c2ecf20Sopenharmony_ci u64 av_tail_ackno:48; 738c2ecf20Sopenharmony_ci bool av_buf_nonce[DCCPAV_NUM_ACKVECS]; 748c2ecf20Sopenharmony_ci u8 av_overflow:1; 758c2ecf20Sopenharmony_ci struct list_head av_records; 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/** 798c2ecf20Sopenharmony_ci * struct dccp_ackvec_record - Records information about sent Ack Vectors 808c2ecf20Sopenharmony_ci * 818c2ecf20Sopenharmony_ci * These list entries define the additional information which the HC-Receiver 828c2ecf20Sopenharmony_ci * keeps about recently-sent Ack Vectors; again refer to RFC 4340, Appendix A. 838c2ecf20Sopenharmony_ci * 848c2ecf20Sopenharmony_ci * @avr_node: the list node in @av_records 858c2ecf20Sopenharmony_ci * @avr_ack_seqno: sequence number of the packet the Ack Vector was sent on 868c2ecf20Sopenharmony_ci * @avr_ack_ackno: the Ack number that this record/Ack Vector refers to 878c2ecf20Sopenharmony_ci * @avr_ack_ptr: pointer into @av_buf where this record starts 888c2ecf20Sopenharmony_ci * @avr_ack_runlen: run length of @avr_ack_ptr at the time of sending 898c2ecf20Sopenharmony_ci * @avr_ack_nonce: the sum of @av_buf_nonce's at the time this record was sent 908c2ecf20Sopenharmony_ci * 918c2ecf20Sopenharmony_ci * The list as a whole is sorted in descending order by @avr_ack_seqno. 928c2ecf20Sopenharmony_ci */ 938c2ecf20Sopenharmony_cistruct dccp_ackvec_record { 948c2ecf20Sopenharmony_ci struct list_head avr_node; 958c2ecf20Sopenharmony_ci u64 avr_ack_seqno:48; 968c2ecf20Sopenharmony_ci u64 avr_ack_ackno:48; 978c2ecf20Sopenharmony_ci u16 avr_ack_ptr; 988c2ecf20Sopenharmony_ci u8 avr_ack_runlen; 998c2ecf20Sopenharmony_ci u8 avr_ack_nonce:1; 1008c2ecf20Sopenharmony_ci}; 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ciint dccp_ackvec_init(void); 1038c2ecf20Sopenharmony_civoid dccp_ackvec_exit(void); 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_cistruct dccp_ackvec *dccp_ackvec_alloc(const gfp_t priority); 1068c2ecf20Sopenharmony_civoid dccp_ackvec_free(struct dccp_ackvec *av); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_civoid dccp_ackvec_input(struct dccp_ackvec *av, struct sk_buff *skb); 1098c2ecf20Sopenharmony_ciint dccp_ackvec_update_records(struct dccp_ackvec *av, u64 seq, u8 sum); 1108c2ecf20Sopenharmony_civoid dccp_ackvec_clear_state(struct dccp_ackvec *av, const u64 ackno); 1118c2ecf20Sopenharmony_ciu16 dccp_ackvec_buflen(const struct dccp_ackvec *av); 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic inline bool dccp_ackvec_is_empty(const struct dccp_ackvec *av) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci return av->av_overflow == 0 && av->av_buf_head == av->av_buf_tail; 1168c2ecf20Sopenharmony_ci} 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci/** 1198c2ecf20Sopenharmony_ci * struct dccp_ackvec_parsed - Record offsets of Ack Vectors in skb 1208c2ecf20Sopenharmony_ci * @vec: start of vector (offset into skb) 1218c2ecf20Sopenharmony_ci * @len: length of @vec 1228c2ecf20Sopenharmony_ci * @nonce: whether @vec had an ECN nonce of 0 or 1 1238c2ecf20Sopenharmony_ci * @node: FIFO - arranged in descending order of ack_ackno 1248c2ecf20Sopenharmony_ci * 1258c2ecf20Sopenharmony_ci * This structure is used by CCIDs to access Ack Vectors in a received skb. 1268c2ecf20Sopenharmony_ci */ 1278c2ecf20Sopenharmony_cistruct dccp_ackvec_parsed { 1288c2ecf20Sopenharmony_ci u8 *vec, 1298c2ecf20Sopenharmony_ci len, 1308c2ecf20Sopenharmony_ci nonce:1; 1318c2ecf20Sopenharmony_ci struct list_head node; 1328c2ecf20Sopenharmony_ci}; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_ciint dccp_ackvec_parsed_add(struct list_head *head, u8 *vec, u8 len, u8 nonce); 1358c2ecf20Sopenharmony_civoid dccp_ackvec_parsed_cleanup(struct list_head *parsed_chunks); 1368c2ecf20Sopenharmony_ci#endif /* _ACKVEC_H */ 137