162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 262306a36Sopenharmony_ci#ifndef _DCCP_FEAT_H 362306a36Sopenharmony_ci#define _DCCP_FEAT_H 462306a36Sopenharmony_ci/* 562306a36Sopenharmony_ci * net/dccp/feat.h 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Feature negotiation for the DCCP protocol (RFC 4340, section 6) 862306a36Sopenharmony_ci * Copyright (c) 2008 Gerrit Renker <gerrit@erg.abdn.ac.uk> 962306a36Sopenharmony_ci * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk> 1062306a36Sopenharmony_ci */ 1162306a36Sopenharmony_ci#include <linux/types.h> 1262306a36Sopenharmony_ci#include "dccp.h" 1362306a36Sopenharmony_ci 1462306a36Sopenharmony_ci/* 1562306a36Sopenharmony_ci * Known limit values 1662306a36Sopenharmony_ci */ 1762306a36Sopenharmony_ci/* Ack Ratio takes 2-byte integer values (11.3) */ 1862306a36Sopenharmony_ci#define DCCPF_ACK_RATIO_MAX 0xFFFF 1962306a36Sopenharmony_ci/* Wmin=32 and Wmax=2^46-1 from 7.5.2 */ 2062306a36Sopenharmony_ci#define DCCPF_SEQ_WMIN 32 2162306a36Sopenharmony_ci#define DCCPF_SEQ_WMAX 0x3FFFFFFFFFFFull 2262306a36Sopenharmony_ci/* Maximum number of SP values that fit in a single (Confirm) option */ 2362306a36Sopenharmony_ci#define DCCP_FEAT_MAX_SP_VALS (DCCP_SINGLE_OPT_MAXLEN - 2) 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_cienum dccp_feat_type { 2662306a36Sopenharmony_ci FEAT_AT_RX = 1, /* located at RX side of half-connection */ 2762306a36Sopenharmony_ci FEAT_AT_TX = 2, /* located at TX side of half-connection */ 2862306a36Sopenharmony_ci FEAT_SP = 4, /* server-priority reconciliation (6.3.1) */ 2962306a36Sopenharmony_ci FEAT_NN = 8, /* non-negotiable reconciliation (6.3.2) */ 3062306a36Sopenharmony_ci FEAT_UNKNOWN = 0xFF /* not understood or invalid feature */ 3162306a36Sopenharmony_ci}; 3262306a36Sopenharmony_ci 3362306a36Sopenharmony_cienum dccp_feat_state { 3462306a36Sopenharmony_ci FEAT_DEFAULT = 0, /* using default values from 6.4 */ 3562306a36Sopenharmony_ci FEAT_INITIALISING, /* feature is being initialised */ 3662306a36Sopenharmony_ci FEAT_CHANGING, /* Change sent but not confirmed yet */ 3762306a36Sopenharmony_ci FEAT_UNSTABLE, /* local modification in state CHANGING */ 3862306a36Sopenharmony_ci FEAT_STABLE /* both ends (think they) agree */ 3962306a36Sopenharmony_ci}; 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_ci/** 4262306a36Sopenharmony_ci * dccp_feat_val - Container for SP or NN feature values 4362306a36Sopenharmony_ci * @nn: single NN value 4462306a36Sopenharmony_ci * @sp.vec: single SP value plus optional preference list 4562306a36Sopenharmony_ci * @sp.len: length of @sp.vec in bytes 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_citypedef union { 4862306a36Sopenharmony_ci u64 nn; 4962306a36Sopenharmony_ci struct { 5062306a36Sopenharmony_ci u8 *vec; 5162306a36Sopenharmony_ci u8 len; 5262306a36Sopenharmony_ci } sp; 5362306a36Sopenharmony_ci} dccp_feat_val; 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci/** 5662306a36Sopenharmony_ci * struct feat_entry - Data structure to perform feature negotiation 5762306a36Sopenharmony_ci * @val: feature's current value (SP features may have preference list) 5862306a36Sopenharmony_ci * @state: feature's current state 5962306a36Sopenharmony_ci * @feat_num: one of %dccp_feature_numbers 6062306a36Sopenharmony_ci * @needs_mandatory: whether Mandatory options should be sent 6162306a36Sopenharmony_ci * @needs_confirm: whether to send a Confirm instead of a Change 6262306a36Sopenharmony_ci * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm) 6362306a36Sopenharmony_ci * @is_local: feature location (1) or feature-remote (0) 6462306a36Sopenharmony_ci * @node: list pointers, entries arranged in FIFO order 6562306a36Sopenharmony_ci */ 6662306a36Sopenharmony_cistruct dccp_feat_entry { 6762306a36Sopenharmony_ci dccp_feat_val val; 6862306a36Sopenharmony_ci enum dccp_feat_state state:8; 6962306a36Sopenharmony_ci u8 feat_num; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci bool needs_mandatory, 7262306a36Sopenharmony_ci needs_confirm, 7362306a36Sopenharmony_ci empty_confirm, 7462306a36Sopenharmony_ci is_local; 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci struct list_head node; 7762306a36Sopenharmony_ci}; 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_cistatic inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry) 8062306a36Sopenharmony_ci{ 8162306a36Sopenharmony_ci if (entry->needs_confirm) 8262306a36Sopenharmony_ci return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R; 8362306a36Sopenharmony_ci return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R; 8462306a36Sopenharmony_ci} 8562306a36Sopenharmony_ci 8662306a36Sopenharmony_ci/** 8762306a36Sopenharmony_ci * struct ccid_dependency - Track changes resulting from choosing a CCID 8862306a36Sopenharmony_ci * @dependent_feat: one of %dccp_feature_numbers 8962306a36Sopenharmony_ci * @is_local: local (1) or remote (0) @dependent_feat 9062306a36Sopenharmony_ci * @is_mandatory: whether presence of @dependent_feat is mission-critical or not 9162306a36Sopenharmony_ci * @val: corresponding default value for @dependent_feat (u8 is sufficient here) 9262306a36Sopenharmony_ci */ 9362306a36Sopenharmony_cistruct ccid_dependency { 9462306a36Sopenharmony_ci u8 dependent_feat; 9562306a36Sopenharmony_ci bool is_local:1, 9662306a36Sopenharmony_ci is_mandatory:1; 9762306a36Sopenharmony_ci u8 val; 9862306a36Sopenharmony_ci}; 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* 10162306a36Sopenharmony_ci * Sysctls to seed defaults for feature negotiation 10262306a36Sopenharmony_ci */ 10362306a36Sopenharmony_ciextern unsigned long sysctl_dccp_sequence_window; 10462306a36Sopenharmony_ciextern int sysctl_dccp_rx_ccid; 10562306a36Sopenharmony_ciextern int sysctl_dccp_tx_ccid; 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ciint dccp_feat_init(struct sock *sk); 10862306a36Sopenharmony_ciint dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local, 10962306a36Sopenharmony_ci u8 const *list, u8 len); 11062306a36Sopenharmony_ciint dccp_feat_parse_options(struct sock *, struct dccp_request_sock *, 11162306a36Sopenharmony_ci u8 mand, u8 opt, u8 feat, u8 *val, u8 len); 11262306a36Sopenharmony_ciint dccp_feat_clone_list(struct list_head const *, struct list_head *); 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* 11562306a36Sopenharmony_ci * Encoding variable-length options and their maximum length. 11662306a36Sopenharmony_ci * 11762306a36Sopenharmony_ci * This affects NN options (SP options are all u8) and other variable-length 11862306a36Sopenharmony_ci * options (see table 3 in RFC 4340). The limit is currently given the Sequence 11962306a36Sopenharmony_ci * Window NN value (sec. 7.5.2) and the NDP count (sec. 7.7) option, all other 12062306a36Sopenharmony_ci * options consume less than 6 bytes (timestamps are 4 bytes). 12162306a36Sopenharmony_ci * When updating this constant (e.g. due to new internet drafts / RFCs), make 12262306a36Sopenharmony_ci * sure that you also update all code which refers to it. 12362306a36Sopenharmony_ci */ 12462306a36Sopenharmony_ci#define DCCP_OPTVAL_MAXLEN 6 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_civoid dccp_encode_value_var(const u64 value, u8 *to, const u8 len); 12762306a36Sopenharmony_ciu64 dccp_decode_value_var(const u8 *bf, const u8 len); 12862306a36Sopenharmony_ciu64 dccp_feat_nn_get(struct sock *sk, u8 feat); 12962306a36Sopenharmony_ci 13062306a36Sopenharmony_ciint dccp_insert_option_mandatory(struct sk_buff *skb); 13162306a36Sopenharmony_ciint dccp_insert_fn_opt(struct sk_buff *skb, u8 type, u8 feat, u8 *val, u8 len, 13262306a36Sopenharmony_ci bool repeat_first); 13362306a36Sopenharmony_ci#endif /* _DCCP_FEAT_H */ 134