13#include <netlink/cli/utils.h>
14#include <netlink/cli/ct.h>
16struct nfnl_ct *nl_cli_ct_alloc(
void)
22 nl_cli_fatal(ENOMEM,
"Unable to allocate conntrack object");
27struct nl_cache *nl_cli_ct_alloc_cache(
struct nl_sock *sk)
32void nl_cli_ct_parse_family(
struct nfnl_ct *ct,
char *arg)
36 if ((family = nl_str2af(arg)) == AF_UNSPEC)
38 "Unable to nl_cli_ct_parse family \"%s\": %s",
39 arg, nl_geterror(NLE_INVAL));
41 nfnl_ct_set_family(ct, family);
44void nl_cli_ct_parse_protocol(
struct nfnl_ct *ct,
char *arg)
48 if ((proto = nl_str2ip_proto(arg)) < 0)
50 "Unable to nl_cli_ct_parse protocol \"%s\": %s",
51 arg, nl_geterror(proto));
53 nfnl_ct_set_proto(ct, proto);
56void nl_cli_ct_parse_mark(
struct nfnl_ct *ct,
char *arg)
59 nfnl_ct_set_mark(ct, mark);
62void nl_cli_ct_parse_timeout(
struct nfnl_ct *ct,
char *arg)
65 nfnl_ct_set_timeout(ct, timeout);
68void nl_cli_ct_parse_id(
struct nfnl_ct *ct,
char *arg)
71 nfnl_ct_set_id(ct,
id);
74void nl_cli_ct_parse_use(
struct nfnl_ct *ct,
char *arg)
77 nfnl_ct_set_use(ct, use);
80void nl_cli_ct_parse_src(
struct nfnl_ct *ct,
int reply,
char *arg)
83 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
84 if ((err = nfnl_ct_set_src(ct, reply, a)) < 0)
89void nl_cli_ct_parse_dst(
struct nfnl_ct *ct,
int reply,
char *arg)
92 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_ct_get_family(ct));
93 if ((err = nfnl_ct_set_dst(ct, reply, a)) < 0)
94 nl_cli_fatal(err,
"Unable to set destination address: %s",
98void nl_cli_ct_parse_src_port(
struct nfnl_ct *ct,
int reply,
char *arg)
101 nfnl_ct_set_src_port(ct, reply, port);
104void nl_cli_ct_parse_dst_port(
struct nfnl_ct *ct,
int reply,
char *arg)
107 nfnl_ct_set_dst_port(ct, reply, port);
110void nl_cli_ct_parse_tcp_state(
struct nfnl_ct *ct,
char *arg)
114 if ((state = nfnl_ct_str2tcp_state(arg)) < 0)
116 "Unable to nl_cli_ct_parse tcp state \"%s\": %s",
117 arg, nl_geterror(state));
119 nfnl_ct_set_tcp_state(ct, state);
122void nl_cli_ct_parse_status(
struct nfnl_ct *ct,
char *arg)
126 if ((status = nfnl_ct_str2status(arg)) < 0)
128 "Unable to nl_cli_ct_parse flags \"%s\": %s",
129 arg, nl_geterror(status));
131 nfnl_ct_set_status(ct, status);
134void nl_cli_ct_parse_zone(
struct nfnl_ct *ct,
char *arg)
137 nfnl_ct_set_zone(ct, zone);
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));
void nl_cli_fatal(int err, const char *fmt,...)
Print error message and quit application.
uint32_t nl_cli_parse_u32(const char *arg)
Parse a text based 32 bit unsigned integer argument.
int nfnl_ct_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
Build a conntrack cache holding all conntrack currently in the kernel.