25#ifndef JOIN_FABRIC_INTERFACEMANAGER_HPP
26#define JOIN_FABRIC_INTERFACEMANAGER_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};
int mtu() const
get socket mtu.
Definition socket.hpp:1074
int ttl() const noexcept
returns the Time-To-Live value.
Definition socket.hpp:1112
interface manager class.
Definition interfacemanager.hpp:154
InterfaceManager(Reactor *reactor=nullptr)
create instance.
Definition interfacemanager.cpp:41
int refresh()
refresh all data.
Definition interfacemanager.cpp:116
Interface::Ptr findByName(const std::string &interfaceName)
find interface by name.
Definition interfacemanager.cpp:88
int createVethInterface(const std::string &hostName, const std::string &peerName, pid_t *pid=nullptr, bool sync=false)
creates a Virtual Ethernet interface pair.
Definition interfacemanager.cpp:323
std::function< void(const AddressInfo &info)> AddressNotify
Definition interfacemanager.hpp:157
int removeInterface(uint32_t interfaceIndex, bool sync=false)
deletes the specified network interface.
Definition interfacemanager.cpp:486
uint64_t addAddressListener(const AddressNotify &cb)
register a callback to be invoked when an address update occurs.
Definition interfacemanager.cpp:156
void removeLinkListener(uint64_t id)
unregister a previously registered link update callback.
Definition interfacemanager.cpp:145
Interface::Ptr findByIndex(uint32_t interfaceIndex)
find interface by index.
Definition interfacemanager.cpp:71
std::function< void(const LinkInfo &info)> LinkNotify
Definition interfacemanager.hpp:156
InterfaceList enumerate()
enumerate all interfaces.
Definition interfacemanager.cpp:97
int createBridgeInterface(const std::string &interfaceName, bool sync=false)
creates a bridge interface.
Definition interfacemanager.cpp:218
void removeAddressListener(uint64_t id)
unregister a previously registered address update callback.
Definition interfacemanager.cpp:171
static InterfaceManager & instance()
get the singleton instance.
Definition interfacemanager.cpp:61
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:254
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 interfacemanager.cpp:130
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 interfacemanager.cpp:375
int createDummyInterface(const std::string &interfaceName, bool sync=false)
creates a dummy interface.
Definition interfacemanager.cpp:182
~InterfaceManager()
destroy instance.
Definition interfacemanager.cpp:52
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 ipaddress.hpp:51
MAC address class.
Definition macaddress.hpp:46
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
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 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 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
address change notification payload.
Definition interfacemanager.hpp:146
Interface::Address address
Definition interfacemanager.hpp:147
IP address entry associated with an interface.
Definition interface.hpp:66
link change notification payload.
Definition interfacemanager.hpp:137
InterfaceChangeType flags
Definition interfacemanager.hpp:139
Interface::Ptr interface
Definition interfacemanager.hpp:138