blob: c65cb2453e43d7836e80ab25059d3993c5d875ce [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 Melo91f0ebf2006-03-20 19:21:44 -080026struct ccid_operations {
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070027 unsigned char ccid_id;
28 const char *ccid_name;
29 struct module *ccid_owner;
Christoph Lametere18b8902006-12-06 20:33:20 -080030 struct kmem_cache *ccid_hc_rx_slab;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080031 __u32 ccid_hc_rx_obj_size;
Christoph Lametere18b8902006-12-06 20:33:20 -080032 struct kmem_cache *ccid_hc_tx_slab;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080033 __u32 ccid_hc_tx_obj_size;
34 int (*ccid_hc_rx_init)(struct ccid *ccid, struct sock *sk);
35 int (*ccid_hc_tx_init)(struct ccid *ccid, struct sock *sk);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070036 void (*ccid_hc_rx_exit)(struct sock *sk);
37 void (*ccid_hc_tx_exit)(struct sock *sk);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030038 void (*ccid_hc_rx_packet_recv)(struct sock *sk,
39 struct sk_buff *skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070040 int (*ccid_hc_rx_parse_options)(struct sock *sk,
41 unsigned char option,
42 unsigned char len, u16 idx,
43 unsigned char* value);
Arnaldo Carvalho de Melo2d0817d2006-03-20 22:32:06 -080044 int (*ccid_hc_rx_insert_options)(struct sock *sk,
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030045 struct sk_buff *skb);
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -030046 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,
Gerrit Renker6b57c932006-11-28 19:55:06 -020053 struct sk_buff *skb);
54 void (*ccid_hc_tx_packet_sent)(struct sock *sk,
55 int more, unsigned 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
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080070extern int ccid_register(struct ccid_operations *ccid_ops);
71extern int ccid_unregister(struct ccid_operations *ccid_ops);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070072
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080073struct ccid {
74 struct ccid_operations *ccid_ops;
75 char ccid_priv[0];
76};
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070077
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080078static inline void *ccid_priv(const struct ccid *ccid)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070079{
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080080 return (void *)ccid->ccid_priv;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070081}
82
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080083extern struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx,
84 gfp_t gfp);
85
86extern struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk,
87 gfp_t gfp);
88extern struct ccid *ccid_hc_tx_new(unsigned char id, struct sock *sk,
89 gfp_t gfp);
90
91extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk);
92extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk);
93
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070094static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
Gerrit Renker6b57c932006-11-28 19:55:06 -020095 struct sk_buff *skb)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -070096{
97 int rc = 0;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -080098 if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL)
Gerrit Renker6b57c932006-11-28 19:55:06 -020099 rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700100 return rc;
101}
102
103static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk,
Gerrit Renker6b57c932006-11-28 19:55:06 -0200104 int more, unsigned int len)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700105{
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800106 if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL)
107 ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700108}
109
110static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk,
111 struct sk_buff *skb)
112{
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800113 if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL)
114 ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700115}
116
117static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk,
118 struct sk_buff *skb)
119{
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800120 if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL)
121 ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700122}
123
124static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk,
125 unsigned char option,
126 unsigned char len, u16 idx,
127 unsigned char* value)
128{
129 int rc = 0;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800130 if (ccid->ccid_ops->ccid_hc_tx_parse_options != NULL)
131 rc = ccid->ccid_ops->ccid_hc_tx_parse_options(sk, option, len, idx,
Arnaldo Carvalho de Melo7690af32005-08-13 20:34:54 -0300132 value);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700133 return rc;
134}
135
136static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk,
137 unsigned char option,
138 unsigned char len, u16 idx,
139 unsigned char* value)
140{
141 int rc = 0;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800142 if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL)
143 rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value);
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700144 return rc;
145}
146
Arnaldo Carvalho de Melo2d0817d2006-03-20 22:32:06 -0800147static inline int ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk,
148 struct sk_buff *skb)
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700149{
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800150 if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL)
Arnaldo Carvalho de Melo2d0817d2006-03-20 22:32:06 -0800151 return ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb);
152 return 0;
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700153}
Arnaldo Carvalho de Melo2babe1f2005-08-23 21:52:35 -0700154
155static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk,
156 struct tcp_info *info)
157{
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800158 if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL)
159 ccid->ccid_ops->ccid_hc_rx_get_info(sk, info);
Arnaldo Carvalho de Melo2babe1f2005-08-23 21:52:35 -0700160}
161
162static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk,
163 struct tcp_info *info)
164{
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800165 if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL)
166 ccid->ccid_ops->ccid_hc_tx_get_info(sk, info);
Arnaldo Carvalho de Melo2babe1f2005-08-23 21:52:35 -0700167}
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -0700168
169static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk,
170 const int optname, int len,
171 u32 __user *optval, int __user *optlen)
172{
173 int rc = -ENOPROTOOPT;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800174 if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL)
175 rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len,
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -0700176 optval, optlen);
177 return rc;
178}
179
180static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk,
181 const int optname, int len,
182 u32 __user *optval, int __user *optlen)
183{
184 int rc = -ENOPROTOOPT;
Arnaldo Carvalho de Melo91f0ebf2006-03-20 19:21:44 -0800185 if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL)
186 rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len,
Arnaldo Carvalho de Melo88f964d2005-09-18 00:19:32 -0700187 optval, optlen);
188 return rc;
189}
Arnaldo Carvalho de Melo7c657872005-08-09 20:14:34 -0700190#endif /* _CCID_H */