forked from Mirror/frr
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:
parent
849d8f2bbd
commit
91cde6087d
59
ldpd/ldpe.c
59
ldpd/ldpe.c
|
@ -257,8 +257,7 @@ ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data,
|
||||||
{
|
{
|
||||||
if (iev_lde->ibuf.fd == -1)
|
if (iev_lde->ibuf.fd == -1)
|
||||||
return (0);
|
return (0);
|
||||||
return (imsg_compose_event(iev_lde, type, peerid, pid, -1,
|
return (imsg_compose_event(iev_lde, type, peerid, pid, -1, data, datalen));
|
||||||
data, datalen));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
|
@ -309,8 +308,7 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
|
|
||||||
switch (imsg.hdr.type) {
|
switch (imsg.hdr.type) {
|
||||||
case IMSG_IFSTATUS:
|
case IMSG_IFSTATUS:
|
||||||
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct kif))
|
||||||
sizeof(struct kif))
|
|
||||||
fatalx("IFSTATUS imsg with wrong len");
|
fatalx("IFSTATUS imsg with wrong len");
|
||||||
kif = imsg.data;
|
kif = imsg.data;
|
||||||
|
|
||||||
|
@ -336,15 +334,13 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IMSG_NEWADDR:
|
case IMSG_NEWADDR:
|
||||||
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct kaddr))
|
||||||
sizeof(struct kaddr))
|
|
||||||
fatalx("NEWADDR imsg with wrong len");
|
fatalx("NEWADDR imsg with wrong len");
|
||||||
|
|
||||||
if_addr_add(imsg.data);
|
if_addr_add(imsg.data);
|
||||||
break;
|
break;
|
||||||
case IMSG_DELADDR:
|
case IMSG_DELADDR:
|
||||||
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct kaddr))
|
||||||
sizeof(struct kaddr))
|
|
||||||
fatalx("DELADDR imsg with wrong len");
|
fatalx("DELADDR imsg with wrong len");
|
||||||
|
|
||||||
if_addr_del(imsg.data);
|
if_addr_del(imsg.data);
|
||||||
|
@ -369,8 +365,7 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
iev_lde->ev_write = NULL;
|
iev_lde->ev_write = NULL;
|
||||||
break;
|
break;
|
||||||
case IMSG_INIT:
|
case IMSG_INIT:
|
||||||
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct ldpd_init))
|
||||||
sizeof(struct ldpd_init))
|
|
||||||
fatalx("INIT imsg with wrong len");
|
fatalx("INIT imsg with wrong len");
|
||||||
|
|
||||||
memcpy(&init, imsg.data, sizeof(init));
|
memcpy(&init, imsg.data, sizeof(init));
|
||||||
|
@ -398,14 +393,11 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
disc_socket = -1;
|
disc_socket = -1;
|
||||||
edisc_socket = -1;
|
edisc_socket = -1;
|
||||||
session_socket = -1;
|
session_socket = -1;
|
||||||
if ((ldp_af_conf_get(leconf, af))->flags &
|
if (CHECK_FLAG((ldp_af_conf_get(leconf, af))->flags, F_LDPD_AF_ENABLED))
|
||||||
F_LDPD_AF_ENABLED)
|
ldpe_imsg_compose_parent(IMSG_REQUEST_SOCKETS, af, NULL, 0);
|
||||||
ldpe_imsg_compose_parent(IMSG_REQUEST_SOCKETS,
|
|
||||||
af, NULL, 0);
|
|
||||||
break;
|
break;
|
||||||
case IMSG_SOCKET_NET:
|
case IMSG_SOCKET_NET:
|
||||||
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(enum socket_type))
|
||||||
sizeof(enum socket_type))
|
|
||||||
fatalx("SOCKET_NET imsg with wrong len");
|
fatalx("SOCKET_NET imsg with wrong len");
|
||||||
socket_type = imsg.data;
|
socket_type = imsg.data;
|
||||||
|
|
||||||
|
@ -434,15 +426,13 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ldpe_setup_sockets(af, disc_socket, edisc_socket,
|
ldpe_setup_sockets(af, disc_socket, edisc_socket, session_socket);
|
||||||
session_socket);
|
|
||||||
if_update_all(af);
|
if_update_all(af);
|
||||||
tnbr_update_all(af);
|
tnbr_update_all(af);
|
||||||
RB_FOREACH(nbr, nbr_id_head, &nbrs_by_id) {
|
RB_FOREACH(nbr, nbr_id_head, &nbrs_by_id) {
|
||||||
if (nbr->af != af)
|
if (nbr->af != af)
|
||||||
continue;
|
continue;
|
||||||
nbr->laddr = (ldp_af_conf_get(leconf,
|
nbr->laddr = (ldp_af_conf_get(leconf, af))->trans_addr;
|
||||||
af))->trans_addr;
|
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
nbrp = nbr_params_find(leconf, nbr->id);
|
nbrp = nbr_params_find(leconf, nbr->id);
|
||||||
if (nbrp) {
|
if (nbrp) {
|
||||||
|
@ -456,8 +446,7 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IMSG_RTRID_UPDATE:
|
case IMSG_RTRID_UPDATE:
|
||||||
memcpy(&global.rtr_id, imsg.data,
|
memcpy(&global.rtr_id, imsg.data, sizeof(global.rtr_id));
|
||||||
sizeof(global.rtr_id));
|
|
||||||
if (leconf->rtr_id.s_addr == INADDR_ANY) {
|
if (leconf->rtr_id.s_addr == INADDR_ANY) {
|
||||||
ldpe_reset_nbrs(AF_UNSPEC);
|
ldpe_reset_nbrs(AF_UNSPEC);
|
||||||
}
|
}
|
||||||
|
@ -465,8 +454,7 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
tnbr_update_all(AF_UNSPEC);
|
tnbr_update_all(AF_UNSPEC);
|
||||||
break;
|
break;
|
||||||
case IMSG_RECONF_CONF:
|
case IMSG_RECONF_CONF:
|
||||||
if ((nconf = malloc(sizeof(struct ldpd_conf))) ==
|
if ((nconf = malloc(sizeof(struct ldpd_conf))) == NULL)
|
||||||
NULL)
|
|
||||||
fatal(NULL);
|
fatal(NULL);
|
||||||
memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
|
memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
|
||||||
|
|
||||||
|
@ -546,16 +534,13 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
memcpy(&ldp_debug, imsg.data, sizeof(ldp_debug));
|
memcpy(&ldp_debug, imsg.data, sizeof(ldp_debug));
|
||||||
break;
|
break;
|
||||||
case IMSG_FILTER_UPDATE:
|
case IMSG_FILTER_UPDATE:
|
||||||
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct ldp_access)) {
|
||||||
sizeof(struct ldp_access)) {
|
|
||||||
log_warnx("%s: wrong imsg len", __func__);
|
log_warnx("%s: wrong imsg len", __func__);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
laccess = imsg.data;
|
laccess = imsg.data;
|
||||||
ldpe_check_filter_af(AF_INET, &leconf->ipv4,
|
ldpe_check_filter_af(AF_INET, &leconf->ipv4, laccess->name);
|
||||||
laccess->name);
|
ldpe_check_filter_af(AF_INET6, &leconf->ipv6, laccess->name);
|
||||||
ldpe_check_filter_af(AF_INET6, &leconf->ipv6,
|
|
||||||
laccess->name);
|
|
||||||
break;
|
break;
|
||||||
case IMSG_LDP_SYNC_IF_STATE_REQUEST:
|
case IMSG_LDP_SYNC_IF_STATE_REQUEST:
|
||||||
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
if (imsg.hdr.len != IMSG_HEADER_SIZE +
|
||||||
|
@ -605,8 +590,7 @@ static void ldpe_dispatch_main(struct event *thread)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_debug("%s: error handling imsg %d",
|
log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type);
|
||||||
__func__, imsg.hdr.type);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
|
@ -650,8 +634,7 @@ static void ldpe_dispatch_lde(struct event *thread)
|
||||||
case IMSG_RELEASE_ADD:
|
case IMSG_RELEASE_ADD:
|
||||||
case IMSG_REQUEST_ADD:
|
case IMSG_REQUEST_ADD:
|
||||||
case IMSG_WITHDRAW_ADD:
|
case IMSG_WITHDRAW_ADD:
|
||||||
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
|
if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(struct map))
|
||||||
sizeof(struct map))
|
|
||||||
fatalx("invalid size of map request");
|
fatalx("invalid size of map request");
|
||||||
map = imsg.data;
|
map = imsg.data;
|
||||||
|
|
||||||
|
@ -706,8 +689,7 @@ static void ldpe_dispatch_lde(struct event *thread)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IMSG_NOTIFICATION_SEND:
|
case IMSG_NOTIFICATION_SEND:
|
||||||
if (imsg.hdr.len - IMSG_HEADER_SIZE !=
|
if (imsg.hdr.len - IMSG_HEADER_SIZE != sizeof(struct notify_msg))
|
||||||
sizeof(struct notify_msg))
|
|
||||||
fatalx("invalid size of OE request");
|
fatalx("invalid size of OE request");
|
||||||
nm = imsg.data;
|
nm = imsg.data;
|
||||||
|
|
||||||
|
@ -741,8 +723,7 @@ static void ldpe_dispatch_lde(struct event *thread)
|
||||||
session_shutdown(nbr,S_SHUTDOWN,0,0);
|
session_shutdown(nbr,S_SHUTDOWN,0,0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
log_debug("%s: error handling imsg %d",
|
log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type);
|
||||||
__func__, imsg.hdr.type);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
imsg_free(&imsg);
|
imsg_free(&imsg);
|
||||||
|
@ -860,7 +841,7 @@ ldpe_remove_dynamic_tnbrs(int af)
|
||||||
if (tnbr->af != af)
|
if (tnbr->af != af)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tnbr->flags &= ~F_TNBR_DYNAMIC;
|
UNSET_FLAG(tnbr->flags, F_TNBR_DYNAMIC);
|
||||||
tnbr_check(leconf, tnbr);
|
tnbr_check(leconf, tnbr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue