isisd: reuse the nexthop lookup functions to avoid code duplication

Nothing special here.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2019-08-06 17:24:54 -03:00
parent 1e4d64aa6f
commit 9e1194c20c

View File

@ -48,18 +48,18 @@
#include "isis_route.h" #include "isis_route.h"
#include "isis_zebra.h" #include "isis_zebra.h"
static struct isis_nexthop *
nexthoplookup(struct list *nexthops, struct in_addr *ip, ifindex_t ifindex);
static struct isis_nexthop6 *
nexthop6lookup(struct list *nexthops6, struct in6_addr *ip6, ifindex_t ifindex);
static struct isis_nexthop *isis_nexthop_create(struct in_addr *ip, static struct isis_nexthop *isis_nexthop_create(struct in_addr *ip,
ifindex_t ifindex) ifindex_t ifindex)
{ {
struct listnode *node;
struct isis_nexthop *nexthop; struct isis_nexthop *nexthop;
for (ALL_LIST_ELEMENTS_RO(isis->nexthops, node, nexthop)) { nexthop = nexthoplookup(isis->nexthops, ip, ifindex);
if (nexthop->ifindex != ifindex) if (nexthop) {
continue;
if (memcmp(&nexthop->ip, ip, sizeof(struct in_addr)) != 0)
continue;
nexthop->lock++; nexthop->lock++;
return nexthop; return nexthop;
} }
@ -85,8 +85,8 @@ static void isis_nexthop_delete(struct isis_nexthop *nexthop)
return; return;
} }
static int nexthoplookup(struct list *nexthops, struct in_addr *ip, static struct isis_nexthop *nexthoplookup(struct list *nexthops,
ifindex_t ifindex) struct in_addr *ip, ifindex_t ifindex)
{ {
struct listnode *node; struct listnode *node;
struct isis_nexthop *nh; struct isis_nexthop *nh;
@ -94,10 +94,10 @@ static int nexthoplookup(struct list *nexthops, struct in_addr *ip,
for (ALL_LIST_ELEMENTS_RO(nexthops, node, nh)) { for (ALL_LIST_ELEMENTS_RO(nexthops, node, nh)) {
if (!(memcmp(ip, &nh->ip, sizeof(struct in_addr))) if (!(memcmp(ip, &nh->ip, sizeof(struct in_addr)))
&& ifindex == nh->ifindex) && ifindex == nh->ifindex)
return 1; return nh;
} }
return 0; return NULL;
} }
static struct isis_nexthop6 *isis_nexthop6_new(struct in6_addr *ip6, static struct isis_nexthop6 *isis_nexthop6_new(struct in6_addr *ip6,
@ -117,15 +117,10 @@ static struct isis_nexthop6 *isis_nexthop6_new(struct in6_addr *ip6,
static struct isis_nexthop6 *isis_nexthop6_create(struct in6_addr *ip6, static struct isis_nexthop6 *isis_nexthop6_create(struct in6_addr *ip6,
ifindex_t ifindex) ifindex_t ifindex)
{ {
struct listnode *node;
struct isis_nexthop6 *nexthop6; struct isis_nexthop6 *nexthop6;
for (ALL_LIST_ELEMENTS_RO(isis->nexthops6, node, nexthop6)) { nexthop6 = nexthop6lookup(isis->nexthops6, ip6, ifindex);
if (nexthop6->ifindex != ifindex) if (nexthop6) {
continue;
if (memcmp(&nexthop6->ip6, ip6, sizeof(struct in6_addr)) != 0)
continue;
nexthop6->lock++; nexthop6->lock++;
return nexthop6; return nexthop6;
} }
@ -147,8 +142,8 @@ static void isis_nexthop6_delete(struct isis_nexthop6 *nexthop6)
return; return;
} }
static int nexthop6lookup(struct list *nexthops6, struct in6_addr *ip6, static struct isis_nexthop6 *
ifindex_t ifindex) nexthop6lookup(struct list *nexthops6, struct in6_addr *ip6, ifindex_t ifindex)
{ {
struct listnode *node; struct listnode *node;
struct isis_nexthop6 *nh6; struct isis_nexthop6 *nh6;
@ -156,10 +151,10 @@ static int nexthop6lookup(struct list *nexthops6, struct in6_addr *ip6,
for (ALL_LIST_ELEMENTS_RO(nexthops6, node, nh6)) { for (ALL_LIST_ELEMENTS_RO(nexthops6, node, nh6)) {
if (!(memcmp(ip6, &nh6->ip6, sizeof(struct in6_addr))) if (!(memcmp(ip6, &nh6->ip6, sizeof(struct in6_addr)))
&& ifindex == nh6->ifindex) && ifindex == nh6->ifindex)
return 1; return nh6;
} }
return 0; return NULL;
} }
static void adjinfo2nexthop(struct list *nexthops, struct isis_adjacency *adj) static void adjinfo2nexthop(struct list *nexthops, struct isis_adjacency *adj)
@ -291,13 +286,13 @@ static int isis_route_info_same(struct isis_route_info *new,
for (ALL_LIST_ELEMENTS_RO(new->nexthops, node, nexthop)) for (ALL_LIST_ELEMENTS_RO(new->nexthops, node, nexthop))
if (nexthoplookup(old->nexthops, &nexthop->ip, if (nexthoplookup(old->nexthops, &nexthop->ip,
nexthop->ifindex) nexthop->ifindex)
== 0) == NULL)
return 0; return 0;
for (ALL_LIST_ELEMENTS_RO(old->nexthops, node, nexthop)) for (ALL_LIST_ELEMENTS_RO(old->nexthops, node, nexthop))
if (nexthoplookup(new->nexthops, &nexthop->ip, if (nexthoplookup(new->nexthops, &nexthop->ip,
nexthop->ifindex) nexthop->ifindex)
== 0) == NULL)
return 0; return 0;
} else if (family == AF_INET6) { } else if (family == AF_INET6) {
for (ALL_LIST_ELEMENTS_RO(new->nexthops6, node, nexthop6)) for (ALL_LIST_ELEMENTS_RO(new->nexthops6, node, nexthop6))