[DCCP]: Introduce CCID getsockopt for the CCIDs
[safe/jmp/linux-2.6] / net / dccp / ccid.h
1 #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>
17 #include <linux/compiler.h>
18 #include <linux/dccp.h>
19 #include <linux/list.h>
20 #include <linux/module.h>
21
22 #define CCID_MAX 255
23
24 struct 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);
34         void            (*ccid_hc_rx_packet_recv)(struct sock *sk,
35                                                   struct sk_buff *skb);
36         int             (*ccid_hc_rx_parse_options)(struct sock *sk,
37                                                     unsigned char option,
38                                                     unsigned char len, u16 idx,
39                                                     unsigned char* value);
40         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);
46         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,
51                                                   struct sk_buff *skb, int len);
52         void            (*ccid_hc_tx_packet_sent)(struct sock *sk, int more,
53                                                   int len);
54         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);
58         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);
66 };
67
68 extern int         ccid_register(struct ccid *ccid);
69 extern int         ccid_unregister(struct ccid *ccid);
70
71 extern struct ccid *ccid_init(unsigned char id, struct sock *sk);
72 extern void        ccid_exit(struct ccid *ccid, struct sock *sk);
73
74 static inline void __ccid_get(struct ccid *ccid)
75 {
76         __module_get(ccid->ccid_owner);
77 }
78
79 static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk,
80                                          struct sk_buff *skb, int len)
81 {
82         int rc = 0;
83         if (ccid->ccid_hc_tx_send_packet != NULL)
84                 rc = ccid->ccid_hc_tx_send_packet(sk, skb, len);
85         return rc;
86 }
87
88 static 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
95 static 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
103 static 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
111 static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk)
112 {
113         if (ccid->ccid_hc_rx_exit != NULL &&
114             dccp_sk(sk)->dccps_hc_rx_ccid_private != NULL)
115                 ccid->ccid_hc_rx_exit(sk);
116 }
117
118 static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk)
119 {
120         if (ccid->ccid_hc_tx_exit != NULL &&
121             dccp_sk(sk)->dccps_hc_tx_ccid_private != NULL)
122                 ccid->ccid_hc_tx_exit(sk);
123 }
124
125 static 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
132 static 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
139 static 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)
146                 rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx,
147                                                     value);
148         return rc;
149 }
150
151 static 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
162 static 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
169 static 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 }
175
176 static 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
183 static 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 }
189
190 static 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
201 static 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 }
211 #endif /* _CCID_H */