25#ifndef JOIN_FABRIC_ROUTE_HPP
26#define JOIN_FABRIC_ROUTE_HPP
39#include <linux/rtnetlink.h>
70 return lhs._index == rhs._index && lhs._dest == rhs._dest && lhs._prefix == rhs._prefix;
81 return std::tie (lhs._index, lhs._dest, lhs._prefix) <=> std::tie (rhs._index, rhs._dest, rhs._prefix);
98 using Ptr = std::shared_ptr<Route>;
114 uint32_t
index () const noexcept;
126 uint32_t
prefix () const noexcept;
144 uint8_t
type () const;
150 uint8_t
scope () const;
186 bool isLocal () const noexcept;
222 bool isDhcp () const noexcept;
228 bool isBoot () const noexcept;
244 int remove (
bool sync = false) const;
257 uint32_t _prefix = 0;
263 uint32_t _metric = 0;
266 uint8_t _type = RTN_UNICAST;
269 uint8_t _scope = RT_SCOPE_UNIVERSE;
272 uint8_t _protocol = RTPROT_STATIC;
275 mutable
Mutex _mutex;
278 friend
bool operator== (const
Route::
Ptr& lhs, const
Route::
Ptr& rhs) noexcept;
281 friend
std::strong_ordering operator<=> (const
Route::
Ptr& lhs, const
Route::
Ptr& rhs) noexcept;
303 return lhs->_index == rhs->_index && lhs->_dest == rhs->_dest && lhs->_prefix == rhs->_prefix;
316 return bool (lhs) <=> bool (rhs);
318 return std::tie (lhs->_index, lhs->_dest, lhs->_prefix) <=> std::tie (rhs->_index, rhs->_dest, rhs->_prefix);
336 size_t h = std::hash<uint32_t>{}(
key._index);
337 h ^= std::hash<join::IpAddress>{}(
key._dest) + 0x9e3779b9 + (h << 6) + (h >> 2);
338 h ^= std::hash<uint32_t>{}(
key._prefix) + 0x9e3779b9 + (h << 6) + (h >> 2);
IPv6, IPv4 address class.
Definition ip_address.hpp:52
class used to protect shared data from being simultaneously accessed by multiple threads.
Definition mutex.hpp:37
kernel routing table manager class.
Definition route_manager.hpp:141
class representing a single kernel routing table entry.
Definition route.hpp:88
const IpAddress & dest() const noexcept
get the destination network address.
Definition route.cpp:58
bool isProhibit() const noexcept
check if route returns ICMP prohibited.
Definition route.cpp:153
int remove(bool sync=false) const
remove this route entry from the kernel table.
Definition route.cpp:243
uint8_t scope() const
get the route scope.
Definition route.cpp:106
friend std::strong_ordering operator<=>(const Route::Ptr &lhs, const Route::Ptr &rhs) noexcept
three-way compare routes.
Definition route.hpp:312
uint8_t type() const
get the route type.
Definition route.cpp:96
bool isLocal() const noexcept
check if route is a local route.
Definition route.cpp:162
bool isDhcp() const noexcept
check if route was added by a DHCP client.
Definition route.cpp:216
bool isUnicast() const noexcept
check if route is a standard unicast route.
Definition route.cpp:126
bool isScopeUniverse() const noexcept
check if route is universe-scoped.
Definition route.cpp:171
uint32_t metric() const
get the route metric.
Definition route.cpp:86
uint32_t index() const noexcept
get interface index.
Definition route.cpp:49
bool isUnreachable() const noexcept
check if route returns ICMP unreachable.
Definition route.cpp:144
Route()=delete
create instance.
bool isBlackhole() const noexcept
check if route silently drops packets.
Definition route.cpp:135
int set(const IpAddress &gateway, uint32_t metric=0, bool sync=false) const
update this route entry in the kernel table.
Definition route.cpp:234
bool isScopeHost() const noexcept
check if route is host-scoped.
Definition route.cpp:189
bool isScopeLink() const noexcept
check if route is link-scoped.
Definition route.cpp:180
bool isStatic() const noexcept
check if route was added statically.
Definition route.cpp:198
~Route()=default
destroy instance.
bool isBoot() const noexcept
check if route was added at boot time.
Definition route.cpp:225
bool isKernel() const noexcept
check if route was added by the kernel.
Definition route.cpp:207
uint8_t protocol() const
get the route protocol.
Definition route.cpp:116
IpAddress gateway() const
get the gateway address.
Definition route.cpp:76
std::shared_ptr< Route > Ptr
Definition route.hpp:98
uint32_t prefix() const noexcept
get the prefix length.
Definition route.cpp:67
const std::string key(65, 'a')
key.
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< Route::Ptr > RouteList
list of routes.
Definition route.hpp:322
std::strong_ordering operator<=>(const BasicLinkLayerEndpoint< Protocol > &a, const BasicLinkLayerEndpoint< Protocol > &b) noexcept
three-way compare endpoints.
Definition endpoint.hpp:208
key identifying a routing table entry.
Definition route.hpp:51
uint32_t _index
interface index.
Definition route.hpp:53
uint32_t _prefix
prefix length.
Definition route.hpp:59
IpAddress _dest
destination network address.
Definition route.hpp:56