FD.io VPP  v19.04.1-1-ge4a0f9f
Vector Packet Processing
bfd_protocol.h
Go to the documentation of this file.
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 #ifndef __included_bfd_protocol_h__
16 #define __included_bfd_protocol_h__
17 /**
18  * @file
19  * @brief BFD protocol declarations
20  */
21 
22 #include <vppinfra/types.h>
23 #include <vppinfra/clib.h>
24 
25 /* auth type value, max key length, name, description */
26 #define foreach_bfd_auth_type(F) \
27  F (0, 0, reserved, "Reserved") \
28  F (1, 16, simple_password, "Simple Password") \
29  F (2, 16, keyed_md5, "Keyed MD5") \
30  F (3, 16, meticulous_keyed_md5, "Meticulous Keyed MD5") \
31  F (4, 20, keyed_sha1, "Keyed SHA1") \
32  F (5, 20, meticulous_keyed_sha1, "Meticulous Keyed SHA1")
33 
34 #define BFD_AUTH_TYPE_NAME(t) BFD_AUTH_TYPE_##t
35 
36 typedef enum
37 {
38 #define F(n, l, t, s) BFD_AUTH_TYPE_NAME (t) = n,
40 #undef F
42 
43 /**
44  * @brief get the maximum length of key data for given auth type
45  */
46 u32 bfd_max_key_len_for_auth_type (bfd_auth_type_e auth_type);
47 const char *bfd_auth_type_str (bfd_auth_type_e auth_type);
48 
49 /* *INDENT-OFF* */
50 typedef CLIB_PACKED (struct {
51  u8 type;
52  u8 len;
53 }) bfd_auth_common_t;
54 /* *INDENT-ON* */
55 
56 /* *INDENT-OFF* */
57 typedef CLIB_PACKED (struct {
58  /*
59  * 4.4. Keyed SHA1 and Meticulous Keyed SHA1 Authentication Section Format
60 
61  * If the Authentication Present (A) bit is set in the header, and the
62  * Authentication Type field contains 4 (Keyed SHA1) or 5 (Meticulous
63  * Keyed SHA1), the Authentication Section has the following format:
64 
65  * 0 1 2 3
66  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
67  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68  * | Auth Type | Auth Len | Auth Key ID | Reserved |
69  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70  * | Sequence Number |
71  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72  * | Auth Key/Hash... |
73  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74  * | ... |
75  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76  */
77  bfd_auth_common_t type_len;
78  u8 key_id;
79  u8 reserved;
80  u32 seq_num;
81  /*
82  * Auth Key/Hash
83 
84  * This field carries the 20-byte SHA1 hash for the packet. When the
85  * hash is calculated, the shared SHA1 key is stored in this field,
86  * padded to a length of 20 bytes with trailing zero bytes if needed.
87  * The shared key MUST be encoded and configured to section 6.7.4.
88  */
89  u8 hash[20];
90 }) bfd_auth_sha1_t;
91 /* *INDENT-ON* */
92 
93 /* *INDENT-OFF* */
94 typedef CLIB_PACKED (struct {
95  /*
96  * The Mandatory Section of a BFD Control packet has the following
97  * format:
98 
99  * 0 1 2 3
100  * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
101  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
102  * |Vers | Diag |Sta|P|F|C|A|D|M| Detect Mult | Length |
103  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
104  * | My Discriminator |
105  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
106  * | Your Discriminator |
107  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
108  * | Desired Min TX Interval |
109  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
110  * | Required Min RX Interval |
111  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
112  * | Required Min Echo RX Interval |
113  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
114  */
115  struct
116  {
117  u8 vers_diag;
118  u8 sta_flags;
119  u8 detect_mult;
120  u8 length;
121  } head;
122  u32 my_disc;
123  u32 your_disc;
124  u32 des_min_tx;
125  u32 req_min_rx;
126  u32 req_min_echo_rx;
127 }) bfd_pkt_t;
128 /* *INDENT-ON* */
129 
130 /* *INDENT-OFF* */
131 typedef CLIB_PACKED (struct {
132  bfd_pkt_t pkt;
133  bfd_auth_common_t common_auth;
134 }) bfd_pkt_with_common_auth_t;
135 /* *INDENT-ON* */
136 
137 /* *INDENT-OFF* */
138 typedef CLIB_PACKED (struct {
139  bfd_pkt_t pkt;
140  bfd_auth_sha1_t sha1_auth;
141 }) bfd_pkt_with_sha1_auth_t;
142 /* *INDENT-ON* */
143 
144 u8 bfd_pkt_get_version (const bfd_pkt_t * pkt);
145 void bfd_pkt_set_version (bfd_pkt_t * pkt, int version);
146 u8 bfd_pkt_get_diag_code (const bfd_pkt_t * pkt);
147 void bfd_pkt_set_diag_code (bfd_pkt_t * pkt, int value);
148 u8 bfd_pkt_get_state (const bfd_pkt_t * pkt);
149 void bfd_pkt_set_state (bfd_pkt_t * pkt, int value);
150 u8 bfd_pkt_get_poll (const bfd_pkt_t * pkt);
151 void bfd_pkt_set_final (bfd_pkt_t * pkt);
152 u8 bfd_pkt_get_final (const bfd_pkt_t * pkt);
153 void bfd_pkt_set_poll (bfd_pkt_t * pkt);
154 u8 bfd_pkt_get_control_plane_independent (const bfd_pkt_t * pkt);
155 void bfd_pkt_set_control_plane_independent (bfd_pkt_t * pkt);
156 u8 bfd_pkt_get_auth_present (const bfd_pkt_t * pkt);
157 void bfd_pkt_set_auth_present (bfd_pkt_t * pkt);
158 u8 bfd_pkt_get_demand (const bfd_pkt_t * pkt);
159 void bfd_pkt_set_demand (bfd_pkt_t * pkt);
160 u8 bfd_pkt_get_multipoint (const bfd_pkt_t * pkt);
161 void bfd_pkt_set_multipoint (bfd_pkt_t * pkt);
162 
163 /* BFD diagnostic codes */
164 #define foreach_bfd_diag_code(F) \
165  F (0, no_diag, "No Diagnostic") \
166  F (1, det_time_exp, "Control Detection Time Expired") \
167  F (2, echo_failed, "Echo Function Failed") \
168  F (3, neighbor_sig_down, "Neighbor Signaled Session Down") \
169  F (4, fwd_plain_reset, "Forwarding Plane Reset") \
170  F (5, path_down, "Path Down") \
171  F (6, concat_path_down, "Concatenated Path Down") \
172  F (7, admin_down, "Administratively Down") \
173  F (8, reverse_concat_path_down, "Reverse Concatenated Path Down")
174 
175 #define BFD_DIAG_CODE_NAME(t) BFD_DIAG_CODE_##t
176 
177 typedef enum
178 {
179 #define F(n, t, s) BFD_DIAG_CODE_NAME (t) = n,
181 #undef F
183 
184 const char *bfd_diag_code_string (bfd_diag_code_e diag);
185 
186 /* BFD state values */
187 #define foreach_bfd_state(F) \
188  F (0, admin_down, "AdminDown") \
189  F (1, down, "Down") \
190  F (2, init, "Init") \
191  F (3, up, "Up")
192 
193 #define BFD_STATE_NAME(t) BFD_STATE_##t
194 
195 typedef enum
196 {
197 #define F(n, t, s) BFD_STATE_NAME (t) = n,
199 #undef F
200 } bfd_state_e;
201 
202 const char *bfd_state_string (bfd_state_e state);
203 
204 #endif /* __included_bfd_protocol_h__ */
205 
206 /*
207  * fd.io coding-style-patch-verification: ON
208  *
209  * Local Variables:
210  * eval: (c-set-style "gnu")
211  * End:
212  */
u8 bfd_pkt_get_auth_present(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:98
u8 bfd_pkt_get_version(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:22
u8 bfd_pkt_get_final(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:72
void bfd_pkt_set_demand(bfd_pkt_t *pkt)
const char * bfd_diag_code_string(bfd_diag_code_e diag)
Definition: bfd_protocol.c:164
bfd_diag_code_e
Definition: bfd_protocol.h:177
void bfd_pkt_set_poll(bfd_pkt_t *pkt)
Definition: bfd_protocol.c:66
void bfd_pkt_set_auth_present(bfd_pkt_t *pkt)
Definition: bfd_protocol.c:104
bfd_auth_type_e
Definition: bfd_protocol.h:36
unsigned char u8
Definition: types.h:56
vhost_vring_state_t state
Definition: vhost_user.h:120
unsigned int u32
Definition: types.h:88
void bfd_pkt_set_diag_code(bfd_pkt_t *pkt, int value)
Definition: bfd_protocol.c:41
void bfd_pkt_set_final(bfd_pkt_t *pkt)
Definition: bfd_protocol.c:78
u32 bfd_max_key_len_for_auth_type(bfd_auth_type_e auth_type)
get the maximum length of key data for given auth type
Definition: bfd_protocol.c:138
#define F(n, l, t, s)
Definition: bfd_protocol.h:197
u8 bfd_pkt_get_demand(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:110
const char * bfd_state_string(bfd_state_e state)
Definition: bfd_protocol.c:177
u8 bfd_pkt_get_diag_code(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:35
u8 len
Definition: ip_types.api:49
bfd_state_e
Definition: bfd_protocol.h:195
#define foreach_bfd_state(F)
Definition: bfd_protocol.h:187
typedef CLIB_PACKED(struct{u8 type;u8 len;}) bfd_auth_common_t
u8 bfd_pkt_get_control_plane_independent(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:84
#define foreach_bfd_auth_type(F)
Definition: bfd_protocol.h:26
option version
Definition: memclnt.api:17
u8 bfd_pkt_get_multipoint(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:124
u8 bfd_pkt_get_poll(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:60
void bfd_pkt_set_version(bfd_pkt_t *pkt, int version)
Definition: bfd_protocol.c:28
void bfd_pkt_set_multipoint(bfd_pkt_t *pkt)
void bfd_pkt_set_control_plane_independent(bfd_pkt_t *pkt)
u8 bfd_pkt_get_state(const bfd_pkt_t *pkt)
Definition: bfd_protocol.c:48
void bfd_pkt_set_state(bfd_pkt_t *pkt, int value)
Definition: bfd_protocol.c:54
const char * bfd_auth_type_str(bfd_auth_type_e auth_type)
Definition: bfd_protocol.c:151
#define foreach_bfd_diag_code(F)
Definition: bfd_protocol.h:164