21 #include "softwarecontainer-common.h" 23 #include <linux/rtnetlink.h> 24 #include <arpa/inet.h> 40 LOG_DECLARE_CLASS_CONTEXT(
"NETL",
"Netlink");
42 typedef std::pair<rtattr, void*> AttributeInfo;
43 typedef std::vector<AttributeInfo> AttributeList;
44 typedef std::pair<ifinfomsg, AttributeList> LinkInfo;
45 typedef std::pair<ifaddrmsg, AttributeList> AddressInfo;
46 typedef std::pair<rtmsg, AttributeList> RouteInfo;
108 bool linkUp(
const int ifaceIndex);
117 bool linkDown(
const int ifaceIndex);
129 bool setIP(
const int ifaceIndex,
const in_addr ip,
const unsigned char netmask);
139 bool findLink(
const char *ifaceName, LinkInfo &linkInfo);
150 bool findAddresses(
const unsigned int interfaceIndex, std::vector<AddressInfo> &result);
162 bool hasAddress(
const std::vector<AddressInfo> &haystack,
const int addressFamily,
const char *needle);
191 template<
typename msgtype,
typename InfoType>
192 bool saveMessage(
const struct nlmsghdr &header, std::vector<InfoType> &result);
208 template<
typename msgtype>
209 bool getAttributes(
const struct nlmsghdr &header, AttributeList &result);
223 template<
typename payload>
struct netlink_request {
240 template<
typename payload>
241 netlink_request<payload> createMessage(
const int type,
const int flags);
262 template<
typename payload>
263 bool addAttribute(netlink_request<payload> &req,
const int type,
const size_t length,
const void *data);
276 template<
typename payload>
277 bool sendMessage(netlink_request<payload> &request);
291 void freeAttributes(AttributeList &attrList);
294 struct sockaddr_nl m_local;
295 struct sockaddr_nl m_kernel;
298 unsigned int m_sequenceNumber;
301 std::vector< LinkInfo > m_links;
302 std::vector< AddressInfo > m_addresses;
303 std::vector< RouteInfo > m_routes;
306 bool m_hasKernelDump;
307 bool m_netlinkInitialized;
virtual bool checkKernelDump()
check for a kernel dump, and if not present, try to get one
bool linkDown(const int ifaceIndex)
Bring a given interface down.
bool hasAddress(const std::vector< AddressInfo > &haystack, const int addressFamily, const char *needle)
checks if an address is present in the given list
Netlink()
Construct a new Netlink object.
bool getKernelDump()
get a dump of all links, addresses and routes from the kernel.
bool linkUp(const int ifaceIndex)
Bring the given interface up.
virtual ~Netlink()
release all resources held by the Netlink object
bool findAddresses(const unsigned int interfaceIndex, std::vector< AddressInfo > &result)
Get all addresses associated with the given interface index.
bool setDefaultGateway(const char *gatewayAddress)
Sets an ip address as the default gateway.
bool findLink(const char *ifaceName, LinkInfo &linkInfo)
Check that the device given is a network bridge.
bool setIP(const int ifaceIndex, const in_addr ip, const unsigned char netmask)
Sets an IP address for a network link.
Developers guide to adding a config item:
Handles various network operations over netlink.