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