18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci#ifndef _DCCP_FEAT_H
38c2ecf20Sopenharmony_ci#define _DCCP_FEAT_H
48c2ecf20Sopenharmony_ci/*
58c2ecf20Sopenharmony_ci *  net/dccp/feat.h
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci *  Feature negotiation for the DCCP protocol (RFC 4340, section 6)
88c2ecf20Sopenharmony_ci *  Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk>
98c2ecf20Sopenharmony_ci *  Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk>
108c2ecf20Sopenharmony_ci */
118c2ecf20Sopenharmony_ci#include <linux/types.h>
128c2ecf20Sopenharmony_ci#include "dccp.h"
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * Known limit values
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_ci/* Ack Ratio takes 2-byte integer values (11.3) */
188c2ecf20Sopenharmony_ci#define DCCPF_ACK_RATIO_MAX	0xFFFF
198c2ecf20Sopenharmony_ci/* Wmin=32 and Wmax=2^46-1 from 7.5.2 */
208c2ecf20Sopenharmony_ci#define DCCPF_SEQ_WMIN		32
218c2ecf20Sopenharmony_ci#define DCCPF_SEQ_WMAX		0x3FFFFFFFFFFFull
228c2ecf20Sopenharmony_ci/* Maximum number of SP values that fit in a single (Confirm) option */
238c2ecf20Sopenharmony_ci#define DCCP_FEAT_MAX_SP_VALS	(DCCP_SINGLE_OPT_MAXLEN - 2)
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cienum dccp_feat_type {
268c2ecf20Sopenharmony_ci	FEAT_AT_RX   = 1,	/* located at RX side of half-connection  */
278c2ecf20Sopenharmony_ci	FEAT_AT_TX   = 2,	/* located at TX side of half-connection  */
288c2ecf20Sopenharmony_ci	FEAT_SP      = 4,	/* server-priority reconciliation (6.3.1) */
298c2ecf20Sopenharmony_ci	FEAT_NN	     = 8,	/* non-negotiable reconciliation (6.3.2)  */
308c2ecf20Sopenharmony_ci	FEAT_UNKNOWN = 0xFF	/* not understood or invalid feature	  */
318c2ecf20Sopenharmony_ci};
328c2ecf20Sopenharmony_ci
338c2ecf20Sopenharmony_cienum dccp_feat_state {
348c2ecf20Sopenharmony_ci	FEAT_DEFAULT = 0,	/* using default values from 6.4 */
358c2ecf20Sopenharmony_ci	FEAT_INITIALISING,	/* feature is being initialised  */
368c2ecf20Sopenharmony_ci	FEAT_CHANGING,		/* Change sent but not confirmed yet */
378c2ecf20Sopenharmony_ci	FEAT_UNSTABLE,		/* local modification in state CHANGING */
388c2ecf20Sopenharmony_ci	FEAT_STABLE		/* both ends (think they) agree */
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci/**
428c2ecf20Sopenharmony_ci * dccp_feat_val  -  Container for SP or NN feature values
438c2ecf20Sopenharmony_ci * @nn:     single NN value
448c2ecf20Sopenharmony_ci * @sp.vec: single SP value plus optional preference list
458c2ecf20Sopenharmony_ci * @sp.len: length of @sp.vec in bytes
468c2ecf20Sopenharmony_ci */
478c2ecf20Sopenharmony_citypedef union {
488c2ecf20Sopenharmony_ci	u64 nn;
498c2ecf20Sopenharmony_ci	struct {
508c2ecf20Sopenharmony_ci		u8	*vec;
518c2ecf20Sopenharmony_ci		u8	len;
528c2ecf20Sopenharmony_ci	}   sp;
538c2ecf20Sopenharmony_ci} dccp_feat_val;
548c2ecf20Sopenharmony_ci
558c2ecf20Sopenharmony_ci/**
568c2ecf20Sopenharmony_ci * struct feat_entry  -  Data structure to perform feature negotiation
578c2ecf20Sopenharmony_ci * @val: feature's current value (SP features may have preference list)
588c2ecf20Sopenharmony_ci * @state: feature's current state
598c2ecf20Sopenharmony_ci * @feat_num: one of %dccp_feature_numbers
608c2ecf20Sopenharmony_ci * @needs_mandatory: whether Mandatory options should be sent
618c2ecf20Sopenharmony_ci * @needs_confirm: whether to send a Confirm instead of a Change
628c2ecf20Sopenharmony_ci * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm)
638c2ecf20Sopenharmony_ci * @is_local: feature location (1) or feature-remote (0)
648c2ecf20Sopenharmony_ci * @node: list pointers, entries arranged in FIFO order
658c2ecf20Sopenharmony_ci */
668c2ecf20Sopenharmony_cistruct dccp_feat_entry {
678c2ecf20Sopenharmony_ci	dccp_feat_val           val;
688c2ecf20Sopenharmony_ci	enum dccp_feat_state    state:8;
698c2ecf20Sopenharmony_ci	u8                      feat_num;
708c2ecf20Sopenharmony_ci
718c2ecf20Sopenharmony_ci	bool			needs_mandatory,
728c2ecf20Sopenharmony_ci				needs_confirm,
738c2ecf20Sopenharmony_ci				empty_confirm,
748c2ecf20Sopenharmony_ci				is_local;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	struct list_head	node;
778c2ecf20Sopenharmony_ci};
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry)
808c2ecf20Sopenharmony_ci{
818c2ecf20Sopenharmony_ci	if (entry->needs_confirm)
828c2ecf20Sopenharmony_ci		return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R;
838c2ecf20Sopenharmony_ci	return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R;
848c2ecf20Sopenharmony_ci}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/**
878c2ecf20Sopenharmony_ci * struct ccid_dependency  -  Track changes resulting from choosing a CCID
888c2ecf20Sopenharmony_ci * @dependent_feat: one of %dccp_feature_numbers
898c2ecf20Sopenharmony_ci * @is_local: local (1) or remote (0) @dependent_feat
908c2ecf20Sopenharmony_ci * @is_mandatory: whether presence of @dependent_feat is mission-critical or not
918c2ecf20Sopenharmony_ci * @val: corresponding default value for @dependent_feat (u8 is sufficient here)
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_cistruct ccid_dependency {
948c2ecf20Sopenharmony_ci	u8	dependent_feat;
958c2ecf20Sopenharmony_ci	bool	is_local:1,
968c2ecf20Sopenharmony_ci		is_mandatory:1;
978c2ecf20Sopenharmony_ci	u8	val;
988c2ecf20Sopenharmony_ci};
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci/*
1018c2ecf20Sopenharmony_ci * Sysctls to seed defaults for feature negotiation
1028c2ecf20Sopenharmony_ci */
1038c2ecf20Sopenharmony_ciextern unsigned long sysctl_dccp_sequence_window;
1048c2ecf20Sopenharmony_ciextern int	     sysctl_dccp_rx_ccid;
1058c2ecf20Sopenharmony_ciextern int	     sysctl_dccp_tx_ccid;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ciint dccp_feat_init(struct sock *sk);
1088c2ecf20Sopenharmony_civoid dccp_feat_initialise_sysctls(void);
1098c2ecf20Sopenharmony_ciint dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local,
1108c2ecf20Sopenharmony_ci			  u8 const *list, u8 len);
1118c2ecf20Sopenharmony_ciint dccp_feat_parse_options(struct sock *, struct dccp_request_sock *,
1128c2ecf20Sopenharmony_ci			    u8 mand, u8 opt, u8 feat, u8 *val, u8 len);
1138c2ecf20Sopenharmony_ciint dccp_feat_clone_list(struct list_head const *, struct list_head *);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_ci/*
1168c2ecf20Sopenharmony_ci * Encoding variable-length options and their maximum length.
1178c2ecf20Sopenharmony_ci *
1188c2ecf20Sopenharmony_ci * This affects NN options (SP options are all u8) and other variable-length
1198c2ecf20Sopenharmony_ci * options (see table 3 in RFC 4340). The limit is currently given the Sequence
1208c2ecf20Sopenharmony_ci * Window NN value (sec. 7.5.2) and the NDP count (sec. 7.7) option, all other
1218c2ecf20Sopenharmony_ci * options consume less than 6 bytes (timestamps are 4 bytes).
1228c2ecf20Sopenharmony_ci * When updating this constant (e.g. due to new internet drafts / RFCs), make
1238c2ecf20Sopenharmony_ci * sure that you also update all code which refers to it.
1248c2ecf20Sopenharmony_ci */
1258c2ecf20Sopenharmony_ci#define DCCP_OPTVAL_MAXLEN	6
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_civoid dccp_encode_value_var(const u64 value, u8 *to, const u8 len);
1288c2ecf20Sopenharmony_ciu64 dccp_decode_value_var(const u8 *bf, const u8 len);
1298c2ecf20Sopenharmony_ciu64 dccp_feat_nn_get(struct sock *sk, u8 feat);
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ciint dccp_insert_option_mandatory(struct sk_buff *skb);
1328c2ecf20Sopenharmony_ciint dccp_insert_fn_opt(struct sk_buff *skb, u8 type, u8 feat, u8 *val, u8 len,
1338c2ecf20Sopenharmony_ci		       bool repeat_first);
1348c2ecf20Sopenharmony_ci#endif /* _DCCP_FEAT_H */
135