2 * NET Generic infrastructure for INET connection oriented protocols.
4 * Definitions for inet_connection_sock
6 * Authors: Many people, see the TCP sources
8 * From code originally in TCP
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.
15 #ifndef _INET_CONNECTION_SOCK_H
16 #define _INET_CONNECTION_SOCK_H
19 #include <linux/string.h>
20 #include <linux/timer.h>
21 #include <net/request_sock.h>
23 #define INET_CSK_DEBUG 1
25 /* Cancel timers, when they are not required. */
26 #undef INET_CSK_CLEAR_TIMERS
28 struct inet_bind_bucket
;
31 /** inet_connection_sock - INET connection oriented sock
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
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
;
53 __u8 icsk_retransmits
;
56 __u8 icsk_syn_retries
;
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 */
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 */
75 static inline struct inet_connection_sock
*inet_csk(const struct sock
*sk
)
77 return (struct inet_connection_sock
*)sk
;
80 enum inet_csk_ack_state_t
{
86 extern void inet_csk_init_xmit_timers(struct sock
*sk
,
87 void (*retransmit_handler
)(unsigned long),
88 void (*delack_handler
)(unsigned long),
89 void (*keepalive_handler
)(unsigned long));
90 extern void inet_csk_clear_xmit_timers(struct sock
*sk
);
92 static inline void inet_csk_schedule_ack(struct sock
*sk
)
94 inet_csk(sk
)->icsk_ack
.pending
|= ICSK_ACK_SCHED
;
97 static inline int inet_csk_ack_scheduled(const struct sock
*sk
)
99 return inet_csk(sk
)->icsk_ack
.pending
& ICSK_ACK_SCHED
;
102 static inline void inet_csk_delack_init(struct sock
*sk
)
104 memset(&inet_csk(sk
)->icsk_ack
, 0, sizeof(inet_csk(sk
)->icsk_ack
));
107 extern void inet_csk_delete_keepalive_timer(struct sock
*sk
);
108 extern void inet_csk_reset_keepalive_timer(struct sock
*sk
, unsigned long timeout
);
110 #ifdef INET_CSK_DEBUG
111 extern const char inet_csk_timer_bug_msg
[];
114 static inline void inet_csk_clear_xmit_timer(struct sock
*sk
, const int what
)
116 struct inet_connection_sock
*icsk
= inet_csk(sk
);
118 if (what
== ICSK_TIME_RETRANS
|| what
== ICSK_TIME_PROBE0
) {
119 icsk
->icsk_pending
= 0;
120 #ifdef INET_CSK_CLEAR_TIMERS
121 sk_stop_timer(sk
, &icsk
->icsk_retransmit_timer
);
123 } else if (what
== ICSK_TIME_DACK
) {
124 icsk
->icsk_ack
.blocked
= icsk
->icsk_ack
.pending
= 0;
125 #ifdef INET_CSK_CLEAR_TIMERS
126 sk_stop_timer(sk
, &icsk
->icsk_delack_timer
);
129 #ifdef INET_CSK_DEBUG
131 pr_debug(inet_csk_timer_bug_msg
);
137 * Reset the retransmission timer
139 static inline void inet_csk_reset_xmit_timer(struct sock
*sk
, const int what
,
141 const unsigned long max_when
)
143 struct inet_connection_sock
*icsk
= inet_csk(sk
);
145 if (when
> max_when
) {
146 #ifdef INET_CSK_DEBUG
147 pr_debug("reset_xmit_timer: sk=%p %d when=0x%lx, caller=%p\n",
148 sk
, what
, when
, current_text_addr());
153 if (what
== ICSK_TIME_RETRANS
|| what
== ICSK_TIME_PROBE0
) {
154 icsk
->icsk_pending
= what
;
155 icsk
->icsk_timeout
= jiffies
+ when
;
156 sk_reset_timer(sk
, &icsk
->icsk_retransmit_timer
, icsk
->icsk_timeout
);
157 } else if (what
== ICSK_TIME_DACK
) {
158 icsk
->icsk_ack
.pending
|= ICSK_ACK_TIMER
;
159 icsk
->icsk_ack
.timeout
= jiffies
+ when
;
160 sk_reset_timer(sk
, &icsk
->icsk_delack_timer
, icsk
->icsk_ack
.timeout
);
162 #ifdef INET_CSK_DEBUG
164 pr_debug(inet_csk_timer_bug_msg
);
169 extern struct sock
*inet_csk_accept(struct sock
*sk
, int flags
, int *err
);
171 extern struct request_sock
*inet_csk_search_req(const struct sock
*sk
,
172 struct request_sock
***prevp
,
176 extern int inet_csk_get_port(struct inet_hashinfo
*hashinfo
,
177 struct sock
*sk
, unsigned short snum
);
179 extern struct dst_entry
* inet_csk_route_req(struct sock
*sk
,
180 const struct request_sock
*req
);
182 static inline void inet_csk_reqsk_queue_add(struct sock
*sk
,
183 struct request_sock
*req
,
186 reqsk_queue_add(&inet_csk(sk
)->icsk_accept_queue
, req
, sk
, child
);
189 extern void inet_csk_reqsk_queue_hash_add(struct sock
*sk
,
190 struct request_sock
*req
,
191 const unsigned timeout
);
193 static inline void inet_csk_reqsk_queue_removed(struct sock
*sk
,
194 struct request_sock
*req
)
196 if (reqsk_queue_removed(&inet_csk(sk
)->icsk_accept_queue
, req
) == 0)
197 inet_csk_delete_keepalive_timer(sk
);
200 static inline void inet_csk_reqsk_queue_added(struct sock
*sk
,
201 const unsigned long timeout
)
203 if (reqsk_queue_added(&inet_csk(sk
)->icsk_accept_queue
) == 0)
204 inet_csk_reset_keepalive_timer(sk
, timeout
);
207 static inline int inet_csk_reqsk_queue_len(const struct sock
*sk
)
209 return reqsk_queue_len(&inet_csk(sk
)->icsk_accept_queue
);
212 static inline int inet_csk_reqsk_queue_young(const struct sock
*sk
)
214 return reqsk_queue_len_young(&inet_csk(sk
)->icsk_accept_queue
);
217 static inline int inet_csk_reqsk_queue_is_full(const struct sock
*sk
)
219 return reqsk_queue_is_full(&inet_csk(sk
)->icsk_accept_queue
);
222 static inline void inet_csk_reqsk_queue_unlink(struct sock
*sk
,
223 struct request_sock
*req
,
224 struct request_sock
**prev
)
226 reqsk_queue_unlink(&inet_csk(sk
)->icsk_accept_queue
, req
, prev
);
229 static inline void inet_csk_reqsk_queue_drop(struct sock
*sk
,
230 struct request_sock
*req
,
231 struct request_sock
**prev
)
233 inet_csk_reqsk_queue_unlink(sk
, req
, prev
);
234 inet_csk_reqsk_queue_removed(sk
, req
);
238 #endif /* _INET_CONNECTION_SOCK_H */