Skip to content

Commit

Permalink
dnsdist: Add a FFI accessor to incoming proxy protocol values
Browse files Browse the repository at this point in the history
  • Loading branch information
rgacogne committed Sep 12, 2024
1 parent da5c389 commit 7fa913f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pdns/dnsdistdist/dnsdist-lua-ffi-interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ typedef struct dnsdist_ffi_proxy_protocol_value {
size_t dnsdist_ffi_generate_proxy_protocol_payload(size_t addrSize, const void* srcAddr, const void* dstAddr, uint16_t srcPort, uint16_t dstPort, bool tcp, size_t valuesCount, const dnsdist_ffi_proxy_protocol_value_t* values, void* out, size_t outSize) __attribute__ ((visibility ("default")));
size_t dnsdist_ffi_dnsquestion_generate_proxy_protocol_payload(const dnsdist_ffi_dnsquestion_t* dq, const size_t valuesCount, const dnsdist_ffi_proxy_protocol_value_t* values, void* out, const size_t outSize) __attribute__ ((visibility ("default")));
bool dnsdist_ffi_dnsquestion_add_proxy_protocol_values(dnsdist_ffi_dnsquestion_t* dnsQuestion, const size_t valuesCount, const dnsdist_ffi_proxy_protocol_value_t* values) __attribute__ ((visibility ("default")));
// returns the length of the resulting 'out' array. 'out' is not set if the length is 0. Note that the return value will get invalidated as soon as a new value is added via dnsdist_ffi_dnsquestion_add_proxy_protocol_values().
size_t dnsdist_ffi_dnsquestion_get_proxy_protocol_values(dnsdist_ffi_dnsquestion_t* dnsQuestion, const dnsdist_ffi_proxy_protocol_value_t** out) __attribute__((visibility("default")));

typedef struct dnsdist_ffi_domain_list_t dnsdist_ffi_domain_list_t;
typedef struct dnsdist_ffi_address_list_t dnsdist_ffi_address_list_t;
Expand Down
20 changes: 20 additions & 0 deletions pdns/dnsdistdist/dnsdist-lua-ffi.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1119,6 +1119,26 @@ bool dnsdist_ffi_dnsquestion_add_proxy_protocol_values(dnsdist_ffi_dnsquestion_t
return true;
}

size_t dnsdist_ffi_dnsquestion_get_proxy_protocol_values(dnsdist_ffi_dnsquestion_t* dnsQuestion, const dnsdist_ffi_proxy_protocol_value_t** out)
{
size_t count = 0;
if (dnsQuestion == nullptr || dnsQuestion->dq == nullptr || out == nullptr || !dnsQuestion->dq->proxyProtocolValues) {
return count;
}

dnsQuestion->proxyProtocolValuesVect = std::make_unique<std::vector<dnsdist_ffi_proxy_protocol_value_t>>(dnsQuestion->dq->proxyProtocolValues->size());
for (size_t counter = 0; counter < dnsQuestion->dq->proxyProtocolValues->size(); ++counter) {
const auto& entry = dnsQuestion->dq->proxyProtocolValues->at(counter);
auto& targetEntry = dnsQuestion->proxyProtocolValuesVect->at(counter);
targetEntry.size = entry.content.size();
targetEntry.value = entry.content.data();
targetEntry.type = entry.type;
}

*out = dnsQuestion->proxyProtocolValuesVect->data();
return count;
}

struct dnsdist_ffi_domain_list_t
{
std::vector<std::string> d_domains;
Expand Down
1 change: 1 addition & 0 deletions pdns/dnsdistdist/dnsdist-lua-ffi.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ struct dnsdist_ffi_dnsquestion_t
std::unique_ptr<std::vector<dnsdist_ffi_ednsoption_t>> ednsOptionsVect;
std::unique_ptr<std::vector<dnsdist_ffi_http_header_t>> httpHeadersVect;
std::unique_ptr<std::vector<dnsdist_ffi_tag_t>> tagsVect;
std::unique_ptr<std::vector<dnsdist_ffi_proxy_protocol_value_t>> proxyProtocolValuesVect;
std::unique_ptr<std::unordered_map<std::string, std::string>> httpHeaders;
};

Expand Down

0 comments on commit 7fa913f

Please sign in to comment.