blob: c37eeeaf5c6e21982c341391d8d8db1a9929bdb9 [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
24struct ccid {
25 unsigned char ccid_id;
26 const char *ccid_name;
27 struct module *ccid_owner;
28 int (*ccid_init)(struct sock *sk);
29 void (*ccid_exit)(struct sock *sk);
30 int (*ccid_hc_rx_init)(struct sock *sk);
31 int (*ccid_hc_tx_init)(struct sock *sk);
32 void (*ccid_hc_rx_exit)(struct sock *sk);
33 void (*ccid_hc_tx_exit)(struct sock *sk);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030034 void (*ccid_hc_rx_packet_recv)(struct sock *sk,
35 struct sk_buff *skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070036 int (*ccid_hc_rx_parse_options)(struct sock *sk,
37 unsigned char option,
38 unsigned char len, u16 idx,
39 unsigned char* value);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030040 void (*ccid_hc_rx_insert_options)(struct sock *sk,
41 struct sk_buff *skb);
42 void (*ccid_hc_tx_insert_options)(struct sock *sk,
43 struct sk_buff *skb);
44 void (*ccid_hc_tx_packet_recv)(struct sock *sk,
45 struct sk_buff *skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070046 int (*ccid_hc_tx_parse_options)(struct sock *sk,
47 unsigned char option,
48 unsigned char len, u16 idx,
49 unsigned char* value);
50 int (*ccid_hc_tx_send_packet)(struct sock *sk,
Arnaldo Carvalho de Melo27258ee2005-08-09 20:30:56 -070051 struct sk_buff *skb, int len);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030052 void (*ccid_hc_tx_packet_sent)(struct sock *sk, int more,
53 int len);
Arnaldo Carvalho de Melo2babe1f2005-08-23 21:52:35 -070054 void (*ccid_hc_rx_get_info)(struct sock *sk,
55 struct tcp_info *info);
56 void (*ccid_hc_tx_get_info)(struct sock *sk,
57 struct tcp_info *info);
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -070058 int (*ccid_hc_rx_getsockopt)(struct sock *sk,
59 const int optname, int len,
60 u32 __user *optval,
61 int __user *optlen);
62 int (*ccid_hc_tx_getsockopt)(struct sock *sk,
63 const int optname, int len,
64 u32 __user *optval,
65 int __user *optlen);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070066};
67
68extern int ccid_register(struct ccid *ccid);
69extern int ccid_unregister(struct ccid *ccid);
70
71extern struct ccid *ccid_init(unsigned char id, struct sock *sk);
72extern void ccid_exit(struct ccid *ccid, struct sock *sk);
73
74static inline void __ccid_get(struct ccid *ccid)
75{
76 __module_get(ccid->ccid_owner);
77}
78
79static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
Arnaldo Carvalho de Melo27258ee2005-08-09 20:30:56 -070080 struct sk_buff *skb, int len)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070081{
82 int rc = 0;
83 if (ccid->ccid_hc_tx_send_packet != NULL)
Arnaldo Carvalho de Melo27258ee2005-08-09 20:30:56 -070084 rc = ccid->ccid_hc_tx_send_packet(sk, skb, len);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070085 return rc;
86}
87
88static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
89 int more, int len)
90{
91 if (ccid->ccid_hc_tx_packet_sent != NULL)
92 ccid->ccid_hc_tx_packet_sent(sk, more, len);
93}
94
95static inline int ccid_hc_rx_init(struct ccid *ccid, struct sock *sk)
96{
97 int rc = 0;
98 if (ccid->ccid_hc_rx_init != NULL)
99 rc = ccid->ccid_hc_rx_init(sk);
100 return rc;
101}
102
103static inline int ccid_hc_tx_init(struct ccid *ccid, struct sock *sk)
104{
105 int rc = 0;
106 if (ccid->ccid_hc_tx_init != NULL)
107 rc = ccid->ccid_hc_tx_init(sk);
108 return rc;
109}
110
111static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk)
112{
Arnaldo Carvalho de Melo777b25a2005-10-10 21:24:20 -0700113 if (ccid != NULL && ccid->ccid_hc_rx_exit != NULL &&
Arnaldo Carvalho de Melo012e13e2005-08-23 21:51:13 -0700114 dccp_sk(sk)->dccps_hc_rx_ccid_private != NULL)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700115 ccid->ccid_hc_rx_exit(sk);
116}
117
118static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk)
119{
Arnaldo Carvalho de Melo777b25a2005-10-10 21:24:20 -0700120 if (ccid != NULL && ccid->ccid_hc_tx_exit != NULL &&
Arnaldo Carvalho de Melo012e13e2005-08-23 21:51:13 -0700121 dccp_sk(sk)->dccps_hc_tx_ccid_private != NULL)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700122 ccid->ccid_hc_tx_exit(sk);
123}
124
125static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
126 struct sk_buff *skb)
127{
128 if (ccid->ccid_hc_rx_packet_recv != NULL)
129 ccid->ccid_hc_rx_packet_recv(sk, skb);
130}
131
132static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
133 struct sk_buff *skb)
134{
135 if (ccid->ccid_hc_tx_packet_recv != NULL)
136 ccid->ccid_hc_tx_packet_recv(sk, skb);
137}
138
139static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
140 unsigned char option,
141 unsigned char len, u16 idx,
142 unsigned char* value)
143{
144 int rc = 0;
145 if (ccid->ccid_hc_tx_parse_options != NULL)
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300146 rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx,
147 value);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700148 return rc;
149}
150
151static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
152 unsigned char option,
153 unsigned char len, u16 idx,
154 unsigned char* value)
155{
156 int rc = 0;
157 if (ccid->ccid_hc_rx_parse_options != NULL)
158 rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value);
159 return rc;
160}
161
162static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk,
163 struct sk_buff *skb)
164{
165 if (ccid->ccid_hc_tx_insert_options != NULL)
166 ccid->ccid_hc_tx_insert_options(sk, skb);
167}
168
169static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
170 struct sk_buff *skb)
171{
172 if (ccid->ccid_hc_rx_insert_options != NULL)
173 ccid->ccid_hc_rx_insert_options(sk, skb);
174}
Arnaldo Carvalho de Melo2babe1f2005-08-23 21:52:35 -0700175
176static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
177 struct tcp_info *info)
178{
179 if (ccid->ccid_hc_rx_get_info != NULL)
180 ccid->ccid_hc_rx_get_info(sk, info);
181}
182
183static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
184 struct tcp_info *info)
185{
186 if (ccid->ccid_hc_tx_get_info != NULL)
187 ccid->ccid_hc_tx_get_info(sk, info);
188}
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -0700189
190static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
191 const int optname, int len,
192 u32 __user *optval, int __user *optlen)
193{
194 int rc = -ENOPROTOOPT;
195 if (ccid->ccid_hc_rx_getsockopt != NULL)
196 rc = ccid->ccid_hc_rx_getsockopt(sk, optname, len,
197 optval, optlen);
198 return rc;
199}
200
201static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
202 const int optname, int len,
203 u32 __user *optval, int __user *optlen)
204{
205 int rc = -ENOPROTOOPT;
206 if (ccid->ccid_hc_tx_getsockopt != NULL)
207 rc = ccid->ccid_hc_tx_getsockopt(sk, optname, len,
208 optval, optlen);
209 return rc;
210}
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700211#endif /* _CCID_H */