]>
git.proxmox.com Git - mirror_frr.git/blob - ripngd/ripng_nb_state.c
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 "agg_table.h"
30 #include "northbound.h"
33 #include "ripngd/ripngd.h"
34 #include "ripngd/ripng_nb.h"
35 #include "ripngd/ripng_debug.h"
36 #include "ripngd/ripng_route.h"
39 * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor
41 const void *ripngd_instance_state_neighbors_neighbor_get_next(
42 struct nb_cb_get_next_args
*args
)
44 const struct ripng
*ripng
= args
->parent_list_entry
;
45 struct listnode
*node
;
47 if (args
->list_entry
== NULL
)
48 node
= listhead(ripng
->peer_list
);
50 node
= listnextnode((struct listnode
*)args
->list_entry
);
55 int ripngd_instance_state_neighbors_neighbor_get_keys(
56 struct nb_cb_get_keys_args
*args
)
58 const struct listnode
*node
= args
->list_entry
;
59 const struct ripng_peer
*peer
= listgetdata(node
);
62 (void)inet_ntop(AF_INET6
, &peer
->addr
, args
->keys
->key
[0],
63 sizeof(args
->keys
->key
[0]));
68 const void *ripngd_instance_state_neighbors_neighbor_lookup_entry(
69 struct nb_cb_lookup_entry_args
*args
)
71 const struct ripng
*ripng
= args
->parent_list_entry
;
72 struct in6_addr address
;
73 struct ripng_peer
*peer
;
74 struct listnode
*node
;
76 yang_str2ipv6(args
->keys
->key
[0], &address
);
78 for (ALL_LIST_ELEMENTS_RO(ripng
->peer_list
, node
, peer
)) {
79 if (IPV6_ADDR_SAME(&peer
->addr
, &address
))
87 * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor/address
89 struct yang_data
*ripngd_instance_state_neighbors_neighbor_address_get_elem(
90 struct nb_cb_get_elem_args
*args
)
92 const struct listnode
*node
= args
->list_entry
;
93 const struct ripng_peer
*peer
= listgetdata(node
);
95 return yang_data_new_ipv6(args
->xpath
, &peer
->addr
);
99 * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor/last-update
101 struct yang_data
*ripngd_instance_state_neighbors_neighbor_last_update_get_elem(
102 struct nb_cb_get_elem_args
*args
)
104 /* TODO: yang:date-and-time is tricky */
109 * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor/bad-packets-rcvd
112 ripngd_instance_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
113 struct nb_cb_get_elem_args
*args
)
115 const struct listnode
*node
= args
->list_entry
;
116 const struct ripng_peer
*peer
= listgetdata(node
);
118 return yang_data_new_uint32(args
->xpath
, peer
->recv_badpackets
);
122 * XPath: /frr-ripngd:ripngd/instance/state/neighbors/neighbor/bad-routes-rcvd
125 ripngd_instance_state_neighbors_neighbor_bad_routes_rcvd_get_elem(
126 struct nb_cb_get_elem_args
*args
)
128 const struct listnode
*node
= args
->list_entry
;
129 const struct ripng_peer
*peer
= listgetdata(node
);
131 return yang_data_new_uint32(args
->xpath
, peer
->recv_badroutes
);
135 * XPath: /frr-ripngd:ripngd/instance/state/routes/route
138 ripngd_instance_state_routes_route_get_next(struct nb_cb_get_next_args
*args
)
140 const struct ripng
*ripng
= args
->parent_list_entry
;
143 if (args
->list_entry
== NULL
)
144 rn
= agg_route_top(ripng
->table
);
146 rn
= agg_route_next((struct agg_node
*)args
->list_entry
);
147 /* Optimization: skip empty route nodes. */
148 while (rn
&& rn
->info
== NULL
)
149 rn
= agg_route_next(rn
);
154 int ripngd_instance_state_routes_route_get_keys(
155 struct nb_cb_get_keys_args
*args
)
157 const struct agg_node
*rn
= args
->list_entry
;
160 (void)prefix2str(agg_node_get_prefix(rn
), args
->keys
->key
[0],
161 sizeof(args
->keys
->key
[0]));
166 const void *ripngd_instance_state_routes_route_lookup_entry(
167 struct nb_cb_lookup_entry_args
*args
)
169 const struct ripng
*ripng
= args
->parent_list_entry
;
170 struct prefix prefix
;
173 yang_str2ipv6p(args
->keys
->key
[0], &prefix
);
175 rn
= agg_node_lookup(ripng
->table
, &prefix
);
176 if (!rn
|| !rn
->info
)
185 * XPath: /frr-ripngd:ripngd/instance/state/routes/route/prefix
187 struct yang_data
*ripngd_instance_state_routes_route_prefix_get_elem(
188 struct nb_cb_get_elem_args
*args
)
190 const struct agg_node
*rn
= args
->list_entry
;
191 const struct ripng_info
*rinfo
= listnode_head(rn
->info
);
193 return yang_data_new_ipv6p(args
->xpath
, agg_node_get_prefix(rinfo
->rp
));
197 * XPath: /frr-ripngd:ripngd/instance/state/routes/route/next-hop
199 struct yang_data
*ripngd_instance_state_routes_route_next_hop_get_elem(
200 struct nb_cb_get_elem_args
*args
)
202 const struct agg_node
*rn
= args
->list_entry
;
203 const struct ripng_info
*rinfo
= listnode_head(rn
->info
);
205 return yang_data_new_ipv6(args
->xpath
, &rinfo
->nexthop
);
209 * XPath: /frr-ripngd:ripngd/instance/state/routes/route/interface
211 struct yang_data
*ripngd_instance_state_routes_route_interface_get_elem(
212 struct nb_cb_get_elem_args
*args
)
214 const struct agg_node
*rn
= args
->list_entry
;
215 const struct ripng_info
*rinfo
= listnode_head(rn
->info
);
216 const struct ripng
*ripng
= ripng_info_get_instance(rinfo
);
218 return yang_data_new_string(
220 ifindex2ifname(rinfo
->ifindex
, ripng
->vrf
->vrf_id
));
224 * XPath: /frr-ripngd:ripngd/instance/state/routes/route/metric
226 struct yang_data
*ripngd_instance_state_routes_route_metric_get_elem(
227 struct nb_cb_get_elem_args
*args
)
229 const struct agg_node
*rn
= args
->list_entry
;
230 const struct ripng_info
*rinfo
= listnode_head(rn
->info
);
232 return yang_data_new_uint8(args
->xpath
, rinfo
->metric
);