8#include <netlink/cli/utils.h>
9#include <netlink/cli/ct.h>
11#include <linux/rtnetlink.h>
15static void print_usage(
void)
18 "Usage: nf-ct-add [OPTION]... [CONNTRACK ENTRY]\n"
21 " -q, --quiet Do not print informal notifications.\n"
22 " -h, --help Show this help\n"
23 " -v, --version Show versioning information\n"
25 "Conntrack Selection\n"
26 " -p, --proto=PROTOCOL Protocol\n"
27 " --orig-src=ADDR Original source address\n"
28 " --orig-sport=PORT Original source port\n"
29 " --orig-dst=ADDR Original destination address\n"
30 " --orig-dport=PORT Original destination port\n"
31 " --reply-src=ADDR Reply source address\n"
32 " --reply-sport=PORT Reply source port\n"
33 " --reply-dst=ADDR Reply destination address\n"
34 " --reply-dport=PORT Reply destination port\n"
35 " -F, --family=FAMILY Address family\n"
36 " --mark=NUM Mark value\n"
37 " --timeout=NUM Timeout value\n"
38 " --status Bitset representing status of connection.\n"
39 " --zone=NUM Zone value\n"
44int main(
int argc,
char *argv[])
52 int err, nlflags = NLM_F_CREATE;
54 ct = nl_cli_ct_alloc();
72 static struct option long_opts[] = {
73 {
"quiet", 0, 0,
'q' },
74 {
"help", 0, 0,
'h' },
75 {
"version", 0, 0,
'v' },
76 {
"proto", 1, 0,
'p' },
77 {
"orig-src", 1, 0, ARG_ORIG_SRC },
78 {
"orig-sport", 1, 0, ARG_ORIG_SPORT },
79 {
"orig-dst", 1, 0, ARG_ORIG_DST },
80 {
"orig-dport", 1, 0, ARG_ORIG_DPORT },
81 {
"reply-src", 1, 0, ARG_REPLY_SRC },
82 {
"reply-sport", 1, 0, ARG_REPLY_SPORT },
83 {
"reply-dst", 1, 0, ARG_REPLY_DST },
84 {
"reply-dport", 1, 0, ARG_REPLY_DPORT },
85 {
"family", 1, 0,
'F' },
86 {
"mark", 1, 0, ARG_MARK },
87 {
"timeout", 1, 0, ARG_TIMEOUT },
88 {
"status", 1, 0, ARG_STATUS },
89 {
"zone", 1, 0, ARG_ZONE },
93 c = getopt_long(argc, argv,
"46q:hv:p:F:", long_opts, &optidx);
98 case '?': exit(NLE_INVAL);
99 case 'q': quiet = 1;
break;
100 case '4': nfnl_ct_set_family(ct, AF_INET);
break;
101 case '6': nfnl_ct_set_family(ct, AF_INET6);
break;
102 case 'h': print_usage();
break;
103 case 'v': nl_cli_print_version();
break;
104 case 'p': nl_cli_ct_parse_protocol(ct, optarg);
break;
105 case ARG_ORIG_SRC: nl_cli_ct_parse_src(ct, 0, optarg);
break;
106 case ARG_ORIG_SPORT: nl_cli_ct_parse_src_port(ct, 0, optarg);
break;
107 case ARG_ORIG_DST: nl_cli_ct_parse_dst(ct, 0, optarg);
break;
108 case ARG_ORIG_DPORT: nl_cli_ct_parse_dst_port(ct, 0, optarg);
break;
109 case ARG_REPLY_SRC: nl_cli_ct_parse_src(ct, 1, optarg);
break;
110 case ARG_REPLY_SPORT: nl_cli_ct_parse_src_port(ct, 1, optarg);
break;
111 case ARG_REPLY_DST: nl_cli_ct_parse_dst(ct, 1, optarg);
break;
112 case ARG_REPLY_DPORT: nl_cli_ct_parse_dst_port(ct, 1, optarg);
break;
113 case 'F': nl_cli_ct_parse_family(ct, optarg);
break;
114 case ARG_MARK: nl_cli_ct_parse_mark(ct, optarg);
break;
115 case ARG_TIMEOUT: nl_cli_ct_parse_timeout(ct, optarg);
break;
116 case ARG_STATUS: nl_cli_ct_parse_status(ct, optarg);
break;
117 case ARG_ZONE: nl_cli_ct_parse_zone(ct, optarg);
break;
126 sock = nl_cli_alloc_socket();
127 nl_cli_connect(sock, NETLINK_NETFILTER);
129 if ((err = nfnl_ct_add(sock, ct, nlflags)) < 0)
130 nl_cli_fatal(err,
"Unable to add conntrack: %s", nl_geterror(err));
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
void nl_object_dump(struct nl_object *obj, struct nl_dump_params *params)
Dump this object according to the specified parameters.
@ NL_DUMP_LINE
Dump object briefly on one line.
enum nl_dump_type dp_type
Specifies the type of dump that is requested.