Migrate is_valid_ipv4_addr() to a more generic function
It is now called is_valid_ip_addr() and expects an additional parameter for the address family.
This commit is contained in:
parent
a0dda67dfe
commit
b3494dcfc1
@ -982,7 +982,7 @@ parse_rc_param(fko_cli_options_t *options, const char *var_name, char * val)
|
||||
else /* Assume IP address and validate */
|
||||
{
|
||||
strlcpy(options->allow_ip_str, val, sizeof(options->allow_ip_str));
|
||||
if(! is_valid_ipv4_addr(options->allow_ip_str, strlen(options->allow_ip_str)))
|
||||
if(! is_valid_ip_addr(options->allow_ip_str, strlen(options->allow_ip_str), AF_INET))
|
||||
parse_error = -1;
|
||||
}
|
||||
}
|
||||
@ -1862,7 +1862,7 @@ validate_options(fko_cli_options_t *options)
|
||||
{
|
||||
options->resolve_ip_http_https = 0;
|
||||
|
||||
if(! is_valid_ipv4_addr(options->allow_ip_str, strlen(options->allow_ip_str)))
|
||||
if(! is_valid_ip_addr(options->allow_ip_str, strlen(options->allow_ip_str), AF_UNSPEC))
|
||||
{
|
||||
log_msg(LOG_VERBOSITY_ERROR,
|
||||
"Invalid allow IP specified for SPA access");
|
||||
@ -1872,7 +1872,7 @@ validate_options(fko_cli_options_t *options)
|
||||
|
||||
if (options->spoof_ip_src_str[0] != 0x00)
|
||||
{
|
||||
if(! is_valid_ipv4_addr(options->spoof_ip_src_str, strlen(options->spoof_ip_src_str)))
|
||||
if(! is_valid_ip_addr(options->spoof_ip_src_str, strlen(options->spoof_ip_src_str), AF_UNSPEC))
|
||||
{
|
||||
log_msg(LOG_VERBOSITY_ERROR, "Invalid spoof IP");
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
@ -820,7 +820,7 @@ set_nat_access(fko_ctx_t ctx, fko_cli_options_t *options, const char * const acc
|
||||
}
|
||||
|
||||
|
||||
if (is_valid_ipv4_addr(options->nat_access_str, hostlen) || is_valid_hostname(options->nat_access_str, hostlen))
|
||||
if (is_valid_ip_addr(options->nat_access_str, hostlen, AF_UNSPEC) || is_valid_hostname(options->nat_access_str, hostlen))
|
||||
{
|
||||
snprintf(nat_access_buf, MAX_LINE_LEN, NAT_ACCESS_STR_TEMPLATE,
|
||||
options->nat_access_str, access_port);
|
||||
|
||||
@ -122,7 +122,7 @@ is_valid_encoded_msg_len(const int len)
|
||||
/* Validate an IPv4 address
|
||||
*/
|
||||
int
|
||||
is_valid_ipv4_addr(const char * const ip_str, const int len)
|
||||
is_valid_ip_addr(const char * const ip_str, const int len, const int family)
|
||||
{
|
||||
const char *ndx = ip_str;
|
||||
char tmp_ip_str[MAX_IPV4_STR_LEN + 1] = {0};
|
||||
|
||||
@ -40,7 +40,7 @@
|
||||
*/
|
||||
int is_valid_encoded_msg_len(const int len);
|
||||
int is_valid_pt_msg_len(const int len);
|
||||
int is_valid_ipv4_addr(const char * const ip_str, const int len);
|
||||
int is_valid_ip_addr(const char * const ip_str, const int len, const int family);
|
||||
int is_valid_hostname(const char * const hostname_str, const int len);
|
||||
int is_base64(const unsigned char * const buf, const unsigned short int len);
|
||||
void hex_dump(const unsigned char *data, const int size);
|
||||
|
||||
@ -64,7 +64,7 @@ have_allow_ip(const char *msg)
|
||||
res = FKO_ERROR_INVALID_ALLOW_IP;
|
||||
|
||||
if(res == FKO_SUCCESS)
|
||||
if (! is_valid_ipv4_addr(ip_str, strlen(ip_str)))
|
||||
if (! is_valid_ip_addr(ip_str, strlen(ip_str), AF_INET))
|
||||
res = FKO_ERROR_INVALID_ALLOW_IP;
|
||||
|
||||
return(res);
|
||||
|
||||
@ -119,7 +119,7 @@ preprocess_spa_data(const fko_srv_options_t *opts, spa_pkt_info_t *spa_pkt, spa_
|
||||
|
||||
xff -= i - 1;
|
||||
|
||||
if (!is_valid_ipv4_addr(xff, strlen(xff)))
|
||||
if (!is_valid_ip_addr(xff, strlen(xff), AF_UNSPEC))
|
||||
log_msg(LOG_WARNING,
|
||||
"Error parsing X-Forwarded-For header: value '%s' is not an IP address",
|
||||
xff);
|
||||
@ -1088,8 +1088,8 @@ incoming_spa(fko_srv_options_t *opts)
|
||||
continue;
|
||||
}
|
||||
|
||||
if((spa_ip_demark-spadat.spa_message) < MIN_IPV4_STR_LEN-1
|
||||
|| (spa_ip_demark-spadat.spa_message) > MAX_IPV4_STR_LEN)
|
||||
if((spa_ip_demark-spadat.spa_message) < MIN_IPV46_STR_LEN-1
|
||||
|| (spa_ip_demark-spadat.spa_message) > MAX_IPV46_STR_LEN)
|
||||
{
|
||||
log_msg(LOG_WARNING,
|
||||
"[%s] (stanza #%d) Invalid source IP in SPA message, ignoring SPA packet",
|
||||
@ -1100,7 +1100,7 @@ incoming_spa(fko_srv_options_t *opts)
|
||||
strlcpy(spadat.spa_message_src_ip,
|
||||
spadat.spa_message, (spa_ip_demark-spadat.spa_message)+1);
|
||||
|
||||
if(! is_valid_ipv4_addr(spadat.spa_message_src_ip, strlen(spadat.spa_message_src_ip)))
|
||||
if(! is_valid_ip_addr(spadat.spa_message_src_ip, strlen(spadat.spa_message_src_ip), AF_UNSPEC))
|
||||
{
|
||||
log_msg(LOG_WARNING,
|
||||
"[%s] (stanza #%d) Invalid source IP in SPA message, ignoring SPA packet",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user