From 871cd53f8f9b8c36eacbdfd546a0a4acba29e53b Mon Sep 17 00:00:00 2001 From: Ken-ichirou MATSUZAWA Date: Tue, 7 Oct 2014 13:40:08 +0900 Subject: qa: build unshared nfct environment nssocket forks and change netns pre-establishd by ip(8), serves its socket descriptor to parent via nssocket(). Since this socket is isolated, it can be used to create regression tests for conntrack. This also adds a conntrack event testcase as a first user. A ct_echo_event.sh script is provided to build and run this test automatically: # ./qa/ct_echo_event.sh make: Entering directory... ...debug output like: [NEW] tcp 6 2 SYN_SENT src=10.255.255.249 dst=10.255.255.250 sport... [UPDATE] tcp 6 2 SYN_RECV src=10.255.255.249 dst=10.255.255.250 sport... ... [DESTROY] icmp 1 src=10.255.255.249 dst=10.255.255.250 type=8 code=0... # echo $? 0 Signed-off-by: Ken-ichirou MATSUZAWA Signed-off-by: Florian Westphal --- qa/ct_echo_event.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 qa/ct_echo_event.c (limited to 'qa/ct_echo_event.c') diff --git a/qa/ct_echo_event.c b/qa/ct_echo_event.c new file mode 100644 index 0000000..6874395 --- /dev/null +++ b/qa/ct_echo_event.c @@ -0,0 +1,62 @@ +#include +#include +#include +#include +#include + +#include + +#include "nssocket.h" + +static void udp_echo(const struct mnl_socket *nl, + const char *pre, const char *post) +{ + u_int8_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) +{ + u_int8_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 \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(); +} -- cgit v1.2.3