Skip to contentSkip to conversation

netfilter: xt_LOG: avoid using old-style "<.>" printk prefix

PATCH In review Romain Francoise 3 participants 4 messages Sep 10, 2012 – Sep 12, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: xt_LOG: avoid using old-style "<.>" printk prefix

Since commit 04d2c8c83d ("printk: convert the format for KERN_<LEVEL> to a 2 byte pattern"), printk no longer uses a "<.>" string prefix internally, so the call in xt_LOG ends up emitting the prefix as part of the log itself (and possibly not at the configured level).

To avoid having to worry about printk's internal formatting, switch to printk_emit(), specifying the desired level directly.

---
 include/net/netfilter/xt_log.h |    7 +++++--
 net/netfilter/xt_LOG.c         |    6 +++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
include/net/netfilter/xt_log.h +5 -2
index 9d9756c..343f5bb 100644
@@ -39,11 +39,14 @@ static struct sbuff *sb_open(void)
 	return m;
 }
 
-static void sb_close(struct sbuff *m)
+static void sb_emit(struct sbuff *m, int level)
 {
 	m->buf[m->count] = 0;
-	printk("%s\n", m->buf);
+	printk_emit(0, level, NULL, 0, "%s\n", m->buf);
+}
 
+static void sb_close(struct sbuff *m)
+{
 	if (likely(m != &emergency))
 		kfree(m);
 	else {
net/netfilter/xt_LOG.c +5 -1
index ff5f75f..d33ff9f 100644
@@ -436,7 +436,7 @@ log_packet_common(struct sbuff *m,
 		  const struct nf_loginfo *loginfo,
 		  const char *prefix)
 {
-	sb_add(m, "<%d>%sIN=%s OUT=%s ", loginfo->u.log.level,
+	sb_add(m, "%sIN=%s OUT=%s ",
 	       prefix,
 	       in ? in->name : "",
 	       out ? out->name : "");
@@ -477,6 +477,8 @@ ipt_log_packet(u_int8_t pf,
 
 	dump_ipv4_packet(m, loginfo, skb, 0);
 
+	sb_emit(m, loginfo->u.log.level);
+
 	sb_close(m);
 }
 
@@ -807,6 +809,8 @@ ip6t_log_packet(u_int8_t pf,
 
 	dump_ipv6_packet(m, loginfo, skb, skb_network_offset(skb), 1);
 
+	sb_emit(m, loginfo->u.log.level);
+
 	sb_close(m);
 }
 #endif
Signature · 1 line
1.7.10.4
#1 lore raw

Hi,

CC'ing Joe Perches and Eric Dumazet, they are discussing a similar patch.

Would you be OK with the prink_emit variant to solve this? (Once several issues are resolved).

Quoted 7 lines · Romain Francoise

Since commit 04d2c8c83d ("printk: convert the format for KERN_<LEVEL> to a 2 byte pattern"), printk no longer uses a "<.>" string prefix internally, so the call in xt_LOG ends up emitting the prefix as part of the log itself (and possibly not at the configured level).

To avoid having to worry about printk's internal formatting, switch to printk_emit(), specifying the desired level directly.

ebt_log chunk is missing.

Quoted 11 lines
---
 include/net/netfilter/xt_log.h |    7 +++++--
 net/netfilter/xt_LOG.c         |    6 +++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
include/net/netfilter/xt_log.h +0 -0
index 9d9756c..343f5bb 100644

include/net/netfilter/xt_log.h static struct sbuff *sb_open(void) · line 45

Quoted 9 lines
include/net/netfilter/xt_log.h +2 -2
@@ -39,11 +39,14 @@ static struct sbuff *sb_open(void)
 	return m;
 }
 
-static void sb_close(struct sbuff *m)
+static void sb_emit(struct sbuff *m, int level)
 {
 	m->buf[m->count] = 0;
-	printk("%s\n", m->buf);
+	printk_emit(0, level, NULL, 0, "%s\n", m->buf);

I think it should be printk_emit(-1, ... Note facility is -1.

Thus, we skip the syslog prefix stripping (we can skip it and save some cycles).

Quoted 46 lines
include/net/netfilter/xt_log.h +3 -0
+}
 
+static void sb_close(struct sbuff *m)
+{
 	if (likely(m != &emergency))
 		kfree(m);
 	else {
net/netfilter/xt_LOG.c +5 -1
index ff5f75f..d33ff9f 100644
@@ -436,7 +436,7 @@ log_packet_common(struct sbuff *m,
 		  const struct nf_loginfo *loginfo,
 		  const char *prefix)
 {
-	sb_add(m, "<%d>%sIN=%s OUT=%s ", loginfo->u.log.level,
+	sb_add(m, "%sIN=%s OUT=%s ",
 	       prefix,
 	       in ? in->name : "",
 	       out ? out->name : "");
@@ -477,6 +477,8 @@ ipt_log_packet(u_int8_t pf,
 
 	dump_ipv4_packet(m, loginfo, skb, 0);
 
+	sb_emit(m, loginfo->u.log.level);
+
 	sb_close(m);
 }
 
@@ -807,6 +809,8 @@ ip6t_log_packet(u_int8_t pf,
 
 	dump_ipv6_packet(m, loginfo, skb, skb_network_offset(skb), 1);
 
+	sb_emit(m, loginfo->u.log.level);
+
 	sb_close(m);
 }
 #endif
Signature · 7 lines
1.7.10.4


--
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw

Hi Pablo,

Quoted 1 line · Pablo Neira Ayuso

ebt_log chunk is missing.

Sorry, didn't notice that it has the same bug. Do you want that in the same patch, or separate?

Quoted 8 lines

include/net/netfilter/xt_log.h static struct sbuff *sb_open(void) · line 45

Quoted 3 lines
include/net/netfilter/xt_log.h +1 -1
 	m->buf[m->count] = 0;
-	printk("%s\n", m->buf);
+	printk_emit(0, level, NULL, 0, "%s\n", m->buf);

I think it should be printk_emit(-1, ... Note facility is -1.

Thus, we skip the syslog prefix stripping (we can skip it and save some cycles).

I don't think that's possible, the facility is copied down to user-space consumers and it has to be zero for the message to be identified as originating from the kernel (0 is LOG_KERN).

As it boils down to a single test for KERN_SOH_ASCII I don't think it matters very much.

Thanks!

#3 lore raw

Replying from different email, @netfilter.org is currently down due to some power supply problems.

Quoted 15 lines · Romain Francoise

Hi Pablo,

Quoted 1 line · Pablo Neira Ayuso

ebt_log chunk is missing.

Sorry, didn't notice that it has the same bug. Do you want that in the same patch, or separate?

Quoted 5 lines

include/net/netfilter/xt_log.h static struct sbuff *sb_open(void) · line 45

Quoted 3 lines
include/net/netfilter/xt_log.h +1 -1
 	m->buf[m->count] = 0;
-	printk("%s\n", m->buf);
+	printk_emit(0, level, NULL, 0, "%s\n", m->buf);

I think it should be printk_emit(-1, ... Note facility is -1.

Quoted 6 lines
Quoted 2 lines

Thus, we skip the syslog prefix stripping (we can skip it and save some cycles).

I don't think that's possible, the facility is copied down to user-space consumers and it has to be zero for the message to be identified as originating from the kernel (0 is LOG_KERN).

I see.

Quoted 2 lines

As it boils down to a single test for KERN_SOH_ASCII I don't think it matters very much.

I'm going to take Joe's patch, I prefer using the printk interface.

Thanks anyway.