nfsd: nfsd should drop CAP_MKNOD for non-root
[safe/jmp/linux-2.6] / net / ipv4 / tcp_minisocks.c
index 463d2b2..f67effb 100644 (file)
@@ -5,8 +5,6 @@
  *
  *             Implementation of the Transmission Control Protocol(TCP).
  *
- * Version:    $Id: tcp_minisocks.c,v 1.15 2002/02/01 22:01:04 davem Exp $
- *
  * Authors:    Ross Biro
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Mark Evans, <evansmp@uhura.aston.ac.uk>
@@ -35,6 +33,8 @@
 #endif
 
 int sysctl_tcp_syncookies __read_mostly = SYNC_INIT;
+EXPORT_SYMBOL(sysctl_tcp_syncookies);
+
 int sysctl_tcp_abort_on_overflow __read_mostly;
 
 struct inet_timewait_death_row tcp_death_row = {
@@ -244,7 +244,7 @@ kill:
        }
 
        if (paws_reject)
-               NET_INC_STATS_BH(LINUX_MIB_PAWSESTABREJECTED);
+               NET_INC_STATS_BH(twsk_net(tw), LINUX_MIB_PAWSESTABREJECTED);
 
        if (!th->rst) {
                /* In this case we must reset the TIMEWAIT timer.
@@ -368,6 +368,12 @@ void tcp_twsk_destructor(struct sock *sk)
 
 EXPORT_SYMBOL_GPL(tcp_twsk_destructor);
 
+static inline void TCP_ECN_openreq_child(struct tcp_sock *tp,
+                                        struct request_sock *req)
+{
+       tp->ecn_flags = inet_rsk(req)->ecn_ok ? TCP_ECN_OK : 0;
+}
+
 /* This is not only more efficient than what we used to do, it eliminates
  * a lot of code duplication between IPv4/IPv6 SYN recv processing. -DaveM
  *
@@ -389,6 +395,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
                newtp->pred_flags = 0;
                newtp->rcv_wup = newtp->copied_seq = newtp->rcv_nxt = treq->rcv_isn + 1;
                newtp->snd_sml = newtp->snd_una = newtp->snd_nxt = treq->snt_isn + 1;
+               newtp->snd_up = treq->snt_isn + 1;
 
                tcp_prequeue_init(newtp);
 
@@ -399,7 +406,6 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
                newicsk->icsk_rto = TCP_TIMEOUT_INIT;
 
                newtp->packets_out = 0;
-               newtp->left_out = 0;
                newtp->retrans_out = 0;
                newtp->sacked_out = 0;
                newtp->fackets_out = 0;
@@ -440,7 +446,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
                newtp->rx_opt.tstamp_ok = ireq->tstamp_ok;
                if ((newtp->rx_opt.sack_ok = ireq->sack_ok) != 0) {
                        if (sysctl_tcp_fack)
-                               newtp->rx_opt.sack_ok |= 2;
+                               tcp_enable_fack(newtp);
                }
                newtp->window_clamp = req->window_clamp;
                newtp->rcv_ssthresh = req->rcv_wnd;
@@ -453,7 +459,8 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
                        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->rx_opt.snd_wscale;
+               newtp->snd_wnd = (ntohs(tcp_hdr(skb)->window) <<
+                                 newtp->rx_opt.snd_wscale);
                newtp->max_window = newtp->snd_wnd;
 
                if (newtp->rx_opt.tstamp_ok) {
@@ -474,7 +481,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
                newtp->rx_opt.mss_clamp = req->mss;
                TCP_ECN_openreq_child(newtp, req);
 
-               TCP_INC_STATS_BH(TCP_MIB_PASSIVEOPENS);
+               TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_PASSIVEOPENS);
        }
        return newsk;
 }
@@ -484,11 +491,11 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
  *     as a request_sock.
  */
 
-struct sock *tcp_check_req(struct sock *sk,struct sk_buff *skb,
+struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
                           struct request_sock *req,
                           struct request_sock **prev)
 {
-       struct tcphdr *th = skb->h.th;
+       const struct tcphdr *th = tcp_hdr(skb);
        __be32 flg = tcp_flag_word(th) & (TCP_FLAG_RST|TCP_FLAG_SYN|TCP_FLAG_ACK);
        int paws_reject = 0;
        struct tcp_options_received tmp_opt;
@@ -530,7 +537,7 @@ struct sock *tcp_check_req(struct sock *sk,struct sk_buff *skb,
                 * Enforce "SYN-ACK" according to figure 8, figure 6
                 * of RFC793, fixed by RFC1122.
                 */
-               req->rsk_ops->rtx_syn_ack(sk, req, NULL);
+               req->rsk_ops->rtx_syn_ack(sk, req);
                return NULL;
        }
 
@@ -603,98 +610,96 @@ struct sock *tcp_check_req(struct sock *sk,struct sk_buff *skb,
                                          tcp_rsk(req)->rcv_isn + 1, tcp_rsk(req)->rcv_isn + 1 + req->rcv_wnd)) {
                /* Out of window: send ACK and drop. */
                if (!(flg & TCP_FLAG_RST))
-                       req->rsk_ops->send_ack(skb, req);
+                       req->rsk_ops->send_ack(sk, skb, req);
                if (paws_reject)
-                       NET_INC_STATS_BH(LINUX_MIB_PAWSESTABREJECTED);
+                       NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_PAWSESTABREJECTED);
                return NULL;
        }
 
        /* In sequence, PAWS is OK. */
 
        if (tmp_opt.saw_tstamp && !after(TCP_SKB_CB(skb)->seq, tcp_rsk(req)->rcv_isn + 1))
-                       req->ts_recent = tmp_opt.rcv_tsval;
+               req->ts_recent = tmp_opt.rcv_tsval;
 
-               if (TCP_SKB_CB(skb)->seq == tcp_rsk(req)->rcv_isn) {
-                       /* Truncate SYN, it is out of window starting
-                          at tcp_rsk(req)->rcv_isn + 1. */
-                       flg &= ~TCP_FLAG_SYN;
-               }
+       if (TCP_SKB_CB(skb)->seq == tcp_rsk(req)->rcv_isn) {
+               /* Truncate SYN, it is out of window starting
+                  at tcp_rsk(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)) {
-                       TCP_INC_STATS_BH(TCP_MIB_ATTEMPTFAILS);
-                       goto embryonic_reset;
-               }
+       /* RFC793: "second check the RST bit" and
+        *         "fourth, check the SYN bit"
+        */
+       if (flg & (TCP_FLAG_RST|TCP_FLAG_SYN)) {
+               TCP_INC_STATS_BH(sock_net(sk), TCP_MIB_ATTEMPTFAILS);
+               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;
-
-               /* If TCP_DEFER_ACCEPT is set, drop bare ACK. */
-               if (inet_csk(sk)->icsk_accept_queue.rskq_defer_accept &&
-                   TCP_SKB_CB(skb)->end_seq == tcp_rsk(req)->rcv_isn + 1) {
-                       inet_rsk(req)->acked = 1;
-                       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;
 
-               /* 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 = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb,
-                                                                req, NULL);
-               if (child == NULL)
-                       goto listen_overflow;
+       /* If TCP_DEFER_ACCEPT is set, drop bare ACK. */
+       if (inet_csk(sk)->icsk_accept_queue.rskq_defer_accept &&
+           TCP_SKB_CB(skb)->end_seq == tcp_rsk(req)->rcv_isn + 1) {
+               inet_rsk(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 = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL);
+       if (child == NULL)
+               goto listen_overflow;
 #ifdef CONFIG_TCP_MD5SIG
-               else {
-                       /* Copy over the MD5 key from the original socket */
-                       struct tcp_md5sig_key *key;
-                       struct tcp_sock *tp = tcp_sk(sk);
-                       key = tp->af_specific->md5_lookup(sk, child);
-                       if (key != NULL) {
-                               /*
-                                * We're using one, so create a matching key on the
-                                * newsk structure. If we fail to get memory then we
-                                * end up not copying the key across. Shucks.
-                                */
-                               char *newkey = kmemdup(key->key, key->keylen,
-                                                      GFP_ATOMIC);
-                               if (newkey) {
-                                       if (!tcp_alloc_md5sig_pool())
-                                               BUG();
-                                       tp->af_specific->md5_add(child, child,
-                                                                newkey,
-                                                                key->keylen);
-                               }
+       else {
+               /* Copy over the MD5 key from the original socket */
+               struct tcp_md5sig_key *key;
+               struct tcp_sock *tp = tcp_sk(sk);
+               key = tp->af_specific->md5_lookup(sk, child);
+               if (key != NULL) {
+                       /*
+                        * We're using one, so create a matching key on the
+                        * newsk structure. If we fail to get memory then we
+                        * end up not copying the key across. Shucks.
+                        */
+                       char *newkey = kmemdup(key->key, key->keylen,
+                                              GFP_ATOMIC);
+                       if (newkey) {
+                               if (!tcp_alloc_md5sig_pool())
+                                       BUG();
+                               tp->af_specific->md5_add(child, child, newkey,
+                                                        key->keylen);
                        }
                }
+       }
 #endif
 
-               inet_csk_reqsk_queue_unlink(sk, req, prev);
-               inet_csk_reqsk_queue_removed(sk, req);
+       inet_csk_reqsk_queue_unlink(sk, req, prev);
+       inet_csk_reqsk_queue_removed(sk, req);
 
-               inet_csk_reqsk_queue_add(sk, req, child);
-               return child;
+       inet_csk_reqsk_queue_add(sk, req, child);
+       return child;
 
-       listen_overflow:
-               if (!sysctl_tcp_abort_on_overflow) {
-                       inet_rsk(req)->acked = 1;
-                       return NULL;
-               }
+listen_overflow:
+       if (!sysctl_tcp_abort_on_overflow) {
+               inet_rsk(req)->acked = 1;
+               return NULL;
+       }
 
-       embryonic_reset:
-               NET_INC_STATS_BH(LINUX_MIB_EMBRYONICRSTS);
-               if (!(flg & TCP_FLAG_RST))
-                       req->rsk_ops->send_reset(sk, skb);
+embryonic_reset:
+       NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
+       if (!(flg & TCP_FLAG_RST))
+               req->rsk_ops->send_reset(sk, skb);
 
-               inet_csk_reqsk_queue_drop(sk, req, prev);
-               return NULL;
+       inet_csk_reqsk_queue_drop(sk, req, prev);
+       return NULL;
 }
 
 /*
@@ -710,8 +715,8 @@ int tcp_child_process(struct sock *parent, struct sock *child,
        int state = child->sk_state;
 
        if (!sock_owned_by_user(child)) {
-               ret = tcp_rcv_state_process(child, skb, skb->h.th, skb->len);
-
+               ret = tcp_rcv_state_process(child, skb, tcp_hdr(skb),
+                                           skb->len);
                /* Wakeup parent, send SIGIO */
                if (state == TCP_SYN_RECV && child->sk_state != state)
                        parent->sk_data_ready(parent, 0);