Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2016 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 | * @file |
| 17 | * @brief BFD global declarations |
| 18 | */ |
| 19 | #ifndef __included_bfd_main_h__ |
| 20 | #define __included_bfd_main_h__ |
| 21 | |
| 22 | #include <vppinfra/timing_wheel.h> |
| 23 | #include <vnet/vnet.h> |
| 24 | #include <vnet/bfd/bfd_protocol.h> |
| 25 | #include <vnet/bfd/bfd_udp.h> |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 26 | #include <vlib/log.h> |
Dave Barach | 1e3417f | 2018-07-25 08:30:27 -0400 | [diff] [blame] | 27 | #include <vppinfra/os.h> |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 28 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 29 | #define foreach_bfd_mode(F) \ |
| 30 | F (asynchronous) \ |
| 31 | F (demand) |
| 32 | |
| 33 | typedef enum |
| 34 | { |
| 35 | #define F(x) BFD_MODE_##x, |
| 36 | foreach_bfd_mode (F) |
| 37 | #undef F |
| 38 | } bfd_mode_e; |
| 39 | |
| 40 | typedef struct |
| 41 | { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 42 | /** global configuration key ID */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 43 | u32 conf_key_id; |
| 44 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 45 | /** keeps track of how many sessions reference this key */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 46 | u32 use_count; |
| 47 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 48 | /** |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 49 | * key data directly usable for bfd purposes - already padded with zeroes |
| 50 | * (so we don't need the actual length) |
| 51 | */ |
| 52 | u8 key[20]; |
| 53 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 54 | /** authentication type for this key */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 55 | bfd_auth_type_e auth_type; |
| 56 | } bfd_auth_key_t; |
| 57 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 58 | #define foreach_bfd_poll_state(F) \ |
| 59 | F (NOT_NEEDED) \ |
| 60 | F (NEEDED) \ |
| 61 | F (IN_PROGRESS) \ |
| 62 | F (IN_PROGRESS_AND_QUEUED) |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 63 | |
| 64 | typedef enum |
| 65 | { |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 66 | #define F(x) BFD_POLL_##x, |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 67 | foreach_bfd_poll_state (F) |
| 68 | #undef F |
| 69 | } bfd_poll_state_e; |
| 70 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 71 | /** |
| 72 | * hop types |
| 73 | */ |
| 74 | #define foreach_bfd_hop(F) \ |
| 75 | F (SINGLE, "single") \ |
| 76 | F (MULTI, "multi") \ |
| 77 | |
| 78 | typedef enum |
| 79 | { |
| 80 | #define F(sym, str) BFD_HOP_TYPE_##sym, |
| 81 | foreach_bfd_hop (F) |
| 82 | #undef F |
| 83 | } bfd_hop_type_e; |
| 84 | |
Klement Sekera | 2bce033 | 2017-02-09 06:03:46 +0100 | [diff] [blame] | 85 | typedef struct bfd_session_s |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 86 | { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 87 | /** index in bfd_main.sessions pool */ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 88 | u32 bs_idx; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 89 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 90 | /** session state */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 91 | bfd_state_e local_state; |
| 92 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 93 | /** remote session state */ |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 94 | bfd_state_e remote_state; |
| 95 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 96 | /** BFD hop type */ |
| 97 | bfd_hop_type_e hop_type; |
| 98 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 99 | /** local diagnostics */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 100 | bfd_diag_code_e local_diag; |
| 101 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 102 | /** remote diagnostics */ |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 103 | bfd_diag_code_e remote_diag; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 104 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 105 | /** local discriminator */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 106 | u32 local_discr; |
| 107 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 108 | /** remote discriminator */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 109 | u32 remote_discr; |
| 110 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 111 | /** configured desired min tx interval (microseconds) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 112 | u32 config_desired_min_tx_usec; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 113 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 114 | /** configured desired min tx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 115 | u64 config_desired_min_tx_clocks; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 116 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 117 | /** effective desired min tx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 118 | u64 effective_desired_min_tx_clocks; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 119 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 120 | /** configured required min rx interval (microseconds) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 121 | u32 config_required_min_rx_usec; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 122 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 123 | /** configured required min rx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 124 | u64 config_required_min_rx_clocks; |
| 125 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 126 | /** effective required min rx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 127 | u64 effective_required_min_rx_clocks; |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 128 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 129 | /** remote min rx interval (microseconds) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 130 | u64 remote_min_rx_usec; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 131 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 132 | /** remote min rx interval (clocks) */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 133 | u64 remote_min_rx_clocks; |
| 134 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 135 | /** remote min echo rx interval (microseconds) */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 136 | u64 remote_min_echo_rx_usec; |
| 137 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 138 | /** remote min echo rx interval (clocks) */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 139 | u64 remote_min_echo_rx_clocks; |
| 140 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 141 | /** remote desired min tx interval (clocks) */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 142 | u64 remote_desired_min_tx_clocks; |
| 143 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 144 | /** configured detect multiplier */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 145 | u8 local_detect_mult; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 146 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 147 | /** 1 if remote system sets demand mode, 0 otherwise */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 148 | u8 remote_demand; |
| 149 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 150 | /** remote detect multiplier */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 151 | u8 remote_detect_mult; |
| 152 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 153 | /** 1 is echo function is active, 0 otherwise */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 154 | u8 echo; |
| 155 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 156 | /** set to value of timer in timing wheel, 0 if never set */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 157 | u64 wheel_time_clocks; |
| 158 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 159 | /** transmit interval */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 160 | u64 transmit_interval_clocks; |
| 161 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 162 | /** next time at which to transmit a packet */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 163 | u64 tx_timeout_clocks; |
| 164 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 165 | /** timestamp of last packet transmitted */ |
Klement Sekera | 3e0a356 | 2016-12-19 09:05:21 +0100 | [diff] [blame] | 166 | u64 last_tx_clocks; |
| 167 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 168 | /** timestamp of last packet received */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 169 | u64 last_rx_clocks; |
| 170 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 171 | /** transmit interval for echo packets */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 172 | u64 echo_transmit_interval_clocks; |
| 173 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 174 | /** next time at which to transmit echo packet */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 175 | u64 echo_tx_timeout_clocks; |
| 176 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 177 | /** timestamp of last echo packet transmitted */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 178 | u64 echo_last_tx_clocks; |
| 179 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 180 | /** timestamp of last echo packet received */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 181 | u64 echo_last_rx_clocks; |
| 182 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 183 | /** secret used for calculating/checking checksum of echo packets */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 184 | u32 echo_secret; |
| 185 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 186 | /** detection time */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 187 | u64 detection_time_clocks; |
| 188 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 189 | /** state info regarding poll sequence */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 190 | bfd_poll_state_e poll_state; |
| 191 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 192 | /** |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 193 | * helper for delayed poll sequence - marks either start of running poll |
| 194 | * sequence or timeout, after which we can start the next poll sequnce |
| 195 | */ |
| 196 | u64 poll_state_start_or_timeout_clocks; |
| 197 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 198 | /** authentication information */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 199 | struct |
| 200 | { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 201 | /** current key in use */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 202 | bfd_auth_key_t *curr_key; |
| 203 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 204 | /** |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 205 | * set to next key to use if delayed switch is enabled - in that case |
| 206 | * the key is switched when first incoming packet is signed with next_key |
| 207 | */ |
| 208 | bfd_auth_key_t *next_key; |
| 209 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 210 | /** sequence number incremented occasionally or always (if meticulous) */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 211 | u32 local_seq_number; |
| 212 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 213 | /** remote sequence number */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 214 | u32 remote_seq_number; |
| 215 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 216 | /** set to 1 if remote sequence number is known */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 217 | u8 remote_seq_number_known; |
| 218 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 219 | /** current key ID sent out in bfd packet */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 220 | u8 curr_bfd_key_id; |
| 221 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 222 | /** key ID to use when switched to next_key */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 223 | u8 next_bfd_key_id; |
| 224 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 225 | /** |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 226 | * set to 1 if delayed action is pending, which might be activation |
| 227 | * of authentication, change of key or deactivation |
| 228 | */ |
| 229 | u8 is_delayed; |
| 230 | } auth; |
| 231 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 232 | /** transport type for this session */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 233 | bfd_transport_e transport; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 234 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 235 | /** union of transport-specific data */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 236 | union |
| 237 | { |
| 238 | bfd_udp_session_t udp; |
| 239 | }; |
| 240 | } bfd_session_t; |
| 241 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 242 | /** |
| 243 | * listener events |
| 244 | */ |
| 245 | #define foreach_bfd_listen_event(F) \ |
| 246 | F (CREATE, "sesion-created") \ |
| 247 | F (UPDATE, "session-updated") \ |
| 248 | F (DELETE, "session-deleted") |
| 249 | |
| 250 | typedef enum |
| 251 | { |
| 252 | #define F(sym, str) BFD_LISTEN_EVENT_##sym, |
| 253 | foreach_bfd_listen_event (F) |
| 254 | #undef F |
| 255 | } bfd_listen_event_e; |
| 256 | |
| 257 | /** |
| 258 | * session nitification call back function type |
| 259 | */ |
| 260 | typedef void (*bfd_notify_fn_t) (bfd_listen_event_e, const bfd_session_t *); |
| 261 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 262 | typedef struct |
| 263 | { |
Dave Barach | 1e3417f | 2018-07-25 08:30:27 -0400 | [diff] [blame] | 264 | /** lock to protect data structures */ |
| 265 | clib_spinlock_t lock; |
| 266 | int lock_recursion_count; |
| 267 | uword owner_thread_index; |
| 268 | |
| 269 | /** Number of event wakeup RPCs in flight. Should be 0 or 1 */ |
| 270 | int bfd_process_wakeup_events_in_flight; |
| 271 | |
| 272 | /** The timestamp of last wakeup event being sent */ |
| 273 | u64 bfd_process_wakeup_event_start_clocks; |
| 274 | |
| 275 | /** The time it took the last wakeup event to make it to handling */ |
| 276 | u64 bfd_process_wakeup_event_delay_clocks; |
| 277 | |
| 278 | /** When the bfd process is supposed to wake up next */ |
| 279 | u64 bfd_process_next_wakeup_clocks; |
| 280 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 281 | /** pool of bfd sessions context data */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 282 | bfd_session_t *sessions; |
| 283 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 284 | /** timing wheel for scheduling timeouts */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 285 | timing_wheel_t wheel; |
| 286 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 287 | /** timing wheel inaccuracy, in clocks */ |
Klement Sekera | 637b9c4 | 2016-12-08 05:19:14 +0100 | [diff] [blame] | 288 | u64 wheel_inaccuracy; |
| 289 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 290 | /** hashmap - bfd session by discriminator */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 291 | u32 *session_by_disc; |
| 292 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 293 | /** background process node index */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 294 | u32 bfd_process_node_index; |
| 295 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 296 | /** convenience variables */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 297 | vlib_main_t *vlib_main; |
| 298 | vnet_main_t *vnet_main; |
| 299 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 300 | /** cpu clocks per second */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 301 | f64 cpu_cps; |
| 302 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 303 | /** default desired min tx in clocks */ |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 304 | u64 default_desired_min_tx_clocks; |
| 305 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 306 | /** minimum required min rx while echo function is active - clocks */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 307 | u64 min_required_min_rx_while_echo_clocks; |
| 308 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 309 | /** for generating random numbers */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 310 | u32 random_seed; |
| 311 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 312 | /** pool of authentication keys */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 313 | bfd_auth_key_t *auth_keys; |
| 314 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 315 | /** hashmap - index in pool auth_keys by conf_key_id */ |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 316 | u32 *auth_key_by_conf_key_id; |
| 317 | |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 318 | /** vector of callback notification functions */ |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 319 | bfd_notify_fn_t *listeners; |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 320 | |
| 321 | /** log class */ |
| 322 | vlib_log_class_t log_class; |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 323 | } bfd_main_t; |
| 324 | |
| 325 | extern bfd_main_t bfd_main; |
| 326 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 327 | /** Packet counters */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 328 | #define foreach_bfd_error(F) \ |
| 329 | F (NONE, "good bfd packets (processed)") \ |
| 330 | F (BAD, "invalid bfd packets") \ |
| 331 | F (DISABLED, "bfd packets received on disabled interfaces") |
| 332 | |
| 333 | typedef enum |
| 334 | { |
| 335 | #define F(sym, str) BFD_ERROR_##sym, |
| 336 | foreach_bfd_error (F) |
| 337 | #undef F |
| 338 | BFD_N_ERROR, |
| 339 | } bfd_error_t; |
| 340 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 341 | /** bfd packet trace capture */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 342 | typedef struct |
| 343 | { |
| 344 | u32 len; |
| 345 | u8 data[400]; |
| 346 | } bfd_input_trace_t; |
| 347 | |
| 348 | enum |
| 349 | { |
| 350 | BFD_EVENT_RESCHEDULE = 1, |
| 351 | BFD_EVENT_NEW_SESSION, |
Klement Sekera | a57a970 | 2017-02-02 06:58:07 +0100 | [diff] [blame] | 352 | BFD_EVENT_CONFIG_CHANGED, |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 353 | } bfd_process_event_e; |
| 354 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 355 | /* *INDENT-OFF* */ |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 356 | /** echo packet structure */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 357 | typedef CLIB_PACKED (struct { |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 358 | /** local discriminator */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 359 | u32 discriminator; |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 360 | /** expire time of this packet - clocks */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 361 | u64 expire_time_clocks; |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 362 | /** checksum - based on discriminator, local secret and expire time */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 363 | u64 checksum; |
| 364 | }) bfd_echo_pkt_t; |
| 365 | /* *INDENT-ON* */ |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 366 | |
Dave Barach | 1e3417f | 2018-07-25 08:30:27 -0400 | [diff] [blame] | 367 | static inline void |
| 368 | bfd_lock (bfd_main_t * bm) |
| 369 | { |
| 370 | uword my_thread_index = __os_thread_index; |
| 371 | |
| 372 | if (bm->owner_thread_index == my_thread_index |
| 373 | && bm->lock_recursion_count > 0) |
| 374 | { |
| 375 | bm->lock_recursion_count++; |
| 376 | return; |
| 377 | } |
| 378 | |
| 379 | clib_spinlock_lock_if_init (&bm->lock); |
| 380 | bm->lock_recursion_count = 1; |
| 381 | bm->owner_thread_index = my_thread_index; |
| 382 | } |
| 383 | |
| 384 | static inline void |
| 385 | bfd_unlock (bfd_main_t * bm) |
| 386 | { |
| 387 | uword my_thread_index = __os_thread_index; |
| 388 | ASSERT (bm->owner_thread_index == my_thread_index); |
| 389 | |
| 390 | if (bm->lock_recursion_count > 1) |
| 391 | { |
| 392 | bm->lock_recursion_count--; |
| 393 | return; |
| 394 | } |
| 395 | bm->lock_recursion_count = 0; |
| 396 | bm->owner_thread_index = ~0; |
| 397 | clib_spinlock_unlock_if_init (&bm->lock); |
| 398 | } |
| 399 | |
Dave Barach | 1e3417f | 2018-07-25 08:30:27 -0400 | [diff] [blame] | 400 | static inline void |
| 401 | bfd_lock_check (bfd_main_t * bm) |
| 402 | { |
| 403 | if (PREDICT_FALSE (bm->lock_recursion_count < 1)) |
Dave Barach | ccf444d | 2018-09-14 09:27:42 -0400 | [diff] [blame] | 404 | clib_warning ("lock check failure"); |
Dave Barach | 1e3417f | 2018-07-25 08:30:27 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 407 | u8 *bfd_input_format_trace (u8 * s, va_list * args); |
| 408 | bfd_session_t *bfd_get_session (bfd_main_t * bm, bfd_transport_e t); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 409 | void bfd_put_session (bfd_main_t * bm, bfd_session_t * bs); |
| 410 | bfd_session_t *bfd_find_session_by_idx (bfd_main_t * bm, uword bs_idx); |
| 411 | bfd_session_t *bfd_find_session_by_disc (bfd_main_t * bm, u32 disc); |
| 412 | void bfd_session_start (bfd_main_t * bm, bfd_session_t * bs); |
| 413 | void bfd_consume_pkt (bfd_main_t * bm, const bfd_pkt_t * bfd, u32 bs_idx); |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 414 | int bfd_consume_echo_pkt (bfd_main_t * bm, vlib_buffer_t * b); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 415 | int bfd_verify_pkt_common (const bfd_pkt_t * pkt); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 416 | int bfd_verify_pkt_auth (const bfd_pkt_t * pkt, u16 pkt_size, |
| 417 | bfd_session_t * bs); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 418 | void bfd_event (bfd_main_t * bm, bfd_session_t * bs); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 419 | void bfd_init_final_control_frame (vlib_main_t * vm, vlib_buffer_t * b, |
Klement Sekera | e50e856 | 2017-04-04 16:19:48 +0200 | [diff] [blame] | 420 | bfd_main_t * bm, bfd_session_t * bs, |
| 421 | int is_local); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 422 | u8 *format_bfd_session (u8 * s, va_list * args); |
Damjan Marion | 07a3857 | 2018-01-21 06:44:18 -0800 | [diff] [blame] | 423 | u8 *format_bfd_session_brief (u8 * s, va_list * args); |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 424 | u8 *format_bfd_auth_key (u8 * s, va_list * args); |
Klement Sekera | b17dd96 | 2017-01-09 07:43:48 +0100 | [diff] [blame] | 425 | void bfd_session_set_flags (bfd_session_t * bs, u8 admin_up_down); |
| 426 | unsigned bfd_auth_type_supported (bfd_auth_type_e auth_type); |
| 427 | vnet_api_error_t bfd_auth_activate (bfd_session_t * bs, u32 conf_key_id, |
| 428 | u8 bfd_key_id, u8 is_delayed); |
| 429 | vnet_api_error_t bfd_auth_deactivate (bfd_session_t * bs, u8 is_delayed); |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 430 | vnet_api_error_t bfd_session_set_params (bfd_main_t * bm, bfd_session_t * bs, |
| 431 | u32 desired_min_tx_usec, |
| 432 | u32 required_min_rx_usec, |
| 433 | u8 detect_mult); |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 434 | |
Klement Sekera | 7388448 | 2017-02-23 09:26:30 +0100 | [diff] [blame] | 435 | u32 bfd_clocks_to_usec (const bfd_main_t * bm, u64 clocks); |
| 436 | const char *bfd_poll_state_string (bfd_poll_state_e state); |
| 437 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 438 | #define USEC_PER_MS 1000LL |
| 439 | #define USEC_PER_SECOND (1000 * USEC_PER_MS) |
| 440 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 441 | /** default, slow transmission interval for BFD packets, per spec at least 1s */ |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 442 | #define BFD_DEFAULT_DESIRED_MIN_TX_USEC USEC_PER_SECOND |
| 443 | |
Klement Sekera | b16bfe3 | 2017-02-28 11:56:48 +0100 | [diff] [blame] | 444 | /** |
Klement Sekera | 239790f | 2017-02-16 10:53:53 +0100 | [diff] [blame] | 445 | * minimum required min rx set locally when echo function is used, per spec |
| 446 | * should be set to at least 1s |
| 447 | */ |
| 448 | #define BFD_REQUIRED_MIN_RX_USEC_WHILE_ECHO USEC_PER_SECOND |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 449 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 450 | /** |
| 451 | * Register a callback function to receive session notifications. |
| 452 | */ |
| 453 | void bfd_register_listener (bfd_notify_fn_t fn); |
| 454 | |
Klement Sekera | 0e3c0de | 2016-09-29 14:43:44 +0200 | [diff] [blame] | 455 | #endif /* __included_bfd_main_h__ */ |
| 456 | |
| 457 | /* |
| 458 | * fd.io coding-style-patch-verification: ON |
| 459 | * |
| 460 | * Local Variables: |
| 461 | * eval: (c-set-style "gnu") |
| 462 | * End: |
| 463 | */ |