Skip to contentSkip to conversation

expr: immediate: check for chain attribute to release chain name

PATCH New Pablo Neira Ayuso 1 participant 3 messages Feb 26, 2024 netfilter

lore
Share & tools
lore

Pablo Neira Ayuso

author maintainer
#0 lore raw

PATCH 1/3 expr: immediate: check for chain attribute to release chain name

Check for chain name attribute to release chain name, for consistency with other existing attributes.

---
 include/data_reg.h   |  2 --
 src/expr/data_reg.c  | 12 ------------
 src/expr/immediate.c |  4 ++--
 3 files changed, 2 insertions(+), 16 deletions(-)
include/data_reg.h +0 -2
index 5ee7080daef0..946354dc9881 100644
@@ -35,8 +35,6 @@ int nftnl_data_reg_snprintf(char *buf, size_t size,
 struct nlattr;
 
 int nftnl_parse_data(union nftnl_data_reg *data, struct nlattr *attr, int *type);
-void nftnl_free_verdict(const union nftnl_data_reg *data);
-
 int nftnl_data_cpy(union nftnl_data_reg *dreg, const void *src, uint32_t len);
 
 #endif
src/expr/data_reg.c +0 -12
index 690b23dbad6c..d2ccf2e8dc68 100644
@@ -206,18 +206,6 @@ int nftnl_parse_data(union nftnl_data_reg *data, struct nlattr *attr, int *type)
 	return ret;
 }
 
-void nftnl_free_verdict(const union nftnl_data_reg *data)
-{
-	switch(data->verdict) {
-	case NFT_JUMP:
-	case NFT_GOTO:
-		xfree(data->chain);
-		break;
-	default:
-		break;
-	}
-}
-
 int nftnl_data_cpy(union nftnl_data_reg *dreg, const void *src, uint32_t len)
 {
 	int ret = 0;
src/expr/immediate.c +2 -2
index f56aa8fd6999..acc01a10154e 100644
@@ -214,8 +214,8 @@ static void nftnl_expr_immediate_free(const struct nftnl_expr *e)
 {
 	struct nftnl_expr_immediate *imm = nftnl_expr_data(e);
 
-	if (e->flags & (1 << NFTNL_EXPR_IMM_VERDICT))
-		nftnl_free_verdict(&imm->data);
+	if (e->flags & (1 << NFTNL_EXPR_IMM_CHAIN))
+		xfree(imm->data.chain);
 }
 
 struct expr_ops expr_ops_immediate = {
Signature · 1 line
2.30.2
author maintainer
#1 lore raw

PATCH 2/3 udata: incorrect userdata buffer size validation

Use the current remaining space in the buffer to ensure more userdata attributes still fit in, buf->size is the total size of the userdata buffer.

---
 src/udata.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
src/udata.c +7 -1
index 0cc3520ccede..e9bfc35e624c 100644
@@ -42,6 +42,11 @@ uint32_t nftnl_udata_buf_len(const struct nftnl_udata_buf *buf)
 	return (uint32_t)(buf->end - buf->data);
 }
 
+static uint32_t nftnl_udata_buf_space(const struct nftnl_udata_buf *buf)
+{
+	return buf->size - nftnl_udata_buf_len(buf);
+}
+
 EXPORT_SYMBOL(nftnl_udata_buf_data);
 void *nftnl_udata_buf_data(const struct nftnl_udata_buf *buf)
 {
@@ -74,7 +79,8 @@ bool nftnl_udata_put(struct nftnl_udata_buf *buf, uint8_t type, uint32_t len,
 {
 	struct nftnl_udata *attr;
 
-	if (len > UINT8_MAX || buf->size < len + sizeof(struct nftnl_udata))
+	if (len > UINT8_MAX ||
+	    nftnl_udata_buf_space(buf) < len + sizeof(struct nftnl_udata))
 		return false;
 
 	attr = (struct nftnl_udata *)buf->end;
Signature · 1 line
2.30.2
author maintainer
#2 lore raw

PATCH 3/3 utils: remove unused code

In reply to Pablo Neira Ayuso

Remove several internal code that have no use these days:

- nftnl_str2family
- nftnl_strtoi
- nftnl_get_value
- enum nftnl_type

---
 include/utils.h |  19 -----
 src/utils.c     | 194 ------------------------------------------------
 2 files changed, 213 deletions(-)
include/utils.h +0 -19
index 8af5a8e973fa..ff76f77ebb35 100644
@@ -68,27 +68,8 @@ void __nftnl_assert_attr_exists(uint16_t attr, uint16_t attr_max,
 #define array_size(arr)		(sizeof(arr) / sizeof((arr)[0]) + __must_be_array(arr))
 
 const char *nftnl_family2str(uint32_t family);
-int nftnl_str2family(const char *family);
-
-enum nftnl_type {
-	NFTNL_TYPE_U8,
-	NFTNL_TYPE_U16,
-	NFTNL_TYPE_U32,
-	NFTNL_TYPE_U64,
-	NFTNL_TYPE_S8,
-	NFTNL_TYPE_S16,
-	NFTNL_TYPE_S32,
-	NFTNL_TYPE_S64,
-};
-
-int nftnl_strtoi(const char *string, int base, void *number, enum nftnl_type type);
-int nftnl_get_value(enum nftnl_type type, void *val, void *out);
 
 const char *nftnl_verdict2str(uint32_t verdict);
-int nftnl_str2verdict(const char *verdict, int *verdict_num);
-
-const char *nftnl_cmd2tag(enum nftnl_cmd_type cmd);
-uint32_t nftnl_str2cmd(const char *cmd);
 
 enum nftnl_cmd_type nftnl_flag2cmd(uint32_t flags);
 
src/utils.c +0 -194

212 lines not on this page · raw message

Signature · 1 line
2.30.2