aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/syncookies.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/ipv4/syncookies.c')
-rw-r--r--net/ipv4/syncookies.c48
1 files changed, 24 insertions, 24 deletions
diff --git a/net/ipv4/syncookies.c b/net/ipv4/syncookies.c
index 5c24db4a3c91..02bef6aa8b30 100644
--- a/net/ipv4/syncookies.c
+++ b/net/ipv4/syncookies.c
@@ -138,23 +138,23 @@ static __u32 check_tcp_syn_cookie(__u32 cookie, __be32 saddr, __be32 daddr,
138} 138}
139 139
140/* 140/*
141 * This table has to be sorted and terminated with (__u16)-1. 141 * MSS Values are taken from the 2009 paper
142 * XXX generate a better table. 142 * 'Measuring TCP Maximum Segment Size' by S. Alcock and R. Nelson:
143 * Unresolved Issues: HIPPI with a 64k MSS is not well supported. 143 * - values 1440 to 1460 accounted for 80% of observed mss values
144 * - values outside the 536-1460 range are rare (<0.2%).
145 *
146 * Table must be sorted.
144 */ 147 */
145static __u16 const msstab[] = { 148static __u16 const msstab[] = {
146 64 - 1, 149 64,
147 256 - 1, 150 512,
148 512 - 1, 151 536,
149 536 - 1, 152 1024,
150 1024 - 1, 153 1440,
151 1440 - 1, 154 1460,
152 1460 - 1, 155 4312,
153 4312 - 1, 156 8960,
154 (__u16)-1
155}; 157};
156/* The number doesn't include the -1 terminator */
157#define NUM_MSS (ARRAY_SIZE(msstab) - 1)
158 158
159/* 159/*
160 * Generate a syncookie. mssp points to the mss, which is returned 160 * Generate a syncookie. mssp points to the mss, which is returned
@@ -169,10 +169,10 @@ __u32 cookie_v4_init_sequence(struct sock *sk, struct sk_buff *skb, __u16 *mssp)
169 169
170 tcp_synq_overflow(sk); 170 tcp_synq_overflow(sk);
171 171
172 /* XXX sort msstab[] by probability? Binary search? */ 172 for (mssind = ARRAY_SIZE(msstab) - 1; mssind ; mssind--)
173 for (mssind = 0; mss > msstab[mssind + 1]; mssind++) 173 if (mss >= msstab[mssind])
174 ; 174 break;
175 *mssp = msstab[mssind] + 1; 175 *mssp = msstab[mssind];
176 176
177 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT); 177 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_SYNCOOKIESSENT);
178 178
@@ -202,7 +202,7 @@ static inline int cookie_check(struct sk_buff *skb, __u32 cookie)
202 jiffies / (HZ * 60), 202 jiffies / (HZ * 60),
203 COUNTER_TRIES); 203 COUNTER_TRIES);
204 204
205 return mssind < NUM_MSS ? msstab[mssind] + 1 : 0; 205 return mssind < ARRAY_SIZE(msstab) ? msstab[mssind] : 0;
206} 206}
207 207
208static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb, 208static inline struct sock *get_cookie_sock(struct sock *sk, struct sk_buff *skb,
@@ -266,7 +266,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
266 struct rtable *rt; 266 struct rtable *rt;
267 __u8 rcv_wscale; 267 __u8 rcv_wscale;
268 268
269 if (!sysctl_tcp_syncookies || !th->ack) 269 if (!sysctl_tcp_syncookies || !th->ack || th->rst)
270 goto out; 270 goto out;
271 271
272 if (tcp_synq_no_recent_overflow(sk) || 272 if (tcp_synq_no_recent_overflow(sk) ||
@@ -347,22 +347,22 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
347 { .sport = th->dest, 347 { .sport = th->dest,
348 .dport = th->source } } }; 348 .dport = th->source } } };
349 security_req_classify_flow(req, &fl); 349 security_req_classify_flow(req, &fl);
350 if (ip_route_output_key(&init_net, &rt, &fl)) { 350 if (ip_route_output_key(sock_net(sk), &rt, &fl)) {
351 reqsk_free(req); 351 reqsk_free(req);
352 goto out; 352 goto out;
353 } 353 }
354 } 354 }
355 355
356 /* Try to redo what tcp_v4_send_synack did. */ 356 /* Try to redo what tcp_v4_send_synack did. */
357 req->window_clamp = tp->window_clamp ? :dst_metric(&rt->u.dst, RTAX_WINDOW); 357 req->window_clamp = tp->window_clamp ? :dst_metric(&rt->dst, RTAX_WINDOW);
358 358
359 tcp_select_initial_window(tcp_full_space(sk), req->mss, 359 tcp_select_initial_window(tcp_full_space(sk), req->mss,
360 &req->rcv_wnd, &req->window_clamp, 360 &req->rcv_wnd, &req->window_clamp,
361 ireq->wscale_ok, &rcv_wscale, 361 ireq->wscale_ok, &rcv_wscale,
362 dst_metric(&rt->u.dst, RTAX_INITRWND)); 362 dst_metric(&rt->dst, RTAX_INITRWND));
363 363
364 ireq->rcv_wscale = rcv_wscale; 364 ireq->rcv_wscale = rcv_wscale;
365 365
366 ret = get_cookie_sock(sk, skb, req, &rt->u.dst); 366 ret = get_cookie_sock(sk, skb, req, &rt->dst);
367out: return ret; 367out: return ret;
368} 368}