summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/expr/bitwise.c12
-rw-r--r--src/expr/byteorder.c16
-rw-r--r--src/expr/cmp.c13
-rw-r--r--src/expr/counter.c12
-rw-r--r--src/expr/ct.c12
-rw-r--r--src/expr/exthdr.c12
-rw-r--r--src/expr/immediate.c16
-rw-r--r--src/expr/limit.c12
-rw-r--r--src/expr/log.c12
-rw-r--r--src/expr/lookup.c12
-rw-r--r--src/expr/match.c12
-rw-r--r--src/expr/meta.c12
-rw-r--r--src/expr/nat.c16
-rw-r--r--src/expr/payload.c12
-rw-r--r--src/expr/target.c12
-rw-r--r--src/expr_ops.h2
16 files changed, 97 insertions, 98 deletions
diff --git a/src/expr/bitwise.c b/src/expr/bitwise.c
index 7ea5376..bfb3163 100644
--- a/src/expr/bitwise.c
+++ b/src/expr/bitwise.c
@@ -35,7 +35,7 @@ static int
nft_rule_expr_bitwise_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_bitwise *bitwise = (struct nft_expr_bitwise *)e->data;
+ struct nft_expr_bitwise *bitwise = nft_expr_data(e);
switch(type) {
case NFT_EXPR_BITWISE_SREG:
@@ -65,7 +65,7 @@ static const void *
nft_rule_expr_bitwise_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_bitwise *bitwise = (struct nft_expr_bitwise *)e->data;
+ struct nft_expr_bitwise *bitwise = nft_expr_data(e);
switch(type) {
case NFT_EXPR_BITWISE_SREG:
@@ -137,7 +137,7 @@ static int nft_rule_expr_bitwise_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_bitwise_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_bitwise *bitwise = (struct nft_expr_bitwise *)e->data;
+ struct nft_expr_bitwise *bitwise = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_BITWISE_SREG))
mnl_attr_put_u32(nlh, NFTA_BITWISE_SREG, htonl(bitwise->sreg));
@@ -166,7 +166,7 @@ nft_rule_expr_bitwise_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_bitwise_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_bitwise *bitwise = (struct nft_expr_bitwise *)e->data;
+ struct nft_expr_bitwise *bitwise = nft_expr_data(e);
struct nlattr *tb[NFTA_BITWISE_MAX+1] = {};
int ret = 0;
@@ -201,7 +201,7 @@ static int
nft_rule_expr_bitwise_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_bitwise *bitwise = (struct nft_expr_bitwise *)e->data;
+ struct nft_expr_bitwise *bitwise = nft_expr_data(e);
int32_t reg;
reg = nft_mxml_reg_parse(tree, "sreg", MXML_DESCEND_FIRST);
@@ -333,7 +333,7 @@ static int
nft_rule_expr_bitwise_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_bitwise *bitwise = (struct nft_expr_bitwise *)e->data;
+ struct nft_expr_bitwise *bitwise = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/byteorder.c b/src/expr/byteorder.c
index 53283c1..2326961 100644
--- a/src/expr/byteorder.c
+++ b/src/expr/byteorder.c
@@ -35,8 +35,7 @@ static int
nft_rule_expr_byteorder_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_byteorder *byteorder =
- (struct nft_expr_byteorder *)e->data;
+ struct nft_expr_byteorder *byteorder = nft_expr_data(e);
switch(type) {
case NFT_EXPR_BYTEORDER_SREG:
@@ -64,8 +63,7 @@ static const void *
nft_rule_expr_byteorder_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_byteorder *byteorder =
- (struct nft_expr_byteorder *)e->data;
+ struct nft_expr_byteorder *byteorder = nft_expr_data(e);
switch(type) {
case NFT_EXPR_BYTEORDER_SREG:
@@ -132,8 +130,7 @@ static int nft_rule_expr_byteorder_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_byteorder_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_byteorder *byteorder =
- (struct nft_expr_byteorder *)e->data;
+ struct nft_expr_byteorder *byteorder = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_BYTEORDER_SREG)) {
mnl_attr_put_u32(nlh, NFTA_BYTEORDER_SREG,
@@ -160,7 +157,7 @@ nft_rule_expr_byteorder_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_byteorder_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_byteorder *byteorder = (struct nft_expr_byteorder *)e->data;
+ struct nft_expr_byteorder *byteorder = nft_expr_data(e);
struct nlattr *tb[NFTA_BYTEORDER_MAX+1] = {};
int ret = 0;
@@ -205,8 +202,7 @@ static int
nft_rule_expr_byteorder_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_byteorder *byteorder =
- (struct nft_expr_byteorder *)e->data;
+ struct nft_expr_byteorder *byteorder = nft_expr_data(e);
mxml_node_t *node = NULL;
uint64_t tmp;
char *endptr = NULL;
@@ -327,7 +323,7 @@ static int
nft_rule_expr_byteorder_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_byteorder *byteorder = (struct nft_expr_byteorder *)e->data;
+ struct nft_expr_byteorder *byteorder = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/cmp.c b/src/expr/cmp.c
index f49261f..2fa9bf5 100644
--- a/src/expr/cmp.c
+++ b/src/expr/cmp.c
@@ -34,7 +34,7 @@ static int
nft_rule_expr_cmp_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_cmp *cmp = (struct nft_expr_cmp *)e->data;
+ struct nft_expr_cmp *cmp = nft_expr_data(e);
switch(type) {
case NFT_EXPR_CMP_SREG:
@@ -57,7 +57,7 @@ static const void *
nft_rule_expr_cmp_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_cmp *cmp = (struct nft_expr_cmp *)e->data;
+ struct nft_expr_cmp *cmp = nft_expr_data(e);
switch(type) {
case NFT_EXPR_CMP_SREG:
@@ -118,7 +118,7 @@ static int nft_rule_expr_cmp_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_cmp_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_cmp *cmp = (struct nft_expr_cmp *)e->data;
+ struct nft_expr_cmp *cmp = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_CMP_SREG))
mnl_attr_put_u32(nlh, NFTA_CMP_SREG, htonl(cmp->sreg));
@@ -136,7 +136,7 @@ nft_rule_expr_cmp_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_cmp_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_cmp *cmp = (struct nft_expr_cmp *)e->data;
+ struct nft_expr_cmp *cmp = nft_expr_data(e);
struct nlattr *tb[NFTA_CMP_MAX+1] = {};
int ret = 0;
@@ -171,7 +171,7 @@ static char *expr_cmp_str[] = {
static int nft_rule_expr_cmp_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_cmp *cmp = (struct nft_expr_cmp *)e->data;
+ struct nft_expr_cmp *cmp = nft_expr_data(e);
mxml_node_t *node = NULL;
int32_t reg;
@@ -280,7 +280,8 @@ static int
nft_rule_expr_cmp_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_cmp *cmp = (struct nft_expr_cmp *)e->data;
+ struct nft_expr_cmp *cmp = nft_expr_data(e);
+
switch(type) {
case NFT_RULE_O_DEFAULT:
return nft_rule_expr_cmp_snprintf_default(buf, size, cmp);
diff --git a/src/expr/counter.c b/src/expr/counter.c
index e32a46c..8521a22 100644
--- a/src/expr/counter.c
+++ b/src/expr/counter.c
@@ -32,7 +32,7 @@ static int
nft_rule_expr_counter_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_counter *ctr = (struct nft_expr_counter *)e->data;
+ struct nft_expr_counter *ctr = nft_expr_data(e);
switch(type) {
case NFT_EXPR_CTR_BYTES:
@@ -51,7 +51,7 @@ static const void *
nft_rule_expr_counter_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_counter *ctr = (struct nft_expr_counter *)e->data;
+ struct nft_expr_counter *ctr = nft_expr_data(e);
switch(type) {
case NFT_EXPR_CTR_BYTES:
@@ -99,7 +99,7 @@ static int nft_rule_expr_counter_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_counter_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_counter *ctr = (struct nft_expr_counter *)e->data;
+ struct nft_expr_counter *ctr = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_CTR_BYTES))
mnl_attr_put_u64(nlh, NFTA_COUNTER_BYTES, htobe64(ctr->bytes));
@@ -110,7 +110,7 @@ nft_rule_expr_counter_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_counter_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_counter *ctr = (struct nft_expr_counter *)e->data;
+ struct nft_expr_counter *ctr = nft_expr_data(e);
struct nlattr *tb[NFTA_COUNTER_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_counter_cb, tb) < 0)
@@ -132,7 +132,7 @@ static int
nft_rule_expr_counter_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_counter *ctr = (struct nft_expr_counter *)e->data;
+ struct nft_expr_counter *ctr = nft_expr_data(e);
mxml_node_t *node = NULL;
char *endptr;
uint64_t tmp;
@@ -172,7 +172,7 @@ static int
nft_rule_expr_counter_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_counter *ctr = (struct nft_expr_counter *)e->data;
+ struct nft_expr_counter *ctr = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/ct.c b/src/expr/ct.c
index 8ca2167..fedb1f2 100644
--- a/src/expr/ct.c
+++ b/src/expr/ct.c
@@ -39,7 +39,7 @@ static int
nft_rule_expr_ct_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_ct *ct = (struct nft_expr_ct *)e->data;
+ struct nft_expr_ct *ct = nft_expr_data(e);
switch(type) {
case NFT_EXPR_CT_KEY:
@@ -61,7 +61,7 @@ static const void *
nft_rule_expr_ct_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_ct *ct = (struct nft_expr_ct *)e->data;
+ struct nft_expr_ct *ct = nft_expr_data(e);
switch(type) {
case NFT_EXPR_CT_KEY:
@@ -122,7 +122,7 @@ static int nft_rule_expr_ct_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_ct_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_ct *ct = (struct nft_expr_ct *)e->data;
+ struct nft_expr_ct *ct = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_CT_KEY))
mnl_attr_put_u32(nlh, NFTA_CT_KEY, htonl(ct->key));
@@ -135,7 +135,7 @@ nft_rule_expr_ct_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_ct_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_ct *ct = (struct nft_expr_ct *)e->data;
+ struct nft_expr_ct *ct = nft_expr_data(e);
struct nlattr *tb[NFTA_CT_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_ct_cb, tb) < 0)
@@ -195,7 +195,7 @@ static inline int str2ctkey(const char *ctkey)
static int nft_rule_expr_ct_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_ct *ct = (struct nft_expr_ct *)e->data;
+ struct nft_expr_ct *ct = nft_expr_data(e);
mxml_node_t *node = NULL;
uint64_t tmp;
int32_t reg;
@@ -248,7 +248,7 @@ static int
nft_rule_expr_ct_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_ct *ct = (struct nft_expr_ct *)e->data;
+ struct nft_expr_ct *ct = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/exthdr.c b/src/expr/exthdr.c
index a89d17b..5fd2550 100644
--- a/src/expr/exthdr.c
+++ b/src/expr/exthdr.c
@@ -41,7 +41,7 @@ static int
nft_rule_expr_exthdr_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_exthdr *exthdr = (struct nft_expr_exthdr *)e->data;
+ struct nft_expr_exthdr *exthdr = nft_expr_data(e);
switch(type) {
case NFT_EXPR_EXTHDR_DREG:
@@ -66,7 +66,7 @@ static const void *
nft_rule_expr_exthdr_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_exthdr *exthdr = (struct nft_expr_exthdr *)e->data;
+ struct nft_expr_exthdr *exthdr = nft_expr_data(e);
switch(type) {
case NFT_EXPR_EXTHDR_DREG:
@@ -135,7 +135,7 @@ static int nft_rule_expr_exthdr_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_exthdr_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_exthdr *exthdr = (struct nft_expr_exthdr *)e->data;
+ struct nft_expr_exthdr *exthdr = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_EXTHDR_DREG))
mnl_attr_put_u32(nlh, NFTA_EXTHDR_DREG, htonl(exthdr->dreg));
@@ -150,7 +150,7 @@ nft_rule_expr_exthdr_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_exthdr_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_exthdr *exthdr = (struct nft_expr_exthdr *)e->data;
+ struct nft_expr_exthdr *exthdr = nft_expr_data(e);
struct nlattr *tb[NFTA_EXTHDR_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_exthdr_cb, tb) < 0)
@@ -215,7 +215,7 @@ static int
nft_rule_expr_exthdr_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_exthdr *exthdr = (struct nft_expr_exthdr *)e->data;
+ struct nft_expr_exthdr *exthdr = nft_expr_data(e);
mxml_node_t *node = NULL;
uint64_t tmp;
char *endptr;
@@ -278,7 +278,7 @@ static int
nft_rule_expr_exthdr_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_exthdr *exthdr = (struct nft_expr_exthdr *)e->data;
+ struct nft_expr_exthdr *exthdr = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/immediate.c b/src/expr/immediate.c
index 1aa937b..8177766 100644
--- a/src/expr/immediate.c
+++ b/src/expr/immediate.c
@@ -31,7 +31,7 @@ static int
nft_rule_expr_immediate_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
switch(type) {
case NFT_EXPR_IMM_DREG:
@@ -60,7 +60,7 @@ static const void *
nft_rule_expr_immediate_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
switch(type) {
case NFT_EXPR_IMM_DREG:
@@ -127,7 +127,7 @@ static int nft_rule_expr_immediate_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_immediate_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_IMM_DREG))
mnl_attr_put_u32(nlh, NFTA_IMMEDIATE_DREG, htonl(imm->dreg));
@@ -157,7 +157,7 @@ nft_rule_expr_immediate_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_immediate_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
struct nlattr *tb[NFTA_IMMEDIATE_MAX+1] = {};
int ret = 0;
@@ -199,7 +199,7 @@ static int
nft_rule_expr_immediate_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
int datareg_type;
int32_t reg;
@@ -240,7 +240,7 @@ nft_rule_expr_immediate_snprintf_json(char *buf, size_t len,
struct nft_rule_expr *e, uint32_t flags)
{
int size = len, offset = 0, ret;
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
ret = snprintf(buf, len, "\"dreg\" : %u, "
"\"immediatedata\" : {", imm->dreg);
@@ -274,7 +274,7 @@ nft_rule_expr_immediate_snprintf_xml(char *buf, size_t len,
struct nft_rule_expr *e, uint32_t flags)
{
int size = len, offset = 0, ret;
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
ret = snprintf(buf, len, "<dreg>%u</dreg>"
"<immediatedata>", imm->dreg);
@@ -308,7 +308,7 @@ nft_rule_expr_immediate_snprintf_default(char *buf, size_t len,
struct nft_rule_expr *e, uint32_t flags)
{
int size = len, offset = 0, ret;
- struct nft_expr_immediate *imm = (struct nft_expr_immediate *)e->data;
+ struct nft_expr_immediate *imm = nft_expr_data(e);
ret = snprintf(buf, len, "reg %u ", imm->dreg);
SNPRINTF_BUFFER_SIZE(ret, size, len, offset);
diff --git a/src/expr/limit.c b/src/expr/limit.c
index cce74ce..f2f7703 100644
--- a/src/expr/limit.c
+++ b/src/expr/limit.c
@@ -32,7 +32,7 @@ static int
nft_rule_expr_limit_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_limit *limit = (struct nft_expr_limit *)e->data;
+ struct nft_expr_limit *limit = nft_expr_data(e);
switch(type) {
case NFT_EXPR_LIMIT_RATE:
@@ -51,7 +51,7 @@ static const void *
nft_rule_expr_limit_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_limit *limit = (struct nft_expr_limit *)e->data;
+ struct nft_expr_limit *limit = nft_expr_data(e);
switch(type) {
case NFT_EXPR_LIMIT_RATE:
@@ -97,7 +97,7 @@ static int nft_rule_expr_limit_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_limit_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_limit *limit = (struct nft_expr_limit *)e->data;
+ struct nft_expr_limit *limit = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_LIMIT_RATE))
mnl_attr_put_u64(nlh, NFTA_LIMIT_RATE, htobe64(limit->rate));
@@ -108,7 +108,7 @@ nft_rule_expr_limit_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_limit_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_limit *limit = (struct nft_expr_limit *)e->data;
+ struct nft_expr_limit *limit = nft_expr_data(e);
struct nlattr *tb[NFTA_LIMIT_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_limit_cb, tb) < 0)
@@ -129,7 +129,7 @@ nft_rule_expr_limit_parse(struct nft_rule_expr *e, struct nlattr *attr)
static int nft_rule_expr_limit_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_limit *limit = (struct nft_expr_limit *)e->data;
+ struct nft_expr_limit *limit = nft_expr_data(e);
mxml_node_t *node = NULL;
uint64_t tmp;
char *endptr;
@@ -172,7 +172,7 @@ static int
nft_rule_expr_limit_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_limit *limit = (struct nft_expr_limit *)e->data;
+ struct nft_expr_limit *limit = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/log.c b/src/expr/log.c
index 94e2908..b2c39c1 100644
--- a/src/expr/log.c
+++ b/src/expr/log.c
@@ -33,7 +33,7 @@ static int
nft_rule_expr_log_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_log *log = (struct nft_expr_log *)e->data;
+ struct nft_expr_log *log = nft_expr_data(e);
switch(type) {
case NFT_EXPR_LOG_PREFIX:
@@ -61,7 +61,7 @@ static const void *
nft_rule_expr_log_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_log *log = (struct nft_expr_log *)e->data;
+ struct nft_expr_log *log = nft_expr_data(e);
switch(type) {
case NFT_EXPR_LOG_PREFIX:
@@ -126,7 +126,7 @@ static int nft_rule_expr_log_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_log_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_log *log = (struct nft_expr_log *)e->data;
+ struct nft_expr_log *log = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_LOG_PREFIX))
mnl_attr_put_str(nlh, NFTA_LOG_PREFIX, log->prefix);
@@ -141,7 +141,7 @@ nft_rule_expr_log_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_log_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_log *log = (struct nft_expr_log *)e->data;
+ struct nft_expr_log *log = nft_expr_data(e);
struct nlattr *tb[NFTA_LOG_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_log_cb, tb) < 0)
@@ -173,7 +173,7 @@ nft_rule_expr_log_parse(struct nft_rule_expr *e, struct nlattr *attr)
static int nft_rule_expr_log_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_log *log = (struct nft_expr_log *)e->data;
+ struct nft_expr_log *log = nft_expr_data(e);
mxml_node_t *node = NULL;
uint64_t tmp;
char *endptr;
@@ -235,7 +235,7 @@ static int
nft_rule_expr_log_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_log *log = (struct nft_expr_log *)e->data;
+ struct nft_expr_log *log = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/lookup.c b/src/expr/lookup.c
index 9495ab0..027f1b5 100644
--- a/src/expr/lookup.c
+++ b/src/expr/lookup.c
@@ -37,7 +37,7 @@ static int
nft_rule_expr_lookup_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
+ struct nft_expr_lookup *lookup = nft_expr_data(e);
switch(type) {
case NFT_EXPR_LOOKUP_SREG:
@@ -60,7 +60,7 @@ static const void *
nft_rule_expr_lookup_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
+ struct nft_expr_lookup *lookup = nft_expr_data(e);
switch(type) {
case NFT_EXPR_LOOKUP_SREG:
@@ -116,7 +116,7 @@ static int nft_rule_expr_lookup_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_lookup_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
+ struct nft_expr_lookup *lookup = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_LOOKUP_SREG))
mnl_attr_put_u32(nlh, NFTA_LOOKUP_SREG, htonl(lookup->sreg));
@@ -129,7 +129,7 @@ nft_rule_expr_lookup_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_lookup_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
+ struct nft_expr_lookup *lookup = nft_expr_data(e);
struct nlattr *tb[NFTA_LOOKUP_MAX+1] = {};
int ret = 0;
@@ -156,7 +156,7 @@ static int
nft_rule_expr_lookup_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
+ struct nft_expr_lookup *lookup = nft_expr_data(e);
mxml_node_t *node = NULL;
int32_t reg;
@@ -235,7 +235,7 @@ static int
nft_rule_expr_lookup_snprintf(char *buf, size_t size, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_lookup *lookup = (struct nft_expr_lookup *)e->data;
+ struct nft_expr_lookup *lookup = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/match.c b/src/expr/match.c
index 8bc2878..ee894a1 100644
--- a/src/expr/match.c
+++ b/src/expr/match.c
@@ -38,7 +38,7 @@ static int
nft_rule_expr_match_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_match *mt = (struct nft_expr_match *)e->data;
+ struct nft_expr_match *mt = nft_expr_data(e);
switch(type) {
case NFT_EXPR_MT_NAME:
@@ -65,7 +65,7 @@ static const void *
nft_rule_expr_match_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_match *mt = (struct nft_expr_match *)e->data;
+ struct nft_expr_match *mt = nft_expr_data(e);
switch(type) {
case NFT_EXPR_MT_NAME:
@@ -131,7 +131,7 @@ static int nft_rule_expr_match_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_match_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_match *mt = (struct nft_expr_match *)e->data;
+ struct nft_expr_match *mt = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_MT_NAME))
mnl_attr_put_strz(nlh, NFTA_MATCH_NAME, mt->name);
@@ -143,7 +143,7 @@ nft_rule_expr_match_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int nft_rule_expr_match_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_match *match = (struct nft_expr_match *)e->data;
+ struct nft_expr_match *match = nft_expr_data(e);
struct nlattr *tb[NFTA_MATCH_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_match_cb, tb) < 0)
@@ -187,7 +187,7 @@ static int nft_rule_expr_match_parse(struct nft_rule_expr *e, struct nlattr *att
static int nft_rule_expr_match_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_match *mt = (struct nft_expr_match *)e->data;
+ struct nft_expr_match *mt = nft_expr_data(e);
mxml_node_t *node = NULL;
/* get and set <name>. Not mandatory */
@@ -238,7 +238,7 @@ static int
nft_rule_expr_match_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_match *match = (struct nft_expr_match *)e->data;
+ struct nft_expr_match *match = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/meta.c b/src/expr/meta.c
index ceb7af2..6b19764 100644
--- a/src/expr/meta.c
+++ b/src/expr/meta.c
@@ -35,7 +35,7 @@ static int
nft_rule_expr_meta_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_meta *meta = (struct nft_expr_meta *)e->data;
+ struct nft_expr_meta *meta = nft_expr_data(e);
switch(type) {
case NFT_EXPR_META_KEY:
@@ -54,7 +54,7 @@ static const void *
nft_rule_expr_meta_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_meta *meta = (struct nft_expr_meta *)e->data;
+ struct nft_expr_meta *meta = nft_expr_data(e);
switch(type) {
case NFT_EXPR_META_KEY:
@@ -102,7 +102,7 @@ static int nft_rule_expr_meta_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_meta_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_meta *meta = (struct nft_expr_meta *)e->data;
+ struct nft_expr_meta *meta = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_META_KEY))
mnl_attr_put_u32(nlh, NFTA_META_KEY, htonl(meta->key));
@@ -113,7 +113,7 @@ nft_rule_expr_meta_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_meta_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_meta *meta = (struct nft_expr_meta *)e->data;
+ struct nft_expr_meta *meta = nft_expr_data(e);
struct nlattr *tb[NFTA_META_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_meta_cb, tb) < 0)
@@ -172,7 +172,7 @@ static inline int str2meta_key(const char *str)
static int nft_rule_expr_meta_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_meta *meta = (struct nft_expr_meta *)e->data;
+ struct nft_expr_meta *meta = nft_expr_data(e);
mxml_node_t *node = NULL;
int32_t reg;
int key;
@@ -207,7 +207,7 @@ static int
nft_rule_expr_meta_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_meta *meta = (struct nft_expr_meta *)e->data;
+ struct nft_expr_meta *meta = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/nat.c b/src/expr/nat.c
index 5ba2f4d..78184c4 100644
--- a/src/expr/nat.c
+++ b/src/expr/nat.c
@@ -36,7 +36,7 @@ static int
nft_rule_expr_nat_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
switch(type) {
case NFT_EXPR_NAT_TYPE:
@@ -68,7 +68,7 @@ static const void *
nft_rule_expr_nat_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
switch(type) {
case NFT_EXPR_NAT_TYPE:
@@ -143,7 +143,7 @@ static int nft_rule_expr_nat_cb(const struct nlattr *attr, void *data)
static int
nft_rule_expr_nat_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
struct nlattr *tb[NFTA_NAT_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_nat_cb, tb) < 0)
@@ -184,7 +184,7 @@ nft_rule_expr_nat_parse(struct nft_rule_expr *e, struct nlattr *attr)
static void
nft_rule_expr_nat_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_NAT_TYPE))
mnl_attr_put_u32(nlh, NFTA_NAT_TYPE, htonl(nat->type));
@@ -208,7 +208,7 @@ nft_rule_expr_nat_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int nft_rule_expr_nat_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
mxml_node_t *node;
int32_t reg;
int family;
@@ -280,7 +280,7 @@ static int
nft_rule_expr_nat_snprintf_json(char *buf, size_t size,
struct nft_rule_expr *e)
{
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
int len = size, offset = 0, ret = 0;
if (nat->type == NFT_NAT_SNAT)
@@ -318,7 +318,7 @@ static int
nft_rule_expr_nat_snprintf_xml(char *buf, size_t size,
struct nft_rule_expr *e)
{
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
int len = size, offset = 0, ret = 0;
/* Is a mandatory element. Provide a default, even empty */
@@ -358,7 +358,7 @@ static int
nft_rule_expr_nat_snprintf_default(char *buf, size_t size,
struct nft_rule_expr *e)
{
- struct nft_expr_nat *nat = (struct nft_expr_nat *)e->data;
+ struct nft_expr_nat *nat = nft_expr_data(e);
int len = size, offset = 0, ret = 0;
switch (nat->type) {
diff --git a/src/expr/payload.c b/src/expr/payload.c
index 7ae356b..d856f2e 100644
--- a/src/expr/payload.c
+++ b/src/expr/payload.c
@@ -36,7 +36,7 @@ static int
nft_rule_expr_payload_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_payload *payload = (struct nft_expr_payload *)e->data;
+ struct nft_expr_payload *payload = nft_expr_data(e);
switch(type) {
case NFT_EXPR_PAYLOAD_DREG:
@@ -61,7 +61,7 @@ static const void *
nft_rule_expr_payload_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_payload *payload = (struct nft_expr_payload *)e->data;
+ struct nft_expr_payload *payload = nft_expr_data(e);
switch(type) {
case NFT_EXPR_PAYLOAD_DREG:
@@ -125,7 +125,7 @@ static int nft_rule_expr_payload_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_payload_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_payload *payload = (struct nft_expr_payload *)e->data;
+ struct nft_expr_payload *payload = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_PAYLOAD_DREG))
mnl_attr_put_u32(nlh, NFTA_PAYLOAD_DREG, htonl(payload->dreg));
@@ -140,7 +140,7 @@ nft_rule_expr_payload_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int
nft_rule_expr_payload_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_payload *payload = (struct nft_expr_payload *)e->data;
+ struct nft_expr_payload *payload = nft_expr_data(e);
struct nlattr *tb[NFTA_PAYLOAD_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_payload_cb, tb) < 0)
@@ -200,7 +200,7 @@ static int
nft_rule_expr_payload_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_payload *payload = (struct nft_expr_payload *)e->data;
+ struct nft_expr_payload *payload = nft_expr_data(e);
mxml_node_t *node = NULL;
uint64_t tmp;
int32_t reg;
@@ -312,7 +312,7 @@ static int
nft_rule_expr_payload_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_payload *payload = (struct nft_expr_payload *)e->data;
+ struct nft_expr_payload *payload = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr/target.c b/src/expr/target.c
index 15e167b..d9d9daf 100644
--- a/src/expr/target.c
+++ b/src/expr/target.c
@@ -38,7 +38,7 @@ static int
nft_rule_expr_target_set(struct nft_rule_expr *e, uint16_t type,
const void *data, size_t data_len)
{
- struct nft_expr_target *tg = (struct nft_expr_target *)e->data;
+ struct nft_expr_target *tg = nft_expr_data(e);
switch(type) {
case NFT_EXPR_TG_NAME:
@@ -65,7 +65,7 @@ static const void *
nft_rule_expr_target_get(const struct nft_rule_expr *e, uint16_t type,
size_t *data_len)
{
- struct nft_expr_target *tg = (struct nft_expr_target *)e->data;
+ struct nft_expr_target *tg = nft_expr_data(e);
switch(type) {
case NFT_EXPR_TG_NAME:
@@ -131,7 +131,7 @@ static int nft_rule_expr_target_cb(const struct nlattr *attr, void *data)
static void
nft_rule_expr_target_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
{
- struct nft_expr_target *tg = (struct nft_expr_target *)e->data;
+ struct nft_expr_target *tg = nft_expr_data(e);
if (e->flags & (1 << NFT_EXPR_TG_NAME))
mnl_attr_put_strz(nlh, NFTA_TARGET_NAME, tg->name);
@@ -143,7 +143,7 @@ nft_rule_expr_target_build(struct nlmsghdr *nlh, struct nft_rule_expr *e)
static int nft_rule_expr_target_parse(struct nft_rule_expr *e, struct nlattr *attr)
{
- struct nft_expr_target *target = (struct nft_expr_target *)e->data;
+ struct nft_expr_target *target = nft_expr_data(e);
struct nlattr *tb[NFTA_TARGET_MAX+1] = {};
if (mnl_attr_parse_nested(attr, nft_rule_expr_target_cb, tb) < 0)
@@ -188,7 +188,7 @@ static int
nft_rule_expr_target_xml_parse(struct nft_rule_expr *e, mxml_node_t *tree)
{
#ifdef XML_PARSING
- struct nft_expr_target *tg = (struct nft_expr_target *)e->data;
+ struct nft_expr_target *tg = nft_expr_data(e);
mxml_node_t *node = NULL;
/* Get and set <name>. Optional */
@@ -240,7 +240,7 @@ static int
nft_rule_expr_target_snprintf(char *buf, size_t len, uint32_t type,
uint32_t flags, struct nft_rule_expr *e)
{
- struct nft_expr_target *target = (struct nft_expr_target *)e->data;
+ struct nft_expr_target *target = nft_expr_data(e);
switch(type) {
case NFT_RULE_O_DEFAULT:
diff --git a/src/expr_ops.h b/src/expr_ops.h
index d8a0b36..78413fc 100644
--- a/src/expr_ops.h
+++ b/src/expr_ops.h
@@ -30,4 +30,6 @@ struct expr_ops {
void nft_expr_ops_register(struct expr_ops *ops);
struct expr_ops *nft_expr_ops_lookup(const char *name);
+#define nft_expr_data(ops) (void *)ops->data
+
#endif