25#ifndef JOIN_FABRIC_INTERFACEMANAGER_HPP
26#define JOIN_FABRIC_INTERFACEMANAGER_HPP
301 int createVlanInterface (
const std::string& interfaceName, uint32_t parentIndex, uint16_t
id,
302 uint16_t proto = ETH_P_8021Q,
bool sync =
false);
313 int createVlanInterface (
const std::string& interfaceName,
const std::string& parentName, uint16_t
id,
314 uint16_t proto = ETH_P_8021Q,
bool sync =
false);
324 int createVethInterface (
const std::string& hostName,
const std::string& peerName, pid_t* pid =
nullptr,
340 const IpAddress& remoteAddress,
const uint32_t* ikey =
nullptr,
341 const uint32_t* okey =
nullptr, uint8_t
ttl = 64,
bool sync =
false);
357 const uint32_t* ikey =
nullptr,
const uint32_t* okey =
nullptr, uint8_t
ttl = 64,
374 int removeInterface (
const std::string& interfaceName,
bool sync =
false);
382 static void addPeerInfoData (
struct nlmsghdr* nlh,
const std::string& peerName);
391 int mtu (uint32_t interfaceIndex, uint32_t mtuBytes,
bool sync =
false);
400 int mac (uint32_t interfaceIndex,
const MacAddress& macAddress,
bool sync =
false);
409 int addToBridge (uint32_t interfaceIndex, uint32_t masterIndex,
bool sync =
false);
417 int removeFromBridge (uint32_t interfaceIndex,
bool sync =
false);
426 int enable (uint32_t interfaceIndex,
bool enabled =
true,
bool sync =
false);
437 int addAddress (uint32_t interfaceIndex,
const IpAddress& ipAddress, uint32_t prefix,
438 const IpAddress& broadcast = {},
bool sync =
false);
449 int removeAddress (uint32_t interfaceIndex,
const IpAddress& ipAddress, uint32_t prefix,
450 const IpAddress& broadcast = {},
bool sync =
false);
462 int addRoute (uint32_t interfaceIndex,
const IpAddress& dest, uint32_t prefix,
const IpAddress& gateway,
463 uint32_t* metric =
nullptr,
bool sync =
false);
475 int removeRoute (uint32_t interfaceIndex,
const IpAddress& dest, uint32_t prefix,
const IpAddress& gateway,
476 uint32_t* metric =
nullptr,
bool sync =
false);
483 int dumpLink (
bool sync =
false);
490 int dumpAddress (
bool sync =
false);
497 int dumpRoute (
bool sync =
false);
503 void onMessage (
struct nlmsghdr* nlh)
override;
509 void onLinkMessage (
struct nlmsghdr* nlh);
522 void onAddressMessage (
struct nlmsghdr* nlh);
528 void onRouteMessage (
struct nlmsghdr* nlh);
534 void notifyLinkUpdate (
const LinkInfo& info);
540 void notifyAddressUpdate (
const AddressInfo& info);
546 void notifyRouteUpdate (
const RouteInfo& info);
556 static constexpr uint16_t reservedVlanId = 0;
559 static constexpr uint16_t maxVlanId = 4094;
562 std::unordered_map<uint32_t, Interface::Ptr> _interfaces;
568 std::unordered_map<uint64_t, LinkNotify> _linkListeners;
571 std::unordered_map<uint64_t, AddressNotify> _addressListeners;
574 std::unordered_map<uint64_t, RouteNotify> _routeListeners;
577 uint64_t _listenerCounter = 0;
580 Mutex _listenerMutex;
int ttl() const
returns the Time-To-Live value.
Definition socket.hpp:1112
int mtu() const
get socket mtu.
Definition socket.hpp:1074
interface manager class.
Definition interfacemanager.hpp:162
InterfaceManager(Reactor *reactor=nullptr)
create instance.
Definition interfacemanager.cpp:41
int refresh()
refresh all data.
Definition interfacemanager.cpp:117
Interface::Ptr findByName(const std::string &interfaceName)
find interface by name.
Definition interfacemanager.cpp:89
int createVethInterface(const std::string &hostName, const std::string &peerName, pid_t *pid=nullptr, bool sync=false)
creates a Virtual Ethernet nterface pair.
Definition interfacemanager.cpp:332
std::function< void(const AddressInfo &info)> AddressNotify
Definition interfacemanager.hpp:165
int removeInterface(uint32_t interfaceIndex, bool sync=false)
deletes the specified network interface.
Definition interfacemanager.cpp:495
uint64_t addAddressListener(const AddressNotify &cb)
registers a callback to be invoked when a address update occurs.
Definition interfacemanager.cpp:151
void removeLinkListener(uint64_t id)
unregisters a previously registered link update callback.
Definition interfacemanager.cpp:141
Interface::Ptr findByIndex(uint32_t interfaceIndex)
find interface by index.
Definition interfacemanager.cpp:72
std::function< void(const LinkInfo &info)> LinkNotify
Definition interfacemanager.hpp:164
InterfaceList enumerate()
enumerate all interfaces.
Definition interfacemanager.cpp:98
int createBridgeInterface(const std::string &interfaceName, bool sync=false)
creates a bridge interface.
Definition interfacemanager.cpp:227
void removeAddressListener(uint64_t id)
unregisters a previously registered address update callback.
Definition interfacemanager.cpp:161
uint64_t addRouteListener(const RouteNotify &cb)
registers a callback to be invoked when a route update occurs.
Definition interfacemanager.cpp:171
static InterfaceManager & instance()
get the a singleton instance.
Definition interfacemanager.cpp:62
void removeRouteListener(uint64_t id)
unregisters a previously registered route update callback.
Definition interfacemanager.cpp:181
int createVlanInterface(const std::string &interfaceName, uint32_t parentIndex, uint16_t id, uint16_t proto=ETH_P_8021Q, bool sync=false)
creates a VLAN interface.
Definition interfacemanager.cpp:263
InterfaceManager(const InterfaceManager &other)=delete
create instance by copy.
uint64_t addLinkListener(const LinkNotify &cb)
registers a callback to be invoked when a link update occurs.
Definition interfacemanager.cpp:131
int createGreInterface(const std::string &tunnelName, uint32_t parentIndex, const IpAddress &localAddress, const IpAddress &remoteAddress, const uint32_t *ikey=nullptr, const uint32_t *okey=nullptr, uint8_t ttl=64, bool sync=false)
creates a a GRE tunnel interface.
Definition interfacemanager.cpp:384
std::function< void(const RouteInfo &info)> RouteNotify
Definition interfacemanager.hpp:166
int createDummyInterface(const std::string &interfaceName, bool sync=false)
creates a dummy interface.
Definition interfacemanager.cpp:191
~InterfaceManager()
destroy instance.
Definition interfacemanager.cpp:53
InterfaceManager(InterfaceManager &&other)=delete
create instance by move.
InterfaceManager & operator=(const InterfaceManager &other)=delete
assign instance by copy.
interface class.
Definition interface.hpp:50
std::shared_ptr< Interface > Ptr
Definition interface.hpp:60
std::tuple< IpAddress, uint32_t, IpAddress, uint32_t > Route
Definition interface.hpp:63
std::tuple< IpAddress, uint32_t, IpAddress > Address
Definition interface.hpp:61
IPv6, IPv4 address class.
Definition ipaddress.hpp:51
MAC address class.
Definition macaddress.hpp:46
base class for netlink-based managers.
Definition netlinkmanager.hpp:49
Reactor * reactor() const noexcept
get the event loop reactor.
Definition netlinkmanager.cpp:52
Reactor class.
Definition reactor.hpp:120
Definition acceptor.hpp:32
std::vector< Interface::Ptr > InterfaceList
list of interfaces.
Definition interface.hpp:452
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
enumeration of interface change type.
Definition interfacemanager.hpp:44
InterfaceChangeType operator~(InterfaceChangeType a)
perform binary NOT on InterfaceChangeType.
Definition interfacemanager.hpp:95
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 on InterfaceChangeType.
Definition interfacemanager.hpp:128
IpAddress operator|(const IpAddress &a, const IpAddress &b)
perform OR operation on IP address.
Definition ipaddress.cpp:1692
address information.
Definition interfacemanager.hpp:146
Interface::Address address
Definition interfacemanager.hpp:147
link information.
Definition interfacemanager.hpp:137
InterfaceChangeType flags
Definition interfacemanager.hpp:139
Interface::Ptr interface
Definition interfacemanager.hpp:138
route information.
Definition interfacemanager.hpp:154
Interface::Route route
Definition interfacemanager.hpp:155