Coverage Report

Created: 2025-12-05 06:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/frr/lib/affinitymap_northbound.c
Line
Count
Source
1
/*
2
 * affinity map northbound implementation.
3
 *
4
 * Copyright 2022 Hiroki Shirokura, LINE Corporation
5
 * Copyright 2022 Masakazu Asama
6
 * Copyright 2022 6WIND S.A.
7
 *
8
 * This file is part of Free Range Routing (FRR).
9
 *
10
 * FRR is free software; you can redistribute it and/or modify it
11
 * under the terms of the GNU General Public License as published by the
12
 * Free Software Foundation; either version 2, or (at your option) any
13
 * later version.
14
 *
15
 * FRR is distributed in the hope that it will be useful, but
16
 * WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18
 * General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License along
21
 * with this program; see the file COPYING; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
 */
24
25
#include <zebra.h>
26
27
#include "lib/command.h"
28
#include "lib/log.h"
29
#include "lib/northbound.h"
30
#include "lib/affinitymap.h"
31
32
/*
33
 * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map
34
 */
35
36
static int lib_affinity_map_create(struct nb_cb_create_args *args)
37
0
{
38
0
  return NB_OK;
39
0
}
40
41
static int lib_affinity_map_destroy(struct nb_cb_destroy_args *args)
42
0
{
43
0
  const char *name;
44
45
0
  name = yang_dnode_get_string((const struct lyd_node *)args->dnode,
46
0
             "./name");
47
48
0
  switch (args->event) {
49
0
  case NB_EV_VALIDATE:
50
0
    if (!affinity_map_check_use_hook(name))
51
0
      break;
52
0
    snprintf(args->errmsg, args->errmsg_len,
53
0
       "affinity-map %s is used", name);
54
0
    return NB_ERR_VALIDATION;
55
0
  case NB_EV_PREPARE:
56
0
  case NB_EV_ABORT:
57
0
    break;
58
0
  case NB_EV_APPLY:
59
0
    affinity_map_unset(name);
60
0
    break;
61
0
  }
62
0
  return NB_OK;
63
0
}
64
65
/*
66
 * XPath: /frr-affinity-map:lib/affinity-maps/affinity-map/value
67
 */
68
static int lib_affinity_map_value_modify(struct nb_cb_modify_args *args)
69
0
{
70
0
  const char *name;
71
0
  char *map_name;
72
0
  uint16_t pos;
73
74
0
  name = yang_dnode_get_string(
75
0
    (const struct lyd_node *)args->dnode->parent, "./name");
76
77
0
  pos = yang_dnode_get_uint16(
78
0
    (const struct lyd_node *)args->dnode->parent, "./value");
79
80
0
  switch (args->event) {
81
0
  case NB_EV_VALIDATE:
82
0
    map_name = affinity_map_name_get(pos);
83
0
    if (map_name &&
84
0
        strncmp(map_name, name, AFFINITY_NAME_SIZE) != 0) {
85
0
      snprintf(args->errmsg, args->errmsg_len,
86
0
         "bit-position is used by %s.", map_name);
87
0
      return NB_ERR_VALIDATION;
88
0
    }
89
0
    if (!affinity_map_check_update_hook(name, pos)) {
90
0
      snprintf(
91
0
        args->errmsg, args->errmsg_len,
92
0
        "affinity-map new bit-position > 31 but is used with standard admin-groups");
93
0
      return NB_ERR_VALIDATION;
94
0
    }
95
0
    break;
96
0
  case NB_EV_PREPARE:
97
0
  case NB_EV_ABORT:
98
0
    break;
99
0
  case NB_EV_APPLY:
100
0
    affinity_map_update_hook(name, pos);
101
0
    affinity_map_set(name, pos);
102
0
    break;
103
0
  }
104
105
0
  return NB_OK;
106
0
}
107
108
static int lib_affinity_map_value_destroy(struct nb_cb_destroy_args *args)
109
0
{
110
0
  return NB_OK;
111
0
}
112
113
/* clang-format off */
114
const struct frr_yang_module_info frr_affinity_map_info = {
115
  .name = "frr-affinity-map",
116
  .nodes = {
117
    {
118
      .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map",
119
      .cbs = {
120
        .create = lib_affinity_map_create,
121
        .destroy = lib_affinity_map_destroy,
122
        .cli_show = cli_show_affinity_map,
123
      }
124
    },
125
    {
126
      .xpath = "/frr-affinity-map:lib/affinity-maps/affinity-map/value",
127
      .cbs = {
128
        .modify = lib_affinity_map_value_modify,
129
        .destroy = lib_affinity_map_value_destroy,
130
      }
131
    },
132
    {
133
      .xpath = NULL,
134
    },
135
  }
136
};