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

PowerDNS / pdns / 19741624072

27 Nov 2025 03:45PM UTC coverage: 73.086% (+0.02%) from 73.065%
19741624072

Pull #16570

github

web-flow
Merge 08a2cdb1d into f94a3f63f
Pull Request #16570: rec: rewrite all unwrap calls in web.rs

38523 of 63408 branches covered (60.75%)

Branch coverage included in aggregate %.

128044 of 164496 relevant lines covered (77.84%)

6531485.83 hits per line

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

75.0
/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
#include "protozero.hh"
26

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

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

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

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

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

55
  DNSQuestion* dq{nullptr};
56
  ComboAddress maskedRemote;
57
  std::string trailingData;
58
  std::optional<std::string> result{std::nullopt};
59
  std::optional<std::string> httpPath{std::nullopt};
60
  std::optional<std::string> httpQueryString{std::nullopt};
61
  std::optional<std::string> httpHost{std::nullopt};
62
  std::optional<std::string> httpScheme{std::nullopt};
63
  std::unique_ptr<std::vector<dnsdist_ffi_ednsoption_t>> ednsOptionsVect;
64
  std::unique_ptr<std::vector<dnsdist_ffi_http_header_t>> httpHeadersVect;
65
  std::unique_ptr<std::vector<dnsdist_ffi_tag_t>> tagsVect;
66
  std::unique_ptr<std::vector<dnsdist_ffi_proxy_protocol_value_t>> proxyProtocolValuesVect;
67
  std::unique_ptr<std::unordered_map<std::string, std::string>> httpHeaders;
68
#if !defined(DISABLE_PROTOBUF)
69
  protozero::pbf_writer pbfWriter{};
70
  protozero::pbf_writer pbfMetaWriter{};
71
  protozero::pbf_writer pbfMetaValueWriter{};
72
#endif /* DISABLE_PROTOBUF */
73
};
74

75
// dnsdist_ffi_dnsresponse_t is a lightuserdata
76
template <>
77
struct LuaContext::Pusher<dnsdist_ffi_dnsresponse_t*>
78
{
79
  static const int minSize = 1;
80
  static const int maxSize = 1;
81

82
  static PushedObject push(lua_State* state, dnsdist_ffi_dnsresponse_t* ptr) noexcept
83
  {
94✔
84
    lua_pushlightuserdata(state, ptr);
94✔
85
    return PushedObject{state, 1};
94✔
86
  }
94✔
87
};
88

89
struct dnsdist_ffi_dnsresponse_t
90
{
91
  dnsdist_ffi_dnsresponse_t(DNSResponse* dr_) :
92
    dr(dr_)
99✔
93
  {
99✔
94
  }
99✔
95

96
  DNSResponse* dr{nullptr};
97
  std::optional<std::string> result{std::nullopt};
98
#if !defined(DISABLE_PROTOBUF)
99
  protozero::pbf_writer pbfWriter{};
100
  protozero::pbf_writer pbfMetaWriter{};
101
  protozero::pbf_writer pbfMetaValueWriter{};
102
#endif /* DISABLE_PROTOBUF */
103
};
104

105
// dnsdist_ffi_server_t is a lightuserdata
106
template <>
107
struct LuaContext::Pusher<dnsdist_ffi_server_t*>
108
{
109
  static const int minSize = 1;
110
  static const int maxSize = 1;
111

112
  static PushedObject push(lua_State* state, dnsdist_ffi_server_t* ptr) noexcept
113
  {
×
114
    lua_pushlightuserdata(state, ptr);
×
115
    return PushedObject{state, 1};
×
116
  }
×
117
};
118

119
struct dnsdist_ffi_server_t
120
{
121
  dnsdist_ffi_server_t(const std::shared_ptr<DownstreamState>& server_) :
122
    server(server_)
45✔
123
  {
45✔
124
  }
45✔
125

126
  const std::shared_ptr<DownstreamState>& server;
127
};
128

129
// dnsdist_ffi_servers_list_t is a lightuserdata
130
template <>
131
struct LuaContext::Pusher<dnsdist_ffi_servers_list_t*>
132
{
133
  static const int minSize = 1;
134
  static const int maxSize = 1;
135

136
  static PushedObject push(lua_State* state, dnsdist_ffi_servers_list_t* ptr) noexcept
137
  {
22✔
138
    lua_pushlightuserdata(state, ptr);
22✔
139
    return PushedObject{state, 1};
22✔
140
  }
22✔
141
};
142

143
struct dnsdist_ffi_servers_list_t
144
{
145
  dnsdist_ffi_servers_list_t(const ServerPolicy::NumberedServerVector& servers_) :
146
    servers(servers_)
22✔
147
  {
22✔
148
    ffiServers.reserve(servers.size());
22✔
149
    for (const auto& server : servers) {
42✔
150
      ffiServers.push_back(dnsdist_ffi_server_t(server.second));
42✔
151
    }
42✔
152
  }
22✔
153

154
  std::vector<dnsdist_ffi_server_t> ffiServers;
155
  const ServerPolicy::NumberedServerVector& servers;
156
};
157

158
// dnsdist_ffi_network_message_t is a lightuserdata
159
template <>
160
struct LuaContext::Pusher<dnsdist_ffi_network_message_t*>
161
{
162
  static const int minSize = 1;
163
  static const int maxSize = 1;
164

165
  static PushedObject push(lua_State* state, dnsdist_ffi_network_message_t* ptr) noexcept
166
  {
×
167
    lua_pushlightuserdata(state, ptr);
×
168
    return PushedObject{state, 1};
×
169
  }
×
170
};
171

172
struct dnsdist_ffi_network_message_t
173
{
174
  dnsdist_ffi_network_message_t(const std::string& payload_, const std::string& from_, uint16_t endpointID_) :
175
    payload(payload_), from(from_), endpointID(endpointID_)
176
  {
×
177
  }
×
178

179
  const std::string& payload;
180
  const std::string& from;
181
  uint16_t endpointID;
182
};
183

184
const char* getLuaFFIWrappers();
185
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