blob: de681c6ad081307c8fd1069eb6c370b4854177cd [file] [log] [blame]
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -07001#ifndef _CCID_H
2#define _CCID_H
3/*
4 * net/dccp/ccid.h
5 *
6 * An implementation of the DCCP protocol
7 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>
8 *
9 * CCID infrastructure
10 *
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#include <net/sock.h>
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -070017#include <linux/compiler.h>
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070018#include <linux/dccp.h>
19#include <linux/list.h>
20#include <linux/module.h>
21
22#define CCID_MAX 255
23
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020024struct tcp_info;
25
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070026struct ccid {
27 unsigned char ccid_id;
28 const char *ccid_name;
29 struct module *ccid_owner;
30 int (*ccid_init)(struct sock *sk);
31 void (*ccid_exit)(struct sock *sk);
32 int (*ccid_hc_rx_init)(struct sock *sk);
33 int (*ccid_hc_tx_init)(struct sock *sk);
34 void (*ccid_hc_rx_exit)(struct sock *sk);
35 void (*ccid_hc_tx_exit)(struct sock *sk);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030036 void (*ccid_hc_rx_packet_recv)(struct sock *sk,
37 struct sk_buff *skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070038 int (*ccid_hc_rx_parse_options)(struct sock *sk,
39 unsigned char option,
40 unsigned char len, u16 idx,
41 unsigned char* value);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030042 void (*ccid_hc_rx_insert_options)(struct sock *sk,
43 struct sk_buff *skb);
44 void (*ccid_hc_tx_insert_options)(struct sock *sk,
45 struct sk_buff *skb);
46 void (*ccid_hc_tx_packet_recv)(struct sock *sk,
47 struct sk_buff *skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070048 int (*ccid_hc_tx_parse_options)(struct sock *sk,
49 unsigned char option,
50 unsigned char len, u16 idx,
51 unsigned char* value);
52 int (*ccid_hc_tx_send_packet)(struct sock *sk,
Arnaldo Carvalho de Melo27258ee2005-08-09 20:30:56 -070053 struct sk_buff *skb, int len);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030054 void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more,
55 int len);
Arnaldo Carvalho de Melo2babe1f2005-08-23 21:52:35 -070056 void (*ccid_hc_rx_get_info)(struct sock *sk,
57 struct tcp_info *info);
58 void (*ccid_hc_tx_get_info)(struct sock *sk,
59 struct tcp_info *info);
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -070060 int (*ccid_hc_rx_getsockopt)(struct sock *sk,
61 const int optname, int len,
62 u32 __user *optval,
63 int __user *optlen);
64 int (*ccid_hc_tx_getsockopt)(struct sock *sk,
65 const int optname, int len,
66 u32 __user *optval,
67 int __user *optlen);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070068};
69
70extern int ccid_register(struct ccid *ccid);
71extern int ccid_unregister(struct ccid *ccid);
72
73extern struct ccid *ccid_init(unsigned char id, struct sock *sk);
74extern void ccid_exit(struct ccid *ccid, struct sock *sk);
75
76static inline void __ccid_get(struct ccid *ccid)
77{
78 __module_get(ccid->ccid_owner);
79}
80
81static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
Arnaldo Carvalho de Melo27258ee2005-08-09 20:30:56 -070082 struct sk_buff *skb, int len)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070083{
84 int rc = 0;
85 if (ccid->ccid_hc_tx_send_packet != NULL)
Arnaldo Carvalho de Melo27258ee2005-08-09 20:30:56 -070086 rc = ccid->ccid_hc_tx_send_packet(sk, skb, len);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070087 return rc;
88}
89
90static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
91 int more, int len)
92{
93 if (ccid->ccid_hc_tx_packet_sent != NULL)
94 ccid->ccid_hc_tx_packet_sent(sk, more, len);
95}
96
97static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk)
98{
99 int rc = 0;
100 if (ccid->ccid_hc_rx_init != NULL)
101 rc = ccid->ccid_hc_rx_init(sk);
102 return rc;
103}
104
105static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk)
106{
107 int rc = 0;
108 if (ccid->ccid_hc_tx_init != NULL)
109 rc = ccid->ccid_hc_tx_init(sk);
110 return rc;
111}
112
113static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk)
114{
Arnaldo Carvalho de Melo777b25a2005-10-10 21:24:20 -0700115 if (ccid != NULL && ccid->ccid_hc_rx_exit != NULL &&
Arnaldo Carvalho de Melo012e13e2005-08-23 21:51:13 -0700116 dccp_sk(sk)->dccps_hc_rx_ccid_private != NULL)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700117 ccid->ccid_hc_rx_exit(sk);
118}
119
120static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk)
121{
Arnaldo Carvalho de Melo777b25a2005-10-10 21:24:20 -0700122 if (ccid != NULL && ccid->ccid_hc_tx_exit != NULL &&
Arnaldo Carvalho de Melo012e13e2005-08-23 21:51:13 -0700123 dccp_sk(sk)->dccps_hc_tx_ccid_private != NULL)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700124 ccid->ccid_hc_tx_exit(sk);
125}
126
127static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
128 struct sk_buff *skb)
129{
130 if (ccid->ccid_hc_rx_packet_recv != NULL)
131 ccid->ccid_hc_rx_packet_recv(sk, skb);
132}
133
134static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
135 struct sk_buff *skb)
136{
137 if (ccid->ccid_hc_tx_packet_recv != NULL)
138 ccid->ccid_hc_tx_packet_recv(sk, skb);
139}
140
141static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
142 unsigned char option,
143 unsigned char len, u16 idx,
144 unsigned char* value)
145{
146 int rc = 0;
147 if (ccid->ccid_hc_tx_parse_options != NULL)
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300148 rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx,
149 value);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700150 return rc;
151}
152
153static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
154 unsigned char option,
155 unsigned char len, u16 idx,
156 unsigned char* value)
157{
158 int rc = 0;
159 if (ccid->ccid_hc_rx_parse_options != NULL)
160 rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value);
161 return rc;
162}
163
164static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk,
165 struct sk_buff *skb)
166{
167 if (ccid->ccid_hc_tx_insert_options != NULL)
168 ccid->ccid_hc_tx_insert_options(sk, skb);
169}
170
171static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
172 struct sk_buff *skb)
173{
174 if (ccid->ccid_hc_rx_insert_options != NULL)
175 ccid->ccid_hc_rx_insert_options(sk, skb);
176}
Arnaldo Carvalho de Melo2babe1f2005-08-23 21:52:35 -0700177
178static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
179 struct tcp_info *info)
180{
181 if (ccid->ccid_hc_rx_get_info != NULL)
182 ccid->ccid_hc_rx_get_info(sk, info);
183}
184
185static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
186 struct tcp_info *info)
187{
188 if (ccid->ccid_hc_tx_get_info != NULL)
189 ccid->ccid_hc_tx_get_info(sk, info);
190}
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -0700191
192static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
193 const int optname, int len,
194 u32 __user *optval, int __user *optlen)
195{
196 int rc = -ENOPROTOOPT;
197 if (ccid->ccid_hc_rx_getsockopt != NULL)
198 rc = ccid->ccid_hc_rx_getsockopt(sk, optname, len,
199 optval, optlen);
200 return rc;
201}
202
203static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
204 const int optname, int len,
205 u32 __user *optval, int __user *optlen)
206{
207 int rc = -ENOPROTOOPT;
208 if (ccid->ccid_hc_tx_getsockopt != NULL)
209 rc = ccid->ccid_hc_tx_getsockopt(sk, optname, len,
210 optval, optlen);
211 return rc;
212}
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700213#endif /* _CCID_H */