Path.cpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * Copyright (c)2013-2020 ZeroTier, Inc.
  3. *
  4. * Use of this software is governed by the Business Source License included
  5. * in the LICENSE.TXT file in the project's root directory.
  6. *
  7. * Change Date: 2024-01-01
  8. *
  9. * On the date above, in accordance with the Business Source License, use
  10. * of this software will be governed by version 2.0 of the Apache License.
  11. */
  12. /****/
  13. #include "Path.hpp"
  14. #include "RuntimeEnvironment.hpp"
  15. #include "Node.hpp"
  16. namespace ZeroTier {
  17. bool Path::send(const RuntimeEnvironment *RR,void *tPtr,const void *data,unsigned int len,int64_t now)
  18. {
  19. if (RR->node->putPacket(tPtr,_localSocket,_addr,data,len)) {
  20. _lastOut = now;
  21. return true;
  22. }
  23. return false;
  24. }
  25. bool Path::isAddressValidForPath(const InetAddress &a)
  26. {
  27. if ((a.ss_family == AF_INET)||(a.ss_family == AF_INET6)) {
  28. switch(a.ipScope()) {
  29. /* Note: we don't do link-local at the moment. Unfortunately these
  30. * cause several issues. The first is that they usually require a
  31. * device qualifier, which we don't handle yet and can't portably
  32. * push in PUSH_DIRECT_PATHS. The second is that some OSes assign
  33. * these very ephemerally or otherwise strangely. So we'll use
  34. * private, pseudo-private, shared (e.g. carrier grade NAT), or
  35. * global IP addresses. */
  36. case InetAddress::IP_SCOPE_PRIVATE:
  37. case InetAddress::IP_SCOPE_PSEUDOPRIVATE:
  38. case InetAddress::IP_SCOPE_SHARED:
  39. case InetAddress::IP_SCOPE_GLOBAL:
  40. if (a.ss_family == AF_INET6) {
  41. // TEMPORARY HACK: for now, we are going to blacklist he.net IPv6
  42. // tunnels due to very spotty performance and low MTU issues over
  43. // these IPv6 tunnel links.
  44. const uint8_t *ipd = reinterpret_cast<const uint8_t *>(reinterpret_cast<const struct sockaddr_in6 *>(&a)->sin6_addr.s6_addr);
  45. if ((ipd[0] == 0x20)&&(ipd[1] == 0x01)&&(ipd[2] == 0x04)&&(ipd[3] == 0x70))
  46. return false;
  47. }
  48. return true;
  49. default:
  50. return false;
  51. }
  52. }
  53. return false;
  54. }
  55. } // namespace ZeroTier