Coverage Report

Created: 2023-11-12 09:30

/proc/self/cwd/source/common/common/dns_utils.cc
Line
Count
Source (jump to first uncovered line)
1
#include "source/common/common/dns_utils.h"
2
3
#include "source/common/common/assert.h"
4
#include "source/common/network/utility.h"
5
#include "source/common/runtime/runtime_features.h"
6
7
namespace Envoy {
8
namespace DnsUtils {
9
10
Network::DnsLookupFamily
11
0
getDnsLookupFamilyFromCluster(const envoy::config::cluster::v3::Cluster& cluster) {
12
0
  return getDnsLookupFamilyFromEnum(cluster.dns_lookup_family());
13
0
}
14
15
Network::DnsLookupFamily
16
2
getDnsLookupFamilyFromEnum(envoy::config::cluster::v3::Cluster::DnsLookupFamily family) {
17
2
  switch (family) {
18
0
    PANIC_ON_PROTO_ENUM_SENTINEL_VALUES;
19
1
  case envoy::config::cluster::v3::Cluster::V6_ONLY:
20
1
    return Network::DnsLookupFamily::V6Only;
21
0
  case envoy::config::cluster::v3::Cluster::V4_ONLY:
22
0
    return Network::DnsLookupFamily::V4Only;
23
1
  case envoy::config::cluster::v3::Cluster::AUTO:
24
1
    return Network::DnsLookupFamily::Auto;
25
0
  case envoy::config::cluster::v3::Cluster::V4_PREFERRED:
26
0
    return Network::DnsLookupFamily::V4Preferred;
27
0
  case envoy::config::cluster::v3::Cluster::ALL:
28
0
    return Network::DnsLookupFamily::All;
29
2
  }
30
0
  IS_ENVOY_BUG("unexpected dns lookup family enum");
31
0
  return Network::DnsLookupFamily::All;
32
0
}
33
34
std::vector<Network::Address::InstanceConstSharedPtr>
35
0
generateAddressList(const std::list<Network::DnsResponse>& responses, uint32_t port) {
36
0
  std::vector<Network::Address::InstanceConstSharedPtr> addresses;
37
0
  for (const auto& response : responses) {
38
0
    auto address = Network::Utility::getAddressWithPort(*(response.addrInfo().address_), port);
39
0
    if (address) {
40
0
      addresses.push_back(address);
41
0
    }
42
0
  }
43
0
  return addresses;
44
0
}
45
46
bool listChanged(const std::vector<Network::Address::InstanceConstSharedPtr>& list1,
47
0
                 const std::vector<Network::Address::InstanceConstSharedPtr>& list2) {
48
0
  if (list1.size() != list2.size()) {
49
0
    return true;
50
0
  }
51
  // Eventually we could rewrite this to not count a change to the order of
52
  // addresses as a functional change.
53
0
  for (size_t i = 0; i < list1.size(); ++i) {
54
0
    if (*list1[i] != *list2[i]) {
55
0
      return true;
56
0
    }
57
0
  }
58
0
  return false;
59
0
}
60
61
} // namespace DnsUtils
62
} // namespace Envoy