ldpd: changes for code maintainability

these changes are for improving the code maintainability and readability

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
This commit is contained in:
sri-mohan1 2023-06-08 23:19:43 +05:30
parent 22c329ed32
commit 8443d112b3
5 changed files with 17 additions and 34 deletions

View file

@ -106,8 +106,7 @@ static void control_accept(struct event *thread)
*/ */
if (errno == ENFILE || errno == EMFILE) if (errno == ENFILE || errno == EMFILE)
accept_pause(); accept_pause();
else if (errno != EWOULDBLOCK && errno != EINTR && else if (errno != EWOULDBLOCK && errno != EINTR && errno != ECONNABORTED)
errno != ECONNABORTED)
log_warn("%s: accept", __func__); log_warn("%s: accept", __func__);
return; return;
} }
@ -192,8 +191,7 @@ static void control_dispatch_imsg(struct event *thread)
c->iev.ev_read = NULL; c->iev.ev_read = NULL;
if (((n = imsg_read(&c->iev.ibuf)) == -1 && errno != EAGAIN) || if (((n = imsg_read(&c->iev.ibuf)) == -1 && errno != EAGAIN) || n == 0) {
n == 0) {
control_close(fd); control_close(fd);
return; return;
} }
@ -217,12 +215,10 @@ static void control_dispatch_imsg(struct event *thread)
/* ignore */ /* ignore */
break; break;
case IMSG_CTL_SHOW_INTERFACE: case IMSG_CTL_SHOW_INTERFACE:
if (imsg.hdr.len == IMSG_HEADER_SIZE + if (imsg.hdr.len == IMSG_HEADER_SIZE + sizeof(ifidx)) {
sizeof(ifidx)) {
memcpy(&ifidx, imsg.data, sizeof(ifidx)); memcpy(&ifidx, imsg.data, sizeof(ifidx));
ldpe_iface_ctl(c, ifidx); ldpe_iface_ctl(c, ifidx);
imsg_compose_event(&c->iev, IMSG_CTL_END, 0, imsg_compose_event(&c->iev, IMSG_CTL_END, 0, 0, -1, NULL, 0);
0, -1, NULL, 0);
} }
break; break;
case IMSG_CTL_SHOW_DISCOVERY: case IMSG_CTL_SHOW_DISCOVERY:
@ -242,8 +238,7 @@ static void control_dispatch_imsg(struct event *thread)
ldpe_nbr_ctl(c); ldpe_nbr_ctl(c);
break; break;
case IMSG_CTL_CLEAR_NBR: case IMSG_CTL_CLEAR_NBR:
if (imsg.hdr.len != IMSG_HEADER_SIZE + if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct ctl_nbr))
sizeof(struct ctl_nbr))
break; break;
nbr_clear_ctl(imsg.data); nbr_clear_ctl(imsg.data);
@ -255,8 +250,7 @@ static void control_dispatch_imsg(struct event *thread)
/* ignore */ /* ignore */
break; break;
default: default:
log_debug("%s: error handling imsg %d", __func__, log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type);
imsg.hdr.type);
break; break;
} }
imsg_free(&imsg); imsg_free(&imsg);

View file

@ -97,8 +97,7 @@ ldp_vty_debug(struct vty *vty, const char *negate, const char *type_str,
DEBUG_ON(zebra, LDP_DEBUG_ZEBRA); DEBUG_ON(zebra, LDP_DEBUG_ZEBRA);
} }
main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug, main_imsg_compose_both(IMSG_DEBUG_UPDATE, &ldp_debug, sizeof(ldp_debug));
sizeof(ldp_debug));
return (CMD_SUCCESS); return (CMD_SUCCESS);
} }
@ -119,13 +118,11 @@ ldp_vty_show_debugging(struct vty *vty)
if (LDP_DEBUG(labels, LDP_DEBUG_LABELS)) if (LDP_DEBUG(labels, LDP_DEBUG_LABELS))
vty_out (vty, " LDP labels debugging is on\n"); vty_out (vty, " LDP labels debugging is on\n");
if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL)) if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV_ALL))
vty_out (vty, vty_out (vty, " LDP detailed messages debugging is on (inbound)\n");
" LDP detailed messages debugging is on (inbound)\n");
else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV)) else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_RECV))
vty_out (vty," LDP messages debugging is on (inbound)\n"); vty_out (vty," LDP messages debugging is on (inbound)\n");
if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL)) if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND_ALL))
vty_out (vty, vty_out (vty, " LDP detailed messages debugging is on (outbound)\n");
" LDP detailed messages debugging is on (outbound)\n");
else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND)) else if (LDP_DEBUG(msg, LDP_DEBUG_MSG_SEND))
vty_out (vty," LDP messages debugging is on (outbound)\n"); vty_out (vty," LDP messages debugging is on (outbound)\n");
if (LDP_DEBUG(sync, LDP_DEBUG_SYNC)) if (LDP_DEBUG(sync, LDP_DEBUG_SYNC))

View file

@ -35,13 +35,11 @@ vlog(int pri, const char *fmt, va_list ap)
switch (ldpd_process) { switch (ldpd_process) {
case PROC_LDE_ENGINE: case PROC_LDE_ENGINE:
vsnprintfrr(buf, sizeof(buf), fmt, ap); vsnprintfrr(buf, sizeof(buf), fmt, ap);
lde_imsg_compose_parent_sync(IMSG_LOG, pri, buf, lde_imsg_compose_parent_sync(IMSG_LOG, pri, buf, strlen(buf) + 1);
strlen(buf) + 1);
break; break;
case PROC_LDP_ENGINE: case PROC_LDP_ENGINE:
vsnprintfrr(buf, sizeof(buf), fmt, ap); vsnprintfrr(buf, sizeof(buf), fmt, ap);
ldpe_imsg_compose_parent_sync(IMSG_LOG, pri, buf, ldpe_imsg_compose_parent_sync(IMSG_LOG, pri, buf, strlen(buf) + 1);
strlen(buf) + 1);
break; break;
case PROC_MAIN: case PROC_MAIN:
vzlog(pri, fmt, ap); vzlog(pri, fmt, ap);
@ -121,15 +119,13 @@ void
fatal(const char *emsg) fatal(const char *emsg)
{ {
if (emsg == NULL) if (emsg == NULL)
logit(LOG_CRIT, "fatal in %s: %s", log_procname, logit(LOG_CRIT, "fatal in %s: %s", log_procname, strerror(errno));
strerror(errno));
else else
if (errno) if (errno)
logit(LOG_CRIT, "fatal in %s: %s: %s", logit(LOG_CRIT, "fatal in %s: %s: %s",
log_procname, emsg, strerror(errno)); log_procname, emsg, strerror(errno));
else else
logit(LOG_CRIT, "fatal in %s: %s", logit(LOG_CRIT, "fatal in %s: %s", log_procname, emsg);
log_procname, emsg);
exit(1); exit(1);
} }

View file

@ -74,8 +74,7 @@ log_addr(int af, const union ldpd_addr *addr)
switch (af) { switch (af) {
case AF_INET: case AF_INET:
round = (round + 1) % NUM_LOGS; round = (round + 1) % NUM_LOGS;
if (inet_ntop(AF_INET, &addr->v4, buf[round], if (inet_ntop(AF_INET, &addr->v4, buf[round], sizeof(buf[round])) == NULL)
sizeof(buf[round])) == NULL)
return ("???"); return ("???");
return (buf[round]); return (buf[round]);
case AF_INET6: case AF_INET6:
@ -166,8 +165,7 @@ log_hello_src(const struct hello_source *src)
switch (src->type) { switch (src->type) {
case HELLO_LINK: case HELLO_LINK:
snprintf(buf, sizeof(buf), "iface %s", snprintf(buf, sizeof(buf), "iface %s", src->link.ia->iface->name);
src->link.ia->iface->name);
break; break;
case HELLO_TARGETED: case HELLO_TARGETED:
snprintf(buf, sizeof(buf), "source %s", snprintf(buf, sizeof(buf), "source %s",

View file

@ -256,8 +256,7 @@ pfkey_read(int sd, struct sadb_msg *h)
} }
/* XXX: Only one message can be outstanding. */ /* XXX: Only one message can be outstanding. */
if (hdr.sadb_msg_seq == sadb_msg_seq && if (hdr.sadb_msg_seq == sadb_msg_seq && hdr.sadb_msg_pid == pid) {
hdr.sadb_msg_pid == pid) {
if (h) if (h)
*h = hdr; *h = hdr;
return (0); return (0);
@ -412,8 +411,7 @@ pfkey_establish(struct nbr *nbr, struct nbr_params *nbrp)
{ {
switch (nbr->auth.method) { switch (nbr->auth.method) {
case AUTH_MD5SIG: case AUTH_MD5SIG:
strlcpy(nbr->auth.md5key, nbrp->auth.md5key, strlcpy(nbr->auth.md5key, nbrp->auth.md5key, sizeof(nbr->auth.md5key));
sizeof(nbr->auth.md5key));
return pfkey_md5sig_establish(nbr, nbrp); return pfkey_md5sig_establish(nbr, nbrp);
case AUTH_NONE: case AUTH_NONE:
return 0; return 0;