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