2 * Copyright (C) 2018 NetDEF, Inc.
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)
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
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
29 #include "northbound.h"
32 #include "ripd/ripd.h"
33 #include "ripd/rip_nb.h"
34 #include "ripd/rip_debug.h"
35 #include "ripd/rip_interface.h"
38 * XPath: /frr-ripd:ripd/instance
40 const void *ripd_instance_get_next(struct nb_cb_get_next_args
*args
)
42 struct rip
*rip
= (struct rip
*)args
->list_entry
;
44 if (args
->list_entry
== NULL
)
45 rip
= RB_MIN(rip_instance_head
, &rip_instances
);
47 rip
= RB_NEXT(rip_instance_head
, rip
);
52 int ripd_instance_get_keys(struct nb_cb_get_keys_args
*args
)
54 const struct rip
*rip
= args
->list_entry
;
57 strlcpy(args
->keys
->key
[0], rip
->vrf_name
, sizeof(args
->keys
->key
[0]));
62 const void *ripd_instance_lookup_entry(struct nb_cb_lookup_entry_args
*args
)
64 const char *vrf_name
= args
->keys
->key
[0];
66 return rip_lookup_by_vrf_name(vrf_name
);
70 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor
72 const void *ripd_instance_state_neighbors_neighbor_get_next(
73 struct nb_cb_get_next_args
*args
)
75 const struct rip
*rip
= args
->parent_list_entry
;
76 struct listnode
*node
;
78 if (args
->list_entry
== NULL
)
79 node
= listhead(rip
->peer_list
);
81 node
= listnextnode((struct listnode
*)args
->list_entry
);
86 int ripd_instance_state_neighbors_neighbor_get_keys(
87 struct nb_cb_get_keys_args
*args
)
89 const struct listnode
*node
= args
->list_entry
;
90 const struct rip_peer
*peer
= listgetdata(node
);
93 (void)inet_ntop(AF_INET
, &peer
->addr
, args
->keys
->key
[0],
94 sizeof(args
->keys
->key
[0]));
99 const void *ripd_instance_state_neighbors_neighbor_lookup_entry(
100 struct nb_cb_lookup_entry_args
*args
)
102 const struct rip
*rip
= args
->parent_list_entry
;
103 struct in_addr address
;
104 struct rip_peer
*peer
;
105 struct listnode
*node
;
107 yang_str2ipv4(args
->keys
->key
[0], &address
);
109 for (ALL_LIST_ELEMENTS_RO(rip
->peer_list
, node
, peer
)) {
110 if (IPV4_ADDR_SAME(&peer
->addr
, &address
))
118 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/address
120 struct yang_data
*ripd_instance_state_neighbors_neighbor_address_get_elem(
121 struct nb_cb_get_elem_args
*args
)
123 const struct listnode
*node
= args
->list_entry
;
124 const struct rip_peer
*peer
= listgetdata(node
);
126 return yang_data_new_ipv4(args
->xpath
, &peer
->addr
);
130 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/last-update
132 struct yang_data
*ripd_instance_state_neighbors_neighbor_last_update_get_elem(
133 struct nb_cb_get_elem_args
*args
)
135 /* TODO: yang:date-and-time is tricky */
140 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/bad-packets-rcvd
143 ripd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
144 struct nb_cb_get_elem_args
*args
)
146 const struct listnode
*node
= args
->list_entry
;
147 const struct rip_peer
*peer
= listgetdata(node
);
149 return yang_data_new_uint32(args
->xpath
, peer
->recv_badpackets
);
153 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/bad-routes-rcvd
156 ripd_instance_state_neighbors_neighbor_bad_routes_rcvd_get_elem(
157 struct nb_cb_get_elem_args
*args
)
159 const struct listnode
*node
= args
->list_entry
;
160 const struct rip_peer
*peer
= listgetdata(node
);
162 return yang_data_new_uint32(args
->xpath
, peer
->recv_badroutes
);
166 * XPath: /frr-ripd:ripd/instance/state/routes/route
169 ripd_instance_state_routes_route_get_next(struct nb_cb_get_next_args
*args
)
171 const struct rip
*rip
= args
->parent_list_entry
;
172 struct route_node
*rn
;
174 if (args
->list_entry
== NULL
)
175 rn
= route_top(rip
->table
);
177 rn
= route_next((struct route_node
*)args
->list_entry
);
178 while (rn
&& rn
->info
== NULL
)
184 int ripd_instance_state_routes_route_get_keys(struct nb_cb_get_keys_args
*args
)
186 const struct route_node
*rn
= args
->list_entry
;
189 (void)prefix2str(&rn
->p
, args
->keys
->key
[0],
190 sizeof(args
->keys
->key
[0]));
195 const void *ripd_instance_state_routes_route_lookup_entry(
196 struct nb_cb_lookup_entry_args
*args
)
198 const struct rip
*rip
= args
->parent_list_entry
;
199 struct prefix prefix
;
200 struct route_node
*rn
;
202 yang_str2ipv4p(args
->keys
->key
[0], &prefix
);
204 rn
= route_node_lookup(rip
->table
, &prefix
);
205 if (!rn
|| !rn
->info
)
208 route_unlock_node(rn
);
214 * XPath: /frr-ripd:ripd/instance/state/routes/route/prefix
216 struct yang_data
*ripd_instance_state_routes_route_prefix_get_elem(
217 struct nb_cb_get_elem_args
*args
)
219 const struct route_node
*rn
= args
->list_entry
;
220 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
222 return yang_data_new_ipv4p(args
->xpath
, &rinfo
->rp
->p
);
226 * XPath: /frr-ripd:ripd/instance/state/routes/route/next-hop
228 struct yang_data
*ripd_instance_state_routes_route_next_hop_get_elem(
229 struct nb_cb_get_elem_args
*args
)
231 const struct route_node
*rn
= args
->list_entry
;
232 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
234 switch (rinfo
->nh
.type
) {
235 case NEXTHOP_TYPE_IPV4
:
236 case NEXTHOP_TYPE_IPV4_IFINDEX
:
237 return yang_data_new_ipv4(args
->xpath
, &rinfo
->nh
.gate
.ipv4
);
244 * XPath: /frr-ripd:ripd/instance/state/routes/route/interface
246 struct yang_data
*ripd_instance_state_routes_route_interface_get_elem(
247 struct nb_cb_get_elem_args
*args
)
249 const struct route_node
*rn
= args
->list_entry
;
250 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
251 const struct rip
*rip
= rip_info_get_instance(rinfo
);
253 switch (rinfo
->nh
.type
) {
254 case NEXTHOP_TYPE_IFINDEX
:
255 case NEXTHOP_TYPE_IPV4_IFINDEX
:
256 return yang_data_new_string(
258 ifindex2ifname(rinfo
->nh
.ifindex
, rip
->vrf
->vrf_id
));
265 * XPath: /frr-ripd:ripd/instance/state/routes/route/metric
267 struct yang_data
*ripd_instance_state_routes_route_metric_get_elem(
268 struct nb_cb_get_elem_args
*args
)
270 const struct route_node
*rn
= args
->list_entry
;
271 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
273 return yang_data_new_uint8(args
->xpath
, rinfo
->metric
);