| 723 | } |
| 724 | |
| 725 | uint32_t CNetAddr::GetMappedAS(const std::vector<bool> &asmap) const { |
| 726 | uint32_t net_class = GetNetClass(); |
| 727 | if (asmap.size() == 0 || (net_class != NET_IPV4 && net_class != NET_IPV6)) { |
| 728 | return 0; // Indicates not found, safe because AS0 is reserved per RFC7607. |
| 729 | } |
| 730 | std::vector<bool> ip_bits(128); |
| 731 | if (HasLinkedIPv4()) { |
| 732 | // For lookup, treat as if it was just an IPv4 address (IPV4_IN_IPV6_PREFIX + IPv4 bits) |
| 733 | for (int8_t byte_i = 0; byte_i < 12; ++byte_i) { |
| 734 | for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) { |
| 735 | ip_bits[byte_i * 8 + bit_i] = (IPV4_IN_IPV6_PREFIX[byte_i] >> (7 - bit_i)) & 1; |
| 736 | } |
| 737 | } |
| 738 | uint32_t ipv4 = GetLinkedIPv4(); |
| 739 | for (int i = 0; i < 32; ++i) { |
| 740 | ip_bits[96 + i] = (ipv4 >> (31 - i)) & 1; |
| 741 | } |
| 742 | } else { |
| 743 | // Use all 128 bits of the IPv6 address otherwise |
| 744 | assert(IsIPv6()); |
| 745 | for (int8_t byte_i = 0; byte_i < 16; ++byte_i) { |
| 746 | uint8_t cur_byte = m_addr[byte_i]; |
| 747 | for (uint8_t bit_i = 0; bit_i < 8; ++bit_i) { |
| 748 | ip_bits[byte_i * 8 + bit_i] = (cur_byte >> (7 - bit_i)) & 1; |
| 749 | } |
| 750 | } |
| 751 | } |
| 752 | uint32_t mapped_as = Interpret(asmap, ip_bits); |
| 753 | return mapped_as; |
| 754 | } |
| 755 | |
| 756 | /** |
| 757 | * Get the canonical identifier of our network group |