25#ifndef JOIN_FABRIC_ROUTEMANAGER_HPP
26#define JOIN_FABRIC_ROUTEMANAGER_HPP
60 return RouteChangeType (
static_cast<uint32_t
> (a) &
static_cast<uint32_t
> (b));
71 return RouteChangeType (
static_cast<uint32_t
> (a) |
static_cast<uint32_t
> (b));
82 return RouteChangeType (
static_cast<uint32_t
> (a) ^
static_cast<uint32_t
> (b));
250 uint32_t metric = 0,
bool sync =
false);
262 int addRoute (
const std::string& interfaceName,
const IpAddress& dest, uint32_t prefix,
263 const IpAddress& gateway = {}, uint32_t metric = 0,
bool sync =
false);
273 int removeRoute (uint32_t index,
const IpAddress& dest, uint32_t prefix,
bool sync =
false);
283 int removeRoute (
const std::string& interfaceName,
const IpAddress& dest, uint32_t prefix,
bool sync =
false);
291 int flushRoutes (uint32_t index,
bool sync =
false);
299 int flushRoutes (
const std::string& interfaceName,
bool sync =
false);
312 int setRoute (uint32_t index,
const IpAddress& dest, uint32_t prefix,
const IpAddress& gateway, uint32_t metric,
320 int dumpRoutes (
bool sync =
false);
326 void onMessage (
struct nlmsghdr* nlh)
override;
332 void onRouteMessage (
struct nlmsghdr* nlh);
338 void notifyRouteUpdate (
const RouteInfo& info);
348 Route::Ptr acquire (uint32_t index,
const IpAddress& dest, uint32_t prefix, RouteInfo& info);
351 std::unordered_map<RouteKey, Route::Ptr> _routes;
357 std::unordered_map<uint64_t, RouteNotify> _routeListeners;
360 std::atomic<uint64_t> _listenerCounter{0};
IPv6, IPv4 address class.
Definition ipaddress.hpp:51
base class for netlink-based managers.
Definition netlinkmanager.hpp:51
Reactor * reactor() const noexcept
get the event loop reactor.
Definition netlinkmanager.cpp:66
Reactor class.
Definition reactor.hpp:120
kernel routing table manager class.
Definition routemanager.hpp:141
uint64_t addRouteListener(const RouteNotify &cb)
register a callback invoked on any route table change.
Definition routemanager.cpp:159
int removeRoute(uint32_t index, const IpAddress &dest, uint32_t prefix, bool sync=false)
remove a route entry from the kernel table.
Definition routemanager.cpp:241
std::function< void(const RouteInfo &info)> RouteNotify
Definition routemanager.hpp:143
RouteManager & operator=(const RouteManager &)=delete
assign instance by copy.
int flushRoutes(uint32_t index, bool sync=false)
flush all route entries for a given interface.
Definition routemanager.cpp:297
RouteList enumerate()
enumerate all cached route entries.
Definition routemanager.cpp:96
static RouteManager & instance()
get the singleton instance.
Definition routemanager.cpp:60
RouteManager(Reactor *reactor=nullptr)
create instance.
Definition routemanager.cpp:40
int refresh()
refresh all data.
Definition routemanager.cpp:145
Route::Ptr findByIndex(uint32_t index, const IpAddress &dest, uint32_t prefix)
find a route entry by interface index, destination and prefix.
Definition routemanager.cpp:70
void removeRouteListener(uint64_t id)
unregister a previously registered callback.
Definition routemanager.cpp:174
RouteManager(RouteManager &&)=delete
create instance by move.
RouteManager(const RouteManager &)=delete
create instance by copy.
int addRoute(uint32_t index, const IpAddress &dest, uint32_t prefix, const IpAddress &gateway={}, uint32_t metric=0, bool sync=false)
add a route entry in the kernel table.
Definition routemanager.cpp:185
Route::Ptr findByName(const std::string &interfaceName, const IpAddress &dest, uint32_t prefix)
find a route entry by interface name, destination and prefix.
Definition routemanager.cpp:87
~RouteManager()
destroy instance.
Definition routemanager.cpp:51
class representing a single kernel routing table entry.
Definition route.hpp:94
std::shared_ptr< Route > Ptr
Definition route.hpp:104
Definition acceptor.hpp:32
IpAddress operator^(const IpAddress &a, const IpAddress &b)
perform XOR operation on IP address.
Definition ipaddress.cpp:1719
constexpr const JsonReadMode & operator&=(JsonReadMode &a, JsonReadMode b) noexcept
perform binary AND on JsonReadMode.
Definition json.hpp:916
IpAddress operator&(const IpAddress &a, const IpAddress &b)
perform AND operation on IP address.
Definition ipaddress.cpp:1665
InterfaceChangeType operator~(InterfaceChangeType a)
perform binary NOT on InterfaceChangeType.
Definition interfacemanager.hpp:95
RouteChangeType
enumeration of route change types.
Definition routemanager.hpp:41
std::vector< Route::Ptr > RouteList
list of routes.
Definition route.hpp:341
constexpr const JsonReadMode & operator|=(JsonReadMode &a, JsonReadMode b) noexcept
perform binary OR on JsonReadMode.
Definition json.hpp:927
const InterfaceChangeType & operator^=(InterfaceChangeType &a, InterfaceChangeType b)
perform binary XOR assignment on InterfaceChangeType.
Definition interfacemanager.hpp:128
IpAddress operator|(const IpAddress &a, const IpAddress &b)
perform OR operation on IP address.
Definition ipaddress.cpp:1692
route change notification payload.
Definition routemanager.hpp:132
Route::Ptr route
Definition routemanager.hpp:133
RouteChangeType flags
Definition routemanager.hpp:134