xref: /linux/net/dccp/feat.h (revision a1c613ae4c322ddd58d5a8539dbfba2a0380a8c0)
1*d2912cb1SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
2afe00251SAndrea Bittau #ifndef _DCCP_FEAT_H
3afe00251SAndrea Bittau #define _DCCP_FEAT_H
4afe00251SAndrea Bittau /*
5afe00251SAndrea Bittau  *  net/dccp/feat.h
6afe00251SAndrea Bittau  *
763b8e286SGerrit Renker  *  Feature negotiation for the DCCP protocol (RFC 4340, section 6)
863b8e286SGerrit Renker  *  Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk>
9afe00251SAndrea Bittau  *  Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
10afe00251SAndrea Bittau  */
11afe00251SAndrea Bittau #include <linux/types.h>
12c02fdc0eSGerrit Renker #include "dccp.h"
13afe00251SAndrea Bittau 
14e8ef967aSGerrit Renker /*
15e8ef967aSGerrit Renker  * Known limit values
16e8ef967aSGerrit Renker  */
17e8ef967aSGerrit Renker /* Ack Ratio takes 2-byte integer values (11.3) */
18e8ef967aSGerrit Renker #define DCCPF_ACK_RATIO_MAX	0xFFFF
19e8ef967aSGerrit Renker /* Wmin=32 and Wmax=2^46-1 from 7.5.2 */
20e8ef967aSGerrit Renker #define DCCPF_SEQ_WMIN		32
21e8ef967aSGerrit Renker #define DCCPF_SEQ_WMAX		0x3FFFFFFFFFFFull
22b20a9c24SGerrit Renker /* Maximum number of SP values that fit in a single (Confirm) option */
23b20a9c24SGerrit Renker #define DCCP_FEAT_MAX_SP_VALS	(DCCP_SINGLE_OPT_MAXLEN - 2)
24e8ef967aSGerrit Renker 
25bd012f2eSGerrit Renker enum dccp_feat_type {
26bd012f2eSGerrit Renker 	FEAT_AT_RX   = 1,	/* located at RX side of half-connection  */
27bd012f2eSGerrit Renker 	FEAT_AT_TX   = 2,	/* located at TX side of half-connection  */
28bd012f2eSGerrit Renker 	FEAT_SP      = 4,	/* server-priority reconciliation (6.3.1) */
29bd012f2eSGerrit Renker 	FEAT_NN	     = 8,	/* non-negotiable reconciliation (6.3.2)  */
30bd012f2eSGerrit Renker 	FEAT_UNKNOWN = 0xFF	/* not understood or invalid feature	  */
31bd012f2eSGerrit Renker };
32bd012f2eSGerrit Renker 
33bd012f2eSGerrit Renker enum dccp_feat_state {
34bd012f2eSGerrit Renker 	FEAT_DEFAULT = 0,	/* using default values from 6.4 */
35bd012f2eSGerrit Renker 	FEAT_INITIALISING,	/* feature is being initialised  */
36bd012f2eSGerrit Renker 	FEAT_CHANGING,		/* Change sent but not confirmed yet */
37bd012f2eSGerrit Renker 	FEAT_UNSTABLE,		/* local modification in state CHANGING */
38bd012f2eSGerrit Renker 	FEAT_STABLE		/* both ends (think they) agree */
39bd012f2eSGerrit Renker };
40bd012f2eSGerrit Renker 
41bd012f2eSGerrit Renker /**
42bd012f2eSGerrit Renker  * dccp_feat_val  -  Container for SP or NN feature values
43bd012f2eSGerrit Renker  * @nn:     single NN value
44bd012f2eSGerrit Renker  * @sp.vec: single SP value plus optional preference list
45bd012f2eSGerrit Renker  * @sp.len: length of @sp.vec in bytes
46bd012f2eSGerrit Renker  */
47bd012f2eSGerrit Renker typedef union {
48bd012f2eSGerrit Renker 	u64 nn;
49bd012f2eSGerrit Renker 	struct {
50bd012f2eSGerrit Renker 		u8	*vec;
51bd012f2eSGerrit Renker 		u8	len;
52bd012f2eSGerrit Renker 	}   sp;
53bd012f2eSGerrit Renker } dccp_feat_val;
54bd012f2eSGerrit Renker 
55bd012f2eSGerrit Renker /**
56bd012f2eSGerrit Renker  * struct feat_entry  -  Data structure to perform feature negotiation
57bd012f2eSGerrit Renker  * @val: feature's current value (SP features may have preference list)
58bd012f2eSGerrit Renker  * @state: feature's current state
59bd012f2eSGerrit Renker  * @feat_num: one of %dccp_feature_numbers
60bd012f2eSGerrit Renker  * @needs_mandatory: whether Mandatory options should be sent
61bd012f2eSGerrit Renker  * @needs_confirm: whether to send a Confirm instead of a Change
62bd012f2eSGerrit Renker  * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm)
63bd012f2eSGerrit Renker  * @is_local: feature location (1) or feature-remote (0)
64bd012f2eSGerrit Renker  * @node: list pointers, entries arranged in FIFO order
65bd012f2eSGerrit Renker  */
66bd012f2eSGerrit Renker struct dccp_feat_entry {
67bd012f2eSGerrit Renker 	dccp_feat_val           val;
68bd012f2eSGerrit Renker 	enum dccp_feat_state    state:8;
69bd012f2eSGerrit Renker 	u8                      feat_num;
70bd012f2eSGerrit Renker 
71bd012f2eSGerrit Renker 	bool			needs_mandatory,
72bd012f2eSGerrit Renker 				needs_confirm,
73bd012f2eSGerrit Renker 				empty_confirm,
74bd012f2eSGerrit Renker 				is_local;
75bd012f2eSGerrit Renker 
76bd012f2eSGerrit Renker 	struct list_head	node;
77bd012f2eSGerrit Renker };
78bd012f2eSGerrit Renker 
dccp_feat_genopt(struct dccp_feat_entry * entry)79bd012f2eSGerrit Renker static inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry)
80bd012f2eSGerrit Renker {
81bd012f2eSGerrit Renker 	if (entry->needs_confirm)
82bd012f2eSGerrit Renker 		return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R;
83bd012f2eSGerrit Renker 	return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R;
84bd012f2eSGerrit Renker }
85bd012f2eSGerrit Renker 
86e8ef967aSGerrit Renker /**
87e8ef967aSGerrit Renker  * struct ccid_dependency  -  Track changes resulting from choosing a CCID
88e8ef967aSGerrit Renker  * @dependent_feat: one of %dccp_feature_numbers
89e8ef967aSGerrit Renker  * @is_local: local (1) or remote (0) @dependent_feat
90e8ef967aSGerrit Renker  * @is_mandatory: whether presence of @dependent_feat is mission-critical or not
91e8ef967aSGerrit Renker  * @val: corresponding default value for @dependent_feat (u8 is sufficient here)
92e8ef967aSGerrit Renker  */
93e8ef967aSGerrit Renker struct ccid_dependency {
94e8ef967aSGerrit Renker 	u8	dependent_feat;
95e8ef967aSGerrit Renker 	bool	is_local:1,
96e8ef967aSGerrit Renker 		is_mandatory:1;
97e8ef967aSGerrit Renker 	u8	val;
98e8ef967aSGerrit Renker };
99e8ef967aSGerrit Renker 
100883ca833SGerrit Renker /*
101883ca833SGerrit Renker  * Sysctls to seed defaults for feature negotiation
102883ca833SGerrit Renker  */
103883ca833SGerrit Renker extern unsigned long sysctl_dccp_sequence_window;
104883ca833SGerrit Renker extern int	     sysctl_dccp_rx_ccid;
105883ca833SGerrit Renker extern int	     sysctl_dccp_tx_ccid;
106883ca833SGerrit Renker 
107a402a5aaSJoe Perches int dccp_feat_init(struct sock *sk);
108a402a5aaSJoe Perches int dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
10949aebc66SGerrit Renker 			  u8 const *list, u8 len);
110a402a5aaSJoe Perches int dccp_feat_parse_options(struct sock *, struct dccp_request_sock *,
111e77b8363SGerrit Renker 			    u8 mand, u8 opt, u8 feat, u8 *val, u8 len);
112a402a5aaSJoe Perches int dccp_feat_clone_list(struct list_head const *, struct list_head *);
113afe00251SAndrea Bittau 
11402fa460eSGerrit Renker /*
11502fa460eSGerrit Renker  * Encoding variable-length options and their maximum length.
11602fa460eSGerrit Renker  *
11702fa460eSGerrit Renker  * This affects NN options (SP options are all u8) and other variable-length
11802fa460eSGerrit Renker  * options (see table 3 in RFC 4340). The limit is currently given the Sequence
11902fa460eSGerrit Renker  * Window NN value (sec. 7.5.2) and the NDP count (sec. 7.7) option, all other
12002fa460eSGerrit Renker  * options consume less than 6 bytes (timestamps are 4 bytes).
12102fa460eSGerrit Renker  * When updating this constant (e.g. due to new internet drafts / RFCs), make
12202fa460eSGerrit Renker  * sure that you also update all code which refers to it.
12302fa460eSGerrit Renker  */
12402fa460eSGerrit Renker #define DCCP_OPTVAL_MAXLEN	6
12502fa460eSGerrit Renker 
126a402a5aaSJoe Perches void dccp_encode_value_var(const u64 value, u8 *to, const u8 len);
127a402a5aaSJoe Perches u64 dccp_decode_value_var(const u8 *bf, const u8 len);
128a402a5aaSJoe Perches u64 dccp_feat_nn_get(struct sock *sk, u8 feat);
129d3710566SGerrit Renker 
130a402a5aaSJoe Perches int dccp_insert_option_mandatory(struct sk_buff *skb);
131a402a5aaSJoe Perches int dccp_insert_fn_opt(struct sk_buff *skb, u8 type, u8 feat, u8 *val, u8 len,
132a402a5aaSJoe Perches 		       bool repeat_first);
133afe00251SAndrea Bittau #endif /* _DCCP_FEAT_H */
134