bfd_pkt.h (7428B)
1 /* 2 * 3 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 4 * 5 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 6 * 7 * File: bfd_pkt.h 8 * Purpose: BFD Packet Format definitions 9 * common to SDK and uKernel. 10 */ 11 12 #ifndef _SOC_SHARED_BFD_PKT_H_ 13 #define _SOC_SHARED_BFD_PKT_H_ 14 15 #ifdef BCM_UKERNEL 16 /* Build for uKernel not SDK */ 17 #include "sdk_typedefs.h" 18 #else 19 #include <sal/types.h> 20 #endif 21 22 #include <shared/pack.h> 23 #include <shared/bfd.h> 24 25 26 /******************************************* 27 * Pack/Unpack Macros 28 * 29 * Data is packed/unpacked in/from Network byte order 30 */ 31 #define SHR_BFD_ENCAP_PACK_U8(_buf, _var) _SHR_PACK_U8(_buf, _var) 32 #define SHR_BFD_ENCAP_PACK_U16(_buf, _var) _SHR_PACK_U16(_buf, _var) 33 #define SHR_BFD_ENCAP_PACK_U32(_buf, _var) _SHR_PACK_U32(_buf, _var) 34 #define SHR_BFD_ENCAP_UNPACK_U8(_buf, _var) _SHR_UNPACK_U8(_buf, _var) 35 #define SHR_BFD_ENCAP_UNPACK_U16(_buf, _var) _SHR_UNPACK_U16(_buf, _var) 36 #define SHR_BFD_ENCAP_UNPACK_U32(_buf, _var) _SHR_UNPACK_U32(_buf, _var) 37 38 39 /****************************************** 40 * Network Packet Format definitions 41 * 42 * Note: LENGTH is specified in bytes unless noted otherwise 43 */ 44 45 /* BFD Control Packet lengths */ 46 #define SHR_BFD_CONTROL_HEADER_LENGTH 24 /* Mandatory */ 47 #define SHR_BFD_AUTH_SP_HEADER_START_LENGTH 3 48 #define SHR_BFD_AUTH_SHA1_LENGTH 28 49 #define SHR_BFD_AUTH_SHA1_AUTH_KEY_OFFSET 8 50 /* Offsets are relative to the start of BFD PDU */ 51 #define SHR_BFD_MY_DISCR_OFFSET 4 52 #define SHR_BFD_YOUR_DISCR_OFFSET 8 53 54 /* UDP Header */ 55 #define SHR_BFD_UDP_HEADER_LENGTH 8 56 #define SHR_BFD_UDP_SINGLE_HOP_DEST_PORT 3784 57 #define SHR_BFD_ECHO_DEST_PORT 3785 58 #define SHR_BFD_UDP_MULTI_HOP_DEST_PORT 4784 59 #define SHR_MICRO_BFD_DEST_PORT 6784 60 61 /* IPv4 Header */ 62 #define SHR_BFD_IPV4_VERSION 4 63 #define SHR_BFD_IPV4_HEADER_LENGTH 20 /* Bytes */ 64 #define SHR_BFD_IPV4_HEADER_LENGTH_WORDS 5 /* Words */ 65 #define SHR_BFD_IPV4_HEADER_SA_LENGTH 4 66 #define SHR_BFD_IPV4_HEADER_SA_OFFSET 12 67 #define SHR_BFD_IPV4_HEADER_DA_OFFSET 16 68 69 /* IPv6 Header */ 70 #define SHR_BFD_IPV6_VERSION 6 71 #define SHR_BFD_IPV6_HEADER_LENGTH 40 72 #define SHR_BFD_IPV6_HEADER_SA_LENGTH 16 73 #define SHR_BFD_IPV6_HEADER_SA_OFFSET 8 74 #define SHR_BFD_IPV6_HEADER_DA_OFFSET 24 75 76 /* IP Protocols */ 77 #define SHR_BFD_IP_PROTOCOL_UDP 17 78 #define SHR_BFD_IP_PROTOCOL_IPV4_ENCAP 4 79 #define SHR_BFD_IP_PROTOCOL_IPV6_ENCAP 41 80 #define SHR_BFD_IP_PROTOCOL_GRE 47 81 82 /* GRE */ 83 #define SHR_BFD_GRE_HEADER_LENGTH 4 84 85 /* Associated Channel Header */ 86 #define SHR_BFD_ACH_HEADER_LENGTH 4 87 #define SHR_BFD_ACH_FIRST_NIBBLE 0x1 88 #define SHR_BFD_ACH_VERSION 0x0 89 #define SHR_BFD_ACH_CHANNEL_TYPE_RAW 0x0007 90 #define SHR_BFD_ACH_CHANNEL_TYPE_IPV4 0x0021 91 #define SHR_BFD_ACH_CHANNEL_TYPE_IPV6 0x0057 92 #define SHR_BFD_ACH_CHANNEL_TYPE_MPLS_TP_CC 0x0022 /* Continuity Check */ 93 #define SHR_BFD_ACH_CHANNEL_TYPE_MPLS_TP_CV 0x0023 /* Connectivity Verif */ 94 #define SHR_BFD_ACH_CHANNEL_TYPE_MPLS_TP_FM 0x0058 /* Fault Management */ 95 96 #define SHR_BFD_ACH_CHANNEL_IS_MPLS_TP_CC(_ach) \ 97 (((_ach)[2] == 0x00) && ((_ach)[3] == 0x22)) 98 #define SHR_BFD_ACH_CHANNEL_IS_MPLS_TP_CV(_ach) \ 99 (((_ach)[2] == 0x00) && ((_ach)[3] == 0x23)) 100 #define SHR_BFD_ACH_CHANNEL_IS_MPLS_TP_FM(_ach) \ 101 (((_ach)[2] == 0x00) && ((_ach)[3] == 0x58)) 102 103 #define SHR_BFD_ACH_CHANNEL_MPLS_TP_CC_SET(_ach) \ 104 do { \ 105 (_ach)[2] = 0x00; \ 106 (_ach)[3] = 0x22; \ 107 } while (0) 108 109 #define SHR_BFD_ACH_CHANNEL_MPLS_TP_CV_SET(_ach) \ 110 do { \ 111 (_ach)[2] = 0x00; \ 112 (_ach)[3] = 0x23; \ 113 } while (0) 114 115 /* MPLS Fault Management Message */ 116 #define SHR_BFD_MPLS_FM_HEADER_LENGTH 4 117 #define SHR_BFD_MPLS_FM_VERSION 1 118 #define SHR_BFD_MPLS_FM_MSG_TYPE_AIS 1 /* Alarm Indication Signal */ 119 #define SHR_BFD_MPLS_FM_MSG_TYPE_LKR 2 /* Lock Report */ 120 #define SHR_BFD_MPLS_FM_FLAGS_L 0x02 /* Link Down Indication */ 121 122 #define SHR_BFD_MPLS_FM_IS_AIS(_msg) \ 123 (((_msg)[1]) == 1) 124 #define SHR_BFD_MPLS_FM_IS_LKR(_msg) \ 125 (((_msg)[1]) == 2) 126 #define SHR_BFD_MPLS_FM_IS_LDI(_msg) \ 127 (SHR_BFD_MPLS_FM_IS_AIS(_msg) && (((_msg)[2]) & SHR_BFD_MPLS_FM_FLAGS_L)) 128 129 /* MPLS */ 130 #define SHR_BFD_MPLS_LABEL_LENGTH 4 131 #define SHR_BFD_MPLS_ROUTER_ALERT_LABEL 1 132 #define SHR_BFD_MPLS_GAL_LABEL 13 133 #define SHR_BFD_MPLS_LABEL_LABEL_LENGTH 3 /* Label field in MPLS */ 134 135 #define SHR_BFD_MPLS_IS_BOS(_label) \ 136 (((_label)[2]) & 0x1) 137 #define SHR_BFD_MPLS_IS_GAL(_label) \ 138 (((_label)[0] == 0x00) && ((_label)[1] == 0x00) && \ 139 ((((_label)[2]) & 0xF0) == 0xD0)) 140 141 /* L2 Header */ 142 #define SHR_BFD_L2_ETYPE_IPV4 0x0800 143 #define SHR_BFD_L2_ETYPE_IPV6 0x86DD 144 #define SHR_BFD_L2_ETYPE_MPLS_UCAST 0x8847 145 #define SHR_BFD_L2_HEADER_TAGGED_LENGTH 18 146 #define SHR_BFD_L2_HEADER_TAGGED_ETYPE_OFFSET 16 147 148 /* Ethernet Frame */ 149 #define SHR_BFD_ENET_UNTAGGED_MIN_PKT_SIZE 64 150 #define SHR_BFD_ENET_TAGGED_MIN_PKT_SIZE 68 151 #define SHR_BFD_ENET_IS_TAGGED(_pkt) \ 152 (((_pkt)[12] == 0x81) && ((_pkt)[13] == 0x00)) 153 154 155 /************************************* 156 * BFD Control Packet Format 157 */ 158 159 /* 160 * BFD Simple Password Authentication 161 */ 162 typedef struct shr_bfd_auth_header_sp_s { 163 uint8 key_id; 164 char password[_SHR_BFD_AUTH_SIMPLE_PASSWORD_KEY_LENGTH]; 165 } shr_bfd_auth_header_sp_t; 166 167 /* 168 * BFD SHA1 Authentication 169 */ 170 typedef struct shr_bfd_auth_header_sha1_s { 171 uint8 key_id; 172 uint8 reserved; 173 uint32 sequence; 174 uint8 key[_SHR_BFD_AUTH_SHA1_KEY_LENGTH]; 175 } shr_bfd_auth_header_sha1_t; 176 177 /* 178 * BFD Authentication Header 179 */ 180 typedef struct shr_bfd_auth_header_s { 181 uint8 type; 182 uint8 length; 183 union { 184 shr_bfd_auth_header_sp_t sp; 185 shr_bfd_auth_header_sha1_t sha1; 186 } data; 187 } shr_bfd_auth_header_t; 188 189 /* 190 * BFD Control Packet Header 191 */ 192 typedef struct shr_bfd_header_s { 193 /* Mandatory */ 194 #ifdef LE_HOST 195 uint32 length:8, 196 detect_multiplier:8, 197 multipoint:1, 198 demand_mode:1, 199 auth_present:1, 200 cpi:1, 201 final:1, 202 poll:1, 203 state:2, 204 diag:5, 205 version: 3; 206 #else 207 uint32 version: 3, 208 diag:5, 209 state:2, 210 poll:1, 211 final:1, 212 cpi:1, 213 auth_present:1, 214 demand_mode:1, 215 multipoint:1, 216 detect_multiplier:8, 217 length:8; 218 #endif /* LE_HOST */ 219 220 uint32 my_discriminator; 221 uint32 your_discriminator; 222 uint32 desired_min_tx_interval; 223 uint32 required_min_rx_interval; 224 uint32 required_min_echo_rx_interval; 225 226 /* Optional BFD Authentication header may be present */ 227 } shr_bfd_header_t; 228 229 #endif /* _SOC_SHARED_BFD_PKT_H_ */