]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Add a simple load-tester utility to initiate over control socket
authorMartin Willi <martin@revosec.ch>
Thu, 18 Oct 2012 13:41:44 +0000 (15:41 +0200)
committerMartin Willi <martin@revosec.ch>
Thu, 29 Nov 2012 09:22:51 +0000 (10:22 +0100)
src/libcharon/plugins/load_tester/.gitignore [new file with mode: 0644]
src/libcharon/plugins/load_tester/Makefile.am
src/libcharon/plugins/load_tester/load_tester.c [new file with mode: 0644]

diff --git a/src/libcharon/plugins/load_tester/.gitignore b/src/libcharon/plugins/load_tester/.gitignore
new file mode 100644 (file)
index 0000000..bef0e63
--- /dev/null
@@ -0,0 +1 @@
+load-tester
index 0069fb5ab10334c3524579c763b82dade1848d68..0a5cada434b8092e2c748322567de73bfe6f95cd 100644 (file)
@@ -21,3 +21,6 @@ libstrongswan_load_tester_la_SOURCES = \
        load_tester_diffie_hellman.c load_tester_diffie_hellman.h
 
 libstrongswan_load_tester_la_LDFLAGS = -module -avoid-version
+
+ipsec_PROGRAMS = load-tester
+load_tester_SOURCES = load_tester.c
diff --git a/src/libcharon/plugins/load_tester/load_tester.c b/src/libcharon/plugins/load_tester/load_tester.c
new file mode 100644 (file)
index 0000000..fc41df7
--- /dev/null
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2012 Martin Willi
+ * Copyright (C) 2012 revosec AG
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ */
+
+#include "load_tester_control.h"
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+
+/**
+ * Connect to the daemon, return stream
+ */
+static FILE* make_connection()
+{
+       struct sockaddr_un addr;
+       FILE *stream;
+       int fd;
+
+       addr.sun_family = AF_UNIX;
+       strcpy(addr.sun_path, LOAD_TESTER_SOCKET);
+
+       fd = socket(AF_UNIX, SOCK_SEQPACKET, 0);
+       if (fd < 0)
+       {
+               fprintf(stderr, "opening socket failed: %s\n", strerror(errno));
+               return NULL;
+       }
+       if (connect(fd, (struct sockaddr *)&addr,
+                       offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path)) < 0)
+       {
+               fprintf(stderr, "connecting to %s failed: %s\n",
+                               LOAD_TESTER_SOCKET, strerror(errno));
+               close(fd);
+               return NULL;
+       }
+       stream = fdopen(fd, "r+");
+       if (!stream)
+       {
+               close(fd);
+               return NULL;
+       }
+       return stream;
+}
+
+/**
+ * Initiate load-tests
+ */
+static int initiate(unsigned int count)
+{
+       FILE *stream;
+       char c;
+
+       stream = make_connection();
+       if (!stream)
+       {
+               return 1;
+       }
+
+       fprintf(stream, "%u\n", count);
+
+       while (1)
+       {
+               fflush(stream);
+               c = fgetc(stream);
+               if (c == EOF)
+               {
+                       break;
+               }
+               if (fputc(c, stdout) == EOF)
+               {
+                       break;
+               }
+               fflush(stdout);
+       }
+       fclose(stream);
+       return 0;
+}
+
+int main(int argc, char *argv[])
+{
+       if (argc == 3 && strcmp(argv[1], "initiate") == 0)
+       {
+               return initiate(atoi(argv[2]));
+       }
+       fprintf(stderr, "Usage:\n");
+       fprintf(stderr, "  %s initiate <count>\n", argv[0]);
+       return 1;
+}