From: Patrick McHardy <kaber@trash.net>
To: "Carlos Falgueras García" <carlosfg@riseup.net>
Cc: netfilter-devel@vger.kernel.org, pablo@netfilter.org
Subject: Re: [PATCH 3/4] libnftnl: set: Implement new buffer of TLV objects.
Date: Mon, 4 Jan 2016 12:06:26 +0000 [thread overview]
Message-ID: <20160104120625.GA31140@macbook.localdomain> (raw)
In-Reply-To: <1451849900-18077-3-git-send-email-carlosfg@riseup.net>
On 03.01, Carlos Falgueras García wrote:
> +/* TLV validation */
> +enum nftnl_attr_data_type {
> + NFTNL_ATTR_TYPE_UNSPEC,
> + NFTNL_ATTR_TYPE_U8,
> + NFTNL_ATTR_TYPE_U16,
> + NFTNL_ATTR_TYPE_U32,
> + NFTNL_ATTR_TYPE_U64,
> + NFTNL_ATTR_TYPE_STRING,
> + NFTNL_ATTR_TYPE_FLAG,
> + NFTNL_ATTR_TYPE_MSECS,
> + NFTNL_ATTR_TYPE_NESTED,
> + NFTNL_ATTR_TYPE_NESTED_COMPAT,
> + NFTNL_ATTR_TYPE_NUL_STRING,
> + NFTNL_ATTR_TYPE_BINARY,
> + __NFTNL_ATTR_TYPE_MAX,
We don't need quite a few of these. Compat is obviously unnecessary. Same thing
goes for MSECS and NUL_STRING since the kernel doesn't do interpretation of
the user data. FLAG I would avoid since it uses a full u8, so better have
userspace simply use that and do interpretation as a flag.
> +/*
> + * TLV structures:
> + * nftnl_attr
> + * <-- sizeof(nftnl_attr) --> <-- nftnl_attr->len -->
> + * +--------------------------+- - - - - -+- - - - - -- - - - - -+- - - - - +
> + * | Header | Pading | Payload | Pading |
> + * | (4 bytes) | (4 bytes) | | |
> + * +--------------------------+- - - - - -+- - - - - - - - - - - -+- - - - - +
> + * <------------------------ nftnl_attr_get_size() ------------------------>
We don't need a header I'd think. Just the raw attributes.
> + * nftnl_attr->type (16 bits)
> + * +---+---+-------------------------------+
> + * | N | O | Attribute Type |
> + * +---+---+-------------------------------+
> + * N := Carries nested attributes
> + * O := Payload stored in network byte order
> + *
> + * Note: The N and O flag are mutually exclusive.
> + */
> +
> +struct nftnl_attr {
> + uint16_t type;
> + uint16_t len;
u16 is too large for both. Our maximum length is 256 anyways, without the
header u8 is enough. For type I'd also say u8 should be enough, especially
when considering the very limited space.
> +#define NFTNLA_F_NESTED (1 << 15)
> +#define NFTNLA_F_NET_BYTEORDER (1 << 14)
> +#define NFTNLA_TYPE_MASK ~(NFTNLA_F_NESTED | NFTNLA_F_NET_BYTEORDER)
Also unnecessary since the kernel doesn't do interpretation.
> +#define NFTNL_ALIGNTO 8
> +#define NFTNL_ALIGN(len) (((len)+NFTNL_ALIGNTO-1) & ~(NFTNL_ALIGNTO-1))
I'd at least consider whether we really want this or whether userspace should
do an unconditional copy to avoid unaligned accesses. We have very limited
space and should try to pack tightly.
--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-01-04 12:16 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-03 19:38 [PATCH 1/4] nf: netfilter: nf_tables_api: Add new attributes into nft_set to store user data Carlos Falgueras García
2016-01-03 19:38 ` [PATCH 2/4] libnftnl: set: Add new attribute into 'set' to store an arbitrary length " Carlos Falgueras García
2016-01-03 19:38 ` [PATCH 3/4] libnftnl: set: Implement new buffer of TLV objects Carlos Falgueras García
2016-01-04 12:06 ` Patrick McHardy [this message]
2016-01-03 19:38 ` [PATCH 4/4] libnftnl: examples: Modify the example to allow add TLV objects as user data Carlos Falgueras García
2016-01-04 12:32 ` [PATCH 1/4] nf: netfilter: nf_tables_api: Add new attributes into nft_set to store " Patrick McHardy
2016-01-05 10:34 ` Pablo Neira Ayuso
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160104120625.GA31140@macbook.localdomain \
--to=kaber@trash.net \
--cc=carlosfg@riseup.net \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).