blob: 177f7dee4d101bf3a5963b0cd61d03cc1c605552 [file] [log] [blame]
Andrea Bittauafe00252006-03-20 17:43:56 -08001#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 Renkerc02fdc02006-11-14 12:48:10 -020015#include "dccp.h"
Andrea Bittauafe00252006-03-20 17:43:56 -080016
Gerrit Renkerc02fdc02006-11-14 12:48:10 -020017static inline int dccp_feat_is_valid_length(u8 type, u8 feature, u8 len)
18{
19 /* sec. 6.1: Confirm has at least length 3,
20 * sec. 6.2: Change has at least length 4 */
21 if (len < 3)
22 return 1;
23 if (len < 4 && (type == DCCPO_CHANGE_L || type == DCCPO_CHANGE_R))
24 return 1;
25 /* XXX: add per-feature length validation (sec. 6.6.8) */
26 return 0;
27}
28
29static inline int dccp_feat_is_reserved(const u8 feat)
30{
31 return (feat > DCCPF_DATA_CHECKSUM &&
32 feat < DCCPF_MIN_CCID_SPECIFIC) ||
YOSHIFUJI Hideakic9eaf172007-02-09 23:24:38 +090033 feat == DCCPF_RESERVED;
Gerrit Renkerc02fdc02006-11-14 12:48:10 -020034}
35
36/* feature negotiation knows only these four option types (RFC 4340, sec. 6) */
37static inline int dccp_feat_is_valid_type(const u8 optnum)
38{
39 return optnum >= DCCPO_CHANGE_L && optnum <= DCCPO_CONFIRM_R;
40
41}
42
43#ifdef CONFIG_IP_DCCP_DEBUG
44extern const char *dccp_feat_typename(const u8 type);
45extern const char *dccp_feat_name(const u8 feat);
46
47static inline void dccp_feat_debug(const u8 type, const u8 feat, const u8 val)
48{
49 dccp_pr_debug("%s(%s (%d), %d)\n", dccp_feat_typename(type),
50 dccp_feat_name(feat), feat, val);
51}
52#else
53#define dccp_feat_debug(type, feat, val)
54#endif /* CONFIG_IP_DCCP_DEBUG */
Andrea Bittauafe00252006-03-20 17:43:56 -080055
Arnaldo Carvalho de Melo8ca0d172006-03-20 22:51:53 -080056extern int dccp_feat_change(struct dccp_minisock *dmsk, u8 type, u8 feature,
Andrea Bittauafe00252006-03-20 17:43:56 -080057 u8 *val, u8 len, gfp_t gfp);
58extern int dccp_feat_change_recv(struct sock *sk, u8 type, u8 feature,
59 u8 *val, u8 len);
60extern int dccp_feat_confirm_recv(struct sock *sk, u8 type, u8 feature,
61 u8 *val, u8 len);
Arnaldo Carvalho de Melo8ca0d172006-03-20 22:51:53 -080062extern void dccp_feat_clean(struct dccp_minisock *dmsk);
Andrea Bittauafe00252006-03-20 17:43:56 -080063extern int dccp_feat_clone(struct sock *oldsk, struct sock *newsk);
Arnaldo Carvalho de Melo8ca0d172006-03-20 22:51:53 -080064extern int dccp_feat_init(struct dccp_minisock *dmsk);
Andrea Bittauafe00252006-03-20 17:43:56 -080065
Andrea Bittauafe00252006-03-20 17:43:56 -080066#endif /* _DCCP_FEAT_H */