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