]> err.no Git - linux-2.6/blobdiff - net/dccp/input.c
Merge git://git.kernel.org/pub/scm/linux/kernel/git/sam/kbuild
[linux-2.6] / net / dccp / input.c
index 6276b23fc20417daa6e87970408a40c76d7909ba..3560a2a875a05561f2d0b353cb62b6b58095e8b4 100644 (file)
@@ -19,6 +19,9 @@
 #include "ccid.h"
 #include "dccp.h"
 
+/* rate-limit for syncs in reply to sequence-invalid packets; RFC 4340, 7.5.4 */
+int sysctl_dccp_sync_ratelimit __read_mostly = HZ / 8;
+
 static void dccp_fin(struct sock *sk, struct sk_buff *skb)
 {
        sk->sk_shutdown |= RCV_SHUTDOWN;
@@ -102,9 +105,6 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
         *        Update S.GSR, S.SWL, S.SWH
         *        If P.type != Sync,
         *           Update S.GAR
-        *      Otherwise,
-        *        Send Sync packet acknowledging P.seqno
-        *        Drop packet and return
         */
        lswl = dp->dccps_swl;
        lawl = dp->dccps_awl;
@@ -125,6 +125,23 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
                    (ackno != DCCP_PKT_WITHOUT_ACK_SEQ))
                        dp->dccps_gar = ackno;
        } else {
+               unsigned long now = jiffies;
+               /*
+                *   Step 6: Check sequence numbers
+                *      Otherwise,
+                *         If P.type == Reset,
+                *            Send Sync packet acknowledging S.GSR
+                *         Otherwise,
+                *            Send Sync packet acknowledging P.seqno
+                *      Drop packet and return
+                *
+                *   These Syncs are rate-limited as per RFC 4340, 7.5.4:
+                *   at most 1 / (dccp_sync_rate_limit * HZ) Syncs per second.
+                */
+               if (time_before(now, (dp->dccps_rate_last +
+                                     sysctl_dccp_sync_ratelimit)))
+                       return 0;
+
                DCCP_WARN("DCCP: Step 6 failed for %s packet, "
                          "(LSWL(%llu) <= P.seqno(%llu) <= S.SWH(%llu)) and "
                          "(P.ackno %s or LAWL(%llu) <= P.ackno(%llu) <= S.AWH(%llu), "
@@ -135,6 +152,11 @@ static int dccp_check_seqno(struct sock *sk, struct sk_buff *skb)
                                                              : "exists",
                          (unsigned long long) lawl, (unsigned long long) ackno,
                          (unsigned long long) dp->dccps_awh);
+
+               dp->dccps_rate_last = now;
+
+               if (dh->dccph_type == DCCP_PKT_RESET)
+                       seqno = dp->dccps_gsr;
                dccp_send_sync(sk, seqno, DCCP_PKT_SYNC);
                return -1;
        }
@@ -532,11 +554,6 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
                return 0;
        }
 
-       if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
-               dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK);
-               goto discard;
-       }
-
        switch (sk->sk_state) {
        case DCCP_CLOSED:
                dcb->dccpd_reset_code = DCCP_RESET_CODE_NO_CONNECTION;
@@ -567,6 +584,9 @@ int dccp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
                        sk_wake_async(sk, 0, POLL_OUT);
                        break;
                }
+       } else if (unlikely(dh->dccph_type == DCCP_PKT_SYNC)) {
+               dccp_send_sync(sk, dcb->dccpd_seq, DCCP_PKT_SYNCACK);
+               goto discard;
        }
 
        if (!queued) {