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