diff options
author | Arnaldo Carvalho de Melo <acme@mandriva.com> | 2006-03-20 22:21:44 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2006-03-20 22:21:44 -0500 |
commit | 91f0ebf7b6d5cb2b6e818d48587566144821babe (patch) | |
tree | 505c66f36bd72014d7eacb7a04ea011bae2e9a3a /net/dccp/ccid.h | |
parent | f38c39d6ce8226519455a6dfe91c2ad84f363f6f (diff) |
[DCCP] CCID: Improve CCID infrastructure
1. No need for ->ccid_init nor ->ccid_exit, this is what module_{init,exit}
does and anynways neither ccid2 nor ccid3 were using it.
2. Rename struct ccid to struct ccid_operations and introduce struct ccid
with a pointer to ccid_operations and rigth after it the rx or tx
private state.
3. Remove the pointer to the state of the half connections from struct
dccp_sock, now its derived thru ccid_priv() from the ccid pointer.
Now we also can implement the setsockopt for changing the CCID easily as
no ccid init routines can affect struct dccp_sock in any way that prevents
other CCIDs from working if a CCID switch operation is asked by apps.
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/dccp/ccid.h')
-rw-r--r-- | net/dccp/ccid.h | 115 |
1 files changed, 50 insertions, 65 deletions
diff --git a/net/dccp/ccid.h b/net/dccp/ccid.h index de681c6ad081..3dec50d49731 100644 --- a/net/dccp/ccid.h +++ b/net/dccp/ccid.h | |||
@@ -23,14 +23,16 @@ | |||
23 | 23 | ||
24 | struct tcp_info; | 24 | struct tcp_info; |
25 | 25 | ||
26 | struct ccid { | 26 | struct ccid_operations { |
27 | unsigned char ccid_id; | 27 | unsigned char ccid_id; |
28 | const char *ccid_name; | 28 | const char *ccid_name; |
29 | struct module *ccid_owner; | 29 | struct module *ccid_owner; |
30 | int (*ccid_init)(struct sock *sk); | 30 | kmem_cache_t *ccid_hc_rx_slab; |
31 | void (*ccid_exit)(struct sock *sk); | 31 | __u32 ccid_hc_rx_obj_size; |
32 | int (*ccid_hc_rx_init)(struct sock *sk); | 32 | kmem_cache_t *ccid_hc_tx_slab; |
33 | int (*ccid_hc_tx_init)(struct sock *sk); | 33 | __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); | ||
34 | void (*ccid_hc_rx_exit)(struct sock *sk); | 36 | void (*ccid_hc_rx_exit)(struct sock *sk); |
35 | void (*ccid_hc_tx_exit)(struct sock *sk); | 37 | void (*ccid_hc_tx_exit)(struct sock *sk); |
36 | void (*ccid_hc_rx_packet_recv)(struct sock *sk, | 38 | void (*ccid_hc_rx_packet_recv)(struct sock *sk, |
@@ -67,75 +69,58 @@ struct ccid { | |||
67 | int __user *optlen); | 69 | int __user *optlen); |
68 | }; | 70 | }; |
69 | 71 | ||
70 | extern int ccid_register(struct ccid *ccid); | 72 | extern int ccid_register(struct ccid_operations *ccid_ops); |
71 | extern int ccid_unregister(struct ccid *ccid); | 73 | extern int ccid_unregister(struct ccid_operations *ccid_ops); |
72 | 74 | ||
73 | extern struct ccid *ccid_init(unsigned char id, struct sock *sk); | 75 | struct ccid { |
74 | extern void ccid_exit(struct ccid *ccid, struct sock *sk); | 76 | struct ccid_operations *ccid_ops; |
77 | char ccid_priv[0]; | ||
78 | }; | ||
75 | 79 | ||
76 | static inline void __ccid_get(struct ccid *ccid) | 80 | static inline void *ccid_priv(const struct ccid *ccid) |
77 | { | 81 | { |
78 | __module_get(ccid->ccid_owner); | 82 | return (void *)ccid->ccid_priv; |
79 | } | 83 | } |
80 | 84 | ||
85 | extern struct ccid *ccid_new(unsigned char id, struct sock *sk, int rx, | ||
86 | gfp_t gfp); | ||
87 | |||
88 | extern struct ccid *ccid_hc_rx_new(unsigned char id, struct sock *sk, | ||
89 | gfp_t gfp); | ||
90 | extern struct ccid *ccid_hc_tx_new(unsigned char id, struct sock *sk, | ||
91 | gfp_t gfp); | ||
92 | |||
93 | extern void ccid_hc_rx_delete(struct ccid *ccid, struct sock *sk); | ||
94 | extern void ccid_hc_tx_delete(struct ccid *ccid, struct sock *sk); | ||
95 | |||
81 | static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, | 96 | static inline int ccid_hc_tx_send_packet(struct ccid *ccid, struct sock *sk, |
82 | struct sk_buff *skb, int len) | 97 | struct sk_buff *skb, int len) |
83 | { | 98 | { |
84 | int rc = 0; | 99 | int rc = 0; |
85 | if (ccid->ccid_hc_tx_send_packet != NULL) | 100 | if (ccid->ccid_ops->ccid_hc_tx_send_packet != NULL) |
86 | rc = ccid->ccid_hc_tx_send_packet(sk, skb, len); | 101 | rc = ccid->ccid_ops->ccid_hc_tx_send_packet(sk, skb, len); |
87 | return rc; | 102 | return rc; |
88 | } | 103 | } |
89 | 104 | ||
90 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, | 105 | static inline void ccid_hc_tx_packet_sent(struct ccid *ccid, struct sock *sk, |
91 | int more, int len) | 106 | int more, int len) |
92 | { | 107 | { |
93 | if (ccid->ccid_hc_tx_packet_sent != NULL) | 108 | if (ccid->ccid_ops->ccid_hc_tx_packet_sent != NULL) |
94 | ccid->ccid_hc_tx_packet_sent(sk, more, len); | 109 | ccid->ccid_ops->ccid_hc_tx_packet_sent(sk, more, len); |
95 | } | ||
96 | |||
97 | static 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 | |||
105 | static 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 | |||
113 | static inline void ccid_hc_rx_exit(struct ccid *ccid, struct sock *sk) | ||
114 | { | ||
115 | if (ccid != NULL && ccid->ccid_hc_rx_exit != NULL && | ||
116 | dccp_sk(sk)->dccps_hc_rx_ccid_private != NULL) | ||
117 | ccid->ccid_hc_rx_exit(sk); | ||
118 | } | ||
119 | |||
120 | static inline void ccid_hc_tx_exit(struct ccid *ccid, struct sock *sk) | ||
121 | { | ||
122 | if (ccid != NULL && ccid->ccid_hc_tx_exit != NULL && | ||
123 | dccp_sk(sk)->dccps_hc_tx_ccid_private != NULL) | ||
124 | ccid->ccid_hc_tx_exit(sk); | ||
125 | } | 110 | } |
126 | 111 | ||
127 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, | 112 | static inline void ccid_hc_rx_packet_recv(struct ccid *ccid, struct sock *sk, |
128 | struct sk_buff *skb) | 113 | struct sk_buff *skb) |
129 | { | 114 | { |
130 | if (ccid->ccid_hc_rx_packet_recv != NULL) | 115 | if (ccid->ccid_ops->ccid_hc_rx_packet_recv != NULL) |
131 | ccid->ccid_hc_rx_packet_recv(sk, skb); | 116 | ccid->ccid_ops->ccid_hc_rx_packet_recv(sk, skb); |
132 | } | 117 | } |
133 | 118 | ||
134 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, | 119 | static inline void ccid_hc_tx_packet_recv(struct ccid *ccid, struct sock *sk, |
135 | struct sk_buff *skb) | 120 | struct sk_buff *skb) |
136 | { | 121 | { |
137 | if (ccid->ccid_hc_tx_packet_recv != NULL) | 122 | if (ccid->ccid_ops->ccid_hc_tx_packet_recv != NULL) |
138 | ccid->ccid_hc_tx_packet_recv(sk, skb); | 123 | ccid->ccid_ops->ccid_hc_tx_packet_recv(sk, skb); |
139 | } | 124 | } |
140 | 125 | ||
141 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, | 126 | static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, |
@@ -144,8 +129,8 @@ static inline int ccid_hc_tx_parse_options(struct ccid *ccid, struct sock *sk, | |||
144 | unsigned char* value) | 129 | unsigned char* value) |
145 | { | 130 | { |
146 | int rc = 0; | 131 | int rc = 0; |
147 | if (ccid->ccid_hc_tx_parse_options != NULL) | 132 | if (ccid->ccid_ops->ccid_hc_tx_parse_options != NULL) |
148 | rc = ccid->ccid_hc_tx_parse_options(sk, option, len, idx, | 133 | rc = ccid->ccid_ops->ccid_hc_tx_parse_options(sk, option, len, idx, |
149 | value); | 134 | value); |
150 | return rc; | 135 | return rc; |
151 | } | 136 | } |
@@ -156,37 +141,37 @@ static inline int ccid_hc_rx_parse_options(struct ccid *ccid, struct sock *sk, | |||
156 | unsigned char* value) | 141 | unsigned char* value) |
157 | { | 142 | { |
158 | int rc = 0; | 143 | int rc = 0; |
159 | if (ccid->ccid_hc_rx_parse_options != NULL) | 144 | if (ccid->ccid_ops->ccid_hc_rx_parse_options != NULL) |
160 | rc = ccid->ccid_hc_rx_parse_options(sk, option, len, idx, value); | 145 | rc = ccid->ccid_ops->ccid_hc_rx_parse_options(sk, option, len, idx, value); |
161 | return rc; | 146 | return rc; |
162 | } | 147 | } |
163 | 148 | ||
164 | static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, | 149 | static inline void ccid_hc_tx_insert_options(struct ccid *ccid, struct sock *sk, |
165 | struct sk_buff *skb) | 150 | struct sk_buff *skb) |
166 | { | 151 | { |
167 | if (ccid->ccid_hc_tx_insert_options != NULL) | 152 | if (ccid->ccid_ops->ccid_hc_tx_insert_options != NULL) |
168 | ccid->ccid_hc_tx_insert_options(sk, skb); | 153 | ccid->ccid_ops->ccid_hc_tx_insert_options(sk, skb); |
169 | } | 154 | } |
170 | 155 | ||
171 | static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, | 156 | static inline void ccid_hc_rx_insert_options(struct ccid *ccid, struct sock *sk, |
172 | struct sk_buff *skb) | 157 | struct sk_buff *skb) |
173 | { | 158 | { |
174 | if (ccid->ccid_hc_rx_insert_options != NULL) | 159 | if (ccid->ccid_ops->ccid_hc_rx_insert_options != NULL) |
175 | ccid->ccid_hc_rx_insert_options(sk, skb); | 160 | ccid->ccid_ops->ccid_hc_rx_insert_options(sk, skb); |
176 | } | 161 | } |
177 | 162 | ||
178 | static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk, | 163 | static inline void ccid_hc_rx_get_info(struct ccid *ccid, struct sock *sk, |
179 | struct tcp_info *info) | 164 | struct tcp_info *info) |
180 | { | 165 | { |
181 | if (ccid->ccid_hc_rx_get_info != NULL) | 166 | if (ccid->ccid_ops->ccid_hc_rx_get_info != NULL) |
182 | ccid->ccid_hc_rx_get_info(sk, info); | 167 | ccid->ccid_ops->ccid_hc_rx_get_info(sk, info); |
183 | } | 168 | } |
184 | 169 | ||
185 | static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk, | 170 | static inline void ccid_hc_tx_get_info(struct ccid *ccid, struct sock *sk, |
186 | struct tcp_info *info) | 171 | struct tcp_info *info) |
187 | { | 172 | { |
188 | if (ccid->ccid_hc_tx_get_info != NULL) | 173 | if (ccid->ccid_ops->ccid_hc_tx_get_info != NULL) |
189 | ccid->ccid_hc_tx_get_info(sk, info); | 174 | ccid->ccid_ops->ccid_hc_tx_get_info(sk, info); |
190 | } | 175 | } |
191 | 176 | ||
192 | static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, | 177 | static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, |
@@ -194,8 +179,8 @@ static inline int ccid_hc_rx_getsockopt(struct ccid *ccid, struct sock *sk, | |||
194 | u32 __user *optval, int __user *optlen) | 179 | u32 __user *optval, int __user *optlen) |
195 | { | 180 | { |
196 | int rc = -ENOPROTOOPT; | 181 | int rc = -ENOPROTOOPT; |
197 | if (ccid->ccid_hc_rx_getsockopt != NULL) | 182 | if (ccid->ccid_ops->ccid_hc_rx_getsockopt != NULL) |
198 | rc = ccid->ccid_hc_rx_getsockopt(sk, optname, len, | 183 | rc = ccid->ccid_ops->ccid_hc_rx_getsockopt(sk, optname, len, |
199 | optval, optlen); | 184 | optval, optlen); |
200 | return rc; | 185 | return rc; |
201 | } | 186 | } |
@@ -205,8 +190,8 @@ static inline int ccid_hc_tx_getsockopt(struct ccid *ccid, struct sock *sk, | |||
205 | u32 __user *optval, int __user *optlen) | 190 | u32 __user *optval, int __user *optlen) |
206 | { | 191 | { |
207 | int rc = -ENOPROTOOPT; | 192 | int rc = -ENOPROTOOPT; |
208 | if (ccid->ccid_hc_tx_getsockopt != NULL) | 193 | if (ccid->ccid_ops->ccid_hc_tx_getsockopt != NULL) |
209 | rc = ccid->ccid_hc_tx_getsockopt(sk, optname, len, | 194 | rc = ccid->ccid_ops->ccid_hc_tx_getsockopt(sk, optname, len, |
210 | optval, optlen); | 195 | optval, optlen); |
211 | return rc; | 196 | return rc; |
212 | } | 197 | } |