summaryrefslogtreecommitdiffstats
path: root/tests/ct_echo_event.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2019-03-09 11:56:05 +0100
committerPablo Neira Ayuso <pablo@netfilter.org>2019-03-11 13:34:51 +0100
commit9c0ed46f68cada9f3455be91adb553d020012596 (patch)
tree249499eb5b3b977a29088b4bff905a82ce546a14 /tests/ct_echo_event.c
parente0d8a7cec8ba5ca8fed95eacb5c9f1166f386490 (diff)
Rename 'qa' directory to 'tests'
When searching for library tests, 'qa' is easily overlooked. Use a more common name instead. Suggested-by: Pablo Neira Ayuso <pablo@netfilter.org> Signed-off-by: Phil Sutter <phil@nwl.cc> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'tests/ct_echo_event.c')
-rw-r--r--tests/ct_echo_event.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/ct_echo_event.c b/tests/ct_echo_event.c
new file mode 100644
index 0000000..eb9c82f
--- /dev/null
+++ b/tests/ct_echo_event.c
@@ -0,0 +1,62 @@
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <netinet/in.h>
+
+#include <libmnl/libmnl.h>
+
+#include "nssocket.h"
+
+static void udp_echo(const struct mnl_socket *nl,
+ const char *pre, const char *post)
+{
+ uint8_t proto = IPPROTO_UDP;
+
+ sync_fifo(pre);
+ timeout.tv_sec = INIT_TIMEOUT;
+ handle_qacb(nl, true, cb_udp_new, &proto);
+ handle_qacb(nl, true, cb_udp_update, &proto);
+ handle_qacb(nl, true, cb_udp_destroy, &proto);
+ handle_qacb(nl, false, NULL, NULL);
+ sync_fifo(post);
+}
+
+static void icmp_echo(const struct mnl_socket *nl,
+ const char *pre, const char *post)
+{
+ uint8_t proto = IPPROTO_ICMP;
+
+ sync_fifo(pre);
+ timeout.tv_sec = INIT_TIMEOUT;
+ handle_qacb(nl, true, cb_icmp_new, &proto);
+ handle_qacb(nl, true, cb_icmp_update, &proto);
+ handle_qacb(nl, true, cb_icmp_destroy, &proto);
+ handle_qacb(nl, false, NULL, NULL);
+ sync_fifo(post);
+}
+
+int main(int argc, char *argv[])
+{
+ struct mnl_socket *nl;
+ char *pre, *post;
+
+ if (argc != 4) {
+ fprintf(stderr, "usage: %s <netns> <pre_fifo> <post_fifo>\n", argv[0]);
+ exit(EXIT_FAILURE);
+ }
+ pre = argv[2];
+ post = argv[3];
+
+ nl = mnl_event_nssocket(argv[1]);
+ if (nl == NULL) {
+ perror("init_mnl_socket");
+ exit(EXIT_FAILURE);
+ }
+
+ tcp_echo(nl, pre, post);
+ udp_echo(nl, pre, post);
+ icmp_echo(nl, pre, post);
+
+ return fini_nssocket();
+}