Skip to contentSkip to conversation

netfilter: nft_log: group is u16, snaplen u32

PATCH Applied Florian Westphal 2 participants 6 messages Sep 13, 2013 – Sep 14, 2013

Subsystems (2)
lore
Share & tools
lore

Florian Westphal

author maintainer
#0 lore raw

PATCH 1/3 netfilter: nft_log: group is u16, snaplen u32

0edecbe17ae (netfilter: nft_log: group and qthreshold are 2^16) made the correct changes except in the nla_policy where it changed snaplen instead of group attibute.

---
 net/netfilter/nft_log.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nft_log.c +2 -2
index 65cc62f..70b1be2 100644
@@ -37,9 +37,9 @@ static void nft_log_eval(const struct nft_expr *expr,
 }
 
 static const struct nla_policy nft_log_policy[NFTA_LOG_MAX + 1] = {
-	[NFTA_LOG_GROUP]	= { .type = NLA_U32 },
+	[NFTA_LOG_GROUP]	= { .type = NLA_U16 },
 	[NFTA_LOG_PREFIX]	= { .type = NLA_STRING },
-	[NFTA_LOG_SNAPLEN]	= { .type = NLA_U16 },
+	[NFTA_LOG_SNAPLEN]	= { .type = NLA_U32 },
 	[NFTA_LOG_QTHRESHOLD]	= { .type = NLA_U16 },
 };
 
Signature · 1 line
1.7.8.6
author maintainer
#1 lore raw

PATCH 2/3 expr: log: use real length when fetching attributes

NFTA_LOG_SNAPLEN is u32 and NFTA_LOG_QTHRESHOLD is u16. Without this, netlink messages from kernel fail mnl_validate step when QTHRESH or SNAPLEN was set.

Also, nft_rule_expr_log_get must update data_length, else 'nft list' doesn't show log arguments (prefix, group ..) because the netlink message decoding uses nft_rule_expr_get_u16/32 etc. which validate the length, too.

---
 src/expr/log.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)
src/expr/log.c +6 -2
index bbbd5b9..90fb32e 100644
@@ -64,12 +64,16 @@ nft_rule_expr_log_get(const struct nft_rule_expr *e, uint16_t type,
 
 	switch(type) {
 	case NFT_EXPR_LOG_PREFIX:
+		*data_len = strlen(log->prefix)+1;
 		return log->prefix;
 	case NFT_EXPR_LOG_GROUP:
+		*data_len = sizeof(log->group);
 		return &log->group;
 	case NFT_EXPR_LOG_SNAPLEN:
+		*data_len = sizeof(log->snaplen);
 		return &log->snaplen;
 	case NFT_EXPR_LOG_QTHRESHOLD:
+		*data_len = sizeof(log->qthreshold);
 		return &log->qthreshold;
 	}
 	return NULL;
@@ -91,13 +95,13 @@ static int nft_rule_expr_log_cb(const struct nlattr *attr, void *data)
 		}
 		break;
 	case NFTA_LOG_GROUP:
-	case NFTA_LOG_SNAPLEN:
+	case NFTA_LOG_QTHRESHOLD:
 		if (mnl_attr_validate(attr, MNL_TYPE_U16) < 0) {
 			perror("mnl_attr_validate");
 			return MNL_CB_ERROR;
 		}
 		break;
-	case NFTA_LOG_QTHRESHOLD:
+	case NFTA_LOG_SNAPLEN:
 		if (mnl_attr_validate(attr, MNL_TYPE_U32) < 0) {
 			perror("mnl_attr_validate");
 			return MNL_CB_ERROR;
Signature · 1 line
1.7.8.6
#2 lore raw

Re: [PATCH libnftables 2/3] expr: log: use real length when fetching attributes

Quoted 7 lines · Florian Westphal

NFTA_LOG_SNAPLEN is u32 and NFTA_LOG_QTHRESHOLD is u16. Without this, netlink messages from kernel fail mnl_validate step when QTHRESH or SNAPLEN was set.

Also, nft_rule_expr_log_get must update data_length, else 'nft list' doesn't show log arguments (prefix, group ..) because the netlink message decoding uses nft_rule_expr_get_u16/32 etc. which validate the length, too.

Also applied, thanks.

author maintainer
#3 lore raw

PATCH 3/3 log: s/threshold/queue-threshold/

In reply to Florian Westphal

on input we expect "queue-threshold" token, so use the same name when printing the output.

---
 src/statement.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
src/statement.c +1 -1
index 1a3ea3c..69db48f 100644
@@ -122,7 +122,7 @@ static void log_stmt_print(const struct stmt *stmt)
 	if (stmt->log.snaplen)
 		printf(" snaplen %u", stmt->log.snaplen);
 	if (stmt->log.qthreshold)
-		printf(" threshold %u", stmt->log.qthreshold);
+		printf(" queue-threshold %u", stmt->log.qthreshold);
 }
 
 static void log_stmt_destroy(struct stmt *stmt)
Signature · 1 line
1.7.8.6
maintainer Applied
#4 lore raw

Re: [PATCH nftables 3/3] log: s/threshold/queue-threshold/

Quoted 2 lines · Florian Westphal

on input we expect "queue-threshold" token, so use the same name when printing the output.

Applied, thanks.

maintainer Applied
#5 lore raw
In reply to Florian Westphal
Quoted 3 lines · Florian Westphal

0edecbe17ae (netfilter: nft_log: group and qthreshold are 2^16) made the correct changes except in the nla_policy where it changed snaplen instead of group attibute.

Applied, thanks Florian.