2 * src/nf-ct-dump.c Dump conntrack attributes
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10 * Copyright (c) 2007 Philip Craig <philipc@snapgear.com>
11 * Copyright (c) 2007 Secure Computing Corporation
15 #include <netlink/netfilter/ct.h>
16 #include <linux/netfilter/nf_conntrack_common.h>
20 static void print_usage(void)
23 "Usage: nf-ct-dump <mode> [<filter>]\n"
24 " mode := { brief | detailed | stats | xml }\n"
25 " filter := [family FAMILY] [proto PROTO] [tcpstate TCPSTATE]\n"
26 " [status STATUS] [timeout TIMEOUT] [mark MARK] [use USE] [id ID]\n"
27 " [origsrc ADDR] [origdst ADDR] [origsrcport PORT] [origdstport PORT]\n"
28 " [origicmpid ID] [origicmptype TYPE] [origicmpcode CODE]\n"
29 " [origpackets PACKETS] [origbytes BYTES]\n"
30 " [replysrc ADDR] [replydst ADDR] [replysrcport PORT] [replydstport PORT]\n"
31 " [replyicmpid ID] [replyicmptype TYPE] [replyicmpcode CODE]\n"
32 " [replypackets PACKETS] [replybytes BYTES]\n"
33 " [{ replied | unreplied }] [{ assured | unassured }]\n"
38 int main(int argc, char *argv[])
40 struct nl_handle *nlh;
41 struct nl_cache *ct_cache;
43 struct nl_dump_params params = {
45 .dp_type = NL_DUMP_BRIEF
49 if (nltool_init(argc, argv) < 0)
52 if (argc < 2 || !strcmp(argv[1], "-h"))
55 nlh = nltool_alloc_handle();
63 if (nltool_connect(nlh, NETLINK_NETFILTER) < 0)
66 ct_cache = nfnl_ct_alloc_cache(nlh);
68 fprintf(stderr, "Unable to retrieve ct cache: %s\n",
72 nl_cache_mngt_provide(ct_cache);
74 params.dp_type = nltool_parse_dumptype(argv[1]);
75 if (params.dp_type < 0)
78 get_filter(ct, argc, argv, 2);
79 nl_cache_dump_filter(ct_cache, ¶ms, (struct nl_object *) ct);
84 nl_cache_free(ct_cache);