Coverage Report

Created: 2025-11-09 06:11

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/frr/lib/routing_nb_config.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3
 * Copyright (C) 2018        Vmware
4
 *                           Vishal Dhingra
5
 */
6
7
#include <zebra.h>
8
9
#include "northbound.h"
10
#include "libfrr.h"
11
#include "vrf.h"
12
#include "lib_errors.h"
13
#include "routing_nb.h"
14
15
16
DEFINE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args));
17
18
/*
19
 * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol
20
 */
21
22
int routing_control_plane_protocols_control_plane_protocol_create(
23
  struct nb_cb_create_args *args)
24
0
{
25
0
  struct vrf *vrf;
26
0
  const char *vrfname;
27
28
0
  switch (args->event) {
29
0
  case NB_EV_VALIDATE:
30
0
    if (hook_call(routing_conf_event, args))
31
0
      return NB_ERR_VALIDATION;
32
0
    break;
33
0
  case NB_EV_PREPARE:
34
0
  case NB_EV_ABORT:
35
0
    break;
36
0
  case NB_EV_APPLY:
37
    /*
38
     * If the daemon relies on the VRF pointer stored in this
39
     * dnode, then it should register the dependency between this
40
     * module and the VRF module using
41
     * routing_control_plane_protocols_register_vrf_dependency.
42
     * If such dependency is not registered, then nothing is
43
     * stored in the dnode. If the dependency is registered,
44
     * find the vrf and store the pointer.
45
     */
46
0
    if (nb_node_has_dependency(args->dnode->schema->priv)) {
47
0
      vrfname = yang_dnode_get_string(args->dnode, "./vrf");
48
0
      vrf = vrf_lookup_by_name(vrfname);
49
0
      assert(vrf);
50
0
      nb_running_set_entry(args->dnode, vrf);
51
0
    }
52
0
    break;
53
0
  };
54
55
0
  return NB_OK;
56
0
}
57
58
int routing_control_plane_protocols_control_plane_protocol_destroy(
59
  struct nb_cb_destroy_args *args)
60
0
{
61
0
  if (args->event != NB_EV_APPLY)
62
0
    return NB_OK;
63
64
  /*
65
   * If dependency on VRF module is registered, then VRF
66
   * pointer was stored and must be cleared.
67
   */
68
0
  if (nb_node_has_dependency(args->dnode->schema->priv))
69
0
    nb_running_unset_entry(args->dnode);
70
71
0
  return NB_OK;
72
0
}
73
74
static void vrf_to_control_plane_protocol(const struct lyd_node *dnode,
75
            char *xpath)
76
0
{
77
0
  const char *vrf;
78
79
0
  vrf = yang_dnode_get_string(dnode, "./name");
80
81
0
  snprintf(xpath, XPATH_MAXLEN, FRR_ROUTING_KEY_XPATH_VRF, vrf);
82
0
}
83
84
static void control_plane_protocol_to_vrf(const struct lyd_node *dnode,
85
            char *xpath)
86
0
{
87
0
  const char *vrf;
88
89
0
  vrf = yang_dnode_get_string(dnode, "./vrf");
90
91
0
  snprintf(xpath, XPATH_MAXLEN, FRR_VRF_KEY_XPATH, vrf);
92
0
}
93
94
void routing_control_plane_protocols_register_vrf_dependency(void)
95
0
{
96
0
  struct nb_dependency_callbacks cbs;
97
98
0
  cbs.get_dependant_xpath = vrf_to_control_plane_protocol;
99
0
  cbs.get_dependency_xpath = control_plane_protocol_to_vrf;
100
101
0
  nb_node_set_dependency_cbs(FRR_VRF_XPATH, FRR_ROUTING_XPATH, &cbs);
102
0
}