]> git.puffer.fish Git - matthieu/frr.git/commitdiff
ripngd: implement northbound callbacks to fetch neighbor information
authorRenato Westphal <renato@opensourcerouting.org>
Thu, 29 Nov 2018 18:41:32 +0000 (16:41 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Mon, 3 Dec 2018 15:47:58 +0000 (13:47 -0200)
The "neighbors" YANG container was copied and adapted from the
ietf-rip module.

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

index 6ec80982be26d41d555b9afb3cec0a226aafe6e3..ad727582ddb77b3577452890a6c764d4d30fad68 100644 (file)
@@ -579,14 +579,26 @@ static const void *
 ripngd_state_neighbors_neighbor_get_next(const void *parent_list_entry,
                                         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 ripngd_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 ripng_peer *peer = listgetdata(node);
+
+       keys->num = 1;
+       (void)inet_ntop(AF_INET6, &peer->addr, keys->key[0],
+                       sizeof(keys->key[0]));
+
        return NB_OK;
 }
 
@@ -594,7 +606,17 @@ static const void *
 ripngd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry,
                                             const struct yang_list_keys *keys)
 {
-       /* TODO: implement me. */
+       struct in6_addr address;
+       struct ripng_peer *peer;
+       struct listnode *node;
+
+       yang_str2ipv6(keys->key[0], &address);
+
+       for (ALL_LIST_ELEMENTS_RO(peer_list, node, peer)) {
+               if (IPV6_ADDR_SAME(&peer->addr, &address))
+                       return node;
+       }
+
        return NULL;
 }
 
@@ -605,8 +627,10 @@ static struct yang_data *
 ripngd_state_neighbors_neighbor_address_get_elem(const char *xpath,
                                                 const void *list_entry)
 {
-       /* TODO: implement me. */
-       return NULL;
+       const struct listnode *node = list_entry;
+       const struct ripng_peer *peer = listgetdata(node);
+
+       return yang_data_new_ipv6(xpath, &peer->addr);
 }
 
 /*
@@ -616,7 +640,7 @@ static struct yang_data *
 ripngd_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;
 }
 
@@ -627,8 +651,10 @@ static struct yang_data *
 ripngd_state_neighbors_neighbor_bad_packets_rcvd_get_elem(
        const char *xpath, const void *list_entry)
 {
-       /* TODO: implement me. */
-       return NULL;
+       const struct listnode *node = list_entry;
+       const struct ripng_peer *peer = listgetdata(node);
+
+       return yang_data_new_uint32(xpath, peer->recv_badpackets);
 }
 
 /*
@@ -638,8 +664,10 @@ static struct yang_data *
 ripngd_state_neighbors_neighbor_bad_routes_rcvd_get_elem(const char *xpath,
                                                         const void *list_entry)
 {
-       /* TODO: implement me. */
-       return NULL;
+       const struct listnode *node = list_entry;
+       const struct ripng_peer *peer = listgetdata(node);
+
+       return yang_data_new_uint32(xpath, peer->recv_badroutes);
 }
 
 /*
index fc29b9d0d944a2dae36a6f2566bc46c98687d086..5b32374ace87238f08127ea0a80c941ba628ce02 100644 (file)
@@ -329,6 +329,7 @@ struct ripng_offset_list {
 
 /* Extern variables. */
 extern struct ripng *ripng;
+extern struct list *peer_list;
 extern struct zebra_privs_t ripngd_privs;
 extern struct thread_master *master;