diff options
author | Martin Willi <martin@revosec.ch> | 2012-10-18 15:41:44 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2012-11-29 10:22:51 +0100 |
commit | 965f7bd54faf3e3b6fe4fe2eee9c58e8291af4e0 (patch) | |
tree | dbff55de5ed2014157deb041d35e7aad0edd1e58 | |
parent | d65683eef4879153e38c0de5fcffe7d5d42de13c (diff) | |
download | strongswan-965f7bd54faf3e3b6fe4fe2eee9c58e8291af4e0.tar.bz2 strongswan-965f7bd54faf3e3b6fe4fe2eee9c58e8291af4e0.tar.xz |
Add a simple load-tester utility to initiate over control socket
-rw-r--r-- | src/libcharon/plugins/load_tester/.gitignore | 1 | ||||
-rw-r--r-- | src/libcharon/plugins/load_tester/Makefile.am | 3 | ||||
-rw-r--r-- | src/libcharon/plugins/load_tester/load_tester.c | 104 |
3 files changed, 108 insertions, 0 deletions
diff --git a/src/libcharon/plugins/load_tester/.gitignore b/src/libcharon/plugins/load_tester/.gitignore new file mode 100644 index 000000000..bef0e6344 --- /dev/null +++ b/src/libcharon/plugins/load_tester/.gitignore @@ -0,0 +1 @@ +load-tester diff --git a/src/libcharon/plugins/load_tester/Makefile.am b/src/libcharon/plugins/load_tester/Makefile.am index 0069fb5ab..0a5cada43 100644 --- a/src/libcharon/plugins/load_tester/Makefile.am +++ b/src/libcharon/plugins/load_tester/Makefile.am @@ -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 index 000000000..fc41df76a --- /dev/null +++ b/src/libcharon/plugins/load_tester/load_tester.c @@ -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; +} |