blob: 45b6ec1a2345cd2eeb9b662c61f3b96b2a7f9002 [file] [log] [blame]
Ratan Gupta233524c2017-05-27 11:47:31 +05301#pragma once
Ratan Gupta233524c2017-05-27 11:47:31 +05302#include <linux/netlink.h>
3
Ratan Gupta233524c2017-05-27 11:47:31 +05304#include <map>
Patrick Venture189d44e2018-07-09 12:30:59 -07005#include <string>
William A. Kennington IIIe0b8fd62021-10-23 14:35:08 -07006#include <string_view>
Ratan Gupta233524c2017-05-27 11:47:31 +05307
8namespace phosphor
9{
10namespace network
11{
12namespace route
13{
Ratan Gupta233524c2017-05-27 11:47:31 +053014class Table
15{
Gunnar Mills57d9c502018-09-14 14:42:34 -050016 public:
William A. Kennington IIIe0564842021-10-23 16:02:22 -070017 /** @brief Rebuilds the routing table from the kernel */
18 void refresh();
Ratan Gupta233524c2017-05-27 11:47:31 +053019
Gunnar Mills57d9c502018-09-14 14:42:34 -050020 /**
William A. Kennington IIId3c249c2019-02-01 21:12:02 -080021 * @brief gets the default v4 gateway.
Gunnar Mills57d9c502018-09-14 14:42:34 -050022 *
Ravi Tejaa5a09442020-07-17 00:57:33 -050023 * @returns the default v4 gateway list.
Gunnar Mills57d9c502018-09-14 14:42:34 -050024 */
William A. Kennington IIIe0564842021-10-23 16:02:22 -070025 inline const auto& getDefaultGateway() const
Gunnar Mills57d9c502018-09-14 14:42:34 -050026 {
27 return defaultGateway;
William A. Kennington IIIe0564842021-10-23 16:02:22 -070028 }
Ratan Gupta233524c2017-05-27 11:47:31 +053029
Gunnar Mills57d9c502018-09-14 14:42:34 -050030 /**
William A. Kennington IIId3c249c2019-02-01 21:12:02 -080031 * @brief gets the default v6 gateway.
32 *
Ravi Tejaa5a09442020-07-17 00:57:33 -050033 * @returns the default v6 gateway list.
William A. Kennington IIId3c249c2019-02-01 21:12:02 -080034 */
William A. Kennington IIIe0564842021-10-23 16:02:22 -070035 inline const auto& getDefaultGateway6() const
William A. Kennington IIId3c249c2019-02-01 21:12:02 -080036 {
37 return defaultGateway6;
38 };
39
Gunnar Mills57d9c502018-09-14 14:42:34 -050040 private:
41 /**
Gunnar Mills57d9c502018-09-14 14:42:34 -050042 * @brief Parse the route and add it to the route list.
43 *
44 * @param[in] nlHdr - net link message header.
45 */
William A. Kennington IIIe0b8fd62021-10-23 14:35:08 -070046 void parseRoutes(const struct nlmsghdr& nlHdr, std::string_view msg);
Ratan Gupta233524c2017-05-27 11:47:31 +053047
Ravi Tejaa5a09442020-07-17 00:57:33 -050048 std::map<std::string, std::string> defaultGateway; // default gateway list
49 std::map<std::string, std::string> defaultGateway6; // default gateway list
Ratan Gupta233524c2017-05-27 11:47:31 +053050};
51
Gunnar Mills57d9c502018-09-14 14:42:34 -050052} // namespace route
53} // namespace network
54} // namespace phosphor