OpenSDN source code
address_util.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved.
3  * Copyright Contributors to the OpenSDN project
4  */
5 #ifndef BASE_ADDRESS_UTIL_H__
6 #define BASE_ADDRESS_UTIL_H__
7 
8 #include <string>
9 #include <vector>
10 
11 #include <base/address.h>
12 #include <boost/asio/io_service.hpp>
13 
14 /*
15  * Returns true if the given IPv4 address is member of the IPv4 subnet
16  * indicated by IPv4 address and prefix length. Otherwise returns false.
17  */
18 bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip,
19  uint16_t plen);
20 /*
21  * Returns true if the given IPv6 address is member of the IPv6 subnet
22  * indicated by IPv6 address and prefix length. Otherwise returns false.
23  */
24 bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet,
25  uint8_t plen);
26 /*
27  * Returns canonical hostname
28  */
29 
30 std::string ResolveCanonicalName();
31 
32 /*
33  * Returns canonical hostname by IPv4
34  */
35 
36 std::string ResolveCanonicalName(const std::string& ipv4);
37 
38 /*
39  * Returns canonical hostname by IPv6
40  */
41 
42 std::string ResolveCanonicalNameIPv6(const std::string& ipv6);
43 
44 /*
45  * Returns boost::asio::ip::address if given string is either valid
46  * IPv4, IPv6 or a resolvable FQDN
47 */
48 
49 boost::asio::ip::address AddressFromString(
50  const std::string &ip_address_str,
51  boost::system::error_code *ec);
52 
54  uint16_t plen);
55 
56 bool ValidateIPAddressString(std::string ip_address_str,
57  std::string *error_msg);
58 
59 IpAddress PrefixToIpNetmask(uint32_t prefix_len);
60 uint32_t NetmaskToPrefix(uint32_t netmask);
61 
62 IpAddress PrefixToIp6Netmask(uint32_t plen);
63 
64 void IpToU64(const IpAddress &sip, const IpAddress &dip,
65  uint64_t *sip_u, uint64_t *sip_l,
66  uint64_t *dip_u, uint64_t *dip_l);
67 void U64ToIpv6(uint64_t upper, uint64_t lower, IpAddress *ip);
68 void U64ToIp(uint64_t sip_u, uint64_t sip_l, uint64_t dip_u, uint64_t dip_l,
69  int family, IpAddress *sip, IpAddress *dip);
70 void Ip6AddressToU64Array(const Ip6Address &addr, uint64_t *arr, int size);
71 
72 bool ValidateServerEndpoints(std::vector<std::string> list,
73  std::string *error_msg);
74 
75 std::string VectorIpv6ToString(const std::vector<signed char> &ipv6);
76 
77 /*
78  * Return IP address string for a host if it is resolvable, empty string
79  * otherwise.
80  */
81 std::string GetHostIp(boost::asio::io_context *io_service,
82  const std::string &hostname);
83 
84 /*
85  * Get VN name from routing instance
86  */
87 std::string GetVNFromRoutingInstance(const std::string &vn);
88 
89 #endif // BASE_ADDRESS_UTIL_H__
boost::asio::ip::address_v6 Ip6Address
Definition: address.h:16
boost::asio::ip::address IpAddress
Definition: address.h:14
boost::asio::ip::address_v4 Ip4Address
Definition: address.h:15
void U64ToIp(uint64_t sip_u, uint64_t sip_l, uint64_t dip_u, uint64_t dip_l, int family, IpAddress *sip, IpAddress *dip)
bool IsIp6SubnetMember(const Ip6Address &ip, const Ip6Address &subnet, uint8_t plen)
Definition: address_util.cc:30
std::string ResolveCanonicalNameIPv6(const std::string &ipv6)
Definition: address_util.cc:90
std::string VectorIpv6ToString(const std::vector< signed char > &ipv6)
void IpToU64(const IpAddress &sip, const IpAddress &dip, uint64_t *sip_u, uint64_t *sip_l, uint64_t *dip_u, uint64_t *dip_l)
std::string GetHostIp(boost::asio::io_context *io_service, const std::string &hostname)
IpAddress PrefixToIpNetmask(uint32_t prefix_len)
std::string GetVNFromRoutingInstance(const std::string &vn)
bool IsIp4SubnetMember(const Ip4Address &ip, const Ip4Address &prefix_ip, uint16_t plen)
Definition: address_util.cc:20
boost::asio::ip::address AddressFromString(const std::string &ip_address_str, boost::system::error_code *ec)
uint32_t NetmaskToPrefix(uint32_t netmask)
bool ValidateServerEndpoints(std::vector< std::string > list, std::string *error_msg)
Ip4Address GetIp4SubnetBroadcastAddress(const Ip4Address &ip_prefix, uint16_t plen)
bool ValidateIPAddressString(std::string ip_address_str, std::string *error_msg)
void U64ToIpv6(uint64_t upper, uint64_t lower, IpAddress *ip)
void Ip6AddressToU64Array(const Ip6Address &addr, uint64_t *arr, int size)
IpAddress PrefixToIp6Netmask(uint32_t plen)
std::string ResolveCanonicalName()
Definition: address_util.cc:41