From: Renato Westphal Date: Wed, 9 May 2018 04:35:03 +0000 (-0300) Subject: ripd: implement northbound callbacks to fetch neighbor information X-Git-Tag: frr-7.1-dev~228^2~13 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=5c1a84977b749f30b8361e135d2a555f6fa3383d;p=mirror%2Ffrr.git ripd: implement northbound callbacks to fetch neighbor information 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 --- diff --git a/ripd/rip_northbound.c b/ripd/rip_northbound.c index 6666912a00..8c52482314 100644 --- a/ripd/rip_northbound.c +++ b/ripd/rip_northbound.c @@ -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); } /* diff --git a/ripd/ripd.h b/ripd/ripd.h index 6af99ada21..81e97f8428 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -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;