diff options
author | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2008-09-04 01:30:19 -0400 |
---|---|---|
committer | Gerrit Renker <gerrit@erg.abdn.ac.uk> | 2008-09-04 01:45:26 -0400 |
commit | 5c7c9451f1f422b69bf0e161e471dd3976ecd408 (patch) | |
tree | be9afac388bb4b62a34db7025d83dc8730b4510c | |
parent | 959fd992f05b7468bf30d759ac0c9fd0ef0fa80b (diff) |
dccp: Basic data structure for feature negotiation
This patch prepares for the new and extended feature-negotiation routines.
The following feature-negotiation data structures are provided:
* a container for the various (SP or NN) values,
* symbolic state names to track feature states,
* an entry struct which holds all current information together,
* elementary functions to fill in and process these structures.
Entry structs are arranged as FIFO for the following reason: RFC 4340 specifies
that if multiple options of the same type are present, they are processed in the
order of their appearance in the packet; which means that this order needs to be
preserved in the local data structure (the later insertion code also respects
this order).
The struct list_head has been chosen for the following reasons: the most
frequent operations are
* add new entry at tail (when receiving Change or setting socket options);
* delete entry (when Confirm has been received);
* deep copy of entire list (cloning from listening socket onto request socket).
The NN value has been set to 64 bit, which is a currently sufficient upper limit
(Sequence Window feature has 48 bit).
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
-rw-r--r-- | net/dccp/feat.c | 14 | ||||
-rw-r--r-- | net/dccp/feat.h | 60 |
2 files changed, 74 insertions, 0 deletions
diff --git a/net/dccp/feat.c b/net/dccp/feat.c index 933a0ecf8d46..94a81b8e5efb 100644 --- a/net/dccp/feat.c +++ b/net/dccp/feat.c | |||
@@ -23,6 +23,20 @@ | |||
23 | 23 | ||
24 | #define DCCP_FEAT_SP_NOAGREE (-123) | 24 | #define DCCP_FEAT_SP_NOAGREE (-123) |
25 | 25 | ||
26 | /* copy constructor, fval must not already contain allocated memory */ | ||
27 | static int dccp_feat_clone_sp_val(dccp_feat_val *fval, u8 const *val, u8 len) | ||
28 | { | ||
29 | fval->sp.len = len; | ||
30 | if (fval->sp.len > 0) { | ||
31 | fval->sp.vec = kmemdup(val, len, gfp_any()); | ||
32 | if (fval->sp.vec == NULL) { | ||
33 | fval->sp.len = 0; | ||
34 | return -ENOBUFS; | ||
35 | } | ||
36 | } | ||
37 | return 0; | ||
38 | } | ||
39 | |||
26 | int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, | 40 | int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, |
27 | u8 *val, u8 len, gfp_t gfp) | 41 | u8 *val, u8 len, gfp_t gfp) |
28 | { | 42 | { |
diff --git a/net/dccp/feat.h b/net/dccp/feat.h index e272222c7ace..94203c230c65 100644 --- a/net/dccp/feat.h +++ b/net/dccp/feat.h | |||
@@ -14,6 +14,66 @@ | |||
14 | #include <linux/types.h> | 14 | #include <linux/types.h> |
15 | #include "dccp.h" | 15 | #include "dccp.h" |
16 | 16 | ||
17 | enum dccp_feat_type { | ||
18 | FEAT_AT_RX = 1, /* located at RX side of half-connection */ | ||
19 | FEAT_AT_TX = 2, /* located at TX side of half-connection */ | ||
20 | FEAT_SP = 4, /* server-priority reconciliation (6.3.1) */ | ||
21 | FEAT_NN = 8, /* non-negotiable reconciliation (6.3.2) */ | ||
22 | FEAT_UNKNOWN = 0xFF /* not understood or invalid feature */ | ||
23 | }; | ||
24 | |||
25 | enum dccp_feat_state { | ||
26 | FEAT_DEFAULT = 0, /* using default values from 6.4 */ | ||
27 | FEAT_INITIALISING, /* feature is being initialised */ | ||
28 | FEAT_CHANGING, /* Change sent but not confirmed yet */ | ||
29 | FEAT_UNSTABLE, /* local modification in state CHANGING */ | ||
30 | FEAT_STABLE /* both ends (think they) agree */ | ||
31 | }; | ||
32 | |||
33 | /** | ||
34 | * dccp_feat_val - Container for SP or NN feature values | ||
35 | * @nn: single NN value | ||
36 | * @sp.vec: single SP value plus optional preference list | ||
37 | * @sp.len: length of @sp.vec in bytes | ||
38 | */ | ||
39 | typedef union { | ||
40 | u64 nn; | ||
41 | struct { | ||
42 | u8 *vec; | ||
43 | u8 len; | ||
44 | } sp; | ||
45 | } dccp_feat_val; | ||
46 | |||
47 | /** | ||
48 | * struct feat_entry - Data structure to perform feature negotiation | ||
49 | * @feat_num: one of %dccp_feature_numbers | ||
50 | * @val: feature's current value (SP features may have preference list) | ||
51 | * @state: feature's current state | ||
52 | * @needs_mandatory: whether Mandatory options should be sent | ||
53 | * @needs_confirm: whether to send a Confirm instead of a Change | ||
54 | * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm) | ||
55 | * @is_local: feature location (1) or feature-remote (0) | ||
56 | * @node: list pointers, entries arranged in FIFO order | ||
57 | */ | ||
58 | struct dccp_feat_entry { | ||
59 | u8 feat_num; | ||
60 | dccp_feat_val val; | ||
61 | enum dccp_feat_state state:8; | ||
62 | bool needs_mandatory:1, | ||
63 | needs_confirm:1, | ||
64 | empty_confirm:1, | ||
65 | is_local:1; | ||
66 | |||
67 | struct list_head node; | ||
68 | }; | ||
69 | |||
70 | static inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry) | ||
71 | { | ||
72 | if (entry->needs_confirm) | ||
73 | return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R; | ||
74 | return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R; | ||
75 | } | ||
76 | |||
17 | #ifdef CONFIG_IP_DCCP_DEBUG | 77 | #ifdef CONFIG_IP_DCCP_DEBUG |
18 | extern const char *dccp_feat_typename(const u8 type); | 78 | extern const char *dccp_feat_typename(const u8 type); |
19 | extern const char *dccp_feat_name(const u8 feat); | 79 | extern const char *dccp_feat_name(const u8 feat); |