libnetfilter_conntrack  1.0.6
ct_echo_event.c
1 #include <assert.h>
2 #include <errno.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <netinet/in.h>
6 
7 #include <libmnl/libmnl.h>
8 
9 #include "nssocket.h"
10 
11 static void udp_echo(const struct mnl_socket *nl,
12  const char *pre, const char *post)
13 {
14  uint8_t proto = IPPROTO_UDP;
15 
16  sync_fifo(pre);
17  timeout.tv_sec = INIT_TIMEOUT;
18  handle_qacb(nl, true, cb_udp_new, &proto);
19  handle_qacb(nl, true, cb_udp_update, &proto);
20  handle_qacb(nl, true, cb_udp_destroy, &proto);
21  handle_qacb(nl, false, NULL, NULL);
22  sync_fifo(post);
23 }
24 
25 static void icmp_echo(const struct mnl_socket *nl,
26  const char *pre, const char *post)
27 {
28  uint8_t proto = IPPROTO_ICMP;
29 
30  sync_fifo(pre);
31  timeout.tv_sec = INIT_TIMEOUT;
32  handle_qacb(nl, true, cb_icmp_new, &proto);
33  handle_qacb(nl, true, cb_icmp_update, &proto);
34  handle_qacb(nl, true, cb_icmp_destroy, &proto);
35  handle_qacb(nl, false, NULL, NULL);
36  sync_fifo(post);
37 }
38 
39 int main(int argc, char *argv[])
40 {
41  struct mnl_socket *nl;
42  char *pre, *post;
43 
44  if (argc != 4) {
45  fprintf(stderr, "usage: %s <netns> <pre_fifo> <post_fifo>\n", argv[0]);
46  exit(EXIT_FAILURE);
47  }
48  pre = argv[2];
49  post = argv[3];
50 
51  nl = mnl_event_nssocket(argv[1]);
52  if (nl == NULL) {
53  perror("init_mnl_socket");
54  exit(EXIT_FAILURE);
55  }
56 
57  tcp_echo(nl, pre, post);
58  udp_echo(nl, pre, post);
59  icmp_echo(nl, pre, post);
60 
61  return fini_nssocket();
62 }