From 4adc415e993e7e673fd62b29e3d6d7e2560b3b47 Mon Sep 17 00:00:00 2001 From: sri-mohan1 Date: Sat, 20 Aug 2022 11:24:29 +0530 Subject: [PATCH] ospfd: changes for code maintainability these changes are for improving the code maintainability Signed-off-by: sri-mohan1 --- ospfd/ospf_apiserver.c | 175 +++++++++++++++++------------------------ 1 file changed, 74 insertions(+), 101 deletions(-) diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index b8567830b1..f5ed77dab5 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -378,7 +378,7 @@ void ospf_apiserver_read(struct thread *thread) apiserv->t_sync_read = NULL; if (IS_DEBUG_OSPF_EVENT) - zlog_debug("API: ospf_apiserver_read: Peer: %pI4/%u", + zlog_debug("API: %s: Peer: %pI4/%u", __func__, &apiserv->peer_sync.sin_addr, ntohs(apiserv->peer_sync.sin_port)); } @@ -388,13 +388,13 @@ void ospf_apiserver_read(struct thread *thread) apiserv->t_async_read = NULL; if (IS_DEBUG_OSPF_EVENT) - zlog_debug("API: ospf_apiserver_read: Peer: %pI4/%u", + zlog_debug("API: %s: Peer: %pI4/%u", __func__, &apiserv->peer_async.sin_addr, ntohs(apiserv->peer_async.sin_port)); } #endif /* USE_ASYNC_READ */ else { - zlog_warn("ospf_apiserver_read: Unknown fd(%d)", fd); + zlog_warn("%s: Unknown fd(%d)", __func__, fd); ospf_apiserver_free(apiserv); return; } @@ -402,9 +402,8 @@ void ospf_apiserver_read(struct thread *thread) /* Read message from fd. */ msg = msg_read(fd); if (msg == NULL) { - zlog_warn( - "ospf_apiserver_read: read failed on fd=%d, closing connection", - fd); + zlog_warn("%s: read failed on fd=%d, closing connection", + __func__, fd); /* Perform cleanup. */ ospf_apiserver_free(apiserv); @@ -438,20 +437,19 @@ void ospf_apiserver_sync_write(struct thread *thread) /* Sanity check */ if (fd != apiserv->fd_sync) { - zlog_warn("ospf_apiserver_sync_write: Unknown fd=%d", fd); + zlog_warn("%s: Unknown fd=%d", __func__, fd); goto out; } if (IS_DEBUG_OSPF_EVENT) - zlog_debug("API: ospf_apiserver_sync_write: Peer: %pI4/%u", + zlog_debug("API: %s: Peer: %pI4/%u", __func__, &apiserv->peer_sync.sin_addr, ntohs(apiserv->peer_sync.sin_port)); /* Check whether there is really a message in the fifo. */ msg = msg_fifo_pop(apiserv->out_sync_fifo); if (!msg) { - zlog_warn( - "API: ospf_apiserver_sync_write: No message in Sync-FIFO?"); + zlog_warn("API: %s: No message in Sync-FIFO?", __func__); return; } @@ -464,8 +462,7 @@ void ospf_apiserver_sync_write(struct thread *thread) msg_free(msg); if (rc < 0) { - zlog_warn("ospf_apiserver_sync_write: write failed on fd=%d", - fd); + zlog_warn("%s: write failed on fd=%d", __func__, fd); goto out; } @@ -500,20 +497,19 @@ void ospf_apiserver_async_write(struct thread *thread) /* Sanity check */ if (fd != apiserv->fd_async) { - zlog_warn("ospf_apiserver_async_write: Unknown fd=%d", fd); + zlog_warn("%s: Unknown fd=%d", __func__, fd); goto out; } if (IS_DEBUG_OSPF_EVENT) - zlog_debug("API: ospf_apiserver_async_write: Peer: %pI4/%u", + zlog_debug("API: %s: Peer: %pI4/%u", __func__, &apiserv->peer_async.sin_addr, ntohs(apiserv->peer_async.sin_port)); /* Check whether there is really a message in the fifo. */ msg = msg_fifo_pop(apiserv->out_async_fifo); if (!msg) { - zlog_warn( - "API: ospf_apiserver_async_write: No message in Async-FIFO?"); + zlog_warn("API: %s: No message in Async-FIFO?", __func__); return; } @@ -526,8 +522,7 @@ void ospf_apiserver_async_write(struct thread *thread) msg_free(msg); if (rc < 0) { - zlog_warn("ospf_apiserver_async_write: write failed on fd=%d", - fd); + zlog_warn("%s: write failed on fd=%d", __func__, fd); goto out; } @@ -575,8 +570,7 @@ int ospf_apiserver_serv_sock_family(unsigned short port, int family) /* Listen socket under queue length 3. */ rc = listen(accept_sock, 3); if (rc < 0) { - zlog_warn("ospf_apiserver_serv_sock_family: listen: %s", - safe_strerror(errno)); + zlog_warn("%s: listen: %s", __func__, safe_strerror(errno)); close(accept_sock); /* Close socket */ return rc; } @@ -608,8 +602,7 @@ void ospf_apiserver_accept(struct thread *thread) /* Accept connection for synchronous messages */ new_sync_sock = sockunion_accept(accept_sock, &su); if (new_sync_sock < 0) { - zlog_warn("ospf_apiserver_accept: accept: %s", - safe_strerror(errno)); + zlog_warn("%s: accept: %s", __func__, safe_strerror(errno)); return; } @@ -622,16 +615,15 @@ void ospf_apiserver_accept(struct thread *thread) ret = getpeername(new_sync_sock, (struct sockaddr *)&peer_sync, &peerlen); if (ret < 0) { - zlog_warn("ospf_apiserver_accept: getpeername: %s", + zlog_warn("%s: getpeername: %s", __func__, safe_strerror(errno)); close(new_sync_sock); return; } if (IS_DEBUG_OSPF_EVENT) - zlog_debug("API: ospf_apiserver_accept: New peer: %pI4/%u", - &peer_sync.sin_addr, - ntohs(peer_sync.sin_port)); + zlog_debug("API: %s: New peer: %pI4/%u", __func__, + &peer_sync.sin_addr, ntohs(peer_sync.sin_port)); /* Create new socket for asynchronous messages. */ peer_async = peer_sync; @@ -640,18 +632,16 @@ void ospf_apiserver_accept(struct thread *thread) /* Check if remote port number to make reverse connection is valid one. */ if (ntohs(peer_async.sin_port) == ospf_apiserver_getport()) { - zlog_warn( - "API: ospf_apiserver_accept: Peer(%pI4/%u): Invalid async port number?", - &peer_async.sin_addr, - ntohs(peer_async.sin_port)); + zlog_warn("API: %s: Peer(%pI4/%u): Invalid async port number?", + __func__, &peer_async.sin_addr, + ntohs(peer_async.sin_port)); close(new_sync_sock); return; } new_async_sock = socket(AF_INET, SOCK_STREAM, 0); if (new_async_sock < 0) { - zlog_warn("ospf_apiserver_accept: socket: %s", - safe_strerror(errno)); + zlog_warn("%s: socket: %s", __func__, safe_strerror(errno)); close(new_sync_sock); return; } @@ -660,8 +650,7 @@ void ospf_apiserver_accept(struct thread *thread) sizeof(struct sockaddr_in)); if (ret < 0) { - zlog_warn("ospf_apiserver_accept: connect: %s", - safe_strerror(errno)); + zlog_warn("%s: connect: %s", __func__, safe_strerror(errno)); close(new_sync_sock); close(new_async_sock); return; @@ -672,8 +661,7 @@ void ospf_apiserver_accept(struct thread *thread) /* Make the asynchronous channel write-only. */ ret = shutdown(new_async_sock, SHUT_RD); if (ret < 0) { - zlog_warn("ospf_apiserver_accept: shutdown: %s", - safe_strerror(errno)); + zlog_warn("%s: shutdown: %s", __func__, safe_strerror(errno)); close(new_sync_sock); close(new_async_sock); return; @@ -734,7 +722,7 @@ static int ospf_apiserver_send_msg(struct ospf_apiserver *apiserv, event = OSPF_APISERVER_ASYNC_WRITE; break; default: - zlog_warn("ospf_apiserver_send_msg: Unknown message type %d", + zlog_warn("%s: Unknown message type %d", __func__, msg->hdr.msgtype); return -1; } @@ -759,7 +747,7 @@ int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, uint32_t seqnr, int ret; if (!msg) { - zlog_warn("ospf_apiserver_send_reply: msg_new failed"); + zlog_warn("%s: msg_new failed", __func__); #ifdef NOTYET /* Cannot allocate new message. What should we do? */ ospf_apiserver_free(apiserv); @@ -815,7 +803,7 @@ int ospf_apiserver_handle_msg(struct ospf_apiserver *apiserv, struct msg *msg) rc = ospf_apiserver_handle_sync_router_id(apiserv, msg); break; default: - zlog_warn("ospf_apiserver_handle_msg: Unknown message type: %d", + zlog_warn("%s: Unknown message type: %d", __func__, msg->hdr.msgtype); rc = -1; } @@ -846,8 +834,7 @@ int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserv, originator_func = ospf_apiserver_lsa11_originator; break; default: - zlog_warn("ospf_apiserver_register_opaque_type: lsa_type(%d)", - lsa_type); + zlog_warn("%s: lsa_type(%d)", __func__, lsa_type); return OSPF_API_ILLEGALLSATYPE; } @@ -1018,8 +1005,8 @@ void ospf_apiserver_notify_ready_type9(struct ospf_apiserver *apiserv) 0, OSPF_OPAQUE_LINK_LSA, r->opaque_type, oi->address->u.prefix4); if (!msg) { - zlog_warn( - "apiserver_notify_ready_type9: msg_new failed"); + zlog_warn("%s: msg_new failed", + __func__); #ifdef NOTYET /* Cannot allocate new message. What * should we do? */ @@ -1067,8 +1054,8 @@ void ospf_apiserver_notify_ready_type10(struct ospf_apiserver *apiserv) 0, OSPF_OPAQUE_AREA_LSA, r->opaque_type, area->area_id); if (!msg) { - zlog_warn( - "apiserver_notify_ready_type10: msg_new failed"); + zlog_warn("%s: msg_new failed", + __func__); #ifdef NOTYET /* Cannot allocate new message. What * should we do? */ @@ -1110,8 +1097,7 @@ void ospf_apiserver_notify_ready_type11(struct ospf_apiserver *apiserv) r->opaque_type, noarea_id); if (!msg) { - zlog_warn( - "apiserver_notify_ready_type11: msg_new failed"); + zlog_warn("%s: msg_new failed", __func__); #ifdef NOTYET /* Cannot allocate new message. What should we * do? */ @@ -1234,8 +1220,7 @@ static int apiserver_sync_callback(struct ospf_lsa *lsa, void *p_arg, MSG_LSA_UPDATE_NOTIFY, seqnum, ifaddr, area_id, lsa->flags & OSPF_LSA_SELF, lsa->data); if (!msg) { - zlog_warn( - "apiserver_sync_callback: new_msg_update failed"); + zlog_warn("%s: new_msg_update failed", __func__); #ifdef NOTYET /* Cannot allocate new message. What should we do? */ /* ospf_apiserver_free (apiserv);*/ /* Do nothing @@ -1534,7 +1519,7 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, /* Create a stream for internal opaque LSA */ if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { - zlog_warn("ospf_apiserver_opaque_lsa_new: stream_new failed"); + zlog_warn("%s: stream_new failed", __func__); return NULL; } @@ -1627,7 +1612,7 @@ int ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv, case OSPF_OPAQUE_LINK_LSA: oi = ospf_apiserver_if_lookup_by_addr(omsg->ifaddr); if (!oi) { - zlog_warn("apiserver_originate: unknown interface %pI4", + zlog_warn("%s: unknown interface %pI4", __func__, &omsg->ifaddr); rc = OSPF_API_NOSUCHINTERFACE; goto out; @@ -1638,7 +1623,7 @@ int ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv, case OSPF_OPAQUE_AREA_LSA: area = ospf_area_lookup_by_area_id(ospf, omsg->area_id); if (!area) { - zlog_warn("apiserver_originate: unknown area %pI4", + zlog_warn("%s: unknown area %pI4", __func__, &omsg->area_id); rc = OSPF_API_NOSUCHAREA; goto out; @@ -1650,9 +1635,8 @@ int ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv, break; default: /* We can only handle opaque types here */ - zlog_warn( - "apiserver_originate: Cannot originate non-opaque LSA type %d", - data->type); + zlog_warn("%s: Cannot originate non-opaque LSA type %d", + __func__, data->type); rc = OSPF_API_ILLEGALLSATYPE; goto out; } @@ -1663,9 +1647,8 @@ int ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv, if (!apiserver_is_opaque_type_registered(apiserv, lsa_type, opaque_type)) { - zlog_warn( - "apiserver_originate: LSA-type(%d)/Opaque-type(%d): Not registered", - lsa_type, opaque_type); + zlog_warn("%s: LSA-type(%d)/Opaque-type(%d): Not registered", + __func__, lsa_type, opaque_type); rc = OSPF_API_OPAQUETYPENOTREGISTERED; goto out; } @@ -1785,9 +1768,8 @@ int ospf_apiserver_originate1(struct ospf_lsa *lsa, struct ospf_lsa *old) */ assert(!ospf_opaque_is_owned(old)); if (IS_LSA_MAX_SEQ(old)) { - flog_warn( - EC_OSPF_LSA_INSTALL_FAILURE, - "ospf_apiserver_originate1: old LSA at maxseq"); + flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, + "%s: old LSA at maxseq", __func__); return -1; } lsa->data->ls_seqnum = lsa_seqnum_increment(old); @@ -1869,9 +1851,8 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa) apiserv = lookup_apiserver_by_lsa(lsa); if (!apiserv) { - zlog_warn( - "ospf_apiserver_lsa_refresher: LSA[%s]: No apiserver?", - dump_lsa_key(lsa)); + zlog_warn("%s: LSA[%s]: No apiserver?", __func__, + dump_lsa_key(lsa)); lsa->data->ls_age = htons(OSPF_LSA_MAXAGE); /* Flush it anyway. */ goto out; @@ -1889,8 +1870,7 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa) new = ospf_apiserver_opaque_lsa_new(lsa->area, lsa->oi, lsa->data); if (!new) { - zlog_warn( - "ospf_apiserver_lsa_refresher: Cannot create a new LSA?"); + zlog_warn("%s: Cannot create a new LSA?", __func__); goto out; } } else { @@ -1908,9 +1888,8 @@ struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa) /* Install LSA into LSDB. */ if (ospf_lsa_install(ospf, new->oi, new) == NULL) { - flog_warn( - EC_OSPF_LSA_INSTALL_FAILURE, - "ospf_apiserver_lsa_refresher: ospf_lsa_install failed"); + flog_warn(EC_OSPF_LSA_INSTALL_FAILURE, + "%s: ospf_lsa_install failed", __func__); ospf_lsa_unlock(&new); goto out; } @@ -1962,7 +1941,7 @@ int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv, case OSPF_OPAQUE_AREA_LSA: area = ospf_area_lookup_by_area_id(ospf, dmsg->area_id); if (!area) { - zlog_warn("ospf_apiserver_lsa_delete: unknown area %pI4", + zlog_warn("%s: unknown area %pI4", __func__, &dmsg->area_id); rc = OSPF_API_NOSUCHAREA; goto out; @@ -1973,9 +1952,8 @@ int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv, area = NULL; break; default: - zlog_warn( - "ospf_apiserver_lsa_delete: Cannot delete non-opaque LSA type %d", - dmsg->lsa_type); + zlog_warn("%s: Cannot delete non-opaque LSA type %d", __func__, + dmsg->lsa_type); rc = OSPF_API_ILLEGALLSATYPE; goto out; } @@ -1986,9 +1964,8 @@ int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv, if (!apiserver_is_opaque_type_registered(apiserv, lsa_type, opaque_type)) { - zlog_warn( - "ospf_apiserver_lsa_delete: LSA-type(%d)/Opaque-type(%d): Not registered", - lsa_type, opaque_type); + zlog_warn("%s: LSA-type(%d)/Opaque-type(%d): Not registered", + __func__, lsa_type, opaque_type); rc = OSPF_API_OPAQUETYPENOTREGISTERED; goto out; } @@ -2004,9 +1981,8 @@ int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv, */ old = ospf_lsa_lookup(ospf, area, dmsg->lsa_type, id, ospf->router_id); if (!old) { - zlog_warn( - "ospf_apiserver_lsa_delete: LSA[Type%d:%pI4] not in LSDB", - dmsg->lsa_type, &id); + zlog_warn("%s: LSA[Type%d:%pI4] not in LSDB", __func__, + dmsg->lsa_type, &id); rc = OSPF_API_NOSUCHLSA; goto out; } @@ -2114,7 +2090,7 @@ int ospf_apiserver_new_if(struct interface *ifp) if (ifp->name[0] == '\0') { /* interface has empty name */ - zlog_warn("ospf_apiserver_new_if: interface has no name?"); + zlog_warn("%s: interface has no name?", __func__); return 0; } @@ -2125,7 +2101,7 @@ int ospf_apiserver_new_if(struct interface *ifp) if (ifp->name[0] == '\0') { /* interface has empty name */ - zlog_warn("ospf_apiserver_new_if: interface has no name?"); + zlog_warn("%s: interface has no name?", __func__); return 0; } @@ -2134,9 +2110,8 @@ int ospf_apiserver_new_if(struct interface *ifp) if (!oi) { /* This interface is known to Zebra but not to OSPF daemon yet. */ - zlog_warn( - "ospf_apiserver_new_if: interface %s not known to OSPFd?", - ifp->name); + zlog_warn("%s: interface %s not known to OSPFd?", __func__, + ifp->name); return 0; } @@ -2154,9 +2129,8 @@ int ospf_apiserver_del_if(struct interface *ifp) struct ospf_interface *oi; /* zlog_warn for debugging */ - zlog_warn("ospf_apiserver_del_if"); - zlog_warn("ifp name=%s status=%d index=%d", ifp->name, ifp->status, - ifp->ifindex); + zlog_warn("%s ifp name=%s status=%d index=%d", __func__, ifp->name, + ifp->status, ifp->ifindex); oi = ospf_apiserver_if_lookup_by_ifp(ifp); @@ -2179,20 +2153,19 @@ void ospf_apiserver_ism_change(struct ospf_interface *oi, int old_state) /* Tell clients about interface change */ /* zlog_warn for debugging */ - zlog_warn("ospf_apiserver_ism_change"); + zlog_warn("%s", __func__); if (listcount(apiserver_list) > 0) { ospf_apiserver_clients_notify_ism_change(oi); } - zlog_warn("oi->ifp->name=%s", oi->ifp->name); - zlog_warn("old_state=%d", old_state); - zlog_warn("oi->state=%d", oi->state); + zlog_warn("%s oi->ifp->name=%s old_state=%d oi->state=%d", __func__, + oi->ifp->name, old_state, oi->state); } void ospf_apiserver_nsm_change(struct ospf_neighbor *nbr, int old_status) { /* Neighbor status changed, tell clients about it */ - zlog_warn("ospf_apiserver_nsm_change"); + zlog_warn("%s", __func__); if (listcount(apiserver_list) > 0) { ospf_apiserver_clients_notify_nsm_change(nbr); } @@ -2300,7 +2273,8 @@ void ospf_apiserver_clients_notify_ready_type9(struct ospf_interface *oi) oi->address->u.prefix4); if (!msg) { zlog_warn( - "ospf_apiserver_clients_notify_ready_type9: new_msg_ready_notify failed"); + "%s: new_msg_ready_notify failed", + __func__); #ifdef NOTYET /* Cannot allocate new message. What * should we do? */ @@ -2344,7 +2318,8 @@ void ospf_apiserver_clients_notify_ready_type10(struct ospf_area *area) area->area_id); if (!msg) { zlog_warn( - "ospf_apiserver_clients_notify_ready_type10: new_msg_ready_nofity failed"); + "%s: new_msg_ready_nofity failed", + __func__); #ifdef NOTYET /* Cannot allocate new message. What * should we do? */ @@ -2390,7 +2365,8 @@ void ospf_apiserver_clients_notify_ready_type11(struct ospf *top) id_null); if (!msg) { zlog_warn( - "ospf_apiserver_clients_notify_ready_type11: new_msg_ready_notify failed"); + "%s: new_msg_ready_notify failed", + __func__); #ifdef NOTYET /* Cannot allocate new message. What * should we do? */ @@ -2449,8 +2425,7 @@ void ospf_apiserver_clients_notify_ism_change(struct ospf_interface *oi) msg = new_msg_ism_change(0, ifaddr, area_id, oi->state); if (!msg) { - zlog_warn( - "apiserver_clients_notify_ism_change: msg_new failed"); + zlog_warn("%s: msg_new failed", __func__); return; } @@ -2473,8 +2448,7 @@ void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr) msg = new_msg_nsm_change(0, ifaddr, nbraddr, nbr->router_id, nbr->state); if (!msg) { - zlog_warn( - "apiserver_clients_notify_nsm_change: msg_new failed"); + zlog_warn("%s: msg_new failed", __func__); return; } @@ -2509,8 +2483,7 @@ static int apiserver_clients_lsa_change_notify(uint8_t msgtype, ifaddr, area_id, lsa->flags & OSPF_LSA_SELF, lsa->data); if (!msg) { - zlog_warn( - "apiserver_clients_lsa_change_notify: msg_new failed"); + zlog_warn("%s: msg_new failed", __func__); return -1; } -- 2.39.5