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 | * |
| 6 | * An implementation of the DCCP protocol |
| 7 | * Copyright (c) 2005 Andrea Bittau <a.bittau@cs.ucl.ac.uk> |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | */ |
| 13 | |
| 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 |
| 25 | |
Gerrit Renker | bd012f2 | 2008-11-04 23:38:20 -0800 | [diff] [blame] | 26 | enum dccp_feat_type { |
| 27 | FEAT_AT_RX = 1, /* located at RX side of half-connection */ |
| 28 | FEAT_AT_TX = 2, /* located at TX side of half-connection */ |
| 29 | FEAT_SP = 4, /* server-priority reconciliation (6.3.1) */ |
| 30 | FEAT_NN = 8, /* non-negotiable reconciliation (6.3.2) */ |
| 31 | FEAT_UNKNOWN = 0xFF /* not understood or invalid feature */ |
| 32 | }; |
| 33 | |
| 34 | enum dccp_feat_state { |
| 35 | FEAT_DEFAULT = 0, /* using default values from 6.4 */ |
| 36 | FEAT_INITIALISING, /* feature is being initialised */ |
| 37 | FEAT_CHANGING, /* Change sent but not confirmed yet */ |
| 38 | FEAT_UNSTABLE, /* local modification in state CHANGING */ |
| 39 | FEAT_STABLE /* both ends (think they) agree */ |
| 40 | }; |
| 41 | |
| 42 | /** |
| 43 | * dccp_feat_val - Container for SP or NN feature values |
| 44 | * @nn: single NN value |
| 45 | * @sp.vec: single SP value plus optional preference list |
| 46 | * @sp.len: length of @sp.vec in bytes |
| 47 | */ |
| 48 | typedef union { |
| 49 | u64 nn; |
| 50 | struct { |
| 51 | u8 *vec; |
| 52 | u8 len; |
| 53 | } sp; |
| 54 | } dccp_feat_val; |
| 55 | |
| 56 | /** |
| 57 | * struct feat_entry - Data structure to perform feature negotiation |
| 58 | * @val: feature's current value (SP features may have preference list) |
| 59 | * @state: feature's current state |
| 60 | * @feat_num: one of %dccp_feature_numbers |
| 61 | * @needs_mandatory: whether Mandatory options should be sent |
| 62 | * @needs_confirm: whether to send a Confirm instead of a Change |
| 63 | * @empty_confirm: whether to send an empty Confirm (depends on @needs_confirm) |
| 64 | * @is_local: feature location (1) or feature-remote (0) |
| 65 | * @node: list pointers, entries arranged in FIFO order |
| 66 | */ |
| 67 | struct dccp_feat_entry { |
| 68 | dccp_feat_val val; |
| 69 | enum dccp_feat_state state:8; |
| 70 | u8 feat_num; |
| 71 | |
| 72 | bool needs_mandatory, |
| 73 | needs_confirm, |
| 74 | empty_confirm, |
| 75 | is_local; |
| 76 | |
| 77 | struct list_head node; |
| 78 | }; |
| 79 | |
| 80 | static inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry) |
| 81 | { |
| 82 | if (entry->needs_confirm) |
| 83 | return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R; |
| 84 | return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R; |
| 85 | } |
| 86 | |
Gerrit Renker | e8ef967 | 2008-11-12 00:43:40 -0800 | [diff] [blame] | 87 | /** |
| 88 | * struct ccid_dependency - Track changes resulting from choosing a CCID |
| 89 | * @dependent_feat: one of %dccp_feature_numbers |
| 90 | * @is_local: local (1) or remote (0) @dependent_feat |
| 91 | * @is_mandatory: whether presence of @dependent_feat is mission-critical or not |
| 92 | * @val: corresponding default value for @dependent_feat (u8 is sufficient here) |
| 93 | */ |
| 94 | struct ccid_dependency { |
| 95 | u8 dependent_feat; |
| 96 | bool is_local:1, |
| 97 | is_mandatory:1; |
| 98 | u8 val; |
| 99 | }; |
| 100 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 101 | #ifdef CONFIG_IP_DCCP_DEBUG |
| 102 | extern const char *dccp_feat_typename(const u8 type); |
| 103 | extern const char *dccp_feat_name(const u8 feat); |
| 104 | |
| 105 | static inline void dccp_feat_debug(const u8 type, const u8 feat, const u8 val) |
| 106 | { |
| 107 | dccp_pr_debug("%s(%s (%d), %d)\n", dccp_feat_typename(type), |
| 108 | dccp_feat_name(feat), feat, val); |
| 109 | } |
| 110 | #else |
| 111 | #define dccp_feat_debug(type, feat, val) |
| 112 | #endif /* CONFIG_IP_DCCP_DEBUG */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 113 | |
Gerrit Renker | 49aebc6 | 2008-11-16 22:51:23 -0800 | [diff] [blame^] | 114 | extern int dccp_feat_register_sp(struct sock *sk, u8 feat, u8 is_local, |
| 115 | u8 const *list, u8 len); |
| 116 | extern int dccp_feat_register_nn(struct sock *sk, u8 feat, u64 val); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 117 | extern int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, |
| 118 | u8 *val, u8 len); |
| 119 | extern int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature, |
| 120 | u8 *val, u8 len); |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 121 | extern void dccp_feat_clean(struct dccp_minisock *dmsk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 122 | extern int dccp_feat_clone(struct sock *oldsk, struct sock *newsk); |
Gerrit Renker | ac75773 | 2008-11-04 23:55:49 -0800 | [diff] [blame] | 123 | 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] | 124 | extern int dccp_feat_init(struct sock *sk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 125 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 126 | #endif /* _DCCP_FEAT_H */ |