/* * Copyright (c) 2011-2016 Cisco and/or its affiliates. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at: * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file * @brief BFD global declarations */ #ifndef __included_bfd_main_h__ #define __included_bfd_main_h__ #include #include #include #include #include #include #define foreach_bfd_mode(F) \ F (asynchronous) \ F (demand) typedef enum { #define F(x) BFD_MODE_##x, foreach_bfd_mode (F) #undef F } bfd_mode_e; typedef struct { /** global configuration key ID */ u32 conf_key_id; /** keeps track of how many sessions reference this key */ u32 use_count; /** * key data directly usable for bfd purposes - already padded with zeroes * (so we don't need the actual length) */ u8 key[20]; /** authentication type for this key */ bfd_auth_type_e auth_type; } bfd_auth_key_t; #define foreach_bfd_poll_state(F) \ F (NOT_NEEDED) \ F (NEEDED) \ F (IN_PROGRESS) \ F (IN_PROGRESS_AND_QUEUED) typedef enum { #define F(x) BFD_POLL_##x, foreach_bfd_poll_state (F) #undef F } bfd_poll_state_e; /** * hop types */ #define foreach_bfd_hop(F) \ F (SINGLE, "single") \ F (MULTI, "multi") \ typedef enum { #define F(sym, str) BFD_HOP_TYPE_##sym, foreach_bfd_hop (F) #undef F } bfd_hop_type_e; typedef struct bfd_session_s { /** index in bfd_main.sessions pool */ u32 bs_idx; /** session state */ bfd_state_e local_state; /** remote session state */ bfd_state_e remote_state; /** BFD hop type */ bfd_hop_type_e hop_type; /** local diagnostics */ bfd_diag_code_e local_diag; /** remote diagnostics */ bfd_diag_code_e remote_diag; /** local discriminator */ u32 local_discr; /** remote discriminator */ u32 remote_discr; /** configured desired min tx interval (microseconds) */ u32 config_desired_min_tx_usec; /** configured desired min tx interval (clocks) */ u64 config_desired_min_tx_clocks; /** effective desired min tx interval (clocks) */ u64 effective_desired_min_tx_clocks; /** configured required min rx interval (microseconds) */ u32 config_required_min_rx_usec; /** configured required min rx interval (clocks) */ u64 config_required_min_rx_clocks; /** effective required min rx interval (clocks) */ u64 effective_required_min_rx_clocks; /** remote min rx interval (microseconds) */ u64 remote_min_rx_usec; /** remote min rx interval (clocks) */ u64 remote_min_rx_clocks; /** remote min echo rx interval (microseconds) */ u64 remote_min_echo_rx_usec; /** remote min echo rx interval (clocks) */ u64 remote_min_echo_rx_clocks; /** remote desired min tx interval (clocks) */ u64 remote_desired_min_tx_clocks; /** configured detect multiplier */ u8 local_detect_mult; /** 1 if remote system sets demand mode, 0 otherwise */ u8 remote_demand; /** remote detect multiplier */ u8 remote_detect_mult; /** 1 is echo function is active, 0 otherwise */ u8 echo; /** set to value of timer in timing wheel, 0 if never set */ u64 wheel_time_clocks; /** transmit interval */ u64 transmit_interval_clocks; /** next time at which to transmit a packet */ u64 tx_timeout_clocks; /** timestamp of last packet transmitted */ u64 last_tx_clocks; /** timestamp of last packet received */ u64 last_rx_clocks; /** transmit interval for echo packets */ u64 echo_transmit_interval_clocks; /** next time at which to transmit echo packet */ u64 echo_tx_timeout_clocks; /** timestamp of last echo packet transmitted */ u64 echo_last_tx_clocks; /** timestamp of last echo packet received */ u64 echo_last_rx_clocks; /** secret used for calculating/checking checksum of echo packets */ u32 echo_secret; /** detection time */ u64 detection_time_clocks; /** state info regarding poll sequence */ bfd_poll_state_e poll_state; /** * helper for delayed poll sequence - marks either start of running poll * sequence or timeout, after which we can start the next poll sequnce */ u64 poll_state_start_or_timeout_clocks; /** authentication information */ struct { /** current key in use */ bfd_auth_key_t *curr_key; /** * set to next key to use if delayed switch is enabled - in that case * the key is switched when first incoming packet is signed with next_key */ bfd_auth_key_t *next_key; /** sequence number incremented occasionally or always (if meticulous) */ u32 local_seq_number; /** remote sequence number */ u32 remote_seq_number; /** set to 1 if remote sequence number is known */ u8 remote_seq_number_known; /** current key ID sent out in bfd packet */ u8 curr_bfd_key_id; /** key ID to use when switched to next_key */ u8 next_bfd_key_id; /** * set to 1 if delayed action is pending, which might be activation * of authentication, change of key or deactivation */ u8 is_delayed; } auth; /** transport type for this session */ bfd_transport_e transport; /** union of transport-specific data */ union { bfd