RoutingTable.hpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * ZeroTier One - Global Peer to Peer Ethernet
  3. * Copyright (C) 2011-2014 ZeroTier Networks LLC
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. *
  18. * --
  19. *
  20. * ZeroTier may be used and distributed under the terms of the GPLv3, which
  21. * are available at: http://www.gnu.org/licenses/gpl-3.0.html
  22. *
  23. * If you would like to embed ZeroTier into a commercial application or
  24. * redistribute it in a modified binary form, please contact ZeroTier Networks
  25. * LLC. Start here: http://www.zerotier.com/
  26. */
  27. #ifndef ZT_SYSTEMNETWORKSTACK_HPP
  28. #define ZT_SYSTEMNETWORKSTACK_HPP
  29. #include <stdint.h>
  30. #include <vector>
  31. #include <string>
  32. #include <set>
  33. #include "InetAddress.hpp"
  34. #include "NonCopyable.hpp"
  35. namespace ZeroTier {
  36. /**
  37. * Base class for OS-dependent interfaces to the system network configuration
  38. */
  39. class SystemNetworkStack : NonCopyable
  40. {
  41. public:
  42. struct RoutingTableEntry
  43. {
  44. char device[128];
  45. InetAddress destination;
  46. InetAddress gateway;
  47. unsigned int deviceMetric;
  48. };
  49. SystemNetworkStack() {}
  50. virtual ~SystemNetworkStack() {}
  51. /**
  52. * @return All routing table entries sorted in order of destination
  53. */
  54. virtual std::vector<RoutingTableEntry> routingTable() const = 0;
  55. /**
  56. * Add or update a routing table entry
  57. *
  58. * Note that metrics may only be changed at the device level,
  59. * so changes to deviceMetric are ignored.
  60. *
  61. * @param re Entry to add/update
  62. * @return True if successful
  63. */
  64. virtual bool addUpdateRoute(const RoutingTableEntry &re) = 0;
  65. /**
  66. * @param ifname Name of interface (Unix-style device or Windows device name)
  67. * @return Interface metric (higher = lower priority)
  68. */
  69. virtual unsigned int interfaceMetric(const char *ifname) const = 0;
  70. /**
  71. * @param ifname Name of interface (Unix-style device or Windows device name)
  72. * @param metric New metric (higher = lower priority)
  73. * @return True if successful
  74. */
  75. virtual bool setInterfaceMetric(const char *ifname,unsigned int metric) = 0;
  76. /**
  77. * @return Interface names sorted in ascending order
  78. */
  79. virtual std::vector<std::string> interfaces() const = 0;
  80. /**
  81. * @param ignoreInterfaces List of interfaces to exclude from fingerprint
  82. * @return Integer CRC-type fingerprint of current network environment
  83. */
  84. inline uint64_t networkEnvironmentFingerprint(const std::set<std::string> &ignoreInterfaces) const
  85. {
  86. std::vector<RoutingTableEntry> rtab(routingTable());
  87. };
  88. };
  89. } // namespace ZeroTier
  90. #endif