10#ifndef PROTO_FUZZER_TFTP_MOCK_SERVER_H_
11#define PROTO_FUZZER_TFTP_MOCK_SERVER_H_
13#include <netinet/in.h>
21#include "curl_fuzzer.pb.h"
25namespace proto_fuzzer {
77 curl_socket_t
HandleOpenSocket(curlsocktype purpose,
struct curl_sockaddr* address)
override;
81 void RunLoop(CURLM* multi, CURL* easy,
const curl::fuzzer::proto::Scenario& scenario)
override;
89 void PrepareScript(
const curl::fuzzer::proto::Connection&
connection);
93 static bool ConfigureSocket(
int fd);
95 static int OpenLoopbackSocket(
struct sockaddr_in* bound_address);
97 static bool RewriteDestination(
struct curl_sockaddr* address,
const struct sockaddr_in& destination);
101 std::size_t DrainClientDatagrams();
103 void RememberClientAddress(
const struct sockaddr_in& address, socklen_t length);
105 bool SendNextDatagram();
107 std::array<const std::string*, scenario_limits::kMaxResponseChunks + 1> response_datagrams_;
108 std::size_t response_datagram_count_;
109 std::size_t next_response_datagram_;
113 struct sockaddr_in client_address_;
114 socklen_t client_address_length_;
115 bool has_client_address_;
117 std::uint16_t request_port_;
118 std::uint16_t transfer_port_;
119 std::vector<TftpReceivedDatagram> received_datagrams_;
MockConnection * connection()
~TftpMockServer() override
Close the two server endpoints after the base drive has removed curl's separately-owned client descri...
void RunLoop(CURLM *multi, CURL *easy, const curl::fuzzer::proto::Scenario &scenario) override
Give curl one nonblocking state-machine turn, retain all client packets that turn produced,...
SocketSetupDisposition GetSocketSetupDisposition(curl_socket_t curlfd, curlsocktype purpose) const override
TFTP returns an unconnected IPv4 datagram descriptor, so curl must still bind/configure it before the...
std::uint16_t request_port() const
Expose the kernel-selected request endpoint for transfer-ID assertions, not for routing.
void ObserveState() override
Retain protocol outcomes in coverage and introspector builds.
curl_socket_t HandleOpenSocket(curlsocktype purpose, struct curl_sockaddr *address) override
Create both server transfer IDs before returning curl's client socket.
std::uint16_t transfer_port() const
Expose the kernel-selected response endpoint for transfer-ID assertions, not for routing.
TftpMockServer()
Start without live descriptors or borrowed scenario storage.
const std::vector< TftpReceivedDatagram > & received_datagrams() const
Return bounded observations from the most recent run rather than parsing them in the peer.
MockServerBase — common plumbing shared by every protocol-specific mock server.
SocketSetupDisposition
Tell curl whether an application-provided socket still needs its normal connect/options setup or alre...
Shared complexity limits for structured scenarios.
constexpr std::size_t kMaxResponseChunks
Enough response boundaries to exercise incremental parsers while keeping per-perform delivery work fi...
One bounded observation of a datagram curl sent to the in-process peer.
TftpSocketRole received_on
Server endpoint that received the packet.
std::uint16_t source_port
Curl's UDP transfer ID in host byte order.
std::string bytes
Complete UDP payload, including TFTP header.
TftpSocketRole
Identifies which stable server transfer ID received a client datagram.
@ kRequest
Endpoint placed in curl's rewritten destination address.
@ kTransfer
Endpoint used for replies and the rest of the exchange.