MCPcopy Create free account
hub / github.com/SNAS/openbmp / handleInitMsg

Method handleInitMsg

Server/src/bmp/parseBMP.cpp:838–920  ·  view source on GitHub ↗

* handle the initiation message and update the router entry * * \param [in] sock Socket to read the init message from * \param [in/out] r_entry Already defined router entry reference (will be updated) */

Source from the content-addressed store, hash-verified

836 * \param [in/out] r_entry Already defined router entry reference (will be updated)
837 */
838void parseBMP::handleInitMsg(int sock, MsgBusInterface::obj_router &r_entry) {
839 info_tlv_msg info;
840 char infoBuf[sizeof(r_entry.initiate_data)];
841 int infoLen;
842 r_entry.hash_type=0;
843
844 // Buffer the init message for parsing
845 bufferBMPMessage(sock);
846
847 u_char *bufPtr = bmp_data;
848
849 /*
850 * Loop through the init message (in buffer) to parse each TLV
851 */
852 for (int i=0; i < bmp_data_len; i += BMP_INFO_TLV_HDR_LEN) {
853 memcpy(&info, bufPtr, BMP_INFO_TLV_HDR_LEN);
854 info.info = NULL;
855 bgp::SWAP_BYTES(&info.len);
856 bgp::SWAP_BYTES(&info.type);
857
858 bufPtr += BMP_INFO_TLV_HDR_LEN; // Move pointer past the info header
859
860 // TODO: Change to SELF_DEBUG after IOS supports INIT messages correctly
861 LOG_INFO("Init message type %hu and length %hu parsed", info.type, info.len);
862
863 if (info.len > 0) {
864 infoLen = sizeof(infoBuf) < info.len ? sizeof(infoBuf) : info.len;
865 bzero(infoBuf, sizeof(infoBuf));
866 memcpy(infoBuf, bufPtr, infoLen);
867 bufPtr += infoLen; // Move pointer past the info data
868 i += infoLen; // Update the counter past the info data
869
870 info.info = infoBuf;
871
872 }
873 else {
874 // ignore info lengths of zero
875 continue;
876 }
877
878 /*
879 * Save the data based on info type
880 */
881 switch (info.type) {
882 case INIT_TYPE_FREE_FORM_STRING :
883 infoLen = sizeof(r_entry.initiate_data) < (info.len - 1) ? (sizeof(r_entry.initiate_data) - 1) : info.len;
884 memcpy(r_entry.initiate_data, info.info, infoLen);
885 LOG_INFO("Init message type %hu = %s", info.type, r_entry.initiate_data);
886
887 break;
888
889 case INIT_TYPE_SYSNAME :
890 infoLen = sizeof(r_entry.name) < (info.len - 1) ? (sizeof(r_entry.name) - 1) : info.len;
891 strncpy((char *)r_entry.name, info.info, infoLen);
892 LOG_INFO("Init message type %hu = %s", info.type, r_entry.name);
893
894 if(r_entry.hash_type<2) //Here we will check if bgp_id is not received, then we will update the hash_type
895 r_entry.hash_type=1;

Callers 1

ReadIncomingMsgMethod · 0.80

Calls 1

SWAP_BYTESFunction · 0.85

Tested by

no test coverage detected