aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@ghostprotocols.net>2005-08-09 23:11:41 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2005-08-29 18:49:24 -0400
commit0a5578cf8e5e045aaa68643c17ce885426697c6b (patch)
tree1c58ba5c3236499ec5abeedcc43faa7bed816b07
parent9f1d2604c71498579609b1532fedc5a89276bb00 (diff)
[ICSK]: Generalise tcp_listen_{start,stop}
This also moved inet_iif from tcp to inet_hashtables.h, as it is needed by the inet_lookup callers, perhaps this needs a bit of polishing, but for now seems fine. Signed-off-by: Arnaldo Carvalho de Melo <acme@ghostprotocols.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/net/inet_hashtables.h6
-rw-r--r--include/net/sock.h1
-rw-r--r--include/net/tcp.h4
-rw-r--r--net/ipv4/af_inet.c2
-rw-r--r--net/ipv4/tcp.c38
-rw-r--r--net/ipv4/tcp_ipv4.c6
-rw-r--r--net/ipv6/tcp_ipv6.c1
7 files changed, 33 insertions, 25 deletions
diff --git a/include/net/inet_hashtables.h b/include/net/inet_hashtables.h
index f0c21c07f894..646b6ea7fe26 100644
--- a/include/net/inet_hashtables.h
+++ b/include/net/inet_hashtables.h
@@ -26,6 +26,7 @@
26#include <linux/wait.h> 26#include <linux/wait.h>
27 27
28#include <net/inet_connection_sock.h> 28#include <net/inet_connection_sock.h>
29#include <net/route.h>
29#include <net/sock.h> 30#include <net/sock.h>
30#include <net/tcp_states.h> 31#include <net/tcp_states.h>
31 32
@@ -280,6 +281,11 @@ out:
280 wake_up(&hashinfo->lhash_wait); 281 wake_up(&hashinfo->lhash_wait);
281} 282}
282 283
284static inline int inet_iif(const struct sk_buff *skb)
285{
286 return ((struct rtable *)skb->dst)->rt_iif;
287}
288
283extern struct sock *__inet_lookup_listener(const struct hlist_head *head, 289extern struct sock *__inet_lookup_listener(const struct hlist_head *head,
284 const u32 daddr, 290 const u32 daddr,
285 const unsigned short hnum, 291 const unsigned short hnum,
diff --git a/include/net/sock.h b/include/net/sock.h
index 48cc337a6566..8678313a22b4 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -558,6 +558,7 @@ struct proto {
558 558
559 kmem_cache_t *twsk_slab; 559 kmem_cache_t *twsk_slab;
560 unsigned int twsk_obj_size; 560 unsigned int twsk_obj_size;
561 atomic_t *orphan_count;
561 562
562 struct request_sock_ops *rsk_prot; 563 struct request_sock_ops *rsk_prot;
563 564
diff --git a/include/net/tcp.h b/include/net/tcp.h
index dd9a5a288f88..68f1ec1c583a 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -860,7 +860,7 @@ static __inline__ void tcp_update_wl(struct tcp_sock *tp, u32 ack, u32 seq)
860 tp->snd_wl1 = seq; 860 tp->snd_wl1 = seq;
861} 861}
862 862
863extern void tcp_destroy_sock(struct sock *sk); 863extern void inet_csk_destroy_sock(struct sock *sk);
864 864
865 865
866/* 866/*
@@ -987,7 +987,7 @@ static __inline__ void tcp_done(struct sock *sk)
987 if (!sock_flag(sk, SOCK_DEAD)) 987 if (!sock_flag(sk, SOCK_DEAD))
988 sk->sk_state_change(sk); 988 sk->sk_state_change(sk);
989 else 989 else
990 tcp_destroy_sock(sk); 990 inet_csk_destroy_sock(sk);
991} 991}
992 992
993static __inline__ void tcp_sack_reset(struct tcp_options_received *rx_opt) 993static __inline__ void tcp_sack_reset(struct tcp_options_received *rx_opt)
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
index 7137e6420d66..f691058cf599 100644
--- a/net/ipv4/af_inet.c
+++ b/net/ipv4/af_inet.c
@@ -202,7 +202,7 @@ int inet_listen(struct socket *sock, int backlog)
202 * we can only allow the backlog to be adjusted. 202 * we can only allow the backlog to be adjusted.
203 */ 203 */
204 if (old_state != TCP_LISTEN) { 204 if (old_state != TCP_LISTEN) {
205 err = tcp_listen_start(sk); 205 err = inet_csk_listen_start(sk, TCP_SYNQ_HSIZE);
206 if (err) 206 if (err)
207 goto out; 207 goto out;
208 } 208 }
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 581016a6a93f..a1f812159ced 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -273,6 +273,8 @@ DEFINE_SNMP_STAT(struct tcp_mib, tcp_statistics);
273 273
274atomic_t tcp_orphan_count = ATOMIC_INIT(0); 274atomic_t tcp_orphan_count = ATOMIC_INIT(0);
275 275
276EXPORT_SYMBOL_GPL(tcp_orphan_count);
277
276int sysctl_tcp_mem[3]; 278int sysctl_tcp_mem[3];
277int sysctl_tcp_wmem[3] = { 4 * 1024, 16 * 1024, 128 * 1024 }; 279int sysctl_tcp_wmem[3] = { 4 * 1024, 16 * 1024, 128 * 1024 };
278int sysctl_tcp_rmem[3] = { 4 * 1024, 87380, 87380 * 2 }; 280int sysctl_tcp_rmem[3] = { 4 * 1024, 87380, 87380 * 2 };
@@ -454,12 +456,11 @@ int tcp_ioctl(struct sock *sk, int cmd, unsigned long arg)
454 return put_user(answ, (int __user *)arg); 456 return put_user(answ, (int __user *)arg);
455} 457}
456 458
457 459int inet_csk_listen_start(struct sock *sk, const int nr_table_entries)
458int tcp_listen_start(struct sock *sk)
459{ 460{
460 struct inet_sock *inet = inet_sk(sk); 461 struct inet_sock *inet = inet_sk(sk);
461 struct inet_connection_sock *icsk = inet_csk(sk); 462 struct inet_connection_sock *icsk = inet_csk(sk);
462 int rc = reqsk_queue_alloc(&icsk->icsk_accept_queue, TCP_SYNQ_HSIZE); 463 int rc = reqsk_queue_alloc(&icsk->icsk_accept_queue, nr_table_entries);
463 464
464 if (rc != 0) 465 if (rc != 0)
465 return rc; 466 return rc;
@@ -488,12 +489,13 @@ int tcp_listen_start(struct sock *sk)
488 return -EADDRINUSE; 489 return -EADDRINUSE;
489} 490}
490 491
492EXPORT_SYMBOL_GPL(inet_csk_listen_start);
493
491/* 494/*
492 * This routine closes sockets which have been at least partially 495 * This routine closes sockets which have been at least partially
493 * opened, but not yet accepted. 496 * opened, but not yet accepted.
494 */ 497 */
495 498static void inet_csk_listen_stop(struct sock *sk)
496static void tcp_listen_stop (struct sock *sk)
497{ 499{
498 struct inet_connection_sock *icsk = inet_csk(sk); 500 struct inet_connection_sock *icsk = inet_csk(sk);
499 struct request_sock *acc_req; 501 struct request_sock *acc_req;
@@ -524,13 +526,13 @@ static void tcp_listen_stop (struct sock *sk)
524 BUG_TRAP(!sock_owned_by_user(child)); 526 BUG_TRAP(!sock_owned_by_user(child));
525 sock_hold(child); 527 sock_hold(child);
526 528
527 tcp_disconnect(child, O_NONBLOCK); 529 sk->sk_prot->disconnect(child, O_NONBLOCK);
528 530
529 sock_orphan(child); 531 sock_orphan(child);
530 532
531 atomic_inc(&tcp_orphan_count); 533 atomic_inc(sk->sk_prot->orphan_count);
532 534
533 tcp_destroy_sock(child); 535 inet_csk_destroy_sock(child);
534 536
535 bh_unlock_sock(child); 537 bh_unlock_sock(child);
536 local_bh_enable(); 538 local_bh_enable();
@@ -542,6 +544,8 @@ static void tcp_listen_stop (struct sock *sk)
542 BUG_TRAP(!sk->sk_ack_backlog); 544 BUG_TRAP(!sk->sk_ack_backlog);
543} 545}
544 546
547EXPORT_SYMBOL_GPL(inet_csk_listen_stop);
548
545static inline void tcp_mark_push(struct tcp_sock *tp, struct sk_buff *skb) 549static inline void tcp_mark_push(struct tcp_sock *tp, struct sk_buff *skb)
546{ 550{
547 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH; 551 TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH;
@@ -1561,7 +1565,7 @@ void tcp_shutdown(struct sock *sk, int how)
1561 * can assume the socket waitqueue is inactive and nobody will 1565 * can assume the socket waitqueue is inactive and nobody will
1562 * try to jump onto it. 1566 * try to jump onto it.
1563 */ 1567 */
1564void tcp_destroy_sock(struct sock *sk) 1568void inet_csk_destroy_sock(struct sock *sk)
1565{ 1569{
1566 BUG_TRAP(sk->sk_state == TCP_CLOSE); 1570 BUG_TRAP(sk->sk_state == TCP_CLOSE);
1567 BUG_TRAP(sock_flag(sk, SOCK_DEAD)); 1571 BUG_TRAP(sock_flag(sk, SOCK_DEAD));
@@ -1580,7 +1584,7 @@ void tcp_destroy_sock(struct sock *sk)
1580 1584
1581 sk_refcnt_debug_release(sk); 1585 sk_refcnt_debug_release(sk);
1582 1586
1583 atomic_dec(&tcp_orphan_count); 1587 atomic_dec(sk->sk_prot->orphan_count);
1584 sock_put(sk); 1588 sock_put(sk);
1585} 1589}
1586 1590
@@ -1596,7 +1600,7 @@ void tcp_close(struct sock *sk, long timeout)
1596 tcp_set_state(sk, TCP_CLOSE); 1600 tcp_set_state(sk, TCP_CLOSE);
1597 1601
1598 /* Special case. */ 1602 /* Special case. */
1599 tcp_listen_stop(sk); 1603 inet_csk_listen_stop(sk);
1600 1604
1601 goto adjudge_to_death; 1605 goto adjudge_to_death;
1602 } 1606 }
@@ -1704,7 +1708,7 @@ adjudge_to_death:
1704 if (tmo > TCP_TIMEWAIT_LEN) { 1708 if (tmo > TCP_TIMEWAIT_LEN) {
1705 inet_csk_reset_keepalive_timer(sk, tcp_fin_time(sk)); 1709 inet_csk_reset_keepalive_timer(sk, tcp_fin_time(sk));
1706 } else { 1710 } else {
1707 atomic_inc(&tcp_orphan_count); 1711 atomic_inc(sk->sk_prot->orphan_count);
1708 tcp_time_wait(sk, TCP_FIN_WAIT2, tmo); 1712 tcp_time_wait(sk, TCP_FIN_WAIT2, tmo);
1709 goto out; 1713 goto out;
1710 } 1714 }
@@ -1712,7 +1716,7 @@ adjudge_to_death:
1712 } 1716 }
1713 if (sk->sk_state != TCP_CLOSE) { 1717 if (sk->sk_state != TCP_CLOSE) {
1714 sk_stream_mem_reclaim(sk); 1718 sk_stream_mem_reclaim(sk);
1715 if (atomic_read(&tcp_orphan_count) > sysctl_tcp_max_orphans || 1719 if (atomic_read(sk->sk_prot->orphan_count) > sysctl_tcp_max_orphans ||
1716 (sk->sk_wmem_queued > SOCK_MIN_SNDBUF && 1720 (sk->sk_wmem_queued > SOCK_MIN_SNDBUF &&
1717 atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])) { 1721 atomic_read(&tcp_memory_allocated) > sysctl_tcp_mem[2])) {
1718 if (net_ratelimit()) 1722 if (net_ratelimit())
@@ -1723,10 +1727,10 @@ adjudge_to_death:
1723 NET_INC_STATS_BH(LINUX_MIB_TCPABORTONMEMORY); 1727 NET_INC_STATS_BH(LINUX_MIB_TCPABORTONMEMORY);
1724 } 1728 }
1725 } 1729 }
1726 atomic_inc(&tcp_orphan_count); 1730 atomic_inc(sk->sk_prot->orphan_count);
1727 1731
1728 if (sk->sk_state == TCP_CLOSE) 1732 if (sk->sk_state == TCP_CLOSE)
1729 tcp_destroy_sock(sk); 1733 inet_csk_destroy_sock(sk);
1730 /* Otherwise, socket is reprieved until protocol close. */ 1734 /* Otherwise, socket is reprieved until protocol close. */
1731 1735
1732out: 1736out:
@@ -1757,7 +1761,7 @@ int tcp_disconnect(struct sock *sk, int flags)
1757 1761
1758 /* ABORT function of RFC793 */ 1762 /* ABORT function of RFC793 */
1759 if (old_state == TCP_LISTEN) { 1763 if (old_state == TCP_LISTEN) {
1760 tcp_listen_stop(sk); 1764 inet_csk_listen_stop(sk);
1761 } else if (tcp_need_reset(old_state) || 1765 } else if (tcp_need_reset(old_state) ||
1762 (tp->snd_nxt != tp->write_seq && 1766 (tp->snd_nxt != tp->write_seq &&
1763 (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK))) { 1767 (1 << old_state) & (TCPF_CLOSING | TCPF_LAST_ACK))) {
@@ -2253,7 +2257,7 @@ void __init tcp_init(void)
2253} 2257}
2254 2258
2255EXPORT_SYMBOL(tcp_close); 2259EXPORT_SYMBOL(tcp_close);
2256EXPORT_SYMBOL(tcp_destroy_sock); 2260EXPORT_SYMBOL(inet_csk_destroy_sock);
2257EXPORT_SYMBOL(tcp_disconnect); 2261EXPORT_SYMBOL(tcp_disconnect);
2258EXPORT_SYMBOL(tcp_getsockopt); 2262EXPORT_SYMBOL(tcp_getsockopt);
2259EXPORT_SYMBOL(tcp_ioctl); 2263EXPORT_SYMBOL(tcp_ioctl);
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 2f605b9e6b67..b966102b9f39 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -431,11 +431,6 @@ failure:
431 return err; 431 return err;
432} 432}
433 433
434static inline int inet_iif(const struct sk_buff *skb)
435{
436 return ((struct rtable *)skb->dst)->rt_iif;
437}
438
439/* 434/*
440 * This routine does path mtu discovery as defined in RFC1191. 435 * This routine does path mtu discovery as defined in RFC1191.
441 */ 436 */
@@ -1993,6 +1988,7 @@ struct proto tcp_prot = {
1993 .get_port = tcp_v4_get_port, 1988 .get_port = tcp_v4_get_port,
1994 .enter_memory_pressure = tcp_enter_memory_pressure, 1989 .enter_memory_pressure = tcp_enter_memory_pressure,
1995 .sockets_allocated = &tcp_sockets_allocated, 1990 .sockets_allocated = &tcp_sockets_allocated,
1991 .orphan_count = &tcp_orphan_count,
1996 .memory_allocated = &tcp_memory_allocated, 1992 .memory_allocated = &tcp_memory_allocated,
1997 .memory_pressure = &tcp_memory_pressure, 1993 .memory_pressure = &tcp_memory_pressure,
1998 .sysctl_mem = sysctl_tcp_mem, 1994 .sysctl_mem = sysctl_tcp_mem,
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index b9c7003b7f8b..0b51ec310ebe 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -2248,6 +2248,7 @@ struct proto tcpv6_prot = {
2248 .sockets_allocated = &tcp_sockets_allocated, 2248 .sockets_allocated = &tcp_sockets_allocated,
2249 .memory_allocated = &tcp_memory_allocated, 2249 .memory_allocated = &tcp_memory_allocated,
2250 .memory_pressure = &tcp_memory_pressure, 2250 .memory_pressure = &tcp_memory_pressure,
2251 .orphan_count = &tcp_orphan_count,
2251 .sysctl_mem = sysctl_tcp_mem, 2252 .sysctl_mem = sysctl_tcp_mem,
2252 .sysctl_wmem = sysctl_tcp_wmem, 2253 .sysctl_wmem = sysctl_tcp_wmem,
2253 .sysctl_rmem = sysctl_tcp_rmem, 2254 .sysctl_rmem = sysctl_tcp_rmem,