2 * src/lib/ct.c CLI Conntrack Helpers
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) 2008-2009 Thomas Graf <tgraf@suug.ch>
14 * @defgroup cli_ct Connection Tracking
19 #include <netlink/cli/utils.h>
20 #include <netlink/cli/ct.h>
22 struct nfnl_ct *nl_cli_ct_alloc(void)
28 nl_cli_fatal(ENOMEM, "Unable to allocate conntrack object");
33 struct nl_cache *nl_cli_ct_alloc_cache(struct nl_sock *sk)
35 return nl_cli_alloc_cache(sk, "conntrack", nfnl_ct_alloc_cache);
38 void nl_cli_ct_parse_family(struct nfnl_ct *ct, char *arg)
42 if ((family = nl_str2af(arg)) == AF_UNSPEC)
44 "Unable to nl_cli_ct_parse family \"%s\": %s",
45 arg, nl_geterror(NLE_INVAL));
47 nfnl_ct_set_family(ct, family);
50 void nl_cli_ct_parse_protocol(struct nfnl_ct *ct, char *arg)
54 if ((proto = nl_str2ip_proto(arg)) < 0)
56 "Unable to nl_cli_ct_parse protocol \"%s\": %s",
57 arg, nl_geterror(proto));
59 nfnl_ct_set_proto(ct, proto);
62 void nl_cli_ct_parse_mark(struct nfnl_ct *ct, char *arg)
64 uint32_t mark = nl_cli_parse_u32(arg);
65 nfnl_ct_set_mark(ct, mark);
68 void nl_cli_ct_parse_timeout(struct nfnl_ct *ct, char *arg)
70 uint32_t timeout = nl_cli_parse_u32(arg);
71 nfnl_ct_set_timeout(ct, timeout);
74 void nl_cli_ct_parse_id(struct nfnl_ct *ct, char *arg)
76 uint32_t id = nl_cli_parse_u32(arg);
77 nfnl_ct_set_id(ct, id);
80 void nl_cli_ct_parse_use(struct nfnl_ct *ct, char *arg)
82 uint32_t use = nl_cli_parse_u32(arg);
83 nfnl_ct_set_use(ct, use);
86 void nl_cli_ct_parse_src(struct nfnl_ct *ct, int reply, char *arg)
89 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
90 if ((err = nfnl_ct_set_src(ct, reply, a)) < 0)
91 nl_cli_fatal(err, "Unable to set source address: %s",
95 void nl_cli_ct_parse_dst(struct nfnl_ct *ct, int reply, char *arg)
98 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
99 if ((err = nfnl_ct_set_dst(ct, reply, a)) < 0)
100 nl_cli_fatal(err, "Unable to set destination address: %s",
104 void nl_cli_ct_parse_src_port(struct nfnl_ct *ct, int reply, char *arg)
106 uint32_t port = nl_cli_parse_u32(arg);
107 nfnl_ct_set_src_port(ct, reply, port);
110 void nl_cli_ct_parse_dst_port(struct nfnl_ct *ct, int reply, char *arg)
112 uint32_t port = nl_cli_parse_u32(arg);
113 nfnl_ct_set_dst_port(ct, reply, port);
116 void nl_cli_ct_parse_tcp_state(struct nfnl_ct *ct, char *arg)
120 if ((state = nfnl_ct_str2tcp_state(arg)) < 0)
122 "Unable to nl_cli_ct_parse tcp state \"%s\": %s",
123 arg, nl_geterror(state));
125 nfnl_ct_set_tcp_state(ct, state);
128 void nl_cli_ct_parse_status(struct nfnl_ct *ct, char *arg)
132 if ((status = nfnl_ct_str2status(arg)) < 0)
134 "Unable to nl_cli_ct_parse flags \"%s\": %s",
135 arg, nl_geterror(status));
137 nfnl_ct_set_status(ct, status);
141 } else if (arg_match("origicmpid")) {
143 nfnl_ct_set_icmp_id(ct, 0, strtoul(argv[idx++], NULL, 0));
144 } else if (arg_match("origicmptype")) {
146 nfnl_ct_set_icmp_type(ct, 0, strtoul(argv[idx++], NULL, 0));
147 } else if (arg_match("origicmpcode")) {
149 nfnl_ct_set_icmp_code(ct, 0, strtoul(argv[idx++], NULL, 0));
150 } else if (arg_match("replyicmpid")) {
152 nfnl_ct_set_icmp_id(ct, 1, strtoul(argv[idx++], NULL, 0));
153 } else if (arg_match("replyicmptype")) {
155 nfnl_ct_set_icmp_type(ct, 1, strtoul(argv[idx++], NULL, 0));
156 } else if (arg_match("replyicmpcode")) {
158 nfnl_ct_set_icmp_code(ct, 1, strtoul(argv[idx++], NULL, 0));