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