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