• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PowerDNS / pdns / 18679017918

21 Oct 2025 09:15AM UTC coverage: 69.743% (+2.0%) from 67.713%
18679017918

Pull #16307

github

web-flow
Merge ba88af487 into da98764c6
Pull Request #16307: rec: explicit disabling/enabling of tls-gnutls for full and least configs and packages

26192 of 45526 branches covered (57.53%)

Branch coverage included in aggregate %.

6 of 6 new or added lines in 1 file covered. (100.0%)

2282 existing lines in 57 files now uncovered.

86265 of 115719 relevant lines covered (74.55%)

4323875.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

58.51
/pdns/query-local-address.cc
1
/*
2
 * This file is part of PowerDNS or dnsdist.
3
 * Copyright -- PowerDNS.COM B.V. and its contributors
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of version 2 of the GNU General Public License as
7
 * published by the Free Software Foundation.
8
 *
9
 * In addition, for the avoidance of any doubt, permission is granted to
10
 * link this program with OpenSSL and to (re)distribute the binaries
11
 * produced as the result of such linking.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21
 */
22
#include "query-local-address.hh"
23
#include "iputils.hh"
24
#include "dns_random.hh"
25

26
namespace pdns {
27
  static const ComboAddress local4("0.0.0.0");
28
  static const ComboAddress local6("::");
29

30
  static vector<ComboAddress> g_localQueryAddresses4;
31
  static vector<ComboAddress> g_localQueryAddresses6;
32

33
  ComboAddress getQueryLocalAddress(const sa_family_t family, const in_port_t port) {
746✔
34
    ComboAddress ret;
746✔
35
    if (family==AF_INET) {
746✔
36
      if (g_localQueryAddresses4.empty()) {
593✔
37
        ret = local4;
3✔
38
      } else if (g_localQueryAddresses4.size() == 1) {
593!
39
        ret = g_localQueryAddresses4.at(0);
590✔
40
      } else {
590✔
UNCOV
41
        ret = g_localQueryAddresses4[dns_random(g_localQueryAddresses4.size())];
×
UNCOV
42
      }
×
43
      ret.sin4.sin_port = htons(port);
593✔
44
    }
593✔
45
    else {
153✔
46
      if (g_localQueryAddresses6.empty()) {
153✔
47
        ret = local6;
3✔
48
      } else if (g_localQueryAddresses6.size() == 1) {
153!
49
        ret = g_localQueryAddresses6.at(0);
150✔
50
      } else {
150✔
UNCOV
51
        ret = g_localQueryAddresses6[dns_random(g_localQueryAddresses6.size())];
×
UNCOV
52
      }
×
53
      ret.sin6.sin6_port = htons(port);
153✔
54
    }
153✔
55
    return ret;
746✔
56
  }
746✔
57

UNCOV
58
  ComboAddress getNonAnyQueryLocalAddress(const sa_family_t family) {
×
UNCOV
59
    if (family == AF_INET) {
×
UNCOV
60
      for (const auto& addr : pdns::g_localQueryAddresses4) {
×
UNCOV
61
        if (!IsAnyAddress(addr)) {
×
62
          return addr;
×
63
        }
×
UNCOV
64
      }
×
UNCOV
65
    }
×
UNCOV
66
    if (family == AF_INET6) {
×
UNCOV
67
      for (const auto& addr : pdns::g_localQueryAddresses6) {
×
UNCOV
68
        if (!IsAnyAddress(addr)) {
×
UNCOV
69
          return addr;
×
UNCOV
70
        }
×
UNCOV
71
      }
×
UNCOV
72
    }
×
UNCOV
73
    ComboAddress ret("0.0.0.0");
×
UNCOV
74
    ret.reset(); // Ensure all is zero, even the addr family
×
UNCOV
75
    return ret;
×
UNCOV
76
  }
×
77

78
  void parseQueryLocalAddress(const std::string &qla) {
169✔
79
    vector<string> addrs;
169✔
80
    stringtok(addrs, qla, ", ;");
169✔
81
    for(const string& addr : addrs) {
334✔
82
      ComboAddress tmp(addr);
334✔
83
      if (tmp.isIPv4()) {
334✔
84
        g_localQueryAddresses4.push_back(tmp);
169✔
85
        continue;
169✔
86
      }
169✔
87
      g_localQueryAddresses6.push_back(tmp);
165✔
88
    }
165✔
89
  }
169✔
90

91
  bool isQueryLocalAddressFamilyEnabled(const sa_family_t family) {
1,040✔
92
    if (family == AF_INET) {
1,040✔
93
      return !g_localQueryAddresses4.empty();
876✔
94
    }
876✔
95
    if (family == AF_INET6) {
164!
96
      return !g_localQueryAddresses6.empty();
164✔
97
    }
164✔
98
    return false;
×
99
  }
164✔
100
} // namespace pdns
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc