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(const void *parent_list_entry
,
41 const void *list_entry
)
43 struct rip
*rip
= (struct rip
*)list_entry
;
45 if (list_entry
== NULL
)
46 rip
= RB_MIN(rip_instance_head
, &rip_instances
);
48 rip
= RB_NEXT(rip_instance_head
, rip
);
53 int ripd_instance_get_keys(const void *list_entry
, struct yang_list_keys
*keys
)
55 const struct rip
*rip
= list_entry
;
58 strlcpy(keys
->key
[0], rip
->vrf_name
, sizeof(keys
->key
[0]));
63 const void *ripd_instance_lookup_entry(const void *parent_list_entry
,
64 const struct yang_list_keys
*keys
)
66 const char *vrf_name
= keys
->key
[0];
68 return rip_lookup_by_vrf_name(vrf_name
);
72 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor
75 ripd_instance_state_neighbors_neighbor_get_next(const void *parent_list_entry
,
76 const void *list_entry
)
78 const struct rip
*rip
= parent_list_entry
;
79 struct listnode
*node
;
81 if (list_entry
== NULL
)
82 node
= listhead(rip
->peer_list
);
84 node
= listnextnode((struct listnode
*)list_entry
);
89 int ripd_instance_state_neighbors_neighbor_get_keys(const void *list_entry
,
90 struct yang_list_keys
*keys
)
92 const struct listnode
*node
= list_entry
;
93 const struct rip_peer
*peer
= listgetdata(node
);
96 (void)inet_ntop(AF_INET
, &peer
->addr
, keys
->key
[0],
97 sizeof(keys
->key
[0]));
102 const void *ripd_instance_state_neighbors_neighbor_lookup_entry(
103 const void *parent_list_entry
, const struct yang_list_keys
*keys
)
105 const struct rip
*rip
= parent_list_entry
;
106 struct in_addr address
;
107 struct rip_peer
*peer
;
108 struct listnode
*node
;
110 yang_str2ipv4(keys
->key
[0], &address
);
112 for (ALL_LIST_ELEMENTS_RO(rip
->peer_list
, node
, peer
)) {
113 if (IPV4_ADDR_SAME(&peer
->addr
, &address
))
121 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/address
124 ripd_instance_state_neighbors_neighbor_address_get_elem(const char *xpath
,
125 const void *list_entry
)
127 const struct listnode
*node
= list_entry
;
128 const struct rip_peer
*peer
= listgetdata(node
);
130 return yang_data_new_ipv4(xpath
, &peer
->addr
);
134 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/last-update
136 struct yang_data
*ripd_instance_state_neighbors_neighbor_last_update_get_elem(
137 const char *xpath
, const void *list_entry
)
139 /* TODO: yang:date-and-time is tricky */
144 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/bad-packets-rcvd
147 ripd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
148 const char *xpath
, const void *list_entry
)
150 const struct listnode
*node
= list_entry
;
151 const struct rip_peer
*peer
= listgetdata(node
);
153 return yang_data_new_uint32(xpath
, peer
->recv_badpackets
);
157 * XPath: /frr-ripd:ripd/instance/state/neighbors/neighbor/bad-routes-rcvd
160 ripd_instance_state_neighbors_neighbor_bad_routes_rcvd_get_elem(
161 const char *xpath
, const void *list_entry
)
163 const struct listnode
*node
= list_entry
;
164 const struct rip_peer
*peer
= listgetdata(node
);
166 return yang_data_new_uint32(xpath
, peer
->recv_badroutes
);
170 * XPath: /frr-ripd:ripd/instance/state/routes/route
173 ripd_instance_state_routes_route_get_next(const void *parent_list_entry
,
174 const void *list_entry
)
176 const struct rip
*rip
= parent_list_entry
;
177 struct route_node
*rn
;
179 if (list_entry
== NULL
)
180 rn
= route_top(rip
->table
);
182 rn
= route_next((struct route_node
*)list_entry
);
183 while (rn
&& rn
->info
== NULL
)
189 int ripd_instance_state_routes_route_get_keys(const void *list_entry
,
190 struct yang_list_keys
*keys
)
192 const struct route_node
*rn
= list_entry
;
195 (void)prefix2str(&rn
->p
, keys
->key
[0], sizeof(keys
->key
[0]));
201 ripd_instance_state_routes_route_lookup_entry(const void *parent_list_entry
,
202 const struct yang_list_keys
*keys
)
204 const struct rip
*rip
= parent_list_entry
;
205 struct prefix prefix
;
206 struct route_node
*rn
;
208 yang_str2ipv4p(keys
->key
[0], &prefix
);
210 rn
= route_node_lookup(rip
->table
, &prefix
);
211 if (!rn
|| !rn
->info
)
214 route_unlock_node(rn
);
220 * XPath: /frr-ripd:ripd/instance/state/routes/route/prefix
223 ripd_instance_state_routes_route_prefix_get_elem(const char *xpath
,
224 const void *list_entry
)
226 const struct route_node
*rn
= list_entry
;
227 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
229 return yang_data_new_ipv4p(xpath
, &rinfo
->rp
->p
);
233 * XPath: /frr-ripd:ripd/instance/state/routes/route/next-hop
236 ripd_instance_state_routes_route_next_hop_get_elem(const char *xpath
,
237 const void *list_entry
)
239 const struct route_node
*rn
= list_entry
;
240 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
242 switch (rinfo
->nh
.type
) {
243 case NEXTHOP_TYPE_IPV4
:
244 case NEXTHOP_TYPE_IPV4_IFINDEX
:
245 return yang_data_new_ipv4(xpath
, &rinfo
->nh
.gate
.ipv4
);
252 * XPath: /frr-ripd:ripd/instance/state/routes/route/interface
255 ripd_instance_state_routes_route_interface_get_elem(const char *xpath
,
256 const void *list_entry
)
258 const struct route_node
*rn
= list_entry
;
259 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
260 const struct rip
*rip
= rip_info_get_instance(rinfo
);
262 switch (rinfo
->nh
.type
) {
263 case NEXTHOP_TYPE_IFINDEX
:
264 case NEXTHOP_TYPE_IPV4_IFINDEX
:
265 return yang_data_new_string(
267 ifindex2ifname(rinfo
->nh
.ifindex
, rip
->vrf
->vrf_id
));
274 * XPath: /frr-ripd:ripd/instance/state/routes/route/metric
277 ripd_instance_state_routes_route_metric_get_elem(const char *xpath
,
278 const void *list_entry
)
280 const struct route_node
*rn
= list_entry
;
281 const struct rip_info
*rinfo
= listnode_head(rn
->info
);
283 return yang_data_new_uint8(xpath
, rinfo
->metric
);