All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: netfilter-devel@vger.kernel.org
Subject: [PATCH libnftnl] object: define nftnl_obj_unset()
Date: Tue,  2 Jan 2024 14:25:40 +0100	[thread overview]
Message-ID: <20240102132540.31391-1-pablo@netfilter.org> (raw)

For consistency with existing objects, implement this interface.
This is already defined in libnftnl.map so the intention was to
provide it.

Fixes: 5573d0146c1a ("src: support for stateful objects")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
 src/object.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/src/object.c b/src/object.c
index 9e768610cddb..0814be744448 100644
--- a/src/object.c
+++ b/src/object.c
@@ -69,6 +69,34 @@ bool nftnl_obj_is_set(const struct nftnl_obj *obj, uint16_t attr)
 	return obj->flags & (1 << attr);
 }
 
+EXPORT_SYMBOL(nftnl_obj_unset);
+void nftnl_obj_unset(struct nftnl_obj *obj, uint16_t attr)
+{
+	if (!(obj->flags & (1 << attr)))
+		return;
+
+	switch (attr) {
+	case NFTNL_OBJ_TABLE:
+		xfree(obj->table);
+		break;
+	case NFTNL_OBJ_NAME:
+		xfree(obj->name);
+		break;
+	case NFTNL_OBJ_USERDATA:
+		xfree(obj->user.data);
+		break;
+	case NFTNL_OBJ_TYPE:
+	case NFTNL_OBJ_FAMILY:
+	case NFTNL_OBJ_USE:
+	case NFTNL_OBJ_HANDLE:
+		break;
+	default:
+		break;
+	}
+
+	obj->flags &= ~(1 << attr);
+}
+
 static uint32_t nftnl_obj_validate[NFTNL_OBJ_MAX + 1] = {
 	[NFTNL_OBJ_FAMILY]	= sizeof(uint32_t),
 	[NFTNL_OBJ_USE]		= sizeof(uint32_t),
-- 
2.30.2


             reply	other threads:[~2024-01-02 13:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-02 13:25 Pablo Neira Ayuso [this message]
2024-01-02 17:50 ` [PATCH libnftnl] object: define nftnl_obj_unset() Nicholas Vinson
2024-01-03 10:32   ` Pablo Neira Ayuso
2024-01-03 14:53     ` Nicholas Vinson

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=20240102132540.31391-1-pablo@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=netfilter-devel@vger.kernel.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 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.