* Return values: * -1 the cookie is invalid and no valid cookie is available * 0 the cookie is invalid and the latest cookie has been returned * 1 the cookie is valid and the latest cookie has been returned */
| 609 | * 1 the cookie is valid and the latest cookie has been returned |
| 610 | */ |
| 611 | int |
| 612 | tcp_fastopen_check_cookie(struct in_conninfo *inc, uint8_t *cookie, |
| 613 | unsigned int len, uint64_t *latest_cookie) |
| 614 | { |
| 615 | struct rm_priotracker tracker; |
| 616 | unsigned int i, key_index; |
| 617 | int rv; |
| 618 | uint64_t cur_cookie; |
| 619 | |
| 620 | if (V_tcp_fastopen_acceptany) { |
| 621 | *latest_cookie = 0; |
| 622 | return (1); |
| 623 | } |
| 624 | |
| 625 | TCP_FASTOPEN_KEYS_RLOCK(&tracker); |
| 626 | if (len != TCP_FASTOPEN_COOKIE_LEN) { |
| 627 | if (V_tcp_fastopen_numkeys > 0) { |
| 628 | *latest_cookie = |
| 629 | tcp_fastopen_make_cookie( |
| 630 | V_tcp_fastopen_keys.key[V_tcp_fastopen_keys.newest], |
| 631 | inc); |
| 632 | rv = 0; |
| 633 | } else |
| 634 | rv = -1; |
| 635 | goto out; |
| 636 | } |
| 637 | |
| 638 | /* |
| 639 | * Check against each available key, from newest to oldest. |
| 640 | */ |
| 641 | key_index = V_tcp_fastopen_keys.newest; |
| 642 | for (i = 0; i < V_tcp_fastopen_numkeys; i++) { |
| 643 | cur_cookie = |
| 644 | tcp_fastopen_make_cookie(V_tcp_fastopen_keys.key[key_index], |
| 645 | inc); |
| 646 | if (i == 0) |
| 647 | *latest_cookie = cur_cookie; |
| 648 | rv = tcp_fastopen_find_cookie_match_locked(cookie, &cur_cookie); |
| 649 | if (rv) |
| 650 | goto out; |
| 651 | if (key_index == 0) |
| 652 | key_index = TCP_FASTOPEN_MAX_KEYS - 1; |
| 653 | else |
| 654 | key_index--; |
| 655 | } |
| 656 | rv = 0; |
| 657 | |
| 658 | out: |
| 659 | TCP_FASTOPEN_KEYS_RUNLOCK(&tracker); |
| 660 | return (rv); |
| 661 | } |
| 662 | |
| 663 | static int |
| 664 | sysctl_net_inet_tcp_fastopen_autokey(SYSCTL_HANDLER_ARGS) |
no test coverage detected