]> git.proxmox.com Git - mirror_frr.git/blame - bfdd/bfdd_nb_state.c
Merge pull request #13649 from donaldsharp/unlock_the_node_or_else
[mirror_frr.git] / bfdd / bfdd_nb_state.c
CommitLineData
acddc0ed 1// SPDX-License-Identifier: GPL-2.0-or-later
6c574029
RW
2/*
3 * BFD daemon northbound implementation.
4 *
5 * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
6 * Rafael Zalamena
6c574029
RW
7 */
8
9#include <zebra.h>
10
11#include "lib/log.h"
12#include "lib/northbound.h"
13
14#include "bfd.h"
15#include "bfdd_nb.h"
16
17/*
18 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop
19 */
60ee8be1
RW
20const void *
21bfdd_bfd_sessions_single_hop_get_next(struct nb_cb_get_next_args *args)
6c574029 22{
60ee8be1 23 return bfd_session_next(args->list_entry, false);
6c574029
RW
24}
25
60ee8be1 26int bfdd_bfd_sessions_single_hop_get_keys(struct nb_cb_get_keys_args *args)
6c574029 27{
60ee8be1 28 const struct bfd_session *bs = args->list_entry;
6c574029
RW
29 char dstbuf[INET6_ADDRSTRLEN];
30
31 inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf));
32
60ee8be1
RW
33 args->keys->num = 3;
34 strlcpy(args->keys->key[0], dstbuf, sizeof(args->keys->key[0]));
35 strlcpy(args->keys->key[1], bs->key.ifname, sizeof(args->keys->key[1]));
36 strlcpy(args->keys->key[2], bs->key.vrfname,
37 sizeof(args->keys->key[2]));
6c574029
RW
38
39 return NB_OK;
40}
41
42const void *
60ee8be1 43bfdd_bfd_sessions_single_hop_lookup_entry(struct nb_cb_lookup_entry_args *args)
6c574029 44{
60ee8be1
RW
45 const char *dest_addr = args->keys->key[0];
46 const char *ifname = args->keys->key[1];
47 const char *vrf = args->keys->key[2];
6c574029
RW
48 struct sockaddr_any psa, lsa;
49 struct bfd_key bk;
50
51 strtosa(dest_addr, &psa);
52 memset(&lsa, 0, sizeof(lsa));
53 gen_bfd_key(&bk, &psa, &lsa, false, ifname, vrf);
54
55 return bfd_key_lookup(bk);
56}
57
58/*
59 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-discriminator
60 */
61struct yang_data *
62bfdd_bfd_sessions_single_hop_stats_local_discriminator_get_elem(
60ee8be1 63 struct nb_cb_get_elem_args *args)
6c574029 64{
60ee8be1 65 const struct bfd_session *bs = args->list_entry;
6c574029 66
60ee8be1 67 return yang_data_new_uint32(args->xpath, bs->discrs.my_discr);
6c574029
RW
68}
69
70/*
71 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-state
72 */
60ee8be1
RW
73struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_state_get_elem(
74 struct nb_cb_get_elem_args *args)
6c574029 75{
60ee8be1 76 const struct bfd_session *bs = args->list_entry;
6c574029 77
60ee8be1 78 return yang_data_new_enum(args->xpath, bs->ses_state);
6c574029
RW
79}
80
81/*
82 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-diagnostic
83 */
84struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_diagnostic_get_elem(
60ee8be1 85 struct nb_cb_get_elem_args *args)
6c574029 86{
60ee8be1 87 const struct bfd_session *bs = args->list_entry;
6c574029 88
60ee8be1 89 return yang_data_new_enum(args->xpath, bs->local_diag);
6c574029
RW
90}
91
92/*
93 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/local-multiplier
94 */
95struct yang_data *bfdd_bfd_sessions_single_hop_stats_local_multiplier_get_elem(
60ee8be1 96 struct nb_cb_get_elem_args *args)
6c574029 97{
60ee8be1 98 const struct bfd_session *bs = args->list_entry;
6c574029 99
60ee8be1 100 return yang_data_new_int8(args->xpath, bs->detect_mult);
6c574029
RW
101}
102
103/*
104 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-discriminator
105 */
106struct yang_data *
107bfdd_bfd_sessions_single_hop_stats_remote_discriminator_get_elem(
60ee8be1 108 struct nb_cb_get_elem_args *args)
6c574029 109{
60ee8be1 110 const struct bfd_session *bs = args->list_entry;
6c574029
RW
111
112 if (bs->discrs.remote_discr == 0)
113 return NULL;
114
60ee8be1 115 return yang_data_new_uint32(args->xpath, bs->discrs.remote_discr);
6c574029
RW
116}
117
118/*
119 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-state
120 */
60ee8be1
RW
121struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_state_get_elem(
122 struct nb_cb_get_elem_args *args)
6c574029 123{
60ee8be1 124 const struct bfd_session *bs = args->list_entry;
6c574029 125
60ee8be1 126 return yang_data_new_enum(args->xpath, bs->ses_state);
6c574029
RW
127}
128
129/*
130 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-diagnostic
131 */
132struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_diagnostic_get_elem(
60ee8be1 133 struct nb_cb_get_elem_args *args)
6c574029 134{
60ee8be1 135 const struct bfd_session *bs = args->list_entry;
6c574029 136
60ee8be1 137 return yang_data_new_enum(args->xpath, bs->remote_diag);
6c574029
RW
138}
139
140/*
141 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/remote-multiplier
142 */
143struct yang_data *bfdd_bfd_sessions_single_hop_stats_remote_multiplier_get_elem(
60ee8be1 144 struct nb_cb_get_elem_args *args)
6c574029 145{
60ee8be1 146 const struct bfd_session *bs = args->list_entry;
6c574029 147
60ee8be1 148 return yang_data_new_int8(args->xpath, bs->remote_detect_mult);
6c574029
RW
149}
150
151/*
152 * XPath:
153 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-transmission-interval
154 */
155struct yang_data *
156bfdd_bfd_sessions_single_hop_stats_negotiated_transmission_interval_get_elem(
60ee8be1 157 struct nb_cb_get_elem_args *args)
6c574029 158{
60ee8be1 159 const struct bfd_session *bs = args->list_entry;
6c574029 160
60ee8be1
RW
161 return yang_data_new_uint32(args->xpath,
162 bs->remote_timers.desired_min_tx);
6c574029
RW
163}
164
165/*
166 * XPath:
167 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-receive-interval
168 */
169struct yang_data *
170bfdd_bfd_sessions_single_hop_stats_negotiated_receive_interval_get_elem(
60ee8be1 171 struct nb_cb_get_elem_args *args)
6c574029 172{
60ee8be1 173 const struct bfd_session *bs = args->list_entry;
6c574029 174
60ee8be1
RW
175 return yang_data_new_uint32(args->xpath,
176 bs->remote_timers.required_min_rx);
6c574029
RW
177}
178
179/*
180 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/detection-mode
181 */
182struct yang_data *bfdd_bfd_sessions_single_hop_stats_detection_mode_get_elem(
60ee8be1 183 struct nb_cb_get_elem_args *args)
6c574029 184{
60ee8be1 185 const struct bfd_session *bs = args->list_entry;
6c574029
RW
186 int detection_mode;
187
188 /*
189 * Detection mode:
190 * 1. Async with echo
191 * 2. Async without echo
192 * 3. Demand with echo
193 * 4. Demand without echo
194 *
195 * TODO: support demand mode.
196 */
b88113ef 197 if (CHECK_FLAG(bs->flags, BFD_SESS_FLAG_ECHO))
6c574029
RW
198 detection_mode = 1;
199 else
200 detection_mode = 2;
201
60ee8be1 202 return yang_data_new_enum(args->xpath, detection_mode);
6c574029
RW
203}
204
205/*
206 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-down-time
207 */
208struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_down_time_get_elem(
60ee8be1 209 struct nb_cb_get_elem_args *args)
6c574029
RW
210{
211 /*
212 * TODO: implement me.
213 *
214 * No yang support for time elements yet.
215 */
216 return NULL;
217}
218
219/*
220 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/last-up-time
221 */
222struct yang_data *bfdd_bfd_sessions_single_hop_stats_last_up_time_get_elem(
60ee8be1 223 struct nb_cb_get_elem_args *args)
6c574029
RW
224{
225 /*
226 * TODO: implement me.
227 *
228 * No yang support for time elements yet.
229 */
230 return NULL;
231}
232
233/*
234 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-down-count
235 */
236struct yang_data *
237bfdd_bfd_sessions_single_hop_stats_session_down_count_get_elem(
60ee8be1 238 struct nb_cb_get_elem_args *args)
6c574029 239{
60ee8be1 240 const struct bfd_session *bs = args->list_entry;
6c574029 241
60ee8be1 242 return yang_data_new_uint64(args->xpath, bs->stats.session_down);
6c574029
RW
243}
244
245/*
246 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/session-up-count
247 */
248struct yang_data *bfdd_bfd_sessions_single_hop_stats_session_up_count_get_elem(
60ee8be1 249 struct nb_cb_get_elem_args *args)
6c574029 250{
60ee8be1 251 const struct bfd_session *bs = args->list_entry;
6c574029 252
60ee8be1 253 return yang_data_new_uint64(args->xpath, bs->stats.session_up);
6c574029
RW
254}
255
256/*
257 * XPath:
258 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-input-count
259 */
260struct yang_data *
261bfdd_bfd_sessions_single_hop_stats_control_packet_input_count_get_elem(
60ee8be1 262 struct nb_cb_get_elem_args *args)
6c574029 263{
60ee8be1 264 const struct bfd_session *bs = args->list_entry;
6c574029 265
60ee8be1 266 return yang_data_new_uint64(args->xpath, bs->stats.rx_ctrl_pkt);
6c574029
RW
267}
268
269/*
270 * XPath:
271 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/control-packet-output-count
272 */
273struct yang_data *
274bfdd_bfd_sessions_single_hop_stats_control_packet_output_count_get_elem(
60ee8be1 275 struct nb_cb_get_elem_args *args)
6c574029 276{
60ee8be1 277 const struct bfd_session *bs = args->list_entry;
6c574029 278
60ee8be1 279 return yang_data_new_uint64(args->xpath, bs->stats.tx_ctrl_pkt);
6c574029
RW
280}
281
282/*
283 * XPath:
284 * /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/negotiated-echo-transmission-interval
285 */
286struct yang_data *
287bfdd_bfd_sessions_single_hop_stats_negotiated_echo_transmission_interval_get_elem(
60ee8be1 288 struct nb_cb_get_elem_args *args)
6c574029 289{
60ee8be1 290 const struct bfd_session *bs = args->list_entry;
6c574029 291
60ee8be1
RW
292 return yang_data_new_uint32(args->xpath,
293 bs->remote_timers.required_min_echo);
6c574029
RW
294}
295
296/*
297 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-input-count
298 */
299struct yang_data *
300bfdd_bfd_sessions_single_hop_stats_echo_packet_input_count_get_elem(
60ee8be1 301 struct nb_cb_get_elem_args *args)
6c574029 302{
60ee8be1 303 const struct bfd_session *bs = args->list_entry;
6c574029 304
60ee8be1 305 return yang_data_new_uint64(args->xpath, bs->stats.rx_echo_pkt);
6c574029
RW
306}
307
308/*
309 * XPath: /frr-bfdd:bfdd/bfd/sessions/single-hop/stats/echo-packet-output-count
310 */
311struct yang_data *
312bfdd_bfd_sessions_single_hop_stats_echo_packet_output_count_get_elem(
60ee8be1 313 struct nb_cb_get_elem_args *args)
6c574029 314{
60ee8be1 315 const struct bfd_session *bs = args->list_entry;
6c574029 316
60ee8be1 317 return yang_data_new_uint64(args->xpath, bs->stats.tx_echo_pkt);
6c574029
RW
318}
319
320/*
321 * XPath: /frr-bfdd:bfdd/bfd/sessions/multi-hop
322 */
60ee8be1
RW
323const void *
324bfdd_bfd_sessions_multi_hop_get_next(struct nb_cb_get_next_args *args)
6c574029 325{
60ee8be1 326 return bfd_session_next(args->list_entry, true);
6c574029
RW
327}
328
60ee8be1 329int bfdd_bfd_sessions_multi_hop_get_keys(struct nb_cb_get_keys_args *args)
6c574029 330{
60ee8be1 331 const struct bfd_session *bs = args->list_entry;
6c574029
RW
332 char dstbuf[INET6_ADDRSTRLEN], srcbuf[INET6_ADDRSTRLEN];
333
334 inet_ntop(bs->key.family, &bs->key.peer, dstbuf, sizeof(dstbuf));
335 inet_ntop(bs->key.family, &bs->key.local, srcbuf, sizeof(srcbuf));
336
60ee8be1
RW
337 args->keys->num = 4;
338 strlcpy(args->keys->key[0], srcbuf, sizeof(args->keys->key[0]));
339 strlcpy(args->keys->key[1], dstbuf, sizeof(args->keys->key[1]));
874ca769
IR
340 strlcpy(args->keys->key[2], bs->key.vrfname,
341 sizeof(args->keys->key[2]));
6c574029
RW
342
343 return NB_OK;
344}
345
346const void *
60ee8be1 347bfdd_bfd_sessions_multi_hop_lookup_entry(struct nb_cb_lookup_entry_args *args)
6c574029 348{
60ee8be1
RW
349 const char *source_addr = args->keys->key[0];
350 const char *dest_addr = args->keys->key[1];
874ca769 351 const char *vrf = args->keys->key[2];
6c574029
RW
352 struct sockaddr_any psa, lsa;
353 struct bfd_key bk;
354
355 strtosa(dest_addr, &psa);
356 strtosa(source_addr, &lsa);
874ca769 357 gen_bfd_key(&bk, &psa, &lsa, true, NULL, vrf);
6c574029
RW
358
359 return bfd_key_lookup(bk);
360}