Added logic to read IPv6 addresses

This commit is contained in:
Pavel Odintsov 2022-03-25 13:40:29 +00:00
parent 264d716a64
commit c9ba4315bb
3 changed files with 27 additions and 0 deletions

View File

@ -128,6 +128,8 @@ bool gobgp_announce_host_ipv6 = false;
bgp_community_attribute_element_t bgp_community_host_ipv6;
bgp_community_attribute_element_t bgp_community_subnet_ipv6;;
subnet_ipv6_cidr_mask_t ipv6_next_hop;
void gobgp_action_init() {
logger << log4cpp::Priority::INFO << "GoBGP action module loaded";
gobgp_client =
@ -137,6 +139,21 @@ void gobgp_action_init() {
gobgp_nexthop = configuration_map["gobgp_next_hop"];
}
// Set IPv6 hop to safe default
ipv6_next_hop.cidr_prefix_length = 128;
read_ipv6_host_from_string("100::1", ipv6_next_hop.subnet_address);
if (configuration_map.count("gobgp_next_hop_ipv6")) {
bool parsed_next_hop_result =
read_ipv6_host_from_string(configuration_map["gobgp_next_hop_ipv6"], ipv6_next_hop.subnet_address);
if (!parsed_next_hop_result) {
logger << log4cpp::Priority::ERROR << "Can't parse specified IPv6 next hop to IPv6 address: " << configuration_map["gobgp_next_hop_ipv6"];
}
}
logger << log4cpp::Priority::INFO << "IPv6 next hop: " << print_ipv6_cidr_subnet(ipv6_next_hop);
if (configuration_map.count("gobgp_announce_host")) {
gobgp_announce_host = configuration_map["gobgp_announce_host"] == "on";
}

View File

@ -1462,3 +1462,12 @@ bool convert_string_to_positive_integer_safe(std::string line, int& value) {
return true;
}
// Read IPv6 host address from string representation
bool read_ipv6_host_from_string(std::string ipv6_host_as_string, in6_addr& result) {
if (inet_pton(AF_INET6, ipv6_host_as_string.c_str(), &result) == 1) {
return true;
} else {
return false;
}
}

View File

@ -121,3 +121,4 @@ bool set_boost_process_name(boost::thread* thread, std::string process_name);
std::string print_ipv6_cidr_subnet(subnet_ipv6_cidr_mask_t subnet);
std::string convert_any_ip_to_string(subnet_ipv6_cidr_mask_t subnet);
bool convert_string_to_positive_integer_safe(std::string line, int& value);
bool read_ipv6_host_from_string(std::string ipv6_host_as_string, in6_addr& result);