Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[config] Fix for regex in IpV4Adress #1850

Merged
merged 5 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 18 additions & 33 deletions ecal/core/include/ecal/config/transport_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,47 +33,32 @@ namespace eCAL
{
namespace UDP
{
namespace Network
struct MulticastConfiguration
{
struct Configuration
{
Types::IpAddressV4 group { "239.0.0.1" }; //!< UDP multicast group base (Default: 239.0.0.1)
unsigned int ttl { 3U }; /*!< UDP ttl value, also known as hop limit, is used in determining
the intermediate routers being traversed towards the destination (Default: 3) */
};
}

namespace Local
{
struct Configuration
{
Types::IpAddressV4 group { "127.255.255.255" }; //!< UDP multicast group base (Default: 127.255.255.255)
unsigned int ttl { 1U }; /*!< UDP ttl value, also known as hop limit, is used in determining
the intermediate routers being traversed towards the destination (Default: 1) */
};
}
Types::IpAddressV4 group{"239.0.0.1"}; //!< UDP multicast group base
unsigned int ttl; /*!< UDP ttl value, also known as hop limit, is used in determining
the intermediate routers being traversed towards the destination */
};

struct Configuration
{
Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.)
v1: default behavior
v2: new behavior, comes with a bit more intuitive handling regarding masking of the groups (Default: v2) */
unsigned int port { 14002 }; /*!< UDP multicast port number (Default: 14002) */
Types::UDPMode mode { Types::UDPMode::LOCAL }; /*!< Valid modes: local, network (Default: local)*/
Types::IpAddressV4 mask { "255.255.255.240" }; /*!< v1: Mask maximum number of dynamic multicast group (Default: 0.0.0.1-0.0.0.255)
v2: masks are now considered like routes masking (Default: 255.0.0.0-255.255.255.255)*/
Types::UdpConfigVersion config_version { Types::UdpConfigVersion::V2 }; /*!< UDP configuration version (Since eCAL 5.12.)
v1: default behavior
v2: new behavior, comes with a bit more intuitive handling regarding masking of the groups (Default: v2) */
unsigned int port { 14002 }; /*!< UDP multicast port number (Default: 14002) */
Types::UDPMode mode { Types::UDPMode::LOCAL }; /*!< Valid modes: local, network (Default: local)*/
Types::IpAddressV4 mask { "255.255.255.240" }; /*!< v1: Mask maximum number of dynamic multicast group (Default: 0.0.0.1-0.0.0.255)
v2: masks are now considered like routes masking (Default: 255.0.0.0-255.255.255.255)*/

unsigned int send_buffer { 5242880 }; //!< UDP send buffer in bytes (Default: 5242880)
unsigned int receive_buffer { 5242880 }; //!< UDP receive buffer in bytes (Default: 5242880)
bool join_all_interfaces { false }; /*!< Linux specific setting to enable joining multicast groups on all network interfacs
unsigned int send_buffer { 5242880 }; //!< UDP send buffer in bytes (Default: 5242880)
unsigned int receive_buffer { 5242880 }; //!< UDP receive buffer in bytes (Default: 5242880)
bool join_all_interfaces { false }; /*!< Linux specific setting to enable joining multicast groups on all network interfacs
independent of their link state. Enabling this makes sure that eCAL processes
receive data if they are started before network devices are up and running. (Default: false)*/
bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false)
bool npcap_enabled { false }; //!< Enable to receive UDP traffic with the Npcap based receiver (Default: false)

Network::Configuration network;
const Local::Configuration local;

ECAL_API Configuration& operator=(const Configuration& other);
MulticastConfiguration network { "239.0.0.1", 3U }; //!< default: "239.0.0.1", 3U
static const MulticastConfiguration local; //!< default: "127.255.255.255", 1U
};
}

Expand Down
1 change: 1 addition & 0 deletions ecal/core/include/ecal/types/ecal_custom_data_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace eCAL
{
public:
ECAL_API IpAddressV4(const std::string& ip_address_);
ECAL_API IpAddressV4(const char* ip_address_);

ECAL_API std::string Get() const;

Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/config/configuration_to_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,15 +220,15 @@ namespace YAML
return true;
}

Node convert<eCAL::TransportLayer::UDP::Network::Configuration>::encode(const eCAL::TransportLayer::UDP::Network::Configuration& config_)
Node convert<eCAL::TransportLayer::UDP::MulticastConfiguration>::encode(const eCAL::TransportLayer::UDP::MulticastConfiguration& config_)
{
Node node;
node["group"] = config_.group.Get();
node["ttl"] = config_.ttl;
return node;
}

bool convert<eCAL::TransportLayer::UDP::Network::Configuration>::decode(const Node& node_, eCAL::TransportLayer::UDP::Network::Configuration& config_)
bool convert<eCAL::TransportLayer::UDP::MulticastConfiguration>::decode(const Node& node_, eCAL::TransportLayer::UDP::MulticastConfiguration& config_)
{
AssignValue<std::string>(config_.group, node_, "group");
AssignValue<unsigned int>(config_.ttl, node_, "ttl");
Expand Down Expand Up @@ -265,7 +265,7 @@ namespace YAML
AssignValue<bool>(config_.join_all_interfaces, node_, "join_all_interfaces");
AssignValue<bool>(config_.npcap_enabled, node_, "npcap_enabled");

AssignValue<eCAL::TransportLayer::UDP::Network::Configuration>(config_.network, node_, "network");
AssignValue<eCAL::TransportLayer::UDP::MulticastConfiguration>(config_.network, node_, "network");
return true;
}

Expand Down
6 changes: 3 additions & 3 deletions ecal/core/src/config/configuration_to_yaml.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ namespace YAML
};

template<>
struct convert<eCAL::TransportLayer::UDP::Network::Configuration>
struct convert<eCAL::TransportLayer::UDP::MulticastConfiguration>
{
static Node encode(const eCAL::TransportLayer::UDP::Network::Configuration& config_);
static Node encode(const eCAL::TransportLayer::UDP::MulticastConfiguration& config_);

static bool decode(const Node& node_, eCAL::TransportLayer::UDP::Network::Configuration& config_);
static bool decode(const Node& node_, eCAL::TransportLayer::UDP::MulticastConfiguration& config_);
};

template<>
Expand Down
15 changes: 1 addition & 14 deletions ecal/core/src/config/transport_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,7 @@ namespace eCAL
{
namespace UDP
{
Configuration& Configuration::operator=(const Configuration& other)
{
config_version = other.config_version;
join_all_interfaces = other.join_all_interfaces;
mask = other.mask;
mode = other.mode;
network = other.network;
npcap_enabled = other.npcap_enabled;
port = other.port;
receive_buffer = other.receive_buffer;
send_buffer = other.send_buffer;

return *this;
}
const MulticastConfiguration Configuration::local { "127.255.255.255", 1U };
}
}
}
15 changes: 10 additions & 5 deletions ecal/core/src/types/ecal_custom_data_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

namespace{
const std::array<const std::regex, 3> INVALID_IPV4_ADDRESSES = {
std::regex("((255|[fF][fF])\\.){3}(255|[fF][fF])"), // 255.255.255.255
std::regex("((127|7[fF]).((0|00|000)\\.){2}(1|01|001))"), // 127.0.0.1
std::regex("((0|00|000)\\.){3}(0|00|000)") // 0.0.0.0
std::regex("^(((255)|([fF]{2}))\\.){3}((255)|([fF]{2}))$"), // 255.255.255.255
std::regex("((127|7[fF]).((0|00|000)\\.){2}(1|01|001))"), // 127.0.0.1
Peguen marked this conversation as resolved.
Show resolved Hide resolved
std::regex("((0|00|000)\\.){3}(0|00|000)") // 0.0.0.0
};
const std::regex IPV4_DEC_REGEX = std::regex("(([0-9]|[0-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])");
const std::regex IPV4_HEX_REGEX = std::regex("(([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])\\.){3}([0-9a-fA-F]|[0-9a-fA-F][0-9a-fA-F])");
const std::regex IPV4_DEC_REGEX = std::regex("^((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9][0-9]|[0-9])$");
const std::regex IPV4_HEX_REGEX = std::regex("^([0-9a-fA-F]{1,2}\\.){3}[0-9a-fA-F]{1,2}$");
}

namespace eCAL
Expand All @@ -48,6 +48,11 @@ namespace eCAL
validateIpString(ip_address_);
}

IpAddressV4::IpAddressV4(const char* ip_address_)
{
validateIpString(ip_address_);
}

void IpAddressV4::validateIpString(const std::string& ip_address_)
{
if ( std::regex_match(ip_address_, IPV4_DEC_REGEX)
Expand Down
Loading