25#ifndef JOIN_FABRIC_ROUTE_HPP
26#define JOIN_FABRIC_ROUTE_HPP
37#include <linux/rtnetlink.h>
68 return lhs._index == rhs._index && lhs._dest == rhs._dest && lhs._prefix == rhs._prefix;
79 if (lhs._index != rhs._index)
81 return lhs._index < rhs._index;
83 if (lhs._dest != rhs._dest)
85 return lhs._dest < rhs._dest;
87 return lhs._prefix < rhs._prefix;
104 using Ptr = std::shared_ptr<Route>;
121 uint32_t
index () const noexcept;
133 uint32_t
prefix () const noexcept;
151 uint8_t
type () const;
157 uint8_t
scope () const;
193 bool isLocal () const noexcept;
229 bool isDhcp () const noexcept;
235 bool isBoot () const noexcept;
251 int remove (
bool sync = false) const;
264 uint32_t _prefix = 0;
270 uint32_t _metric = 0;
273 uint8_t _type = RTN_UNICAST;
276 uint8_t _scope = RT_SCOPE_UNIVERSE;
279 uint8_t _protocol = RTPROT_STATIC;
282 mutable
Mutex _mutex;
285 friend
bool operator== (const
Route::
Ptr& lhs, const
Route::
Ptr& rhs) noexcept;
288 friend
bool operator< (const
Route::
Ptr& lhs, const
Route::
Ptr& rhs) noexcept;
310 return lhs->_index == rhs->_index && lhs->_dest == rhs->_dest && lhs->_prefix == rhs->_prefix;
329 if (lhs->_index != rhs->_index)
331 return lhs->_index < rhs->_index;
333 if (lhs->_dest != rhs->_dest)
335 return lhs->_dest < rhs->_dest;
337 return lhs->_prefix < rhs->_prefix;
355 size_t h = std::hash<uint32_t>{}(
key._index);
356 h ^= std::hash<join::IpAddress>{}(
key._dest) + 0x9e3779b9 + (h << 6) + (h >> 2);
357 h ^= std::hash<uint32_t>{}(
key._prefix) + 0x9e3779b9 + (h << 6) + (h >> 2);
IPv6, IPv4 address class.
Definition ipaddress.hpp:51
class used to protect shared data from being simultaneously accessed by multiple threads.
Definition mutex.hpp:37
kernel routing table manager class.
Definition routemanager.hpp:141
class representing a single kernel routing table entry.
Definition route.hpp:94
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
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
std::vector< Ptr > List
Definition route.hpp:105
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
friend bool operator<(const Route::Ptr &lhs, const Route::Ptr &rhs) noexcept
compare two routes for ordering.
Definition route.hpp:319
~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:104
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 BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoint is lower.
Definition endpoint.hpp:207
std::vector< Route::Ptr > RouteList
list of routes.
Definition route.hpp:341
bool operator==(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:183
key identifying a routing table entry.
Definition route.hpp:49
uint32_t _index
interface index.
Definition route.hpp:51
uint32_t _prefix
prefix length.
Definition route.hpp:57
IpAddress _dest
destination network address.
Definition route.hpp:54