Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bfdd: changes for code maintainability #16394

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bfdd/bfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ static uint32_t ptm_bfd_gen_ID(void)
* random session identification numbers.
*/
do {
session_id = ((frr_weak_random() << 16) & 0xFFFF0000)
| (frr_weak_random() & 0x0000FFFF);
session_id = CHECK_FLAG((frr_weak_random() << 16), 0xFFFF0000) |
CHECK_FLAG(frr_weak_random(), 0x0000FFFF);
} while (session_id == 0 || bfd_id_lookup(session_id) != NULL);

return session_id;
Expand Down
25 changes: 13 additions & 12 deletions bfdd/bfd.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,45 +97,46 @@ struct bfd_echo_pkt {
/* Macros for manipulating control packets */
#define BFD_VERMASK 0x07
#define BFD_DIAGMASK 0x1F
#define BFD_GETVER(diag) ((diag >> 5) & BFD_VERMASK)
#define BFD_SETVER(diag, val) ((diag) |= (val & BFD_VERMASK) << 5)
#define BFD_GETVER(diag) (CHECK_FLAG((diag >> 5), BFD_VERMASK))
#define BFD_SETVER(diag, val) \
SET_FLAG((diag), CHECK_FLAG(val, BFD_VERMASK) << 5)
#define BFD_VERSION 1
#define BFD_PBIT 0x20
#define BFD_FBIT 0x10
#define BFD_CBIT 0x08
#define BFD_ABIT 0x04
#define BFD_DEMANDBIT 0x02
#define BFD_MBIT 0x01
#define BFD_GETMBIT(flags) (flags & BFD_MBIT)
#define BFD_GETMBIT(flags) (CHECK_FLAG(flags, BFD_MBIT))
#define BFD_SETDEMANDBIT(flags, val) \
{ \
if ((val)) \
flags |= BFD_DEMANDBIT; \
SET_FLAG(flags, BFD_DEMANDBIT); \
}
#define BFD_SETPBIT(flags, val) \
{ \
if ((val)) \
flags |= BFD_PBIT; \
SET_FLAG(flags, BFD_PBIT); \
}
#define BFD_GETPBIT(flags) (flags & BFD_PBIT)
#define BFD_GETPBIT(flags) (CHECK_FLAG(flags, BFD_PBIT))
#define BFD_SETFBIT(flags, val) \
{ \
if ((val)) \
flags |= BFD_FBIT; \
SET_FLAG(flags, BFD_FBIT); \
}
#define BFD_GETFBIT(flags) (flags & BFD_FBIT)
#define BFD_GETFBIT(flags) (CHECK_FLAG(flags, BFD_FBIT))
#define BFD_SETSTATE(flags, val) \
{ \
if ((val)) \
flags |= (val & 0x3) << 6; \
SET_FLAG(flags, (CHECK_FLAG(val, 0x3) << 6)); \
}
#define BFD_GETSTATE(flags) ((flags >> 6) & 0x3)
#define BFD_GETSTATE(flags) (CHECK_FLAG((flags >> 6), 0x3))
#define BFD_SETCBIT(flags, val) \
{ \
if ((val)) \
flags |= val; \
SET_FLAG(flags, val); \
}
#define BFD_GETCBIT(flags) (flags & BFD_CBIT)
#define BFD_GETCBIT(flags) (CHECK_FLAG(flags, BFD_CBIT))
#define BFD_ECHO_VERSION 1
#define BFD_ECHO_PKT_LEN sizeof(struct bfd_echo_pkt)

Expand Down
4 changes: 2 additions & 2 deletions bfdd/bfd_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -982,7 +982,7 @@ void bfd_recv_cb(struct event *t)
}

/* Save remote diagnostics before state switch. */
bfd->remote_diag = cp->diag & BFD_DIAGMASK;
bfd->remote_diag = CHECK_FLAG(cp->diag, BFD_DIAGMASK);

/* Update remote timers settings. */
bfd->remote_timers.desired_min_tx = ntohl(cp->timers.desired_min_tx);
Expand Down Expand Up @@ -1738,7 +1738,7 @@ void bfd_peer_mac_set(int sd, struct bfd_session *bfd,

if (CHECK_FLAG(bfd->flags, BFD_SESS_FLAG_MAC_SET))
return;
if (ifp->flags & IFF_NOARP)
if (CHECK_FLAG(ifp->flags, IFF_NOARP))
return;

if (peer->sa_sin.sin_family == AF_INET) {
Expand Down
Loading