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 | bd012f2 | 2008-11-04 23:38:20 -0800 | [diff] [blame^] | 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 | * @val: feature's current value (SP features may have preference list) |
| 50 | * @state: feature's current state |
| 51 | * @feat_num: one of %dccp_feature_numbers |
| 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 | dccp_feat_val val; |
| 60 | enum dccp_feat_state state:8; |
| 61 | u8 feat_num; |
| 62 | |
| 63 | bool needs_mandatory, |
| 64 | needs_confirm, |
| 65 | empty_confirm, |
| 66 | is_local; |
| 67 | |
| 68 | struct list_head node; |
| 69 | }; |
| 70 | |
| 71 | static inline u8 dccp_feat_genopt(struct dccp_feat_entry *entry) |
| 72 | { |
| 73 | if (entry->needs_confirm) |
| 74 | return entry->is_local ? DCCPO_CONFIRM_L : DCCPO_CONFIRM_R; |
| 75 | return entry->is_local ? DCCPO_CHANGE_L : DCCPO_CHANGE_R; |
| 76 | } |
| 77 | |
Gerrit Renker | c02fdc0 | 2006-11-14 12:48:10 -0200 | [diff] [blame] | 78 | #ifdef CONFIG_IP_DCCP_DEBUG |
| 79 | extern const char *dccp_feat_typename(const u8 type); |
| 80 | extern const char *dccp_feat_name(const u8 feat); |
| 81 | |
| 82 | static inline void dccp_feat_debug(const u8 type, const u8 feat, const u8 val) |
| 83 | { |
| 84 | dccp_pr_debug("%s(%s (%d), %d)\n", dccp_feat_typename(type), |
| 85 | dccp_feat_name(feat), feat, val); |
| 86 | } |
| 87 | #else |
| 88 | #define dccp_feat_debug(type, feat, val) |
| 89 | #endif /* CONFIG_IP_DCCP_DEBUG */ |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 90 | |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 91 | extern int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature, |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 92 | u8 *val, u8 len, gfp_t gfp); |
| 93 | extern int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature, |
| 94 | u8 *val, u8 len); |
| 95 | extern int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature, |
| 96 | u8 *val, u8 len); |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 97 | extern void dccp_feat_clean(struct dccp_minisock *dmsk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 98 | extern int dccp_feat_clone(struct sock *oldsk, struct sock *newsk); |
Arnaldo Carvalho de Melo | 8ca0d17 | 2006-03-20 22:51:53 -0800 | [diff] [blame] | 99 | extern int dccp_feat_init(struct dccp_minisock *dmsk); |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 100 | |
Andrea Bittau | afe0025 | 2006-03-20 17:43:56 -0800 | [diff] [blame] | 101 | #endif /* _DCCP_FEAT_H */ |