Skip to content

Commit

Permalink
Merge branch 'json-plugin-remove-ip-check' into 'master'
Browse files Browse the repository at this point in the history
json output: remove IP format checking in Config to allow domain names to be entered

See merge request monitoring/ipfixcol2!11
  • Loading branch information
Lukas955 committed Mar 12, 2024
2 parents 4ccdd42 + 72a79a3 commit 68f6277
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 35 deletions.
15 changes: 0 additions & 15 deletions src/plugins/output/json-kafka/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,21 +126,6 @@ static const struct fds_xml_args args_params[] = {
FDS_OPTS_END
};

/**
* \brief Check if a given string is a valid IPv4/IPv6 address
* \param[in] ip_addr Address to check
* \return True or false
*/
bool
Config::check_ip(const std::string &ip_addr)
{
in_addr ipv4;
in6_addr ipv6;

return (inet_pton(AF_INET, ip_addr.c_str(), &ipv4) == 1
|| inet_pton(AF_INET6, ip_addr.c_str(), &ipv6) == 1);
}

/**
* \brief Check one of 2 expected options
*
Expand Down
1 change: 0 additions & 1 deletion src/plugins/output/json-kafka/src/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ struct cfg_kafka : cfg_output {
/** Parsed configuration of an instance */
class Config {
private:
bool check_ip(const std::string &ip_addr);
bool check_or(const std::string &elem, const char *value, const std::string &val_true,
const std::string &val_false);
void check_validity();
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/output/json/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ with each other.
"``ncat -lk <local ip> <local port>``"

:``name``: Identification name of the output. Used only for readability.
:``ip``: IPv4/IPv6 address of the client
:``ip``: IP address or domain name of the client
:``port``: Remote port number
:``protocol``: Transport protocol: TCP or UDP (this field is case insensitive)
:``blocking``:
Expand Down
19 changes: 2 additions & 17 deletions src/plugins/output/json/src/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,21 +257,6 @@ static const struct fds_xml_args args_params[] = {
FDS_OPTS_END
};

/**
* \brief Check if a given string is a valid IPv4/IPv6 address
* \param[in] ip_addr Address to check
* \return True or false
*/
bool
Config::check_ip(const std::string &ip_addr)
{
in_addr ipv4;
in6_addr ipv6;

return (inet_pton(AF_INET, ip_addr.c_str(), &ipv4) == 1
|| inet_pton(AF_INET6, ip_addr.c_str(), &ipv6) == 1);
}

/**
* \brief Check one of 2 expected options
*
Expand Down Expand Up @@ -436,9 +421,9 @@ Config::parse_send(fds_xml_ctx_t *send)
throw std::runtime_error("Name of a <send> output must be defined!");
}

if (output.addr.empty() || !check_ip(output.addr)) {
if (output.addr.empty()) {
throw std::runtime_error("Value of the element <ip> of the output <send> '" + output.name
+ "' is not a valid IPv4/IPv6 address");
+ "' must be defined!");
}

outputs.sends.push_back(output);
Expand Down
1 change: 0 additions & 1 deletion src/plugins/output/json/src/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ struct cfg_syslog : cfg_output {
/** Parsed configuration of an instance */
class Config {
private:
bool check_ip(const std::string &ip_addr);
bool check_or(const std::string &elem, const char *value, const std::string &val_true,
const std::string &val_false);
bool is_syslog_ascii(const std::string &str);
Expand Down

0 comments on commit 68f6277

Please sign in to comment.