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

PowerDNS / pdns / 12595591960

03 Jan 2025 09:27AM UTC coverage: 62.774% (+2.5%) from 60.245%
12595591960

Pull #15008

github

web-flow
Merge c2a2749d3 into 788f396a7
Pull Request #15008: Do not follow CNAME records for ANY or CNAME queries

30393 of 78644 branches covered (38.65%)

Branch coverage included in aggregate %.

105822 of 138350 relevant lines covered (76.49%)

4613078.44 hits per line

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

72.22
/pdns/dnsdistdist/dnsdist-lua-ffi.hh
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
#pragma once
23

24
#include "dnsdist.hh"
25

26
extern "C"
27
{
28
#include "dnsdist-lua-ffi-interface.h"
29
}
30

31
#include "ext/luawrapper/include/LuaContext.hpp"
32

33
// dnsdist_ffi_dnsquestion_t is a lightuserdata
34
template <>
35
struct LuaContext::Pusher<dnsdist_ffi_dnsquestion_t*>
36
{
37
  static const int minSize = 1;
38
  static const int maxSize = 1;
39

40
  static PushedObject push(lua_State* state, dnsdist_ffi_dnsquestion_t* ptr) noexcept
41
  {
732✔
42
    lua_pushlightuserdata(state, ptr);
732✔
43
    return PushedObject{state, 1};
732✔
44
  }
732✔
45
};
46

47
struct dnsdist_ffi_dnsquestion_t
48
{
49
  dnsdist_ffi_dnsquestion_t(DNSQuestion* dq_) :
50
    dq(dq_)
51
  {
565✔
52
  }
565✔
53

54
  DNSQuestion* dq{nullptr};
55
  ComboAddress maskedRemote;
56
  std::string trailingData;
57
  std::optional<std::string> result{std::nullopt};
58
  std::optional<std::string> httpPath{std::nullopt};
59
  std::optional<std::string> httpQueryString{std::nullopt};
60
  std::optional<std::string> httpHost{std::nullopt};
61
  std::optional<std::string> httpScheme{std::nullopt};
62
  std::unique_ptr<std::vector<dnsdist_ffi_ednsoption_t>> ednsOptionsVect;
63
  std::unique_ptr<std::vector<dnsdist_ffi_http_header_t>> httpHeadersVect;
64
  std::unique_ptr<std::vector<dnsdist_ffi_tag_t>> tagsVect;
65
  std::unique_ptr<std::vector<dnsdist_ffi_proxy_protocol_value_t>> proxyProtocolValuesVect;
66
  std::unique_ptr<std::unordered_map<std::string, std::string>> httpHeaders;
67
};
68

69
// dnsdist_ffi_dnsresponse_t is a lightuserdata
70
template <>
71
struct LuaContext::Pusher<dnsdist_ffi_dnsresponse_t*>
72
{
73
  static const int minSize = 1;
74
  static const int maxSize = 1;
75

76
  static PushedObject push(lua_State* state, dnsdist_ffi_dnsresponse_t* ptr) noexcept
77
  {
91✔
78
    lua_pushlightuserdata(state, ptr);
91✔
79
    return PushedObject{state, 1};
91✔
80
  }
91✔
81
};
82

83
struct dnsdist_ffi_dnsresponse_t
84
{
85
  dnsdist_ffi_dnsresponse_t(DNSResponse* dr_) :
86
    dr(dr_)
87
  {
93✔
88
  }
93✔
89

90
  DNSResponse* dr{nullptr};
91
  std::optional<std::string> result{std::nullopt};
92
};
93

94
// dnsdist_ffi_server_t is a lightuserdata
95
template <>
96
struct LuaContext::Pusher<dnsdist_ffi_server_t*>
97
{
98
  static const int minSize = 1;
99
  static const int maxSize = 1;
100

101
  static PushedObject push(lua_State* state, dnsdist_ffi_server_t* ptr) noexcept
102
  {
×
103
    lua_pushlightuserdata(state, ptr);
×
104
    return PushedObject{state, 1};
×
105
  }
×
106
};
107

108
struct dnsdist_ffi_server_t
109
{
110
  dnsdist_ffi_server_t(const std::shared_ptr<DownstreamState>& server_) :
111
    server(server_)
112
  {
46✔
113
  }
46✔
114

115
  const std::shared_ptr<DownstreamState>& server;
116
};
117

118
// dnsdist_ffi_servers_list_t is a lightuserdata
119
template <>
120
struct LuaContext::Pusher<dnsdist_ffi_servers_list_t*>
121
{
122
  static const int minSize = 1;
123
  static const int maxSize = 1;
124

125
  static PushedObject push(lua_State* state, dnsdist_ffi_servers_list_t* ptr) noexcept
126
  {
44✔
127
    lua_pushlightuserdata(state, ptr);
44✔
128
    return PushedObject{state, 1};
44✔
129
  }
44✔
130
};
131

132
struct dnsdist_ffi_servers_list_t
133
{
134
  dnsdist_ffi_servers_list_t(const ServerPolicy::NumberedServerVector& servers_) :
135
    servers(servers_)
136
  {
22✔
137
    ffiServers.reserve(servers.size());
22✔
138
    for (const auto& server : servers) {
42✔
139
      ffiServers.push_back(dnsdist_ffi_server_t(server.second));
42✔
140
    }
42✔
141
  }
22✔
142

143
  std::vector<dnsdist_ffi_server_t> ffiServers;
144
  const ServerPolicy::NumberedServerVector& servers;
145
};
146

147
// dnsdist_ffi_network_message_t is a lightuserdata
148
template <>
149
struct LuaContext::Pusher<dnsdist_ffi_network_message_t*>
150
{
151
  static const int minSize = 1;
152
  static const int maxSize = 1;
153

154
  static PushedObject push(lua_State* state, dnsdist_ffi_network_message_t* ptr) noexcept
155
  {
×
156
    lua_pushlightuserdata(state, ptr);
×
157
    return PushedObject{state, 1};
×
158
  }
×
159
};
160

161
struct dnsdist_ffi_network_message_t
162
{
163
  dnsdist_ffi_network_message_t(const std::string& payload_, const std::string& from_, uint16_t endpointID_) :
164
    payload(payload_), from(from_), endpointID(endpointID_)
165
  {
×
166
  }
×
167

168
  const std::string& payload;
169
  const std::string& from;
170
  uint16_t endpointID;
171
};
172

173
const char* getLuaFFIWrappers();
174
void setupLuaFFIPerThreadContext(LuaContext& luaCtx);
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