zebra: use SET/UNSET/CHECK/COND in protodown code

Use the SET/UNSET/CHECK/COND macros for flag bifields
where appropriate throught the protodown code base.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
This commit is contained in:
Stephen Worley 2022-02-15 18:21:18 -05:00
parent 26a64ff9ca
commit 7140b00cb0
3 changed files with 29 additions and 33 deletions

View File

@ -852,11 +852,10 @@ static void netlink_proc_dplane_if_protodown(struct zebra_if *zif,
* If the reason we got from the kernel is ONLY frr though, don't
* set it.
*/
if (protodown && rc_bitfield &&
is_if_protodown_reason_only_frr(rc_bitfield) == false)
zif->protodown_rc |= ZEBRA_PROTODOWN_EXTERNAL;
else
zif->protodown_rc &= ~ZEBRA_PROTODOWN_EXTERNAL;
COND_FLAG(zif->protodown_rc, ZEBRA_PROTODOWN_EXTERNAL,
protodown && rc_bitfield &&
!is_if_protodown_reason_only_frr(rc_bitfield));
old_protodown = !!ZEBRA_IF_IS_PROTODOWN(zif);
if (protodown == old_protodown)
@ -866,17 +865,16 @@ static void netlink_proc_dplane_if_protodown(struct zebra_if *zif,
zlog_debug("interface %s dplane change, protdown %s",
zif->ifp->name, protodown ? "on" : "off");
if (protodown)
zif->flags |= ZIF_FLAG_PROTODOWN;
else
zif->flags &= ~ZIF_FLAG_PROTODOWN;
/* Set protodown, respectively */
COND_FLAG(zif->flags, ZIF_FLAG_PROTODOWN, protodown);
if (zebra_evpn_is_es_bond_member(zif->ifp)) {
/* Check it's not already being sent to the dplane first */
if (protodown && (zif->flags & ZIF_FLAG_SET_PROTODOWN))
if (protodown && CHECK_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN))
return;
if (!protodown && (zif->flags & ZIF_FLAG_UNSET_PROTODOWN))
if (!protodown
&& CHECK_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN))
return;
if (IS_ZEBRA_DEBUG_EVPN_MH_ES || IS_ZEBRA_DEBUG_KERNEL)
@ -885,9 +883,9 @@ static void netlink_proc_dplane_if_protodown(struct zebra_if *zif,
zif->ifp->name, old_protodown ? "on" : "off");
if (old_protodown)
zif->flags |= ZIF_FLAG_SET_PROTODOWN;
SET_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN);
else
zif->flags |= ZIF_FLAG_UNSET_PROTODOWN;
SET_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN);
dplane_intf_update(zif->ifp);
}
@ -926,7 +924,7 @@ static void if_sweep_protodown(struct zebra_if *zif)
zif->protodown_rc);
/* Only clear our reason codes, leave external if it was set */
zif->protodown_rc &= ~ZEBRA_PROTODOWN_ALL;
UNSET_FLAG(zif->protodown_rc, ZEBRA_PROTODOWN_ALL);
dplane_intf_update(zif->ifp);
}

View File

@ -1246,8 +1246,8 @@ static bool if_ignore_set_protodown(const struct interface *ifp, bool new_down,
/* Current state as we know it */
old_down = !!(ZEBRA_IF_IS_PROTODOWN(zif));
old_set_down = !!(zif->flags & ZIF_FLAG_SET_PROTODOWN);
old_unset_down = !!(zif->flags & ZIF_FLAG_UNSET_PROTODOWN);
old_set_down = !!CHECK_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN);
old_unset_down = !!CHECK_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN);
if (new_protodown_rc == zif->protodown_rc) {
/* Early return if already down & reason bitfield matches */
@ -1311,9 +1311,9 @@ int zebra_if_update_protodown_rc(struct interface *ifp, bool new_down,
zif->protodown_rc = new_protodown_rc;
if (new_down)
zif->flags |= ZIF_FLAG_SET_PROTODOWN;
SET_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN);
else
zif->flags |= ZIF_FLAG_UNSET_PROTODOWN;
SET_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN);
#ifdef HAVE_NETLINK
dplane_intf_update(ifp);
@ -1450,15 +1450,12 @@ static void zebra_if_update_ctx(struct zebra_dplane_ctx *ctx,
}
/* Update our info */
if (down)
zif->flags |= ZIF_FLAG_PROTODOWN;
else
zif->flags &= ~ZIF_FLAG_PROTODOWN;
COND_FLAG(zif->flags, ZIF_FLAG_PROTODOWN, down);
done:
/* Clear our dplane flags */
zif->flags &= ~ZIF_FLAG_SET_PROTODOWN;
zif->flags &= ~ZIF_FLAG_UNSET_PROTODOWN;
UNSET_FLAG(zif->flags, ZIF_FLAG_SET_PROTODOWN);
UNSET_FLAG(zif->flags, ZIF_FLAG_UNSET_PROTODOWN);
}
/*
@ -1859,19 +1856,19 @@ const char *zebra_protodown_rc_str(uint32_t protodown_rc, char *pd_buf,
strlcat(pd_buf, "(", pd_buf_len);
if (protodown_rc & ZEBRA_PROTODOWN_EXTERNAL)
if (CHECK_FLAG(protodown_rc, ZEBRA_PROTODOWN_EXTERNAL))
strlcat(pd_buf, "external,", pd_buf_len);
if (protodown_rc & ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY)
if (CHECK_FLAG(protodown_rc, ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY))
strlcat(pd_buf, "startup-delay,", pd_buf_len);
if (protodown_rc & ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN)
if (CHECK_FLAG(protodown_rc, ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN))
strlcat(pd_buf, "uplinks-down,", pd_buf_len);
if (protodown_rc & ZEBRA_PROTODOWN_VRRP)
if (CHECK_FLAG(protodown_rc, ZEBRA_PROTODOWN_VRRP))
strlcat(pd_buf, "vrrp,", pd_buf_len);
if (protodown_rc & ZEBRA_PROTODOWN_SHARP)
if (CHECK_FLAG(protodown_rc, ZEBRA_PROTODOWN_SHARP))
strlcat(pd_buf, "sharp,", pd_buf_len);
len = strnlen(pd_buf, pd_buf_len);

View File

@ -3463,13 +3463,14 @@ void zebra_evpn_mh_json(json_object *json)
if (zmh_info->protodown_rc) {
json_array = json_object_new_array();
if (zmh_info->protodown_rc & ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY)
if (CHECK_FLAG(zmh_info->protodown_rc,
ZEBRA_PROTODOWN_EVPN_STARTUP_DELAY))
json_object_array_add(
json_array,
json_object_new_string("startupDelay"));
if (zmh_info->protodown_rc & ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN)
json_object_array_add(
json_array,
if (CHECK_FLAG(zmh_info->protodown_rc,
ZEBRA_PROTODOWN_EVPN_UPLINK_DOWN))
json_object_array_add(json_array,
json_object_new_string("uplinkDown"));
json_object_object_add(json, "protodownReasons", json_array);
}