The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
bfd.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License as published by
5  * the Free Software Foundation; either version 2 of the License, or
6  * (at your option) any later version.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16  */
17 
18 /*
19  * $Id: 601b9e9b8427485932f37823b6d8c349dd308342 $
20  *
21  * @file protocols/bfd/bfd.h
22  * @brief Structures and prototypes for base BFD functionality.
23  *
24  * @copyright 2023 Network RADIUS SAS (legal@networkradius.com)
25  */
26 #include <freeradius-devel/util/rand.h>
27 #include <freeradius-devel/util/log.h>
28 #include <freeradius-devel/util/pair.h>
29 #include <freeradius-devel/util/md5.h>
30 #include <freeradius-devel/util/sha1.h>
31 #include <freeradius-devel/util/dbuff.h>
32 
33 typedef enum bfd_session_state_t {
39 
40 typedef enum bfd_diag_t {
51 
52 typedef enum bfd_auth_type_t {
60 
61 #define BFD_AUTH_INVALID (BFD_AUTH_MET_KEYED_SHA1 + 1)
62 
63 typedef struct {
67 } __attribute__ ((packed)) bfd_auth_basic_t;
68 
69 
70 typedef struct {
71  uint8_t auth_type;
72  uint8_t auth_len;
73  uint8_t key_id;
74  uint8_t password[16];
75 } __attribute__ ((packed)) bfd_auth_simple_t;
76 
77 typedef struct {
78  uint8_t auth_type;
79  uint8_t auth_len;
80  uint8_t key_id;
84 } __attribute__ ((packed)) bfd_auth_md5_t;
85 
86 typedef struct {
87  uint8_t auth_type;
88  uint8_t auth_len;
89  uint8_t key_id;
90  uint8_t reserved;
91  uint32_t sequence_no;
93 } __attribute__ ((packed)) bfd_auth_sha1_t;
94 
95 typedef union bfd_auth_t {
96  union {
97  bfd_auth_basic_t basic;
98  bfd_auth_simple_t password;
99  bfd_auth_md5_t md5;
100  bfd_auth_sha1_t sha1;
101  };
102 } __attribute__ ((packed)) bfd_auth_t;
103 
104 
105 /*
106  * A packet
107  */
108 typedef struct {
109 #ifdef WORDS_BIGENDIAN
110  unsigned int version : 3;
111  unsigned int diag : 5;
112  unsigned int state : 2;
113  unsigned int poll : 1;
114  unsigned int final : 1;
115  unsigned int control_plane_independent : 1;
116  unsigned int auth_present : 1;
117  unsigned int demand : 1;
118  unsigned int multipoint : 1;
119 #else
120  unsigned int diag : 5;
121  unsigned int version : 3;
122 
123  unsigned int multipoint : 1;
124  unsigned int demand : 1;
125  unsigned int auth_present : 1;
126  unsigned int control_plane_independent : 1;
127  unsigned int final : 1;
128  unsigned int poll : 1;
129  unsigned int state : 2;
130 #endif
139 } __attribute__ ((packed)) bfd_packet_t;
140 
141 #define FR_BFD_HEADER_LENGTH (24)
142 
143 typedef enum {
149 #define FR_BFD_CODE_MAX (4)
150 
151 extern char const *fr_bfd_packet_names[FR_BFD_CODE_MAX];
152 #define FR_BFD_PACKET_CODE_VALID(_code) (_code < FR_BFD_CODE_MAX)
153 
154 typedef struct {
155  TALLOC_CTX *tmp_ctx; //!< for temporary things cleaned up during decoding
156  char const *secret; //!< shared secret. MUST be talloc'd
157 } fr_bfd_ctx_t;
158 
159 ssize_t fr_bfd_encode(uint8_t *packet, size_t packet_len, uint8_t const *original,
160  char const *secret, size_t secret_len, fr_pair_list_t *vps);
161 
163  uint8_t const *packet, size_t packet_len,
164  char const *secret, size_t secret_len);
165 
166 bool fr_bfd_packet_ok(char const **err, uint8_t const *packet, size_t packet_len);
167 
168 int fr_bfd_global_init(void);
169 void fr_bfd_global_free(void);
170 
172 extern size_t const bfd_auth_type_table_len;
uint8_t auth_len
Definition: bfd.h:65
unsigned int diag
Definition: bfd.h:120
char const * fr_bfd_packet_names[FR_BFD_CODE_MAX]
Definition: base.c:63
TALLOC_CTX * tmp_ctx
for temporary things cleaned up during decoding
Definition: bfd.h:155
fr_bfd_packet_code_t
Definition: bfd.h:143
@ FR_BFD_INIT
Definition: bfd.h:146
@ FR_BFD_ADMIN_DOWN
Definition: bfd.h:144
@ FR_BFD_UP
Definition: bfd.h:147
@ FR_BFD_DOWN
Definition: bfd.h:145
uint32_t required_min_rx_interval
Definition: bfd.h:136
unsigned int control_plane_independent
Definition: bfd.h:126
unsigned int auth_present
Definition: bfd.h:125
bfd_auth_type_t
Definition: bfd.h:52
@ BFD_AUTH_MET_KEYED_MD5
Definition: bfd.h:56
@ BFD_AUTH_MET_KEYED_SHA1
Definition: bfd.h:58
@ BFD_AUTH_SIMPLE
Definition: bfd.h:54
@ BFD_AUTH_KEYED_SHA1
Definition: bfd.h:57
@ BFD_AUTH_KEYED_MD5
Definition: bfd.h:55
@ BFD_AUTH_RESERVED
Definition: bfd.h:53
uint8_t length
Definition: bfd.h:132
uint8_t detect_multi
Definition: bfd.h:131
uint32_t my_disc
Definition: bfd.h:133
uint8_t key_id
Definition: bfd.h:66
ssize_t fr_bfd_encode(uint8_t *packet, size_t packet_len, uint8_t const *original, char const *secret, size_t secret_len, fr_pair_list_t *vps)
int fr_bfd_global_init(void)
Definition: base.c:221
unsigned int final
Definition: bfd.h:127
ssize_t fr_bfd_decode(TALLOC_CTX *ctx, fr_pair_list_t *out, uint8_t const *packet, size_t packet_len, char const *secret, size_t secret_len)
uint8_t reserved
Definition: bfd.h:81
uint32_t your_disc
Definition: bfd.h:134
unsigned int demand
Definition: bfd.h:124
unsigned int multipoint
Definition: bfd.h:123
void fr_bfd_global_free(void)
Definition: base.c:244
bfd_diag_t
Definition: bfd.h:40
@ BFD_FORWARD_PLANE_RESET
Definition: bfd.h:45
@ BFD_CONCATENATED_PATH_DOWN
Definition: bfd.h:47
@ BFD_ECHO_FAILED
Definition: bfd.h:43
@ BFD_CTRL_EXPIRED
Definition: bfd.h:42
@ BFD_PATH_DOWN
Definition: bfd.h:46
@ BFD_DIAG_NONE
Definition: bfd.h:41
@ BFD_REVERSE_CONCAT_PATH_DOWN
Definition: bfd.h:49
@ BFD_NEIGHBOR_DOWN
Definition: bfd.h:44
@ BFD_ADMIN_DOWN
Definition: bfd.h:48
size_t const bfd_auth_type_table_len
Definition: base.c:78
typedef __attribute__
#define FR_BFD_CODE_MAX
Definition: bfd.h:149
unsigned int poll
Definition: bfd.h:128
char const * secret
shared secret. MUST be talloc'd
Definition: bfd.h:156
bfd_auth_t auth
Definition: bfd.h:138
unsigned int state
Definition: bfd.h:129
uint32_t sequence_no
Definition: bfd.h:82
unsigned int version
Definition: bfd.h:121
uint8_t auth_type
Definition: bfd.h:64
fr_table_num_ordered_t const bfd_auth_type_table[]
Definition: base.c:70
bool fr_bfd_packet_ok(char const **err, uint8_t const *packet, size_t packet_len)
Definition: base.c:83
uint32_t desired_min_tx_interval
Definition: bfd.h:135
uint32_t min_echo_rx_interval
Definition: bfd.h:137
bfd_session_state_t
Definition: bfd.h:33
@ BFD_STATE_DOWN
Definition: bfd.h:35
@ BFD_STATE_INIT
Definition: bfd.h:36
@ BFD_STATE_ADMIN_DOWN
Definition: bfd.h:34
@ BFD_STATE_UP
Definition: bfd.h:37
Definition: bfd.h:95
static fr_slen_t err
Definition: dict.h:645
#define MD5_DIGEST_LENGTH
Definition: merged_model.c:248
unsigned int uint32_t
Definition: merged_model.c:33
long int ssize_t
Definition: merged_model.c:24
unsigned char uint8_t
Definition: merged_model.c:30
static char * secret
Definition: radclient-ng.c:69
#define SHA1_DIGEST_LENGTH
Definition: sha1.h:29
An element in an arbitrarily ordered array of name to num mappings.
Definition: table.h:53
static size_t char ** out
Definition: value.h:984