]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_nb_state.c
zebra: single vxlan device dataplace vni update changes
[mirror_frr.git] / zebra / zebra_nb_state.c
CommitLineData
ce45ffe7
CS
1/*
2 * Copyright (C) 2020 Cumulus Networks, Inc.
3 * Chirag Shah
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <zebra.h>
21#include "northbound.h"
22#include "libfrr.h"
23#include "zebra_nb.h"
09268680 24#include "zebra/interface.h"
9d86e091 25#include "zebra/zebra_router.h"
5a634c34
CS
26#include "zebra/debug.h"
27#include "printfrr.h"
8d30ff3b 28#include "zebra/zebra_vxlan.h"
ce45ffe7 29
b00f3e4b
CS
30/*
31 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/up-count
32 */
33struct yang_data *
60ee8be1 34lib_interface_zebra_state_up_count_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b 35{
60ee8be1 36 const struct interface *ifp = args->list_entry;
09268680
CS
37 struct zebra_if *zebra_if;
38
39 zebra_if = ifp->info;
40
60ee8be1 41 return yang_data_new_uint16(args->xpath, zebra_if->up_count);
b00f3e4b
CS
42}
43
44/*
45 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/down-count
46 */
47struct yang_data *
60ee8be1 48lib_interface_zebra_state_down_count_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b 49{
60ee8be1 50 const struct interface *ifp = args->list_entry;
09268680
CS
51 struct zebra_if *zebra_if;
52
53 zebra_if = ifp->info;
54
60ee8be1 55 return yang_data_new_uint16(args->xpath, zebra_if->down_count);
b00f3e4b
CS
56}
57
58/*
59 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/zif-type
60 */
61struct yang_data *
60ee8be1 62lib_interface_zebra_state_zif_type_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b
CS
63{
64 /* TODO: implement me. */
65 return NULL;
66}
67
68/*
69 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/ptm-status
70 */
71struct yang_data *
60ee8be1 72lib_interface_zebra_state_ptm_status_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b
CS
73{
74 /* TODO: implement me. */
75 return NULL;
76}
77
78/*
79 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/vlan-id
80 */
81struct yang_data *
60ee8be1 82lib_interface_zebra_state_vlan_id_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b 83{
60ee8be1 84 const struct interface *ifp = args->list_entry;
09268680
CS
85 struct zebra_if *zebra_if;
86 struct zebra_l2info_vlan *vlan_info;
87
88 if (!IS_ZEBRA_IF_VLAN(ifp))
89 return NULL;
90
91 zebra_if = ifp->info;
92 vlan_info = &zebra_if->l2info.vl;
93
60ee8be1 94 return yang_data_new_uint16(args->xpath, vlan_info->vid);
b00f3e4b
CS
95}
96
97/*
98 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/vni-id
99 */
100struct yang_data *
60ee8be1 101lib_interface_zebra_state_vni_id_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b 102{
60ee8be1 103 const struct interface *ifp = args->list_entry;
09268680 104 struct zebra_if *zebra_if;
8d30ff3b 105 struct zebra_vxlan_vni *vni;
09268680
CS
106
107 if (!IS_ZEBRA_IF_VXLAN(ifp))
108 return NULL;
109
110 zebra_if = ifp->info;
09268680 111
8d30ff3b
SR
112 if (!IS_ZEBRA_VXLAN_IF_VNI(zebra_if))
113 return NULL;
114
115 vni = zebra_vxlan_if_vni_find(zebra_if, 0);
116 return yang_data_new_uint32(args->xpath, vni->vni);
b00f3e4b
CS
117}
118
119/*
120 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/remote-vtep
121 */
122struct yang_data *
60ee8be1 123lib_interface_zebra_state_remote_vtep_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b 124{
60ee8be1 125 const struct interface *ifp = args->list_entry;
09268680
CS
126 struct zebra_if *zebra_if;
127 struct zebra_l2info_vxlan *vxlan_info;
128
129 if (!IS_ZEBRA_IF_VXLAN(ifp))
130 return NULL;
131
132 zebra_if = ifp->info;
133 vxlan_info = &zebra_if->l2info.vxl;
134
60ee8be1 135 return yang_data_new_ipv4(args->xpath, &vxlan_info->vtep_ip);
b00f3e4b
CS
136}
137
138/*
139 * XPath: /frr-interface:lib/interface/frr-zebra:zebra/state/mcast-group
140 */
141struct yang_data *
60ee8be1 142lib_interface_zebra_state_mcast_group_get_elem(struct nb_cb_get_elem_args *args)
b00f3e4b 143{
60ee8be1 144 const struct interface *ifp = args->list_entry;
09268680 145 struct zebra_if *zebra_if;
8d30ff3b 146 struct zebra_vxlan_vni *vni;
09268680
CS
147
148 if (!IS_ZEBRA_IF_VXLAN(ifp))
149 return NULL;
150
151 zebra_if = ifp->info;
09268680 152
8d30ff3b
SR
153 if (!IS_ZEBRA_VXLAN_IF_VNI(zebra_if))
154 return NULL;
155
156 vni = zebra_vxlan_if_vni_find(zebra_if, 0);
157 return yang_data_new_ipv4(args->xpath, &vni->mcast_grp);
b00f3e4b
CS
158}
159
56a88b9e 160const void *lib_vrf_zebra_ribs_rib_get_next(struct nb_cb_get_next_args *args)
ce45ffe7 161{
56a88b9e 162 struct vrf *vrf = (struct vrf *)args->parent_list_entry;
9d86e091 163 struct zebra_router_table *zrt =
56a88b9e 164 (struct zebra_router_table *)args->list_entry;
9d86e091
CS
165
166 struct zebra_vrf *zvrf;
167 afi_t afi;
168 safi_t safi;
169
170 zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id);
171
56a88b9e 172 if (args->list_entry == NULL) {
9d86e091
CS
173 afi = AFI_IP;
174 safi = SAFI_UNICAST;
175
176 zrt = zebra_router_find_zrt(zvrf, zvrf->table_id, afi, safi);
177 if (zrt == NULL)
178 return NULL;
179 } else {
180 zrt = RB_NEXT(zebra_router_table_head, zrt);
181 /* vrf_id/ns_id do not match, only walk for the given VRF */
182 while (zrt && zrt->ns_id != zvrf->zns->ns_id)
183 zrt = RB_NEXT(zebra_router_table_head, zrt);
184 }
185
186 return zrt;
ce45ffe7
CS
187}
188
56a88b9e 189int lib_vrf_zebra_ribs_rib_get_keys(struct nb_cb_get_keys_args *args)
ce45ffe7 190{
56a88b9e 191 const struct zebra_router_table *zrt = args->list_entry;
9d86e091 192
56a88b9e 193 args->keys->num = 2;
9d86e091 194
755100ac 195 snprintfrr(args->keys->key[0], sizeof(args->keys->key[0]), "%s",
196 yang_afi_safi_value2identity(zrt->afi, zrt->safi));
6cde4b45 197 snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), "%u",
5a634c34 198 zrt->tableid);
9d86e091 199
ce45ffe7
CS
200 return NB_OK;
201}
202
56a88b9e
CS
203const void *
204lib_vrf_zebra_ribs_rib_lookup_entry(struct nb_cb_lookup_entry_args *args)
ce45ffe7 205{
56a88b9e 206 struct vrf *vrf = (struct vrf *)args->parent_list_entry;
9d86e091 207 struct zebra_vrf *zvrf;
5a634c34
CS
208 afi_t afi;
209 safi_t safi;
210 uint32_t table_id = 0;
9d86e091
CS
211
212 zvrf = zebra_vrf_lookup_by_id(vrf->vrf_id);
213
755100ac 214 yang_afi_safi_identity2value(args->keys->key[0], &afi, &safi);
5a634c34
CS
215 table_id = yang_str2uint32(args->keys->key[1]);
216 /* table_id 0 assume vrf's table_id. */
217 if (!table_id)
218 table_id = zvrf->table_id;
219
220 return zebra_router_find_zrt(zvrf, table_id, afi, safi);
ce45ffe7
CS
221}
222
6c380957
IR
223/*
224 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/afi-safi-name
225 */
226struct yang_data *
227lib_vrf_zebra_ribs_rib_afi_safi_name_get_elem(struct nb_cb_get_elem_args *args)
228{
229 const struct zebra_router_table *zrt = args->list_entry;
230
231 return yang_data_new_string(args->xpath,
232 yang_afi_safi_value2identity(zrt->afi, zrt->safi));
233}
234
235/*
236 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/table-id
237 */
238struct yang_data *
239lib_vrf_zebra_ribs_rib_table_id_get_elem(struct nb_cb_get_elem_args *args)
240{
241 const struct zebra_router_table *zrt = args->list_entry;
242
243 return yang_data_new_uint32(args->xpath, zrt->tableid);
244}
245
ce45ffe7 246/*
56a88b9e 247 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route
ce45ffe7 248 */
56a88b9e
CS
249const void *
250lib_vrf_zebra_ribs_rib_route_get_next(struct nb_cb_get_next_args *args)
ce45ffe7 251{
56a88b9e 252 const struct zebra_router_table *zrt = args->parent_list_entry;
78769ea2 253 struct route_node *rn = (struct route_node *)args->list_entry;
9d86e091 254
56a88b9e 255 if (args->list_entry == NULL)
9d86e091
CS
256 rn = route_top(zrt->table);
257 else
8998807f 258 rn = srcdest_route_next(rn);
78769ea2
RW
259 /* Optimization: skip empty route nodes. */
260 while (rn && rn->info == NULL)
261 rn = route_next(rn);
9d86e091 262
9b4d578f
RW
263 /* Skip link-local routes. */
264 if (rn && rn->p.family == AF_INET6
265 && IN6_IS_ADDR_LINKLOCAL(&rn->p.u.prefix6))
266 return NULL;
267
9d86e091 268 return rn;
ce45ffe7
CS
269}
270
56a88b9e 271int lib_vrf_zebra_ribs_rib_route_get_keys(struct nb_cb_get_keys_args *args)
ce45ffe7 272{
56a88b9e 273 const struct route_node *rn = args->list_entry;
9d86e091 274
56a88b9e
CS
275 args->keys->num = 1;
276 prefix2str(&rn->p, args->keys->key[0], sizeof(args->keys->key[0]));
9d86e091 277
ce45ffe7
CS
278 return NB_OK;
279}
280
281const void *
56a88b9e 282lib_vrf_zebra_ribs_rib_route_lookup_entry(struct nb_cb_lookup_entry_args *args)
ce45ffe7 283{
56a88b9e 284 const struct zebra_router_table *zrt = args->parent_list_entry;
9d86e091
CS
285 struct prefix p;
286 struct route_node *rn;
287
56a88b9e 288 yang_str2prefix(args->keys->key[0], &p);
9d86e091
CS
289
290 rn = route_node_lookup(zrt->table, &p);
291
292 if (!rn)
293 return NULL;
294
295 route_unlock_node(rn);
296
297 return rn;
ce45ffe7
CS
298}
299
300/*
56a88b9e 301 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/prefix
ce45ffe7 302 */
60ee8be1 303struct yang_data *
56a88b9e 304lib_vrf_zebra_ribs_rib_route_prefix_get_elem(struct nb_cb_get_elem_args *args)
ce45ffe7 305{
56a88b9e 306 const struct route_node *rn = args->list_entry;
9d86e091 307
56a88b9e 308 return yang_data_new_prefix(args->xpath, &rn->p);
ce45ffe7
CS
309}
310
311/*
56a88b9e 312 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry
ce45ffe7 313 */
56a88b9e
CS
314const void *lib_vrf_zebra_ribs_rib_route_route_entry_get_next(
315 struct nb_cb_get_next_args *args)
ed5abdb2 316{
5a634c34
CS
317 struct route_entry *re = (struct route_entry *)args->list_entry;
318 struct route_node *rn = (struct route_node *)args->parent_list_entry;
319
320 if (args->list_entry == NULL)
321 RNODE_FIRST_RE(rn, re);
322 else
323 RNODE_NEXT_RE(rn, re);
9d86e091
CS
324
325 return re;
ed5abdb2
CS
326}
327
56a88b9e 328int lib_vrf_zebra_ribs_rib_route_route_entry_get_keys(
60ee8be1 329 struct nb_cb_get_keys_args *args)
ed5abdb2 330{
5a634c34
CS
331 struct route_entry *re = (struct route_entry *)args->list_entry;
332
333 args->keys->num = 1;
334
335 strlcpy(args->keys->key[0], zebra_route_string(re->type),
336 sizeof(args->keys->key[0]));
337
ed5abdb2
CS
338 return NB_OK;
339}
340
56a88b9e 341const void *lib_vrf_zebra_ribs_rib_route_route_entry_lookup_entry(
60ee8be1 342 struct nb_cb_lookup_entry_args *args)
ce45ffe7 343{
5a634c34
CS
344 struct route_node *rn = (struct route_node *)args->parent_list_entry;
345 struct route_entry *re = NULL;
346 int proto_type = 0;
347 afi_t afi;
348
349 afi = family2afi(rn->p.family);
350 proto_type = proto_redistnum(afi, args->keys->key[0]);
351
352 RNODE_FOREACH_RE (rn, re) {
353 if (proto_type == re->type)
354 return re;
355 }
356
ce45ffe7
CS
357 return NULL;
358}
359
360/*
56a88b9e 361 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/protocol
ce45ffe7 362 */
56a88b9e 363struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_protocol_get_elem(
60ee8be1 364 struct nb_cb_get_elem_args *args)
ce45ffe7 365{
5a634c34
CS
366 struct route_entry *re = (struct route_entry *)args->list_entry;
367
368 return yang_data_new_enum(args->xpath, re->type);
ce45ffe7
CS
369}
370
371/*
56a88b9e 372 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/instance
ce45ffe7 373 */
56a88b9e 374struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_instance_get_elem(
60ee8be1 375 struct nb_cb_get_elem_args *args)
ce45ffe7 376{
5a634c34
CS
377 struct route_entry *re = (struct route_entry *)args->list_entry;
378
379 if (re->instance)
380 return yang_data_new_uint16(args->xpath, re->instance);
381
ce45ffe7
CS
382 return NULL;
383}
384
385/*
56a88b9e 386 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/distance
ce45ffe7 387 */
56a88b9e 388struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_distance_get_elem(
60ee8be1 389 struct nb_cb_get_elem_args *args)
ce45ffe7 390{
5a634c34
CS
391 struct route_entry *re = (struct route_entry *)args->list_entry;
392
393 return yang_data_new_uint8(args->xpath, re->distance);
ce45ffe7
CS
394}
395
396/*
56a88b9e 397 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/metric
ce45ffe7 398 */
56a88b9e 399struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_metric_get_elem(
60ee8be1 400 struct nb_cb_get_elem_args *args)
ce45ffe7 401{
5a634c34
CS
402 struct route_entry *re = (struct route_entry *)args->list_entry;
403
404 return yang_data_new_uint32(args->xpath, re->metric);
ce45ffe7
CS
405}
406
407/*
56a88b9e 408 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/tag
ce45ffe7 409 */
56a88b9e 410struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_tag_get_elem(
60ee8be1 411 struct nb_cb_get_elem_args *args)
ce45ffe7 412{
5a634c34
CS
413 struct route_entry *re = (struct route_entry *)args->list_entry;
414
415 if (re->tag)
416 return yang_data_new_uint32(args->xpath, re->tag);
417
ce45ffe7
CS
418 return NULL;
419}
420
421/*
56a88b9e 422 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/selected
ce45ffe7 423 */
56a88b9e 424struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_selected_get_elem(
60ee8be1 425 struct nb_cb_get_elem_args *args)
ce45ffe7 426{
5a634c34
CS
427 struct route_entry *re = (struct route_entry *)args->list_entry;
428
429 if (CHECK_FLAG(re->flags, ZEBRA_FLAG_SELECTED))
430 return yang_data_new_empty(args->xpath);
431
ce45ffe7
CS
432 return NULL;
433}
434
435/*
56a88b9e 436 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/installed
ce45ffe7 437 */
56a88b9e 438struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_installed_get_elem(
60ee8be1 439 struct nb_cb_get_elem_args *args)
ce45ffe7 440{
5a634c34
CS
441 struct route_entry *re = (struct route_entry *)args->list_entry;
442
443 if (CHECK_FLAG(re->status, ROUTE_ENTRY_INSTALLED))
444 return yang_data_new_empty(args->xpath);
445
ce45ffe7
CS
446 return NULL;
447}
448
449/*
56a88b9e 450 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/failed
ce45ffe7 451 */
56a88b9e 452struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_failed_get_elem(
60ee8be1 453 struct nb_cb_get_elem_args *args)
ce45ffe7 454{
5a634c34
CS
455 struct route_entry *re = (struct route_entry *)args->list_entry;
456
457 if (CHECK_FLAG(re->status, ROUTE_ENTRY_FAILED))
458 return yang_data_new_empty(args->xpath);
459
ce45ffe7
CS
460 return NULL;
461}
462
463/*
56a88b9e 464 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/queued
ce45ffe7 465 */
56a88b9e 466struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_queued_get_elem(
60ee8be1 467 struct nb_cb_get_elem_args *args)
ce45ffe7 468{
5a634c34
CS
469 struct route_entry *re = (struct route_entry *)args->list_entry;
470
471 if (CHECK_FLAG(re->status, ROUTE_ENTRY_QUEUED))
472 return yang_data_new_empty(args->xpath);
473
ce45ffe7
CS
474 return NULL;
475}
476
477/*
56a88b9e
CS
478 * XPath:
479 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/internal-flags
ce45ffe7 480 */
56a88b9e
CS
481struct yang_data *
482lib_vrf_zebra_ribs_rib_route_route_entry_internal_flags_get_elem(
60ee8be1 483 struct nb_cb_get_elem_args *args)
ce45ffe7 484{
5a634c34
CS
485 struct route_entry *re = (struct route_entry *)args->list_entry;
486
487 if (re->flags)
488 return yang_data_new_int32(args->xpath, re->flags);
489
ce45ffe7
CS
490 return NULL;
491}
492
493/*
56a88b9e
CS
494 * XPath:
495 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/internal-status
ce45ffe7 496 */
56a88b9e
CS
497struct yang_data *
498lib_vrf_zebra_ribs_rib_route_route_entry_internal_status_get_elem(
60ee8be1 499 struct nb_cb_get_elem_args *args)
ce45ffe7 500{
5a634c34
CS
501 struct route_entry *re = (struct route_entry *)args->list_entry;
502
503 if (re->status)
504 return yang_data_new_int32(args->xpath, re->status);
505
ce45ffe7
CS
506 return NULL;
507}
508
509/*
56a88b9e 510 * XPath: /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/uptime
ce45ffe7 511 */
56a88b9e 512struct yang_data *lib_vrf_zebra_ribs_rib_route_route_entry_uptime_get_elem(
60ee8be1 513 struct nb_cb_get_elem_args *args)
ce45ffe7 514{
5a634c34
CS
515 struct route_entry *re = (struct route_entry *)args->list_entry;
516
517 return yang_data_new_date_and_time(args->xpath, re->uptime);
ce45ffe7
CS
518}
519
520/*
56a88b9e 521 * XPath:
2b2282eb 522 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/id
ce45ffe7
CS
523 */
524struct yang_data *
2b2282eb 525lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_id_get_elem(
60ee8be1 526 struct nb_cb_get_elem_args *args)
ce45ffe7 527{
2b2282eb 528 struct route_entry *re = (struct route_entry *)args->list_entry;
5a634c34 529
2b2282eb 530 return yang_data_new_uint32(args->xpath, re->nhe->id);
ce45ffe7
CS
531}
532
533/*
534 * XPath:
2b2282eb 535 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop
ce45ffe7 536 */
ed5abdb2 537const void *
2b2282eb 538lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_get_next(
60ee8be1 539 struct nb_cb_get_next_args *args)
ce45ffe7 540{
5a634c34 541 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
2b2282eb
CS
542 struct route_entry *re = (struct route_entry *)args->parent_list_entry;
543 struct nhg_hash_entry *nhe = re->nhe;
5a634c34 544
2b2282eb 545 if (args->list_entry == NULL) {
5a634c34 546 nexthop = nhe->nhg.nexthop;
2b2282eb 547 } else
5a634c34
CS
548 nexthop = nexthop_next(nexthop);
549
550 return nexthop;
ce45ffe7
CS
551}
552
2b2282eb 553int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_get_keys(
60ee8be1 554 struct nb_cb_get_keys_args *args)
ce45ffe7 555{
5a634c34
CS
556 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
557
20e310a9 558 args->keys->num = 4;
5a634c34
CS
559
560 strlcpy(args->keys->key[0], yang_nexthop_type2str(nexthop->type),
561 sizeof(args->keys->key[0]));
562
20e310a9
CS
563 snprintfrr(args->keys->key[1], sizeof(args->keys->key[1]), "%" PRIu32,
564 nexthop->vrf_id);
565
5a634c34
CS
566 switch (nexthop->type) {
567 case NEXTHOP_TYPE_IPV4:
568 case NEXTHOP_TYPE_IPV4_IFINDEX:
20e310a9 569 snprintfrr(args->keys->key[2], sizeof(args->keys->key[2]),
5a634c34
CS
570 "%pI4", &nexthop->gate.ipv4);
571 if (nexthop->ifindex)
20e310a9 572 strlcpy(args->keys->key[3],
5a634c34
CS
573 ifindex2ifname(nexthop->ifindex,
574 nexthop->vrf_id),
20e310a9 575 sizeof(args->keys->key[3]));
5a634c34
CS
576 else
577 /* no ifindex */
20e310a9
CS
578 strlcpy(args->keys->key[3], " ",
579 sizeof(args->keys->key[3]));
5a634c34
CS
580
581 break;
582 case NEXTHOP_TYPE_IPV6:
583 case NEXTHOP_TYPE_IPV6_IFINDEX:
20e310a9 584 snprintfrr(args->keys->key[2], sizeof(args->keys->key[2]),
5a634c34
CS
585 "%pI6", &nexthop->gate.ipv6);
586
587 if (nexthop->ifindex)
20e310a9 588 strlcpy(args->keys->key[3],
5a634c34
CS
589 ifindex2ifname(nexthop->ifindex,
590 nexthop->vrf_id),
20e310a9 591 sizeof(args->keys->key[3]));
5a634c34
CS
592 else
593 /* no ifindex */
20e310a9
CS
594 strlcpy(args->keys->key[3], " ",
595 sizeof(args->keys->key[3]));
5a634c34
CS
596
597 break;
598 case NEXTHOP_TYPE_IFINDEX:
20e310a9
CS
599 strlcpy(args->keys->key[2], "", sizeof(args->keys->key[2]));
600 strlcpy(args->keys->key[3],
5a634c34 601 ifindex2ifname(nexthop->ifindex, nexthop->vrf_id),
20e310a9 602 sizeof(args->keys->key[3]));
5a634c34
CS
603
604 break;
605 case NEXTHOP_TYPE_BLACKHOLE:
606 /* Gateway IP */
20e310a9
CS
607 strlcpy(args->keys->key[2], "", sizeof(args->keys->key[2]));
608 strlcpy(args->keys->key[3], " ", sizeof(args->keys->key[3]));
5a634c34
CS
609 break;
610 default:
611 break;
612 }
613
ce45ffe7
CS
614 return NB_OK;
615}
616
617const void *
2b2282eb 618lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_lookup_entry(
60ee8be1 619 struct nb_cb_lookup_entry_args *args)
ce45ffe7 620{
bf6f7f7d
RW
621 struct nhg_hash_entry *nhe;
622 struct nexthop nexthop_lookup = {};
623 struct nexthop *nexthop;
624 const char *nh_type_str;
625
626 nhe = (struct nhg_hash_entry *)args->parent_list_entry;
627 nexthop_lookup.vrf_id = nhe->vrf_id;
628
629 /*
630 * Get nexthop type.
631 * TODO: use yang_str2enum() instead.
632 */
633 nh_type_str = args->keys->key[0];
634 if (strmatch(nh_type_str, "ifindex"))
635 nexthop_lookup.type = NEXTHOP_TYPE_IFINDEX;
636 else if (strmatch(nh_type_str, "ip4"))
637 nexthop_lookup.type = NEXTHOP_TYPE_IPV4;
638 else if (strmatch(nh_type_str, "ip4-ifindex"))
639 nexthop_lookup.type = NEXTHOP_TYPE_IPV4_IFINDEX;
640 else if (strmatch(nh_type_str, "ip6"))
641 nexthop_lookup.type = NEXTHOP_TYPE_IPV6;
642 else if (strmatch(nh_type_str, "ip6-ifindex"))
643 nexthop_lookup.type = NEXTHOP_TYPE_IPV6_IFINDEX;
644 else if (strmatch(nh_type_str, "blackhole"))
645 nexthop_lookup.type = NEXTHOP_TYPE_BLACKHOLE;
646 else
647 /* unexpected */
648 return NULL;
649
650 /* Get nexthop address. */
651 switch (nexthop_lookup.type) {
652 case NEXTHOP_TYPE_IPV4:
653 case NEXTHOP_TYPE_IPV4_IFINDEX:
654 yang_str2ipv4(args->keys->key[1], &nexthop_lookup.gate.ipv4);
655 break;
656 case NEXTHOP_TYPE_IPV6:
657 case NEXTHOP_TYPE_IPV6_IFINDEX:
658 yang_str2ipv6(args->keys->key[1], &nexthop_lookup.gate.ipv6);
659 break;
660 case NEXTHOP_TYPE_IFINDEX:
661 case NEXTHOP_TYPE_BLACKHOLE:
662 break;
663 }
664
665 /* Get nexthop interface. */
666 switch (nexthop_lookup.type) {
667 case NEXTHOP_TYPE_IPV4_IFINDEX:
668 case NEXTHOP_TYPE_IPV6_IFINDEX:
669 case NEXTHOP_TYPE_IFINDEX:
670 nexthop_lookup.ifindex =
671 ifname2ifindex(args->keys->key[2], nhe->vrf_id);
672 break;
673 case NEXTHOP_TYPE_IPV4:
674 case NEXTHOP_TYPE_IPV6:
675 case NEXTHOP_TYPE_BLACKHOLE:
676 break;
677 }
678
679 /* Lookup requested nexthop (ignore weight and metric). */
680 for (ALL_NEXTHOPS(nhe->nhg, nexthop)) {
681 nexthop_lookup.weight = nexthop->weight;
682 nexthop_lookup.src = nexthop->src;
683 if (nexthop_same_no_labels(&nexthop_lookup, nexthop))
684 return nexthop;
685 }
686
ce45ffe7
CS
687 return NULL;
688}
689
690/*
691 * XPath:
2b2282eb 692 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/nh-type
ce45ffe7
CS
693 */
694struct yang_data *
2b2282eb 695lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_nh_type_get_elem(
60ee8be1 696 struct nb_cb_get_elem_args *args)
ce45ffe7 697{
5a634c34
CS
698 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
699
700 switch (nexthop->type) {
701 case NEXTHOP_TYPE_IFINDEX:
702 return yang_data_new_string(args->xpath, "ifindex");
703 break;
704 case NEXTHOP_TYPE_IPV4:
705 return yang_data_new_string(args->xpath, "ip4");
706 break;
707 case NEXTHOP_TYPE_IPV4_IFINDEX:
708 return yang_data_new_string(args->xpath, "ip4-ifindex");
709 break;
710 case NEXTHOP_TYPE_IPV6:
711 return yang_data_new_string(args->xpath, "ip6");
712 break;
713 case NEXTHOP_TYPE_IPV6_IFINDEX:
714 return yang_data_new_string(args->xpath, "ip6-ifindex");
715 break;
a98701f0 716 case NEXTHOP_TYPE_BLACKHOLE:
5a634c34
CS
717 break;
718 }
719
ce45ffe7
CS
720 return NULL;
721}
722
723/*
724 * XPath:
2b2282eb 725 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/vrf
ce45ffe7
CS
726 */
727struct yang_data *
2b2282eb 728lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_vrf_get_elem(
60ee8be1 729 struct nb_cb_get_elem_args *args)
ce45ffe7 730{
5a634c34
CS
731 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
732
733 return yang_data_new_string(args->xpath,
734 vrf_id_to_name(nexthop->vrf_id));
ce45ffe7
CS
735}
736
737/*
738 * XPath:
2b2282eb 739 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/gateway
ce45ffe7
CS
740 */
741struct yang_data *
2b2282eb 742lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_gateway_get_elem(
60ee8be1 743 struct nb_cb_get_elem_args *args)
ce45ffe7 744{
5a634c34
CS
745 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
746 struct ipaddr addr;
747
748 switch (nexthop->type) {
749 case NEXTHOP_TYPE_IPV4:
750 case NEXTHOP_TYPE_IPV4_IFINDEX:
751 addr.ipa_type = IPADDR_V4;
752 memcpy(&addr.ipaddr_v4, &(nexthop->gate.ipv4),
753 sizeof(struct in_addr));
754 break;
755 case NEXTHOP_TYPE_IPV6:
756 case NEXTHOP_TYPE_IPV6_IFINDEX:
757 addr.ipa_type = IPADDR_V6;
758 memcpy(&addr.ipaddr_v6, &(nexthop->gate.ipv6),
759 sizeof(struct in6_addr));
760 break;
761 case NEXTHOP_TYPE_BLACKHOLE:
762 case NEXTHOP_TYPE_IFINDEX:
763 /* No addr here */
764 return yang_data_new_string(args->xpath, "");
765 break;
766 default:
767 break;
768 }
769
770 return yang_data_new_ip(args->xpath, &addr);
ce45ffe7
CS
771}
772
773/*
774 * XPath:
2b2282eb 775 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/interface
ce45ffe7
CS
776 */
777struct yang_data *
2b2282eb 778lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_interface_get_elem(
60ee8be1 779 struct nb_cb_get_elem_args *args)
ce45ffe7 780{
5a634c34
CS
781 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
782
783 if (nexthop->ifindex)
c17a3d0f 784 return yang_data_new_string(
5a634c34
CS
785 args->xpath,
786 ifindex2ifname(nexthop->ifindex, nexthop->vrf_id));
787
ce45ffe7
CS
788 return NULL;
789}
790
791/*
792 * XPath:
2b2282eb 793 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/bh-type
ce45ffe7
CS
794 */
795struct yang_data *
2b2282eb 796lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_bh_type_get_elem(
60ee8be1 797 struct nb_cb_get_elem_args *args)
ce45ffe7 798{
5a634c34
CS
799 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
800 const char *type_str = "";
801
802 if (nexthop->type != NEXTHOP_TYPE_BLACKHOLE)
803 return NULL;
804
805 switch (nexthop->bh_type) {
806 case BLACKHOLE_NULL:
807 type_str = "null";
808 break;
809 case BLACKHOLE_REJECT:
810 type_str = "reject";
811 break;
812 case BLACKHOLE_ADMINPROHIB:
813 type_str = "prohibited";
814 break;
815 case BLACKHOLE_UNSPEC:
816 type_str = "unspec";
817 break;
818 }
819
820 return yang_data_new_string(args->xpath, type_str);
ce45ffe7
CS
821}
822
823/*
824 * XPath:
2b2282eb 825 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/onlink
ce45ffe7
CS
826 */
827struct yang_data *
2b2282eb 828lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_onlink_get_elem(
60ee8be1 829 struct nb_cb_get_elem_args *args)
ce45ffe7 830{
5a634c34
CS
831 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
832
833 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK))
834 return yang_data_new_bool(args->xpath, true);
835
ce45ffe7
CS
836 return NULL;
837}
838
065276ae
SM
839/*
840 * XPath:
841 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/srte-color
842 */
843struct yang_data *
844lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_color_get_elem(
845 struct nb_cb_get_elem_args *args)
846{
847 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
848
849 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_SRTE))
850 return yang_data_new_uint32(args->xpath, nexthop->srte_color);
851
852 return NULL;
853}
854
ce45ffe7
CS
855/*
856 * XPath:
2b2282eb 857 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/mpls-label-stack/entry
ce45ffe7
CS
858 */
859const void *
2b2282eb 860lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_get_next(
60ee8be1 861 struct nb_cb_get_next_args *args)
ce45ffe7
CS
862{
863 /* TODO: implement me. */
864 return NULL;
865}
866
2b2282eb 867int lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_get_keys(
60ee8be1 868 struct nb_cb_get_keys_args *args)
ce45ffe7
CS
869{
870 /* TODO: implement me. */
871 return NB_OK;
872}
873
874const void *
2b2282eb 875lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_lookup_entry(
60ee8be1 876 struct nb_cb_lookup_entry_args *args)
ce45ffe7
CS
877{
878 /* TODO: implement me. */
879 return NULL;
880}
881
882/*
883 * XPath:
2b2282eb 884 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/mpls-label-stack/entry/id
ce45ffe7
CS
885 */
886struct yang_data *
2b2282eb 887lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_id_get_elem(
60ee8be1 888 struct nb_cb_get_elem_args *args)
ce45ffe7
CS
889{
890 /* TODO: implement me. */
891 return NULL;
892}
893
894/*
895 * XPath:
2b2282eb 896 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/mpls-label-stack/entry/label
ce45ffe7
CS
897 */
898struct yang_data *
2b2282eb 899lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_label_get_elem(
60ee8be1 900 struct nb_cb_get_elem_args *args)
ce45ffe7
CS
901{
902 /* TODO: implement me. */
903 return NULL;
904}
905
906/*
907 * XPath:
2b2282eb 908 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/mpls-label-stack/entry/ttl
ce45ffe7
CS
909 */
910struct yang_data *
2b2282eb 911lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_ttl_get_elem(
60ee8be1 912 struct nb_cb_get_elem_args *args)
ce45ffe7
CS
913{
914 /* TODO: implement me. */
915 return NULL;
916}
917
918/*
919 * XPath:
2b2282eb 920 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/mpls-label-stack/entry/traffic-class
ce45ffe7
CS
921 */
922struct yang_data *
2b2282eb 923lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_mpls_label_stack_entry_traffic_class_get_elem(
60ee8be1 924 struct nb_cb_get_elem_args *args)
ce45ffe7
CS
925{
926 /* TODO: implement me. */
927 return NULL;
928}
929
930/*
931 * XPath:
2b2282eb 932 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/duplicate
ce45ffe7
CS
933 */
934struct yang_data *
2b2282eb 935lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_duplicate_get_elem(
60ee8be1 936 struct nb_cb_get_elem_args *args)
ce45ffe7 937{
5a634c34
CS
938 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
939
940 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_DUPLICATE))
941 return yang_data_new_empty(args->xpath);
942
ce45ffe7
CS
943 return NULL;
944}
945
946/*
947 * XPath:
2b2282eb 948 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/recursive
ce45ffe7
CS
949 */
950struct yang_data *
2b2282eb 951lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_recursive_get_elem(
60ee8be1 952 struct nb_cb_get_elem_args *args)
ce45ffe7 953{
5a634c34
CS
954 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
955
956 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
957 return yang_data_new_empty(args->xpath);
958
ce45ffe7
CS
959 return NULL;
960}
961
962/*
963 * XPath:
2b2282eb 964 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/active
ce45ffe7
CS
965 */
966struct yang_data *
2b2282eb 967lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_active_get_elem(
60ee8be1 968 struct nb_cb_get_elem_args *args)
ce45ffe7 969{
5a634c34
CS
970 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
971
972 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
973 return yang_data_new_empty(args->xpath);
974
ce45ffe7
CS
975 return NULL;
976}
977
978/*
979 * XPath:
2b2282eb 980 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/fib
ce45ffe7
CS
981 */
982struct yang_data *
2b2282eb 983lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_fib_get_elem(
60ee8be1 984 struct nb_cb_get_elem_args *args)
ce45ffe7 985{
5a634c34
CS
986 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
987
988 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB))
989 return yang_data_new_empty(args->xpath);
990
ce45ffe7
CS
991 return NULL;
992}
7225e61c
CS
993
994/*
995 * XPath:
2b2282eb 996 * /frr-vrf:lib/vrf/frr-zebra:zebra/ribs/rib/route/route-entry/nexthop-group/nexthop/weight
7225e61c
CS
997 */
998struct yang_data *
2b2282eb 999lib_vrf_zebra_ribs_rib_route_route_entry_nexthop_group_nexthop_weight_get_elem(
60ee8be1 1000 struct nb_cb_get_elem_args *args)
7225e61c 1001{
5a634c34
CS
1002 struct nexthop *nexthop = (struct nexthop *)args->list_entry;
1003
1004 if (nexthop->weight)
1005 return yang_data_new_uint8(args->xpath, nexthop->weight);
1006
7225e61c
CS
1007 return NULL;
1008}