Skip to content

Commit

Permalink
Add IPv6 Support in libipmiconsole
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed Jan 13, 2017
1 parent 6695611 commit 961fcb1
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 159 deletions.
113 changes: 54 additions & 59 deletions libipmiconsole/ipmiconsole.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@

#include "freeipmi-portability.h"
#include "conffile.h"
#include "fi_hostlist.h"
#include "parse-common.h"
#include "secure.h"

Expand Down Expand Up @@ -836,10 +837,13 @@ ipmiconsole_engine_submit (ipmiconsole_ctx_t c,
callback_arg) < 0)
goto cleanup;

if (ipmiconsole_ctx_connection_setup (c) < 0)
/* session setup required before connection setup, so
* connection knows if IPv4 or IPv6 used
*/
if (ipmiconsole_ctx_session_setup (c) < 0)
goto cleanup;

if (ipmiconsole_ctx_session_setup (c) < 0)
if (ipmiconsole_ctx_connection_setup (c) < 0)
goto cleanup;

if (ipmiconsole_engine_submit_ctx (c) < 0)
Expand Down Expand Up @@ -1068,10 +1072,13 @@ ipmiconsole_engine_submit_block (ipmiconsole_ctx_t c)
/* Set to success, so we know if an IPMI error occurred later */
ipmiconsole_ctx_set_errnum (c, IPMICONSOLE_ERR_SUCCESS);

if (ipmiconsole_ctx_connection_setup (c) < 0)
/* session setup required before connection setup, so
* connection knows if IPv4 or IPv6 used
*/
if (ipmiconsole_ctx_session_setup (c) < 0)
goto cleanup;

if (ipmiconsole_ctx_session_setup (c) < 0)
if (ipmiconsole_ctx_connection_setup (c) < 0)
goto cleanup;

if (_ipmiconsole_blocking_notification_setup (c) < 0)
Expand Down Expand Up @@ -1153,9 +1160,12 @@ ipmiconsole_ctx_create (const char *hostname,
struct ipmiconsole_engine_config *engine_config)
{
ipmiconsole_ctx_t c = NULL;
char hostnamebuf[MAXHOSTNAMELEN_WITH_PORT + 1];
char *hostname_ptr;
char *hostname_copy = NULL;
char *port_copy = NULL;
const char *hostname_ptr = NULL;
const char *port_ptr = NULL;
uint16_t port = RMCP_PRIMARY_RMCP_PORT;
int ret;

if (!hostname
|| !ipmi_config
Expand Down Expand Up @@ -1184,70 +1194,46 @@ ipmiconsole_ctx_create (const char *hostname,
return (NULL);
}

if (strchr (hostname, ':'))
/* Check for host:port or [Ipv6]:port format */
if ((ret = fi_host_is_host_with_port (hostname,
&hostname_copy,
&port_copy)) < 0)
{
char *ptr;

if (strlen (hostname) > MAXHOSTNAMELEN_WITH_PORT)
{
IPMICONSOLE_DEBUG (("invalid input parameters"));
errno = EINVAL;
return (NULL);
}

memset (hostnamebuf, '\0', MAXHOSTNAMELEN_WITH_PORT + 1);
strcpy (hostnamebuf, hostname);

if ((ptr = strchr (hostnamebuf, ':')))
{
char *endptr;
int tmp;

*ptr = '\0';
ptr++;

if (strlen (hostnamebuf) > MAXHOSTNAMELEN)
{
IPMICONSOLE_DEBUG (("invalid input parameters"));
errno = EINVAL;
return (NULL);
}

errno = 0;
tmp = strtol (ptr, &endptr, 0);
if (errno
|| endptr[0] != '\0'
|| tmp <= 0
|| tmp > USHRT_MAX)
{
IPMICONSOLE_DEBUG (("invalid input parameters"));
errno = EINVAL;
return (NULL);
}

port = tmp;
}
IPMICONSOLE_DEBUG (("fi_host_is_host_with_port: %s", errno));
errno = EINVAL;
return (NULL);
}

hostname_ptr = hostnamebuf;
if (ret)
{
hostname_ptr = hostname_copy;
port_ptr = port_copy;
}
else
hostname_ptr = hostname;

if ((ret = fi_host_is_valid (hostname_ptr,
port_ptr,
&port)) < 0)
{
if (strlen (hostname) > MAXHOSTNAMELEN)
{
IPMICONSOLE_DEBUG (("invalid input parameters"));
errno = EINVAL;
return (NULL);
}
IPMICONSOLE_DEBUG (("fi_host_is_valid: %s", errno));
errno = EINVAL;
goto free_cleanup;
}

hostname_ptr = (char *)hostname;
if (!ret)
{
IPMICONSOLE_DEBUG (("invalid input parameters"));
errno = EINVAL;
goto free_cleanup;
}

/* If engine is not setup, the default_config is not yet known */
if (!ipmiconsole_engine_is_setup ())
{
IPMICONSOLE_DEBUG (("engine not initialized"));
errno = EAGAIN;
return (NULL);
goto free_cleanup;
}

if ((engine_config->engine_flags != IPMICONSOLE_ENGINE_DEFAULT
Expand All @@ -1257,15 +1243,15 @@ ipmiconsole_ctx_create (const char *hostname,
if (!(c = (ipmiconsole_ctx_t)secure_malloc (sizeof (struct ipmiconsole_ctx))))
{
errno = ENOMEM;
return (NULL);
goto free_cleanup;
}
}
else
{
if (!(c = (ipmiconsole_ctx_t)malloc (sizeof (struct ipmiconsole_ctx))))
{
errno = ENOMEM;
return (NULL);
goto free_cleanup;
}
}

Expand Down Expand Up @@ -1299,6 +1285,9 @@ ipmiconsole_ctx_create (const char *hostname,

c->session_submitted = 0;

free (hostname_copy);
free (port_copy);

ipmiconsole_ctx_set_errnum (c, IPMICONSOLE_ERR_SUCCESS);
return (c);

Expand All @@ -1321,6 +1310,12 @@ ipmiconsole_ctx_create (const char *hostname,
secure_free (c, sizeof (struct ipmiconsole_ctx));
else
free (c);

free_cleanup:

free (hostname_copy);
free (port_copy);

return (NULL);
}

Expand Down
Loading

0 comments on commit 961fcb1

Please sign in to comment.