Kea 2.7.5
packet_fuzzer.h
Go to the documentation of this file.
1// Copyright (C) 2016-2024 Internet Systems Consortium, Inc. ("ISC")
2//
3// This Source Code Form is subject to the terms of the Mozilla Public
4// License, v. 2.0. If a copy of the MPL was not distributed with this
5// file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
7#ifndef DHCPSRV_PACKET_FUZZER_H
8#define DHCPSRV_PACKET_FUZZER_H
9
10#ifdef FUZZING
11
12#include <asiolink/io_address.h>
14
15#include <arpa/inet.h>
16#include <net/if.h>
17#include <sys/socket.h>
18#include <unistd.h>
19
20#include <string>
21
22namespace isc {
23
39
40class PacketFuzzer {
41public:
48 static constexpr size_t BUFFER_SIZE = 256 * 1024;
49
55 static constexpr size_t MAX_SEND_SIZE = 64000;
56
63 static constexpr long MAX_LOOP_COUNT = 1000;
64
72 PacketFuzzer(uint16_t const port,
73 std::string const interface,
74 std::string const address);
75
80 ~PacketFuzzer();
81
87 void transfer() const;
88 void transfer(uint8_t const* data, size_t size) const;
89
98 long maxLoopCount() const {
99 return loop_max_;
100 }
101
102private:
114 void createAddressStructures(uint16_t const port,
115 std::string const& interface,
116 isc::asiolink::IOAddress const& io_address);
117
118 // Other member variables.
119 long loop_max_; //< Maximum number of loop iterations
120 size_t sockaddr_len_; //< Length of the structure
121 struct sockaddr* sockaddr_ptr_; //< Pointer to structure used
122 struct sockaddr_in servaddr4_; //< IPv6 address information
123 struct sockaddr_in6 servaddr6_; //< IPv6 address information
124 int sockfd_; //< Socket used to transfer data
125}; // class PacketFuzzer
126
128class FuzzInitFail : public Exception {
129public:
130 FuzzInitFail(const char* file, size_t line, const char* what) :
131 isc::Exception(file, line, what) { }
132}; // class FuzzInitFail
133
134} // namespace isc
135
136#endif // FUZZING
137
138#endif // DHCPSRV_PACKET_FUZZER_H
Defines the logger used by the top-level component of kea-lfc.