RoutingTable.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * ZeroTier One - Network Virtualization Everywhere
  3. * Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
  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. #ifndef ZT_ROUTINGTABLE_HPP
  19. #define ZT_ROUTINGTABLE_HPP
  20. #include <vector>
  21. #include "../node/Constants.hpp"
  22. #include "../node/InetAddress.hpp"
  23. namespace ZeroTier {
  24. class RoutingTable
  25. {
  26. public:
  27. struct Entry
  28. {
  29. /**
  30. * Destination IP and netmask bits (CIDR format)
  31. */
  32. InetAddress destination;
  33. /**
  34. * Gateway or null address if direct link-level route, netmask/port part of InetAddress not used
  35. */
  36. InetAddress gateway;
  37. /**
  38. * System device index or ID (not included in comparison operators, may not be set on all platforms)
  39. */
  40. int deviceIndex;
  41. /**
  42. * Metric or hop count -- higher = lower routing priority
  43. */
  44. int metric;
  45. /**
  46. * Interface scoped route? (always false if not meaningful on this OS)
  47. */
  48. bool ifscope;
  49. /**
  50. * System device name (may be empty if it doesn't exist or isn't important on this OS)
  51. */
  52. char device[128];
  53. /**
  54. * @return True if at least one required field is present (object is not null)
  55. */
  56. inline operator bool() const { return ((destination)||(gateway)); }
  57. };
  58. static std::vector<RoutingTableEntry> get(bool includeLinkLocal,bool includeLoopback);
  59. static RoutingTableEntry set(const InetAddress &destination,const InetAddress &gateway,const char *device,int metric,bool ifscope);
  60. };
  61. } // namespace ZeroTier
  62. #endif