Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
SUSE:SLE-12-SP2:Update
pacemaker
pacemaker-IP-addresses-messages.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File pacemaker-IP-addresses-messages.patch of Package pacemaker
commit 56e89a47eff249306765d95d246783e691e8ce11 Author: Ken Gaillot <kgaillot@redhat.com> Date: Thu Feb 16 11:35:11 2017 -0600 Log: cib,libcrmcommon,lrmd: handle IP addresses better in messages This exposes lib/common/remote.c:get_ip_str() as a new internal API crm_sockaddr2str(), and uses it wherever inet_ntoa() and inet_ntop() were used previously. Mainly, this reduces code duplication. It also takes cib/remote.c one step towards supporting IPv6 addresses. diff --git a/cib/remote.c b/cib/remote.c index 9c2b97219..901155224 100644 --- a/cib/remote.c +++ b/cib/remote.c @@ -285,7 +285,8 @@ cib_remote_listen(gpointer data) { int csock = 0; unsigned laddr; - struct sockaddr_in addr; + struct sockaddr_storage addr; + char ipstr[INET6_ADDRSTRLEN]; int ssock = *(int *)data; int flag; @@ -300,14 +301,15 @@ cib_remote_listen(gpointer data) laddr = sizeof(addr); memset(&addr, 0, sizeof(addr)); csock = accept(ssock, (struct sockaddr *)&addr, &laddr); - crm_debug("New %s connection from %s", - ssock == remote_tls_fd ? "secure" : "clear-text", inet_ntoa(addr.sin_addr)); - if (csock == -1) { - crm_err("accept socket failed"); + crm_perror(LOG_ERR, "Could not accept socket connection"); return TRUE; } + crm_sockaddr2str(&addr, ipstr); + crm_debug("New %s connection from %s", + ((ssock == remote_tls_fd)? "secure" : "clear-text"), ipstr); + if ((flag = fcntl(csock, F_GETFL)) >= 0) { if (fcntl(csock, F_SETFL, flag | O_NONBLOCK) < 0) { crm_err("fcntl() write failed"); diff --git a/include/crm_internal.h b/include/crm_internal.h index a8fee470e..96a68bdee 100644 --- a/include/crm_internal.h +++ b/include/crm_internal.h @@ -204,6 +204,7 @@ int crm_remote_tcp_connect(const char *host, int port); int crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */ int *timer_id, void *userdata, void (*callback) (void *userdata, int sock)); int crm_remote_accept(int ssock); +void crm_sockaddr2str(void *sa, char *s); # ifdef HAVE_GNUTLS_GNUTLS_H /*! diff --git a/lib/ais/plugin.c b/lib/ais/plugin.c index b8a2b9662..fe89f0310 100644 --- a/lib/ais/plugin.c +++ b/lib/ais/plugin.c @@ -674,22 +674,6 @@ pcmk_startup(struct corosync_api_v1 *init_with) return 0; } -/* - static void ais_print_node(const char *prefix, struct totem_ip_address *host) - { - int len = 0; - char *buffer = NULL; - - ais_malloc0(buffer, INET6_ADDRSTRLEN+1); - - inet_ntop(host->family, host->addr, buffer, INET6_ADDRSTRLEN); - - len = strlen(buffer); - ais_info("%s: %.*s", prefix, len, buffer); - ais_free(buffer); - } -*/ - #if 0 /* copied here for reference from exec/totempg.c */ char * diff --git a/lib/common/remote.c b/lib/common/remote.c index 2042f78f0..80a75818f 100644 --- a/lib/common/remote.c +++ b/lib/common/remote.c @@ -837,7 +837,7 @@ int crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */ int *timer_id, void *userdata, void (*callback) (void *userdata, int sock)) { - char buffer[256]; + char buffer[INET6_ADDRSTRLEN]; struct addrinfo *res = NULL; struct addrinfo *rp = NULL; struct addrinfo hints; @@ -882,20 +882,16 @@ crm_remote_tcp_connect_async(const char *host, int port, int timeout, /*ms */ continue; } - memset(buffer, 0, DIMOF(buffer)); + /* Set port appropriately for address family */ + /* (void*) casts avoid false-positive compiler alignment warnings */ if (addr->sa_family == AF_INET6) { - struct sockaddr_in6 *addr_in = (struct sockaddr_in6 *)(void*)addr; - - addr_in->sin6_port = htons(port); - inet_ntop(addr->sa_family, &addr_in->sin6_addr, buffer, DIMOF(buffer)); - + ((struct sockaddr_in6 *)(void*)addr)->sin6_port = htons(port); } else { - struct sockaddr_in *addr_in = (struct sockaddr_in *)(void*)addr; - - addr_in->sin_port = htons(port); - inet_ntop(addr->sa_family, &addr_in->sin_addr, buffer, DIMOF(buffer)); + ((struct sockaddr_in *)(void*)addr)->sin_port = htons(port); } + memset(buffer, 0, DIMOF(buffer)); + crm_sockaddr2str(addr, buffer); crm_info("Attempting to connect to remote server at %s:%d", buffer, port); if (callback) { @@ -928,29 +924,33 @@ crm_remote_tcp_connect(const char *host, int port) return crm_remote_tcp_connect_async(host, port, -1, NULL, NULL, NULL); } - -/* Convert a struct sockaddr address to a string, IPv4 and IPv6: */ - -static char * -get_ip_str(const struct sockaddr_storage * sa, char * s, size_t maxlen) +/*! + * \brief Convert an IP address (IPv4 or IPv6) to a string for logging + * + * \param[in] sa Socket address for IP + * \param[out] s Storage for at least INET6_ADDRSTRLEN bytes + * + * \note sa The socket address can be a pointer to struct sockaddr_in (IPv4), + * struct sockaddr_in6 (IPv6) or struct sockaddr_storage (either), + * as long as its sa_family member is set correctly. + */ +void +crm_sockaddr2str(void *sa, char *s) { - switch(((struct sockaddr *)sa)->sa_family) { + switch (((struct sockaddr*)sa)->sa_family) { case AF_INET: inet_ntop(AF_INET, &(((struct sockaddr_in *)sa)->sin_addr), - s, maxlen); + s, INET6_ADDRSTRLEN); break; case AF_INET6: inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)sa)->sin6_addr), - s, maxlen); + s, INET6_ADDRSTRLEN); break; default: - strncpy(s, "Unknown AF", maxlen); - return NULL; + strcpy(s, "<invalid>"); } - - return s; } int @@ -971,7 +971,7 @@ crm_remote_accept(int ssock) laddr = sizeof(addr); memset(&addr, 0, sizeof(addr)); csock = accept(ssock, (struct sockaddr *)&addr, &laddr); - get_ip_str(&addr, addr_str, INET6_ADDRSTRLEN); + crm_sockaddr2str(&addr, addr_str); crm_info("New remote connection from %s", addr_str); if (csock == -1) { diff --git a/lrmd/tls_backend.c b/lrmd/tls_backend.c index 552b1d29d..8c3643402 100644 --- a/lrmd/tls_backend.c +++ b/lrmd/tls_backend.c @@ -248,17 +248,9 @@ bind_and_listen(struct addrinfo *addr) int optval; int fd; int rc; - char buffer[256] = { 0, }; - - if (addr->ai_family == AF_INET6) { - struct sockaddr_in6 *addr_in = (struct sockaddr_in6 *)(void*)addr->ai_addr; - inet_ntop(addr->ai_family, &addr_in->sin6_addr, buffer, DIMOF(buffer)); - - } else { - struct sockaddr_in *addr_in = (struct sockaddr_in *)(void*)addr->ai_addr; - inet_ntop(addr->ai_family, &addr_in->sin_addr, buffer, DIMOF(buffer)); - } + char buffer[INET6_ADDRSTRLEN] = { 0, }; + crm_sockaddr2str(addr->ai_addr, buffer); crm_trace("Attempting to bind on address %s", buffer); fd = socket(addr->ai_family, addr->ai_socktype, addr->ai_protocol);
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor