diff --git a/mtce-common/src/common/msgClass.cpp b/mtce-common/src/common/msgClass.cpp index b11201f8..ff967a40 100644 --- a/mtce-common/src/common/msgClass.cpp +++ b/mtce-common/src/common/msgClass.cpp @@ -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) ; +} diff --git a/mtce-common/src/common/msgClass.h b/mtce-common/src/common/msgClass.h index abcc88a7..e35fdc4c 100644 --- a/mtce-common/src/common/msgClass.h +++ b/mtce-common/src/common/msgClass.h @@ -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__ */ diff --git a/mtce-common/src/common/redfishUtil.cpp b/mtce-common/src/common/redfishUtil.cpp index 4ceb33e5..5bdfd758 100644 --- a/mtce-common/src/common/redfishUtil.cpp +++ b/mtce-common/src/common/redfishUtil.cpp @@ -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 ) ) diff --git a/mtce-common/src/common/threadUtil.h b/mtce-common/src/common/threadUtil.h index 2cbabe41..b2558fd3 100644 --- a/mtce-common/src/common/threadUtil.h +++ b/mtce-common/src/common/threadUtil.h @@ -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 */