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

Method decodeType_Generic

Server/src/bgp/ExtCommunity.cpp:465–567  ·  view source on GitHub ↗

* Decode Generic subtypes * * \details * Converts to human readable form. * * \param [in] ec_hdr Reference to the extended community header * \param [in] isGlobal4Bytes True if the global admin field is 4 bytes, false if 2 * \param [in] isGlobalIPv4 True if the global admin field is an IPv4 address, false if not * * \return Deco

Source from the content-addressed store, hash-verified

463 * \return Decoded string value
464 */
465 std::string ExtCommunity::decodeType_Generic(const extcomm_hdr &ec_hdr, bool isGlobal4Bytes, bool isGlobalIPv4) {
466 std::stringstream val_ss;
467 uint16_t val_16b;
468 uint32_t val_32b;
469 char ipv4_char[16] = {0};
470
471 /*
472 * Decode values based on bit size
473 */
474 if (isGlobal4Bytes) {
475 // Four-byte global field
476 memcpy(&val_32b, ec_hdr.value, 4);
477 memcpy(&val_16b, ec_hdr.value + 4, 2);
478
479 bgp::SWAP_BYTES(&val_16b);
480
481 if (isGlobalIPv4) {
482 inet_ntop(AF_INET, &val_32b, ipv4_char, sizeof(ipv4_char));
483 } else
484 bgp::SWAP_BYTES(&val_32b);
485
486 } else {
487 // Two-byte global field
488 memcpy(&val_16b, ec_hdr.value, 2);
489 memcpy(&val_32b, ec_hdr.value + 2, 4);
490
491 // Chagne to host order
492 bgp::SWAP_BYTES(&val_16b);
493 bgp::SWAP_BYTES(&val_32b);
494 }
495
496 switch (ec_hdr.low_type) {
497 case EXT_GENERIC_OSPF_ROUTE_TYPE : // deprecated
498 case EXT_GENERIC_OSPF_ROUTER_ID : // deprecated
499 case EXT_GENERIC_OSPF_DOM_ID : // deprecated
500 LOG_INFO("%s: Ignoring deprecated extended community %d/%d", peer_addr.c_str(),
501 ec_hdr.high_type, ec_hdr.low_type);
502 break;
503
504 case EXT_GENERIC_LAYER2_INFO : { // rfc4761
505 u_char encap_type = ec_hdr.value[0];
506 u_char ctrl_flags = ec_hdr.value[1];
507 memcpy(&val_16b, ec_hdr.value + 2, 2); // Layer 2 MTU
508 bgp::SWAP_BYTES(&val_16b);
509
510 val_ss << "l2info=";
511
512 switch (encap_type) {
513 case 19 : // VPLS
514 val_ss << "vpls:";
515 break;
516
517 default:
518 val_ss << (int) encap_type << ":";
519 break;
520 }
521
522 val_ss << ctrl_flags << ":mtu:" << val_16b;

Callers

nothing calls this directly

Calls 1

SWAP_BYTESFunction · 0.85

Tested by

no test coverage detected