Skip to content

Commit

Permalink
lib,zebra: add interface event debugs
Browse files Browse the repository at this point in the history
Add debugs to the interface library, and to a couple of zebra
interface- and vrf-message apis.

Signed-off-by: Mark Stapp <[email protected]>
  • Loading branch information
Mark Stapp committed Mar 6, 2024
1 parent c256a9a commit b214777
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
35 changes: 35 additions & 0 deletions lib/if.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ DEFINE_KOOH(if_unreal, (struct interface *ifp), (ifp));
DEFINE_HOOK(if_up, (struct interface *ifp), (ifp));
DEFINE_KOOH(if_down, (struct interface *ifp), (ifp));

/* Control debug output for the lib module */
static bool ifp_debug;

/* Compare interface names, returning an integer greater than, equal to, or
* less than 0, (following the strcmp convention), according to the
* relationship between ifp1 and ifp2. Interface names consist of an
Expand Down Expand Up @@ -178,11 +181,19 @@ static struct interface *if_new(struct vrf *vrf)

void if_new_via_zapi(struct interface *ifp)
{
if (ifp_debug)
zlog_debug("%s: ifp %s, vrf %u", __func__, ifp->name,
ifp->vrf->vrf_id);

hook_call(if_real, ifp);
}

void if_destroy_via_zapi(struct interface *ifp)
{
if (ifp_debug)
zlog_debug("%s: ifp %s, vrf %u", __func__, ifp->name,
ifp->vrf->vrf_id);

hook_call(if_unreal, ifp);

ifp->oldifindex = ifp->ifindex;
Expand All @@ -194,11 +205,19 @@ void if_destroy_via_zapi(struct interface *ifp)

void if_up_via_zapi(struct interface *ifp)
{
if (ifp_debug)
zlog_debug("%s: ifp %s, vrf %u", __func__, ifp->name,
ifp->vrf->vrf_id);

hook_call(if_up, ifp);
}

void if_down_via_zapi(struct interface *ifp)
{
if (ifp_debug)
zlog_debug("%s: ifp %s, vrf %u", __func__, ifp->name,
ifp->vrf->vrf_id);

hook_call(if_down, ifp);
}

Expand All @@ -210,6 +229,10 @@ static struct interface *if_create_name(const char *name, struct vrf *vrf)

if_set_name(ifp, name);

if (ifp_debug)
zlog_debug("%s: ifp %s, vrf %u", __func__, ifp->name,
ifp->vrf->vrf_id);

hook_call(if_add, ifp);
return ifp;
}
Expand All @@ -222,6 +245,10 @@ void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id)
/* remove interface from old master vrf list */
old_vrf = ifp->vrf;

if (ifp_debug)
zlog_debug("%s: ifp %s, old vrf %u -> new vrf %u", __func__,
ifp->name, old_vrf->vrf_id, vrf_id);

if (ifp->name[0] != '\0')
IFNAME_RB_REMOVE(old_vrf, ifp);

Expand Down Expand Up @@ -261,6 +288,10 @@ void if_delete(struct interface **ifp)
struct interface *ptr = *ifp;
struct vrf *vrf = ptr->vrf;

if (ifp_debug)
zlog_debug("%s: ifp %s, vrf %u", __func__, ptr->name,
vrf->vrf_id);

IFNAME_RB_REMOVE(vrf, ptr);
if (ptr->ifindex != IFINDEX_INTERNAL)
IFINDEX_RB_REMOVE(vrf, ptr);
Expand Down Expand Up @@ -585,6 +616,10 @@ struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id,

break;
case VRF_BACKEND_VRF_LITE:
if (ifp_debug)
zlog_debug("%s: ifname %s, vrf_id %i, vrf_name %s",
__func__, name, vrf_id, vrf_name);

ifp = if_lookup_by_name_all_vrf(name);
if (ifp) {
/* If it came from the kernel or by way of zclient,
Expand Down
16 changes: 16 additions & 0 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ int zsend_interface_add(struct zserv *client, struct interface *ifp)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);

if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: %s %s vrf %s(%u)", __func__, ifp->name,
ifp->vrf->name, ifp->vrf->vrf_id);

zclient_create_header(s, ZEBRA_INTERFACE_ADD, ifp->vrf->vrf_id);
zserv_encode_interface(s, ifp);

Expand All @@ -187,6 +191,10 @@ int zsend_interface_delete(struct zserv *client, struct interface *ifp)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);

if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: %s %s vrf %s(%u)", __func__, ifp->name,
ifp->vrf->name, ifp->vrf->vrf_id);

zclient_create_header(s, ZEBRA_INTERFACE_DELETE, ifp->vrf->vrf_id);
zserv_encode_interface(s, ifp);

Expand All @@ -198,6 +206,10 @@ int zsend_vrf_add(struct zserv *client, struct zebra_vrf *zvrf)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);

if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: %s vrf %s(%u)", __func__, zvrf->vrf->name,
zvrf_id(zvrf));

zclient_create_header(s, ZEBRA_VRF_ADD, zvrf_id(zvrf));
zserv_encode_vrf(s, zvrf);

Expand All @@ -211,6 +223,10 @@ int zsend_vrf_delete(struct zserv *client, struct zebra_vrf *zvrf)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);

if (IS_ZEBRA_DEBUG_EVENT)
zlog_debug("MESSAGE: %s vrf %s(%u)", __func__, zvrf->vrf->name,
zvrf_id(zvrf));

zclient_create_header(s, ZEBRA_VRF_DELETE, zvrf_id(zvrf));
zserv_encode_vrf(s, zvrf);

Expand Down

0 comments on commit b214777

Please sign in to comment.