summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.clang-format1
-rw-r--r--babeld/babel_interface.c3
-rw-r--r--babeld/babel_interface.h1
-rw-r--r--bgpd/bgp_network.c3
-rw-r--r--bgpd/bgp_zebra.c28
-rw-r--r--bgpd/bgpd.c6
-rw-r--r--eigrpd/eigrp_network.c4
-rw-r--r--isisd/isis_circuit.c7
-rw-r--r--isisd/isis_sr.c3
-rw-r--r--ldpd/ldp_zebra.c8
-rw-r--r--lib/bfd.c4
-rw-r--r--lib/if.c51
-rw-r--r--lib/if.h11
-rw-r--r--nhrpd/nhrp_interface.c3
-rw-r--r--ospf6d/ospf6_asbr.c7
-rw-r--r--ospf6d/ospf6_interface.c14
-rw-r--r--ospfd/ospf_interface.c2
-rw-r--r--ospfd/ospf_snmp.c5
-rw-r--r--ospfd/ospfd.c3
-rw-r--r--pimd/pim_hello.c2
-rw-r--r--pimd/pim_iface.c25
-rw-r--r--pimd/pim_igmp_mtrace.c3
-rw-r--r--pimd/pim_pim.c15
-rw-r--r--pimd/pim_tlv.c10
-rw-r--r--pimd/pim_zebra.c3
-rw-r--r--ripd/rip_interface.c22
-rw-r--r--ripd/ripd.c18
-rw-r--r--ripngd/ripng_interface.c9
-rw-r--r--ripngd/ripngd.c3
-rwxr-xr-xtools/checkpatch.pl2
-rw-r--r--vrrpd/vrrp.c18
-rw-r--r--vrrpd/vrrp_zebra.c3
-rw-r--r--zebra/connected.c19
-rw-r--r--zebra/interface.c86
-rw-r--r--zebra/irdp_interface.c12
-rw-r--r--zebra/irdp_main.c39
-rw-r--r--zebra/zapi_msg.c2
-rw-r--r--zebra/zebra_evpn.c9
-rw-r--r--zebra/zebra_nb_config.c2
39 files changed, 184 insertions, 282 deletions
diff --git a/.clang-format b/.clang-format
index 5f21a3f32..3446db48d 100644
--- a/.clang-format
+++ b/.clang-format
@@ -77,7 +77,6 @@ FixNamespaceComments: false
ForEachMacros:
# lib: outliers:
- 'FOR_ALL_INTERFACES'
- - 'FOR_ALL_INTERFACES_ADDRESSES'
# libyang outliers:
- 'LY_FOR_KEYS'
- 'LY_LIST_FOR'
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c
index 854c73acc..c4349b509 100644
--- a/babeld/babel_interface.c
+++ b/babeld/babel_interface.c
@@ -739,12 +739,11 @@ int
is_interface_ll_address(struct interface *ifp, const unsigned char *address)
{
struct connected *connected;
- struct listnode *node;
if(!if_up(ifp))
return 0;
- FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) {
+ frr_each (if_connected, ifp->connected, connected) {
if (connected->address->family == AF_INET6
&& memcmp(&connected->address->u.prefix6, address,
IPV6_MAX_BYTELEN)
diff --git a/babeld/babel_interface.h b/babeld/babel_interface.h
index 12fa6e2ba..a585e23af 100644
--- a/babeld/babel_interface.h
+++ b/babeld/babel_interface.h
@@ -82,7 +82,6 @@ static inline int
if_up(struct interface *ifp)
{
return (if_is_operative(ifp) &&
- ifp->connected != NULL &&
CHECK_FLAG(babel_get_if_nfo(ifp)->flags, BABEL_IF_IS_UP));
}
diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c
index d831c6a78..e07b18f8f 100644
--- a/bgpd/bgp_network.c
+++ b/bgpd/bgp_network.c
@@ -693,7 +693,6 @@ int bgp_update_address(struct interface *ifp, const union sockunion *dst,
{
struct prefix *p, *sel, d;
struct connected *connected;
- struct listnode *node;
int common;
if (!sockunion2hostprefix(dst, &d))
@@ -702,7 +701,7 @@ int bgp_update_address(struct interface *ifp, const union sockunion *dst,
sel = NULL;
common = -1;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
p = connected->address;
if (p->family != d.family)
continue;
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 57d419fab..0aeb59cd9 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -146,7 +146,6 @@ static void bgp_start_interface_nbrs(struct bgp *bgp, struct interface *ifp)
static void bgp_nbr_connected_add(struct bgp *bgp, struct nbr_connected *ifc)
{
- struct listnode *node;
struct connected *connected;
struct interface *ifp;
struct prefix *p;
@@ -155,7 +154,7 @@ static void bgp_nbr_connected_add(struct bgp *bgp, struct nbr_connected *ifc)
* valid local address on the interface.
*/
ifp = ifc->ifp;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
p = connected->address;
if (p->family == AF_INET6
&& IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6))
@@ -227,7 +226,7 @@ static int bgp_ifp_up(struct interface *ifp)
if (!bgp)
return 0;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c))
+ frr_each (if_connected, ifp->connected, c)
bgp_connected_add(bgp, c);
for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc))
@@ -258,7 +257,7 @@ static int bgp_ifp_down(struct interface *ifp)
if (!bgp)
return 0;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c))
+ frr_each (if_connected, ifp->connected, c)
bgp_connected_delete(bgp, c);
for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc))
@@ -559,7 +558,6 @@ static int zebra_read_route(ZAPI_CALLBACK_ARGS)
struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id)
{
struct vrf *vrf;
- struct listnode *cnode;
struct interface *ifp;
struct connected *connected;
struct prefix_ipv4 p;
@@ -574,7 +572,7 @@ struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id)
p.prefixlen = IPV4_MAX_BITLEN;
FOR_ALL_INTERFACES (vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
cp = connected->address;
if (cp->family == AF_INET)
@@ -588,7 +586,6 @@ struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id)
struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id)
{
struct vrf *vrf;
- struct listnode *cnode;
struct interface *ifp;
struct connected *connected;
struct prefix *cp;
@@ -598,7 +595,7 @@ struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id)
return NULL;
FOR_ALL_INTERFACES (vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
cp = connected->address;
if (cp->family == AF_INET)
@@ -613,7 +610,6 @@ struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex,
vrf_id_t vrf_id)
{
struct vrf *vrf;
- struct listnode *cnode;
struct interface *ifp;
struct connected *connected;
struct prefix_ipv6 p;
@@ -628,7 +624,7 @@ struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex,
p.prefixlen = IPV6_MAX_BITLEN;
FOR_ALL_INTERFACES (vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
cp = connected->address;
if (cp->family == AF_INET6)
@@ -649,7 +645,6 @@ struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr,
ifindex_t ifindex, vrf_id_t vrf_id)
{
struct vrf *vrf;
- struct listnode *cnode;
struct interface *ifp;
struct connected *connected;
struct prefix *cp;
@@ -659,7 +654,7 @@ struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr,
return NULL;
FOR_ALL_INTERFACES (vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
cp = connected->address;
if (cp->family == AF_INET6)
@@ -678,11 +673,10 @@ struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr,
static int if_get_ipv6_global(struct interface *ifp, struct in6_addr *addr)
{
- struct listnode *cnode;
struct connected *connected;
struct prefix *cp;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
cp = connected->address;
if (cp->family == AF_INET6)
@@ -696,11 +690,10 @@ static int if_get_ipv6_global(struct interface *ifp, struct in6_addr *addr)
static bool if_get_ipv6_local(struct interface *ifp, struct in6_addr *addr)
{
- struct listnode *cnode;
struct connected *connected;
struct prefix *cp;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
cp = connected->address;
if (cp->family == AF_INET6)
@@ -714,11 +707,10 @@ static bool if_get_ipv6_local(struct interface *ifp, struct in6_addr *addr)
static int if_get_ipv4_address(struct interface *ifp, struct in_addr *addr)
{
- struct listnode *cnode;
struct connected *connected;
struct prefix *cp;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
cp = connected->address;
if ((cp->family == AF_INET)
&& !ipv4_martian(&(cp->u.prefix4))) {
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 6ca0b0645..d89a755f3 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -1610,12 +1610,11 @@ static int bgp_peer_conf_if_to_su_update_v4(struct peer_connection *connection,
struct connected *ifc;
struct prefix p;
uint32_t addr;
- struct listnode *node;
/* If our IPv4 address on the interface is /30 or /31, we can derive the
* IPv4 address of the other end.
*/
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
if (ifc->address && (ifc->address->family == AF_INET)) {
prefix_copy(&p, CONNECTED_PREFIX(ifc));
if (p.prefixlen == 30) {
@@ -8278,10 +8277,9 @@ static void bgp_if_finish(struct bgp *bgp)
return;
FOR_ALL_INTERFACES (vrf, ifp) {
- struct listnode *c_node, *c_nnode;
struct connected *c;
- for (ALL_LIST_ELEMENTS(ifp->connected, c_node, c_nnode, c))
+ frr_each_safe (if_connected, ifp->connected, c)
bgp_connected_delete(bgp, c);
}
}
diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c
index ef567fe4e..5ca5a18a9 100644
--- a/eigrpd/eigrp_network.c
+++ b/eigrpd/eigrp_network.c
@@ -233,13 +233,11 @@ static void eigrp_network_run_interface(struct eigrp *eigrp, struct prefix *p,
struct interface *ifp)
{
struct eigrp_interface *ei;
- struct listnode *cnode;
struct connected *co;
/* if interface prefix is match specified prefix,
then create socket and join multicast group. */
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, co)) {
-
+ frr_each (if_connected, ifp->connected, co) {
if (CHECK_FLAG(co->flags, ZEBRA_IFA_SECONDARY))
continue;
diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c
index 3fca6b23d..7819b20e8 100644
--- a/isisd/isis_circuit.c
+++ b/isisd/isis_circuit.c
@@ -489,7 +489,6 @@ static uint8_t isis_circuit_id_gen(struct isis *isis, struct interface *ifp)
void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
{
- struct listnode *node, *nnode;
struct connected *conn;
if (if_is_broadcast(ifp)) {
@@ -509,20 +508,18 @@ void isis_circuit_if_add(struct isis_circuit *circuit, struct interface *ifp)
circuit->circ_type = CIRCUIT_T_UNKNOWN;
}
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
+ frr_each (if_connected, ifp->connected, conn)
isis_circuit_add_addr(circuit, conn);
-
}
void isis_circuit_if_del(struct isis_circuit *circuit, struct interface *ifp)
{
- struct listnode *node, *nnode;
struct connected *conn;
assert(circuit->interface == ifp);
/* destroy addresses */
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, conn))
+ frr_each_safe (if_connected, ifp->connected, conn)
isis_circuit_del_addr(circuit, conn);
circuit->circ_type = CIRCUIT_T_UNKNOWN;
diff --git a/isisd/isis_sr.c b/isisd/isis_sr.c
index 76cde6d28..1d69dbbbf 100644
--- a/isisd/isis_sr.c
+++ b/isisd/isis_sr.c
@@ -936,7 +936,6 @@ int sr_if_addr_update(struct interface *ifp)
struct isis_circuit *circuit;
struct isis_area *area;
struct connected *connected;
- struct listnode *node;
bool need_lsp_regenerate = false;
/* Get corresponding circuit */
@@ -948,7 +947,7 @@ int sr_if_addr_update(struct interface *ifp)
if (!area)
return 0;
- FOR_ALL_INTERFACES_ADDRESSES (ifp, connected, node) {
+ frr_each (if_connected, ifp->connected, connected) {
for (int i = 0; i < SR_ALGORITHM_COUNT; i++) {
pcfgs[i] = isis_sr_cfg_prefix_find(
area, connected->address, i);
diff --git a/ldpd/ldp_zebra.c b/ldpd/ldp_zebra.c
index a9814f18f..df682a134 100644
--- a/ldpd/ldp_zebra.c
+++ b/ldpd/ldp_zebra.c
@@ -330,7 +330,6 @@ void
kif_redistribute(const char *ifname)
{
struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
- struct listnode *cnode;
struct interface *ifp;
struct connected *ifc;
struct kif kif;
@@ -343,7 +342,7 @@ kif_redistribute(const char *ifname)
ifp2kif(ifp, &kif);
main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif));
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
ifc2kaddr(ifp, ifc, &ka);
main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka, sizeof(ka));
}
@@ -400,7 +399,6 @@ ldp_ifp_destroy(struct interface *ifp)
static int
ldp_interface_status_change(struct interface *ifp)
{
- struct listnode *node;
struct connected *ifc;
struct kif kif;
struct kaddr ka;
@@ -411,12 +409,12 @@ ldp_interface_status_change(struct interface *ifp)
main_imsg_compose_both(IMSG_IFSTATUS, &kif, sizeof(kif));
if (if_is_operative(ifp)) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
ifc2kaddr(ifp, ifc, &ka);
main_imsg_compose_ldpe(IMSG_NEWADDR, 0, &ka, sizeof(ka));
}
} else {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
ifc2kaddr(ifp, ifc, &ka);
main_imsg_compose_ldpe(IMSG_DELADDR, 0, &ka, sizeof(ka));
}
diff --git a/lib/bfd.c b/lib/bfd.c
index 8c3246ff9..2222bb954 100644
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -1282,7 +1282,6 @@ static bool bfd_source_cache_update(struct bfd_source_cache *source,
const struct zapi_nexthop *nh = &route->nexthops[nh_index];
const struct interface *interface;
const struct connected *connected;
- const struct listnode *node;
interface = if_lookup_by_index(nh->ifindex, nh->vrf_id);
if (interface == NULL) {
@@ -1291,8 +1290,7 @@ static bool bfd_source_cache_update(struct bfd_source_cache *source,
continue;
}
- for (ALL_LIST_ELEMENTS_RO(interface->connected, node,
- connected)) {
+ frr_each (if_connected_const, interface->connected, connected) {
if (source->address.family !=
connected->address->family)
continue;
diff --git a/lib/if.c b/lib/if.c
index f583638d7..a42064005 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -164,8 +164,7 @@ static struct interface *if_new(struct vrf *vrf)
ifp->vrf = vrf;
- ifp->connected = list_new();
- ifp->connected->del = ifp_connected_free;
+ if_connected_init(ifp->connected);
ifp->nbr_connected = list_new();
ifp->nbr_connected->del = (void (*)(void *))nbr_connected_free;
@@ -243,11 +242,14 @@ void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id)
/* Delete interface structure. */
void if_delete_retain(struct interface *ifp)
{
+ struct connected *ifc;
+
hook_call(if_del, ifp);
QOBJ_UNREG(ifp);
/* Free connected address list */
- list_delete_all_node(ifp->connected);
+ while ((ifc = if_connected_pop(ifp->connected)))
+ ifp_connected_free(ifc);
/* Free connected nbr address list */
list_delete_all_node(ifp->nbr_connected);
@@ -265,7 +267,7 @@ void if_delete(struct interface **ifp)
if_delete_retain(ptr);
- list_delete(&ptr->connected);
+ if_connected_fini(ptr->connected);
list_delete(&ptr->nbr_connected);
if_link_params_free(ptr);
@@ -427,7 +429,6 @@ struct interface *if_lookup_address_local(const void *src, int family,
vrf_id_t vrf_id)
{
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
- struct listnode *cnode;
struct interface *ifp, *best_down = NULL;
struct prefix *p;
struct connected *c;
@@ -436,7 +437,7 @@ struct interface *if_lookup_address_local(const void *src, int family,
return NULL;
FOR_ALL_INTERFACES (vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
p = c->address;
if (!p || p->family != family)
@@ -468,7 +469,6 @@ struct connected *if_lookup_address(const void *matchaddr, int family,
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
struct prefix addr;
int bestlen = 0;
- struct listnode *cnode;
struct interface *ifp;
struct connected *c;
struct connected *match;
@@ -487,7 +487,7 @@ struct connected *if_lookup_address(const void *matchaddr, int family,
match = NULL;
FOR_ALL_INTERFACES (vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (c->address && (c->address->family == AF_INET)
&& prefix_match(CONNECTED_PREFIX(c), &addr)
&& (c->address->prefixlen > bestlen)) {
@@ -503,12 +503,11 @@ struct connected *if_lookup_address(const void *matchaddr, int family,
struct interface *if_lookup_prefix(const struct prefix *prefix, vrf_id_t vrf_id)
{
struct vrf *vrf = vrf_lookup_by_id(vrf_id);
- struct listnode *cnode;
struct interface *ifp;
struct connected *c;
FOR_ALL_INTERFACES (vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (prefix_cmp(c->address, prefix) == 0) {
return ifp;
}
@@ -775,10 +774,9 @@ const char *if_flag_dump(unsigned long flag)
/* For debugging */
static void if_dump(const struct interface *ifp)
{
- struct listnode *node;
- struct connected *c __attribute__((unused));
+ const struct connected *c;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, c))
+ frr_each (if_connected_const, ifp->connected, c)
zlog_info(
"Interface %s vrf %s(%u) index %d metric %d mtu %d mtu6 %d %s",
ifp->name, ifp->vrf->name, ifp->vrf->vrf_id,
@@ -905,11 +903,10 @@ static int connected_same_prefix(const struct prefix *p1,
/* count the number of connected addresses that are in the given family */
unsigned int connected_count_by_family(struct interface *ifp, int family)
{
- struct listnode *cnode;
struct connected *connected;
unsigned int cnt = 0;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected))
+ frr_each (if_connected, ifp->connected, connected)
if (connected->address->family == family)
cnt++;
@@ -919,14 +916,9 @@ unsigned int connected_count_by_family(struct interface *ifp, int family)
struct connected *connected_lookup_prefix_exact(struct interface *ifp,
const struct prefix *p)
{
- struct listnode *node;
- struct listnode *next;
struct connected *ifc;
- for (node = listhead(ifp->connected); node; node = next) {
- ifc = listgetdata(node);
- next = node->next;
-
+ frr_each (if_connected, ifp->connected, ifc) {
if (connected_same_prefix(ifc->address, p))
return ifc;
}
@@ -936,17 +928,12 @@ struct connected *connected_lookup_prefix_exact(struct interface *ifp,
struct connected *connected_delete_by_prefix(struct interface *ifp,
struct prefix *p)
{
- struct listnode *node;
- struct listnode *next;
struct connected *ifc;
/* In case of same prefix come, replace it with new one. */
- for (node = listhead(ifp->connected); node; node = next) {
- ifc = listgetdata(node);
- next = node->next;
-
+ frr_each_safe (if_connected, ifp->connected, ifc) {
if (connected_same_prefix(ifc->address, p)) {
- listnode_delete(ifp->connected, ifc);
+ if_connected_del(ifp->connected, ifc);
return ifc;
}
}
@@ -958,13 +945,12 @@ struct connected *connected_delete_by_prefix(struct interface *ifp,
struct connected *connected_lookup_prefix(struct interface *ifp,
const struct prefix *addr)
{
- struct listnode *cnode;
struct connected *c;
struct connected *match;
match = NULL;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (c->address && (c->address->family == addr->family)
&& prefix_match(CONNECTED_PREFIX(c), addr)
&& (!match
@@ -995,16 +981,15 @@ struct connected *connected_add_by_prefix(struct interface *ifp,
}
/* Add connected address to the interface. */
- listnode_add(ifp->connected, ifc);
+ if_connected_add_tail(ifp->connected, ifc);
return ifc;
}
struct connected *connected_get_linklocal(struct interface *ifp)
{
- struct listnode *n;
struct connected *c = NULL;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, n, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (c->address->family == AF_INET6
&& IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6))
break;
diff --git a/lib/if.h b/lib/if.h
index e93205758..dd67c32a6 100644
--- a/lib/if.h
+++ b/lib/if.h
@@ -204,6 +204,8 @@ struct if_link_params {
#define INTERFACE_LINK_PARAMS_SIZE sizeof(struct if_link_params)
#define HAS_LINK_PARAMS(ifp) ((ifp)->link_params != NULL)
+PREDECL_DLIST(if_connected);
+
/* Interface structure */
struct interface {
RB_ENTRY(interface) name_entry, index_entry;
@@ -278,7 +280,7 @@ struct interface {
void *distribute_out;
/* Connected address list. */
- struct list *connected;
+ struct if_connected_head connected[1];
/* Neighbor connected address list. */
struct list *nbr_connected;
@@ -373,9 +375,6 @@ DECLARE_QOBJ_TYPE(interface);
if (vrf) \
RB_FOREACH (ifp, if_name_head, &vrf->ifaces_by_name)
-#define FOR_ALL_INTERFACES_ADDRESSES(ifp, connected, node) \
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected))
-
/* called from the library code whenever interfaces are created/deleted
* note: interfaces may not be fully realized at that point; also they
* may not exist in the system (ifindex = IFINDEX_INTERNAL)
@@ -410,6 +409,8 @@ DECLARE_KOOH(if_down, (struct interface *ifp), (ifp));
/* Connected address structure. */
struct connected {
+ struct if_connected_item item;
+
/* Attached interface. */
struct interface *ifp;
@@ -459,6 +460,8 @@ struct connected {
uint32_t metric;
};
+DECLARE_DLIST(if_connected, struct connected, item);
+
/* Nbr Connected address structure. */
struct nbr_connected {
/* Attached interface. */
diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c
index 7c84fde36..b82743f00 100644
--- a/nhrpd/nhrp_interface.c
+++ b/nhrpd/nhrp_interface.c
@@ -259,13 +259,12 @@ static void nhrp_interface_update_address(struct interface *ifp, afi_t afi,
struct nhrp_afi_data *if_ad = &nifp->afi[afi];
struct nhrp_cache *nc;
struct connected *c, *best;
- struct listnode *cnode;
union sockunion addr;
char buf[PREFIX_STRLEN];
/* Select new best match preferring primary address */
best = NULL;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (PREFIX_FAMILY(c->address) != family)
continue;
if (best == NULL) {
diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c
index 99c3e1626..d1c2b8bfc 100644
--- a/ospf6d/ospf6_asbr.c
+++ b/ospf6d/ospf6_asbr.c
@@ -481,7 +481,7 @@ void ospf6_asbr_update_route_ecmp_path(struct ospf6_route *old,
static int ospf6_ase_forward_address_check(struct ospf6 *ospf6,
struct in6_addr *fwd_addr)
{
- struct listnode *anode, *node, *cnode;
+ struct listnode *anode, *node;
struct ospf6_interface *oi;
struct ospf6_area *oa;
struct interface *ifp;
@@ -494,7 +494,7 @@ static int ospf6_ase_forward_address_check(struct ospf6 *ospf6,
continue;
ifp = oi->interface;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (IPV6_ADDR_SAME(&c->address->u.prefix6,
fwd_addr))
return 0;
@@ -1407,12 +1407,11 @@ static void ospf6_external_lsa_fwd_addr_set(struct ospf6 *ospf6,
FOR_ALL_INTERFACES (vrf, ifp) {
struct ospf6_interface *oi = ifp->info;
struct connected *connected;
- struct listnode *node;
if (!oi || CHECK_FLAG(oi->flag, OSPF6_INTERFACE_DISABLE))
continue;
- FOR_ALL_INTERFACES_ADDRESSES (ifp, connected, node) {
+ frr_each (if_connected, ifp->connected, connected) {
if (connected->address->family != AF_INET6)
continue;
if (IN6_IS_ADDR_LINKLOCAL(&connected->address->u.prefix6))
diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c
index 4a88b32df..652d502c8 100644
--- a/ospf6d/ospf6_interface.c
+++ b/ospf6d/ospf6_interface.c
@@ -343,12 +343,11 @@ void ospf6_interface_disable(struct ospf6_interface *oi)
static struct in6_addr *
ospf6_interface_get_linklocal_address(struct interface *ifp)
{
- struct listnode *n;
struct connected *c;
struct in6_addr *l = (struct in6_addr *)NULL;
/* for each connected address */
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, n, c)) {
+ frr_each (if_connected, ifp->connected, c) {
/* if family not AF_INET6, ignore */
if (c->address->family != AF_INET6)
continue;
@@ -405,7 +404,6 @@ void ospf6_interface_connected_route_update(struct interface *ifp)
{
struct ospf6_interface *oi;
struct connected *c;
- struct listnode *node, *nnode;
struct in6_addr nh_addr;
oi = (struct ospf6_interface *)ifp->info;
@@ -425,7 +423,7 @@ void ospf6_interface_connected_route_update(struct interface *ifp)
/* update "route to advertise" interface route table */
ospf6_route_remove_all(oi->route_connected);
- for (ALL_LIST_ELEMENTS(oi->interface->connected, node, nnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (c->address->family != AF_INET6)
continue;
@@ -1015,7 +1013,6 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
struct ospf6_interface *oi;
struct connected *c;
struct prefix *p;
- struct listnode *i;
char strbuf[PREFIX2STR_BUFFER], drouter[32], bdrouter[32];
uint8_t default_iftype;
struct timeval res, now;
@@ -1062,7 +1059,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
if (use_json) {
json_arr = json_object_new_array();
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, i, c)) {
+ frr_each (if_connected, ifp->connected, c) {
json_addr = json_object_new_object();
p = c->address;
prefix2str(p, strbuf, sizeof(strbuf));
@@ -1094,7 +1091,7 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
} else {
vty_out(vty, " Internet Address:\n");
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, i, c)) {
+ frr_each (if_connected, ifp->connected, c) {
p = c->address;
prefix2str(p, strbuf, sizeof(strbuf));
switch (p->family) {
@@ -1331,11 +1328,10 @@ static int ospf6_interface_show(struct vty *vty, struct interface *ifp,
/* Find the global address to be used as a forwarding address in NSSA LSA.*/
struct in6_addr *ospf6_interface_get_global_address(struct interface *ifp)
{
- struct listnode *n;
struct connected *c;
/* for each connected address */
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, n, c)) {
+ frr_each (if_connected, ifp->connected, c) {
/* if family not AF_INET6, ignore */
if (c->address->family != AF_INET6)
continue;
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 3ee1db755..12337abcb 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -962,7 +962,7 @@ struct ospf_interface *ospf_vl_new(struct ospf *ospf,
UNSET_FLAG(vi->status, ZEBRA_INTERFACE_LINKDETECTION);
co = connected_new();
co->ifp = vi;
- listnode_add(vi->connected, co);
+ if_connected_add_tail(vi->connected, co);
p = prefix_ipv4_new();
p->family = AF_INET;
diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c
index c9aaa9f97..fc0c143c2 100644
--- a/ospfd/ospf_snmp.c
+++ b/ospfd/ospf_snmp.c
@@ -1348,7 +1348,7 @@ static int ospf_snmp_if_update(struct interface *ifp)
ifindex = 0;
/* Lookup first IPv4 address entry. */
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
p = CONNECTED_ID(ifc);
if (p->family == AF_INET) {
@@ -1396,11 +1396,10 @@ static int ospf_snmp_if_update(struct interface *ifp)
static int ospf_snmp_is_if_have_addr(struct interface *ifp)
{
- struct listnode *nn;
struct connected *ifc;
/* Is this interface having any connected IPv4 address ? */
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
if (CONNECTED_PREFIX(ifc)->family == AF_INET)
return 1;
}
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index c46d2e278..f44429830 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -1444,7 +1444,6 @@ static void ospf_network_run_interface(struct ospf *ospf, struct interface *ifp,
struct prefix *p,
struct ospf_area *given_area)
{
- struct listnode *cnode;
struct connected *co;
if (memcmp(ifp->name, "VLINK", 5) == 0)
@@ -1456,7 +1455,7 @@ static void ospf_network_run_interface(struct ospf *ospf, struct interface *ifp,
/* if interface prefix is match specified prefix,
then create socket and join multicast group. */
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, co))
+ frr_each (if_connected, ifp->connected, co)
ospf_network_run_subnet(ospf, co, p, given_area);
}
diff --git a/pimd/pim_hello.c b/pimd/pim_hello.c
index 978607d14..a0661ef36 100644
--- a/pimd/pim_hello.c
+++ b/pimd/pim_hello.c
@@ -440,7 +440,7 @@ int pim_hello_build_tlv(struct interface *ifp, uint8_t *tlv_buf,
}
/* Secondary Address List */
- if (ifp->connected->count) {
+ if (if_connected_count(ifp->connected)) {
curr = pim_tlv_append_addrlist_ucast(curr, pastend, ifp,
PIM_AF);
if (!curr) {
diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c
index 7151fc6b3..5d7132c09 100644
--- a/pimd/pim_iface.c
+++ b/pimd/pim_iface.c
@@ -379,7 +379,7 @@ static int pim_sec_addr_update(struct interface *ifp)
sec_addr->flags |= PIM_SEC_ADDRF_STALE;
}
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
pim_addr addr = pim_addr_from_prefix(ifc->address);
if (pim_addr_is_any(addr))
@@ -723,13 +723,12 @@ void pim_if_addr_del(struct connected *ifc, int force_prim_as_any)
if (pim_ifp &&
(!IPV6_ADDR_CMP(&ifc->address->u.prefix6, &pim_ifp->ll_lowest) ||
!IPV6_ADDR_CMP(&ifc->address->u.prefix6, &pim_ifp->ll_highest))) {
- struct listnode *cnode;
struct connected *cc;
memset(&pim_ifp->ll_lowest, 0xff, sizeof(pim_ifp->ll_lowest));
memset(&pim_ifp->ll_highest, 0, sizeof(pim_ifp->ll_highest));
- for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected, cnode, cc)) {
+ frr_each (if_connected, ifc->ifp->connected, cc) {
if (!IN6_IS_ADDR_LINKLOCAL(&cc->address->u.prefix6) &&
!IN6_IS_ADDR_LOOPBACK(&cc->address->u.prefix6))
continue;
@@ -765,8 +764,6 @@ void pim_if_addr_del(struct connected *ifc, int force_prim_as_any)
void pim_if_addr_add_all(struct interface *ifp)
{
struct connected *ifc;
- struct listnode *node;
- struct listnode *nextnode;
int v4_addrs = 0;
int v6_addrs = 0;
struct pim_interface *pim_ifp = ifp->info;
@@ -777,7 +774,7 @@ void pim_if_addr_add_all(struct interface *ifp)
if (!pim_ifp)
return;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
struct prefix *p = ifc->address;
if (p->family != AF_INET)
@@ -813,8 +810,6 @@ void pim_if_addr_add_all(struct interface *ifp)
void pim_if_addr_del_all(struct interface *ifp)
{
struct connected *ifc;
- struct listnode *node;
- struct listnode *nextnode;
struct pim_instance *pim;
pim = ifp->vrf->info;
@@ -825,7 +820,7 @@ void pim_if_addr_del_all(struct interface *ifp)
if (!ifp->info)
return;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) {
+ frr_each_safe (if_connected, ifp->connected, ifc) {
struct prefix *p = ifc->address;
if (p->family != PIM_AF)
@@ -841,14 +836,12 @@ void pim_if_addr_del_all(struct interface *ifp)
void pim_if_addr_del_all_igmp(struct interface *ifp)
{
struct connected *ifc;
- struct listnode *node;
- struct listnode *nextnode;
/* PIM/IGMP enabled ? */
if (!ifp->info)
return;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nextnode, ifc)) {
+ frr_each_safe (if_connected, ifp->connected, ifc) {
struct prefix *p = ifc->address;
if (p->family != AF_INET)
@@ -861,7 +854,6 @@ void pim_if_addr_del_all_igmp(struct interface *ifp)
pim_addr pim_find_primary_addr(struct interface *ifp)
{
struct connected *ifc;
- struct listnode *node;
struct pim_interface *pim_ifp = ifp->info;
if (pim_ifp && !pim_addr_is_any(pim_ifp->update_source))
@@ -873,7 +865,7 @@ pim_addr pim_find_primary_addr(struct interface *ifp)
pim_addr best_addr = PIMADDR_ANY;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
pim_addr addr;
if (ifc->address->family != AF_INET6)
@@ -892,7 +884,7 @@ pim_addr pim_find_primary_addr(struct interface *ifp)
int v6_addrs = 0;
struct connected *promote_ifc = NULL;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
switch (ifc->address->family) {
case AF_INET:
v4_addrs++;
@@ -1523,7 +1515,6 @@ void pim_if_create_pimreg(struct pim_instance *pim)
struct prefix *pim_if_connected_to_source(struct interface *ifp, pim_addr src)
{
- struct listnode *cnode;
struct connected *c;
struct prefix p;
@@ -1532,7 +1523,7 @@ struct prefix *pim_if_connected_to_source(struct interface *ifp, pim_addr src)
pim_addr_to_prefix(&p, src);
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (c->address->family != PIM_AF)
continue;
if (prefix_match(c->address, &p))
diff --git a/pimd/pim_igmp_mtrace.c b/pimd/pim_igmp_mtrace.c
index 4d3f6022a..309da138d 100644
--- a/pimd/pim_igmp_mtrace.c
+++ b/pimd/pim_igmp_mtrace.c
@@ -21,7 +21,6 @@
static struct in_addr mtrace_primary_address(struct interface *ifp)
{
struct connected *ifc;
- struct listnode *node;
struct in_addr any;
struct pim_interface *pim_ifp;
@@ -32,7 +31,7 @@ static struct in_addr mtrace_primary_address(struct interface *ifp)
any.s_addr = INADDR_ANY;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
struct prefix *p = ifc->address;
if (p->family != AF_INET)
diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c
index a4c9178bb..1bc265b13 100644
--- a/pimd/pim_pim.c
+++ b/pimd/pim_pim.c
@@ -743,14 +743,13 @@ static int hello_send(struct interface *ifp, uint16_t holdtime)
pim_ifp = ifp->info;
if (PIM_DEBUG_PIM_HELLO)
- zlog_debug(
- "%s: to %pPA on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%d",
- __func__, &qpim_all_pim_routers_addr, ifp->name,
- holdtime, pim_ifp->pim_propagation_delay_msec,
- pim_ifp->pim_override_interval_msec,
- pim_ifp->pim_can_disable_join_suppression,
- pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id,
- listcount(ifp->connected));
+ zlog_debug("%s: to %pPA on %s: holdt=%u prop_d=%u overr_i=%u dis_join_supp=%d dr_prio=%u gen_id=%08x addrs=%zu",
+ __func__, &qpim_all_pim_routers_addr, ifp->name,
+ holdtime, pim_ifp->pim_propagation_delay_msec,
+ pim_ifp->pim_override_interval_msec,
+ pim_ifp->pim_can_disable_join_suppression,
+ pim_ifp->pim_dr_priority, pim_ifp->pim_generation_id,
+ if_connected_count(ifp->connected));
pim_tlv_size = pim_hello_build_tlv(
ifp, pim_msg + PIM_PIM_MIN_LEN,
diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c
index 80d60b862..c463fa227 100644
--- a/pimd/pim_tlv.c
+++ b/pimd/pim_tlv.c
@@ -217,18 +217,17 @@ int pim_encode_addr_group(uint8_t *buf, afi_t afi, int bidir, int scope,
uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend,
struct interface *ifp, int family)
{
- struct listnode *node;
uint16_t option_len = 0;
uint8_t *curr;
size_t uel;
- struct list *ifconnected = ifp->connected;
+ struct connected *ifc;
struct pim_interface *pim_ifp = ifp->info;
pim_addr addr;
- node = listhead(ifconnected);
+ ifc = if_connected_first(ifp->connected);
/* Empty address list ? */
- if (!node) {
+ if (!ifc) {
return buf;
}
@@ -239,8 +238,7 @@ uint8_t *pim_tlv_append_addrlist_ucast(uint8_t *buf, const uint8_t *buf_pastend,
/* Scan secondary address list */
curr = buf + 4; /* skip T and L */
- for (; node; node = listnextnode(node)) {
- struct connected *ifc = listgetdata(node);
+ for (; ifc; ifc = if_connected_next(ifp->connected, ifc)) {
struct prefix *p = ifc->address;
int l_encode;
diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c
index 73c9df8f8..1da308426 100644
--- a/pimd/pim_zebra.c
+++ b/pimd/pim_zebra.c
@@ -55,12 +55,11 @@ static int pim_router_id_update_zebra(ZAPI_CALLBACK_ARGS)
static void dump_if_address(struct interface *ifp)
{
struct connected *ifc;
- struct listnode *node;
zlog_debug("%s %s: interface %s addresses:", __FILE__, __func__,
ifp->name);
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
struct prefix *p = ifc->address;
if (p->family != AF_INET)
diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c
index 93494549c..65afce8cb 100644
--- a/ripd/rip_interface.c
+++ b/ripd/rip_interface.c
@@ -128,14 +128,12 @@ static void rip_request_interface_send(struct interface *ifp, uint8_t version)
/* RIPv1 and non multicast interface. */
if (if_is_pointopoint(ifp) || if_is_broadcast(ifp)) {
- struct listnode *cnode, *cnnode;
struct connected *connected;
if (IS_RIP_DEBUG_EVENT)
zlog_debug("broadcast request to %s", ifp->name);
- for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode,
- connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (connected->address->family != AF_INET)
continue;
@@ -197,14 +195,13 @@ static void rip_request_interface(struct interface *ifp)
/* Multicast packet receive socket. */
static int rip_multicast_join(struct interface *ifp, int sock)
{
- struct listnode *cnode;
struct connected *ifc;
if (if_is_operative(ifp) && if_is_multicast(ifp)) {
if (IS_RIP_DEBUG_EVENT)
zlog_debug("multicast join at %s", ifp->name);
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
struct prefix_ipv4 *p;
struct in_addr group;
@@ -228,14 +225,13 @@ static int rip_multicast_join(struct interface *ifp, int sock)
/* Leave from multicast group. */
static void rip_multicast_leave(struct interface *ifp, int sock)
{
- struct listnode *cnode;
struct connected *connected;
if (if_is_up(ifp) && if_is_multicast(ifp)) {
if (IS_RIP_DEBUG_EVENT)
zlog_debug("multicast leave from %s", ifp->name);
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix_ipv4 *p;
struct in_addr group;
@@ -256,11 +252,10 @@ static void rip_multicast_leave(struct interface *ifp, int sock)
/* Is there and address on interface that I could use ? */
static int rip_if_ipv4_address_check(struct interface *ifp)
{
- struct listnode *nn;
struct connected *connected;
int count = 0;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix *p;
p = connected->address;
@@ -279,10 +274,9 @@ int if_check_address(struct rip *rip, struct in_addr addr)
struct interface *ifp;
FOR_ALL_INTERFACES (rip->vrf, ifp) {
- struct listnode *cnode;
struct connected *connected;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix_ipv4 *p;
p = (struct prefix_ipv4 *)connected->address;
@@ -596,14 +590,13 @@ static int rip_enable_network_lookup_if(struct interface *ifp)
{
struct rip_interface *ri = ifp->info;
struct rip *rip = ri->rip;
- struct listnode *node, *nnode;
struct connected *connected;
struct prefix_ipv4 address;
if (!rip)
return -1;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix *p;
struct route_node *n;
@@ -780,14 +773,13 @@ static void rip_connect_set(struct interface *ifp, int set)
{
struct rip_interface *ri = ifp->info;
struct rip *rip = ri->rip;
- struct listnode *node, *nnode;
struct connected *connected;
struct prefix_ipv4 address;
struct nexthop nh;
memset(&nh, 0, sizeof(nh));
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix *p;
p = connected->address;
diff --git a/ripd/ripd.c b/ripd/ripd.c
index f197e389b..a94dd96da 100644
--- a/ripd/ripd.c
+++ b/ripd/ripd.c
@@ -404,7 +404,6 @@ static int rip_filter(int rip_distribute, struct prefix_ipv4 *p,
static int rip_nexthop_check(struct rip *rip, struct in_addr *addr)
{
struct interface *ifp;
- struct listnode *cnode;
struct connected *ifc;
struct prefix *p;
@@ -412,7 +411,7 @@ static int rip_nexthop_check(struct rip *rip, struct in_addr *addr)
invalid nexthop. */
FOR_ALL_INTERFACES (rip->vrf, ifp) {
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
p = ifc->address;
if (p->family == AF_INET
@@ -2213,8 +2212,8 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to,
}
if (!suppress && rinfo->type == ZEBRA_ROUTE_CONNECT) {
- for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected,
- listnode, tmp_ifc))
+ frr_each (if_connected, ifc->ifp->connected,
+ tmp_ifc)
if (prefix_match((struct prefix *)p,
tmp_ifc->address)) {
suppress = 1;
@@ -2323,8 +2322,8 @@ void rip_output_process(struct connected *ifc, struct sockaddr_in *to,
if (rinfo->metric_out != RIP_METRIC_INFINITY &&
rinfo->type == ZEBRA_ROUTE_CONNECT) {
- for (ALL_LIST_ELEMENTS_RO(ifc->ifp->connected,
- listnode, tmp_ifc))
+ frr_each (if_connected, ifc->ifp->connected,
+ tmp_ifc)
if (prefix_match((struct prefix *)p,
tmp_ifc->address)) {
rinfo->metric_out =
@@ -2437,7 +2436,6 @@ static void rip_update_interface(struct connected *ifc, uint8_t version,
/* Update send to all interface and neighbor. */
static void rip_update_process(struct rip *rip, int route_type)
{
- struct listnode *ifnode, *ifnnode;
struct connected *connected;
struct interface *ifp;
struct rip_interface *ri;
@@ -2476,8 +2474,7 @@ static void rip_update_process(struct rip *rip, int route_type)
ifp->ifindex);
/* send update on each connected network */
- for (ALL_LIST_ELEMENTS(ifp->connected, ifnode, ifnnode,
- connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (connected->address->family == AF_INET) {
if (vsend & RIPv1)
rip_update_interface(connected, RIPv1,
@@ -2768,7 +2765,6 @@ int rip_request_send(struct sockaddr_in *to, struct interface *ifp,
{
struct rte *rte;
struct rip_packet rip_packet;
- struct listnode *node, *nnode;
memset(&rip_packet, 0, sizeof(rip_packet));
@@ -2792,7 +2788,7 @@ int rip_request_send(struct sockaddr_in *to, struct interface *ifp,
}
/* send request on each connected network */
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix_ipv4 *p;
p = (struct prefix_ipv4 *)connected->address;
diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c
index aa470aa65..35d92632a 100644
--- a/ripngd/ripng_interface.c
+++ b/ripngd/ripng_interface.c
@@ -128,11 +128,10 @@ static int ripng_multicast_leave(struct interface *ifp, int sock)
/* How many link local IPv6 address could be used on the interface ? */
static int ripng_if_ipv6_lladdress_check(struct interface *ifp)
{
- struct listnode *nn;
struct connected *connected;
int count = 0;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, nn, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix *p;
p = connected->address;
@@ -408,14 +407,13 @@ static int ripng_enable_network_lookup_if(struct interface *ifp)
{
struct ripng_interface *ri = ifp->info;
struct ripng *ripng = ri->ripng;
- struct listnode *node;
struct connected *connected;
struct prefix_ipv6 address;
if (!ripng)
return -1;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix *p;
struct agg_node *n;
@@ -590,11 +588,10 @@ static void ripng_connect_set(struct interface *ifp, int set)
{
struct ripng_interface *ri = ifp->info;
struct ripng *ripng = ri->ripng;
- struct listnode *node, *nnode;
struct connected *connected;
struct prefix_ipv6 address;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
struct prefix *p;
p = connected->address;
diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c
index 465b40bd3..bb6ec0234 100644
--- a/ripngd/ripngd.c
+++ b/ripngd/ripngd.c
@@ -392,11 +392,10 @@ static void ripng_nexthop_rte(struct rte *rte, struct sockaddr_in6 *from,
/* If ifp has same link-local address then return 1. */
static int ripng_lladdr_check(struct interface *ifp, struct in6_addr *addr)
{
- struct listnode *node;
struct connected *connected;
struct prefix *p;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
p = connected->address;
if (p->family == AF_INET6
diff --git a/tools/checkpatch.pl b/tools/checkpatch.pl
index e3788bde1..ecae0e92a 100755
--- a/tools/checkpatch.pl
+++ b/tools/checkpatch.pl
@@ -555,7 +555,7 @@ our $Iterators = qr{
TAILQ_FOREACH|TAILQ_FOREACH_SAFE|TAILQ_FOREACH_REVERSE|TAILQ_FOREACH_REVERSE_SAFE|
RB_FOREACH|RB_FOREACH_SAFE|RB_FOREACH_REVERSE|RB_FOREACH_REVERSE_SAFE|
SPLAY_FOREACH|
- FOR_ALL_INTERFACES|FOR_ALL_INTERFACES_ADDRESSES|JSON_FOREACH|
+ FOR_ALL_INTERFACES|JSON_FOREACH|
LY_FOR_KEYS|LY_LIST_FOR|LY_TREE_FOR|LY_TREE_DFS_BEGIN|LYD_TREE_DFS_BEGIN|
RE_DEST_FOREACH_ROUTE|RE_DEST_FOREACH_ROUTE_SAFE|
RNODE_FOREACH_RE|RNODE_FOREACH_RE_SAFE|
diff --git a/vrrpd/vrrp.c b/vrrpd/vrrp.c
index b14a6ecc4..017387924 100644
--- a/vrrpd/vrrp.c
+++ b/vrrpd/vrrp.c
@@ -700,10 +700,9 @@ static int vrrp_bind_to_primary_connected(struct vrrp_router *r)
*/
ifp = r->family == AF_INET ? r->vr->ifp : r->mvl_ifp;
- struct listnode *ln;
struct connected *c = NULL;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, ln, c))
+ frr_each (if_connected, ifp->connected, c)
if (c->address->family == r->family) {
if (r->family == AF_INET6
&& IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6))
@@ -1171,9 +1170,15 @@ static int vrrp_socket(struct vrrp_router *r)
r->vr->vrid, family2str(r->family));
/* Join Rx socket to VRRP IPv4 multicast group */
- assert(listhead(r->vr->ifp->connected));
- struct connected *c = listhead(r->vr->ifp->connected)->data;
- struct in_addr v4 = c->address->u.prefix4;
+ struct connected *c;
+ struct in_addr v4;
+
+ frr_each (if_connected, r->vr->ifp->connected, c)
+ if (c->address->family == AF_INET)
+ break;
+
+ assert(c);
+ v4 = c->address->u.prefix4;
ret = setsockopt_ipv4_multicast(r->sock_rx, IP_ADD_MEMBERSHIP,
v4, htonl(VRRP_MCASTV4_GROUP),
@@ -1703,7 +1708,6 @@ int vrrp_event(struct vrrp_router *r, int event)
*/
static void vrrp_autoconfig_autoaddrupdate(struct vrrp_router *r)
{
- struct listnode *ln;
struct connected *c = NULL;
bool is_v6_ll;
@@ -1714,7 +1718,7 @@ static void vrrp_autoconfig_autoaddrupdate(struct vrrp_router *r)
VRRP_LOGPFX VRRP_LOGPFX_VRID VRRP_LOGPFX_FAM
"Setting Virtual IP list to match IPv4 addresses on %s",
r->vr->vrid, family2str(r->family), r->mvl_ifp->name);
- for (ALL_LIST_ELEMENTS_RO(r->mvl_ifp->connected, ln, c)) {
+ frr_each (if_connected, r->mvl_ifp->connected, c) {
is_v6_ll = (c->address->family == AF_INET6
&& IN6_IS_ADDR_LINKLOCAL(&c->address->u.prefix6));
if (c->address->family == r->family && !is_v6_ll) {
diff --git a/vrrpd/vrrp_zebra.c b/vrrpd/vrrp_zebra.c
index 10394752e..009432b21 100644
--- a/vrrpd/vrrp_zebra.c
+++ b/vrrpd/vrrp_zebra.c
@@ -36,11 +36,10 @@ static void vrrp_zebra_debug_if_dump_address(struct interface *ifp,
const char *func)
{
struct connected *ifc;
- struct listnode *node;
DEBUGD(&vrrp_dbg_zebra, "%s: interface %s addresses:", func, ifp->name);
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
struct prefix *p = ifc->address;
DEBUGD(&vrrp_dbg_zebra, "%s: interface %s address %pFX %s",
diff --git a/zebra/connected.c b/zebra/connected.c
index ee0823f56..9a41400f4 100644
--- a/zebra/connected.c
+++ b/zebra/connected.c
@@ -48,7 +48,7 @@ static void connected_withdraw(struct connected *ifc)
UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) {
- listnode_delete(ifc->ifp->connected, ifc);
+ if_connected_del(ifc->ifp->connected, ifc);
connected_free(&ifc);
}
}
@@ -65,7 +65,7 @@ static void connected_announce(struct interface *ifp, struct connected *ifc)
UNSET_FLAG(ifc->flags, ZEBRA_IFA_UNNUMBERED);
}
- listnode_add(ifp->connected, ifc);
+ if_connected_add_tail(ifp->connected, ifc);
/* Update interface address information to protocol daemon. */
if (ifc->address->family == AF_INET)
@@ -84,9 +84,8 @@ struct connected *connected_check(struct interface *ifp,
{
const struct prefix *p = pu.p;
struct connected *ifc;
- struct listnode *node;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc))
+ frr_each (if_connected, ifp->connected, ifc)
if (prefix_same(ifc->address, p))
return ifc;
@@ -101,9 +100,8 @@ struct connected *connected_check_ptp(struct interface *ifp,
const struct prefix *p = pu.p;
const struct prefix *d = du.p;
struct connected *ifc;
- struct listnode *node;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
if (!prefix_same(ifc->address, p))
continue;
if (!CONNECTED_PEER(ifc) && !d)
@@ -192,7 +190,6 @@ void connected_up(struct interface *ifp, struct connected *ifc)
uint32_t metric;
uint32_t flags = 0;
uint32_t count = 0;
- struct listnode *cnode;
struct connected *c;
zvrf = ifp->vrf->info;
@@ -262,7 +259,7 @@ void connected_up(struct interface *ifp, struct connected *ifc)
* for all the addresses on an interface that
* resolve to the same network and mask
*/
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
struct prefix cp;
prefix_copy(&cp, CONNECTED_PREFIX(c));
@@ -376,7 +373,6 @@ void connected_down(struct interface *ifp, struct connected *ifc)
};
struct zebra_vrf *zvrf;
uint32_t count = 0;
- struct listnode *cnode;
struct connected *c;
zvrf = ifp->vrf->info;
@@ -439,7 +435,7 @@ void connected_down(struct interface *ifp, struct connected *ifc)
* allow the deletion when are removing the last
* one.
*/
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
struct prefix cp;
prefix_copy(&cp, CONNECTED_PREFIX(c));
@@ -616,9 +612,8 @@ void connected_delete_ipv6(struct interface *ifp,
int connected_is_unnumbered(struct interface *ifp)
{
struct connected *connected;
- struct listnode *node;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& connected->address->family == AF_INET)
return CHECK_FLAG(connected->flags,
diff --git a/zebra/interface.c b/zebra/interface.c
index 916495606..58a28c607 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -489,12 +489,11 @@ void if_flags_update(struct interface *ifp, uint64_t newflags)
address. */
void if_addr_wakeup(struct interface *ifp)
{
- struct listnode *node, *nnode;
struct connected *ifc;
struct prefix *p;
enum zebra_dplane_result dplane_res;
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) {
+ frr_each_safe (if_connected, ifp->connected, ifc) {
p = ifc->address;
if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)
@@ -637,32 +636,24 @@ void if_add_update(struct interface *ifp)
/* Install connected routes corresponding to an interface. */
static void if_install_connected(struct interface *ifp)
{
- struct listnode *node;
- struct listnode *next;
struct connected *ifc;
- if (ifp->connected) {
- for (ALL_LIST_ELEMENTS(ifp->connected, node, next, ifc)) {
- if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
- zebra_interface_address_add_update(ifp, ifc);
+ frr_each (if_connected, ifp->connected, ifc) {
+ if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
+ zebra_interface_address_add_update(ifp, ifc);
- connected_up(ifp, ifc);
- }
+ connected_up(ifp, ifc);
}
}
/* Uninstall connected routes corresponding to an interface. */
static void if_uninstall_connected(struct interface *ifp)
{
- struct listnode *node;
- struct listnode *next;
struct connected *ifc;
- if (ifp->connected) {
- for (ALL_LIST_ELEMENTS(ifp->connected, node, next, ifc)) {
- zebra_interface_address_delete_update(ifp, ifc);
- connected_down(ifp, ifc);
- }
+ frr_each_safe (if_connected, ifp->connected, ifc) {
+ zebra_interface_address_delete_update(ifp, ifc);
+ connected_down(ifp, ifc);
}
}
@@ -670,20 +661,15 @@ static void if_uninstall_connected(struct interface *ifp)
/* TODO - Check why IPv4 handling here is different from install or if_down */
static void if_delete_connected(struct interface *ifp)
{
- struct connected *ifc;
+ struct connected *ifc, *ifc_next;
struct prefix cp;
struct route_node *rn;
struct zebra_if *zebra_if;
- struct listnode *node;
- struct listnode *last = NULL;
zebra_if = ifp->info;
- if (!ifp->connected)
- return;
-
- while ((node = (last ? last->next : listhead(ifp->connected)))) {
- ifc = listgetdata(node);
+ for (ifc = if_connected_first(ifp->connected); ifc; ifc = ifc_next) {
+ ifc_next = if_connected_next(ifp->connected, ifc);
cp = *CONNECTED_PREFIX(ifc);
apply_mask(&cp);
@@ -732,11 +718,15 @@ static void if_delete_connected(struct interface *ifp)
* (unconditionally). */
if (!CHECK_FLAG(ifc->conf,
ZEBRA_IFC_CONFIGURED)) {
- listnode_delete(ifp->connected,
+ if (ifc == ifc_next)
+ ifc_next = if_connected_next(
+ ifp->connected,
ifc);
+
+ if_connected_del(ifp->connected,
+ ifc);
connected_free(&ifc);
- } else
- last = node;
+ }
}
/* Free chain list and respective route node. */
@@ -751,14 +741,10 @@ static void if_delete_connected(struct interface *ifp)
UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
UNSET_FLAG(ifc->conf, ZEBRA_IFC_QUEUED);
- if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED))
- last = node;
- else {
- listnode_delete(ifp->connected, ifc);
+ if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_CONFIGURED)) {
+ if_connected_del(ifp->connected, ifc);
connected_free(&ifc);
}
- } else {
- last = node;
}
}
}
@@ -2497,12 +2483,12 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf)
}
uint32_t v6_list_size = 0;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& (connected->address->family == AF_INET6))
v6_list_size++;
}
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& !CHECK_FLAG(connected->flags,
ZEBRA_IFA_SECONDARY)
@@ -2536,7 +2522,6 @@ static void ifs_dump_brief_vty(struct vty *vty, struct vrf *vrf)
static void ifs_dump_brief_vty_json(json_object *json, struct vrf *vrf)
{
struct connected *connected;
- struct listnode *node;
struct interface *ifp;
FOR_ALL_INTERFACES (vrf, ifp) {
@@ -2552,7 +2537,7 @@ static void ifs_dump_brief_vty_json(json_object *json, struct vrf *vrf)
json_addrs = json_object_new_array();
json_object_object_add(json_if, "addresses", json_addrs);
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& !CHECK_FLAG(connected->flags,
ZEBRA_IFA_SECONDARY)
@@ -2765,7 +2750,7 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp)
connected_dump_vty(vty, NULL, connected);
}
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& (connected->address->family == AF_INET6))
connected_dump_vty(vty, NULL, connected);
@@ -3142,7 +3127,7 @@ static void if_dump_vty_json(struct vty *vty, struct interface *ifp,
connected_dump_vty(vty, json_addrs, connected);
}
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) {
+ frr_each (if_connected, ifp->connected, connected) {
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& (connected->address->family == AF_INET6))
connected_dump_vty(vty, json_addrs, connected);
@@ -4886,7 +4871,7 @@ int if_ip_address_install(struct interface *ifp, struct prefix *prefix,
ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
/* Add to linked list. */
- listnode_add(ifp->connected, ifc);
+ if_connected_add_tail(ifp->connected, ifc);
}
/* This address is configured from zebra. */
@@ -4981,7 +4966,7 @@ static int ip_address_install(struct vty *vty, struct interface *ifp,
ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
/* Add to linked list. */
- listnode_add(ifp->connected, ifc);
+ if_connected_add_tail(ifp->connected, ifc);
}
/* This address is configured from zebra. */
@@ -5043,7 +5028,7 @@ int if_ip_address_uinstall(struct interface *ifp, struct prefix *prefix)
/* This is not real address or interface is not active. */
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
- listnode_delete(ifp->connected, ifc);
+ if_connected_del(ifp->connected, ifc);
connected_free(&ifc);
return CMD_WARNING_CONFIG_FAILED;
}
@@ -5106,7 +5091,7 @@ static int ip_address_uninstall(struct vty *vty, struct interface *ifp,
/* This is not real address or interface is not active. */
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
- listnode_delete(ifp->connected, ifc);
+ if_connected_del(ifp->connected, ifc);
connected_free(&ifc);
return CMD_WARNING_CONFIG_FAILED;
}
@@ -5244,7 +5229,7 @@ int if_ipv6_address_install(struct interface *ifp, struct prefix *prefix,
ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
/* Add to linked list. */
- listnode_add(ifp->connected, ifc);
+ if_connected_add_tail(ifp->connected, ifc);
}
/* This address is configured from zebra. */
@@ -5317,7 +5302,7 @@ static int ipv6_address_install(struct vty *vty, struct interface *ifp,
ifc->label = XSTRDUP(MTYPE_CONNECTED_LABEL, label);
/* Add to linked list. */
- listnode_add(ifp->connected, ifc);
+ if_connected_add_tail(ifp->connected, ifc);
}
/* This address is configured from zebra. */
@@ -5354,9 +5339,8 @@ static int ipv6_address_install(struct vty *vty, struct interface *ifp,
int ipv6_address_configured(struct interface *ifp)
{
struct connected *connected;
- struct listnode *node;
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected))
+ frr_each (if_connected, ifp->connected, connected)
if (CHECK_FLAG(connected->conf, ZEBRA_IFC_REAL)
&& (connected->address->family == AF_INET6))
return 1;
@@ -5396,7 +5380,7 @@ static int ipv6_address_uninstall(struct vty *vty, struct interface *ifp,
/* This is not real address or interface is not active. */
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
- listnode_delete(ifp->connected, ifc);
+ if_connected_del(ifp->connected, ifc);
connected_free(&ifc);
return CMD_WARNING_CONFIG_FAILED;
}
@@ -5513,7 +5497,6 @@ static int if_config_write(struct vty *vty)
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name)
FOR_ALL_INTERFACES (vrf, ifp) {
struct zebra_if *if_data;
- struct listnode *addrnode;
struct connected *ifc;
struct prefix *p;
@@ -5541,8 +5524,7 @@ static int if_config_write(struct vty *vty)
ZEBRA_INTERFACE_LINKDETECTION))
vty_out(vty, " no link-detect\n");
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, addrnode,
- ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
if (CHECK_FLAG(ifc->conf,
ZEBRA_IFC_CONFIGURED)) {
char buf[INET6_ADDRSTRLEN];
diff --git a/zebra/irdp_interface.c b/zebra/irdp_interface.c
index 253e6a8dd..591236d68 100644
--- a/zebra/irdp_interface.c
+++ b/zebra/irdp_interface.c
@@ -87,12 +87,12 @@ static const char *inet_2a(uint32_t a, char *b, size_t b_len)
static struct prefix *irdp_get_prefix(struct interface *ifp)
{
- struct listnode *node;
struct connected *ifc;
- if (ifp->connected)
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc))
+ frr_each (if_connected, ifp->connected, ifc) {
+ if (ifc->address->family == AF_INET)
return ifc->address;
+ }
return NULL;
}
@@ -198,7 +198,6 @@ static void irdp_if_start(struct interface *ifp, int multicast,
{
struct zebra_if *zi = ifp->info;
struct irdp_interface *irdp = zi->irdp;
- struct listnode *node;
struct connected *ifc;
uint32_t timer, seed;
@@ -247,11 +246,12 @@ static void irdp_if_start(struct interface *ifp, int multicast,
/* The spec suggests this for randomness */
seed = 0;
- if (ifp->connected)
- for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, ifc)) {
+ frr_each (if_connected, ifp->connected, ifc) {
+ if (ifc->address->family == AF_INET) {
seed = ifc->address->u.prefix4.s_addr;
break;
}
+ }
srandom(seed);
timer = (frr_weak_random() % IRDP_DEFAULT_INTERVAL) + 1;
diff --git a/zebra/irdp_main.c b/zebra/irdp_main.c
index 6548790e9..349ae1a19 100644
--- a/zebra/irdp_main.c
+++ b/zebra/irdp_main.c
@@ -197,7 +197,6 @@ void irdp_send_thread(struct event *t_advert)
struct zebra_if *zi = ifp->info;
struct irdp_interface *irdp = zi->irdp;
struct prefix *p;
- struct listnode *node, *nnode;
struct connected *ifc;
if (!irdp)
@@ -205,16 +204,15 @@ void irdp_send_thread(struct event *t_advert)
irdp->flags &= ~IF_SOLICIT;
- if (ifp->connected)
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) {
- p = ifc->address;
+ frr_each (if_connected, ifp->connected, ifc) {
+ p = ifc->address;
- if (p->family != AF_INET)
- continue;
+ if (p->family != AF_INET)
+ continue;
- irdp_advertisement(ifp, p);
- irdp->irdp_sent++;
- }
+ irdp_advertisement(ifp, p);
+ irdp->irdp_sent++;
+ }
tmp = irdp->MaxAdvertInterval - irdp->MinAdvertInterval;
timer = frr_weak_random() % (tmp + 1);
@@ -237,7 +235,6 @@ void irdp_advert_off(struct interface *ifp)
{
struct zebra_if *zi = ifp->info;
struct irdp_interface *irdp = zi->irdp;
- struct listnode *node, *nnode;
int i;
struct connected *ifc;
struct prefix *p;
@@ -247,19 +244,21 @@ void irdp_advert_off(struct interface *ifp)
EVENT_OFF(irdp->t_advertise);
- if (ifp->connected)
- for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, ifc)) {
- p = ifc->address;
+ frr_each (if_connected, ifp->connected, ifc) {
+ p = ifc->address;
- /* Output some packets with Lifetime 0
- we should add a wait...
- */
+ if (p->family != AF_INET)
+ continue;
- for (i = 0; i < IRDP_LAST_ADVERT_MESSAGES; i++) {
- irdp->irdp_sent++;
- irdp_advertisement(ifp, p);
- }
+ /* Output some packets with Lifetime 0
+ we should add a wait...
+ */
+
+ for (i = 0; i < IRDP_LAST_ADVERT_MESSAGES; i++) {
+ irdp->irdp_sent++;
+ irdp_advertisement(ifp, p);
}
+ }
}
diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c
index 390ebc8f4..8a09fb073 100644
--- a/zebra/zapi_msg.c
+++ b/zebra/zapi_msg.c
@@ -415,7 +415,7 @@ int zsend_interface_addresses(struct zserv *client, struct interface *ifp)
struct nbr_connected *nc;
/* Send interface addresses. */
- for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL))
continue;
diff --git a/zebra/zebra_evpn.c b/zebra/zebra_evpn.c
index ce5e63992..147f5b93f 100644
--- a/zebra/zebra_evpn.c
+++ b/zebra/zebra_evpn.c
@@ -310,13 +310,12 @@ void zebra_evpn_print_hash_detail(struct hash_bucket *bucket, void *data)
int zebra_evpn_del_macip_for_intf(struct interface *ifp,
struct zebra_evpn *zevpn)
{
- struct listnode *cnode = NULL, *cnnode = NULL;
struct connected *c = NULL;
struct ethaddr macaddr;
memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN);
- for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) {
+ frr_each_safe (if_connected, ifp->connected, c) {
struct ipaddr ip;
memset(&ip, 0, sizeof(struct ipaddr));
@@ -344,13 +343,12 @@ int zebra_evpn_del_macip_for_intf(struct interface *ifp,
int zebra_evpn_add_macip_for_intf(struct interface *ifp,
struct zebra_evpn *zevpn)
{
- struct listnode *cnode = NULL, *cnnode = NULL;
struct connected *c = NULL;
struct ethaddr macaddr;
memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN);
- for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) {
+ frr_each_safe (if_connected, ifp->connected, c) {
struct ipaddr ip;
if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL))
@@ -409,13 +407,12 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p,
int zebra_evpn_advertise_subnet(struct zebra_evpn *zevpn, struct interface *ifp,
int advertise)
{
- struct listnode *cnode = NULL, *cnnode = NULL;
struct connected *c = NULL;
struct ethaddr macaddr;
memcpy(&macaddr.octet, ifp->hw_addr, ETH_ALEN);
- for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) {
+ frr_each (if_connected, ifp->connected, c) {
struct prefix p;
memcpy(&p, c->address, sizeof(struct prefix));
diff --git a/zebra/zebra_nb_config.c b/zebra/zebra_nb_config.c
index 5ea03112b..4d3e4c63e 100644
--- a/zebra/zebra_nb_config.c
+++ b/zebra/zebra_nb_config.c
@@ -910,7 +910,7 @@ int lib_interface_zebra_ip_addrs_destroy(struct nb_cb_destroy_args *args)
/* This is not real address or interface is not active. */
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_QUEUED)
|| !CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE)) {
- listnode_delete(ifp->connected, ifc);
+ if_connected_del(ifp->connected, ifc);
connected_free(&ifc);
return NB_ERR_VALIDATION;
}