summaryrefslogtreecommitdiff
path: root/osdep/ManagedRoute.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'osdep/ManagedRoute.hpp')
-rw-r--r--osdep/ManagedRoute.hpp63
1 files changed, 18 insertions, 45 deletions
diff --git a/osdep/ManagedRoute.hpp b/osdep/ManagedRoute.hpp
index 63310f24..fd77a79a 100644
--- a/osdep/ManagedRoute.hpp
+++ b/osdep/ManagedRoute.hpp
@@ -6,23 +6,34 @@
#include "../node/InetAddress.hpp"
#include "../node/Utils.hpp"
+#include "../node/SharedPtr.hpp"
+#include "../node/AtomicCounter.hpp"
+#include "../node/NonCopyable.hpp"
#include <stdexcept>
#include <vector>
+#include <map>
namespace ZeroTier {
/**
* A ZT-managed route that used C++ RAII semantics to automatically clean itself up on deallocate
*/
-class ManagedRoute
+class ManagedRoute : NonCopyable
{
+ friend class SharedPtr<ManagedRoute>;
+
public:
- ManagedRoute()
+ ManagedRoute(const InetAddress &target,const InetAddress &via,const char *device)
{
- _device[0] = (char)0;
+ _target = target;
+ _via = via;
+ if (via.ss_family == AF_INET)
+ _via.setPort(32);
+ else if (via.ss_family == AF_INET6)
+ _via.setPort(128);
+ Utils::scopy(_device,sizeof(_device),device);
_systemDevice[0] = (char)0;
- _applied = false;
}
~ManagedRoute()
@@ -30,45 +41,6 @@ public:
this->remove();
}
- ManagedRoute(const ManagedRoute &r)
- {
- _applied = false;
- *this = r;
- }
-
- inline ManagedRoute &operator=(const ManagedRoute &r)
- {
- if ((!_applied)&&(!r._applied)) {
- memcpy(this,&r,sizeof(ManagedRoute)); // InetAddress is memcpy'able
- } else {
- fprintf(stderr,"Applied ManagedRoute isn't copyable!\n");
- abort();
- }
- return *this;
- }
-
- /**
- * Initialize object and set route
- *
- * Note: on Windows, use the interface NET_LUID in hexadecimal as the
- * "device name."
- *
- * @param target Route target (e.g. 0.0.0.0/0 for default)
- * @param via Route next L3 hop or NULL InetAddress if local in which case it will be routed via device
- * @param device Name or hex LUID of ZeroTier device (e.g. zt#)
- * @return True if route was successfully set
- */
- inline bool set(const InetAddress &target,const InetAddress &via,const char *device)
- {
- if ((!via)&&(!device[0]))
- return false;
- this->remove();
- _target = target;
- _via = via;
- Utils::scopy(_device,sizeof(_device),device);
- return this->sync();
- }
-
/**
* Set or update currently set route
*
@@ -93,13 +65,14 @@ public:
inline const char *device() const { return _device; }
private:
-
InetAddress _target;
InetAddress _via;
InetAddress _systemVia; // for route overrides
+ std::map<InetAddress,bool> _applied; // routes currently applied
char _device[128];
char _systemDevice[128]; // for route overrides
- bool _applied;
+
+ AtomicCounter __refCount;
};
} // namespace ZeroTier