X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=net%2Fipv4%2Ftcp_minisocks.c;h=4bb46b80e3a84bbffcafc5bfd7008e53febf2398;hb=a6d8dea2993ef90fb69b81372daa0b63f8aa940e;hp=a0a8422cdda6eba22ce0424ea420dda581fb6387;hpb=a8e794ca871505c8ea96cc102f4ad555c5231d7f;p=linux-2.6.git diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index a0a8422cd..4bb46b80e 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -29,6 +29,10 @@ #include #include +#include +#include +#include + #ifdef CONFIG_SYSCTL #define SYNC_INIT 0 /* let the user enable it */ #else @@ -41,6 +45,8 @@ int sysctl_tcp_max_tw_buckets = NR_FILE*2; int sysctl_tcp_syncookies = SYNC_INIT; int sysctl_tcp_abort_on_overflow; +static void tcp_tw_schedule(struct tcp_tw_bucket *tw, int timeo); + static __inline__ int tcp_in_window(u32 seq, u32 end_seq, u32 s_win, u32 e_win) { if (seq == s_win) @@ -123,17 +129,17 @@ enum tcp_tw_status tcp_timewait_state_process(struct tcp_tw_bucket *tw, struct sk_buff *skb, struct tcphdr *th, unsigned len) { - struct tcp_opt tp; + struct tcp_options_received tmp_opt; int paws_reject = 0; - tp.saw_tstamp = 0; + tmp_opt.saw_tstamp = 0; if (th->doff > (sizeof(struct tcphdr) >> 2) && tw->tw_ts_recent_stamp) { - tcp_parse_options(skb, &tp, 0); + tcp_parse_options(skb, &tmp_opt, 0); - if (tp.saw_tstamp) { - tp.ts_recent = tw->tw_ts_recent; - tp.ts_recent_stamp = tw->tw_ts_recent_stamp; - paws_reject = tcp_paws_check(&tp, th->rst); + if (tmp_opt.saw_tstamp) { + tmp_opt.ts_recent = tw->tw_ts_recent; + tmp_opt.ts_recent_stamp = tw->tw_ts_recent_stamp; + paws_reject = tcp_paws_check(&tmp_opt, th->rst); } } @@ -174,9 +180,9 @@ kill_with_rst: /* FIN arrived, enter true time-wait state. */ tw->tw_substate = TCP_TIME_WAIT; tw->tw_rcv_nxt = TCP_SKB_CB(skb)->end_seq; - if (tp.saw_tstamp) { + if (tmp_opt.saw_tstamp) { tw->tw_ts_recent_stamp = xtime.tv_sec; - tw->tw_ts_recent = tp.rcv_tsval; + tw->tw_ts_recent = tmp_opt.rcv_tsval; } /* I am shamed, but failed to make it more elegant. @@ -229,8 +235,8 @@ kill: } tcp_tw_schedule(tw, TCP_TIMEWAIT_LEN); - if (tp.saw_tstamp) { - tw->tw_ts_recent = tp.rcv_tsval; + if (tmp_opt.saw_tstamp) { + tw->tw_ts_recent = tmp_opt.rcv_tsval; tw->tw_ts_recent_stamp = xtime.tv_sec; } @@ -257,7 +263,7 @@ kill: if (th->syn && !th->rst && !th->ack && !paws_reject && (after(TCP_SKB_CB(skb)->seq, tw->tw_rcv_nxt) || - (tp.saw_tstamp && (s32)(tw->tw_ts_recent - tp.rcv_tsval) < 0))) { + (tmp_opt.saw_tstamp && (s32)(tw->tw_ts_recent - tmp_opt.rcv_tsval) < 0))) { u32 isn = tw->tw_snd_nxt + 65535 + 2; if (isn == 0) isn++; @@ -266,7 +272,7 @@ kill: } if (paws_reject) - NET_INC_STATS_BH(PAWSEstabRejected); + NET_INC_STATS_BH(LINUX_MIB_PAWSESTABREJECTED); if(!th->rst) { /* In this case we must reset the TIMEWAIT timer. @@ -327,17 +333,17 @@ static void __tcp_tw_hashdance(struct sock *sk, struct tcp_tw_bucket *tw) void tcp_time_wait(struct sock *sk, int state, int timeo) { struct tcp_tw_bucket *tw = NULL; - struct tcp_opt *tp = tcp_sk(sk); + struct tcp_sock *tp = tcp_sk(sk); int recycle_ok = 0; - if (sysctl_tcp_tw_recycle && tp->ts_recent_stamp) + if (sysctl_tcp_tw_recycle && tp->rx_opt.ts_recent_stamp) recycle_ok = tp->af_specific->remember_stamp(sk); if (tcp_tw_count < sysctl_tcp_max_tw_buckets) tw = kmem_cache_alloc(tcp_timewait_cachep, SLAB_ATOMIC); if(tw != NULL) { - struct inet_opt *inet = inet_sk(sk); + struct inet_sock *inet = inet_sk(sk); int rto = (tp->rto<<2) - (tp->rto>>1); /* Give us an identity. */ @@ -351,22 +357,22 @@ void tcp_time_wait(struct sock *sk, int state, int timeo) tw->tw_dport = inet->dport; tw->tw_family = sk->sk_family; tw->tw_reuse = sk->sk_reuse; - tw->tw_rcv_wscale = tp->rcv_wscale; + tw->tw_rcv_wscale = tp->rx_opt.rcv_wscale; atomic_set(&tw->tw_refcnt, 1); tw->tw_hashent = sk->sk_hashent; tw->tw_rcv_nxt = tp->rcv_nxt; tw->tw_snd_nxt = tp->snd_nxt; tw->tw_rcv_wnd = tcp_receive_window(tp); - tw->tw_ts_recent = tp->ts_recent; - tw->tw_ts_recent_stamp = tp->ts_recent_stamp; + tw->tw_ts_recent = tp->rx_opt.ts_recent; + tw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp; tw_dead_node_init(tw); tw->tw_xid = sk->sk_xid; tw->tw_vx_info = NULL; tw->tw_nid = sk->sk_nid; tw->tw_nx_info = NULL; - + #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) if (tw->tw_family == PF_INET6) { struct ipv6_pinfo *np = inet6_sk(sk); @@ -422,7 +428,7 @@ static void tcp_twkill(unsigned long); #define TCP_TWKILL_QUOTA 100 static struct hlist_head tcp_tw_death_row[TCP_TWKILL_SLOTS]; -static spinlock_t tw_death_lock = SPIN_LOCK_UNLOCKED; +static DEFINE_SPINLOCK(tw_death_lock); static struct timer_list tcp_tw_timer = TIMER_INITIALIZER(tcp_twkill, 0, 0); static void twkill_work(void *); static DECLARE_WORK(tcp_twkill_work, twkill_work, NULL); @@ -467,7 +473,7 @@ rescan: } tcp_tw_count -= killed; - NET_ADD_STATS_BH(TimeWaited, killed); + NET_ADD_STATS_BH(LINUX_MIB_TIMEWAITED, killed); return ret; } @@ -556,7 +562,7 @@ static struct timer_list tcp_twcal_timer = TIMER_INITIALIZER(tcp_twcal_tick, 0, 0); static struct hlist_head tcp_twcal_row[TCP_TW_RECYCLE_SLOTS]; -void tcp_tw_schedule(struct tcp_tw_bucket *tw, int timeo) +static void tcp_tw_schedule(struct tcp_tw_bucket *tw, int timeo) { struct hlist_head *list; int slot; @@ -677,7 +683,7 @@ void tcp_twcal_tick(unsigned long dummy) out: if ((tcp_tw_count -= killed) == 0) del_timer(&tcp_tw_timer); - NET_ADD_STATS_BH(TimeWaitKilled, killed); + NET_ADD_STATS_BH(LINUX_MIB_TIMEWAITKILLED, killed); spin_unlock(&tw_death_lock); } @@ -692,10 +698,10 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct open_request *req, /* allocate the newsk from the same slab of the master sock, * if not, at sk_free time we'll try to free it from the wrong * slabcache (i.e. is it TCPv4 or v6?) -acme */ - struct sock *newsk = sk_alloc(PF_INET, GFP_ATOMIC, 0, sk->sk_slab); + struct sock *newsk = sk_alloc(PF_INET, GFP_ATOMIC, 0, sk->sk_prot->slab); if(newsk != NULL) { - struct tcp_opt *newtp; + struct tcp_sock *newtp; struct sk_filter *filter; memcpy(newsk, sk, sizeof(struct tcp_sock)); @@ -713,7 +719,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct open_request *req, sock_lock_init(newsk); bh_lock_sock(newsk); - newsk->sk_dst_lock = RW_LOCK_UNLOCKED; + rwlock_init(&newsk->sk_dst_lock); atomic_set(&newsk->sk_rmem_alloc, 0); skb_queue_head_init(&newsk->sk_receive_queue); atomic_set(&newsk->sk_wmem_alloc, 0); @@ -725,9 +731,10 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct open_request *req, sock_reset_flag(newsk, SOCK_DONE); newsk->sk_userlocks = sk->sk_userlocks & ~SOCK_BINDPORT_LOCK; newsk->sk_backlog.head = newsk->sk_backlog.tail = NULL; - newsk->sk_callback_lock = RW_LOCK_UNLOCKED; + newsk->sk_send_head = NULL; + rwlock_init(&newsk->sk_callback_lock); skb_queue_head_init(&newsk->sk_error_queue); - newsk->sk_write_space = tcp_write_space; + newsk->sk_write_space = sk_stream_write_space; if ((filter = newsk->sk_filter) != NULL) sk_filter_charge(newsk, filter); @@ -740,7 +747,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct open_request *req, return NULL; } - /* Now setup tcp_opt */ + /* Now setup tcp_sock */ newtp = tcp_sk(newsk); newtp->pred_flags = 0; newtp->rcv_nxt = req->rcv_isn + 1; @@ -773,28 +780,24 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct open_request *req, newtp->snd_cwnd = 2; newtp->snd_cwnd_cnt = 0; - newtp->bictcp.cnt = 0; - newtp->bictcp.last_max_cwnd = newtp->bictcp.last_cwnd = 0; - newtp->frto_counter = 0; newtp->frto_highmark = 0; tcp_set_ca_state(newtp, TCP_CA_Open); tcp_init_xmit_timers(newsk); skb_queue_head_init(&newtp->out_of_order_queue); - newtp->send_head = NULL; newtp->rcv_wup = req->rcv_isn + 1; newtp->write_seq = req->snt_isn + 1; newtp->pushed_seq = newtp->write_seq; newtp->copied_seq = req->rcv_isn + 1; - newtp->saw_tstamp = 0; + newtp->rx_opt.saw_tstamp = 0; - newtp->dsack = 0; - newtp->eff_sacks = 0; + newtp->rx_opt.dsack = 0; + newtp->rx_opt.eff_sacks = 0; newtp->probes_out = 0; - newtp->num_sacks = 0; + newtp->rx_opt.num_sacks = 0; newtp->urg_data = 0; newtp->listen_opt = NULL; newtp->accept_queue = newtp->accept_queue_tail = NULL; @@ -806,9 +809,11 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct open_request *req, newsk->sk_priority = 0; atomic_set(&newsk->sk_refcnt, 2); - /* hmm, maybe from socket? */ - set_vx_info(&newsk->sk_vx_info, current->vx_info); - set_nx_info(&newsk->sk_nx_info, current->nx_info); + set_vx_info(&newsk->sk_vx_info, sk->sk_vx_info); + newsk->sk_xid = sk->sk_xid; + vx_sock_inc(newsk); + set_nx_info(&newsk->sk_nx_info, sk->sk_nx_info); + newsk->sk_nid = sk->sk_nid; #ifdef INET_REFCNT_DEBUG atomic_inc(&inet_sock_nr); #endif @@ -821,42 +826,43 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct open_request *req, newsk->sk_sleep = NULL; newsk->sk_owner = NULL; - newtp->tstamp_ok = req->tstamp_ok; - if((newtp->sack_ok = req->sack_ok) != 0) { + newtp->rx_opt.tstamp_ok = req->tstamp_ok; + if((newtp->rx_opt.sack_ok = req->sack_ok) != 0) { if (sysctl_tcp_fack) - newtp->sack_ok |= 2; + newtp->rx_opt.sack_ok |= 2; } newtp->window_clamp = req->window_clamp; newtp->rcv_ssthresh = req->rcv_wnd; newtp->rcv_wnd = req->rcv_wnd; - newtp->wscale_ok = req->wscale_ok; - if (newtp->wscale_ok) { - newtp->snd_wscale = req->snd_wscale; - newtp->rcv_wscale = req->rcv_wscale; + newtp->rx_opt.wscale_ok = req->wscale_ok; + if (newtp->rx_opt.wscale_ok) { + newtp->rx_opt.snd_wscale = req->snd_wscale; + newtp->rx_opt.rcv_wscale = req->rcv_wscale; } else { - newtp->snd_wscale = newtp->rcv_wscale = 0; + newtp->rx_opt.snd_wscale = newtp->rx_opt.rcv_wscale = 0; newtp->window_clamp = min(newtp->window_clamp, 65535U); } - newtp->snd_wnd = ntohs(skb->h.th->window) << newtp->snd_wscale; + newtp->snd_wnd = ntohs(skb->h.th->window) << newtp->rx_opt.snd_wscale; newtp->max_window = newtp->snd_wnd; - if (newtp->tstamp_ok) { - newtp->ts_recent = req->ts_recent; - newtp->ts_recent_stamp = xtime.tv_sec; + if (newtp->rx_opt.tstamp_ok) { + newtp->rx_opt.ts_recent = req->ts_recent; + newtp->rx_opt.ts_recent_stamp = xtime.tv_sec; newtp->tcp_header_len = sizeof(struct tcphdr) + TCPOLEN_TSTAMP_ALIGNED; } else { - newtp->ts_recent_stamp = 0; + newtp->rx_opt.ts_recent_stamp = 0; newtp->tcp_header_len = sizeof(struct tcphdr); } if (skb->len >= TCP_MIN_RCVMSS+newtp->tcp_header_len) newtp->ack.last_seg_size = skb->len-newtp->tcp_header_len; - newtp->mss_clamp = req->mss; + newtp->rx_opt.mss_clamp = req->mss; TCP_ECN_openreq_child(newtp, req); if (newtp->ecn_flags&TCP_ECN_OK) newsk->sk_no_largesend = 1; - tcp_vegas_init(newtp); - TCP_INC_STATS_BH(TcpPassiveOpens); + tcp_ca_init(newtp); + + TCP_INC_STATS_BH(TCP_MIB_PASSIVEOPENS); } return newsk; } @@ -871,24 +877,24 @@ struct sock *tcp_check_req(struct sock *sk,struct sk_buff *skb, struct open_request **prev) { struct tcphdr *th = skb->h.th; - struct tcp_opt *tp = tcp_sk(sk); + struct tcp_sock *tp = tcp_sk(sk); u32 flg = tcp_flag_word(th) & (TCP_FLAG_RST|TCP_FLAG_SYN|TCP_FLAG_ACK); int paws_reject = 0; - struct tcp_opt ttp; + struct tcp_options_received tmp_opt; struct sock *child; - ttp.saw_tstamp = 0; + tmp_opt.saw_tstamp = 0; if (th->doff > (sizeof(struct tcphdr)>>2)) { - tcp_parse_options(skb, &ttp, 0); + tcp_parse_options(skb, &tmp_opt, 0); - if (ttp.saw_tstamp) { - ttp.ts_recent = req->ts_recent; + if (tmp_opt.saw_tstamp) { + tmp_opt.ts_recent = req->ts_recent; /* We do not store true stamp, but it is not required, * it can be estimated (approximately) * from another data. */ - ttp.ts_recent_stamp = xtime.tv_sec - ((TCP_TIMEOUT_INIT/HZ)<retrans); - paws_reject = tcp_paws_check(&ttp, th->rst); + tmp_opt.ts_recent_stamp = xtime.tv_sec - ((TCP_TIMEOUT_INIT/HZ)<retrans); + paws_reject = tcp_paws_check(&tmp_opt, th->rst); } } @@ -987,69 +993,69 @@ struct sock *tcp_check_req(struct sock *sk,struct sk_buff *skb, if (!(flg & TCP_FLAG_RST)) req->class->send_ack(skb, req); if (paws_reject) - NET_INC_STATS_BH(PAWSEstabRejected); + NET_INC_STATS_BH(LINUX_MIB_PAWSESTABREJECTED); return NULL; } /* In sequence, PAWS is OK. */ - if (ttp.saw_tstamp && !after(TCP_SKB_CB(skb)->seq, req->rcv_isn+1)) - req->ts_recent = ttp.rcv_tsval; + if (tmp_opt.saw_tstamp && !after(TCP_SKB_CB(skb)->seq, req->rcv_isn+1)) + req->ts_recent = tmp_opt.rcv_tsval; - if (TCP_SKB_CB(skb)->seq == req->rcv_isn) { - /* Truncate SYN, it is out of window starting - at req->rcv_isn+1. */ - flg &= ~TCP_FLAG_SYN; - } + if (TCP_SKB_CB(skb)->seq == req->rcv_isn) { + /* Truncate SYN, it is out of window starting + at req->rcv_isn+1. */ + flg &= ~TCP_FLAG_SYN; + } - /* RFC793: "second check the RST bit" and - * "fourth, check the SYN bit" - */ - if (flg & (TCP_FLAG_RST|TCP_FLAG_SYN)) - goto embryonic_reset; + /* RFC793: "second check the RST bit" and + * "fourth, check the SYN bit" + */ + if (flg & (TCP_FLAG_RST|TCP_FLAG_SYN)) + goto embryonic_reset; - /* ACK sequence verified above, just make sure ACK is - * set. If ACK not set, just silently drop the packet. - */ - if (!(flg & TCP_FLAG_ACK)) - return NULL; + /* ACK sequence verified above, just make sure ACK is + * set. If ACK not set, just silently drop the packet. + */ + if (!(flg & TCP_FLAG_ACK)) + return NULL; - /* If TCP_DEFER_ACCEPT is set, drop bare ACK. */ - if (tp->defer_accept && TCP_SKB_CB(skb)->end_seq == req->rcv_isn+1) { - req->acked = 1; - return NULL; - } + /* If TCP_DEFER_ACCEPT is set, drop bare ACK. */ + if (tp->defer_accept && TCP_SKB_CB(skb)->end_seq == req->rcv_isn+1) { + req->acked = 1; + return NULL; + } - /* OK, ACK is valid, create big socket and - * feed this segment to it. It will repeat all - * the tests. THIS SEGMENT MUST MOVE SOCKET TO - * ESTABLISHED STATE. If it will be dropped after - * socket is created, wait for troubles. - */ - child = tp->af_specific->syn_recv_sock(sk, skb, req, NULL); - if (child == NULL) - goto listen_overflow; + /* OK, ACK is valid, create big socket and + * feed this segment to it. It will repeat all + * the tests. THIS SEGMENT MUST MOVE SOCKET TO + * ESTABLISHED STATE. If it will be dropped after + * socket is created, wait for troubles. + */ + child = tp->af_specific->syn_recv_sock(sk, skb, req, NULL); + if (child == NULL) + goto listen_overflow; - sk_set_owner(child, sk->sk_owner); - tcp_synq_unlink(tp, req, prev); - tcp_synq_removed(sk, req); + sk_set_owner(child, sk->sk_owner); + tcp_synq_unlink(tp, req, prev); + tcp_synq_removed(sk, req); - tcp_acceptq_queue(sk, req, child); - return child; + tcp_acceptq_queue(sk, req, child); + return child; -listen_overflow: - if (!sysctl_tcp_abort_on_overflow) { - req->acked = 1; - return NULL; - } + listen_overflow: + if (!sysctl_tcp_abort_on_overflow) { + req->acked = 1; + return NULL; + } -embryonic_reset: - NET_INC_STATS_BH(EmbryonicRsts); - if (!(flg & TCP_FLAG_RST)) - req->class->send_reset(skb); + embryonic_reset: + NET_INC_STATS_BH(LINUX_MIB_EMBRYONICRSTS); + if (!(flg & TCP_FLAG_RST)) + req->class->send_reset(skb); - tcp_synq_drop(sk, req, prev); - return NULL; + tcp_synq_drop(sk, req, prev); + return NULL; } /* @@ -1088,7 +1094,3 @@ EXPORT_SYMBOL(tcp_child_process); EXPORT_SYMBOL(tcp_create_openreq_child); EXPORT_SYMBOL(tcp_timewait_state_process); EXPORT_SYMBOL(tcp_tw_deschedule); - -#ifdef CONFIG_SYSCTL -EXPORT_SYMBOL(sysctl_tcp_tw_recycle); -#endif