Why are you not comfortable with your own massage headers-and syn-cookies?

Source: Internet
Author: User
Tags diff

Because the feeling of the hand shares part of the feeling that it should belong to the head, it would be better to find something to replace the hand.
_ U32 secure_tcp_syn_cookie (_ u32 saddr, _ u32 daddr, _ 2010sport,
_ 2010dport, _ u32 sseq, _ u32 count, _ u32 data)
{
_ U32 TMP [16 + hash_buffer_size + hash_extra_size];
_ U32 seq;
... // Lazy Initialization
Memcpy (TMP + 3, syncookie_secret [0], sizeof (syncookie_secret [0]);
TMP [0] = saddr;
TMP [1] = daddr;
TMP [2] = (sport <16) + dport;
Hash_transform (TMP + 16, TMP );
SEQ = TMP [17] + sseq + (count <cookiebits); // Add the SYN serial number to the digest value calculated based on 4 elements, and add the current jiffies to the high 8 bit, SEQ is set to S, sseq is set to SS
Memcpy (TMP + 3, syncookie_secret [1], sizeof (syncookie_secret [1]);
TMP [0] = saddr;
TMP [1] = daddr;
TMP [2] = (sport <16) + dport;
TMP [3] = count;
Hash_transform (TMP + 16, TMP); // calculate another TMP [17]
Return seq + (TMP [17] + Data) & cookiemask); // calculate the final syn-cookie without affecting the 8-bit height and set it to K
}
_ U32 check_tcp_syn_cookie (_ u32 cookie, _ u32 saddr, _ u32 daddr, _ 2010sport,
_ 2010dport, _ u32 sseq, _ u32 count, _ u32 maxdiff)
{
_ U32 TMP [16 + hash_buffer_size + hash_extra_size];
_ U32 diff;
... // And lazy Initialization
Memcpy (TMP + 3, syncookie_secret [0], sizeof (syncookie_secret [0]);
TMP [0] = saddr;
TMP [1] = daddr;
TMP [2] = (sport <16) + dport;
Hash_transform (TMP + 16, TMP );
Cookie-= TMP [17] + sseq; // cookie is K, which is the digest calculated by the SS and 4 elements.
Diff = (count-(cookie> cookiebits) & (_ u32)-1> cookiebits );
If (diff> = maxdiff) // obtain the time when the SYN packet arrives from the top 8 bits. If it takes too long for ACK to arrive, it is regarded as an abnormal phenomenon and discarded.
Return (_ u32)-1;
Memcpy (TMP + 3, syncookie_secret [1], sizeof (syncookie_secret [1]);
TMP [0] = saddr;
TMP [1] = daddr;
TMP [2] = (sport <16) + dport;
TMP [3] = count-diff; get the jiffies of the original SYN Packet
Hash_transform (TMP + 16, TMP );
Return (cookie-TMP [17]) & cookiemask; // finally get the data
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.