Merge "Debian: Redfishtool requests fail when IPV4 address has square brackets"

This commit is contained in:
Zuul 2022-10-11 15:41:59 +00:00 committed by Gerrit Code Review
commit ad1c87669f
4 changed files with 68 additions and 5 deletions

View File

@ -1129,3 +1129,51 @@ int msgClassTx::initSocket()
}
return PASS;
}
/**
* Used to validate and distinguish between IPV4 and IPV6 addresses.
*
* @return PF_UNSPEC for unknown IP address format
* AF_INET for IPV4 addresses
* AF_INET6 for IPV6 addresses
*/
int get_address_ai_family ( const char * addr_ptr )
{
if ( addr_ptr == NULL )
{
slog ("null string pointer");
return ( PF_UNSPEC );
}
struct addrinfo *res = NULL;
struct addrinfo hint ;
MEMSET_ZERO ( hint);
hint.ai_family = PF_UNSPEC;
hint.ai_flags = AI_NUMERICHOST;
if ( getaddrinfo(addr_ptr, NULL, &hint, &res) )
{
wlog ("Invalid address: %s", addr_ptr );
return ( PF_UNSPEC );
}
int ai_family = res->ai_family ;
freeaddrinfo(res);
if ( ai_family == AF_INET )
{
dlog1 ("%s is an ipv4 address\n", addr_ptr );
}
else if ( ai_family == AF_INET6 )
{
dlog1 ("%s is an ipv6 address\n", addr_ptr );
}
else
{
slog ("unknown address format: %s ; ai_family:%d\n",
addr_ptr, ai_family );
ai_family = PF_UNSPEC ;
}
return (ai_family) ;
}

View File

@ -213,4 +213,7 @@ private:
int initSocket();
};
/* Used to validate and distinguish between IPV4 and IPV6 addresses */
int get_address_ai_family ( const char * addr_ptr );
#endif /* __INCLUDE_MSGCLASS_H__ */

View File

@ -16,6 +16,7 @@
using namespace std;
#include "nodeBase.h" /* for ... mtce node common definitions */
#include "msgClass.h" /* for ... get_address_ai_family */
#include "nodeUtil.h" /* for ... tolowercase */
#include "hostUtil.h" /* for ... mtce host common definitions */
#include "jsonUtil.h" /* for ... */
@ -353,10 +354,21 @@ string redfishUtil_create_request ( string cmd,
* defaulting to 20 sec timeout */
command_request.append(" -T 30");
/* specify the bmc ip address */
command_request.append(" -r [");
command_request.append(ip);
command_request.append("]");
/* The square brackets around the ip address in Debian
* cause the redfishtool request to fail */
if ( daemon_is_os_debian() && get_address_ai_family(ip.data()) == AF_INET )
{
/* add the bmc ip address option */
command_request.append(" -r ");
command_request.append(ip);
}
else
{
/* specify the bmc ip address option with square brackets */
command_request.append(" -r [");
command_request.append(ip);
command_request.append("]");
}
#ifdef WANT_INLINE_CREDS
if ( daemon_is_file_present ( MTC_CMD_FIT__INLINE_CREDS ) )

View File

@ -160,7 +160,7 @@ using namespace std;
#define THREAD_INIT_SIG (0xbabef00d)
#define MAX_PTHREADS (1) /* max number concurrent pthreads */
#define DEFAULT_THREAD_TIMEOUT_SECS (60) /* default pthread exec timout */
#define DEFAULT_THREAD_TIMEOUT_SECS (100) /* default pthread exec timout */
#define MAX_LOG_PREFIX_LEN (MAX_CHARS_ON_LINE)
#define THREAD_POST_KILL_WAIT (10) /* wait time between KILL and IDLE */