]> git.proxmox.com Git - mirror_frr.git/commitdiff
ripd: move "peer_list" to the rip structure
authorRenato Westphal <renato@opensourcerouting.org>
Fri, 4 Jan 2019 21:08:10 +0000 (19:08 -0200)
committerRenato Westphal <renato@opensourcerouting.org>
Fri, 18 Jan 2019 18:15:41 +0000 (16:15 -0200)
Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
ripd/rip_main.c
ripd/rip_northbound.c
ripd/rip_peer.c
ripd/rip_snmp.c
ripd/ripd.c
ripd/ripd.h

index e6373664bf19e23bc1f4e2c3bccb543c5aa22201..8c6340f6c7b674ee359acaaf7c4ef18cb1603a7e 100644 (file)
@@ -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);
index 49bf90198a21c56885f79f2588b9b42abc64f7ea..17ba672614f8582e7a1521f82ce0b5a4d48d259d 100644 (file)
@@ -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;
        }
index 21317915d42613853a489112a18684b018c12f62..ca3f25e9499bbb3eb4061c4642b93790d6748322 100644 (file)
@@ -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;
-}
index 19367638cc36e9cb9e70b1304b4ec8028b93f90b..9acc825c0ad3284c26d39cb0fa699806f79fba07 100644 (file)
@@ -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)
index c7e2d6a241bb4e4fb1fabdd1c3fddb8537c122ab..e00b453f9f0288dd0cd7a62b2aab3d3a3e854cf0 100644 (file)
@@ -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);
index 97ad1fb08e06196c31ad1ec45900e76ecd7eb842..100c9d14b18359fda7f1165cfd7589cf1001caea 100644 (file)
@@ -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. */