Add support for nft_connmark
PATCH 1/1 Add support for nft_connmark
From: Kristian Evensen <[email protected]>
This patch adds support for the connmark target.
--- include/libnftables/expr.h | 7 + include/linux/netfilter/nf_tables.h | 35 ++++ src/Makefile.am | 1 + src/expr/connmark.c | 316 ++++++++++++++++++++++++++++++++++++ tests/Makefile.am | 4 + tests/nft-expr_connmark-test.c | 206 +++++++++++++++++++++++ 6 files changed, 569 insertions(+) create mode 100644 src/expr/connmark.c create mode 100644 tests/nft-expr_connmark-test.c
include/libnftables/expr.h +7 -0
@@ -149,6 +149,13 @@ enum { NFT_EXPR_QUEUE_TOTAL, NFT_EXPR_QUEUE_FLAGS, }; + +enum { +NFT_EXPR_CONNMARK_MODE =NFT_RULE_EXPR_ATTR_BASE , +NFT_EXPR_CONNMARK_CTMARK , +NFT_EXPR_CONNMARK_CTMASK , +NFT_EXPR_CONNMARK_NFMASK , +};#ifdef __cplusplus } /* extern "C" */#endif
include/linux/netfilter/nf_tables.h +35 -0
@@ -603,6 +603,41 @@ enum nft_queue_attributes {#define NFT_QUEUE_FLAG_MASK 0x03/** +* enum nft_connmark_types - nf_tables connmark expression types +* +* @NFT_CONNMARK_SAVE: save connmark +* @NFT_CONNMARK_RESTORE: restore connmark +* @NFT_CONNMARK_SET: set connmark (iptables set-xmark) +*/ +enum nft_connmark_types { +NFT_CONNMARK_SAVE , +NFT_CONNMARK_RESTORE , +NFT_CONNMARK_SET +}; + +/** +* enum nft_connmark_attributes - nf_tables connmark expression netlink +* attributes +* +* @NFTA_CONNMARK_MODE: conntrack action (save, set or restore) (NLA_U8) +* @NFTA_CONNMARK_CTMARK: conntrack ctmark (NLA_U32) +* @NFTA_CONNMARK_CTMASK: conntrack ctmask (NLA_U32) +* @NFTA_CONNMARK_NFMASK: conntrack nfmask (NLA_U32) +*/ + +enum nft_connmark_attributes { +NFTA_CONNMARK_UNSPEC , +NFTA_CONNMARK_MODE , +NFTA_CONNMARK_CTMARK , +NFTA_CONNMARK_CTMASK , +NFTA_CONNMARK_NFMASK , + __NFTA_CONNMARK_MAX, +}; +#define NFTA_CONNMARK_MAX (__NFTA_CONNMARK_MAX - 1) + +#define NFT_CONNMARK_DEFAULT_MASK 0xFFFFFFFF + +/** * enum nft_reject_types - nf_tables reject expression reject types * * @NFT_REJECT_ICMP_UNREACH: reject using ICMP unreachable
src/Makefile.am +1 -0
@@ -19,6 +19,7 @@ libnftables_la_SOURCES = utils.c \ expr/bitwise.c \ expr/byteorder.c \ expr/cmp.c \ + expr/connmark.c \ expr/counter.c \ expr/ct.c \ expr/data_reg.c \
src/expr/connmark.c new file +316 -0
316 lines not on this page · raw message
tests/Makefile.am +4 -0
@@ -9,6 +9,7 @@ check_PROGRAMS = nft-parsing-test \ nft-expr_byteorder-test \ nft-expr_counter-test \ nft-expr_cmp-test \ + nft-expr_connmark-test \ nft-expr_ct-test \ nft-expr_exthdr-test \ nft-expr_immediate-test \
@@ -47,6 +48,9 @@ nft_expr_byteorder_test_LDADD = ../src/libnftables.la ${LIBMNL_LIBS} nft_expr_cmp_test_SOURCES = nft-expr_cmp-test.c nft_expr_cmp_test_LDADD = ../src/libnftables.la ${LIBMNL_LIBS} +nft_expr_connmark_test_SOURCES = nft-expr_connmark-test.c +nft_expr_connmark_test_LDADD = ../src/libnftables.la ${LIBMNL_LIBS} ${LIBJSON_LIBS} + nft_expr_counter_test_SOURCES = nft-expr_counter-test.c nft_expr_counter_test_LDADD = ../src/libnftables.la ${LIBMNL_LIBS}
tests/nft-expr_connmark-test.c new file +206 -0
206 lines not on this page · raw message
Signature · 1 line
1.8.3.2
Quoted 5 lines · Kristian Evensen
From: Kristian Evensen <[email protected]>
This patch adds support for the connmark target.
Signed-off-by Kristian Evensen <[email protected]>
src/expr/connmark.c line 30
Quoted 9 lines
src/expr/connmark.c new file +9
-0+ +/* Even though nfmask and ctmark is mutually exclusive, do not use union here. +* The user can provide incorrect json/xml input containing both values. */ +struct nft_expr_connmark { +uint32_t ctmark; +uint32_t ctmask; +uint32_t nfmask; +uint8_t mode; +};
Hi Kristian,
you can use the union if you want, see [0] about the situation in XML and [1] in JSON.
Regards.
[0] http://git.netfilter.org/libnftables/tree/src/expr/meta.c?h=next-3.14#n236
[1] http://git.netfilter.org/libnftables/tree/src/expr/meta.c?h=next-3.14#n195
Signature · 5 lines
Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Arturo,
Quoted 10 lines · Arturo Borrero Gonzalez
Hi Kristian,
you can use the union if you want, see [0] about the situation in XML and [1] in JSON.
Regards.
[0] http://git.netfilter.org/libnftables/tree/src/expr/meta.c?h=next-3.14#n236
[1] http://git.netfilter.org/libnftables/tree/src/expr/meta.c?h=next-3.14#n195
Thank you very much for references, good to know for next time :)
-Kristian