MCPcopy Create free account
hub / github.com/F-Stack/f-stack / tcp_dooptions

Function tcp_dooptions

freebsd/netinet/tcp_input.c:3415–3515  ·  view source on GitHub ↗

* Parse TCP options and place in tcpopt. */

Source from the content-addressed store, hash-verified

3413 * Parse TCP options and place in tcpopt.
3414 */
3415void
3416tcp_dooptions(struct tcpopt *to, u_char *cp, int cnt, int flags)
3417{
3418 int opt, optlen;
3419
3420 to->to_flags = 0;
3421 for (; cnt > 0; cnt -= optlen, cp += optlen) {
3422 opt = cp[0];
3423 if (opt == TCPOPT_EOL)
3424 break;
3425 if (opt == TCPOPT_NOP)
3426 optlen = 1;
3427 else {
3428 if (cnt < 2)
3429 break;
3430 optlen = cp[1];
3431 if (optlen < 2 || optlen > cnt)
3432 break;
3433 }
3434 switch (opt) {
3435 case TCPOPT_MAXSEG:
3436 if (optlen != TCPOLEN_MAXSEG)
3437 continue;
3438 if (!(flags & TO_SYN))
3439 continue;
3440 to->to_flags |= TOF_MSS;
3441 bcopy((char *)cp + 2,
3442 (char *)&to->to_mss, sizeof(to->to_mss));
3443 to->to_mss = ntohs(to->to_mss);
3444 break;
3445 case TCPOPT_WINDOW:
3446 if (optlen != TCPOLEN_WINDOW)
3447 continue;
3448 if (!(flags & TO_SYN))
3449 continue;
3450 to->to_flags |= TOF_SCALE;
3451 to->to_wscale = min(cp[2], TCP_MAX_WINSHIFT);
3452 break;
3453 case TCPOPT_TIMESTAMP:
3454 if (optlen != TCPOLEN_TIMESTAMP)
3455 continue;
3456 to->to_flags |= TOF_TS;
3457 bcopy((char *)cp + 2,
3458 (char *)&to->to_tsval, sizeof(to->to_tsval));
3459 to->to_tsval = ntohl(to->to_tsval);
3460 bcopy((char *)cp + 6,
3461 (char *)&to->to_tsecr, sizeof(to->to_tsecr));
3462 to->to_tsecr = ntohl(to->to_tsecr);
3463 break;
3464 case TCPOPT_SIGNATURE:
3465 /*
3466 * In order to reply to a host which has set the
3467 * TCP_SIGNATURE option in its initial SYN, we have
3468 * to record the fact that the option was observed
3469 * here for the syncache code to perform the correct
3470 * response.
3471 */
3472 if (optlen != TCPOLEN_SIGNATURE)

Callers 4

tcp_inputFunction · 0.85
tcp_do_segmentFunction · 0.85
rack_do_segment_nounlockFunction · 0.85
bbr_do_segment_nounlockFunction · 0.85

Calls 1

minFunction · 0.85

Tested by

no test coverage detected