Florin Coras | 999840c | 2020-03-18 20:31:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #ifndef SRC_VNET_TCP_TCP_SACK_H_ |
| 17 | #define SRC_VNET_TCP_TCP_SACK_H_ |
| 18 | |
| 19 | #include <vnet/tcp/tcp_types.h> |
| 20 | |
| 21 | always_inline u32 |
| 22 | scoreboard_hole_index (sack_scoreboard_t * sb, sack_scoreboard_hole_t * hole) |
| 23 | { |
| 24 | ASSERT (!pool_is_free_index (sb->holes, hole - sb->holes)); |
| 25 | return hole - sb->holes; |
| 26 | } |
| 27 | |
| 28 | always_inline u32 |
| 29 | scoreboard_hole_bytes (sack_scoreboard_hole_t * hole) |
| 30 | { |
| 31 | return hole->end - hole->start; |
| 32 | } |
| 33 | |
| 34 | always_inline sack_scoreboard_hole_t * |
| 35 | scoreboard_get_hole (sack_scoreboard_t * sb, u32 index) |
| 36 | { |
| 37 | if (index != TCP_INVALID_SACK_HOLE_INDEX) |
| 38 | return pool_elt_at_index (sb->holes, index); |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | always_inline sack_scoreboard_hole_t * |
| 43 | scoreboard_next_hole (sack_scoreboard_t * sb, sack_scoreboard_hole_t * hole) |
| 44 | { |
| 45 | if (hole->next != TCP_INVALID_SACK_HOLE_INDEX) |
| 46 | return pool_elt_at_index (sb->holes, hole->next); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | always_inline sack_scoreboard_hole_t * |
| 51 | scoreboard_prev_hole (sack_scoreboard_t * sb, sack_scoreboard_hole_t * hole) |
| 52 | { |
| 53 | if (hole->prev != TCP_INVALID_SACK_HOLE_INDEX) |
| 54 | return pool_elt_at_index (sb->holes, hole->prev); |
| 55 | return 0; |
| 56 | } |
| 57 | |
| 58 | always_inline sack_scoreboard_hole_t * |
| 59 | scoreboard_first_hole (sack_scoreboard_t * sb) |
| 60 | { |
| 61 | if (sb->head != TCP_INVALID_SACK_HOLE_INDEX) |
| 62 | return pool_elt_at_index (sb->holes, sb->head); |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | always_inline sack_scoreboard_hole_t * |
| 67 | scoreboard_last_hole (sack_scoreboard_t * sb) |
| 68 | { |
| 69 | if (sb->tail != TCP_INVALID_SACK_HOLE_INDEX) |
| 70 | return pool_elt_at_index (sb->holes, sb->tail); |
| 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | #if TCP_SCOREBOARD_TRACE |
| 75 | #define tcp_scoreboard_trace_add(_tc, _ack) \ |
| 76 | { \ |
| 77 | static u64 _group = 0; \ |
| 78 | sack_scoreboard_t *_sb = &_tc->sack_sb; \ |
| 79 | sack_block_t *_sack, *_sacks; \ |
| 80 | scoreboard_trace_elt_t *_elt; \ |
| 81 | int i; \ |
| 82 | _group++; \ |
| 83 | _sacks = _tc->rcv_opts.sacks; \ |
| 84 | for (i = 0; i < vec_len (_sacks); i++) \ |
| 85 | { \ |
| 86 | _sack = &_sacks[i]; \ |
| 87 | vec_add2 (_sb->trace, _elt, 1); \ |
| 88 | _elt->start = _sack->start; \ |
| 89 | _elt->end = _sack->end; \ |
| 90 | _elt->ack = _elt->end == _ack ? _ack : 0; \ |
| 91 | _elt->snd_una_max = _elt->end == _ack ? _tc->snd_una_max : 0; \ |
| 92 | _elt->group = _group; \ |
| 93 | } \ |
| 94 | } |
| 95 | #else |
| 96 | #define tcp_scoreboard_trace_add(_tc, _ack) |
| 97 | #endif |
| 98 | |
| 99 | sack_scoreboard_hole_t *scoreboard_next_rxt_hole (sack_scoreboard_t * sb, |
| 100 | sack_scoreboard_hole_t * |
| 101 | start, u8 have_sent_1_smss, |
| 102 | u8 * can_rescue, |
| 103 | u8 * snd_limited); |
| 104 | void scoreboard_clear (sack_scoreboard_t * sb); |
| 105 | void scoreboard_clear_reneging (sack_scoreboard_t * sb, u32 start, u32 end); |
| 106 | void scoreboard_init (sack_scoreboard_t * sb); |
| 107 | void scoreboard_init_rxt (sack_scoreboard_t * sb, u32 snd_una); |
| 108 | |
| 109 | format_function_t format_tcp_scoreboard; |
| 110 | |
| 111 | /* Made public for unit testing only */ |
| 112 | void tcp_update_sack_list (tcp_connection_t * tc, u32 start, u32 end); |
| 113 | u32 tcp_sack_list_bytes (tcp_connection_t * tc); |
| 114 | void tcp_rcv_sacks (tcp_connection_t * tc, u32 ack); |
| 115 | u8 *tcp_scoreboard_replay (u8 * s, tcp_connection_t * tc, u8 verbose); |
| 116 | u8 tcp_scoreboard_is_sane_post_recovery (tcp_connection_t * tc); |
| 117 | |
| 118 | #endif /* SRC_VNET_TCP_TCP_SACK_H_ */ |
| 119 | |
| 120 | /* |
| 121 | * fd.io coding-style-patch-verification: ON |
| 122 | * |
| 123 | * Local Variables: |
| 124 | * eval: (c-set-style "gnu") |
| 125 | * End: |
| 126 | */ |