Skip to content

Commit

Permalink
review code
Browse files Browse the repository at this point in the history
  • Loading branch information
root committed Dec 1, 2023
1 parent 7d81ae6 commit d83f898
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions ospf6d/ospf6_neighbor.c
Original file line number Diff line number Diff line change
Expand Up @@ -846,38 +846,32 @@ DEFPY(ipv6_ospf6_p2xp_neigh_poll_interval,

p2xp_unicast_hello_sched(p2xp_cfg);
return CMD_SUCCESS;

}

/* build state value */
static void ospf6_neighbor_state_message(struct ospf6_neighbor *on,
char *nstate, size_t nstate_len)
static const char *ospf6_neighbor_state_message(struct ospf6_neighbor *on)
{
/* Neighbor State */
if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
snprintf(nstate, nstate_len, "PointToPoint");
return "PointToPoint";
else {
if (on->router_id == on->drouter)
snprintf(nstate, nstate_len, "DR");
return "DR";
else if (on->router_id == on->bdrouter)
snprintf(nstate, nstate_len, "BR");
return "BR";
else
snprintf(nstate, nstate_len, "DROther");
return "DROther";
}
}

/* build nbrState value */
static void ospf6_neighbor_nstate_message(struct ospf6_neighbor *on,
char *nstate, size_t nstate_len)
{
char state[16];

memset(state, 0, sizeof(state));
memset(nstate, 0, nstate_len);

ospf6_neighbor_state_message(on, state, sizeof(state));

snprintf(nstate, nstate_len, "%s/%s", state,
snprintf(nstate, nstate_len, "%s/%s",
ospf6_neighbor_state_message(on),
ospf6_neighbor_state_str[on->state]);
}

Expand Down Expand Up @@ -913,19 +907,11 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
snprintf(deadtime, sizeof(deadtime), "%02ld:%02ld:%02ld", h, m, s);

/* Neighbor State */
if (on->ospf6_if->type == OSPF_IFTYPE_POINTOPOINT)
snprintf(nstate, sizeof(nstate), "PointToPoint");
else if (on->ospf6_if->type == OSPF_IFTYPE_POINTOMULTIPOINT)
if (on->ospf6_if->type == OSPF_IFTYPE_POINTOMULTIPOINT)
snprintf(nstate, sizeof(nstate), "PtMultipoint");
else {
if (on->router_id == on->drouter)
snprintf(nstate, sizeof(nstate), "DR");
else if (on->router_id == on->bdrouter)
snprintf(nstate, sizeof(nstate), "BDR");
else
snprintf(nstate, sizeof(nstate), "DROther");
}
ospf6_neighbor_state_message(on, nstate, sizeof(nstate));
else
snprintf(nstate, sizeof(nstate), "%s",
ospf6_neighbor_state_message(on));

/* Duration */
monotime_since(&on->last_changed, &res);
Expand All @@ -950,7 +936,7 @@ static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on,
ospf6_neighbor_state_str[on->state]);
json_object_int_add(json_route, "nbrPriority", on->priority);
json_object_string_add(json_route, "nbrState", nstate);
json_object_string_add(json_route, "Role",
json_object_string_add(json_route, "role",
ospf6_neighbor_state_str[on->state]);
if (on->inactivity_timer) {
time_store =
Expand Down Expand Up @@ -1071,7 +1057,7 @@ static void ospf6_neighbor_show_detail(struct vty *vty,
ospf6_neighbor_state_str[on->state]);
json_object_int_add(json_neighbor, "nbrPriority", on->priority);
json_object_string_add(json_neighbor, "nbrState", nstate);
json_object_string_add(json_neighbor, "Role",
json_object_string_add(json_neighbor, "role",
ospf6_neighbor_state_str[on->state]);
if (on->inactivity_timer) {
time_store =
Expand Down

0 comments on commit d83f898

Please sign in to comment.