aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2010-12-01 21:09:13 -0500
committerDavid S. Miller <davem@davemloft.net>2010-12-01 21:09:13 -0500
commitccb7c410ddc054b8c1ae780319bc98ae092d3854 (patch)
tree6a363c7232121d2390c091b232ee758fa10e4446 /net/ipv4
parent4399ce402c7c837dec80bf9fb40d079b39b9265a (diff)
timewait_sock: Create and use getpeer op.
The only thing AF-specific about remembering the timestamp for a time-wait TCP socket is getting the peer. Abstract that behind a new timewait_sock_ops vector. Support for real IPV6 sockets is not filled in yet, but curiously this makes timewait recycling start to work for v4-mapped ipv6 sockets. Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/tcp_ipv4.c33
-rw-r--r--net/ipv4/tcp_minisocks.c32
2 files changed, 35 insertions, 30 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 0ddf819cfb5d..dd555051ec8b 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1210,12 +1210,6 @@ static const struct tcp_request_sock_ops tcp_request_sock_ipv4_ops = {
1210}; 1210};
1211#endif 1211#endif
1212 1212
1213static struct timewait_sock_ops tcp_timewait_sock_ops = {
1214 .twsk_obj_size = sizeof(struct tcp_timewait_sock),
1215 .twsk_unique = tcp_twsk_unique,
1216 .twsk_destructor= tcp_twsk_destructor,
1217};
1218
1219int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb) 1213int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
1220{ 1214{
1221 struct tcp_extend_values tmp_ext; 1215 struct tcp_extend_values tmp_ext;
@@ -1783,25 +1777,20 @@ struct inet_peer *tcp_v4_get_peer(struct sock *sk, bool *release_it)
1783} 1777}
1784EXPORT_SYMBOL(tcp_v4_get_peer); 1778EXPORT_SYMBOL(tcp_v4_get_peer);
1785 1779
1786int tcp_v4_tw_remember_stamp(struct inet_timewait_sock *tw) 1780void *tcp_v4_tw_get_peer(struct sock *sk)
1787{ 1781{
1788 struct inet_peer *peer = inet_getpeer_v4(tw->tw_daddr, 1); 1782 struct inet_timewait_sock *tw = inet_twsk(sk);
1789
1790 if (peer) {
1791 const struct tcp_timewait_sock *tcptw = tcp_twsk((struct sock *)tw);
1792
1793 if ((s32)(peer->tcp_ts - tcptw->tw_ts_recent) <= 0 ||
1794 ((u32)get_seconds() - peer->tcp_ts_stamp > TCP_PAWS_MSL &&
1795 peer->tcp_ts_stamp <= (u32)tcptw->tw_ts_recent_stamp)) {
1796 peer->tcp_ts_stamp = (u32)tcptw->tw_ts_recent_stamp;
1797 peer->tcp_ts = tcptw->tw_ts_recent;
1798 }
1799 inet_putpeer(peer);
1800 return 1;
1801 }
1802 1783
1803 return 0; 1784 return inet_getpeer_v4(tw->tw_daddr, 1);
1804} 1785}
1786EXPORT_SYMBOL(tcp_v4_tw_get_peer);
1787
1788static struct timewait_sock_ops tcp_timewait_sock_ops = {
1789 .twsk_obj_size = sizeof(struct tcp_timewait_sock),
1790 .twsk_unique = tcp_twsk_unique,
1791 .twsk_destructor= tcp_twsk_destructor,
1792 .twsk_getpeer = tcp_v4_tw_get_peer,
1793};
1805 1794
1806const struct inet_connection_sock_af_ops ipv4_specific = { 1795const struct inet_connection_sock_af_ops ipv4_specific = {
1807 .queue_xmit = ip_queue_xmit, 1796 .queue_xmit = ip_queue_xmit,
diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
index 059082c873cf..3527b51d6159 100644
--- a/net/ipv4/tcp_minisocks.c
+++ b/net/ipv4/tcp_minisocks.c
@@ -78,6 +78,27 @@ static int tcp_remember_stamp(struct sock *sk)
78 return 0; 78 return 0;
79} 79}
80 80
81static int tcp_tw_remember_stamp(struct inet_timewait_sock *tw)
82{
83 struct sock *sk = (struct sock *) tw;
84 struct inet_peer *peer;
85
86 peer = twsk_getpeer(sk);
87 if (peer) {
88 const struct tcp_timewait_sock *tcptw = tcp_twsk(sk);
89
90 if ((s32)(peer->tcp_ts - tcptw->tw_ts_recent) <= 0 ||
91 ((u32)get_seconds() - peer->tcp_ts_stamp > TCP_PAWS_MSL &&
92 peer->tcp_ts_stamp <= (u32)tcptw->tw_ts_recent_stamp)) {
93 peer->tcp_ts_stamp = (u32)tcptw->tw_ts_recent_stamp;
94 peer->tcp_ts = tcptw->tw_ts_recent;
95 }
96 inet_putpeer(peer);
97 return 1;
98 }
99 return 0;
100}
101
81static __inline__ int tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win) 102static __inline__ int tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win)
82{ 103{
83 if (seq == s_win) 104 if (seq == s_win)
@@ -178,14 +199,9 @@ kill_with_rst:
178 tcptw->tw_ts_recent = tmp_opt.rcv_tsval; 199 tcptw->tw_ts_recent = tmp_opt.rcv_tsval;
179 } 200 }
180 201
181 /* I am shamed, but failed to make it more elegant. 202 if (tcp_death_row.sysctl_tw_recycle &&
182 * Yes, it is direct reference to IP, which is impossible 203 tcptw->tw_ts_recent_stamp &&
183 * to generalize to IPv6. Taking into account that IPv6 204 tcp_tw_remember_stamp(tw))
184 * do not understand recycling in any case, it not
185 * a big problem in practice. --ANK */
186 if (tw->tw_family == AF_INET &&
187 tcp_death_row.sysctl_tw_recycle && tcptw->tw_ts_recent_stamp &&
188 tcp_v4_tw_remember_stamp(tw))
189 inet_twsk_schedule(tw, &tcp_death_row, tw->tw_timeout, 205 inet_twsk_schedule(tw, &tcp_death_row, tw->tw_timeout,
190 TCP_TIMEWAIT_LEN); 206 TCP_TIMEWAIT_LEN);
191 else 207 else