All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Phil Sutter <phil@nwl.cc>, netfilter-devel@vger.kernel.org
Subject: Re: [PATCH libnftnl 3/3] desc: add set description
Date: Fri, 11 Mar 2022 00:24:33 +0100	[thread overview]
Message-ID: <YiqIsbxAQUlIpJSY@salvia> (raw)
In-Reply-To: <Yinhg4XTUjuTuezv@orbyte.nwl.cc>

On Thu, Mar 10, 2022 at 12:31:15PM +0100, Phil Sutter wrote:
> Hi,
> 
> On Thu, Jan 20, 2022 at 01:04:02AM +0100, Pablo Neira Ayuso wrote:
> [...]
> > diff --git a/src/desc.c b/src/desc.c
> > index f73e74c2c7d3..c8b3195db850 100644
> > --- a/src/desc.c
> > +++ b/src/desc.c
> [...]
> > +static int nftnl_set_desc_build_dtype(struct nftnl_udata_buf *udbuf,
> > +				      const struct nftnl_set_desc *dset)
> > +{
> > +	struct nftnl_udata *nest;
> > +	int i, err;
> > +
> > +	switch (dset->type) {
> > +	case NFTNL_DESC_SET_TYPEOF:
> > +		nest = nftnl_udata_nest_start(udbuf, NFTNL_UDATA_SET_KEY);
> > +		for (i = 0; i < dset->key.num_type; i++) {
> > +			err = __nftnl_udata_set_dtype_build(udbuf, dset->key.dtype[i], i);
> > +			if (err < 0)
> > +				return err;
> > +		}
> > +		nftnl_udata_nest_end(udbuf, nest);
> > +		break;
> > +	case NFTNL_DESC_SET_DATATYPE:
> > +		nest = nftnl_udata_nest_start(udbuf, NFTNL_UDATA_SET_DATA);
> > +		for (i = 0; i < dset->data.num_type; i++) {
> > +			err = __nftnl_udata_set_dtype_build(udbuf, dset->data.dtype[i], i);
> > +			if (err < 0)
> > +				return err;
> > +		}
> > +		nftnl_udata_nest_end(udbuf, nest);
> > +		break;
> > +	case NFTNL_DESC_SET_UNSPEC:
> > +		return -1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +static int __nftnl_set_desc_build_typeof(struct nftnl_udata_buf *udbuf,
> > +					 const struct nftnl_expr_desc *dexpr,
> > +					 uint8_t attr_type)
> > +{
> > +	struct nftnl_udata *nest;
> > +	int err;
> > +
> > +	nest = nftnl_udata_nest_start(udbuf, attr_type);
> > +	err = nftnl_expr_desc_build(udbuf, dexpr);
> > +	nftnl_udata_nest_end(udbuf, nest);
> > +
> > +	return err;
> > +}
> > +
> > +static int nftnl_set_desc_build_typeof(struct nftnl_udata_buf *udbuf,
> > +				       const struct nftnl_set_desc *dset)
> > +{
> > +	struct nftnl_udata *nest;
> > +	int i;
> > +
> > +	switch (dset->type) {
> > +	case NFTNL_DESC_SET_TYPEOF:
> > +		nest = nftnl_udata_nest_start(udbuf, NFTNL_UDATA_SET_KEY_TYPEOF);
> > +		for (i = 0; i < dset->key.num_typeof; i++)
> > +			__nftnl_set_desc_build_typeof(udbuf, dset->key.expr[i], i);
> > +
> > +		nftnl_udata_nest_end(udbuf, nest);
> > +		break;
> > +	case NFTNL_DESC_SET_DATATYPE:
> > +		nest = nftnl_udata_nest_start(udbuf, NFTNL_UDATA_SET_DATA_TYPEOF);
> > +		for (i = 0; i < dset->key.num_typeof; i++)
> > +			__nftnl_set_desc_build_typeof(udbuf, dset->data.expr[i], i);
> > +
> > +		nftnl_udata_nest_end(udbuf, nest);
> > +		break;
> > +	case NFTNL_DESC_SET_UNSPEC:
> > +		return -1;
> > +	}
> > +
> > +	return 0;
> > +}
> > +
> > +EXPORT_SYMBOL(nftnl_set_desc_build_udata);
> > +int nftnl_set_desc_build_udata(struct nftnl_udata_buf *udbuf,
> > +			       const struct nftnl_set_desc *dset)
> > +{
> > +	if (!nftnl_udata_put_u32(udbuf, NFTNL_UDATA_SET_FLAGS, dset->flags))
> > +		return -1;
> > +
> > +	switch (dset->type) {
> > +	case NFTNL_DESC_SET_DATATYPE:
> > +		return nftnl_set_desc_build_dtype(udbuf, dset);
> > +	case NFTNL_DESC_SET_TYPEOF:
> > +		return nftnl_set_desc_build_typeof(udbuf, dset);
> > +	case NFTNL_DESC_SET_UNSPEC:
> > +		return -1;
> > +	}
> > +
> > +	if (!nftnl_udata_put_strz(udbuf, NFTNL_UDATA_SET_COMMENT, dset->comment))
> > +		return -1;
> > +
> > +	return -1;
> > +}
> 
> This is odd: Depending on dset->type, nftnl_set_desc_build_udata() calls
> either nftnl_set_desc_build_dtype() or nftnl_set_desc_build_typeof().

That's indeed incorrect, nftnl_set_desc_build_typeof() should be:

static int nftnl_set_desc_build_typeof(struct nftnl_udata_buf *udbuf,
				       const struct nftnl_set_desc *dset)
{
	struct nftnl_udata *nest;
	int i;

	nest = nftnl_udata_nest_start(udbuf, NFTNL_UDATA_SET_KEY_TYPEOF);
	for (i = 0; i < dset->key.num_typeof; i++)
		__nftnl_set_desc_build_typeof(udbuf, dset->key.expr[i], i);

	nftnl_udata_nest_end(udbuf, nest);

	return 0;
}

The idea is: A set can either use datatype or typeof to define the
elements that it stores. Then, a concatenation is possible.

> Yet both check dset->type again. This looks like a mix-up of set/map key
> and data definitions and typeof vs. "regular" definition styles.

This patchset was a sketch PoC, I should have label it more explicit
as such.

  reply	other threads:[~2022-03-10 23:24 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-20  0:03 [PATCH libnftnl 0/3] add description infrastructure Pablo Neira Ayuso
2022-01-20  0:04 ` [PATCH libnftnl 1/3] desc: add expression description Pablo Neira Ayuso
2022-01-20  0:04 ` [PATCH libnftnl 2/3] desc: add datatype description Pablo Neira Ayuso
2022-01-20  0:04 ` [PATCH libnftnl 3/3] desc: add set description Pablo Neira Ayuso
2022-03-10 11:31   ` Phil Sutter
2022-03-10 23:24     ` Pablo Neira Ayuso [this message]
2022-03-11 14:03       ` Phil Sutter
2022-03-10 11:35 ` [PATCH libnftnl 0/3] add description infrastructure Phil Sutter
2022-03-10 23:28   ` Pablo Neira Ayuso
2022-04-06 11:06 ` Phil Sutter
2022-04-06 11:57   ` 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=YiqIsbxAQUlIpJSY@salvia \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=phil@nwl.cc \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.