Version in base suite: 1.1.2-2 Base version: libnftnl_1.1.2-2 Target version: libnftnl_1.1.4-1~bpo10+1 Base file: /srv/ftp-master.debian.org/ftp/pool/main/libn/libnftnl/libnftnl_1.1.2-2.dsc Target file: /srv/ftp-master.debian.org/policy/pool/main/libn/libnftnl/libnftnl_1.1.4-1~bpo10+1.dsc Make_global.am | 2 Makefile.in | 2 configure | 20 +-- configure.ac | 2 debian/changelog | 35 +++++ debian/compat | 2 debian/control | 4 debian/gitlab-ci.yml | 6 debian/libnftnl11.symbols | 20 +++ debian/rules | 3 examples/Makefile.am | 16 ++ examples/Makefile.in | 96 +++++++++++--- examples/nft-ct-expectation-add.c | 153 +++++++++++++++++++++++ examples/nft-ct-expectation-del.c | 126 +++++++++++++++++++ examples/nft-ct-expectation-get.c | 142 ++++++++++++++++++++++ examples/nft-rule-ct-expectation-add.c | 163 +++++++++++++++++++++++++ include/Makefile.am | 1 include/Makefile.in | 1 include/internal.h | 1 include/libnftnl/chain.h | 19 ++ include/libnftnl/expr.h | 15 +- include/libnftnl/gen.h | 1 include/libnftnl/object.h | 8 + include/libnftnl/rule.h | 1 include/libnftnl/udata.h | 33 +++++ include/linux/netfilter/nf_tables.h | 133 ++++++++++++++++---- include/obj.h | 8 + include/rule.h | 27 ++++ include/set_elem.h | 2 libnftnl.pc.in | 1 src/Makefile.am | 2 src/Makefile.in | 15 +- src/chain.c | 172 ++++++++++++++++++++++++++ src/expr/ct.c | 1 src/expr/exthdr.c | 5 src/expr/hash.c | 43 ------ src/expr/meta.c | 6 src/expr/numgen.c | 43 ------ src/expr/osf.c | 17 ++ src/expr/synproxy.c | 170 ++++++++++++++++++++++++++ src/expr_ops.c | 2 src/flowtable.c | 25 ++- src/libnftnl.map | 31 +++- src/obj/ct_expect.c | 213 +++++++++++++++++++++++++++++++++ src/object.c | 3 src/rule.c | 42 +++--- src/set_elem.c | 5 src/udata.c | 6 tests/Makefile.in | 2 49 files changed, 1641 insertions(+), 205 deletions(-) diff -Nru libnftnl-1.1.2/Make_global.am libnftnl-1.1.4/Make_global.am --- libnftnl-1.1.2/Make_global.am 2018-11-13 11:02:34.898977261 +0000 +++ libnftnl-1.1.4/Make_global.am 2019-08-19 09:18:14.303010167 +0000 @@ -18,7 +18,7 @@ # set age to 0. # # -LIBVERSION=11:0:0 +LIBVERSION=12:0:1 AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS} ${LIBMXML_CFLAGS} AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN} diff -Nru libnftnl-1.1.2/Makefile.in libnftnl-1.1.4/Makefile.in --- libnftnl-1.1.2/Makefile.in 2018-11-13 11:02:42.618962979 +0000 +++ libnftnl-1.1.4/Makefile.in 2019-08-19 09:18:21.926994214 +0000 @@ -387,7 +387,7 @@ # set age to 0. # # -LIBVERSION = 11:0:0 +LIBVERSION = 12:0:1 AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS} ${LIBMXML_CFLAGS} AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN} ACLOCAL_AMFLAGS = -I m4 diff -Nru libnftnl-1.1.2/configure libnftnl-1.1.4/configure --- libnftnl-1.1.2/configure 2018-11-13 11:02:41.558964945 +0000 +++ libnftnl-1.1.4/configure 2019-08-19 09:18:20.906996345 +0000 @@ -1,6 +1,6 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.69 for libnftnl 1.1.2. +# Generated by GNU Autoconf 2.69 for libnftnl 1.1.4. # # # Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. @@ -587,8 +587,8 @@ # Identity of this package. PACKAGE_NAME='libnftnl' PACKAGE_TARNAME='libnftnl' -PACKAGE_VERSION='1.1.2' -PACKAGE_STRING='libnftnl 1.1.2' +PACKAGE_VERSION='1.1.4' +PACKAGE_STRING='libnftnl 1.1.4' PACKAGE_BUGREPORT='' PACKAGE_URL='' @@ -1333,7 +1333,7 @@ # Omit some internal or obsolete options to make the list less imposing. # This message is too long to be a string in the A/UX 3.1 sh. cat <<_ACEOF -\`configure' configures libnftnl 1.1.2 to adapt to many kinds of systems. +\`configure' configures libnftnl 1.1.4 to adapt to many kinds of systems. Usage: $0 [OPTION]... [VAR=VALUE]... @@ -1404,7 +1404,7 @@ if test -n "$ac_init_help"; then case $ac_init_help in - short | recursive ) echo "Configuration of libnftnl 1.1.2:";; + short | recursive ) echo "Configuration of libnftnl 1.1.4:";; esac cat <<\_ACEOF @@ -1522,7 +1522,7 @@ test -n "$ac_init_help" && exit $ac_status if $ac_init_version; then cat <<\_ACEOF -libnftnl configure 1.1.2 +libnftnl configure 1.1.4 generated by GNU Autoconf 2.69 Copyright (C) 2012 Free Software Foundation, Inc. @@ -1800,7 +1800,7 @@ This file contains any messages produced by compilers while running configure, to aid debugging if configure makes a mistake. -It was created by libnftnl $as_me 1.1.2, which was +It was created by libnftnl $as_me 1.1.4, which was generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -3821,7 +3821,7 @@ # Define the identity of the package. PACKAGE='libnftnl' - VERSION='1.1.2' + VERSION='1.1.4' cat >>confdefs.h <<_ACEOF @@ -13580,7 +13580,7 @@ # report actual input values of CONFIG_FILES etc. instead of their # values after options handling. ac_log=" -This file was extended by libnftnl $as_me 1.1.2, which was +This file was extended by libnftnl $as_me 1.1.4, which was generated by GNU Autoconf 2.69. Invocation command line was CONFIG_FILES = $CONFIG_FILES @@ -13646,7 +13646,7 @@ cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1 ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`" ac_cs_version="\\ -libnftnl config.status 1.1.2 +libnftnl config.status 1.1.4 configured by $0, generated by GNU Autoconf 2.69, with options \\"\$ac_cs_config\\" diff -Nru libnftnl-1.1.2/configure.ac libnftnl-1.1.4/configure.ac --- libnftnl-1.1.2/configure.ac 2018-11-13 11:02:34.898977261 +0000 +++ libnftnl-1.1.4/configure.ac 2019-08-19 09:18:14.303010167 +0000 @@ -1,6 +1,6 @@ dnl Process this file with autoconf to create configure. -AC_INIT([libnftnl], [1.1.2]) +AC_INIT([libnftnl], [1.1.4]) AC_CONFIG_AUX_DIR([build-aux]) AC_CANONICAL_HOST AC_CONFIG_MACRO_DIR([m4]) diff -Nru libnftnl-1.1.2/debian/changelog libnftnl-1.1.4/debian/changelog --- libnftnl-1.1.2/debian/changelog 2018-12-03 11:20:58.000000000 +0000 +++ libnftnl-1.1.4/debian/changelog 2019-09-18 17:02:47.000000000 +0000 @@ -1,3 +1,38 @@ +libnftnl (1.1.4-1~bpo10+1) buster-backports; urgency=medium + + * Rebuild for buster-backports. + + -- Arturo Borrero Gonzalez Wed, 18 Sep 2019 19:02:47 +0200 + +libnftnl (1.1.4-1) unstable; urgency=medium + + * [c327c9c] New upstream version 1.1.4 + * [5ff0c1e] src:libnftnl: bump debhelper compat to 12 + + -- Arturo Borrero Gonzalez Mon, 26 Aug 2019 12:32:30 +0200 + +libnftnl (1.1.3-2~bpo10+1) buster-backports; urgency=medium + + * Rebuild for buster-backports. + + -- Arturo Borrero Gonzalez Wed, 17 Jul 2019 13:39:01 +0200 + +libnftnl (1.1.3-2) unstable; urgency=medium + + * [221bda5] d/control: bump std-version to 4.4.0 + * [32db9dc] d/rules: drop dbgsym migration override + + -- Arturo Borrero Gonzalez Tue, 09 Jul 2019 14:26:48 +0200 + +libnftnl (1.1.3-1~exp1) experimental; urgency=medium + + * [2b4b69f] src:libnftnl: add salsa CI integration + * [504e47e] New upstream version 1.1.3 + * [ee18350] d/libnftnl11.symbols: refresh file with latest changes from + upstream + + -- Arturo Borrero Gonzalez Tue, 28 May 2019 11:32:46 +0200 + libnftnl (1.1.2-2) unstable; urgency=medium * [e3e8611] d/tests: remove tests diff -Nru libnftnl-1.1.2/debian/compat libnftnl-1.1.4/debian/compat --- libnftnl-1.1.2/debian/compat 2018-11-30 11:29:54.000000000 +0000 +++ libnftnl-1.1.4/debian/compat 2019-09-18 17:01:34.000000000 +0000 @@ -1 +1 @@ -11 +12 diff -Nru libnftnl-1.1.2/debian/control libnftnl-1.1.4/debian/control --- libnftnl-1.1.2/debian/control 2018-11-30 11:29:54.000000000 +0000 +++ libnftnl-1.1.4/debian/control 2019-09-18 17:02:47.000000000 +0000 @@ -2,11 +2,11 @@ Priority: optional Maintainer: Debian Netfilter Packaging Team Uploaders: Arturo Borrero Gonzalez -Build-Depends: debhelper (>= 11), +Build-Depends: debhelper (>= 12), libmnl-dev, libtool, pkg-config -Standards-Version: 4.2.1 +Standards-Version: 4.4.0 Section: libs Homepage: https://git.netfilter.org/libnftnl Vcs-Git: https://salsa.debian.org/pkg-netfilter-team/pkg-libnftnl diff -Nru libnftnl-1.1.2/debian/gitlab-ci.yml libnftnl-1.1.4/debian/gitlab-ci.yml --- libnftnl-1.1.2/debian/gitlab-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/debian/gitlab-ci.yml 2019-08-26 10:34:55.000000000 +0000 @@ -0,0 +1,6 @@ +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml + +variables: + RELEASE: 'unstable' diff -Nru libnftnl-1.1.2/debian/libnftnl11.symbols libnftnl-1.1.4/debian/libnftnl11.symbols --- libnftnl-1.1.2/debian/libnftnl11.symbols 2018-11-30 11:29:54.000000000 +0000 +++ libnftnl-1.1.4/debian/libnftnl11.symbols 2019-08-26 10:34:55.000000000 +0000 @@ -1,5 +1,6 @@ libnftnl.so.11 libnftnl11 #MINVER# LIBNFTNL_11@LIBNFTNL_11 1.1.2 + LIBNFTNL_12@LIBNFTNL_12 1.1.3 nftnl_batch_alloc@LIBNFTNL_11 1.1.2 nftnl_batch_begin@LIBNFTNL_11 1.1.2 nftnl_batch_buffer@LIBNFTNL_11 1.1.2 @@ -31,8 +32,14 @@ nftnl_chain_list_iter_create@LIBNFTNL_11 1.1.2 nftnl_chain_list_iter_destroy@LIBNFTNL_11 1.1.2 nftnl_chain_list_iter_next@LIBNFTNL_11 1.1.2 + nftnl_chain_list_lookup_byname@LIBNFTNL_12 1.1.3 nftnl_chain_nlmsg_build_payload@LIBNFTNL_11 1.1.2 nftnl_chain_nlmsg_parse@LIBNFTNL_11 1.1.2 + nftnl_chain_rule_add@LIBNFTNL_12 1.1.3 + nftnl_chain_rule_add_tail@LIBNFTNL_12 1.1.3 + nftnl_chain_rule_append_at@LIBNFTNL_12 1.1.3 + nftnl_chain_rule_del@LIBNFTNL_12 1.1.3 + nftnl_chain_rule_insert_at@LIBNFTNL_12 1.1.3 nftnl_chain_set@LIBNFTNL_11 1.1.2 nftnl_chain_set_data@LIBNFTNL_11 1.1.2 nftnl_chain_set_s32@LIBNFTNL_11 1.1.2 @@ -91,8 +98,16 @@ nftnl_gen_alloc@LIBNFTNL_11 1.1.2 nftnl_gen_fprintf@LIBNFTNL_11 1.1.2 nftnl_gen_free@LIBNFTNL_11 1.1.2 + nftnl_gen_get@LIBNFTNL_11 1.1.3 + nftnl_gen_get_data@LIBNFTNL_11 1.1.3 + nftnl_gen_get_u32@LIBNFTNL_11 1.1.3 + nftnl_gen_is_set@LIBNFTNL_11 1.1.3 nftnl_gen_nlmsg_parse@LIBNFTNL_11 1.1.2 + nftnl_gen_set@LIBNFTNL_11 1.1.3 + nftnl_gen_set_data@LIBNFTNL_11 1.1.3 + nftnl_gen_set_u32@LIBNFTNL_11 1.1.3 nftnl_gen_snprintf@LIBNFTNL_11 1.1.2 + nftnl_gen_unset@LIBNFTNL_11 1.1.3 nftnl_nlmsg_build_hdr@LIBNFTNL_11 1.1.2 nftnl_obj_alloc@LIBNFTNL_11 1.1.2 nftnl_obj_fprintf@LIBNFTNL_11 1.1.2 @@ -130,6 +145,7 @@ nftnl_parse_perror@LIBNFTNL_11 1.1.2 nftnl_rule_add_expr@LIBNFTNL_11 1.1.2 nftnl_rule_alloc@LIBNFTNL_11 1.1.2 + nftnl_rule_foreach@LIBNFTNL_12 1.1.3 nftnl_rule_fprintf@LIBNFTNL_11 1.1.2 nftnl_rule_free@LIBNFTNL_11 1.1.2 nftnl_rule_get@LIBNFTNL_11 1.1.2 @@ -139,6 +155,9 @@ nftnl_rule_get_u64@LIBNFTNL_11 1.1.2 nftnl_rule_get_u8@LIBNFTNL_11 1.1.2 nftnl_rule_is_set@LIBNFTNL_11 1.1.2 + nftnl_rule_iter_create@LIBNFTNL_12 1.1.3 + nftnl_rule_iter_destroy@LIBNFTNL_12 1.1.3 + nftnl_rule_iter_next@LIBNFTNL_12 1.1.3 nftnl_rule_list_add@LIBNFTNL_11 1.1.2 nftnl_rule_list_add_tail@LIBNFTNL_11 1.1.2 nftnl_rule_list_alloc@LIBNFTNL_11 1.1.2 @@ -151,6 +170,7 @@ nftnl_rule_list_iter_cur@LIBNFTNL_11 1.1.2 nftnl_rule_list_iter_destroy@LIBNFTNL_11 1.1.2 nftnl_rule_list_iter_next@LIBNFTNL_11 1.1.2 + nftnl_rule_lookup_byindex@LIBNFTNL_12 1.1.3 nftnl_rule_nlmsg_build_payload@LIBNFTNL_11 1.1.2 nftnl_rule_nlmsg_parse@LIBNFTNL_11 1.1.2 nftnl_rule_parse@LIBNFTNL_11 1.1.2 diff -Nru libnftnl-1.1.2/debian/rules libnftnl-1.1.4/debian/rules --- libnftnl-1.1.2/debian/rules 2018-11-30 11:29:54.000000000 +0000 +++ libnftnl-1.1.4/debian/rules 2019-08-26 10:34:55.000000000 +0000 @@ -7,6 +7,3 @@ %: dh $@ --with autoreconf - -override_dh_strip: - dh_strip --dbgsym-migration='libnftnl-dbg (<< 1.0.7-2~)' diff -Nru libnftnl-1.1.2/examples/Makefile.am libnftnl-1.1.4/examples/Makefile.am --- libnftnl-1.1.2/examples/Makefile.am 2018-11-13 11:02:34.898977261 +0000 +++ libnftnl-1.1.4/examples/Makefile.am 2019-08-19 09:18:14.303010167 +0000 @@ -29,10 +29,14 @@ nft-flowtable-get \ nft-ruleset-get \ nft-compat-get \ + nft-ct-expectation-add \ + nft-ct-expectation-del \ + nft-ct-expectation-get \ nft-ct-helper-add \ nft-ct-helper-get \ nft-ct-helper-del \ nft-rule-ct-helper-add \ + nft-rule-ct-expectation-add \ nft-rule-ct-timeout-add nft_table_add_SOURCES = nft-table-add.c @@ -122,6 +126,15 @@ nft_compat_get_SOURCES = nft-compat-get.c nft_compat_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} +nft_ct_expectation_add_SOURCES = nft-ct-expectation-add.c +nft_ct_expectation_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} + +nft_ct_expectation_del_SOURCES = nft-ct-expectation-del.c +nft_ct_expectation_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} + +nft_ct_expectation_get_SOURCES = nft-ct-expectation-get.c +nft_ct_expectation_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} + nft_ct_helper_add_SOURCES = nft-ct-helper-add.c nft_ct_helper_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} @@ -134,5 +147,8 @@ nft_rule_ct_helper_add_SOURCES = nft-rule-ct-helper-add.c nft_rule_ct_helper_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} +nft_rule_ct_expectation_add_SOURCES = nft-rule-ct-expectation-add.c +nft_rule_ct_expectation_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} + nft_rule_ct_timeout_add_SOURCES = nft-rule-ct-timeout-add.c nft_rule_ct_timeout_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} diff -Nru libnftnl-1.1.2/examples/Makefile.in libnftnl-1.1.4/examples/Makefile.in --- libnftnl-1.1.2/examples/Makefile.in 2018-11-13 11:02:42.686962852 +0000 +++ libnftnl-1.1.4/examples/Makefile.in 2019-08-19 09:18:21.998994063 +0000 @@ -101,8 +101,12 @@ nft-ct-timeout-del$(EXEEXT) nft-flowtable-add$(EXEEXT) \ nft-flowtable-del$(EXEEXT) nft-flowtable-get$(EXEEXT) \ nft-ruleset-get$(EXEEXT) nft-compat-get$(EXEEXT) \ - nft-ct-helper-add$(EXEEXT) nft-ct-helper-get$(EXEEXT) \ - nft-ct-helper-del$(EXEEXT) nft-rule-ct-helper-add$(EXEEXT) \ + nft-ct-expectation-add$(EXEEXT) \ + nft-ct-expectation-del$(EXEEXT) \ + nft-ct-expectation-get$(EXEEXT) nft-ct-helper-add$(EXEEXT) \ + nft-ct-helper-get$(EXEEXT) nft-ct-helper-del$(EXEEXT) \ + nft-rule-ct-helper-add$(EXEEXT) \ + nft-rule-ct-expectation-add$(EXEEXT) \ nft-rule-ct-timeout-add$(EXEEXT) subdir = examples ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -134,6 +138,18 @@ am_nft_compat_get_OBJECTS = nft-compat-get.$(OBJEXT) nft_compat_get_OBJECTS = $(am_nft_compat_get_OBJECTS) nft_compat_get_DEPENDENCIES = ../src/libnftnl.la $(am__DEPENDENCIES_1) +am_nft_ct_expectation_add_OBJECTS = nft-ct-expectation-add.$(OBJEXT) +nft_ct_expectation_add_OBJECTS = $(am_nft_ct_expectation_add_OBJECTS) +nft_ct_expectation_add_DEPENDENCIES = ../src/libnftnl.la \ + $(am__DEPENDENCIES_1) +am_nft_ct_expectation_del_OBJECTS = nft-ct-expectation-del.$(OBJEXT) +nft_ct_expectation_del_OBJECTS = $(am_nft_ct_expectation_del_OBJECTS) +nft_ct_expectation_del_DEPENDENCIES = ../src/libnftnl.la \ + $(am__DEPENDENCIES_1) +am_nft_ct_expectation_get_OBJECTS = nft-ct-expectation-get.$(OBJEXT) +nft_ct_expectation_get_OBJECTS = $(am_nft_ct_expectation_get_OBJECTS) +nft_ct_expectation_get_DEPENDENCIES = ../src/libnftnl.la \ + $(am__DEPENDENCIES_1) am_nft_ct_helper_add_OBJECTS = nft-ct-helper-add.$(OBJEXT) nft_ct_helper_add_OBJECTS = $(am_nft_ct_helper_add_OBJECTS) nft_ct_helper_add_DEPENDENCIES = ../src/libnftnl.la \ @@ -188,6 +204,12 @@ am_nft_rule_add_OBJECTS = nft-rule-add.$(OBJEXT) nft_rule_add_OBJECTS = $(am_nft_rule_add_OBJECTS) nft_rule_add_DEPENDENCIES = ../src/libnftnl.la $(am__DEPENDENCIES_1) +am_nft_rule_ct_expectation_add_OBJECTS = \ + nft-rule-ct-expectation-add.$(OBJEXT) +nft_rule_ct_expectation_add_OBJECTS = \ + $(am_nft_rule_ct_expectation_add_OBJECTS) +nft_rule_ct_expectation_add_DEPENDENCIES = ../src/libnftnl.la \ + $(am__DEPENDENCIES_1) am_nft_rule_ct_helper_add_OBJECTS = nft-rule-ct-helper-add.$(OBJEXT) nft_rule_ct_helper_add_OBJECTS = $(am_nft_rule_ct_helper_add_OBJECTS) nft_rule_ct_helper_add_DEPENDENCIES = ../src/libnftnl.la \ @@ -277,14 +299,18 @@ am__v_CCLD_1 = SOURCES = $(nft_chain_add_SOURCES) $(nft_chain_del_SOURCES) \ $(nft_chain_get_SOURCES) $(nft_compat_get_SOURCES) \ - $(nft_ct_helper_add_SOURCES) $(nft_ct_helper_del_SOURCES) \ - $(nft_ct_helper_get_SOURCES) $(nft_ct_timeout_add_SOURCES) \ - $(nft_ct_timeout_del_SOURCES) $(nft_ct_timeout_get_SOURCES) \ - $(nft_events_SOURCES) $(nft_flowtable_add_SOURCES) \ - $(nft_flowtable_del_SOURCES) $(nft_flowtable_get_SOURCES) \ - $(nft_map_add_SOURCES) $(nft_obj_add_SOURCES) \ - $(nft_obj_del_SOURCES) $(nft_obj_get_SOURCES) \ - $(nft_rule_add_SOURCES) $(nft_rule_ct_helper_add_SOURCES) \ + $(nft_ct_expectation_add_SOURCES) \ + $(nft_ct_expectation_del_SOURCES) \ + $(nft_ct_expectation_get_SOURCES) $(nft_ct_helper_add_SOURCES) \ + $(nft_ct_helper_del_SOURCES) $(nft_ct_helper_get_SOURCES) \ + $(nft_ct_timeout_add_SOURCES) $(nft_ct_timeout_del_SOURCES) \ + $(nft_ct_timeout_get_SOURCES) $(nft_events_SOURCES) \ + $(nft_flowtable_add_SOURCES) $(nft_flowtable_del_SOURCES) \ + $(nft_flowtable_get_SOURCES) $(nft_map_add_SOURCES) \ + $(nft_obj_add_SOURCES) $(nft_obj_del_SOURCES) \ + $(nft_obj_get_SOURCES) $(nft_rule_add_SOURCES) \ + $(nft_rule_ct_expectation_add_SOURCES) \ + $(nft_rule_ct_helper_add_SOURCES) \ $(nft_rule_ct_timeout_add_SOURCES) $(nft_rule_del_SOURCES) \ $(nft_rule_get_SOURCES) $(nft_ruleset_get_SOURCES) \ $(nft_set_add_SOURCES) $(nft_set_del_SOURCES) \ @@ -294,14 +320,18 @@ $(nft_table_get_SOURCES) $(nft_table_upd_SOURCES) DIST_SOURCES = $(nft_chain_add_SOURCES) $(nft_chain_del_SOURCES) \ $(nft_chain_get_SOURCES) $(nft_compat_get_SOURCES) \ - $(nft_ct_helper_add_SOURCES) $(nft_ct_helper_del_SOURCES) \ - $(nft_ct_helper_get_SOURCES) $(nft_ct_timeout_add_SOURCES) \ - $(nft_ct_timeout_del_SOURCES) $(nft_ct_timeout_get_SOURCES) \ - $(nft_events_SOURCES) $(nft_flowtable_add_SOURCES) \ - $(nft_flowtable_del_SOURCES) $(nft_flowtable_get_SOURCES) \ - $(nft_map_add_SOURCES) $(nft_obj_add_SOURCES) \ - $(nft_obj_del_SOURCES) $(nft_obj_get_SOURCES) \ - $(nft_rule_add_SOURCES) $(nft_rule_ct_helper_add_SOURCES) \ + $(nft_ct_expectation_add_SOURCES) \ + $(nft_ct_expectation_del_SOURCES) \ + $(nft_ct_expectation_get_SOURCES) $(nft_ct_helper_add_SOURCES) \ + $(nft_ct_helper_del_SOURCES) $(nft_ct_helper_get_SOURCES) \ + $(nft_ct_timeout_add_SOURCES) $(nft_ct_timeout_del_SOURCES) \ + $(nft_ct_timeout_get_SOURCES) $(nft_events_SOURCES) \ + $(nft_flowtable_add_SOURCES) $(nft_flowtable_del_SOURCES) \ + $(nft_flowtable_get_SOURCES) $(nft_map_add_SOURCES) \ + $(nft_obj_add_SOURCES) $(nft_obj_del_SOURCES) \ + $(nft_obj_get_SOURCES) $(nft_rule_add_SOURCES) \ + $(nft_rule_ct_expectation_add_SOURCES) \ + $(nft_rule_ct_helper_add_SOURCES) \ $(nft_rule_ct_timeout_add_SOURCES) $(nft_rule_del_SOURCES) \ $(nft_rule_get_SOURCES) $(nft_ruleset_get_SOURCES) \ $(nft_set_add_SOURCES) $(nft_set_del_SOURCES) \ @@ -481,7 +511,7 @@ # set age to 0. # # -LIBVERSION = 11:0:0 +LIBVERSION = 12:0:1 AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS} ${LIBMXML_CFLAGS} AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN} nft_table_add_SOURCES = nft-table-add.c @@ -542,6 +572,12 @@ nft_ruleset_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} nft_compat_get_SOURCES = nft-compat-get.c nft_compat_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} +nft_ct_expectation_add_SOURCES = nft-ct-expectation-add.c +nft_ct_expectation_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} +nft_ct_expectation_del_SOURCES = nft-ct-expectation-del.c +nft_ct_expectation_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} +nft_ct_expectation_get_SOURCES = nft-ct-expectation-get.c +nft_ct_expectation_get_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} nft_ct_helper_add_SOURCES = nft-ct-helper-add.c nft_ct_helper_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} nft_ct_helper_get_SOURCES = nft-ct-helper-get.c @@ -550,6 +586,8 @@ nft_ct_helper_del_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} nft_rule_ct_helper_add_SOURCES = nft-rule-ct-helper-add.c nft_rule_ct_helper_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} +nft_rule_ct_expectation_add_SOURCES = nft-rule-ct-expectation-add.c +nft_rule_ct_expectation_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} nft_rule_ct_timeout_add_SOURCES = nft-rule-ct-timeout-add.c nft_rule_ct_timeout_add_LDADD = ../src/libnftnl.la ${LIBMNL_LIBS} all: all-am @@ -612,6 +650,18 @@ @rm -f nft-compat-get$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nft_compat_get_OBJECTS) $(nft_compat_get_LDADD) $(LIBS) +nft-ct-expectation-add$(EXEEXT): $(nft_ct_expectation_add_OBJECTS) $(nft_ct_expectation_add_DEPENDENCIES) $(EXTRA_nft_ct_expectation_add_DEPENDENCIES) + @rm -f nft-ct-expectation-add$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(nft_ct_expectation_add_OBJECTS) $(nft_ct_expectation_add_LDADD) $(LIBS) + +nft-ct-expectation-del$(EXEEXT): $(nft_ct_expectation_del_OBJECTS) $(nft_ct_expectation_del_DEPENDENCIES) $(EXTRA_nft_ct_expectation_del_DEPENDENCIES) + @rm -f nft-ct-expectation-del$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(nft_ct_expectation_del_OBJECTS) $(nft_ct_expectation_del_LDADD) $(LIBS) + +nft-ct-expectation-get$(EXEEXT): $(nft_ct_expectation_get_OBJECTS) $(nft_ct_expectation_get_DEPENDENCIES) $(EXTRA_nft_ct_expectation_get_DEPENDENCIES) + @rm -f nft-ct-expectation-get$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(nft_ct_expectation_get_OBJECTS) $(nft_ct_expectation_get_LDADD) $(LIBS) + nft-ct-helper-add$(EXEEXT): $(nft_ct_helper_add_OBJECTS) $(nft_ct_helper_add_DEPENDENCIES) $(EXTRA_nft_ct_helper_add_DEPENDENCIES) @rm -f nft-ct-helper-add$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nft_ct_helper_add_OBJECTS) $(nft_ct_helper_add_LDADD) $(LIBS) @@ -672,6 +722,10 @@ @rm -f nft-rule-add$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nft_rule_add_OBJECTS) $(nft_rule_add_LDADD) $(LIBS) +nft-rule-ct-expectation-add$(EXEEXT): $(nft_rule_ct_expectation_add_OBJECTS) $(nft_rule_ct_expectation_add_DEPENDENCIES) $(EXTRA_nft_rule_ct_expectation_add_DEPENDENCIES) + @rm -f nft-rule-ct-expectation-add$(EXEEXT) + $(AM_V_CCLD)$(LINK) $(nft_rule_ct_expectation_add_OBJECTS) $(nft_rule_ct_expectation_add_LDADD) $(LIBS) + nft-rule-ct-helper-add$(EXEEXT): $(nft_rule_ct_helper_add_OBJECTS) $(nft_rule_ct_helper_add_DEPENDENCIES) $(EXTRA_nft_rule_ct_helper_add_DEPENDENCIES) @rm -f nft-rule-ct-helper-add$(EXEEXT) $(AM_V_CCLD)$(LINK) $(nft_rule_ct_helper_add_OBJECTS) $(nft_rule_ct_helper_add_LDADD) $(LIBS) @@ -742,6 +796,9 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-chain-del.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-chain-get.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-compat-get.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-ct-expectation-add.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-ct-expectation-del.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-ct-expectation-get.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-ct-helper-add.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-ct-helper-del.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-ct-helper-get.Po@am__quote@ @@ -757,6 +814,7 @@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-obj-del.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-obj-get.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-rule-add.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-rule-ct-expectation-add.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-rule-ct-helper-add.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-rule-ct-timeout-add.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/nft-rule-del.Po@am__quote@ diff -Nru libnftnl-1.1.2/examples/nft-ct-expectation-add.c libnftnl-1.1.4/examples/nft-ct-expectation-add.c --- libnftnl-1.1.2/examples/nft-ct-expectation-add.c 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/examples/nft-ct-expectation-add.c 2019-08-19 09:18:14.303010167 +0000 @@ -0,0 +1,153 @@ +/* + * (C) 2019 by Stéphane Veyret + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include + +#include + +#include +#include + +static uint16_t parse_family(char *str, const char *option) +{ + if (strcmp(str, "ip") == 0) + return NFPROTO_IPV4; + else if (strcmp(str, "ip6") == 0) + return NFPROTO_IPV6; + else if (strcmp(str, "inet") == 0) + return NFPROTO_INET; + else if (strcmp(str, "arp") == 0) + return NFPROTO_INET; + fprintf(stderr, "Unknown %s: ip, ip6, inet, arp\n", option); + exit(EXIT_FAILURE); +} + +static uint8_t parse_l4proto(char *str) +{ + if (strcmp(str, "udp") == 0) + return IPPROTO_UDP; + else if (strcmp(str, "tcp") == 0) + return IPPROTO_TCP; + else { + fprintf(stderr, "Unknown l4proto: tcp, udp\n"); + exit(EXIT_FAILURE); + } + return IPPROTO_TCP; +} + +static struct nftnl_obj *obj_parse(int argc, char *argv[]) +{ + uint16_t family, l3proto, dport; + uint8_t l4proto, size; + struct nftnl_obj *t; + uint32_t timeout; + + t = nftnl_obj_alloc(); + if (t == NULL) { + perror("OOM"); + return NULL; + } + + family = parse_family(argv[1], "family"); + nftnl_obj_set_u32(t, NFTNL_OBJ_FAMILY, family); + nftnl_obj_set_u32(t, NFTNL_OBJ_TYPE, NFT_OBJECT_CT_EXPECT); + nftnl_obj_set_str(t, NFTNL_OBJ_TABLE, argv[2]); + nftnl_obj_set_str(t, NFTNL_OBJ_NAME, argv[3]); + + if (argc > 8) { + l3proto = parse_family(argv[8], "l3proto"); + nftnl_obj_set_u16(t, NFTNL_OBJ_CT_EXPECT_L3PROTO, l3proto); + } + l4proto = parse_l4proto(argv[4]); + nftnl_obj_set_u8(t, NFTNL_OBJ_CT_EXPECT_L4PROTO, l4proto); + dport = atoi(argv[5]); + nftnl_obj_set_u16(t, NFTNL_OBJ_CT_EXPECT_DPORT, dport); + timeout = atol(argv[6]); + nftnl_obj_set_u32(t, NFTNL_OBJ_CT_EXPECT_TIMEOUT, timeout); + size = atoi(argv[7]); + nftnl_obj_set_u8(t, NFTNL_OBJ_CT_EXPECT_SIZE, size); + + return t; +} + +int main(int argc, char *argv[]) +{ + uint32_t portid, seq, obj_seq, family; + char buf[MNL_SOCKET_BUFFER_SIZE]; + struct mnl_nlmsg_batch *batch; + struct mnl_socket *nl; + struct nlmsghdr *nlh; + struct nftnl_obj *t; + int ret; + + if (argc < 8 || argc > 9) { + fprintf(stderr, "%s [l3proto]\n", argv[0]); + exit(EXIT_FAILURE); + } + + t = obj_parse(argc, argv); + if (t == NULL) { + exit(EXIT_FAILURE); + } + + seq = time(NULL); + batch = mnl_nlmsg_batch_start(buf, sizeof(buf)); + + nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++); + mnl_nlmsg_batch_next(batch); + + obj_seq = seq; + family = nftnl_obj_get_u32(t, NFTNL_OBJ_FAMILY); + nlh = nftnl_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), + NFT_MSG_NEWOBJ, family, + NLM_F_ACK | NLM_F_CREATE, seq++); + nftnl_obj_nlmsg_build_payload(nlh, t); + nftnl_obj_free(t); + mnl_nlmsg_batch_next(batch); + + nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++); + mnl_nlmsg_batch_next(batch); + + nl = mnl_socket_open(NETLINK_NETFILTER); + if (nl == NULL) { + perror("mnl_socket_open"); + exit(EXIT_FAILURE); + } + + if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { + perror("mnl_socket_bind"); + exit(EXIT_FAILURE); + } + portid = mnl_socket_get_portid(nl); + + if (mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch), + mnl_nlmsg_batch_size(batch)) < 0) { + perror("mnl_socket_send"); + exit(EXIT_FAILURE); + } + + mnl_nlmsg_batch_stop(batch); + + ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + while (ret > 0) { + ret = mnl_cb_run(buf, ret, obj_seq, portid, NULL, NULL); + if (ret <= 0) + break; + ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + } + if (ret == -1) { + perror("error"); + exit(EXIT_FAILURE); + } + mnl_socket_close(nl); + + return EXIT_SUCCESS; +} diff -Nru libnftnl-1.1.2/examples/nft-ct-expectation-del.c libnftnl-1.1.4/examples/nft-ct-expectation-del.c --- libnftnl-1.1.2/examples/nft-ct-expectation-del.c 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/examples/nft-ct-expectation-del.c 2019-08-19 09:18:14.303010167 +0000 @@ -0,0 +1,126 @@ +/* + * (C) 2019 by Stéphane Veyret + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include + +static uint16_t parse_family(char *str, const char *option) +{ + if (strcmp(str, "ip") == 0) + return NFPROTO_IPV4; + else if (strcmp(str, "ip6") == 0) + return NFPROTO_IPV6; + else if (strcmp(str, "inet") == 0) + return NFPROTO_INET; + else if (strcmp(str, "arp") == 0) + return NFPROTO_INET; + fprintf(stderr, "Unknown %s: ip, ip6, inet, arp\n", option); + exit(EXIT_FAILURE); +} + +static struct nftnl_obj *obj_parse(int argc, char *argv[]) +{ + struct nftnl_obj *t; + uint16_t family; + + t = nftnl_obj_alloc(); + if (t == NULL) { + perror("OOM"); + return NULL; + } + + family = parse_family(argv[1], "family"); + nftnl_obj_set_u32(t, NFTNL_OBJ_FAMILY, family); + nftnl_obj_set_u32(t, NFTNL_OBJ_TYPE, NFT_OBJECT_CT_EXPECT); + nftnl_obj_set_str(t, NFTNL_OBJ_TABLE, argv[2]); + nftnl_obj_set_str(t, NFTNL_OBJ_NAME, argv[3]); + + return t; +} + +int main(int argc, char *argv[]) +{ + struct mnl_socket *nl; + char buf[MNL_SOCKET_BUFFER_SIZE]; + struct nlmsghdr *nlh; + uint32_t portid, seq, obj_seq, family; + struct nftnl_obj *t; + struct mnl_nlmsg_batch *batch; + int ret; + + if (argc != 4) { + fprintf(stderr, "%s
\n", argv[0]); + exit(EXIT_FAILURE); + } + + t = obj_parse(argc, argv); + if (t == NULL) + exit(EXIT_FAILURE); + + seq = time(NULL); + batch = mnl_nlmsg_batch_start(buf, sizeof(buf)); + + nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++); + mnl_nlmsg_batch_next(batch); + + obj_seq = seq; + family = nftnl_obj_get_u32(t, NFTNL_OBJ_FAMILY); + nlh = nftnl_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), + NFT_MSG_DELOBJ, family, NLM_F_ACK, + seq++); + nftnl_obj_nlmsg_build_payload(nlh, t); + mnl_nlmsg_batch_next(batch); + nftnl_obj_free(t); + + nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++); + mnl_nlmsg_batch_next(batch); + + nl = mnl_socket_open(NETLINK_NETFILTER); + if (nl == NULL) { + perror("mnl_socket_open"); + exit(EXIT_FAILURE); + } + + if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { + perror("mnl_socket_bind"); + exit(EXIT_FAILURE); + } + portid = mnl_socket_get_portid(nl); + + if (mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch), + mnl_nlmsg_batch_size(batch)) < 0) { + perror("mnl_socket_send"); + exit(EXIT_FAILURE); + } + + mnl_nlmsg_batch_stop(batch); + + ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + while (ret > 0) { + ret = mnl_cb_run(buf, ret, obj_seq, portid, NULL, NULL); + if (ret <= 0) + break; + ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + } + if (ret == -1) { + perror("error"); + exit(EXIT_FAILURE); + } + mnl_socket_close(nl); + + return EXIT_SUCCESS; +} diff -Nru libnftnl-1.1.2/examples/nft-ct-expectation-get.c libnftnl-1.1.4/examples/nft-ct-expectation-get.c --- libnftnl-1.1.2/examples/nft-ct-expectation-get.c 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/examples/nft-ct-expectation-get.c 2019-08-19 09:18:14.303010167 +0000 @@ -0,0 +1,142 @@ +/* + * (C) 2019 by Stéphane Veyret + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include + +#include +#include + +#include +#include + +static uint16_t parse_family(char *str, const char *option) +{ + if (strcmp(str, "ip") == 0) + return NFPROTO_IPV4; + else if (strcmp(str, "ip6") == 0) + return NFPROTO_IPV6; + else if (strcmp(str, "inet") == 0) + return NFPROTO_INET; + else if (strcmp(str, "arp") == 0) + return NFPROTO_INET; + fprintf(stderr, "Unknown %s: ip, ip6, inet, arp\n", option); + exit(EXIT_FAILURE); +} + +static struct nftnl_obj *obj_parse(int argc, char *argv[]) +{ + struct nftnl_obj *t; + uint16_t family; + + t = nftnl_obj_alloc(); + if (t == NULL) { + perror("OOM"); + return NULL; + } + + family = parse_family(argv[1], "family"); + nftnl_obj_set_u32(t, NFTNL_OBJ_FAMILY, family); + nftnl_obj_set_u32(t, NFTNL_OBJ_TYPE, NFT_OBJECT_CT_EXPECT); + nftnl_obj_set_str(t, NFTNL_OBJ_TABLE, argv[2]); + + if (argc > 3) + nftnl_obj_set_str(t, NFTNL_OBJ_NAME, argv[3]); + + return t; +} + +static int obj_cb(const struct nlmsghdr *nlh, void *data) +{ + uint32_t *type = data; + struct nftnl_obj *t; + char buf[4096]; + + t = nftnl_obj_alloc(); + if (t == NULL) { + perror("OOM"); + goto err; + } + + if (nftnl_obj_nlmsg_parse(nlh, t) < 0) { + perror("nftnl_obj_nlmsg_parse"); + goto err_free; + } + + nftnl_obj_snprintf(buf, sizeof(buf), t, *type, 0); + printf("%s\n", buf); + +err_free: + nftnl_obj_free(t); +err: + return MNL_CB_OK; +} + +int main(int argc, char *argv[]) +{ + struct mnl_socket *nl; + char buf[MNL_SOCKET_BUFFER_SIZE]; + struct nlmsghdr *nlh; + uint32_t portid, seq, family; + struct nftnl_obj *t; + int ret; + uint32_t type = NFTNL_OUTPUT_DEFAULT; + uint16_t flags = NLM_F_ACK; + + if (argc < 3 || argc > 4) { + fprintf(stderr, "%s
[]\n", argv[0]); + return EXIT_FAILURE; + } + + t = obj_parse(argc, argv); + if (t == NULL) + exit(EXIT_FAILURE); + family = nftnl_obj_get_u32(t, NFTNL_OBJ_FAMILY); + + seq = time(NULL); + if (argc < 4) + flags = NLM_F_DUMP; + nlh = nftnl_nlmsg_build_hdr(buf, NFT_MSG_GETOBJ, family, flags, seq); + nftnl_obj_nlmsg_build_payload(nlh, t); + nftnl_obj_free(t); + + nl = mnl_socket_open(NETLINK_NETFILTER); + if (nl == NULL) { + perror("mnl_socket_open"); + exit(EXIT_FAILURE); + } + + if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { + perror("mnl_socket_bind"); + exit(EXIT_FAILURE); + } + portid = mnl_socket_get_portid(nl); + + if (mnl_socket_sendto(nl, nlh, nlh->nlmsg_len) < 0) { + perror("mnl_socket_send"); + exit(EXIT_FAILURE); + } + + ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + while (ret > 0) { + ret = mnl_cb_run(buf, ret, seq, portid, obj_cb, &type); + if (ret <= 0) + break; + ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + } + if (ret == -1) { + perror("error"); + exit(EXIT_FAILURE); + } + mnl_socket_close(nl); + + return EXIT_SUCCESS; +} diff -Nru libnftnl-1.1.2/examples/nft-rule-ct-expectation-add.c libnftnl-1.1.4/examples/nft-rule-ct-expectation-add.c --- libnftnl-1.1.2/examples/nft-rule-ct-expectation-add.c 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/examples/nft-rule-ct-expectation-add.c 2019-08-19 09:18:14.307010158 +0000 @@ -0,0 +1,163 @@ +/* + * (C) 2019 by Stéphane Veyret + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include +#include +#include /* for offsetof */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include +#include + +static uint16_t parse_family(char *str, const char *option) +{ + if (strcmp(str, "ip") == 0) + return NFPROTO_IPV4; + else if (strcmp(str, "ip6") == 0) + return NFPROTO_IPV6; + else if (strcmp(str, "inet") == 0) + return NFPROTO_INET; + else if (strcmp(str, "arp") == 0) + return NFPROTO_INET; + fprintf(stderr, "Unknown %s: ip, ip6, inet, arp\n", option); + exit(EXIT_FAILURE); +} + +static void add_ct_expect(struct nftnl_rule *r, const char *obj_name) +{ + struct nftnl_expr *e; + + e = nftnl_expr_alloc("objref"); + if (e == NULL) { + perror("expr objref oom"); + exit(EXIT_FAILURE); + } + nftnl_expr_set_str(e, NFTNL_EXPR_OBJREF_IMM_NAME, obj_name); + nftnl_expr_set_u32(e, NFTNL_EXPR_OBJREF_IMM_TYPE, NFT_OBJECT_CT_EXPECT); + + nftnl_rule_add_expr(r, e); +} + +static struct nftnl_rule *setup_rule(uint8_t family, const char *table, + const char *chain, const char *handle, + const char *obj_name) +{ + struct nftnl_rule *r = NULL; + uint64_t handle_num; + + r = nftnl_rule_alloc(); + if (r == NULL) { + perror("OOM"); + exit(EXIT_FAILURE); + } + + nftnl_rule_set(r, NFTNL_RULE_TABLE, table); + nftnl_rule_set(r, NFTNL_RULE_CHAIN, chain); + nftnl_rule_set_u32(r, NFTNL_RULE_FAMILY, family); + + if (handle != NULL) { + handle_num = atoll(handle); + nftnl_rule_set_u64(r, NFTNL_RULE_POSITION, handle_num); + } + + add_ct_expect(r, obj_name); + + return r; +} + +int main(int argc, char *argv[]) +{ + char buf[MNL_SOCKET_BUFFER_SIZE]; + struct mnl_nlmsg_batch *batch; + uint32_t seq = time(NULL); + struct mnl_socket *nl; + struct nftnl_rule *r; + struct nlmsghdr *nlh; + uint8_t family; + int ret; + + if (argc < 5 || argc > 6) { + fprintf(stderr, + "Usage: %s
[] \n", + argv[0]); + exit(EXIT_FAILURE); + } + family = parse_family(argv[1], "family"); + + if (argc < 6) + r = setup_rule(family, argv[2], argv[3], NULL, argv[4]); + else + r = setup_rule(family, argv[2], argv[3], argv[4], argv[5]); + + nl = mnl_socket_open(NETLINK_NETFILTER); + if (nl == NULL) { + perror("mnl_socket_open"); + exit(EXIT_FAILURE); + } + + if (mnl_socket_bind(nl, 0, MNL_SOCKET_AUTOPID) < 0) { + perror("mnl_socket_bind"); + exit(EXIT_FAILURE); + } + + batch = mnl_nlmsg_batch_start(buf, sizeof(buf)); + + nftnl_batch_begin(mnl_nlmsg_batch_current(batch), seq++); + mnl_nlmsg_batch_next(batch); + + nlh = nftnl_rule_nlmsg_build_hdr(mnl_nlmsg_batch_current(batch), + NFT_MSG_NEWRULE, + nftnl_rule_get_u32(r, NFTNL_RULE_FAMILY), + NLM_F_APPEND|NLM_F_CREATE|NLM_F_ACK, + seq++); + + nftnl_rule_nlmsg_build_payload(nlh, r); + nftnl_rule_free(r); + mnl_nlmsg_batch_next(batch); + + nftnl_batch_end(mnl_nlmsg_batch_current(batch), seq++); + mnl_nlmsg_batch_next(batch); + + ret = mnl_socket_sendto(nl, mnl_nlmsg_batch_head(batch), + mnl_nlmsg_batch_size(batch)); + if (ret == -1) { + perror("mnl_socket_sendto"); + exit(EXIT_FAILURE); + } + + mnl_nlmsg_batch_stop(batch); + + ret = mnl_socket_recvfrom(nl, buf, sizeof(buf)); + if (ret == -1) { + perror("mnl_socket_recvfrom"); + exit(EXIT_FAILURE); + } + + ret = mnl_cb_run(buf, ret, 0, mnl_socket_get_portid(nl), NULL, NULL); + if (ret < 0) { + perror("mnl_cb_run"); + exit(EXIT_FAILURE); + } + + mnl_socket_close(nl); + + return EXIT_SUCCESS; +} diff -Nru libnftnl-1.1.2/include/Makefile.am libnftnl-1.1.4/include/Makefile.am --- libnftnl-1.1.2/include/Makefile.am 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/Makefile.am 2019-08-19 09:18:14.307010158 +0000 @@ -10,6 +10,7 @@ set.h \ common.h \ expr.h \ + rule.h \ set_elem.h \ udata.h \ utils.h diff -Nru libnftnl-1.1.2/include/Makefile.in libnftnl-1.1.4/include/Makefile.in --- libnftnl-1.1.2/include/Makefile.in 2018-11-13 11:02:42.706962815 +0000 +++ libnftnl-1.1.4/include/Makefile.in 2019-08-19 09:18:22.022994013 +0000 @@ -320,6 +320,7 @@ set.h \ common.h \ expr.h \ + rule.h \ set_elem.h \ udata.h \ utils.h diff -Nru libnftnl-1.1.2/include/internal.h libnftnl-1.1.4/include/internal.h --- libnftnl-1.1.2/include/internal.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/internal.h 2019-08-19 09:18:14.307010158 +0000 @@ -12,5 +12,6 @@ #include "expr.h" #include "expr_ops.h" #include "buffer.h" +#include "rule.h" #endif /* _LIBNFTNL_INTERNAL_H_ */ diff -Nru libnftnl-1.1.2/include/libnftnl/chain.h libnftnl-1.1.4/include/libnftnl/chain.h --- libnftnl-1.1.2/include/libnftnl/chain.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/libnftnl/chain.h 2019-08-19 09:18:14.307010158 +0000 @@ -13,6 +13,7 @@ #endif struct nftnl_chain; +struct nftnl_rule; struct nftnl_chain *nftnl_chain_alloc(void); void nftnl_chain_free(const struct nftnl_chain *); @@ -54,6 +55,12 @@ int32_t nftnl_chain_get_s32(const struct nftnl_chain *c, uint16_t attr); uint64_t nftnl_chain_get_u64(const struct nftnl_chain *c, uint16_t attr); +void nftnl_chain_rule_add(struct nftnl_rule *rule, struct nftnl_chain *c); +void nftnl_chain_rule_del(struct nftnl_rule *rule); +void nftnl_chain_rule_add_tail(struct nftnl_rule *rule, struct nftnl_chain *c); +void nftnl_chain_rule_insert_at(struct nftnl_rule *rule, struct nftnl_rule *pos); +void nftnl_chain_rule_append_at(struct nftnl_rule *rule, struct nftnl_rule *pos); + struct nlmsghdr; void nftnl_chain_nlmsg_build_payload(struct nlmsghdr *nlh, const struct nftnl_chain *t); @@ -68,12 +75,24 @@ #define nftnl_chain_nlmsg_build_hdr nftnl_nlmsg_build_hdr int nftnl_chain_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_chain *t); +int nftnl_rule_foreach(struct nftnl_chain *c, + int (*cb)(struct nftnl_rule *r, void *data), + void *data); +struct nftnl_rule *nftnl_rule_lookup_byindex(struct nftnl_chain *c, uint32_t index); + +struct nftnl_rule_iter; + +struct nftnl_rule_iter *nftnl_rule_iter_create(const struct nftnl_chain *c); +struct nftnl_rule *nftnl_rule_iter_next(struct nftnl_rule_iter *iter); +void nftnl_rule_iter_destroy(struct nftnl_rule_iter *iter); + struct nftnl_chain_list; struct nftnl_chain_list *nftnl_chain_list_alloc(void); void nftnl_chain_list_free(struct nftnl_chain_list *list); int nftnl_chain_list_is_empty(const struct nftnl_chain_list *list); int nftnl_chain_list_foreach(struct nftnl_chain_list *chain_list, int (*cb)(struct nftnl_chain *t, void *data), void *data); +struct nftnl_chain *nftnl_chain_list_lookup_byname(struct nftnl_chain_list *chain_list, const char *chain); void nftnl_chain_list_add(struct nftnl_chain *r, struct nftnl_chain_list *list); void nftnl_chain_list_add_tail(struct nftnl_chain *r, struct nftnl_chain_list *list); diff -Nru libnftnl-1.1.2/include/libnftnl/expr.h libnftnl-1.1.4/include/libnftnl/expr.h --- libnftnl-1.1.2/include/libnftnl/expr.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/libnftnl/expr.h 2019-08-19 09:18:14.307010158 +0000 @@ -55,8 +55,8 @@ NFTNL_EXPR_NG_MODULUS, NFTNL_EXPR_NG_TYPE, NFTNL_EXPR_NG_OFFSET, - NFTNL_EXPR_NG_SET_NAME, - NFTNL_EXPR_NG_SET_ID, + NFTNL_EXPR_NG_SET_NAME, /* deprecated */ + NFTNL_EXPR_NG_SET_ID, /* deprecated */ }; enum { @@ -259,8 +259,8 @@ NFTNL_EXPR_HASH_SEED, NFTNL_EXPR_HASH_OFFSET, NFTNL_EXPR_HASH_TYPE, - NFTNL_EXPR_HASH_SET_NAME, - NFTNL_EXPR_HASH_SET_ID, + NFTNL_EXPR_HASH_SET_NAME, /* deprecated */ + NFTNL_EXPR_HASH_SET_ID, /* deprecated */ }; enum { @@ -280,6 +280,7 @@ enum { NFTNL_EXPR_OSF_DREG = NFTNL_EXPR_BASE, NFTNL_EXPR_OSF_TTL, + NFTNL_EXPR_OSF_FLAGS, }; enum { @@ -290,6 +291,12 @@ NFTNL_EXPR_XFRM_SPNUM, }; +enum { + NFTNL_EXPR_SYNPROXY_MSS = NFTNL_EXPR_BASE, + NFTNL_EXPR_SYNPROXY_WSCALE, + NFTNL_EXPR_SYNPROXY_FLAGS, +}; + #ifdef __cplusplus } /* extern "C" */ #endif diff -Nru libnftnl-1.1.2/include/libnftnl/gen.h libnftnl-1.1.4/include/libnftnl/gen.h --- libnftnl-1.1.2/include/libnftnl/gen.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/libnftnl/gen.h 2019-08-19 09:18:14.307010158 +0000 @@ -42,7 +42,6 @@ int nftnl_gen_fprintf(FILE *fp, const struct nftnl_gen *gen, uint32_t type, uint32_t flags); #define nftnl_gen_nlmsg_build_hdr nftnl_nlmsg_build_hdr -int nftnl_gen_nlmsg_parse(const struct nlmsghdr *nlh, struct nftnl_gen *gen); #ifdef __cplusplus } /* extern "C" */ diff -Nru libnftnl-1.1.2/include/libnftnl/object.h libnftnl-1.1.4/include/libnftnl/object.h --- libnftnl-1.1.2/include/libnftnl/object.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/libnftnl/object.h 2019-08-19 09:18:14.307010158 +0000 @@ -71,6 +71,14 @@ }; enum { + NFTNL_OBJ_CT_EXPECT_L3PROTO = NFTNL_OBJ_BASE, + NFTNL_OBJ_CT_EXPECT_L4PROTO, + NFTNL_OBJ_CT_EXPECT_DPORT, + NFTNL_OBJ_CT_EXPECT_TIMEOUT, + NFTNL_OBJ_CT_EXPECT_SIZE, +}; + +enum { NFTNL_OBJ_LIMIT_RATE = NFTNL_OBJ_BASE, NFTNL_OBJ_LIMIT_UNIT, NFTNL_OBJ_LIMIT_BURST, diff -Nru libnftnl-1.1.2/include/libnftnl/rule.h libnftnl-1.1.4/include/libnftnl/rule.h --- libnftnl-1.1.2/include/libnftnl/rule.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/libnftnl/rule.h 2019-08-19 09:18:14.307010158 +0000 @@ -28,6 +28,7 @@ NFTNL_RULE_POSITION, NFTNL_RULE_USERDATA, NFTNL_RULE_ID, + NFTNL_RULE_POSITION_ID, __NFTNL_RULE_MAX }; #define NFTNL_RULE_MAX (__NFTNL_RULE_MAX - 1) diff -Nru libnftnl-1.1.2/include/libnftnl/udata.h libnftnl-1.1.4/include/libnftnl/udata.h --- libnftnl-1.1.2/include/libnftnl/udata.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/libnftnl/udata.h 2019-08-19 09:18:14.307010158 +0000 @@ -9,6 +9,39 @@ extern "C" { #endif +enum nftnl_udata_rule_types { + NFTNL_UDATA_RULE_COMMENT, + NFTNL_UDATA_RULE_EBTABLES_POLICY, + __NFTNL_UDATA_RULE_MAX +}; +#define NFTNL_UDATA_RULE_MAX (__NFTNL_UDATA_RULE_MAX - 1) + +#define NFTNL_UDATA_COMMENT_MAXLEN 128 + +enum nftnl_udata_set_types { + NFTNL_UDATA_SET_KEYBYTEORDER, + NFTNL_UDATA_SET_DATABYTEORDER, + NFTNL_UDATA_SET_MERGE_ELEMENTS, + __NFTNL_UDATA_SET_MAX +}; +#define NFTNL_UDATA_SET_MAX (__NFTNL_UDATA_SET_MAX - 1) + +enum nftnl_udata_set_elem_types { + NFTNL_UDATA_SET_ELEM_COMMENT, + NFTNL_UDATA_SET_ELEM_FLAGS, + __NFTNL_UDATA_SET_ELEM_MAX +}; +#define NFTNL_UDATA_SET_ELEM_MAX (__NFTNL_UDATA_SET_ELEM_MAX - 1) + +/** + * enum nftnl_udata_set_elem_flags - meaning of bits in UDATA_SET_ELEM_FLAGS + * + * @SET_ELEM_F_INTERVAL_OPEN: set element denotes a half-open range + */ +enum nftnl_udata_set_elem_flags { + NFTNL_SET_ELEM_F_INTERVAL_OPEN = 0x1, +}; + /* * nftnl user data attributes API */ diff -Nru libnftnl-1.1.2/include/linux/netfilter/nf_tables.h libnftnl-1.1.4/include/linux/netfilter/nf_tables.h --- libnftnl-1.1.2/include/linux/netfilter/nf_tables.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/linux/netfilter/nf_tables.h 2019-08-19 09:18:14.307010158 +0000 @@ -8,6 +8,7 @@ #define NFT_SET_MAXNAMELEN NFT_NAME_MAXLEN #define NFT_OBJ_MAXNAMELEN NFT_NAME_MAXLEN #define NFT_USERDATA_MAXLEN 256 +#define NFT_OSF_MAXGENRELEN 16 /** * enum nft_registers - nf_tables registers @@ -191,6 +192,7 @@ * @NFTA_CHAIN_USE: number of references to this chain (NLA_U32) * @NFTA_CHAIN_TYPE: type name of the string (NLA_NUL_STRING) * @NFTA_CHAIN_COUNTERS: counter specification of the chain (NLA_NESTED: nft_counter_attributes) + * @NFTA_CHAIN_FLAGS: chain flags */ enum nft_chain_attributes { NFTA_CHAIN_UNSPEC, @@ -203,6 +205,7 @@ NFTA_CHAIN_TYPE, NFTA_CHAIN_COUNTERS, NFTA_CHAIN_PAD, + NFTA_CHAIN_FLAGS, __NFTA_CHAIN_MAX }; #define NFTA_CHAIN_MAX (__NFTA_CHAIN_MAX - 1) @@ -218,6 +221,7 @@ * @NFTA_RULE_POSITION: numeric handle of the previous rule (NLA_U64) * @NFTA_RULE_USERDATA: user data (NLA_BINARY, NFT_USERDATA_MAXLEN) * @NFTA_RULE_ID: uniquely identifies a rule in a transaction (NLA_U32) + * @NFTA_RULE_POSITION_ID: transaction unique identifier of the previous rule (NLA_U32) */ enum nft_rule_attributes { NFTA_RULE_UNSPEC, @@ -230,6 +234,7 @@ NFTA_RULE_USERDATA, NFTA_RULE_PAD, NFTA_RULE_ID, + NFTA_RULE_POSITION_ID, __NFTA_RULE_MAX }; #define NFTA_RULE_MAX (__NFTA_RULE_MAX - 1) @@ -266,7 +271,7 @@ * @NFT_SET_INTERVAL: set contains intervals * @NFT_SET_MAP: set is used as a dictionary * @NFT_SET_TIMEOUT: set uses timeouts - * @NFT_SET_EVAL: set contains expressions for evaluation + * @NFT_SET_EVAL: set can be updated from the evaluation path * @NFT_SET_OBJECT: set contains stateful objects */ enum nft_set_flags { @@ -727,10 +732,12 @@ * * @NFT_EXTHDR_OP_IPV6: match against ipv6 extension headers * @NFT_EXTHDR_OP_TCP: match against tcp options + * @NFT_EXTHDR_OP_IPV4: match against ipv4 options */ enum nft_exthdr_op { NFT_EXTHDR_OP_IPV6, NFT_EXTHDR_OP_TCPOPT, + NFT_EXTHDR_OP_IPV4, __NFT_EXTHDR_OP_MAX }; #define NFT_EXTHDR_OP_MAX (__NFT_EXTHDR_OP_MAX - 1) @@ -788,6 +795,10 @@ * @NFT_META_CGROUP: socket control group (skb->sk->sk_classid) * @NFT_META_PRANDOM: a 32bit pseudo-random number * @NFT_META_SECPATH: boolean, secpath_exists (!!skb->sp) + * @NFT_META_IIFKIND: packet input interface kind name (dev->rtnl_link_ops->kind) + * @NFT_META_OIFKIND: packet output interface kind name (dev->rtnl_link_ops->kind) + * @NFT_META_BRI_IIFPVID: packet input bridge port pvid + * @NFT_META_BRI_IIFVPROTO: packet input bridge vlan proto */ enum nft_meta_keys { NFT_META_LEN, @@ -816,6 +827,10 @@ NFT_META_CGROUP, NFT_META_PRANDOM, NFT_META_SECPATH, + NFT_META_IIFKIND, + NFT_META_OIFKIND, + NFT_META_BRI_IIFPVID, + NFT_META_BRI_IIFVPROTO, }; /** @@ -870,8 +885,8 @@ NFTA_HASH_SEED, NFTA_HASH_OFFSET, NFTA_HASH_TYPE, - NFTA_HASH_SET_NAME, - NFTA_HASH_SET_ID, + NFTA_HASH_SET_NAME, /* deprecated */ + NFTA_HASH_SET_ID, /* deprecated */ __NFTA_HASH_MAX, }; #define NFTA_HASH_MAX (__NFTA_HASH_MAX - 1) @@ -934,20 +949,6 @@ #define NFT_SOCKET_MAX (__NFT_SOCKET_MAX - 1) /** - * enum nft_osf_attributes - nf_tables osf expression netlink attributes - * - * @NFTA_OSF_DREG: destination register (NLA_U32) - * @NFTA_OSF_TTL: Value of the TTL osf option (NLA_U8) - */ -enum nft_osf_attributes { - NFTA_OSF_UNSPEC, - NFTA_OSF_DREG, - NFTA_OSF_TTL, - __NFTA_OSF_MAX, -}; -#define NFTA_OSF_MAX (__NFTA_OSF_MAX - 1) - -/** * enum nft_ct_keys - nf_tables ct expression keys * * @NFT_CT_STATE: conntrack state (bitmask of enum ip_conntrack_info) @@ -973,7 +974,7 @@ * @NFT_CT_DST_IP: conntrack layer 3 protocol destination (IPv4 address) * @NFT_CT_SRC_IP6: conntrack layer 3 protocol source (IPv6 address) * @NFT_CT_DST_IP6: conntrack layer 3 protocol destination (IPv6 address) - * @NFT_CT_TIMEOUT: connection tracking timeout policy assigned to conntrack + * @NFT_CT_ID: conntrack id */ enum nft_ct_keys { NFT_CT_STATE, @@ -999,7 +1000,7 @@ NFT_CT_DST_IP, NFT_CT_SRC_IP6, NFT_CT_DST_IP6, - NFT_CT_TIMEOUT, + NFT_CT_ID, __NFT_CT_MAX }; #define NFT_CT_MAX (__NFT_CT_MAX - 1) @@ -1119,6 +1120,33 @@ #define NFTA_LOG_MAX (__NFTA_LOG_MAX - 1) /** + * enum nft_log_level - nf_tables log levels + * + * @NFT_LOGLEVEL_EMERG: system is unusable + * @NFT_LOGLEVEL_ALERT: action must be taken immediately + * @NFT_LOGLEVEL_CRIT: critical conditions + * @NFT_LOGLEVEL_ERR: error conditions + * @NFT_LOGLEVEL_WARNING: warning conditions + * @NFT_LOGLEVEL_NOTICE: normal but significant condition + * @NFT_LOGLEVEL_INFO: informational + * @NFT_LOGLEVEL_DEBUG: debug-level messages + * @NFT_LOGLEVEL_AUDIT: enabling audit logging + */ +enum nft_log_level { + NFT_LOGLEVEL_EMERG, + NFT_LOGLEVEL_ALERT, + NFT_LOGLEVEL_CRIT, + NFT_LOGLEVEL_ERR, + NFT_LOGLEVEL_WARNING, + NFT_LOGLEVEL_NOTICE, + NFT_LOGLEVEL_INFO, + NFT_LOGLEVEL_DEBUG, + NFT_LOGLEVEL_AUDIT, + __NFT_LOGLEVEL_MAX +}; +#define NFT_LOGLEVEL_MAX (__NFT_LOGLEVEL_MAX - 1) + +/** * enum nft_queue_attributes - nf_tables queue expression netlink attributes * * @NFTA_QUEUE_NUM: netlink queue to send messages to (NLA_U16) @@ -1163,7 +1191,7 @@ #define NFTA_QUOTA_MAX (__NFTA_QUOTA_MAX - 1) /** - * enum nft_secmark_attributes - nf_tables secmark expression netlink attributes + * enum nft_secmark_attributes - nf_tables secmark object netlink attributes * * @NFTA_SECMARK_CTX: security context (NLA_STRING) */ @@ -1416,7 +1444,7 @@ }; #define NFTA_CT_HELPER_MAX (__NFTA_CT_HELPER_MAX - 1) -enum nft_ct_timeout_attributes { +enum nft_ct_timeout_timeout_attributes { NFTA_CT_TIMEOUT_UNSPEC, NFTA_CT_TIMEOUT_L3PROTO, NFTA_CT_TIMEOUT_L4PROTO, @@ -1425,6 +1453,17 @@ }; #define NFTA_CT_TIMEOUT_MAX (__NFTA_CT_TIMEOUT_MAX - 1) +enum nft_ct_expectation_attributes { + NFTA_CT_EXPECT_UNSPEC, + NFTA_CT_EXPECT_L3PROTO, + NFTA_CT_EXPECT_L4PROTO, + NFTA_CT_EXPECT_DPORT, + NFTA_CT_EXPECT_TIMEOUT, + NFTA_CT_EXPECT_SIZE, + __NFTA_CT_EXPECT_MAX, +}; +#define NFTA_CT_EXPECT_MAX (__NFTA_CT_EXPECT_MAX - 1) + #define NFT_OBJECT_UNSPEC 0 #define NFT_OBJECT_COUNTER 1 #define NFT_OBJECT_QUOTA 2 @@ -1434,7 +1473,8 @@ #define NFT_OBJECT_TUNNEL 6 #define NFT_OBJECT_CT_TIMEOUT 7 #define NFT_OBJECT_SECMARK 8 -#define __NFT_OBJECT_MAX 9 +#define NFT_OBJECT_CT_EXPECT 9 +#define __NFT_OBJECT_MAX 10 #define NFT_OBJECT_MAX (__NFT_OBJECT_MAX - 1) /** @@ -1502,6 +1542,42 @@ #define NFTA_FLOWTABLE_HOOK_MAX (__NFTA_FLOWTABLE_HOOK_MAX - 1) /** + * enum nft_osf_attributes - nftables osf expression netlink attributes + * + * @NFTA_OSF_DREG: destination register (NLA_U32: nft_registers) + * @NFTA_OSF_TTL: Value of the TTL osf option (NLA_U8) + * @NFTA_OSF_FLAGS: flags (NLA_U32) + */ +enum nft_osf_attributes { + NFTA_OSF_UNSPEC, + NFTA_OSF_DREG, + NFTA_OSF_TTL, + NFTA_OSF_FLAGS, + __NFTA_OSF_MAX, +}; +#define NFTA_OSF_MAX (__NFTA_OSF_MAX - 1) + +enum nft_osf_flags { + NFT_OSF_F_VERSION = (1 << 0), +}; + +/** + * enum nft_synproxy_attributes - nf_tables synproxy expression netlink attributes + * + * @NFTA_SYNPROXY_MSS: mss value sent to the backend (NLA_U16) + * @NFTA_SYNPROXY_WSCALE: wscale value sent to the backend (NLA_U8) + * @NFTA_SYNPROXY_FLAGS: flags (NLA_U32) + */ +enum nft_synproxy_attributes { + NFTA_SYNPROXY_UNSPEC, + NFTA_SYNPROXY_MSS, + NFTA_SYNPROXY_WSCALE, + NFTA_SYNPROXY_FLAGS, + __NFTA_SYNPROXY_MAX, +}; +#define NFTA_SYNPROXY_MAX (__NFTA_SYNPROXY_MAX - 1) + +/** * enum nft_device_attributes - nf_tables device netlink attributes * * @NFTA_DEVICE_NAME: name of this device (NLA_STRING) @@ -1611,8 +1687,8 @@ NFTA_NG_MODULUS, NFTA_NG_TYPE, NFTA_NG_OFFSET, - NFTA_NG_SET_NAME, - NFTA_NG_SET_ID, + NFTA_NG_SET_NAME, /* deprecated */ + NFTA_NG_SET_ID, /* deprecated */ __NFTA_NG_MAX }; #define NFTA_NG_MAX (__NFTA_NG_MAX - 1) @@ -1697,10 +1773,19 @@ }; #define NFT_TUNNEL_MAX (__NFT_TUNNEL_MAX - 1) +enum nft_tunnel_mode { + NFT_TUNNEL_MODE_NONE, + NFT_TUNNEL_MODE_RX, + NFT_TUNNEL_MODE_TX, + __NFT_TUNNEL_MODE_MAX +}; +#define NFT_TUNNEL_MODE_MAX (__NFT_TUNNEL_MODE_MAX - 1) + enum nft_tunnel_attributes { NFTA_TUNNEL_UNSPEC, NFTA_TUNNEL_KEY, NFTA_TUNNEL_DREG, + NFTA_TUNNEL_MODE, __NFTA_TUNNEL_MAX }; #define NFTA_TUNNEL_MAX (__NFTA_TUNNEL_MAX - 1) diff -Nru libnftnl-1.1.2/include/obj.h libnftnl-1.1.4/include/obj.h --- libnftnl-1.1.2/include/obj.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/obj.h 2019-08-19 09:18:14.311010150 +0000 @@ -42,6 +42,13 @@ uint8_t l4proto; uint32_t timeout[NFTNL_CTTIMEOUT_ARRAY_MAX]; } ct_timeout; + struct nftnl_obj_ct_expect { + uint16_t l3proto; + uint16_t dport; + uint8_t l4proto; + uint8_t size; + uint32_t timeout; + } ct_expect; struct nftnl_obj_limit { uint64_t rate; uint64_t unit; @@ -99,6 +106,7 @@ extern struct obj_ops obj_ops_quota; extern struct obj_ops obj_ops_ct_helper; extern struct obj_ops obj_ops_ct_timeout; +extern struct obj_ops obj_ops_ct_expect; extern struct obj_ops obj_ops_limit; extern struct obj_ops obj_ops_tunnel; extern struct obj_ops obj_ops_secmark; diff -Nru libnftnl-1.1.2/include/rule.h libnftnl-1.1.4/include/rule.h --- libnftnl-1.1.2/include/rule.h 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/include/rule.h 2019-08-19 09:18:14.311010150 +0000 @@ -0,0 +1,27 @@ +#ifndef _LIBNFTNL_RULE_INTERNAL_H_ +#define _LIBNFTNL_RULE_INTERNAL_H_ + +struct nftnl_rule { + struct list_head head; + + uint32_t flags; + uint32_t family; + const char *table; + const char *chain; + uint64_t handle; + uint64_t position; + uint32_t id; + uint32_t position_id; + struct { + void *data; + uint32_t len; + } user; + struct { + uint32_t flags; + uint32_t proto; + } compat; + + struct list_head expr_list; +}; + +#endif diff -Nru libnftnl-1.1.2/include/set_elem.h libnftnl-1.1.4/include/set_elem.h --- libnftnl-1.1.2/include/set_elem.h 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/include/set_elem.h 2019-08-19 09:18:14.311010150 +0000 @@ -6,10 +6,10 @@ struct nftnl_set_elem { struct list_head head; uint32_t set_elem_flags; + uint32_t flags; union nftnl_data_reg key; union nftnl_data_reg data; struct nftnl_expr *expr; - uint32_t flags; uint64_t timeout; uint64_t expiration; const char *objref; diff -Nru libnftnl-1.1.2/libnftnl.pc.in libnftnl-1.1.4/libnftnl.pc.in --- libnftnl-1.1.2/libnftnl.pc.in 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/libnftnl.pc.in 2019-08-19 09:18:14.311010150 +0000 @@ -10,6 +10,7 @@ URL: http://netfilter.org/projects/libnftnl/ Version: @VERSION@ Requires: +Requires.private: libmnl Conflicts: Libs: -L${libdir} -lnftnl Cflags: -I${includedir} diff -Nru libnftnl-1.1.2/src/Makefile.am libnftnl-1.1.4/src/Makefile.am --- libnftnl-1.1.2/src/Makefile.am 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/src/Makefile.am 2019-08-19 09:18:14.311010150 +0000 @@ -56,6 +56,7 @@ expr/redir.c \ expr/hash.c \ expr/socket.c \ + expr/synproxy.c \ expr/osf.c \ expr/xfrm.c \ obj/counter.c \ @@ -65,4 +66,5 @@ obj/limit.c \ obj/ct_timeout.c \ obj/secmark.c \ + obj/ct_expect.c \ libnftnl.map diff -Nru libnftnl-1.1.2/src/Makefile.in libnftnl-1.1.4/src/Makefile.in --- libnftnl-1.1.2/src/Makefile.in 2018-11-13 11:02:42.806962630 +0000 +++ libnftnl-1.1.4/src/Makefile.in 2019-08-19 09:18:22.122993804 +0000 @@ -144,9 +144,10 @@ expr/numgen.lo expr/nat.lo expr/tproxy.lo expr/objref.lo \ expr/payload.lo expr/queue.lo expr/quota.lo expr/reject.lo \ expr/rt.lo expr/target.lo expr/tunnel.lo expr/masq.lo \ - expr/redir.lo expr/hash.lo expr/socket.lo expr/osf.lo \ - expr/xfrm.lo obj/counter.lo obj/ct_helper.lo obj/quota.lo \ - obj/tunnel.lo obj/limit.lo obj/ct_timeout.lo obj/secmark.lo + expr/redir.lo expr/hash.lo expr/socket.lo expr/synproxy.lo \ + expr/osf.lo expr/xfrm.lo obj/counter.lo obj/ct_helper.lo \ + obj/quota.lo obj/tunnel.lo obj/limit.lo obj/ct_timeout.lo \ + obj/secmark.lo obj/ct_expect.lo libnftnl_la_OBJECTS = $(am_libnftnl_la_OBJECTS) AM_V_lt = $(am__v_lt_@AM_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) @@ -363,7 +364,7 @@ # set age to 0. # # -LIBVERSION = 11:0:0 +LIBVERSION = 12:0:1 AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS} ${LIBMXML_CFLAGS} AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN} lib_LTLIBRARIES = libnftnl.la @@ -422,6 +423,7 @@ expr/redir.c \ expr/hash.c \ expr/socket.c \ + expr/synproxy.c \ expr/osf.c \ expr/xfrm.c \ obj/counter.c \ @@ -431,6 +433,7 @@ obj/limit.c \ obj/ct_timeout.c \ obj/secmark.c \ + obj/ct_expect.c \ libnftnl.map all: all-am @@ -544,6 +547,7 @@ expr/redir.lo: expr/$(am__dirstamp) expr/$(DEPDIR)/$(am__dirstamp) expr/hash.lo: expr/$(am__dirstamp) expr/$(DEPDIR)/$(am__dirstamp) expr/socket.lo: expr/$(am__dirstamp) expr/$(DEPDIR)/$(am__dirstamp) +expr/synproxy.lo: expr/$(am__dirstamp) expr/$(DEPDIR)/$(am__dirstamp) expr/osf.lo: expr/$(am__dirstamp) expr/$(DEPDIR)/$(am__dirstamp) expr/xfrm.lo: expr/$(am__dirstamp) expr/$(DEPDIR)/$(am__dirstamp) obj/$(am__dirstamp): @@ -559,6 +563,7 @@ obj/limit.lo: obj/$(am__dirstamp) obj/$(DEPDIR)/$(am__dirstamp) obj/ct_timeout.lo: obj/$(am__dirstamp) obj/$(DEPDIR)/$(am__dirstamp) obj/secmark.lo: obj/$(am__dirstamp) obj/$(DEPDIR)/$(am__dirstamp) +obj/ct_expect.lo: obj/$(am__dirstamp) obj/$(DEPDIR)/$(am__dirstamp) libnftnl.la: $(libnftnl_la_OBJECTS) $(libnftnl_la_DEPENDENCIES) $(EXTRA_libnftnl_la_DEPENDENCIES) $(AM_V_CCLD)$(libnftnl_la_LINK) -rpath $(libdir) $(libnftnl_la_OBJECTS) $(libnftnl_la_LIBADD) $(LIBS) @@ -622,11 +627,13 @@ @AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/reject.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/rt.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/socket.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/synproxy.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/target.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/tproxy.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/tunnel.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@expr/$(DEPDIR)/xfrm.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@obj/$(DEPDIR)/counter.Plo@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@obj/$(DEPDIR)/ct_expect.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@obj/$(DEPDIR)/ct_helper.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@obj/$(DEPDIR)/ct_timeout.Plo@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@obj/$(DEPDIR)/limit.Plo@am__quote@ diff -Nru libnftnl-1.1.2/src/chain.c libnftnl-1.1.4/src/chain.c --- libnftnl-1.1.2/src/chain.c 2018-11-13 11:02:34.902977253 +0000 +++ libnftnl-1.1.4/src/chain.c 2019-08-19 09:18:14.311010150 +0000 @@ -27,10 +27,12 @@ #include #include +#include #include struct nftnl_chain { struct list_head head; + struct hlist_node hnode; const char *name; const char *type; @@ -45,6 +47,8 @@ uint64_t bytes; uint64_t handle; uint32_t flags; + + struct list_head rule_list; }; static const char *nftnl_hooknum2str(int family, int hooknum) @@ -90,12 +94,25 @@ EXPORT_SYMBOL(nftnl_chain_alloc); struct nftnl_chain *nftnl_chain_alloc(void) { - return calloc(1, sizeof(struct nftnl_chain)); + struct nftnl_chain *c; + + c = calloc(1, sizeof(struct nftnl_chain)); + if (c == NULL) + return NULL; + + INIT_LIST_HEAD(&c->rule_list); + + return c; } EXPORT_SYMBOL(nftnl_chain_free); void nftnl_chain_free(const struct nftnl_chain *c) { + struct nftnl_rule *r, *tmp; + + list_for_each_entry_safe(r, tmp, &c->rule_list, head) + nftnl_rule_free(r); + if (c->flags & (1 << NFTNL_CHAIN_NAME)) xfree(c->name); if (c->flags & (1 << NFTNL_CHAIN_TABLE)) @@ -406,6 +423,36 @@ mnl_attr_put_strz(nlh, NFTA_CHAIN_TYPE, c->type); } +EXPORT_SYMBOL(nftnl_chain_rule_add); +void nftnl_chain_rule_add(struct nftnl_rule *rule, struct nftnl_chain *c) +{ + list_add(&rule->head, &c->rule_list); +} + +EXPORT_SYMBOL(nftnl_chain_rule_del); +void nftnl_chain_rule_del(struct nftnl_rule *r) +{ + list_del(&r->head); +} + +EXPORT_SYMBOL(nftnl_chain_rule_add_tail); +void nftnl_chain_rule_add_tail(struct nftnl_rule *rule, struct nftnl_chain *c) +{ + list_add_tail(&rule->head, &c->rule_list); +} + +EXPORT_SYMBOL(nftnl_chain_rule_insert_at); +void nftnl_chain_rule_insert_at(struct nftnl_rule *rule, struct nftnl_rule *pos) +{ + list_add_tail(&rule->head, &pos->head); +} + +EXPORT_SYMBOL(nftnl_chain_rule_append_at); +void nftnl_chain_rule_append_at(struct nftnl_rule *rule, struct nftnl_rule *pos) +{ + list_add(&rule->head, &pos->head); +} + static int nftnl_chain_parse_attr_cb(const struct nlattr *attr, void *data) { const struct nlattr **tb = data; @@ -684,20 +731,109 @@ nftnl_chain_do_snprintf); } +EXPORT_SYMBOL(nftnl_rule_foreach); +int nftnl_rule_foreach(struct nftnl_chain *c, + int (*cb)(struct nftnl_rule *r, void *data), + void *data) +{ + struct nftnl_rule *cur, *tmp; + int ret; + + list_for_each_entry_safe(cur, tmp, &c->rule_list, head) { + ret = cb(cur, data); + if (ret < 0) + return ret; + } + return 0; +} + +EXPORT_SYMBOL(nftnl_rule_lookup_byindex); +struct nftnl_rule * +nftnl_rule_lookup_byindex(struct nftnl_chain *c, uint32_t index) +{ + struct nftnl_rule *r; + + list_for_each_entry(r, &c->rule_list, head) { + if (!index) + return r; + index--; + } + return NULL; +} + +struct nftnl_rule_iter { + const struct nftnl_chain *c; + struct nftnl_rule *cur; +}; + +static void nftnl_rule_iter_init(const struct nftnl_chain *c, + struct nftnl_rule_iter *iter) +{ + iter->c = c; + if (list_empty(&c->rule_list)) + iter->cur = NULL; + else + iter->cur = list_entry(c->rule_list.next, struct nftnl_rule, + head); +} + +EXPORT_SYMBOL(nftnl_rule_iter_create); +struct nftnl_rule_iter *nftnl_rule_iter_create(const struct nftnl_chain *c) +{ + struct nftnl_rule_iter *iter; + + iter = calloc(1, sizeof(struct nftnl_rule_iter)); + if (iter == NULL) + return NULL; + + nftnl_rule_iter_init(c, iter); + + return iter; +} + +EXPORT_SYMBOL(nftnl_rule_iter_next); +struct nftnl_rule *nftnl_rule_iter_next(struct nftnl_rule_iter *iter) +{ + struct nftnl_rule *rule = iter->cur; + + if (rule == NULL) + return NULL; + + /* get next rule, if any */ + iter->cur = list_entry(iter->cur->head.next, struct nftnl_rule, head); + if (&iter->cur->head == iter->c->rule_list.next) + return NULL; + + return rule; +} + +EXPORT_SYMBOL(nftnl_rule_iter_destroy); +void nftnl_rule_iter_destroy(struct nftnl_rule_iter *iter) +{ + xfree(iter); +} + +#define CHAIN_NAME_HSIZE 512 + struct nftnl_chain_list { + struct list_head list; + struct hlist_head name_hash[CHAIN_NAME_HSIZE]; }; EXPORT_SYMBOL(nftnl_chain_list_alloc); struct nftnl_chain_list *nftnl_chain_list_alloc(void) { struct nftnl_chain_list *list; + int i; list = calloc(1, sizeof(struct nftnl_chain_list)); if (list == NULL) return NULL; INIT_LIST_HEAD(&list->list); + for (i = 0; i < CHAIN_NAME_HSIZE; i++) + INIT_HLIST_HEAD(&list->name_hash[i]); return list; } @@ -709,6 +845,7 @@ list_for_each_entry_safe(r, tmp, &list->list, head) { list_del(&r->head); + hlist_del(&r->hnode); nftnl_chain_free(r); } xfree(list); @@ -720,15 +857,31 @@ return list_empty(&list->list); } +static uint32_t djb_hash(const char *key) +{ + uint32_t i, hash = 5381; + + for (i = 0; i < strlen(key); i++) + hash = ((hash << 5) + hash) + key[i]; + + return hash; +} + EXPORT_SYMBOL(nftnl_chain_list_add); void nftnl_chain_list_add(struct nftnl_chain *r, struct nftnl_chain_list *list) { + int key = djb_hash(r->name) % CHAIN_NAME_HSIZE; + + hlist_add_head(&r->hnode, &list->name_hash[key]); list_add(&r->head, &list->list); } EXPORT_SYMBOL(nftnl_chain_list_add_tail); void nftnl_chain_list_add_tail(struct nftnl_chain *r, struct nftnl_chain_list *list) { + int key = djb_hash(r->name) % CHAIN_NAME_HSIZE; + + hlist_add_head(&r->hnode, &list->name_hash[key]); list_add_tail(&r->head, &list->list); } @@ -736,6 +889,7 @@ void nftnl_chain_list_del(struct nftnl_chain *r) { list_del(&r->head); + hlist_del(&r->hnode); } EXPORT_SYMBOL(nftnl_chain_list_foreach); @@ -754,6 +908,22 @@ return 0; } +EXPORT_SYMBOL(nftnl_chain_list_lookup_byname); +struct nftnl_chain * +nftnl_chain_list_lookup_byname(struct nftnl_chain_list *chain_list, + const char *chain) +{ + int key = djb_hash(chain) % CHAIN_NAME_HSIZE; + struct nftnl_chain *c; + struct hlist_node *n; + + hlist_for_each_entry(c, n, &chain_list->name_hash[key], hnode) { + if (!strcmp(chain, c->name)) + return c; + } + return NULL; +} + struct nftnl_chain_list_iter { const struct nftnl_chain_list *list; struct nftnl_chain *cur; diff -Nru libnftnl-1.1.2/src/expr/ct.c libnftnl-1.1.4/src/expr/ct.c --- libnftnl-1.1.2/src/expr/ct.c 2018-11-13 11:02:34.906977245 +0000 +++ libnftnl-1.1.4/src/expr/ct.c 2019-08-19 09:18:14.311010150 +0000 @@ -172,6 +172,7 @@ [NFT_CT_DST_IP] = "dst_ip", [NFT_CT_SRC_IP6] = "src_ip6", [NFT_CT_DST_IP6] = "dst_ip6", + [NFT_CT_ID] = "id", }; static const char *ctkey2str(uint32_t ctkey) diff -Nru libnftnl-1.1.2/src/expr/exthdr.c libnftnl-1.1.4/src/expr/exthdr.c --- libnftnl-1.1.2/src/expr/exthdr.c 2018-11-13 11:02:34.906977245 +0000 +++ libnftnl-1.1.4/src/expr/exthdr.c 2019-08-19 09:18:14.311010150 +0000 @@ -200,6 +200,9 @@ case NFT_EXTHDR_OP_TCPOPT: return " tcpopt"; case NFT_EXTHDR_OP_IPV6: + return " ipv6"; + case NFT_EXTHDR_OP_IPV4: + return " ipv4"; default: return ""; } @@ -209,6 +212,8 @@ { if (!strcmp(str, "tcpopt")) return NFT_EXTHDR_OP_TCPOPT; + if (!strcmp(str, "ipv4")) + return NFT_EXTHDR_OP_IPV4; /* if str == "ipv6" or anything else */ return NFT_EXTHDR_OP_IPV6; diff -Nru libnftnl-1.1.2/src/expr/hash.c libnftnl-1.1.4/src/expr/hash.c --- libnftnl-1.1.2/src/expr/hash.c 2018-11-13 11:02:34.906977245 +0000 +++ libnftnl-1.1.4/src/expr/hash.c 2019-08-19 09:18:14.311010150 +0000 @@ -28,10 +28,6 @@ unsigned int modulus; unsigned int seed; unsigned int offset; - struct { - const char *name; - uint32_t id; - } map; }; static int @@ -61,14 +57,6 @@ case NFTNL_EXPR_HASH_TYPE: memcpy(&hash->type, data, sizeof(hash->type)); break; - case NFTNL_EXPR_HASH_SET_NAME: - hash->map.name = strdup(data); - if (!hash->map.name) - return -1; - break; - case NFTNL_EXPR_HASH_SET_ID: - memcpy(&hash->map.id, data, sizeof(hash->map.id)); - break; default: return -1; } @@ -103,12 +91,6 @@ case NFTNL_EXPR_HASH_TYPE: *data_len = sizeof(hash->type); return &hash->type; - case NFTNL_EXPR_HASH_SET_NAME: - *data_len = strlen(hash->map.name) + 1; - return hash->map.name; - case NFTNL_EXPR_HASH_SET_ID: - *data_len = sizeof(hash->map.id); - return &hash->map.id; } return NULL; } @@ -129,14 +111,9 @@ case NFTA_HASH_SEED: case NFTA_HASH_OFFSET: case NFTA_HASH_TYPE: - case NFTA_HASH_SET_ID: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) abi_breakage(); break; - case NFTA_HASH_SET_NAME: - if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) - abi_breakage(); - break; } tb[type] = attr; @@ -162,10 +139,6 @@ mnl_attr_put_u32(nlh, NFTA_HASH_OFFSET, htonl(hash->offset)); if (e->flags & (1 << NFTNL_EXPR_HASH_TYPE)) mnl_attr_put_u32(nlh, NFTA_HASH_TYPE, htonl(hash->type)); - if (e->flags & (1 << NFTNL_EXPR_HASH_SET_NAME)) - mnl_attr_put_str(nlh, NFTA_HASH_SET_NAME, hash->map.name); - if (e->flags & (1 << NFTNL_EXPR_HASH_SET_ID)) - mnl_attr_put_u32(nlh, NFTA_HASH_SET_ID, htonl(hash->map.id)); } static int @@ -206,16 +179,6 @@ hash->type = ntohl(mnl_attr_get_u32(tb[NFTA_HASH_TYPE])); e->flags |= (1 << NFTNL_EXPR_HASH_TYPE); } - if (tb[NFTA_HASH_SET_NAME]) { - hash->map.name = - strdup(mnl_attr_get_str(tb[NFTA_HASH_SET_NAME])); - e->flags |= (1 << NFTNL_EXPR_HASH_SET_NAME); - } - if (tb[NFTA_HASH_SET_ID]) { - hash->map.id = - ntohl(mnl_attr_get_u32(tb[NFTA_HASH_SET_ID])); - e->flags |= (1 << NFTNL_EXPR_HASH_SET_ID); - } return ret; } @@ -252,12 +215,6 @@ SNPRINTF_BUFFER_SIZE(ret, remain, offset); } - if (hash->map.id) { - ret = snprintf(buf + offset, remain, "set %s id %u ", - hash->map.name, hash->map.id); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - } - return offset; } diff -Nru libnftnl-1.1.2/src/expr/meta.c libnftnl-1.1.4/src/expr/meta.c --- libnftnl-1.1.2/src/expr/meta.c 2018-11-13 11:02:34.906977245 +0000 +++ libnftnl-1.1.4/src/expr/meta.c 2019-08-19 09:18:14.311010150 +0000 @@ -22,7 +22,7 @@ #include #ifndef NFT_META_MAX -#define NFT_META_MAX (NFT_META_SECPATH + 1) +#define NFT_META_MAX (NFT_META_BRI_IIFVPROTO + 1) #endif struct nftnl_expr_meta { @@ -159,6 +159,10 @@ [NFT_META_CGROUP] = "cgroup", [NFT_META_PRANDOM] = "prandom", [NFT_META_SECPATH] = "secpath", + [NFT_META_IIFKIND] = "iifkind", + [NFT_META_OIFKIND] = "oifkind", + [NFT_META_BRI_IIFPVID] = "bri_iifpvid", + [NFT_META_BRI_IIFVPROTO] = "bri_iifvproto", }; static const char *meta_key2str(uint8_t key) diff -Nru libnftnl-1.1.2/src/expr/numgen.c libnftnl-1.1.4/src/expr/numgen.c --- libnftnl-1.1.2/src/expr/numgen.c 2018-11-13 11:02:34.906977245 +0000 +++ libnftnl-1.1.4/src/expr/numgen.c 2019-08-19 09:18:14.311010150 +0000 @@ -25,10 +25,6 @@ unsigned int modulus; enum nft_ng_types type; unsigned int offset; - struct { - const char *name; - uint32_t id; - } map; }; static int @@ -50,14 +46,6 @@ case NFTNL_EXPR_NG_OFFSET: memcpy(&ng->offset, data, sizeof(ng->offset)); break; - case NFTNL_EXPR_NG_SET_NAME: - ng->map.name = strdup(data); - if (!ng->map.name) - return -1; - break; - case NFTNL_EXPR_NG_SET_ID: - memcpy(&ng->map.id, data, sizeof(ng->map.id)); - break; default: return -1; } @@ -83,12 +71,6 @@ case NFTNL_EXPR_NG_OFFSET: *data_len = sizeof(ng->offset); return &ng->offset; - case NFTNL_EXPR_NG_SET_NAME: - *data_len = strlen(ng->map.name) + 1; - return ng->map.name; - case NFTNL_EXPR_NG_SET_ID: - *data_len = sizeof(ng->map.id); - return &ng->map.id; } return NULL; } @@ -106,14 +88,9 @@ case NFTA_NG_MODULUS: case NFTA_NG_TYPE: case NFTA_NG_OFFSET: - case NFTA_NG_SET_ID: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) abi_breakage(); break; - case NFTA_NG_SET_NAME: - if (mnl_attr_validate(attr, MNL_TYPE_STRING) < 0) - abi_breakage(); - break; } tb[type] = attr; @@ -133,10 +110,6 @@ mnl_attr_put_u32(nlh, NFTA_NG_TYPE, htonl(ng->type)); if (e->flags & (1 << NFTNL_EXPR_NG_OFFSET)) mnl_attr_put_u32(nlh, NFTA_NG_OFFSET, htonl(ng->offset)); - if (e->flags & (1 << NFTNL_EXPR_NG_SET_NAME)) - mnl_attr_put_str(nlh, NFTA_NG_SET_NAME, ng->map.name); - if (e->flags & (1 << NFTNL_EXPR_NG_SET_ID)) - mnl_attr_put_u32(nlh, NFTA_NG_SET_ID, htonl(ng->map.id)); } static int @@ -165,16 +138,6 @@ ng->offset = ntohl(mnl_attr_get_u32(tb[NFTA_NG_OFFSET])); e->flags |= (1 << NFTNL_EXPR_NG_OFFSET); } - if (tb[NFTA_NG_SET_NAME]) { - ng->map.name = - strdup(mnl_attr_get_str(tb[NFTA_NG_SET_NAME])); - e->flags |= (1 << NFTNL_EXPR_NG_SET_NAME); - } - if (tb[NFTA_NG_SET_ID]) { - ng->map.id = - ntohl(mnl_attr_get_u32(tb[NFTA_NG_SET_ID])); - e->flags |= (1 << NFTNL_EXPR_NG_SET_ID); - } return ret; } @@ -206,12 +169,6 @@ SNPRINTF_BUFFER_SIZE(ret, remain, offset); } - if (ng->map.id) { - ret = snprintf(buf + offset, remain, "set %s id %u ", - ng->map.name, ng->map.id); - SNPRINTF_BUFFER_SIZE(ret, remain, offset); - } - return offset; } diff -Nru libnftnl-1.1.2/src/expr/osf.c libnftnl-1.1.4/src/expr/osf.c --- libnftnl-1.1.2/src/expr/osf.c 2018-11-13 11:02:34.906977245 +0000 +++ libnftnl-1.1.4/src/expr/osf.c 2019-08-19 09:18:14.311010150 +0000 @@ -15,6 +15,7 @@ struct nftnl_expr_osf { enum nft_registers dreg; uint8_t ttl; + uint32_t flags; }; static int nftnl_expr_osf_set(struct nftnl_expr *e, uint16_t type, @@ -29,6 +30,9 @@ case NFTNL_EXPR_OSF_TTL: memcpy(&osf->ttl, data, sizeof(osf->ttl)); break; + case NFTNL_EXPR_OSF_FLAGS: + memcpy(&osf->flags, data, sizeof(osf->flags)); + break; } return 0; } @@ -46,6 +50,9 @@ case NFTNL_EXPR_OSF_TTL: *data_len = sizeof(osf->ttl); return &osf->ttl; + case NFTNL_EXPR_OSF_FLAGS: + *data_len = sizeof(osf->flags); + return &osf->flags; } return NULL; } @@ -60,6 +67,7 @@ switch(type) { case NFTNL_EXPR_OSF_DREG: + case NFTNL_EXPR_OSF_FLAGS: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) abi_breakage(); break; @@ -68,6 +76,7 @@ if (mnl_attr_validate(attr, MNL_TYPE_U8) < 0) abi_breakage(); break; + } tb[type] = attr; @@ -83,6 +92,9 @@ mnl_attr_put_u32(nlh, NFTNL_EXPR_OSF_DREG, htonl(osf->dreg)); if (e->flags & (1 << NFTNL_EXPR_OSF_TTL)) mnl_attr_put_u8(nlh, NFTNL_EXPR_OSF_TTL, osf->ttl); + if (e->flags & (1 << NFTNL_EXPR_OSF_FLAGS)) + if (osf->flags) + mnl_attr_put_u32(nlh, NFTNL_EXPR_OSF_FLAGS, htonl(osf->flags)); } static int @@ -104,6 +116,11 @@ e->flags |= (1 << NFTNL_EXPR_OSF_TTL); } + if (tb[NFTA_OSF_FLAGS]) { + osf->flags = ntohl(mnl_attr_get_u32(tb[NFTA_OSF_FLAGS])); + e->flags |= (1 << NFTNL_EXPR_OSF_FLAGS); + } + return 0; } diff -Nru libnftnl-1.1.2/src/expr/synproxy.c libnftnl-1.1.4/src/expr/synproxy.c --- libnftnl-1.1.2/src/expr/synproxy.c 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/src/expr/synproxy.c 2019-08-19 09:18:14.315010142 +0000 @@ -0,0 +1,170 @@ +#include +#include +#include +#include +#include +#include + +#include "internal.h" +#include +#include +#include + +struct nftnl_expr_synproxy { + uint16_t mss; + uint8_t wscale; + uint32_t flags; +}; + +static int nftnl_expr_synproxy_set(struct nftnl_expr *e, uint16_t type, + const void *data, uint32_t data_len) +{ + struct nftnl_expr_synproxy *synproxy = nftnl_expr_data(e); + + switch(type) { + case NFTNL_EXPR_SYNPROXY_MSS: + memcpy(&synproxy->mss, data, sizeof(synproxy->mss)); + break; + case NFTNL_EXPR_SYNPROXY_WSCALE: + memcpy(&synproxy->wscale, data, sizeof(synproxy->wscale)); + break; + case NFTNL_EXPR_SYNPROXY_FLAGS: + memcpy(&synproxy->flags, data, sizeof(synproxy->flags)); + break; + } + return 0; +} + +static const void * +nftnl_expr_synproxy_get(const struct nftnl_expr *e, uint16_t type, + uint32_t *data_len) +{ + struct nftnl_expr_synproxy *synproxy = nftnl_expr_data(e); + + switch(type) { + case NFTNL_EXPR_SYNPROXY_MSS: + *data_len = sizeof(synproxy->mss); + return &synproxy->mss; + case NFTNL_EXPR_SYNPROXY_WSCALE: + *data_len = sizeof(synproxy->wscale); + return &synproxy->wscale; + case NFTNL_EXPR_SYNPROXY_FLAGS: + *data_len = sizeof(synproxy->flags); + return &synproxy->flags; + } + return NULL; +} + +static int nftnl_expr_synproxy_cb(const struct nlattr *attr, void *data) +{ + const struct nlattr **tb = data; + int type = mnl_attr_get_type(attr); + + if (mnl_attr_type_valid(attr, NFTA_SYNPROXY_MAX) < 0) + return MNL_CB_OK; + + switch(type) { + case NFTNL_EXPR_SYNPROXY_MSS: + if (mnl_attr_validate(attr, MNL_TYPE_U16) < 0) + abi_breakage(); + break; + + case NFTNL_EXPR_SYNPROXY_WSCALE: + if (mnl_attr_validate(attr, MNL_TYPE_U8) < 0) + abi_breakage(); + break; + + case NFTNL_EXPR_SYNPROXY_FLAGS: + if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) + abi_breakage(); + break; + } + + tb[type] = attr; + return MNL_CB_OK; +} + +static void +nftnl_expr_synproxy_build(struct nlmsghdr *nlh, const struct nftnl_expr *e) +{ + struct nftnl_expr_synproxy *synproxy = nftnl_expr_data(e); + + if (e->flags & (1 << NFTNL_EXPR_SYNPROXY_MSS)) + mnl_attr_put_u16(nlh, NFTNL_EXPR_SYNPROXY_MSS, + htons(synproxy->mss)); + if (e->flags & (1 << NFTNL_EXPR_SYNPROXY_WSCALE)) + mnl_attr_put_u8(nlh, NFTNL_EXPR_SYNPROXY_WSCALE, + synproxy->wscale); + if (e->flags & (1 << NFTNL_EXPR_SYNPROXY_FLAGS)) + mnl_attr_put_u32(nlh, NFTNL_EXPR_SYNPROXY_FLAGS, + htonl(synproxy->flags)); +} + +static int +nftnl_expr_synproxy_parse(struct nftnl_expr *e, struct nlattr *attr) +{ + struct nftnl_expr_synproxy *synproxy = nftnl_expr_data(e); + struct nlattr *tb[NFTA_SYNPROXY_MAX + 1] = {}; + + if (mnl_attr_parse_nested(attr, nftnl_expr_synproxy_cb, tb) < 0) + return -1; + + if (tb[NFTA_SYNPROXY_MSS]) { + synproxy->mss = ntohs(mnl_attr_get_u16(tb[NFTA_SYNPROXY_MSS])); + e->flags |= (1 << NFTNL_EXPR_SYNPROXY_MSS); + } + + if (tb[NFTA_SYNPROXY_WSCALE]) { + synproxy->wscale = mnl_attr_get_u8(tb[NFTA_SYNPROXY_WSCALE]); + e->flags |= (1 << NFTNL_EXPR_SYNPROXY_WSCALE); + } + + if (tb[NFTA_SYNPROXY_FLAGS]) { + synproxy->flags = ntohl(mnl_attr_get_u32(tb[NFTA_SYNPROXY_FLAGS])); + e->flags |= (1 << NFTNL_EXPR_SYNPROXY_FLAGS); + } + + return 0; +} + +static int nftnl_expr_synproxy_snprintf_default(char *buf, size_t size, + const struct nftnl_expr *e) +{ + struct nftnl_expr_synproxy *synproxy = nftnl_expr_data(e); + int ret, offset = 0, len = size; + + if (e->flags & (1 << NFTNL_EXPR_SYNPROXY_MSS) && + e->flags & (1 << NFTNL_EXPR_SYNPROXY_WSCALE)) { + ret = snprintf(buf, len, "mss %u wscale %u ", synproxy->mss, + synproxy->wscale); + SNPRINTF_BUFFER_SIZE(ret, len, offset); + } + + return offset; +} + +static int +nftnl_expr_synproxy_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, const struct nftnl_expr *e) +{ + switch(type) { + case NFTNL_OUTPUT_DEFAULT: + return nftnl_expr_synproxy_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_XML: + case NFTNL_OUTPUT_JSON: + default: + break; + } + return -1; +} + +struct expr_ops expr_ops_synproxy = { + .name = "synproxy", + .alloc_len = sizeof(struct nftnl_expr_synproxy), + .max_attr = NFTA_SYNPROXY_MAX, + .set = nftnl_expr_synproxy_set, + .get = nftnl_expr_synproxy_get, + .parse = nftnl_expr_synproxy_parse, + .build = nftnl_expr_synproxy_build, + .snprintf = nftnl_expr_synproxy_snprintf, +}; diff -Nru libnftnl-1.1.2/src/expr_ops.c libnftnl-1.1.4/src/expr_ops.c --- libnftnl-1.1.2/src/expr_ops.c 2018-11-13 11:02:34.906977245 +0000 +++ libnftnl-1.1.4/src/expr_ops.c 2019-08-19 09:18:14.315010142 +0000 @@ -37,6 +37,7 @@ extern struct expr_ops expr_ops_fib; extern struct expr_ops expr_ops_flow; extern struct expr_ops expr_ops_socket; +extern struct expr_ops expr_ops_synproxy; extern struct expr_ops expr_ops_tunnel; extern struct expr_ops expr_ops_osf; extern struct expr_ops expr_ops_xfrm; @@ -80,6 +81,7 @@ &expr_ops_objref, &expr_ops_flow, &expr_ops_socket, + &expr_ops_synproxy, &expr_ops_tunnel, &expr_ops_osf, &expr_ops_xfrm, diff -Nru libnftnl-1.1.2/src/flowtable.c libnftnl-1.1.4/src/flowtable.c --- libnftnl-1.1.2/src/flowtable.c 2018-11-13 11:02:34.910977239 +0000 +++ libnftnl-1.1.4/src/flowtable.c 2019-08-19 09:18:14.315010142 +0000 @@ -85,10 +85,9 @@ case NFTNL_FLOWTABLE_FLAGS: break; case NFTNL_FLOWTABLE_DEVICES: - for (i = 0; i < c->dev_array_len; i++) { + for (i = 0; i < c->dev_array_len; i++) xfree(c->dev_array[i]); - xfree(c->dev_array); - } + xfree(c->dev_array); break; default: return; @@ -146,10 +145,9 @@ len++; if (c->flags & (1 << NFTNL_FLOWTABLE_DEVICES)) { - for (i = 0; i < c->dev_array_len; i++) { + for (i = 0; i < c->dev_array_len; i++) xfree(c->dev_array[i]); - xfree(c->dev_array); - } + xfree(c->dev_array); } c->dev_array = calloc(len + 1, sizeof(char *)); @@ -163,6 +161,7 @@ break; case NFTNL_FLOWTABLE_SIZE: memcpy(&c->size, data, sizeof(c->size)); + break; case NFTNL_FLOWTABLE_FLAGS: memcpy(&c->ft_flags, data, sizeof(c->ft_flags)); break; @@ -246,7 +245,7 @@ uint32_t nftnl_flowtable_get_u32(const struct nftnl_flowtable *c, uint16_t attr) { - uint32_t data_len; + uint32_t data_len = 0; const uint32_t *val = nftnl_flowtable_get_data(c, attr, &data_len); nftnl_assert(val, attr, data_len == sizeof(uint32_t)); @@ -257,7 +256,7 @@ int32_t nftnl_flowtable_get_s32(const struct nftnl_flowtable *c, uint16_t attr) { - uint32_t data_len; + uint32_t data_len = 0; const int32_t *val = nftnl_flowtable_get_data(c, attr, &data_len); nftnl_assert(val, attr, data_len == sizeof(int32_t)); @@ -365,7 +364,7 @@ mnl_attr_for_each_nested(attr, nest) { if (mnl_attr_get_type(attr) != NFTA_DEVICE_NAME) - return -1; + goto err; dev_array[len++] = strdup(mnl_attr_get_str(attr)); if (len >= 8) break; @@ -376,14 +375,18 @@ c->dev_array = calloc(len + 1, sizeof(char *)); if (!c->dev_array) - return -1; + goto err; c->dev_array_len = len; for (i = 0; i < len; i++) - c->dev_array[i] = strdup(dev_array[i]); + c->dev_array[i] = dev_array[i]; return 0; +err: + while (len--) + xfree(dev_array[len]); + return -1; } static int nftnl_flowtable_parse_hook(struct nlattr *attr, struct nftnl_flowtable *c) diff -Nru libnftnl-1.1.2/src/libnftnl.map libnftnl-1.1.4/src/libnftnl.map --- libnftnl-1.1.2/src/libnftnl.map 2018-11-13 11:02:34.910977239 +0000 +++ libnftnl-1.1.4/src/libnftnl.map 2019-08-19 09:18:14.315010142 +0000 @@ -214,14 +214,14 @@ nftnl_gen_alloc; nftnl_gen_free; - nftnl_gen_attr_is_set; - nftnl_gen_attr_unset; - nftnl_gen_attr_set_data; - nftnl_gen_attr_set; - nftnl_gen_attr_set_u32; - nftnl_gen_attr_get_data; - nftnl_gen_attr_get; - nftnl_gen_attr_get_u32; + nftnl_gen_is_set; + nftnl_gen_unset; + nftnl_gen_set_data; + nftnl_gen_set; + nftnl_gen_set_u32; + nftnl_gen_get_data; + nftnl_gen_get; + nftnl_gen_get_u32; nftnl_gen_nlmsg_parse; nftnl_gen_snprintf; nftnl_gen_fprintf; @@ -336,3 +336,18 @@ local: *; }; + +LIBNFTNL_12 { + nftnl_chain_rule_add; + nftnl_chain_rule_add_tail; + nftnl_chain_rule_del; + nftnl_chain_rule_insert_at; + nftnl_chain_rule_append_at; + nftnl_rule_foreach; + nftnl_rule_iter_create; + nftnl_rule_iter_next; + nftnl_rule_iter_destroy; + + nftnl_chain_list_lookup_byname; + nftnl_rule_lookup_byindex; +} LIBNFTNL_11; diff -Nru libnftnl-1.1.2/src/obj/ct_expect.c libnftnl-1.1.4/src/obj/ct_expect.c --- libnftnl-1.1.2/src/obj/ct_expect.c 1970-01-01 00:00:00.000000000 +0000 +++ libnftnl-1.1.4/src/obj/ct_expect.c 2019-08-19 09:18:14.315010142 +0000 @@ -0,0 +1,213 @@ +/* + * (C) 2019 by Stéphane Veyret + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + */ + +#include +#include + +#include + +#include "obj.h" + +static int nftnl_obj_ct_expect_set(struct nftnl_obj *e, uint16_t type, + const void *data, uint32_t data_len) +{ + struct nftnl_obj_ct_expect *exp = nftnl_obj_data(e); + + switch (type) { + case NFTNL_OBJ_CT_EXPECT_L3PROTO: + memcpy(&exp->l3proto, data, sizeof(exp->l3proto)); + break; + case NFTNL_OBJ_CT_EXPECT_L4PROTO: + memcpy(&exp->l4proto, data, sizeof(exp->l4proto)); + break; + case NFTNL_OBJ_CT_EXPECT_DPORT: + memcpy(&exp->dport, data, sizeof(exp->dport)); + break; + case NFTNL_OBJ_CT_EXPECT_TIMEOUT: + memcpy(&exp->timeout, data, sizeof(exp->timeout)); + break; + case NFTNL_OBJ_CT_EXPECT_SIZE: + memcpy(&exp->size, data, sizeof(exp->size)); + break; + default: + return -1; + } + return 0; +} + +static const void *nftnl_obj_ct_expect_get(const struct nftnl_obj *e, + uint16_t type, uint32_t *data_len) +{ + struct nftnl_obj_ct_expect *exp = nftnl_obj_data(e); + + switch (type) { + case NFTNL_OBJ_CT_EXPECT_L3PROTO: + *data_len = sizeof(exp->l3proto); + return &exp->l3proto; + case NFTNL_OBJ_CT_EXPECT_L4PROTO: + *data_len = sizeof(exp->l4proto); + return &exp->l4proto; + case NFTNL_OBJ_CT_EXPECT_DPORT: + *data_len = sizeof(exp->dport); + return &exp->dport; + case NFTNL_OBJ_CT_EXPECT_TIMEOUT: + *data_len = sizeof(exp->timeout); + return &exp->timeout; + case NFTNL_OBJ_CT_EXPECT_SIZE: + *data_len = sizeof(exp->size); + return &exp->size; + } + return NULL; +} + +static int nftnl_obj_ct_expect_cb(const struct nlattr *attr, void *data) +{ + int type = mnl_attr_get_type(attr); + const struct nlattr **tb = data; + + if (mnl_attr_type_valid(attr, NFTA_CT_EXPECT_MAX) < 0) + return MNL_CB_OK; + + switch (type) { + case NFTA_CT_EXPECT_L3PROTO: + if (mnl_attr_validate(attr, MNL_TYPE_U16) < 0) + abi_breakage(); + break; + case NFTA_CT_EXPECT_L4PROTO: + if (mnl_attr_validate(attr, MNL_TYPE_U8) < 0) + abi_breakage(); + break; + case NFTA_CT_EXPECT_DPORT: + if (mnl_attr_validate(attr, MNL_TYPE_U16) < 0) + abi_breakage(); + break; + case NFTA_CT_EXPECT_TIMEOUT: + if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) + abi_breakage(); + break; + case NFTA_CT_EXPECT_SIZE: + if (mnl_attr_validate(attr, MNL_TYPE_U8) < 0) + abi_breakage(); + break; + } + + tb[type] = attr; + return MNL_CB_OK; +} + +static void +nftnl_obj_ct_expect_build(struct nlmsghdr *nlh, const struct nftnl_obj *e) +{ + struct nftnl_obj_ct_expect *exp = nftnl_obj_data(e); + + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L3PROTO)) + mnl_attr_put_u16(nlh, NFTA_CT_EXPECT_L3PROTO, htons(exp->l3proto)); + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L4PROTO)) + mnl_attr_put_u8(nlh, NFTA_CT_EXPECT_L4PROTO, exp->l4proto); + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_DPORT)) + mnl_attr_put_u16(nlh, NFTA_CT_EXPECT_DPORT, htons(exp->dport)); + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_TIMEOUT)) + mnl_attr_put_u32(nlh, NFTA_CT_EXPECT_TIMEOUT, exp->timeout); + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_SIZE)) + mnl_attr_put_u8(nlh, NFTA_CT_EXPECT_SIZE, exp->size); +} + +static int +nftnl_obj_ct_expect_parse(struct nftnl_obj *e, struct nlattr *attr) +{ + struct nftnl_obj_ct_expect *exp = nftnl_obj_data(e); + struct nlattr *tb[NFTA_CT_EXPECT_MAX + 1] = {}; + + if (mnl_attr_parse_nested(attr, nftnl_obj_ct_expect_cb, tb) < 0) + return -1; + + if (tb[NFTA_CT_EXPECT_L3PROTO]) { + exp->l3proto = ntohs(mnl_attr_get_u16(tb[NFTA_CT_EXPECT_L3PROTO])); + e->flags |= (1 << NFTNL_OBJ_CT_EXPECT_L3PROTO); + } + if (tb[NFTA_CT_EXPECT_L4PROTO]) { + exp->l4proto = mnl_attr_get_u8(tb[NFTA_CT_EXPECT_L4PROTO]); + e->flags |= (1 << NFTNL_OBJ_CT_EXPECT_L4PROTO); + } + if (tb[NFTA_CT_EXPECT_DPORT]) { + exp->dport = ntohs(mnl_attr_get_u16(tb[NFTA_CT_EXPECT_DPORT])); + e->flags |= (1 << NFTNL_OBJ_CT_EXPECT_DPORT); + } + if (tb[NFTA_CT_EXPECT_TIMEOUT]) { + exp->timeout = mnl_attr_get_u32(tb[NFTA_CT_EXPECT_TIMEOUT]); + e->flags |= (1 << NFTNL_OBJ_CT_EXPECT_TIMEOUT); + } + if (tb[NFTA_CT_EXPECT_SIZE]) { + exp->size = mnl_attr_get_u8(tb[NFTA_CT_EXPECT_SIZE]); + e->flags |= (1 << NFTNL_OBJ_CT_EXPECT_SIZE); + } + + return 0; +} + +static int nftnl_obj_ct_expect_snprintf_default(char *buf, size_t len, + const struct nftnl_obj *e) +{ + int ret = 0; + int offset = 0, remain = len; + struct nftnl_obj_ct_expect *exp = nftnl_obj_data(e); + + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L3PROTO)) { + ret = snprintf(buf + offset, len, "family %d ", exp->l3proto); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_L4PROTO)) { + ret = snprintf(buf + offset, len, "protocol %d ", exp->l4proto); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_DPORT)) { + ret = snprintf(buf + offset, len, "dport %d ", exp->dport); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_TIMEOUT)) { + ret = snprintf(buf + offset, len, "timeout %d ", exp->timeout); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } + if (e->flags & (1 << NFTNL_OBJ_CT_EXPECT_SIZE)) { + ret = snprintf(buf + offset, len, "size %d ", exp->size); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } + + buf[offset] = '\0'; + return offset; +} + +static int nftnl_obj_ct_expect_snprintf(char *buf, size_t len, uint32_t type, + uint32_t flags, + const struct nftnl_obj *e) +{ + if (len) + buf[0] = '\0'; + + switch (type) { + case NFTNL_OUTPUT_DEFAULT: + return nftnl_obj_ct_expect_snprintf_default(buf, len, e); + case NFTNL_OUTPUT_JSON: + default: + break; + } + return -1; +} + +struct obj_ops obj_ops_ct_expect = { + .name = "ct_expect", + .type = NFT_OBJECT_CT_EXPECT, + .alloc_len = sizeof(struct nftnl_obj_ct_expect), + .max_attr = NFTA_CT_EXPECT_MAX, + .set = nftnl_obj_ct_expect_set, + .get = nftnl_obj_ct_expect_get, + .parse = nftnl_obj_ct_expect_parse, + .build = nftnl_obj_ct_expect_build, + .snprintf = nftnl_obj_ct_expect_snprintf, +}; diff -Nru libnftnl-1.1.2/src/object.c libnftnl-1.1.4/src/object.c --- libnftnl-1.1.2/src/object.c 2018-11-13 11:02:34.910977239 +0000 +++ libnftnl-1.1.4/src/object.c 2019-08-19 09:18:14.315010142 +0000 @@ -25,7 +25,7 @@ #include #include "obj.h" -static struct obj_ops *obj_ops[] = { +static struct obj_ops *obj_ops[__NFT_OBJECT_MAX] = { [NFT_OBJECT_COUNTER] = &obj_ops_counter, [NFT_OBJECT_QUOTA] = &obj_ops_quota, [NFT_OBJECT_CT_HELPER] = &obj_ops_ct_helper, @@ -33,6 +33,7 @@ [NFT_OBJECT_TUNNEL] = &obj_ops_tunnel, [NFT_OBJECT_CT_TIMEOUT] = &obj_ops_ct_timeout, [NFT_OBJECT_SECMARK] = &obj_ops_secmark, + [NFT_OBJECT_CT_EXPECT] = &obj_ops_ct_expect, }; static struct obj_ops *nftnl_obj_ops_lookup(uint32_t type) diff -Nru libnftnl-1.1.2/src/rule.c libnftnl-1.1.4/src/rule.c --- libnftnl-1.1.2/src/rule.c 2018-11-13 11:02:34.910977239 +0000 +++ libnftnl-1.1.4/src/rule.c 2019-08-19 09:18:14.315010142 +0000 @@ -30,28 +30,6 @@ #include #include -struct nftnl_rule { - struct list_head head; - - uint32_t flags; - uint32_t family; - const char *table; - const char *chain; - uint64_t handle; - uint64_t position; - uint32_t id; - struct { - void *data; - uint32_t len; - } user; - struct { - uint32_t flags; - uint32_t proto; - } compat; - - struct list_head expr_list; -}; - EXPORT_SYMBOL(nftnl_rule_alloc); struct nftnl_rule *nftnl_rule_alloc(void) { @@ -109,6 +87,7 @@ case NFTNL_RULE_POSITION: case NFTNL_RULE_FAMILY: case NFTNL_RULE_ID: + case NFTNL_RULE_POSITION_ID: break; case NFTNL_RULE_USERDATA: xfree(r->user.data); @@ -125,6 +104,7 @@ [NFTNL_RULE_FAMILY] = sizeof(uint32_t), [NFTNL_RULE_POSITION] = sizeof(uint64_t), [NFTNL_RULE_ID] = sizeof(uint32_t), + [NFTNL_RULE_POSITION_ID] = sizeof(uint32_t), }; EXPORT_SYMBOL(nftnl_rule_set_data); @@ -180,6 +160,9 @@ case NFTNL_RULE_ID: memcpy(&r->id, data, sizeof(r->id)); break; + case NFTNL_RULE_POSITION_ID: + memcpy(&r->position_id, data, sizeof(r->position_id)); + break; } r->flags |= (1 << attr); return 0; @@ -244,6 +227,9 @@ case NFTNL_RULE_ID: *data_len = sizeof(uint32_t); return &r->id; + case NFTNL_RULE_POSITION_ID: + *data_len = sizeof(uint32_t); + return &r->position_id; } return NULL; } @@ -335,6 +321,8 @@ } if (r->flags & (1 << NFTNL_RULE_ID)) mnl_attr_put_u32(nlh, NFTA_RULE_ID, htonl(r->id)); + if (r->flags & (1 << NFTNL_RULE_POSITION_ID)) + mnl_attr_put_u32(nlh, NFTA_RULE_POSITION_ID, htonl(r->position_id)); } EXPORT_SYMBOL(nftnl_rule_add_expr); @@ -374,6 +362,7 @@ abi_breakage(); break; case NFTA_RULE_ID: + case NFTA_RULE_POSITION_ID: if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) abi_breakage(); break; @@ -505,6 +494,10 @@ r->id = ntohl(mnl_attr_get_u32(tb[NFTA_RULE_ID])); r->flags |= (1 << NFTNL_RULE_ID); } + if (tb[NFTA_RULE_POSITION_ID]) { + r->position_id = ntohl(mnl_attr_get_u32(tb[NFTA_RULE_POSITION_ID])); + r->flags |= (1 << NFTNL_RULE_POSITION_ID); + } r->family = nfg->nfgen_family; r->flags |= (1 << NFTNL_RULE_FAMILY); @@ -588,6 +581,11 @@ SNPRINTF_BUFFER_SIZE(ret, remain, offset); } + if (r->flags & (1 << NFTNL_RULE_POSITION_ID)) { + ret = snprintf(buf + offset, remain, "%u ", r->position_id); + SNPRINTF_BUFFER_SIZE(ret, remain, offset); + } + ret = snprintf(buf + offset, remain, "\n"); SNPRINTF_BUFFER_SIZE(ret, remain, offset); diff -Nru libnftnl-1.1.2/src/set_elem.c libnftnl-1.1.4/src/set_elem.c --- libnftnl-1.1.2/src/set_elem.c 2018-11-13 11:02:34.910977239 +0000 +++ libnftnl-1.1.4/src/set_elem.c 2019-08-19 09:18:14.315010142 +0000 @@ -126,6 +126,9 @@ case NFTNL_SET_ELEM_TIMEOUT: /* NFTA_SET_ELEM_TIMEOUT */ memcpy(&s->timeout, data, sizeof(s->timeout)); break; + case NFTNL_SET_ELEM_EXPIRATION: /* NFTA_SET_ELEM_EXPIRATION */ + memcpy(&s->expiration, data, sizeof(s->expiration)); + break; case NFTNL_SET_ELEM_USERDATA: /* NFTA_SET_ELEM_USERDATA */ if (s->flags & (1 << NFTNL_SET_ELEM_USERDATA)) xfree(s->user.data); @@ -265,6 +268,8 @@ mnl_attr_put_u32(nlh, NFTA_SET_ELEM_FLAGS, htonl(e->set_elem_flags)); if (e->flags & (1 << NFTNL_SET_ELEM_TIMEOUT)) mnl_attr_put_u64(nlh, NFTA_SET_ELEM_TIMEOUT, htobe64(e->timeout)); + if (e->flags & (1 << NFTNL_SET_ELEM_EXPIRATION)) + mnl_attr_put_u64(nlh, NFTA_SET_ELEM_EXPIRATION, htobe64(e->expiration)); if (e->flags & (1 << NFTNL_SET_ELEM_KEY)) { struct nlattr *nest1; diff -Nru libnftnl-1.1.2/src/udata.c libnftnl-1.1.4/src/udata.c --- libnftnl-1.1.2/src/udata.c 2018-11-13 11:02:34.910977239 +0000 +++ libnftnl-1.1.4/src/udata.c 2019-08-19 09:18:14.315010142 +0000 @@ -122,9 +122,11 @@ EXPORT_SYMBOL(nftnl_udata_get_u32); uint32_t nftnl_udata_get_u32(const struct nftnl_udata *attr) { - uint32_t *data = (uint32_t *)attr->value; + uint32_t data; - return *data; + memcpy(&data, attr->value, sizeof(data)); + + return data; } EXPORT_SYMBOL(nftnl_udata_next); diff -Nru libnftnl-1.1.2/tests/Makefile.in libnftnl-1.1.4/tests/Makefile.in --- libnftnl-1.1.2/tests/Makefile.in 2018-11-13 11:02:42.898962460 +0000 +++ libnftnl-1.1.4/tests/Makefile.in 2019-08-19 09:18:22.214993611 +0000 @@ -700,7 +700,7 @@ # set age to 0. # # -LIBVERSION = 11:0:0 +LIBVERSION = 12:0:1 AM_CPPFLAGS = ${regular_CPPFLAGS} -I${top_srcdir}/include ${LIBMNL_CFLAGS} ${LIBMXML_CFLAGS} AM_CFLAGS = ${regular_CFLAGS} ${GCC_FVISIBILITY_HIDDEN} TESTS = $(check_PROGRAMS)