From 29e897ad333790601929c09904a7e2ff146bcf55 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Fri, 4 Jan 2019 19:08:10 -0200 Subject: [PATCH] ripd: move "peer_list" to the rip structure Signed-off-by: Renato Westphal --- ripd/rip_main.c | 1 - ripd/rip_northbound.c | 10 ++++++++-- ripd/rip_peer.c | 21 ++++++--------------- ripd/rip_snmp.c | 3 +++ ripd/ripd.c | 2 ++ ripd/ripd.h | 8 +++++--- 6 files changed, 24 insertions(+), 21 deletions(-) diff --git a/ripd/rip_main.c b/ripd/rip_main.c index e6373664b..8c6340f6c 100644 --- a/ripd/rip_main.c +++ b/ripd/rip_main.c @@ -179,7 +179,6 @@ int main(int argc, char **argv) rip_if_init(); rip_cli_init(); rip_zclient_init(master); - rip_peer_init(); frr_config_fork(); frr_run(master); diff --git a/ripd/rip_northbound.c b/ripd/rip_northbound.c index 49bf90198..17ba67261 100644 --- a/ripd/rip_northbound.c +++ b/ripd/rip_northbound.c @@ -1012,8 +1012,11 @@ ripd_state_neighbors_neighbor_get_next(const void *parent_list_entry, { struct listnode *node; + if (rip == NULL) + return NULL; + if (list_entry == NULL) - node = listhead(peer_list); + node = listhead(rip->peer_list); else node = listnextnode((struct listnode *)list_entry); @@ -1043,7 +1046,10 @@ ripd_state_neighbors_neighbor_lookup_entry(const void *parent_list_entry, yang_str2ipv4(keys->key[0], &address); - for (ALL_LIST_ELEMENTS_RO(peer_list, node, peer)) { + if (rip == NULL) + return NULL; + + for (ALL_LIST_ELEMENTS_RO(rip->peer_list, node, peer)) { if (IPV4_ADDR_SAME(&peer->addr, &address)) return node; } diff --git a/ripd/rip_peer.c b/ripd/rip_peer.c index 21317915d..ca3f25e94 100644 --- a/ripd/rip_peer.c +++ b/ripd/rip_peer.c @@ -29,9 +29,6 @@ #include "ripd/ripd.h" -/* Linked list of RIP peer. */ -struct list *peer_list; - static struct rip_peer *rip_peer_new(void) { return XCALLOC(MTYPE_RIP_PEER, sizeof(struct rip_peer)); @@ -47,7 +44,7 @@ struct rip_peer *rip_peer_lookup(struct in_addr *addr) struct rip_peer *peer; struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS(peer_list, node, nnode, peer)) { + for (ALL_LIST_ELEMENTS(rip->peer_list, node, nnode, peer)) { if (IPV4_ADDR_SAME(&peer->addr, addr)) return peer; } @@ -59,7 +56,7 @@ struct rip_peer *rip_peer_lookup_next(struct in_addr *addr) struct rip_peer *peer; struct listnode *node, *nnode; - for (ALL_LIST_ELEMENTS(peer_list, node, nnode, peer)) { + for (ALL_LIST_ELEMENTS(rip->peer_list, node, nnode, peer)) { if (htonl(peer->addr.s_addr) > htonl(addr->s_addr)) return peer; } @@ -72,7 +69,7 @@ static int rip_peer_timeout(struct thread *t) struct rip_peer *peer; peer = THREAD_ARG(t); - listnode_delete(peer_list, peer); + listnode_delete(rip->peer_list, peer); rip_peer_free(peer); return 0; @@ -91,7 +88,7 @@ static struct rip_peer *rip_peer_get(struct in_addr *addr) } else { peer = rip_peer_new(); peer->addr = *addr; - listnode_add_sort(peer_list, peer); + listnode_add_sort(rip->peer_list, peer); } /* Update timeout thread. */ @@ -162,7 +159,7 @@ void rip_peer_display(struct vty *vty) #define RIP_UPTIME_LEN 25 char timebuf[RIP_UPTIME_LEN]; - for (ALL_LIST_ELEMENTS(peer_list, node, nnode, peer)) { + for (ALL_LIST_ELEMENTS(rip->peer_list, node, nnode, peer)) { vty_out(vty, " %-16s %9d %9d %9d %s\n", inet_ntoa(peer->addr), peer->recv_badpackets, peer->recv_badroutes, ZEBRA_RIP_DISTANCE_DEFAULT, @@ -170,16 +167,10 @@ void rip_peer_display(struct vty *vty) } } -static int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2) +int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2) { if (p2->addr.s_addr == p1->addr.s_addr) return 0; return (htonl(p1->addr.s_addr) < htonl(p2->addr.s_addr)) ? -1 : 1; } - -void rip_peer_init(void) -{ - peer_list = list_new(); - peer_list->cmp = (int (*)(void *, void *))rip_peer_list_cmp; -} diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c index 19367638c..9acc825c0 100644 --- a/ripd/rip_snmp.c +++ b/ripd/rip_snmp.c @@ -284,6 +284,9 @@ static struct rip_peer *rip2PeerLookup(struct variable *v, oid name[], int len; struct rip_peer *peer; + if (!rip) + return NULL; + if (exact) { /* Check the length. */ if (*length - v->namelen != sizeof(struct in_addr) + 1) diff --git a/ripd/ripd.c b/ripd/ripd.c index c7e2d6a24..e00b453f9 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -2692,6 +2692,8 @@ int rip_create(int socket) /* Initialize RIP data structures. */ rip->table = route_table_init(); rip->neighbor = route_table_init(); + rip->peer_list = list_new(); + rip->peer_list->cmp = (int (*)(void *, void *))rip_peer_list_cmp; rip->enable_interface = vector_init(1); rip->enable_network = route_table_init(); rip->passive_nondefault = vector_init(1); diff --git a/ripd/ripd.h b/ripd/ripd.h index 97ad1fb08..100c9d14b 100644 --- a/ripd/ripd.h +++ b/ripd/ripd.h @@ -112,9 +112,12 @@ struct rip { /* RIP routing information base. */ struct route_table *table; - /* RIP neighbor. */ + /* RIP static neighbors. */ struct route_table *neighbor; + /* Linked list of RIP peers. */ + struct list *peer_list; + /* RIP threads. */ struct thread *t_read; @@ -433,13 +436,13 @@ extern void rip_if_rmap_update_interface(struct interface *); extern int rip_show_network_config(struct vty *); extern void rip_show_redistribute_config(struct vty *); -extern void rip_peer_init(void); extern void rip_peer_update(struct sockaddr_in *, uint8_t); extern void rip_peer_bad_route(struct sockaddr_in *); extern void rip_peer_bad_packet(struct sockaddr_in *); extern void rip_peer_display(struct vty *); extern struct rip_peer *rip_peer_lookup(struct in_addr *); extern struct rip_peer *rip_peer_lookup_next(struct in_addr *); +extern int rip_peer_list_cmp(struct rip_peer *p1, struct rip_peer *p2); extern void rip_info_free(struct rip_info *); extern struct rip_distance *rip_distance_new(void); @@ -481,7 +484,6 @@ 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; /* Northbound. */ -- 2.39.5