* [PATCH lnf-queue] api: add nfq_nlmsg_get_timestamp helper
@ 2013-08-22 15:07 Florian Westphal
2013-08-26 22:53 ` Pablo Neira Ayuso
0 siblings, 1 reply; 3+ messages in thread
From: Florian Westphal @ 2013-08-22 15:07 UTC (permalink / raw)
To: netfilter-devel; +Cc: Florian Westphal
The NFQA_TIMESTAMP structure is in network byte order, so it seems
appropriate to add a helper to convert it to a timeval struct.
Signed-off-by: Florian Westphal <fw@strlen.de>
---
examples/nf-queue.c | 9 ++++++++-
include/libnetfilter_queue/libnetfilter_queue.h | 2 ++
src/nlmsg.c | 15 +++++++++++++++
3 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/examples/nf-queue.c b/examples/nf-queue.c
index 1f465ad..2722426 100644
--- a/examples/nf-queue.c
+++ b/examples/nf-queue.c
@@ -5,6 +5,7 @@
#include <string.h>
#include <time.h>
#include <arpa/inet.h>
+#include <sys/time.h>
#include <libmnl/libmnl.h>
#include <linux/netfilter.h>
@@ -54,6 +55,7 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data)
uint32_t id = 0, skbinfo;
struct nfgenmsg *nfg;
uint16_t plen;
+ struct timeval tv;
if (nfq_nlmsg_parse(nlh, attr) < 0) {
perror("problems parsing");
@@ -72,7 +74,11 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data)
plen = mnl_attr_get_payload_len(attr[NFQA_PAYLOAD]);
/* void *payload = mnl_attr_get_payload(attr[NFQA_PAYLOAD]); */
- skbinfo = attr[NFQA_SKB_INFO] ? ntohl(mnl_attr_get_u32(attr[NFQA_SKB_INFO])) : 0;
+ if (attr[NFQA_TIMESTAMP])
+ nfq_nlmsg_get_timestamp(attr[NFQA_TIMESTAMP], &tv);
+ else
+ gettimeofday(&tv, NULL);
+ printf("%lu:%06lu ", (long) tv.tv_sec, (long) tv.tv_usec);
if (attr[NFQA_CAP_LEN]) {
uint32_t orig_len = ntohl(mnl_attr_get_u32(attr[NFQA_CAP_LEN]));
@@ -80,6 +86,7 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data)
printf("truncated ");
}
+ skbinfo = attr[NFQA_SKB_INFO] ? ntohl(mnl_attr_get_u32(attr[NFQA_SKB_INFO])) : 0;
if (skbinfo & NFQA_SKB_GSO)
printf("GSO ");
diff --git a/include/libnetfilter_queue/libnetfilter_queue.h b/include/libnetfilter_queue/libnetfilter_queue.h
index b9f16e2..537cabf 100644
--- a/include/libnetfilter_queue/libnetfilter_queue.h
+++ b/include/libnetfilter_queue/libnetfilter_queue.h
@@ -144,6 +144,8 @@ void nfq_nlmsg_verdict_put_pkt(struct nlmsghdr *nlh, const void *pkt, uint32_t p
int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **pkt);
+void nfq_nlmsg_get_timestamp(const struct nlattr *attr, struct timeval *tv);
+
#ifdef __cplusplus
} /* extern "C" */
#endif
diff --git a/src/nlmsg.c b/src/nlmsg.c
index e7a30e0..10f96cf 100644
--- a/src/nlmsg.c
+++ b/src/nlmsg.c
@@ -172,5 +172,20 @@ int nfq_nlmsg_parse(const struct nlmsghdr *nlh, struct nlattr **attr)
EXPORT_SYMBOL(nfq_nlmsg_parse);
/**
+ * nfq_nlmsg_get_timestamp - get the packet timestamp
+ * \param attr pointer to valid NFQA_TIMESTAMP attribute header
+ * \param timeval structure to fill with data
+ *
+ * This function always succeeds.
+ */
+void nfq_nlmsg_get_timestamp(const struct nlattr *attr, struct timeval *tv)
+{
+ struct nfqnl_msg_packet_timestamp *ts = mnl_attr_get_payload(attr);
+ tv->tv_sec = __be64_to_cpu(ts->sec);
+ tv->tv_usec = __be64_to_cpu(ts->usec);
+}
+EXPORT_SYMBOL(nfq_nlmsg_get_timestamp);
+
+/**
* @}
*/
--
1.7.8.6
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH lnf-queue] api: add nfq_nlmsg_get_timestamp helper
2013-08-22 15:07 [PATCH lnf-queue] api: add nfq_nlmsg_get_timestamp helper Florian Westphal
@ 2013-08-26 22:53 ` Pablo Neira Ayuso
2013-08-28 8:46 ` Florian Westphal
0 siblings, 1 reply; 3+ messages in thread
From: Pablo Neira Ayuso @ 2013-08-26 22:53 UTC (permalink / raw)
To: Florian Westphal; +Cc: netfilter-devel
Hi Florian,
On Thu, Aug 22, 2013 at 05:07:17PM +0200, Florian Westphal wrote:
> The NFQA_TIMESTAMP structure is in network byte order, so it seems
> appropriate to add a helper to convert it to a timeval struct.
>
> Signed-off-by: Florian Westphal <fw@strlen.de>
> ---
> examples/nf-queue.c | 9 ++++++++-
> include/libnetfilter_queue/libnetfilter_queue.h | 2 ++
> src/nlmsg.c | 15 +++++++++++++++
> 3 files changed, 25 insertions(+), 1 deletions(-)
>
> diff --git a/examples/nf-queue.c b/examples/nf-queue.c
> index 1f465ad..2722426 100644
> --- a/examples/nf-queue.c
> +++ b/examples/nf-queue.c
> @@ -5,6 +5,7 @@
> #include <string.h>
> #include <time.h>
> #include <arpa/inet.h>
> +#include <sys/time.h>
>
> #include <libmnl/libmnl.h>
> #include <linux/netfilter.h>
> @@ -54,6 +55,7 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data)
> uint32_t id = 0, skbinfo;
> struct nfgenmsg *nfg;
> uint16_t plen;
> + struct timeval tv;
>
> if (nfq_nlmsg_parse(nlh, attr) < 0) {
> perror("problems parsing");
> @@ -72,7 +74,11 @@ static int queue_cb(const struct nlmsghdr *nlh, void *data)
> plen = mnl_attr_get_payload_len(attr[NFQA_PAYLOAD]);
> /* void *payload = mnl_attr_get_payload(attr[NFQA_PAYLOAD]); */
>
> - skbinfo = attr[NFQA_SKB_INFO] ? ntohl(mnl_attr_get_u32(attr[NFQA_SKB_INFO])) : 0;
> + if (attr[NFQA_TIMESTAMP])
> + nfq_nlmsg_get_timestamp(attr[NFQA_TIMESTAMP], &tv);
I think we can update nfq_get_timestamp to use libmnl without breaking
backward compatibility. Same thing with all other getter functions
that we have.
Regards.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH lnf-queue] api: add nfq_nlmsg_get_timestamp helper
2013-08-26 22:53 ` Pablo Neira Ayuso
@ 2013-08-28 8:46 ` Florian Westphal
0 siblings, 0 replies; 3+ messages in thread
From: Florian Westphal @ 2013-08-28 8:46 UTC (permalink / raw)
To: Pablo Neira Ayuso; +Cc: Florian Westphal, netfilter-devel
Pablo Neira Ayuso <pablo@netfilter.org> wrote:
> Hi Florian,
>
> On Thu, Aug 22, 2013 at 05:07:17PM +0200, Florian Westphal wrote:
> > The NFQA_TIMESTAMP structure is in network byte order, so it seems
> > appropriate to add a helper to convert it to a timeval struct.
[..]
> I think we can update nfq_get_timestamp to use libmnl without breaking
> backward compatibility. Same thing with all other getter functions
> that we have.
How did you plan to do this without breaking api/abi?
To call the existing libnfnetlink based function given an libmnl attr[] array
you need to:
struct nfq_data d;
d.data = (void **) &attr[1];
nfq_get_timestamp(&d, &tv);
Which is just "ewww".
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2013-08-28 8:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-08-22 15:07 [PATCH lnf-queue] api: add nfq_nlmsg_get_timestamp helper Florian Westphal
2013-08-26 22:53 ` Pablo Neira Ayuso
2013-08-28 8:46 ` Florian Westphal
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).