25#ifndef JOIN_FABRIC_DHCP_OPTION_HPP
26#define JOIN_FABRIC_DHCP_OPTION_HPP
54 using IpList = std::vector<IpAddress>;
178 using Options = std::map<uint8_t, DhcpOptionValue>;
245 template <
typename T>
249 return (it ==
_options.end ()) ? nullptr : it->second.getIf<T> ();
269 return (
find (code) !=
end ());
350 template <
typename T>
355 if (!
convert (code, std::forward<T> (value), converted))
360 if (!
_options.emplace (code, std::move (converted)).second)
394 std::stringstream stream;
398 stream <<
codeName (option.first) <<
" (" << int (option.first) <<
"): ";
399 write (stream, option.first, option.second);
403 return stream.str ();
412 template <
typename T>
416 return convert (code, std::forward<T> (value), converted);
424 static const Info*
describe (uint8_t code)
noexcept;
432 static const char*
codeName (uint8_t code)
noexcept;
452 return (value < 32) && ((info.mask >> value) & 1u);
457 return (value >= info.min) && (value <= info.max);
470 template <
typename Target,
typename Source>
473 if (!std::in_range<Target> (value) || !
accepts (info,
static_cast<uint32_t
> (value)))
479 out =
static_cast<Target
> (value);
501 template <
typename T>
503 requires std::integral<T>
550 return convert (code, std::string (value), out);
563 if ((info ==
nullptr) || (info->
type !=
Ip) || (value.
family () != AF_INET))
583 if ((info ==
nullptr) || (info->
type !=
Mac))
660 out << options.
dump ();
DHCP option list.
Definition dhcp_option.hpp:64
static bool isValid(uint8_t code, T &&value)
check that a value can be carried by the given option.
Definition dhcp_option.hpp:413
size_t size() const
get the number of options in the list.
Definition dhcp_option.hpp:321
Code
option codes.
Definition dhcp_option.hpp:70
@ Router
Definition dhcp_option.hpp:74
@ Message
Definition dhcp_option.hpp:127
@ BootFileName
Definition dhcp_option.hpp:134
@ DefaultWwwServer
Definition dhcp_option.hpp:139
@ ServerIdentifier
Definition dhcp_option.hpp:125
@ TcpDefaultTtl
Definition dhcp_option.hpp:108
@ NetbiosDatagramDistributionServer
Definition dhcp_option.hpp:116
@ TimeOffset
Definition dhcp_option.hpp:73
@ XWindowFontServer
Definition dhcp_option.hpp:119
@ IpForwarding
Definition dhcp_option.hpp:90
@ RebindingTimeValue
Definition dhcp_option.hpp:130
@ BroadcastAddress
Definition dhcp_option.hpp:99
@ NetworkInformationServer
Definition dhcp_option.hpp:112
@ StreetTalkDirectoryAssistanceServer
Definition dhcp_option.hpp:143
@ MeritDumpFile
Definition dhcp_option.hpp:85
@ XWindowDisplayManager
Definition dhcp_option.hpp:120
@ DomainNameServer
Definition dhcp_option.hpp:77
@ ExtensionsPath
Definition dhcp_option.hpp:89
@ PerformRouterDiscovery
Definition dhcp_option.hpp:102
@ IpAddressLeaseTime
Definition dhcp_option.hpp:122
@ EthernetEncapsulation
Definition dhcp_option.hpp:107
@ DefaultIrcServer
Definition dhcp_option.hpp:141
@ MaskSupplier
Definition dhcp_option.hpp:101
@ NisDomain
Definition dhcp_option.hpp:111
@ RenewalTimeValue
Definition dhcp_option.hpp:129
@ StreetTalkServer
Definition dhcp_option.hpp:142
@ NameServer
Definition dhcp_option.hpp:76
@ PolicyFilter
Definition dhcp_option.hpp:92
@ OptionOverload
Definition dhcp_option.hpp:123
@ SmtpServer
Definition dhcp_option.hpp:136
@ ParameterRequestList
Definition dhcp_option.hpp:126
@ TrailerEncapsulation
Definition dhcp_option.hpp:105
@ LogServer
Definition dhcp_option.hpp:78
@ TcpKeepaliveGarbage
Definition dhcp_option.hpp:110
@ RouterSolicitationAddress
Definition dhcp_option.hpp:103
@ Pad
Definition dhcp_option.hpp:71
@ TftpServerName
Definition dhcp_option.hpp:133
@ RootPath
Definition dhcp_option.hpp:88
@ DefaultFingerServer
Definition dhcp_option.hpp:140
@ NetbiosScope
Definition dhcp_option.hpp:118
@ VendorClassIdentifier
Definition dhcp_option.hpp:131
@ NntpServer
Definition dhcp_option.hpp:138
@ DomainName
Definition dhcp_option.hpp:86
@ SubnetMask
Definition dhcp_option.hpp:72
@ DefaultIpTimeToLive
Definition dhcp_option.hpp:94
@ ImpressServer
Definition dhcp_option.hpp:81
@ LprServer
Definition dhcp_option.hpp:80
@ ClientIdentifier
Definition dhcp_option.hpp:132
@ TimeServer
Definition dhcp_option.hpp:75
@ SwapServer
Definition dhcp_option.hpp:87
@ PathMtuPlateauTable
Definition dhcp_option.hpp:96
@ NetbiosNameServer
Definition dhcp_option.hpp:115
@ ResourceLocationServer
Definition dhcp_option.hpp:82
@ StaticRoute
Definition dhcp_option.hpp:104
@ AllSubnetsAreLocal
Definition dhcp_option.hpp:98
@ Pop3Server
Definition dhcp_option.hpp:137
@ MaximumDhcpMessageSize
Definition dhcp_option.hpp:128
@ End
Definition dhcp_option.hpp:144
@ MaximumDatagramReassemblySize
Definition dhcp_option.hpp:93
@ RequestedIpAddress
Definition dhcp_option.hpp:121
@ VendorSpecificInformation
Definition dhcp_option.hpp:114
@ DhcpMessageType
Definition dhcp_option.hpp:124
@ HostName
Definition dhcp_option.hpp:83
@ PathMtuAgingTimeout
Definition dhcp_option.hpp:95
@ InterfaceMtu
Definition dhcp_option.hpp:97
@ BootFileSize
Definition dhcp_option.hpp:84
@ NetbiosNodeType
Definition dhcp_option.hpp:117
@ ArpCacheTimeout
Definition dhcp_option.hpp:106
@ MobileIpHomeAgent
Definition dhcp_option.hpp:135
@ NonLocalSourceRouting
Definition dhcp_option.hpp:91
@ PerformMaskDiscovery
Definition dhcp_option.hpp:100
@ CookieServer
Definition dhcp_option.hpp:79
@ TcpKeepaliveInterval
Definition dhcp_option.hpp:109
@ NtpServer
Definition dhcp_option.hpp:113
const_iterator end() const
get an iterator to the element following the last element of the list.
Definition dhcp_option.hpp:294
bool insert(uint8_t code, T &&value)
add an option to the list, converting the value to the type the option carries.
Definition dhcp_option.hpp:351
Options::const_iterator const_iterator
constant iterator from nested container.
Definition dhcp_option.hpp:181
static bool store(const Info &info, Source value, DhcpOptionValue &out)
store an integer value as the given target type.
Definition dhcp_option.hpp:471
Type
type of the value an option carries on the wire.
Definition dhcp_option.hpp:151
@ Word
Definition dhcp_option.hpp:153
@ Ip
Definition dhcp_option.hpp:157
@ Mac
Definition dhcp_option.hpp:158
@ Text
Definition dhcp_option.hpp:156
@ Ips
Definition dhcp_option.hpp:161
@ SLong
Definition dhcp_option.hpp:155
@ Bytes
Definition dhcp_option.hpp:159
@ Long
Definition dhcp_option.hpp:154
@ Byte
Definition dhcp_option.hpp:152
@ Words
Definition dhcp_option.hpp:160
DhcpOption(DhcpOption &&other)=default
create instance by move.
const DhcpOptionValue & at(uint8_t code) const
get the value identified by code, with range verification.
Definition dhcp_option.hpp:235
const T * getIf(uint8_t code) const
get the value identified by code if it is present and holds the requested type.
Definition dhcp_option.hpp:246
const_iterator cend() const
get an iterator to the element following the last element of the list.
Definition dhcp_option.hpp:303
static const char * codeName(uint8_t code) noexcept
get the name of the given option.
Definition dhcp_option.cpp:127
bool contains(uint8_t code) const
check if there is an element identified by code in the list.
Definition dhcp_option.hpp:267
DhcpOption(const DhcpOption &other)=default
create instance by copy.
friend std::weak_ordering operator<=>(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with three-way comparison operator.
Definition dhcp_option.hpp:647
const_iterator find(uint8_t code) const
find the element with the given code.
Definition dhcp_option.hpp:257
std::map< uint8_t, DhcpOptionValue > Options
option list.
Definition dhcp_option.hpp:178
void swap(DhcpOption &other)
exchange the contents of the list with those of other.
Definition dhcp_option.hpp:383
void clear()
remove all elements from the list.
Definition dhcp_option.hpp:339
bool empty() const
check if the list has no element.
Definition dhcp_option.hpp:312
static bool invalid() noexcept
report an invalid option value.
Definition dhcp_option.hpp:488
DhcpOption(const_iterator first, const_iterator last)
create the DhcpOption instance with the elements from range.
Definition dhcp_option.hpp:193
std::string dump() const
dump the options in string format.
Definition dhcp_option.hpp:392
size_t erase(uint8_t code)
remove the element identified by code.
Definition dhcp_option.hpp:331
static bool convert(uint8_t code, const MacAddress &value, DhcpOptionValue &out)
store a hardware address in the given option.
Definition dhcp_option.hpp:580
void insert(const_iterator first, const_iterator last)
insert elements from range.
Definition dhcp_option.hpp:374
static bool convert(uint8_t code, T value, DhcpOptionValue &out)
convert an integer to the type the given option carries.
Definition dhcp_option.hpp:502
static bool convert(uint8_t code, const char *value, DhcpOptionValue &out)
convert a string to the type the given option carries.
Definition dhcp_option.hpp:548
~DhcpOption()=default
destroy the DhcpOption instance.
DhcpOption()=default
create the DhcpOption instance.
Options _options
options.
Definition dhcp_option.hpp:621
static bool convert(uint8_t code, const IpAddress &value, DhcpOptionValue &out)
store an IP address in the given option.
Definition dhcp_option.hpp:560
const_iterator begin() const
get an iterator to the first element of the list.
Definition dhcp_option.hpp:276
static void write(std::ostream &stream, uint8_t code, const DhcpOptionValue &value)
write an option value in string format.
Definition dhcp_option.cpp:137
const_iterator cbegin() const
get an iterator to the first element of the list.
Definition dhcp_option.hpp:285
static bool accepts(const Info &info, uint32_t value) noexcept
check that a value satisfies the constraints of the given option.
Definition dhcp_option.hpp:448
static const Info * describe(uint8_t code) noexcept
get the description of the given option.
Definition dhcp_option.cpp:41
DhcpOption & operator=(const DhcpOption &other)=default
assign instance by copy.
friend bool operator==(const DhcpOption &lhs, const DhcpOption &rhs)
friendship with equal operator.
Definition dhcp_option.hpp:636
IPv6, IPv4 address class.
Definition ip_address.hpp:52
int family() const
get address family.
Definition ip_address.cpp:1250
MAC address class.
Definition mac_address.hpp:47
variant class.
Definition variant.hpp:225
Definition acceptor.hpp:32
bool operator==(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:196
std::vector< IpAddress > IpList
list of IP addresses.
Definition dhcp_option.hpp:54
std::vector< uint16_t > WordList
list of 16 bits words.
Definition dhcp_option.hpp:51
std::ostream & operator<<(std::ostream &os, const BasicLinkLayerEndpoint< Protocol > &endpoint)
push endpoint representation into a stream.
Definition endpoint.hpp:221
std::error_code make_error_code(join::Errc code) noexcept
Create an std::error_code object.
Definition error.cpp:195
std::strong_ordering operator<=>(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
three-way compare endpoints.
Definition endpoint.hpp:208
std::vector< uint8_t > ByteList
list of bytes.
Definition dhcp_option.hpp:48
description of an option.
Definition dhcp_option.hpp:168
uint32_t min
Definition dhcp_option.hpp:172
Type type
Definition dhcp_option.hpp:171
uint32_t mask
Definition dhcp_option.hpp:174
const char * name
Definition dhcp_option.hpp:170
uint32_t max
Definition dhcp_option.hpp:173
uint8_t code
Definition dhcp_option.hpp:169