2020-05-12 08:35:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c)2013-2020 ZeroTier, Inc.
|
|
|
|
*
|
|
|
|
* Use of this software is governed by the Business Source License included
|
|
|
|
* in the LICENSE.TXT file in the project's root directory.
|
|
|
|
*
|
|
|
|
* Change Date: 2024-01-01
|
|
|
|
*
|
|
|
|
* On the date above, in accordance with the Business Source License, use
|
|
|
|
* of this software will be governed by version 2.0 of the Apache License.
|
|
|
|
*/
|
|
|
|
/****/
|
|
|
|
|
2020-06-17 21:54:13 +00:00
|
|
|
#ifndef ZT_LINK_HPP
|
|
|
|
#define ZT_LINK_HPP
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "../node/AtomicCounter.hpp"
|
|
|
|
|
|
|
|
namespace ZeroTier {
|
|
|
|
|
2020-06-17 21:54:13 +00:00
|
|
|
class Link
|
2020-05-12 08:35:48 +00:00
|
|
|
{
|
2020-06-17 21:54:13 +00:00
|
|
|
friend class SharedPtr<Link>;
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2020-06-17 21:54:13 +00:00
|
|
|
Link() {}
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param ifnameStr
|
|
|
|
* @param ipvPref
|
|
|
|
* @param speed
|
|
|
|
* @param enabled
|
|
|
|
* @param mode
|
2020-06-17 21:54:13 +00:00
|
|
|
* @param failoverToLinkStr
|
2020-05-12 08:35:48 +00:00
|
|
|
* @param userSpecifiedAlloc
|
|
|
|
*/
|
2020-06-17 21:54:13 +00:00
|
|
|
Link(std::string& ifnameStr,
|
2020-05-12 08:35:48 +00:00
|
|
|
uint8_t ipvPref,
|
|
|
|
uint32_t speed,
|
2020-06-17 21:54:13 +00:00
|
|
|
uint32_t linkMonitorInterval,
|
2020-05-12 08:35:48 +00:00
|
|
|
uint32_t upDelay,
|
|
|
|
uint32_t downDelay,
|
|
|
|
bool enabled,
|
|
|
|
uint8_t mode,
|
2020-06-17 21:54:13 +00:00
|
|
|
std::string failoverToLinkStr,
|
2020-05-12 08:35:48 +00:00
|
|
|
float userSpecifiedAlloc) :
|
|
|
|
_ifnameStr(ifnameStr),
|
|
|
|
_ipvPref(ipvPref),
|
|
|
|
_speed(speed),
|
|
|
|
_relativeSpeed(0),
|
2020-06-17 21:54:13 +00:00
|
|
|
_linkMonitorInterval(linkMonitorInterval),
|
2020-05-12 08:35:48 +00:00
|
|
|
_upDelay(upDelay),
|
|
|
|
_downDelay(downDelay),
|
|
|
|
_enabled(enabled),
|
|
|
|
_mode(mode),
|
2020-06-17 21:54:13 +00:00
|
|
|
_failoverToLinkStr(failoverToLinkStr),
|
2020-05-12 08:35:48 +00:00
|
|
|
_userSpecifiedAlloc(userSpecifiedAlloc),
|
|
|
|
_isUserSpecified(false)
|
|
|
|
{}
|
2020-05-15 03:09:25 +00:00
|
|
|
|
2020-05-12 08:35:48 +00:00
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The string representation of this link's underlying interface's system name.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline std::string ifname() { return _ifnameStr; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return Whether this link is designated as a primary.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline bool primary() { return _mode == ZT_MULTIPATH_SLAVE_MODE_PRIMARY; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return Whether this link is designated as a spare.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline bool spare() { return _mode == ZT_MULTIPATH_SLAVE_MODE_SPARE; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The name of the link interface that should be used in the event of a failure.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
2020-06-17 21:54:13 +00:00
|
|
|
inline std::string failoverToLink() { return _failoverToLinkStr; }
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return Whether this link interface was specified by the user or auto-detected.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline bool isUserSpecified() { return _isUserSpecified; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* Signify that this link was specified by the user and not the result of auto-detection.
|
2020-05-12 08:35:48 +00:00
|
|
|
*
|
|
|
|
* @param isUserSpecified
|
|
|
|
*/
|
|
|
|
inline void setAsUserSpecified(bool isUserSpecified) { _isUserSpecified = isUserSpecified; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return Whether or not the user has specified failover instructions.
|
|
|
|
*/
|
2020-06-17 21:54:13 +00:00
|
|
|
inline bool userHasSpecifiedFailoverInstructions() { return _failoverToLinkStr.length(); }
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The speed of the link relative to others in the bond.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline uint8_t relativeSpeed() { return _relativeSpeed; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* Sets the speed of the link relative to others in the bond.
|
2020-05-12 08:35:48 +00:00
|
|
|
*
|
2020-06-17 21:54:13 +00:00
|
|
|
* @param relativeSpeed The speed relative to the rest of the link.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline void setRelativeSpeed(uint8_t relativeSpeed) { _relativeSpeed = relativeSpeed; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* Sets the speed of the link relative to others in the bond.
|
2020-05-12 08:35:48 +00:00
|
|
|
*
|
|
|
|
* @param relativeSpeed
|
|
|
|
*/
|
2020-06-17 21:54:13 +00:00
|
|
|
inline void setMonitorInterval(uint32_t interval) { _linkMonitorInterval = interval; }
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The absolute speed of the link (as specified by the user.)
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
2020-06-17 21:54:13 +00:00
|
|
|
inline uint32_t monitorInterval() { return _linkMonitorInterval; }
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The absolute speed of the link (as specified by the user.)
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline uint32_t speed() { return _speed; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The address preference for this link (as specified by the user.)
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline uint8_t ipvPref() { return _ipvPref; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The mode (e.g. primary/spare) for this link (as specified by the user.)
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline uint8_t mode() { return _mode; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The upDelay parameter for all paths on this link.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline uint32_t upDelay() { return _upDelay; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return The downDelay parameter for all paths on this link.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline uint32_t downDelay() { return _downDelay; }
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* @return Whether this link is enabled or disabled
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
inline uint8_t enabled() { return _enabled; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* String representation of underlying interface's system name
|
|
|
|
*/
|
|
|
|
std::string _ifnameStr;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* What preference (if any) a user has for IP protocol version used in
|
|
|
|
* path aggregations. Preference is expressed in the order of the digits:
|
2020-05-15 03:09:25 +00:00
|
|
|
*
|
2020-05-12 08:35:48 +00:00
|
|
|
* 0: no preference
|
|
|
|
* 4: IPv4 only
|
|
|
|
* 6: IPv6 only
|
|
|
|
* 46: IPv4 over IPv6
|
|
|
|
* 64: IPv6 over IPv4
|
|
|
|
*/
|
|
|
|
uint8_t _ipvPref;
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* User-specified speed of this link
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
uint32_t _speed;
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* Speed relative to other specified links (computed by Bond)
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
uint8_t _relativeSpeed;
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* User-specified interval for monitoring paths on this specific link
|
2020-05-12 08:35:48 +00:00
|
|
|
* instead of using the more generic interval specified for the entire
|
|
|
|
* bond.
|
|
|
|
*/
|
2020-06-17 21:54:13 +00:00
|
|
|
uint32_t _linkMonitorInterval;
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* How long before a path is considered to be usable after coming online. (when using policies that
|
|
|
|
* support fail-over events).
|
|
|
|
*/
|
|
|
|
uint32_t _upDelay;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* How long before a path is considered to be dead (when using policies that
|
|
|
|
* support fail-over events).
|
|
|
|
*/
|
|
|
|
uint32_t _downDelay;
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* Whether this link is enabled, or (disabled (possibly bad config))
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
uint8_t _enabled;
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* Whether this link is designated as a primary, a spare, or no preference.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
|
|
|
uint8_t _mode;
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* The specific name of the link to be used in the event that this
|
|
|
|
* link fails.
|
2020-05-12 08:35:48 +00:00
|
|
|
*/
|
2020-06-17 21:54:13 +00:00
|
|
|
std::string _failoverToLinkStr;
|
2020-05-12 08:35:48 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* User-specified allocation
|
|
|
|
*/
|
|
|
|
float _userSpecifiedAlloc;
|
|
|
|
|
|
|
|
/**
|
2020-06-17 21:54:13 +00:00
|
|
|
* Whether or not this link was created as a result of manual user specification. This is
|
2020-05-12 08:35:48 +00:00
|
|
|
* important to know because certain policy decisions are dependent on whether the user
|
|
|
|
* intents to use a specific set of interfaces.
|
|
|
|
*/
|
|
|
|
bool _isUserSpecified;
|
|
|
|
|
|
|
|
AtomicCounter __refCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ZeroTier
|
|
|
|
|
|
|
|
#endif
|