nfsd4: set shorter timeout
[safe/jmp/linux-2.6] / net / dccp / minisocks.c
index 5324fca..5ca49ce 100644 (file)
@@ -10,8 +10,8 @@
  *     2 of the License, or (at your option) any later version.
  */
 
-#include <linux/config.h>
 #include <linux/dccp.h>
+#include <linux/kernel.h>
 #include <linux/skbuff.h>
 #include <linux/timer.h>
 
 struct inet_timewait_death_row dccp_death_row = {
        .sysctl_max_tw_buckets = NR_FILE * 2,
        .period         = DCCP_TIMEWAIT_LEN / INET_TWDR_TWKILL_SLOTS,
-       .death_lock     = SPIN_LOCK_UNLOCKED,
+       .death_lock     = __SPIN_LOCK_UNLOCKED(dccp_death_row.death_lock),
        .hashinfo       = &dccp_hashinfo,
        .tw_timer       = TIMER_INITIALIZER(inet_twdr_hangman, 0,
                                            (unsigned long)&dccp_death_row),
        .twkill_work    = __WORK_INITIALIZER(dccp_death_row.twkill_work,
-                                            inet_twdr_twkill_work,
-                                            &dccp_death_row),
+                                            inet_twdr_twkill_work),
 /* Short-time timewait calendar */
 
        .twcal_hand     = -1,
@@ -84,8 +83,7 @@ void dccp_time_wait(struct sock *sk, int state, int timeo)
                 * socket up.  We've got bigger problems than
                 * non-graceful socket closings.
                 */
-               LIMIT_NETDEBUG(KERN_INFO "DCCP: time wait bucket "
-                                        "table overflow\n");
+               DCCP_WARN("time wait bucket table overflow\n");
        }
 
        dccp_done(sk);
@@ -98,69 +96,38 @@ struct sock *dccp_create_openreq_child(struct sock *sk,
        /*
         * Step 3: Process LISTEN state
         *
-        * // Generate a new socket and switch to that socket
-        * Set S := new socket for this port pair
+        *   (* Generate a new socket and switch to that socket *)
+        *   Set S := new socket for this port pair
         */
        struct sock *newsk = inet_csk_clone(sk, req, GFP_ATOMIC);
 
        if (newsk != NULL) {
-               const struct dccp_request_sock *dreq = dccp_rsk(req);
-               struct inet_connection_sock *newicsk = inet_csk(sk);
+               struct dccp_request_sock *dreq = dccp_rsk(req);
+               struct inet_connection_sock *newicsk = inet_csk(newsk);
                struct dccp_sock *newdp = dccp_sk(newsk);
 
-               newdp->dccps_role          = DCCP_ROLE_SERVER;
-               newdp->dccps_hc_rx_ackvec  = NULL;
-               newdp->dccps_service_list  = NULL;
-               newdp->dccps_service       = dreq->dreq_service;
-               newicsk->icsk_rto          = DCCP_TIMEOUT_INIT;
-               do_gettimeofday(&newdp->dccps_epoch);
-
-               if (dccp_feat_clone(sk, newsk))
-                       goto out_free;
-
-               if (newdp->dccps_options.dccpo_send_ack_vector) {
-                       newdp->dccps_hc_rx_ackvec =
-                                               dccp_ackvec_alloc(GFP_ATOMIC);
-                       if (unlikely(newdp->dccps_hc_rx_ackvec == NULL))
-                               goto out_free;
-               }
-
-               newdp->dccps_hc_rx_ccid =
-                           ccid_hc_rx_new(newdp->dccps_options.dccpo_rx_ccid,
-                                          newsk, GFP_ATOMIC);
-               newdp->dccps_hc_tx_ccid =
-                           ccid_hc_tx_new(newdp->dccps_options.dccpo_tx_ccid,
-                                          newsk, GFP_ATOMIC);
-               if (unlikely(newdp->dccps_hc_rx_ccid == NULL ||
-                            newdp->dccps_hc_tx_ccid == NULL)) {
-                       dccp_ackvec_free(newdp->dccps_hc_rx_ackvec);
-                       ccid_hc_rx_delete(newdp->dccps_hc_rx_ccid, newsk);
-                       ccid_hc_tx_delete(newdp->dccps_hc_tx_ccid, newsk);
-out_free:
-                       /* It is still raw copy of parent, so invalidate
-                        * destructor and make plain sk_free() */
-                       newsk->sk_destruct = NULL;
-                       sk_free(newsk);
-                       return NULL;
-               }
+               newdp->dccps_role           = DCCP_ROLE_SERVER;
+               newdp->dccps_hc_rx_ackvec   = NULL;
+               newdp->dccps_service_list   = NULL;
+               newdp->dccps_service        = dreq->dreq_service;
+               newdp->dccps_timestamp_echo = dreq->dreq_timestamp_echo;
+               newdp->dccps_timestamp_time = dreq->dreq_timestamp_time;
+               newicsk->icsk_rto           = DCCP_TIMEOUT_INIT;
 
+               INIT_LIST_HEAD(&newdp->dccps_featneg);
                /*
                 * Step 3: Process LISTEN state
                 *
-                *      Choose S.ISS (initial seqno) or set from Init Cookie
-                *      Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init
-                *      Cookie
+                *    Choose S.ISS (initial seqno) or set from Init Cookies
+                *    Initialize S.GAR := S.ISS
+                *    Set S.ISR, S.GSR, S.SWL, S.SWH from packet or Init Cookies
                 */
+               newdp->dccps_gar = newdp->dccps_iss = dreq->dreq_iss;
+               dccp_update_gss(newsk, dreq->dreq_iss);
 
-               /* See dccp_v4_conn_request */
-               newdp->dccps_options.dccpo_sequence_window = req->rcv_wnd;
-
-               newdp->dccps_gar = newdp->dccps_isr = dreq->dreq_isr;
+               newdp->dccps_isr = dreq->dreq_isr;
                dccp_update_gsr(newsk, dreq->dreq_isr);
 
-               newdp->dccps_iss = dreq->dreq_iss;
-               dccp_update_gss(newsk, dreq->dreq_iss);
-
                /*
                 * SWL and AWL are initially adjusted so that they are not less than
                 * the initial Sequence Numbers received and sent, respectively:
@@ -174,6 +141,17 @@ out_free:
                dccp_set_seqno(&newdp->dccps_awl,
                               max48(newdp->dccps_awl, newdp->dccps_iss));
 
+               /*
+                * Activate features after initialising the sequence numbers,
+                * since CCID initialisation may depend on GSS, ISR, ISS etc.
+                */
+               if (dccp_feat_activate_values(newsk, &dreq->dreq_featneg)) {
+                       /* It is still raw copy of parent, so invalidate
+                        * destructor and make plain sk_free() */
+                       newsk->sk_destruct = NULL;
+                       sk_free(newsk);
+                       return NULL;
+               }
                dccp_init_xmit_timers(newsk);
 
                DCCP_INC_STATS_BH(DCCP_MIB_PASSIVEOPENS);
@@ -183,7 +161,7 @@ out_free:
 
 EXPORT_SYMBOL_GPL(dccp_create_openreq_child);
 
-/* 
+/*
  * Process an incoming packet for RESPOND sockets represented
  * as an request_sock.
  */
@@ -192,19 +170,21 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
                            struct request_sock **prev)
 {
        struct sock *child = NULL;
+       struct dccp_request_sock *dreq = dccp_rsk(req);
 
        /* Check for retransmitted REQUEST */
        if (dccp_hdr(skb)->dccph_type == DCCP_PKT_REQUEST) {
-               if (after48(DCCP_SKB_CB(skb)->dccpd_seq,
-                           dccp_rsk(req)->dreq_isr)) {
-                       struct dccp_request_sock *dreq = dccp_rsk(req);
 
+               if (after48(DCCP_SKB_CB(skb)->dccpd_seq, dreq->dreq_isr)) {
                        dccp_pr_debug("Retransmitted REQUEST\n");
-                       /* Send another RESPONSE packet */
-                       dccp_set_seqno(&dreq->dreq_iss, dreq->dreq_iss + 1);
-                       dccp_set_seqno(&dreq->dreq_isr,
-                                      DCCP_SKB_CB(skb)->dccpd_seq);
-                       req->rsk_ops->rtx_syn_ack(sk, req, NULL);
+                       dreq->dreq_isr = DCCP_SKB_CB(skb)->dccpd_seq;
+                       /*
+                        * Send another RESPONSE packet
+                        * To protect against Request floods, increment retrans
+                        * counter (backoff, monitored by dccp_response_timer).
+                        */
+                       req->retrans++;
+                       req->rsk_ops->rtx_syn_ack(sk, req);
                }
                /* Network Duplicate, discard packet */
                return NULL;
@@ -217,22 +197,22 @@ struct sock *dccp_check_req(struct sock *sk, struct sk_buff *skb,
                goto drop;
 
        /* Invalid ACK */
-       if (DCCP_SKB_CB(skb)->dccpd_ack_seq != dccp_rsk(req)->dreq_iss) {
+       if (DCCP_SKB_CB(skb)->dccpd_ack_seq != dreq->dreq_iss) {
                dccp_pr_debug("Invalid ACK number: ack_seq=%llu, "
                              "dreq_iss=%llu\n",
                              (unsigned long long)
                              DCCP_SKB_CB(skb)->dccpd_ack_seq,
-                             (unsigned long long)
-                             dccp_rsk(req)->dreq_iss);
+                             (unsigned long long) dreq->dreq_iss);
                goto drop;
        }
 
+       if (dccp_parse_options(sk, dreq, skb))
+                goto drop;
+
        child = inet_csk(sk)->icsk_af_ops->syn_recv_sock(sk, skb, req, NULL);
        if (child == NULL)
                goto listen_overflow;
 
-       /* FIXME: deal with options */
-
        inet_csk_reqsk_queue_unlink(sk, req, prev);
        inet_csk_reqsk_queue_removed(sk, req);
        inet_csk_reqsk_queue_add(sk, req, child);
@@ -243,7 +223,7 @@ listen_overflow:
        DCCP_SKB_CB(skb)->dccpd_reset_code = DCCP_RESET_CODE_TOO_BUSY;
 drop:
        if (dccp_hdr(skb)->dccph_type != DCCP_PKT_RESET)
-               req->rsk_ops->send_reset(skb);
+               req->rsk_ops->send_reset(sk, skb);
 
        inet_csk_reqsk_queue_drop(sk, req, prev);
        goto out;
@@ -283,3 +263,27 @@ int dccp_child_process(struct sock *parent, struct sock *child,
 }
 
 EXPORT_SYMBOL_GPL(dccp_child_process);
+
+void dccp_reqsk_send_ack(struct sock *sk, struct sk_buff *skb,
+                        struct request_sock *rsk)
+{
+       DCCP_BUG("DCCP-ACK packets are never sent in LISTEN/RESPOND state");
+}
+
+EXPORT_SYMBOL_GPL(dccp_reqsk_send_ack);
+
+int dccp_reqsk_init(struct request_sock *req,
+                   struct dccp_sock const *dp, struct sk_buff const *skb)
+{
+       struct dccp_request_sock *dreq = dccp_rsk(req);
+
+       inet_rsk(req)->rmt_port   = dccp_hdr(skb)->dccph_sport;
+       inet_rsk(req)->loc_port   = dccp_hdr(skb)->dccph_dport;
+       inet_rsk(req)->acked      = 0;
+       dreq->dreq_timestamp_echo = 0;
+
+       /* inherit feature negotiation options from listening socket */
+       return dccp_feat_clone_list(&dp->dccps_featneg, &dreq->dreq_featneg);
+}
+
+EXPORT_SYMBOL_GPL(dccp_reqsk_init);