14#include "nl-default.h"
16#include <netlink/cli/utils.h>
17#include <netlink/cli/exp.h>
19struct nfnl_exp *nl_cli_exp_alloc(
void)
23 exp = nfnl_exp_alloc();
25 nl_cli_fatal(ENOMEM,
"Unable to allocate expectation object");
30struct nl_cache *nl_cli_exp_alloc_cache(
struct nl_sock *sk)
35void nl_cli_exp_parse_family(
struct nfnl_exp *exp,
char *arg)
39 if ((family = nl_str2af(arg)) == AF_UNSPEC)
41 "Unable to nl_cli_exp_parse family \"%s\": %s",
42 arg, nl_geterror(NLE_INVAL));
44 nfnl_exp_set_family(exp, family);
47void nl_cli_exp_parse_timeout(
struct nfnl_exp *exp,
char *arg)
50 nfnl_exp_set_timeout(exp, timeout);
53void nl_cli_exp_parse_id(
struct nfnl_exp *exp,
char *arg)
56 nfnl_exp_set_id(exp,
id);
59void nl_cli_exp_parse_helper_name(
struct nfnl_exp *exp,
char *arg)
61 nfnl_exp_set_helper_name(exp, arg);
64void nl_cli_exp_parse_zone(
struct nfnl_exp *exp,
char *arg)
67 nfnl_exp_set_zone(exp, zone);
70void nl_cli_exp_parse_flags(
struct nfnl_exp *exp,
char *arg)
73 nfnl_exp_set_flags(exp, flags);
76void nl_cli_exp_parse_class(
struct nfnl_exp *exp,
char *arg)
78 uint32_t
class = nl_cli_parse_u32(arg);
79 nfnl_exp_set_class(exp,
class);
82void nl_cli_exp_parse_nat_dir(
struct nfnl_exp *exp,
char *arg)
85 nfnl_exp_set_nat_dir(exp, nat_dir);
88void nl_cli_exp_parse_fn(
struct nfnl_exp *exp,
char *arg)
90 nfnl_exp_set_fn(exp, arg);
93void nl_cli_exp_parse_src(
struct nfnl_exp *exp,
int tuple,
char *arg)
96 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_exp_get_family(exp));
97 if ((err = nfnl_exp_set_src(exp, tuple, a)) < 0)
102void nl_cli_exp_parse_dst(
struct nfnl_exp *exp,
int tuple,
char *arg)
105 struct nl_addr *a = nl_cli_addr_parse(arg, nfnl_exp_get_family(exp));
106 if ((err = nfnl_exp_set_dst(exp, tuple, a)) < 0)
107 nl_cli_fatal(err,
"Unable to set destination address: %s",
111void nl_cli_exp_parse_l4protonum(
struct nfnl_exp *exp,
int tuple,
char *arg)
115 if ((l4protonum = nl_str2ip_proto(arg)) < 0)
117 "Unable to nl_cli_exp_parse protocol \"%s\": %s",
118 arg, nl_geterror(l4protonum));
120 nfnl_exp_set_l4protonum(exp, tuple, l4protonum);
123void nl_cli_exp_parse_src_port(
struct nfnl_exp *exp,
int tuple,
char *arg)
126 uint16_t dport = nfnl_exp_get_dst_port(exp, tuple);
127 nfnl_exp_set_ports(exp, tuple, sport, dport);
130void nl_cli_exp_parse_dst_port(
struct nfnl_exp *exp,
int tuple,
char *arg)
133 uint16_t sport = nfnl_exp_get_src_port(exp, tuple);
134 nfnl_exp_set_ports(exp, tuple, sport, dport);
137void nl_cli_exp_parse_icmp_id(
struct nfnl_exp *exp,
int tuple,
char *arg)
140 uint8_t type = nfnl_exp_get_icmp_type(exp, tuple);
141 uint8_t code = nfnl_exp_get_icmp_code(exp, tuple);
142 nfnl_exp_set_icmp(exp, tuple,
id, type, code);
145void nl_cli_exp_parse_icmp_type(
struct nfnl_exp *exp,
int tuple,
char *arg)
148 uint16_t
id = nfnl_exp_get_icmp_id(exp, tuple);
149 uint8_t code = nfnl_exp_get_icmp_code(exp, tuple);
150 nfnl_exp_set_icmp(exp, tuple,
id, type, code);
153void nl_cli_exp_parse_icmp_code(
struct nfnl_exp *exp,
int tuple,
char *arg)
156 uint16_t
id = nfnl_exp_get_icmp_id(exp, tuple);
157 uint8_t type = nfnl_exp_get_icmp_type(exp, tuple);
158 nfnl_exp_set_icmp(exp, tuple,
id, type, code);
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_exp_alloc_cache(struct nl_sock *sk, struct nl_cache **result)
Build a expectation cache holding all expectations currently in the kernel.