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

Method parsePrefixList

Server/src/Config.cpp:786–838  ·  view source on GitHub ↗

* Parse matching prefix_range list and update the provided map with compiled expressions * * \param [in] node prefix_range list node - should be of type sequence * \param [in] name group name, used as the map key * \param [out] map Reference to the map that will be updated with ip addresses */

Source from the content-addressed store, hash-verified

784 * \param [out] map Reference to the map that will be updated with ip addresses
785 */
786void Config::parsePrefixList(const YAML::Node &node, std::string name,
787 std::map<std::string, std::list<match_type_ip>> &map) {
788
789 match_type_ip value;
790 char *prefix_full;
791 char *prefix, *bits;
792
793 for (std::size_t i = 0; i < node.size(); i++) {
794 bzero(value.prefix, sizeof(value.prefix));
795
796 if (node[i].Type() == YAML::NodeType::Scalar) {
797
798 // Split the prefix/bits
799 prefix_full = strdup(node[i].as<std::string>().c_str());
800
801 if (debug_general)
802 std::cout << " Config: parsing prefix range entry: " << prefix_full << std::endl;
803
804 prefix = strtok(prefix_full, "/");
805 bits = strtok(NULL, "/");
806
807 if (prefix == NULL or bits == NULL)
808 throw "Missing prefix range bits value";
809
810 value.bits = atoi(bits);
811
812 if (node[i].as<std::string>().find_first_of(".") != std::string::npos) {
813 value.isIPv4 = true;
814
815 if (value.bits < 1 or value.bits > 32)
816 throw "Invalid prefix range bits value, must be 1 - 32";
817 } else {
818 value.isIPv4 = false;
819
820 if (value.bits < 1 or value.bits > 128)
821 throw "Invalid prefix range bits value, must be 1 - 128";
822 }
823
824
825
826 // add the inet address
827 inet_pton((value.isIPv4 ? AF_INET : AF_INET6), prefix, &value.prefix);
828
829 map[name].push_back(value);
830
831 if (debug_general)
832 printf(" Config: added prefix: %s %s/%d\n", (value.isIPv4 ? "IPv4" : "IPv6"), prefix,
833 value.bits);
834
835 free(prefix_full); // free strdup
836 }
837 }
838}
839
840/**
841 * Perform topic name substitutions based on topic variables

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected