]> err.no Git - linux-2.6/blob - include/net/inet_connection_sock.h
[Bluetooth]: Fix sparse warnings (__nocast type)
[linux-2.6] / include / net / inet_connection_sock.h
1 /*
2  * NET          Generic infrastructure for INET connection oriented protocols.
3  *
4  *              Definitions for inet_connection_sock 
5  *
6  * Authors:     Many people, see the TCP sources
7  *
8  *              From code originally in TCP
9  *
10  *              This program is free software; you can redistribute it and/or
11  *              modify it under the terms of the GNU General Public License
12  *              as published by the Free Software Foundation; either version
13  *              2 of the License, or (at your option) any later version.
14  */
15 #ifndef _INET_CONNECTION_SOCK_H
16 #define _INET_CONNECTION_SOCK_H
17
18 #include <linux/ip.h>
19 #include <linux/string.h>
20 #include <linux/timer.h>
21 #include <net/request_sock.h>
22
23 #define INET_CSK_DEBUG 1
24
25 /* Cancel timers, when they are not required. */
26 #undef INET_CSK_CLEAR_TIMERS
27
28 struct inet_bind_bucket;
29 struct inet_hashinfo;
30
31 /** inet_connection_sock - INET connection oriented sock
32  *
33  * @icsk_accept_queue:     FIFO of established children 
34  * @icsk_bind_hash:        Bind node
35  * @icsk_timeout:          Timeout
36  * @icsk_retransmit_timer: Resend (no ack)
37  * @icsk_rto:              Retransmit timeout
38  * @icsk_retransmits:      Number of unrecovered [RTO] timeouts
39  * @icsk_pending:          Scheduled timer event
40  * @icsk_backoff:          Backoff
41  * @icsk_syn_retries:      Number of allowed SYN (or equivalent) retries
42  * @icsk_ack:              Delayed ACK control data
43  */
44 struct inet_connection_sock {
45         /* inet_sock has to be the first member! */
46         struct inet_sock          icsk_inet;
47         struct request_sock_queue icsk_accept_queue;
48         struct inet_bind_bucket   *icsk_bind_hash;
49         unsigned long             icsk_timeout;
50         struct timer_list         icsk_retransmit_timer;
51         struct timer_list         icsk_delack_timer;
52         __u32                     icsk_rto;
53         __u8                      icsk_retransmits;
54         __u8                      icsk_pending;
55         __u8                      icsk_backoff;
56         __u8                      icsk_syn_retries;
57         struct {
58                 __u8              pending;       /* ACK is pending                         */
59                 __u8              quick;         /* Scheduled number of quick acks         */
60                 __u8              pingpong;      /* The session is interactive             */
61                 __u8              blocked;       /* Delayed ACK was blocked by socket lock */
62                 __u32             ato;           /* Predicted tick of soft clock           */
63                 unsigned long     timeout;       /* Currently scheduled timeout            */
64                 __u32             lrcvtime;      /* timestamp of last received data packet */
65                 __u16             last_seg_size; /* Size of last incoming segment          */
66                 __u16             rcv_mss;       /* MSS used for delayed ACK decisions     */ 
67         } icsk_ack;
68 };
69
70 #define ICSK_TIME_RETRANS       1       /* Retransmit timer */
71 #define ICSK_TIME_DACK          2       /* Delayed ack timer */
72 #define ICSK_TIME_PROBE0        3       /* Zero window probe timer */
73 #define ICSK_TIME_KEEPOPEN      4       /* Keepalive timer */
74
75 static inline struct inet_connection_sock *inet_csk(const struct sock *sk)
76 {
77         return (struct inet_connection_sock *)sk;
78 }
79
80 extern struct sock *inet_csk_clone(struct sock *sk,
81                                    const struct request_sock *req,
82                                    const unsigned int __nocast priority);
83
84 enum inet_csk_ack_state_t {
85         ICSK_ACK_SCHED  = 1,
86         ICSK_ACK_TIMER  = 2,
87         ICSK_ACK_PUSHED = 4
88 };
89
90 extern void inet_csk_init_xmit_timers(struct sock *sk,
91                                       void (*retransmit_handler)(unsigned long),
92                                       void (*delack_handler)(unsigned long),
93                                       void (*keepalive_handler)(unsigned long));
94 extern void inet_csk_clear_xmit_timers(struct sock *sk);
95
96 static inline void inet_csk_schedule_ack(struct sock *sk)
97 {
98         inet_csk(sk)->icsk_ack.pending |= ICSK_ACK_SCHED;
99 }
100
101 static inline int inet_csk_ack_scheduled(const struct sock *sk)
102 {
103         return inet_csk(sk)->icsk_ack.pending & ICSK_ACK_SCHED;
104 }
105
106 static inline void inet_csk_delack_init(struct sock *sk)
107 {
108         memset(&inet_csk(sk)->icsk_ack, 0, sizeof(inet_csk(sk)->icsk_ack));
109 }
110
111 extern void inet_csk_delete_keepalive_timer(struct sock *sk);
112 extern void inet_csk_reset_keepalive_timer(struct sock *sk, unsigned long timeout);
113
114 #ifdef INET_CSK_DEBUG
115 extern const char inet_csk_timer_bug_msg[];
116 #endif
117
118 static inline void inet_csk_clear_xmit_timer(struct sock *sk, const int what)
119 {
120         struct inet_connection_sock *icsk = inet_csk(sk);
121         
122         if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
123                 icsk->icsk_pending = 0;
124 #ifdef INET_CSK_CLEAR_TIMERS
125                 sk_stop_timer(sk, &icsk->icsk_retransmit_timer);
126 #endif
127         } else if (what == ICSK_TIME_DACK) {
128                 icsk->icsk_ack.blocked = icsk->icsk_ack.pending = 0;
129 #ifdef INET_CSK_CLEAR_TIMERS
130                 sk_stop_timer(sk, &icsk->icsk_delack_timer);
131 #endif
132         }
133 #ifdef INET_CSK_DEBUG
134         else {
135                 pr_debug(inet_csk_timer_bug_msg);
136         }
137 #endif
138 }
139
140 /*
141  *      Reset the retransmission timer
142  */
143 static inline void inet_csk_reset_xmit_timer(struct sock *sk, const int what,
144                                              unsigned long when,
145                                              const unsigned long max_when)
146 {
147         struct inet_connection_sock *icsk = inet_csk(sk);
148
149         if (when > max_when) {
150 #ifdef INET_CSK_DEBUG
151                 pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
152                          sk, what, when, current_text_addr());
153 #endif
154                 when = max_when;
155         }
156
157         if (what == ICSK_TIME_RETRANS || what == ICSK_TIME_PROBE0) {
158                 icsk->icsk_pending = what;
159                 icsk->icsk_timeout = jiffies + when;
160                 sk_reset_timer(sk, &icsk->icsk_retransmit_timer, icsk->icsk_timeout);
161         } else if (what == ICSK_TIME_DACK) {
162                 icsk->icsk_ack.pending |= ICSK_ACK_TIMER;
163                 icsk->icsk_ack.timeout = jiffies + when;
164                 sk_reset_timer(sk, &icsk->icsk_delack_timer, icsk->icsk_ack.timeout);
165         }
166 #ifdef INET_CSK_DEBUG
167         else {
168                 pr_debug(inet_csk_timer_bug_msg);
169         }
170 #endif
171 }
172
173 extern struct sock *inet_csk_accept(struct sock *sk, int flags, int *err);
174
175 extern struct request_sock *inet_csk_search_req(const struct sock *sk,
176                                                 struct request_sock ***prevp,
177                                                 const __u16 rport,
178                                                 const __u32 raddr,
179                                                 const __u32 laddr);
180 extern int inet_csk_get_port(struct inet_hashinfo *hashinfo,
181                              struct sock *sk, unsigned short snum);
182
183 extern struct dst_entry* inet_csk_route_req(struct sock *sk,
184                                             const struct request_sock *req);
185
186 static inline void inet_csk_reqsk_queue_add(struct sock *sk,
187                                             struct request_sock *req,
188                                             struct sock *child)
189 {
190         reqsk_queue_add(&inet_csk(sk)->icsk_accept_queue, req, sk, child);
191 }
192
193 extern void inet_csk_reqsk_queue_hash_add(struct sock *sk,
194                                           struct request_sock *req,
195                                           const unsigned timeout);
196
197 static inline void inet_csk_reqsk_queue_removed(struct sock *sk,
198                                                 struct request_sock *req)
199 {
200         if (reqsk_queue_removed(&inet_csk(sk)->icsk_accept_queue, req) == 0)
201                 inet_csk_delete_keepalive_timer(sk);
202 }
203
204 static inline void inet_csk_reqsk_queue_added(struct sock *sk,
205                                               const unsigned long timeout)
206 {
207         if (reqsk_queue_added(&inet_csk(sk)->icsk_accept_queue) == 0)
208                 inet_csk_reset_keepalive_timer(sk, timeout);
209 }
210
211 static inline int inet_csk_reqsk_queue_len(const struct sock *sk)
212 {
213         return reqsk_queue_len(&inet_csk(sk)->icsk_accept_queue);
214 }
215
216 static inline int inet_csk_reqsk_queue_young(const struct sock *sk)
217 {
218         return reqsk_queue_len_young(&inet_csk(sk)->icsk_accept_queue);
219 }
220
221 static inline int inet_csk_reqsk_queue_is_full(const struct sock *sk)
222 {
223         return reqsk_queue_is_full(&inet_csk(sk)->icsk_accept_queue);
224 }
225
226 static inline void inet_csk_reqsk_queue_unlink(struct sock *sk,
227                                                struct request_sock *req,
228                                                struct request_sock **prev)
229 {
230         reqsk_queue_unlink(&inet_csk(sk)->icsk_accept_queue, req, prev);
231 }
232
233 static inline void inet_csk_reqsk_queue_drop(struct sock *sk,
234                                              struct request_sock *req,
235                                              struct request_sock **prev)
236 {
237         inet_csk_reqsk_queue_unlink(sk, req, prev);
238         inet_csk_reqsk_queue_removed(sk, req);
239         reqsk_free(req);
240 }
241
242 extern void inet_csk_reqsk_queue_prune(struct sock *parent,
243                                        const unsigned long interval,
244                                        const unsigned long timeout,
245                                        const unsigned long max_rto);
246
247 extern void inet_csk_destroy_sock(struct sock *sk);
248 extern int  inet_csk_listen_start(struct sock *sk, const int nr_table_entries);
249 extern void inet_csk_listen_stop(struct sock *sk);
250
251 #endif /* _INET_CONNECTION_SOCK_H */