blob: cbb016680b48d0e0388c6f5d2243b78ac698183c [file] [log] [blame]
Davide Pesavento9a8bae52016-02-24 20:33:08 +01001/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
Davide Pesavento50b92262018-07-11 12:28:31 -04002/*
3 * Copyright (c) 2013-2018 Regents of the University of California.
Davide Pesavento9a8bae52016-02-24 20:33:08 +01004 *
5 * This file is part of ndn-cxx library (NDN C++ library with eXperimental eXtensions).
6 *
7 * ndn-cxx library is free software: you can redistribute it and/or modify it under the
8 * terms of the GNU Lesser General Public License as published by the Free Software
9 * Foundation, either version 3 of the License, or (at your option) any later version.
10 *
11 * ndn-cxx library is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
13 * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
14 *
15 * You should have received copies of the GNU General Public License and GNU Lesser
16 * General Public License along with ndn-cxx, e.g., in COPYING.md file. If not, see
17 * <http://www.gnu.org/licenses/>.
18 *
19 * See AUTHORS.md for complete list of ndn-cxx authors and contributors.
Davide Pesavento2bf35a62017-04-02 00:41:06 -040020 *
21 * @author Davide Pesavento <davide.pesavento@lip6.fr>
Davide Pesavento9a8bae52016-02-24 20:33:08 +010022 */
23
Davide Pesavento50b92262018-07-11 12:28:31 -040024#ifndef NDN_NET_NETWORK_MONITOR_IMPL_NETLINK_HPP
25#define NDN_NET_NETWORK_MONITOR_IMPL_NETLINK_HPP
Davide Pesavento9a8bae52016-02-24 20:33:08 +010026
Davide Pesavento2bf35a62017-04-02 00:41:06 -040027#include "ndn-cxx-config.hpp"
Davide Pesavento9a8bae52016-02-24 20:33:08 +010028#include "../network-monitor.hpp"
29
Davide Pesavento2bf35a62017-04-02 00:41:06 -040030#ifndef NDN_CXX_HAVE_RTNETLINK
Davide Pesavento50b92262018-07-11 12:28:31 -040031#error "This file should not be included ..."
Davide Pesavento2bf35a62017-04-02 00:41:06 -040032#endif
33
Davide Pesaventoa0b2a2c2018-07-19 01:01:06 -040034#include "netlink-socket.hpp"
Davide Pesavento9a8bae52016-02-24 20:33:08 +010035
Davide Pesavento2bf35a62017-04-02 00:41:06 -040036#include <map>
37
Davide Pesavento9a8bae52016-02-24 20:33:08 +010038namespace ndn {
Junxiao Shi25467942017-06-30 02:53:14 +000039namespace net {
Davide Pesavento9a8bae52016-02-24 20:33:08 +010040
Davide Pesavento50b92262018-07-11 12:28:31 -040041class NetworkMonitorImplNetlink : public NetworkMonitorImpl
Davide Pesavento9a8bae52016-02-24 20:33:08 +010042{
43public:
Davide Pesavento2bf35a62017-04-02 00:41:06 -040044 /** \brief initialize netlink socket and start enumerating interfaces
45 */
Junxiao Shi2dc416d2017-07-03 04:46:16 +000046 explicit
Davide Pesavento50b92262018-07-11 12:28:31 -040047 NetworkMonitorImplNetlink(boost::asio::io_service& io);
Davide Pesavento9a8bae52016-02-24 20:33:08 +010048
Junxiao Shif4c1eb32017-05-30 17:05:10 +000049 uint32_t
Junxiao Shi2dc416d2017-07-03 04:46:16 +000050 getCapabilities() const final
Junxiao Shif4c1eb32017-05-30 17:05:10 +000051 {
52 return NetworkMonitor::CAP_ENUM |
53 NetworkMonitor::CAP_IF_ADD_REMOVE |
54 NetworkMonitor::CAP_STATE_CHANGE |
55 NetworkMonitor::CAP_MTU_CHANGE |
56 NetworkMonitor::CAP_ADDR_ADD_REMOVE;
57 }
58
Junxiao Shi2dc416d2017-07-03 04:46:16 +000059 shared_ptr<const NetworkInterface>
60 getNetworkInterface(const std::string& ifname) const final;
Davide Pesavento2bf35a62017-04-02 00:41:06 -040061
Junxiao Shi2dc416d2017-07-03 04:46:16 +000062 std::vector<shared_ptr<const NetworkInterface>>
63 listNetworkInterfaces() const final;
Davide Pesavento2bf35a62017-04-02 00:41:06 -040064
Davide Pesavento9a8bae52016-02-24 20:33:08 +010065private:
Davide Pesavento2bf35a62017-04-02 00:41:06 -040066 bool
67 isEnumerating() const;
68
Davide Pesavento9a8bae52016-02-24 20:33:08 +010069 void
Davide Pesaventoa0b2a2c2018-07-19 01:01:06 -040070 parseRtnlMessage(const NetlinkMessage& nlmsg);
Davide Pesavento2bf35a62017-04-02 00:41:06 -040071
72 void
Davide Pesavento50b92262018-07-11 12:28:31 -040073 parseLinkMessage(const NetlinkMessage& nlmsg);
Davide Pesavento2bf35a62017-04-02 00:41:06 -040074
75 void
Davide Pesavento50b92262018-07-11 12:28:31 -040076 parseAddressMessage(const NetlinkMessage& nlmsg);
Davide Pesavento2bf35a62017-04-02 00:41:06 -040077
78 void
Davide Pesavento50b92262018-07-11 12:28:31 -040079 parseRouteMessage(const NetlinkMessage& nlmsg);
80
81 void
82 parseErrorMessage(const NetlinkMessage& nlmsg);
Davide Pesavento2bf35a62017-04-02 00:41:06 -040083
Davide Pesavento9a8bae52016-02-24 20:33:08 +010084private:
Junxiao Shi2dc416d2017-07-03 04:46:16 +000085 std::map<int, shared_ptr<NetworkInterface>> m_interfaces; ///< ifindex => interface
Davide Pesaventoa0b2a2c2018-07-19 01:01:06 -040086 RtnlSocket m_rtnlSocket; ///< rtnetlink socket
Davide Pesavento10774992018-08-19 18:47:50 -040087 GenlSocket m_genlSocket; ///< generic netlink socket to communicate with nl80211
Davide Pesavento2bf35a62017-04-02 00:41:06 -040088 bool m_isEnumeratingLinks; ///< true if a dump of all links is in progress
89 bool m_isEnumeratingAddresses; ///< true if a dump of all addresses is in progress
Davide Pesavento9a8bae52016-02-24 20:33:08 +010090};
91
Junxiao Shi25467942017-06-30 02:53:14 +000092} // namespace net
Davide Pesavento9a8bae52016-02-24 20:33:08 +010093} // namespace ndn
94
Davide Pesavento50b92262018-07-11 12:28:31 -040095#endif // NDN_NET_NETWORK_MONITOR_IMPL_NETLINK_HPP