]> git.puffer.fish Git - mirror/frr.git/commitdiff
ripd: implement northbound callbacks to fetch neighbor information
authorRenato Westphal <renato@opensourcerouting.org>
Wed, 9 May 2018 04:35:03 +0000 (01:35 -0300)
committerRenato Westphal <renato@opensourcerouting.org>
Sat, 27 Oct 2018 18:16:12 +0000 (16:16 -0200)
Support for fetching operational data is experimental at this point.
Locks must be introduced to ensure the peer_list global variable won't
be modified while we're iterating asynchronously over it (or iterating
from a separate pthread).

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_northbound.c
ripd/ripd.h

index 6666912a008c85e6a97a89f56ff67bd50d704335..8c5248231457989bc84b0d798f3eeab242c4f9b8 100644 (file)
@@ -1006,22 +1006,37 @@ static const void *
 ripd_state_neighbors_neighbor_get_next(const char *xpath,
                                       const void *list_entry)
 {
-       /* TODO: implement me. */
-       return NULL;
+       struct listnode *node;
+
+       if (list_entry == NULL)
+               node = listhead(peer_list);
+       else
+               node = listnextnode((struct listnode *)list_entry);
+
+       return node;
 }
 
 static int ripd_state_neighbors_neighbor_get_keys(const void *list_entry,
                                                  struct yang_list_keys *keys)
 {
-       /* TODO: implement me. */
+       const struct listnode *node = list_entry;
+       const struct rip_peer *peer = listgetdata(node);
+
+       keys->num = 1;
+       (void)inet_ntop(AF_INET, &peer->addr, keys->key[0].value,
+                       sizeof(keys->key[0].value));
+
        return NB_OK;
 }
 
 static const void *
 ripd_state_neighbors_neighbor_lookup_entry(const struct yang_list_keys *keys)
 {
-       /* TODO: implement me. */
-       return NULL;
+       struct in_addr address;
+
+       yang_str2ipv4(keys->key[0].value, &address);
+
+       return rip_peer_lookup(&address);
 }
 
 /*
@@ -1031,8 +1046,9 @@ static struct yang_data *
 ripd_state_neighbors_neighbor_address_get_elem(const char *xpath,
                                               const void *list_entry)
 {
-       /* TODO: implement me. */
-       return NULL;
+       const struct rip_peer *peer = list_entry;
+
+       return yang_data_new_ipv4(xpath, &peer->addr);
 }
 
 /*
@@ -1042,7 +1058,7 @@ static struct yang_data *
 ripd_state_neighbors_neighbor_last_update_get_elem(const char *xpath,
                                                   const void *list_entry)
 {
-       /* TODO: implement me. */
+       /* TODO: yang:date-and-time is tricky */
        return NULL;
 }
 
@@ -1053,8 +1069,9 @@ static struct yang_data *
 ripd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(const char *xpath,
                                                        const void *list_entry)
 {
-       /* TODO: implement me. */
-       return NULL;
+       const struct rip_peer *peer = list_entry;
+
+       return yang_data_new_uint32(xpath, peer->recv_badpackets);
 }
 
 /*
@@ -1064,8 +1081,9 @@ static struct yang_data *
 ripd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath,
                                                       const void *list_entry)
 {
-       /* TODO: implement me. */
-       return NULL;
+       const struct rip_peer *peer = list_entry;
+
+       return yang_data_new_uint32(xpath, peer->recv_badroutes);
 }
 
 /*
index 6af99ada217c5faa1497a769ce8caa77a25ae3f1..81e97f842881b829e190ef9604301697f17dc369 100644 (file)
@@ -466,6 +466,7 @@ extern long rip_global_queries;
 DECLARE_HOOK(rip_ifaddr_add, (struct connected * ifc), (ifc))
 DECLARE_HOOK(rip_ifaddr_del, (struct connected * ifc), (ifc))
 
+extern struct list *peer_list;
 extern struct route_table *rip_distance_table;
 extern vector Vrip_passive_nondefault;