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

Method parsePeerHdr

Server/src/bmp/parseBMP.cpp:414–517  ·  view source on GitHub ↗

* Parse the v3 peer header * * \param [in] sock Socket to read the message from */

Source from the content-addressed store, hash-verified

412 * \param [in] sock Socket to read the message from
413 */
414void parseBMP::parsePeerHdr(int sock) {
415 peer_hdr_v3 p_hdr = {0};
416 int i;
417
418 bzero(&p_hdr, sizeof(p_hdr));
419
420 if ((i = Recv(sock, &p_hdr, BMP_PEER_HDR_LEN, MSG_WAITALL))
421 != BMP_PEER_HDR_LEN) {
422 LOG_ERR("sock=%d: Couldn't read all bytes, read %d bytes",
423 sock, i);
424 }
425
426 // Adjust the common header length to remove the peer header (as it's been read)
427 bmp_len -= BMP_PEER_HDR_LEN;
428
429 SELF_DEBUG("parsePeerHdr: sock=%d : Peer Type is %d", sock,
430 p_hdr.peer_type);
431
432 parsePeerFlags(p_hdr.peer_type, p_hdr.peer_flags);
433
434 if (p_entry->isIPv4) {
435 snprintf(peer_addr, sizeof(peer_addr), "%d.%d.%d.%d",
436 p_hdr.peer_addr[12], p_hdr.peer_addr[13], p_hdr.peer_addr[14],
437 p_hdr.peer_addr[15]);
438 SELF_DEBUG("sock=%d : Peer address is IPv4 %s", sock,
439 peer_addr);
440
441 }
442 else {
443 inet_ntop(AF_INET6, p_hdr.peer_addr, peer_addr, sizeof(peer_addr));
444
445 SELF_DEBUG("sock=%d : Peer address is IPv6 %s", sock,
446 peer_addr);
447 }
448
449
450 // convert the BMP byte messages to human readable strings
451 snprintf(peer_as, sizeof(peer_as), "0x%04x%04x",
452 p_hdr.peer_as[0] << 8 | p_hdr.peer_as[1],
453 p_hdr.peer_as[2] << 8 | p_hdr.peer_as[3]);
454
455 inet_ntop(AF_INET, p_hdr.peer_bgp_id, peer_bgp_id, sizeof(peer_bgp_id));
456 SELF_DEBUG("sock=%d : Peer BGP-ID %x.%x.%x.%x (%s)", sock, p_hdr.peer_bgp_id[0],
457 p_hdr.peer_bgp_id[1],p_hdr.peer_bgp_id[2],p_hdr.peer_bgp_id[3], peer_bgp_id);
458
459 // Format based on the type of RD
460 SELF_DEBUG("sock=%d : Peer RD type = %d %d", sock, p_hdr.peer_dist_id[0], p_hdr.peer_dist_id[1]);
461 switch (p_hdr.peer_dist_id[1]) {
462 case 1: // admin = 4bytes (IP address), assign number = 2bytes
463 snprintf(peer_rd, sizeof(peer_rd), "%d.%d.%d.%d:%d",
464 p_hdr.peer_dist_id[2], p_hdr.peer_dist_id[3],
465 p_hdr.peer_dist_id[4], p_hdr.peer_dist_id[5],
466 p_hdr.peer_dist_id[6] << 8 | p_hdr.peer_dist_id[7]);
467 break;
468
469 case 2: // admin = 4bytes (ASN), sub field 2bytes
470 snprintf(peer_rd, sizeof(peer_rd), "%lu:%d",
471 (unsigned long) (p_hdr.peer_dist_id[2] << 24

Callers

nothing calls this directly

Calls 1

SWAP_BYTESFunction · 0.85

Tested by

no test coverage detected