25#ifndef JOIN_FABRIC_INTERFACE_MANAGER_HPP
26#define JOIN_FABRIC_INTERFACE_MANAGER_HPP
279 int createVlanInterface (
const std::string& interfaceName, uint32_t parentIndex, uint16_t
id,
280 uint16_t proto = ETH_P_8021Q,
bool sync =
false);
291 int createVlanInterface (
const std::string& interfaceName,
const std::string& parentName, uint16_t
id,
292 uint16_t proto = ETH_P_8021Q,
bool sync =
false);
302 int createVethInterface (
const std::string& hostName,
const std::string& peerName, pid_t* pid =
nullptr,
318 const IpAddress& remoteAddress,
const uint32_t* ikey =
nullptr,
319 const uint32_t* okey =
nullptr, uint8_t ttl = 64,
bool sync =
false);
335 const uint32_t* ikey =
nullptr,
const uint32_t* okey =
nullptr, uint8_t ttl = 64,
352 int removeInterface (
const std::string& interfaceName,
bool sync =
false);
360 static void addPeerInfoData (
struct nlmsghdr* nlh,
const std::string& peerName);
369 int mtu (uint32_t interfaceIndex, uint32_t mtuBytes,
bool sync =
false);
378 int mac (uint32_t interfaceIndex,
const MacAddress& macAddress,
bool sync =
false);
387 int addToBridge (uint32_t interfaceIndex, uint32_t masterIndex,
bool sync =
false);
395 int removeFromBridge (uint32_t interfaceIndex,
bool sync =
false);
404 int enable (uint32_t interfaceIndex,
bool enabled =
true,
bool sync =
false);
415 int addAddress (uint32_t interfaceIndex,
const IpAddress& ipAddress, uint32_t prefix,
416 const IpAddress& broadcast = {},
bool sync =
false);
427 int removeAddress (uint32_t interfaceIndex,
const IpAddress& ipAddress, uint32_t prefix,
428 const IpAddress& broadcast = {},
bool sync =
false);
435 int dumpLink (
bool sync =
false);
442 int dumpAddress (
bool sync =
false);
448 void onMessage (
struct nlmsghdr* nlh)
override;
454 void onLinkMessage (
struct nlmsghdr* nlh);
468 void onAddressMessage (
struct nlmsghdr* nlh);
474 void notifyLinkUpdate (
const LinkInfo& info);
480 void notifyAddressUpdate (
const AddressInfo& info);
491 static constexpr uint16_t reservedVlanId = 0;
494 static constexpr uint16_t maxVlanId = 4094;
497 std::unordered_map<uint32_t, Interface::Ptr> _interfaces;
503 std::unordered_map<uint64_t, LinkNotify> _linkListeners;
506 std::unordered_map<uint64_t, AddressNotify> _addressListeners;
509 std::atomic<uint64_t> _listenerCounter{0};
interface manager class.
Definition interface_manager.hpp:154
int refresh()
refresh all data.
Definition interface_manager.cpp:117
Interface::Ptr findByName(const std::string &interfaceName)
find interface by name.
Definition interface_manager.cpp:89
int createVethInterface(const std::string &hostName, const std::string &peerName, pid_t *pid=nullptr, bool sync=false)
creates a Virtual Ethernet interface pair.
Definition interface_manager.cpp:328
std::function< void(const AddressInfo &info)> AddressNotify
Definition interface_manager.hpp:157
int removeInterface(uint32_t interfaceIndex, bool sync=false)
deletes the specified network interface.
Definition interface_manager.cpp:491
uint64_t addAddressListener(const AddressNotify &cb)
register a callback to be invoked when an address update occurs.
Definition interface_manager.cpp:159
void removeLinkListener(uint64_t id)
unregister a previously registered link update callback.
Definition interface_manager.cpp:147
Interface::Ptr findByIndex(uint32_t interfaceIndex)
find interface by index.
Definition interface_manager.cpp:72
std::function< void(const LinkInfo &info)> LinkNotify
Definition interface_manager.hpp:156
InterfaceList enumerate()
enumerate all interfaces.
Definition interface_manager.cpp:98
int createBridgeInterface(const std::string &interfaceName, bool sync=false)
creates a bridge interface.
Definition interface_manager.cpp:223
void removeAddressListener(uint64_t id)
unregister a previously registered address update callback.
Definition interface_manager.cpp:175
static InterfaceManager & instance()
get the singleton instance.
Definition interface_manager.cpp:62
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 interface_manager.cpp:259
InterfaceManager(const InterfaceManager &other)=delete
create instance by copy.
uint64_t addLinkListener(const LinkNotify &cb)
register a callback to be invoked when a link update occurs.
Definition interface_manager.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 GRE tunnel interface.
Definition interface_manager.cpp:380
InterfaceManager(Reactor &reactor=ReactorThread::reactor())
create instance.
Definition interface_manager.cpp:42
int createDummyInterface(const std::string &interfaceName, bool sync=false)
creates a dummy interface.
Definition interface_manager.cpp:187
~InterfaceManager()
destroy instance.
Definition interface_manager.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
IPv6, IPv4 address class.
Definition ip_address.hpp:51
MAC address class.
Definition mac_address.hpp:46
base class for netlink-based managers.
Definition netlink_manager.hpp:51
Reactor & reactor() const noexcept
get the event loop reactor.
Definition netlink_manager.cpp:52
static Reactor & reactor()
get the global Reactor instance.
Definition reactor.cpp:584
Reactor class.
Definition reactor.hpp:156
Definition acceptor.hpp:32
std::vector< Interface::Ptr > InterfaceList
list of interfaces.
Definition interface.hpp:394
IpAddress operator^(const IpAddress &a, const IpAddress &b)
perform XOR operation on IP address.
Definition ip_address.cpp:1719
constexpr const JsonReadMode & operator&=(JsonReadMode &a, JsonReadMode b) noexcept
perform binary AND on JsonReadMode.
Definition json.hpp:919
IpAddress operator&(const IpAddress &a, const IpAddress &b)
perform AND operation on IP address.
Definition ip_address.cpp:1665
InterfaceChangeType
enumeration of interface change type.
Definition interface_manager.hpp:44
InterfaceChangeType operator~(InterfaceChangeType a)
perform binary NOT on InterfaceChangeType.
Definition interface_manager.hpp:95
constexpr const JsonReadMode & operator|=(JsonReadMode &a, JsonReadMode b) noexcept
perform binary OR on JsonReadMode.
Definition json.hpp:930
const InterfaceChangeType & operator^=(InterfaceChangeType &a, InterfaceChangeType b)
perform binary XOR assignment on InterfaceChangeType.
Definition interface_manager.hpp:128
IpAddress operator|(const IpAddress &a, const IpAddress &b)
perform OR operation on IP address.
Definition ip_address.cpp:1692
address change notification payload.
Definition interface_manager.hpp:146
Interface::Address address
Definition interface_manager.hpp:147
IP address entry associated with an interface.
Definition interface.hpp:66
link change notification payload.
Definition interface_manager.hpp:137
InterfaceChangeType flags
Definition interface_manager.hpp:139
Interface::Ptr interface
Definition interface_manager.hpp:138