summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorsrijan-sivakumar <ssivakum@redhat.com>2020-07-18 05:59:09 +0530
committerAravinda Vishwanathapura <mail@aravindavk.in>2020-08-19 07:46:41 +0000
commit7c309928591deb8d0188793677958226ac03897a (patch)
tree0b125b2ebb181a2ca307586825b274e54f8e88e6 /libglusterfs
parent2b7455fe833e3dcb281030108bb2f97d4a220b26 (diff)
Events: Socket creation after getaddrinfo and IPv4 and IPv6 packet capture
Issue: Currently, the socket creation is done prior to getaddrinfo function being invoked. This can cause mismatch in the protocol and address families of the created socket and the result of the getaddrinfo api. Also, the glustereventsd UDP server by default only captures IPv4 packets hence IPv6 packets are not even captured. Code Changes: 1. Modified the socket creation in such a way that the parameters taken in are dependent upon the result of the getaddrinfo function. 2. Created a subclass for adding address family in glustereventsd.py for both AF_INET and AF_INET6. 3. Modified addresses in the eventsapiconf.py.in Reasoning behind the approach: 1. If we are using getaddrinfo function then socket creation should happen only after we check if we received back valid addresses. Hence socket creation should come after the call to getaddrinfo 2. The listening server which pushes the events to the webhook has to listen for both IPv4 and IPv6 messages as we would not be sure as to what address family is picked in _gf_event. Fixes: #1377 Change-Id: I568dcd1a977c8832f0fef981e1f81cac7043c760 Signed-off-by: srijan-sivakumar <ssivakum@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/events.c25
1 files changed, 17 insertions, 8 deletions
diff --git a/libglusterfs/src/events.c b/libglusterfs/src/events.c
index 908a318a8a1..6369e8f55be 100644
--- a/libglusterfs/src/events.c
+++ b/libglusterfs/src/events.c
@@ -51,13 +51,6 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
goto out;
}
- /* Initialize UDP socket */
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock < 0) {
- ret = EVENT_ERROR_SOCKET;
- goto out;
- }
-
if (ctx) {
volfile_server_transport = ctx->cmd_args.volfile_server_transport;
}
@@ -66,7 +59,6 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
}
/* host = NULL returns localhost */
- host = NULL;
if (ctx && ctx->cmd_args.volfile_server &&
(strcmp(volfile_server_transport, "unix"))) {
/* If it is client code then volfile_server is set
@@ -84,6 +76,23 @@ _gf_event(eventtypes_t event, const char *fmt, ...)
goto out;
}
+ // iterate over the result and break when socket creation is success.
+ for (; result != NULL; result = result->ai_next) {
+ sock = socket(result->ai_family, result->ai_socktype,
+ result->ai_protocol);
+ if (sock != -1) {
+ break;
+ }
+ }
+ /*
+ * If none of the addrinfo structures lead to a successful socket
+ * creation, socket creation has failed.
+ */
+ if (sock < 0) {
+ ret = EVENT_ERROR_SOCKET;
+ goto out;
+ }
+
va_start(arguments, fmt);
ret = gf_vasprintf(&msg, fmt, arguments);
va_end(arguments);