1 #include <netlink/cli/utils.h>
2
change_cb(struct nl_cache * cache,struct nl_object * obj,int action,void * data)3 static void change_cb(struct nl_cache *cache, struct nl_object *obj,
4 int action, void *data)
5 {
6 struct nfnl_ct *ct = (struct nfnl_ct *) obj;
7 static struct nl_addr *hack = NULL;
8
9 if (!hack)
10 nl_addr_parse("194.88.212.233", AF_INET, &hack);
11
12 if (!nl_addr_cmp(hack, nfnl_ct_get_src(ct, 1)) ||
13 !nl_addr_cmp(hack, nfnl_ct_get_dst(ct, 1))) {
14 struct nl_dump_params dp = {
15 .dp_type = NL_DUMP_LINE,
16 .dp_fd = stdout,
17 };
18
19 printf("UPDATE ");
20 nl_object_dump(obj, &dp);
21 }
22 }
23
main(int argc,char * argv[])24 int main(int argc, char *argv[])
25 {
26 struct nl_cache_mngr *mngr;
27 struct nl_sock *sock;
28 struct nl_cache *ct;
29 int err;
30
31 sock = nl_cli_alloc_socket();
32
33 err = nl_cache_mngr_alloc(sock, NETLINK_NETFILTER, NL_AUTO_PROVIDE, &mngr);
34 if (err < 0) {
35 nl_perror(err, "nl_cache_mngr_alloc");
36 return -1;
37 }
38
39 err = nl_cache_mngr_add(mngr, "netfilter/ct", &change_cb, NULL, &ct);
40 if (err < 0) {
41 nl_perror(err, "nl_cache_mngr_add(netfilter/ct)");
42 return -1;
43 }
44
45 for (;;) {
46 int err = nl_cache_mngr_poll(mngr, 5000);
47 if (err < 0) {
48 nl_perror(err, "nl_cache_mngr_poll()");
49 return -1;
50 }
51
52 }
53
54 nl_cache_mngr_free(mngr);
55
56 return 0;
57 }
58