Message ID | 1329314115-6899-2-git-send-email-richard@nod.at |
---|---|
State | Not Applicable, archived |
Delegated to: | David Miller |
Headers | show |
Le mercredi 15 février 2012 à 14:55 +0100, Richard Weinberger a écrit : > Using XT_LOG_ADD_TIMESTAMP it is possible to have a timestamp > directly in the log message. > > Signed-off-by: Richard Weinberger <richard@nod.at> > --- > include/linux/netfilter/xt_LOG.h | 1 + > net/netfilter/xt_LOG.c | 9 +++++++++ > 2 files changed, 10 insertions(+), 0 deletions(-) > > diff --git a/include/linux/netfilter/xt_LOG.h b/include/linux/netfilter/xt_LOG.h > index e4b1177..d84710c 100644 > --- a/include/linux/netfilter/xt_LOG.h > +++ b/include/linux/netfilter/xt_LOG.h > @@ -8,6 +8,7 @@ > #define XT_LOG_UID 0x08 /* Log UID owning local socket */ > #define XT_LOG_NFLOG 0x10 /* Unsupported, don't reuse */ > #define XT_LOG_MACDECODE 0x20 /* Decode MAC header */ > +#define XT_LOG_ADD_TIMESTAMP 0x40 /* Add a timestamp */ > #define XT_LOG_MASK 0x6f > > struct xt_log_info { > diff --git a/net/netfilter/xt_LOG.c b/net/netfilter/xt_LOG.c > index 211d341..2af2621 100644 > --- a/net/netfilter/xt_LOG.c > +++ b/net/netfilter/xt_LOG.c > @@ -490,6 +490,15 @@ log_packet_common(struct sbuff *m, > if (loginfo->type == NF_LOG_TYPE_LOG) > sb_add(m, "<%d>", loginfo->u.log.level); > > + if (loginfo->u.log.logflags & XT_LOG_ADD_TIMESTAMP) { > + struct timespec tv; > + unsigned int msec; > + > + getnstimeofday(&tv); > + msec = tv.tv_nsec / NSEC_PER_MSEC; > + sb_add(m, "TIMESTAMP=%li.%03li ", tv.tv_sec, msec); Since you want to use this temp variable "unsigned int msec" (I have no idea why...), you must change printf format accordingly : %03u instead of %03li > + } > + > sb_add(m, "%sIN=%s OUT=%s ", prefix, in ? in->name : "", > out ? out->name : ""); > #ifdef CONFIG_BRIDGE_NETFILTER -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On 15.02.2012 15:01, Eric Dumazet wrote: > Le mercredi 15 février 2012 à 14:55 +0100, Richard Weinberger a écrit : >> Using XT_LOG_ADD_TIMESTAMP it is possible to have a timestamp >> directly in the log message. >> >> Signed-off-by: Richard Weinberger<richard@nod.at> >> --- >> include/linux/netfilter/xt_LOG.h | 1 + >> net/netfilter/xt_LOG.c | 9 +++++++++ >> 2 files changed, 10 insertions(+), 0 deletions(-) >> >> diff --git a/include/linux/netfilter/xt_LOG.h b/include/linux/netfilter/xt_LOG.h >> index e4b1177..d84710c 100644 >> --- a/include/linux/netfilter/xt_LOG.h >> +++ b/include/linux/netfilter/xt_LOG.h >> @@ -8,6 +8,7 @@ >> #define XT_LOG_UID 0x08 /* Log UID owning local socket */ >> #define XT_LOG_NFLOG 0x10 /* Unsupported, don't reuse */ >> #define XT_LOG_MACDECODE 0x20 /* Decode MAC header */ >> +#define XT_LOG_ADD_TIMESTAMP 0x40 /* Add a timestamp */ >> #define XT_LOG_MASK 0x6f >> >> struct xt_log_info { >> diff --git a/net/netfilter/xt_LOG.c b/net/netfilter/xt_LOG.c >> index 211d341..2af2621 100644 >> --- a/net/netfilter/xt_LOG.c >> +++ b/net/netfilter/xt_LOG.c >> @@ -490,6 +490,15 @@ log_packet_common(struct sbuff *m, >> if (loginfo->type == NF_LOG_TYPE_LOG) >> sb_add(m, "<%d>", loginfo->u.log.level); >> >> + if (loginfo->u.log.logflags& XT_LOG_ADD_TIMESTAMP) { >> + struct timespec tv; >> + unsigned int msec; >> + >> + getnstimeofday(&tv); >> + msec = tv.tv_nsec / NSEC_PER_MSEC; >> + sb_add(m, "TIMESTAMP=%li.%03li ", tv.tv_sec, msec); > > Since you want to use this temp variable "unsigned int msec" (I have no > idea why...), you must change printf format accordingly : %03u instead > of %03li *grml*. I'll remove the temp variable and use %03u. The temp variable is a left over from another (not submitted) timestamp implementation. Thanks for spotting this! //richard -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wednesday 2012-02-15 15:07, Richard Weinberger wrote: >>> + struct timespec tv; >>> + unsigned int msec; >>> + >>> + getnstimeofday(&tv); >>> + msec = tv.tv_nsec / NSEC_PER_MSEC; >>> + sb_add(m, "TIMESTAMP=%li.%03li ", tv.tv_sec, msec); >> >> Since you want to use this temp variable "unsigned int msec" (I have no >> idea why...), you must change printf format accordingly : %03u instead >> of %03li > > *grml*. > I'll remove the temp variable and use %03u. Why not just print the nsecs directly (with %09 of course)? -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Am 15.02.2012 18:16, schrieb Jan Engelhardt: > > On Wednesday 2012-02-15 15:07, Richard Weinberger wrote: >>>> + struct timespec tv; >>>> + unsigned int msec; >>>> + >>>> + getnstimeofday(&tv); >>>> + msec = tv.tv_nsec / NSEC_PER_MSEC; >>>> + sb_add(m, "TIMESTAMP=%li.%03li ", tv.tv_sec, msec); >>> >>> Since you want to use this temp variable "unsigned int msec" (I have no >>> idea why...), you must change printf format accordingly : %03u instead >>> of %03li >> >> *grml*. >> I'll remove the temp variable and use %03u. > > Why not just print the nsecs directly (with %09 of course)? I don't think that a nanosecond resolution is useful. Thanks, //richard -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/netfilter/xt_LOG.h b/include/linux/netfilter/xt_LOG.h index e4b1177..d84710c 100644 --- a/include/linux/netfilter/xt_LOG.h +++ b/include/linux/netfilter/xt_LOG.h @@ -8,6 +8,7 @@ #define XT_LOG_UID 0x08 /* Log UID owning local socket */ #define XT_LOG_NFLOG 0x10 /* Unsupported, don't reuse */ #define XT_LOG_MACDECODE 0x20 /* Decode MAC header */ +#define XT_LOG_ADD_TIMESTAMP 0x40 /* Add a timestamp */ #define XT_LOG_MASK 0x6f struct xt_log_info { diff --git a/net/netfilter/xt_LOG.c b/net/netfilter/xt_LOG.c index 211d341..2af2621 100644 --- a/net/netfilter/xt_LOG.c +++ b/net/netfilter/xt_LOG.c @@ -490,6 +490,15 @@ log_packet_common(struct sbuff *m, if (loginfo->type == NF_LOG_TYPE_LOG) sb_add(m, "<%d>", loginfo->u.log.level); + if (loginfo->u.log.logflags & XT_LOG_ADD_TIMESTAMP) { + struct timespec tv; + unsigned int msec; + + getnstimeofday(&tv); + msec = tv.tv_nsec / NSEC_PER_MSEC; + sb_add(m, "TIMESTAMP=%li.%03li ", tv.tv_sec, msec); + } + sb_add(m, "%sIN=%s OUT=%s ", prefix, in ? in->name : "", out ? out->name : ""); #ifdef CONFIG_BRIDGE_NETFILTER
Using XT_LOG_ADD_TIMESTAMP it is possible to have a timestamp directly in the log message. Signed-off-by: Richard Weinberger <richard@nod.at> --- include/linux/netfilter/xt_LOG.h | 1 + net/netfilter/xt_LOG.c | 9 +++++++++ 2 files changed, 10 insertions(+), 0 deletions(-)