Rework nfnetlink_queue conntrack support
Subsystems (2)
Pablo Neira Ayuso
maintainercover Rework nfnetlink_queue conntrack support
Hi Ken-ichirou,
Would you have a look at this patchset?
I think it should prepare the ground for what you need.
They are totally untested, so please carefully review them.
Pablo Neira Ayuso (3):
netfilter: ctnetlink: remove ctnetlink_nfqueue_build_size()
netfilter: nfnetlink_queue: get rid of nfnetlink_queue_ct.c
netfilter: rename nfnetlink_queue_core.c to nfnetlink_queue.c
include/linux/netfilter.h | 12 +- include/net/netfilter/nfnetlink_queue.h | 51 -- net/netfilter/Makefile | 1 - net/netfilter/nf_conntrack_netlink.c | 87 +- net/netfilter/nfnetlink_queue.c | 1443 +++++++++++++++++++++++++++++++ net/netfilter/nfnetlink_queue_core.c | 1415 ------------------------------ net/netfilter/nfnetlink_queue_ct.c | 113 --- 7 files changed, 1506 insertions(+), 1616 deletions(-) delete mode 100644 include/net/netfilter/nfnetlink_queue.h create mode 100644 net/netfilter/nfnetlink_queue.c delete mode 100644 net/netfilter/nfnetlink_queue_core.c delete mode 100644 net/netfilter/nfnetlink_queue_ct.c
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerRFC PATCH 1/3 netfilter: ctnetlink: remove ctnetlink_nfqueue_build_size()
Factor out code from netlink_nlmsg_size() to consolidate ctnetlink message size calculation. Don't inline these functions so the compiler decides for us.
--- net/netfilter/nf_conntrack_netlink.c | 42 ++++++++-------------------------- 1 file changed, 9 insertions(+), 33 deletions(-)
net/netfilter/nf_conntrack_netlink.c +9 -33
@@ -596,11 +596,9 @@ ctnetlink_timestamp_size(const struct nf_conn *ct)#endif } -static inline size_t -ctnetlink_nlmsg_size (const struct nf_conn *ct) +static size_t ctnetlink_nlmsg_payload_size (const struct nf_conn *ct) { -return NLMSG_ALIGN (sizeof (struct nfgenmsg )) - +3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ +return 3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ +3 *nla_total_size (0 )/* CTA_TUPLE_IP */ +3 *nla_total_size (0 )/* CTA_TUPLE_PROTO */ +3 *nla_total_size (sizeof (u_int8_t))/* CTA_PROTO_NUM */
@@ -628,6 +626,12 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct) ; } +static size_t ctnetlink_nlmsg_size (const struct nf_conn *ct) +{ +return NLMSG_ALIGN (sizeof (struct nfgenmsg )) + +ctnetlink_nlmsg_payload_size (ct); +} +#ifdef CONFIG_NF_CONNTRACK_EVENTS static int ctnetlink_conntrack_event (unsigned int events,struct nf_ct_event *item)
@@ -2134,34 +2138,6 @@ ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct, struct nf_conntrack_tuple *mask);#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT -static size_t -ctnetlink_nfqueue_build_size (const struct nf_conn *ct) -{ -return 3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ - +3 *nla_total_size (0 )/* CTA_TUPLE_IP */ - +3 *nla_total_size (0 )/* CTA_TUPLE_PROTO */ - +3 *nla_total_size (sizeof (u_int8_t))/* CTA_PROTO_NUM */ - +nla_total_size (sizeof (u_int32_t))/* CTA_ID */ - +nla_total_size (sizeof (u_int32_t))/* CTA_STATUS */ - +nla_total_size (sizeof (u_int32_t))/* CTA_TIMEOUT */ - +nla_total_size (0 )/* CTA_PROTOINFO */ - +nla_total_size (0 )/* CTA_HELP */ - +nla_total_size (NF_CT_HELPER_NAME_LEN )/* CTA_HELP_NAME */ - + ctnetlink_secctx_size(ct) -#ifdef CONFIG_NF_NAT_NEEDED - +2 *nla_total_size (0 )/* CTA_NAT_SEQ_ADJ_ORIG|REPL */ - + 6 * nla_total_size(sizeof(u_int32_t)) /* CTA_NAT_SEQ_OFFSET */ -#endif -#ifdef CONFIG_NF_CONNTRACK_MARK - + nla_total_size(sizeof(u_int32_t)) /* CTA_MARK */ -#endif -#ifdef CONFIG_NF_CONNTRACK_ZONES - + nla_total_size(sizeof(u_int16_t)) /* CTA_ZONE|CTA_TUPLE_ZONE */ -#endif - +ctnetlink_proto_size (ct) - ; -} -static int ctnetlink_nfqueue_build (struct sk_buff *skb,struct nf_conn *ct) {
@@ -2351,7 +2327,7 @@ ctnetlink_nfqueue_attach_expect(const struct nlattr *attr, struct nf_conn *ct, }static struct nfq_ct_hook ctnetlink_nfqueue_hook = { - .build_size = ctnetlink_nfqueue_build_size, + .build_size = ctnetlink_nlmsg_payload_size, .build = ctnetlink_nfqueue_build, .parse = ctnetlink_nfqueue_parse, .attach_expect = ctnetlink_nfqueue_attach_expect,
Signature · 1 line
1.7.10.4
Re: [PATCH RFC 1/3] netfilter: ctnetlink: remove ctnetlink_nfqueue_build_size()
On Tue, Sep 08, 2015 at 06:54:49PM +0200, Pablo Neira Ayuso wrote:
[...]
Quoted 32 lines
net/netfilter/nf_conntrack_netlink.c +8
-4@@ -596,11 +596,9 @@ ctnetlink_timestamp_size(const struct nf_conn *ct)#endif } -static inline size_t -ctnetlink_nlmsg_size (const struct nf_conn *ct) +static size_t ctnetlink_nlmsg_payload_size (const struct nf_conn *ct) { -return NLMSG_ALIGN (sizeof (struct nfgenmsg )) - +3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ +return 3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ +3 *nla_total_size (0 )/* CTA_TUPLE_IP */ +3 *nla_total_size (0 )/* CTA_TUPLE_PROTO */ +3 *nla_total_size (sizeof (u_int8_t))/* CTA_PROTO_NUM */ @@ -628,6 +626,12 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct) ; } +static size_t ctnetlink_nlmsg_size (const struct nf_conn *ct) +{ +return NLMSG_ALIGN (sizeof (struct nfgenmsg )) + +ctnetlink_nlmsg_payload_size (ct); +} +#ifdef CONFIG_NF_CONNTRACK_EVENTS static int ctnetlink_conntrack_event (unsigned int events,struct nf_ct_event *item)
net/netfilter/nf_conntrack_netlink.c ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct, · line 2138
Quoted 5 lines
net/netfilter/nf_conntrack_netlink.c +0
-2@@ -2134,34 +2138,6 @@ ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct, struct nf_conntrack_tuple *mask);#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT -static size_t -ctnetlink_nfqueue_build_size (const struct nf_conn *ct)
A little apart from this issue, it seems that original ctnetlink_nlmsg_size() lacks CTA_USE size.
A conntrack information attached to nfqueue does not have CTA_COUNTERS_ and also CTA_USE attrs, but this change allocates a space for it. If we reuse ctnetlink_nlmsg_size() to avoid a code duplication, I think it would be better to comment it.
Thanks,
Pablo Neira Ayuso
maintainerRe: [PATCH RFC 1/3] netfilter: ctnetlink: remove ctnetlink_nfqueue_build_size()
Quoted 43 lines · Ken-ichirou MATSUZAWA
On Tue, Sep 08, 2015 at 06:54:49PM +0200, Pablo Neira Ayuso wrote:
[...]Quoted 32 lines
net/netfilter/nf_conntrack_netlink.c +8
-4@@ -596,11 +596,9 @@ ctnetlink_timestamp_size(const struct nf_conn *ct)#endif } -static inline size_t -ctnetlink_nlmsg_size (const struct nf_conn *ct) +static size_t ctnetlink_nlmsg_payload_size (const struct nf_conn *ct) { -return NLMSG_ALIGN (sizeof (struct nfgenmsg )) - +3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ +return 3 *nla_total_size (0 )/* CTA_TUPLE_ORIG|REPL|MASTER */ +3 *nla_total_size (0 )/* CTA_TUPLE_IP */ +3 *nla_total_size (0 )/* CTA_TUPLE_PROTO */ +3 *nla_total_size (sizeof (u_int8_t))/* CTA_PROTO_NUM */ @@ -628,6 +626,12 @@ ctnetlink_nlmsg_size(const struct nf_conn *ct) ; } +static size_t ctnetlink_nlmsg_size (const struct nf_conn *ct) +{ +return NLMSG_ALIGN (sizeof (struct nfgenmsg )) + +ctnetlink_nlmsg_payload_size (ct); +} +#ifdef CONFIG_NF_CONNTRACK_EVENTS static int ctnetlink_conntrack_event (unsigned int events,struct nf_ct_event *item)net/netfilter/nf_conntrack_netlink.c ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct, · line 2138
Quoted 5 lines
net/netfilter/nf_conntrack_netlink.c +0
-2@@ -2134,34 +2138,6 @@ ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct, struct nf_conntrack_tuple *mask);#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT -static size_t -ctnetlink_nfqueue_build_size (const struct nf_conn *ct)A little apart from this issue, it seems that original
ctnetlink_nlmsg_size()lacksCTA_USEsize.
Quoted 4 lines
A conntrack information attached to nfqueue does not have
CTA_COUNTERS_and alsoCTA_USEattrs, but this change allocates a space for it. If we reusectnetlink_nlmsg_size()to avoid a code duplication, I think it would be better to comment it.
You're right, I have to revisit this. Will send a v2 of this patchset.
Pablo Neira Ayuso
maintainerRFC PATCH 2/3 netfilter: nfnetlink_queue: get rid of nfnetlink_queue_ct.c
In reply to Pablo Neira AyusoThe original intention was to avoid dependencies between nfnetlink_queue and conntrack without ifdef pollution. However, we can achieve this by moving the conntrack dependent code into ctnetlink and keep some glue code to access the nfq_ct indirection from nfqueue.
After this patch, the nfq_ct indirection is always compiled in the netfilter core to avoid polluting nfqueue with ifdefs. Thus, if nf_conntrack is not compiled this results in only 8-bytes of memory waste in x86_64.
This patch also adds ctnetlink_nfqueue_seqadj() to avoid that the nf_conn structure layout if exposed to nf_queue, which creates another dependency with nf_conntrack at compilation time.
--- include/linux/netfilter.h | 12 ++-- include/net/netfilter/nfnetlink_queue.h | 51 -------------- net/netfilter/Makefile | 1 - net/netfilter/nf_conntrack_netlink.c | 51 +++++++++++++- net/netfilter/nfnetlink_queue_core.c | 52 ++++++++++---- net/netfilter/nfnetlink_queue_ct.c | 113 ------------------------------- 6 files changed, 97 insertions(+), 183 deletions(-) delete mode 100644 include/net/netfilter/nfnetlink_queue.h delete mode 100644 net/netfilter/nfnetlink_queue_ct.c
include/linux/netfilter.h +8 -4
@@ -371,14 +371,21 @@ nf_nat_decode_session(struct sk_buff *skb, struct flowi *fl, u_int8_t family)extern void (*ip_ct_attach)(struct sk_buff *,const struct sk_buff *)__rcu ;void nf_ct_attach (struct sk_buff *,const struct sk_buff *);extern void (*nf_ct_destroy)(struct nf_conntrack *)__rcu ; +#else +static inline void nf_ct_attach (struct sk_buff *new,struct sk_buff *skb) {} +#endif struct nf_conn ;enum ip_conntrack_info ;struct nlattr ;struct nfq_ct_hook { +struct nf_conn *(*get_ct)(struct sk_buff *skb, +enum ip_conntrack_info *ctinfo);size_t (*build_size)(const struct nf_conn *ct); -int (*build)(struct sk_buff *skb,struct nf_conn *ct); +int (*build)(struct sk_buff *skb,struct nf_conn *ct, +enum ip_conntrack_info ctinfo, +u_int16_t ct_attr,u_int16_t ct_info_attr);int (*parse)(const struct nlattr *attr,struct nf_conn *ct);int (*attach_expect)(const struct nlattr *attr,struct nf_conn *ct,u32 portid,u32 report);
@@ -386,9 +393,6 @@ struct nfq_ct_hook { enum ip_conntrack_info ctinfo, s32 off); };extern struct nfq_ct_hook __rcu *nfq_ct_hook; -#else -static inline void nf_ct_attach (struct sk_buff *new,struct sk_buff *skb) {} -#endif /** * nf_skb_duplicated - TEE target has sent a packet
include/net/netfilter/nfnetlink_queue.h deleted +0 -51
51 lines not on this page · raw message
net/netfilter/Makefile +0 -1
@@ -11,7 +11,6 @@ obj-$(CONFIG_NETFILTER) = netfilter.o obj-$(CONFIG_NETFILTER_NETLINK) += nfnetlink.o obj-$(CONFIG_NETFILTER_NETLINK_ACCT) += nfnetlink_acct.o nfnetlink_queue-y := nfnetlink_queue_core.o -nfnetlink_queue-$(CONFIG_NETFILTER_NETLINK_QUEUE_CT) += nfnetlink_queue_ct.o obj-$(CONFIG_NETFILTER_NETLINK_QUEUE) += nfnetlink_queue.o obj-$(CONFIG_NETFILTER_NETLINK_LOG) += nfnetlink_log.o
net/netfilter/nf_conntrack_netlink.c +49 -2
75 lines not on this page · raw message
net/netfilter/nfnetlink_queue_core.c +40 -12
105 lines not on this page · raw message
net/netfilter/nfnetlink_queue_ct.c deleted +0 -113
113 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerRFC PATCH 3/3 netfilter: rename nfnetlink_queue_core.c to nfnetlink_queue.c
In reply to Pablo Neira AyusoNow that we have integrated the ct glue code into nfnetlink_queue without introducing dependencies with the conntrack code.
---
net/netfilter/{nfnetlink_queue_core.c => nfnetlink_queue.c} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename net/netfilter/{nfnetlink_queue_core.c => nfnetlink_queue.c} (100%)net/netfilter/nfnetlink_queue.c renamed from net/netfilter/nfnetlink_queue_core.c +0 -0
Signature · 1 line
1.7.10.4
Re: [PATCH RFC 3/3] netfilter: rename nfnetlink_queue_core.c to nfnetlink_queue.c
On Tue, Sep 08, 2015 at 06:54:51PM +0200, Pablo Neira Ayuso wrote:
[...]
Quoted 2 lines
rename from
net/netfilter/nfnetlink_queue_core.c
rename tonet/netfilter/nfnetlink_queue.c
So you know though, we can delete the nfnetlink_queue_core.o line from Makefile.
May I suggest one thing? How about returning -EOPNOTSUPP at nfqnl_recv_config() if derefering nfq_ct_hook is NULL?
Thanks,
Pablo Neira Ayuso
maintainerRe: [PATCH RFC 3/3] netfilter: rename nfnetlink_queue_core.c to nfnetlink_queue.c
Quoted 7 lines · Ken-ichirou MATSUZAWA
On Tue, Sep 08, 2015 at 06:54:51PM +0200, Pablo Neira Ayuso wrote:
[...]Quoted 2 lines
rename from
net/netfilter/nfnetlink_queue_core.c
rename tonet/netfilter/nfnetlink_queue.cSo you know though, we can delete the nfnetlink_queue_core.o line from
Makefile.
Right, the Makefile update is missing. I'm going to fix that here.
Quoted 2 lines
May I suggest one thing? How about returning
-EOPNOTSUPPatnfqnl_recv_config()if dereferingnfq_ct_hookis NULL?
Makes sense. Thus, the user knows that it is not supported, please send a patch for that.
BTW, I think it would be good to add the missing code on nfqnl_recv_verdict_batch() to support conntrack there too. Would you add that code for nfnetlink_queue.c?
Thanks.
nfqueue batch verdict with conntrack (was [PATCH RFC 3/3] netfilter: rename nfnetlink_queue_core.c to nfnetlink_queue.c)
Quoted 2 lines · Pablo Neira Ayuso
BTW, I think it would be good to add the missing code on
nfqnl_recv_verdict_batch()to support conntrack there too. Would you
Sorry, I have never used it and I tried to understand, but...
It seems batch verdict mark and reinject packets in nfqueue its id is less than user requested. What does conntrack (and payload) work on it? update all conntrack expectations less than the id, to the same one user requests?
Thanks,
cover netfilter: nfnetlink_queue: return -EOPNOTSUPP if QUEUE_CT is disabled
In reply to Pablo Neira AyusoHi,
Quoted 8 lines · Ken-ichirou MATSUZAWA
Quoted 4 lines · Pablo Neira Ayuso
[...]
May I suggest one thing? How about returning-EOPNOTSUPPatnfqnl_recv_config()if dereferingnfq_ct_hookis NULL?Makes sense. Thus, the user knows that it is not supported, please send a patch for that.
Would you review the following patch? It applies on top of your "Rework nfnetlink_queue conntrack support" series.
Thanks,
PATCH 1/1 netfilter: nfnetlink_queue: return -EOPNOTSUPP if QUEUE_CT is disabled
Current kernel ignores NFQA_CFG_F_CONNTRACK config flag request even if NETFILTER_NETLINK_QUEUE_CT is disabled. This patch enables to tell it user by returning error nlmsg.
--- net/netfilter/nfnetlink_queue.c | 5 +++++ 1 file changed, 5 insertions(+)
net/netfilter/nfnetlink_queue.c +5 -0
@@ -1224,6 +1224,11 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb, goto err_out_unlock; }#endif +if (flags & mask &NFQA_CFG_F_CONNTRACK && +rcu_dereference (nfq_ct_hook) ==NULL ) { + ret = -EOPNOTSUPP ; + goto err_out_unlock; + }spin_lock_bh (&queue->lock); queue->flags &= ~mask; queue->flags |= flags & mask;
Signature · 1 line
1.7.10.4
Hi Pablo,
Thank you for taking your time.
Quoted 1 line · Pablo Neira Ayuso
They are totally untested, so please carefully review them.
I'm sorry I could not to meet your expectations since I might not understand your intention correctly, please let me ask three questions:
* We will not modularize nfqueue attaching conntrack information part? (was nfnetlink_queue_ct.c)
* May I update nfqnl_ct prefix to nfnl_ct after this patch series applied to attach nfct info to nflog?
* We do not add another Kconfig for nflog attaching ct info?
I tested your patch a little with following lnf-queue patch and it works fine.
Thanks,
PATCH 1/1 examples: attaching a conntrack information
This patch enables nf-queue in examples directory to show conntrack information if --enable-nfct configure option is specified.
--- configure.ac | 8 ++++ examples/Makefile.am | 3 ++ examples/nf-queue.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 2 deletions(-)
configure.ac +8 -0
@@ -28,6 +28,14 @@ esac dnl Dependencies PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.41]) PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3]) +AC_ARG_ENABLE(nfct, + AS_HELP_STRING([--enable-nfct], [Enable nfct integration in examples [default=no]]), + [enable_nfct=$enableval],[enable_nfct=no]) +AS_IF([test "x$enable_nfct" = "xyes"], [ + PKG_CHECK_MODULES([LIBNETFILTER_CONNTRACK], [libnetfilter_conntrack >= 1.0.2]) + AC_DEFINE([BUILD_NFCT], [1], [building nfct integration example]) +]) +AM_CONDITIONAL([BUILD_NFCT], [test "x$enable_nfct" = "xyes"]) dnl Output the makefiles AC_CONFIG_FILES([Makefile src/Makefile utils/Makefile examples/Makefile
examples/Makefile.am +3 -0
@@ -5,3 +5,6 @@ check_PROGRAMS = nf-queue nf_queue_SOURCES = nf-queue.c nf_queue_LDADD = ../src/libnetfilter_queue.la nf_queue_LDFLAGS = -dynamic -lmnl +if BUILD_NFCT +nf_queue_LDFLAGS += $(LIBNETFILTER_CONNTRACK_LIBS) +endif
examples/nf-queue.c +99 -2
131 lines not on this page · raw message
Signature · 1 line
2.1.4
Florian Westphal
maintainerRe: [PATCH lnf-queue] examples: attaching a conntrack information
Quoted 2 lines · Ken-ichirou MATSUZAWA
This patch enables nf-queue in examples directory to show conntrack information if --enable-nfct configure option is specified.
Thanks for doing this!
examples/nf-queue.c nfq_send_verdict(int queue_num, uint32_t id) · line 63
Quoted 8 lines
examples/nf-queue.c +8
-0+#ifdef BUILD_NFCT +static int print_ctinfo (const struct nlattr *const attr) +{ +char *s =NULL ; + +if (attr ==NULL ) +return MNL_CB_OK ; + attr->nla_len =12 ;
What this?
Re: [PATCH lnf-queue] examples: attaching a conntrack information
Quoted 6 lines · Florian Westphal
examples/nf-queue.c nfq_send_verdict(int queue_num, uint32_t id) · line 63
Quoted 3 lines · Ken-ichirou MATSUZAWA
examples/nf-queue.c +3
-0+if (attr ==NULL ) +return MNL_CB_OK ; + attr->nla_len =12 ;What this?
I just wanted to test const qualifier... sorry. Would you mind deleting the line? or should I send it again?
Thakns,
Florian Westphal
maintainerRe: [PATCH lnf-queue] examples: attaching a conntrack information
Quoted 9 lines · Ken-ichirou MATSUZAWA
Quoted 6 lines · Florian Westphal
examples/nf-queue.c nfq_send_verdict(int queue_num, uint32_t id) · line 63
Quoted 3 lines · Ken-ichirou MATSUZAWA
examples/nf-queue.c +3
-0+if (attr ==NULL ) +return MNL_CB_OK ; + attr->nla_len =12 ;What this?
I just wanted to test const qualifier... sorry.
I suspected as much ;)
Quoted 1 line
Would you mind deleting the line? or should I send it again?
I can delete it.
Pablo Neira Ayuso
maintainerRe: [PATCH lnf-queue] examples: attaching a conntrack information
In reply to Florian WestphalQuoted 5 lines · Florian Westphal
Quoted 2 lines · Ken-ichirou MATSUZAWA
This patch enables nf-queue in examples directory to show conntrack information if --enable-nfct configure option is specified.
Thanks for doing this!
Thanks indeed.
Any chance we can get rid of --enable-nfct configure option?
PATCH v2 1/1 examples: attaching a conntrack information
This patch enables nf-queue in examples directory to show conntrack information if libnetfilter_conntrack exists.
--- configure.ac | 4 ++ examples/Makefile.am | 3 ++ examples/nf-queue.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 106 insertions(+), 2 deletions(-)
configure.ac +4 -0
@@ -28,6 +28,10 @@ esac dnl Dependencies PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.41]) PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3]) +PKG_CHECK_MODULES([LIBNETFILTER_CONNTRACK], [libnetfilter_conntrack >= 1.0.2], + [AC_DEFINE([BUILD_NFCT], [1], [building nfct integration example]) HAVE_LNFCT=1], + [HAVE_LNFCT=0]) +AM_CONDITIONAL([BUILD_NFCT], [test "$HAVE_LNFCT" -eq 1]) dnl Output the makefiles AC_CONFIG_FILES([Makefile src/Makefile utils/Makefile examples/Makefile
examples/Makefile.am +3 -0
@@ -5,3 +5,6 @@ check_PROGRAMS = nf-queue nf_queue_SOURCES = nf-queue.c nf_queue_LDADD = ../src/libnetfilter_queue.la nf_queue_LDFLAGS = -dynamic -lmnl +if BUILD_NFCT +nf_queue_LDFLAGS += $(LIBNETFILTER_CONNTRACK_LIBS) +endif
examples/nf-queue.c +99 -2
131 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCH lnf-queue] examples: attaching a conntrack information
In reply to Pablo Neira AyusoHi,
# I have almost fogotten to send this reply, sorry
Quoted 6 lines · Pablo Neira Ayuso
Quoted 3 lines · Florian Westphal
Quoted 2 lines · Ken-ichirou MATSUZAWA
This patch enables nf-queue in examples directory to show conntrack information if --enable-nfct configure option is specified.
Any chance we can get rid of --enable-nfct configure option?
Sure, would you review the foll^h^h^h^h previous patch?
Pablo Neira Ayuso
maintainerQuoted 5 lines · Ken-ichirou MATSUZAWA
Hi Pablo,
Thank you for taking your time.
On Tue, Sep 08, 2015 at 06:54:48PM +0200, Pablo Neira Ayuso wrote:
Quoted 8 lines
Quoted 1 line
They are totally untested, so please carefully review them.
I'm sorry I could not to meet your expectations since I might not understand your intention correctly, please let me ask three questions:
* We will not modularize nfqueue attaching conntrack information part? (was
nfnetlink_queue_ct.c)
After my patchset, everything is in nf_conntrack_netlink.c, so you only need some little extra glue code to access the nfnl_ct indirection from nfnetlink_log.c
Quoted 2 lines
* May I update
nfqnl_ctprefix tonfnl_ctafter this patch series applied to attach nfct info to nflog?
Yes, that's the idea.
Quoted 1 line
* We do not add another
Kconfigfor nflog attaching ct info?
I think you can add it too, yes.
Quoted 2 lines
I tested your patch a little with following lnf-queue patch and it works fine.
Thanks for reporting.
So will you send a follow up patchset on top of those three to add what you need?
Quoted 7 lines · Pablo Neira Ayuso
Quoted 1 line · Ken-ichirou MATSUZAWA
* We do not add another
Kconfigfor nflog attaching ct info?I think you can add it too, yes.
So will you send a follow up patchset on top of those three to add what you need?
Would you see the following patch set?
I don't understand Kconfig part above well,
would you give me some advice?
Thanks,
PATCH 1/3 netfilter: nfnetlink_queue: rename related to nfqueue attaching conntrack info
The idea of this series of patch is to attach conntrack information to nflog like nfqueue has already done. nfqueue conntrack info attaching basis is generic, rename those names to generic one, glue.
--- include/linux/netfilter.h | 4 +-- net/netfilter/core.c | 4 +-- net/netfilter/nf_conntrack_netlink.c | 54 +++++++++++++++++----------------- net/netfilter/nfnetlink_queue.c | 12 ++++---- 4 files changed, 37 insertions(+), 37 deletions(-)
include/linux/netfilter.h +2 -2
@@ -379,7 +379,7 @@ struct nf_conn;enum ip_conntrack_info ;struct nlattr ; -struct nfq_ct_hook { +struct nfnl_ct_hook {struct nf_conn *(*get_ct)(struct sk_buff *skb,enum ip_conntrack_info *ctinfo);size_t (*build_size)(const struct nf_conn *ct);
@@ -392,7 +392,7 @@ struct nfq_ct_hook {void (*seq_adjust)(struct sk_buff *skb,struct nf_conn *ct,enum ip_conntrack_info ctinfo,s32 off); }; -extern struct nfq_ct_hook __rcu *nfq_ct_hook; +extern struct nfnl_ct_hook __rcu *nfnl_ct_hook;/** * nf_skb_duplicated - TEE target has sent a packet
net/netfilter/core.c +2 -2
@@ -385,8 +385,8 @@ void nf_conntrack_destroy(struct nf_conntrack *nfct) }EXPORT_SYMBOL (nf_conntrack_destroy); -struct nfq_ct_hook __rcu *nfq_ct_hook__read_mostly ; -EXPORT_SYMBOL_GPL (nfq_ct_hook); +struct nfnl_ct_hook __rcu *nfnl_ct_hook__read_mostly ; +EXPORT_SYMBOL_GPL (nfnl_ct_hook);#endif /* CONFIG_NF_CONNTRACK */
net/netfilter/nf_conntrack_netlink.c +27 -27
139 lines not on this page · raw message
net/netfilter/nfnetlink_queue.c +6 -6
@@ -302,7 +302,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, {size_t size;size_t data_len =0 , cap_len =0 ; -struct nfq_ct_hook *nfq_ct; +struct nfnl_ct_hook *nfq_ct;unsigned int hlen =0 ;struct sk_buff *skb;struct nlattr *nla;
@@ -365,7 +365,7 @@ nfqnl_build_packet_message(struct net *net, struct nfqnl_instance *queue, }if (queue->flags &NFQA_CFG_F_CONNTRACK ) { - nfq_ct =rcu_dereference (nfq_ct_hook); + nfq_ct =rcu_dereference (nfnl_ct_hook);if (nfq_ct !=NULL ) { ct = nfq_ct->get_ct (entskb, &ctinfo);if (ct !=NULL )
@@ -1008,7 +1008,7 @@ nfqnl_recv_verdict_batch(struct sock *ctnl, struct sk_buff *skb,return 0 ; } -static struct nf_conn *nfqnl_ct_parse(struct nfq_ct_hook *nfq_ct, +static struct nf_conn *nfqnl_ct_parse(struct nfnl_ct_hook *nfq_ct, const struct nlmsghdr *nlh, const struct nlattr * const nfqa[], struct nf_queue_entry *entry,
@@ -1043,7 +1043,7 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,unsigned int verdict;struct nf_queue_entry *entry;enum ip_conntrack_info uninitialized_var (ctinfo ); -struct nfq_ct_hook *nfq_ct; +struct nfnl_ct_hook *nfq_ct;struct nf_conn *ct =NULL ;struct net *net =sock_net (ctnl);
@@ -1068,7 +1068,7 @@ nfqnl_recv_verdict(struct sock *ctnl, struct sk_buff *skb,if (nfqa[NFQA_CT ]) {/* rcu lock already held from nfnl->call_rcu. */ - nfq_ct =rcu_dereference (nfq_ct_hook); + nfq_ct =rcu_dereference (nfnl_ct_hook);if (nfq_ct !=NULL ) ct =nfqnl_ct_parse (nfq_ct, nlh, nfqa, entry, &ctinfo); }
@@ -1225,7 +1225,7 @@ nfqnl_recv_config(struct sock *ctnl, struct sk_buff *skb, }#endif if (flags & mask &NFQA_CFG_F_CONNTRACK && -rcu_dereference (nfq_ct_hook) ==NULL ) { +rcu_dereference (nfnl_ct_hook) ==NULL ) { ret = -EOPNOTSUPP ; goto err_out_unlock; }
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 1/3] netfilter: nfnetlink_queue: rename related to nfqueue attaching conntrack info
Quoted 3 lines · Ken-ichirou MATSUZAWA
The idea of this series of patch is to attach conntrack information to nflog like nfqueue has already done. nfqueue conntrack info attaching basis is generic, rename those names to generic one, glue.
Looks good, please rebase on top of my two patches (unless you find any problem on them) and resubmit this on top of them.
Thanks.
PATCH 1/3 include: Sync with kernel headers
In reply to Ken-ichirou MATSUZAWA--- include/libnetfilter_log/linux_nfnetlink_log.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
include/libnetfilter_log/linux_nfnetlink_log.h +4 -5
@@ -1,16 +1,12 @@#ifndef _NFNETLINK_LOG_H#define _NFNETLINK_LOG_H -#ifndef aligned_u64 -#define aligned_u64 unsigned long long __attribute__((aligned(8))) -#endif -/* This file describes the netlink messages (i.e. 'protocol packets'), * and not any kind of function definitions. It is shared between kernel and * userspace. Don't put kernel specific stuff in here */ #include <linux/types.h> -#include <libnfnetlink/linux_nfnetlink.h> +#include <linux/netfilter/nfnetlink.h> enum nfulnl_msg_types { NFULNL_MSG_PACKET, /* packet from kernel to userspace */
@@ -55,6 +51,8 @@ enum nfulnl_attr_type {NFULA_HWTYPE ,/* hardware type */ NFULA_HWHEADER ,/* hardware header */ NFULA_HWLEN ,/* hardware header length */ +NFULA_CT ,/* nf_conntrack_netlink.h */ +NFULA_CT_INFO ,/* enum ip_conntrack_info */ __NFULA_MAX };
@@ -97,5 +95,6 @@ enum nfulnl_attr_config {#define NFULNL_CFG_F_SEQ 0x0001#define NFULNL_CFG_F_SEQ_GLOBAL 0x0002 +#define NFULNL_CFG_F_CONNTRACK 0x0004#endif /* _NFNETLINK_LOG_H */
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerRe: [PATCH lnf-log 1/3] include: Sync with kernel headers
Quoted 1 line · Ken-ichirou MATSUZAWA
Signed-off-by Ken-ichirou MATSUZAWA <[email protected]>
Applied now that we got the kernelspace bits upstream, thanks.
PATCH 2/3 netfilter: nf_conntrack_netlink: add const qualifier to nfnl_hook
In reply to Ken-ichirou MATSUZAWAget_ct as is and will not update its skb argument, and users of nfnl_ct_hook is now only nfqueue, so we can add const qualifier.
--- include/linux/netfilter.h | 2 +- net/netfilter/nf_conntrack_netlink.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
include/linux/netfilter.h +1 -1
@@ -380,7 +380,7 @@ enum ip_conntrack_info;struct nlattr ;struct nfnl_ct_hook { -struct nf_conn *(*get_ct)(struct sk_buff *skb, +struct nf_conn *(*get_ct)(const struct sk_buff *skb,enum ip_conntrack_info *ctinfo);size_t (*build_size)(const struct nf_conn *ct); int (*build)(struct sk_buff *skb, struct nf_conn *ct,
net/netfilter/nf_conntrack_netlink.c +1 -1
@@ -2139,7 +2139,7 @@ ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct, struct nf_conntrack_tuple *mask);#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT -static struct nf_conn *ctnetlink_glue_get_ct (struct sk_buff *skb, +static struct nf_conn *ctnetlink_glue_get_ct (const struct sk_buff *skb,enum ip_conntrack_info *ctinfo) {struct nf_conn *ct;
Signature · 1 line
1.7.10.4
PATCH 2/3 nlmsg: Add NFULA_CT and NFULA_CT_INFO attributes support
In reply to Ken-ichirou MATSUZAWAThis patch validate NFULA_CT and NFULA_CT_INFO attributes,
--- src/nlmsg.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
src/nlmsg.c +2 -1
@@ -7,7 +7,6 @@* (at your option) any later version. */ #include <arpa/inet.h> -#include <linux/netfilter/nfnetlink_log.h> #include <libmnl/libmnl.h> #include <libnetfilter_log/libnetfilter_log.h> #include <errno.h>
@@ -112,6 +111,7 @@ static int nflog_parse_attr_cb(const struct nlattr *attr, void *data)case NFULA_SEQ :/* instance-local sequence number */ case NFULA_SEQ_GLOBAL :/* global sequence number */ case NFULA_GID :/* group id of socket */ +case NFULA_CT_INFO :/* enum ip_conntrack_info */ if (mnl_attr_validate (attr,MNL_TYPE_U32 ) <0 )return MNL_CB_ERROR ;break ;
@@ -139,6 +139,7 @@ static int nflog_parse_attr_cb(const struct nlattr *attr, void *data)break ;case NFULA_HWHEADER :/* hardware header */ case NFULA_PAYLOAD :/* opaque data payload */ +case NFULA_CT :/* nf_conntrack_netlink.h */ break ; } tb[type] = attr;
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerRe: [PATCH lnf-log 2/3] nlmsg: Add NFULA_CT and NFULA_CT_INFO attributes support
Quoted 1 line · Ken-ichirou MATSUZAWA
This patch validate
NFULA_CTandNFULA_CT_INFOattributes,
Also applied, thanks.
PATCH 3/3 netfilter: nfnetlink_log: allow to attach conntrack
In reply to Ken-ichirou MATSUZAWAThis patch enables to include the conntrack information together with the packet that is sent to user-space via NFLOG, then a user-space program can acquire NATed information by this NFULA_CT attribute.
Including the conntrack information is optional, you can set it via NFULNL_CFG_F_CONNTRACK flag with the NFULA_CFG_FLAGS attribute like NFQUEUE.
--- include/uapi/linux/netfilter/nfnetlink_log.h | 3 ++ net/netfilter/Kconfig | 8 +++++ net/netfilter/nf_conntrack_netlink.c | 8 ++--- net/netfilter/nfnetlink_log.c | 42 ++++++++++++++++++++++---- 4 files changed, 51 insertions(+), 10 deletions(-)
include/uapi/linux/netfilter/nfnetlink_log.h +3 -0
@@ -51,6 +51,8 @@ enum nfulnl_attr_type {NFULA_HWTYPE ,/* hardware type */ NFULA_HWHEADER ,/* hardware header */ NFULA_HWLEN ,/* hardware header length */ +NFULA_CT ,/* nf_conntrack_netlink.h */ +NFULA_CT_INFO ,/* enum ip_conntrack_info */ __NFULA_MAX };
@@ -93,5 +95,6 @@ enum nfulnl_attr_config {#define NFULNL_CFG_F_SEQ 0x0001#define NFULNL_CFG_F_SEQ_GLOBAL 0x0002 +#define NFULNL_CFG_F_CONNTRACK 0x0004#endif /* _NFNETLINK_LOG_H */
net/netfilter/Kconfig +8 -0
@@ -370,6 +370,14 @@ config NETFILTER_NETLINK_QUEUE_CT If this option is enabled, NFQUEUE can include Connection Tracking information together with the packet is the enqueued via NFNETLINK. +config NETFILTER_NETLINK_LOG_CT + bool "NLOG integration with Connection Tracking" + default n + depends on NETFILTER_NETLINK_LOG + help + If this option is enabled, NFLOG can include Connection Tracking + information. + config NF_NAT tristate
net/netfilter/nf_conntrack_netlink.c +4 -4
@@ -2138,7 +2138,7 @@ ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct,struct nf_conntrack_tuple *tuple, struct nf_conntrack_tuple *mask); -#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT +#if defined(CONFIG_NETFILTER_NETLINK_QUEUE_CT ) || defined(NETFILTER_NETLINK_LOG_CT )static struct nf_conn *ctnetlink_glue_get_ct (const struct sk_buff *skb,enum ip_conntrack_info *ctinfo) {
@@ -2382,7 +2382,7 @@ static struct nfnl_ct_hook ctnetlink_glue_hook = { .attach_expect = ctnetlink_glue_attach_expect, .seq_adjust = ctnetlink_glue_seqadj, }; -#endif /* CONFIG_NETFILTER_NETLINK_QUEUE_CT */ +#endif /* CONFIG_NETFILTER_NETLINK_QUEUE_CT || NETFILTER_NETLINK_LOG_CT */ /*********************************************************************** * EXPECT
@@ -3366,7 +3366,7 @@ static int __init ctnetlink_init(void)pr_err ("ctnetlink_init: cannot register pernet operations\n" ); goto err_unreg_exp_subsys; } -#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT +#if defined(CONFIG_NETFILTER_NETLINK_QUEUE_CT ) || defined(NETFILTER_NETLINK_LOG_CT )/* setup interaction between nf_queue and nf_conntrack_netlink. */ RCU_INIT_POINTER (nfnl_ct_hook, &ctnetlink_glue_hook);#endif
@@ -3387,7 +3387,7 @@ static void __exit ctnetlink_exit(void)unregister_pernet_subsys (&ctnetlink_net_ops);nfnetlink_subsys_unregister (&ctnl_exp_subsys);nfnetlink_subsys_unregister (&ctnl_subsys); -#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT +#if defined(CONFIG_NETFILTER_NETLINK_QUEUE_CT ) || defined(NETFILTER_NETLINK_LOG_CT )RCU_INIT_POINTER (nfnl_ct_hook,NULL );#endif }
net/netfilter/nfnetlink_log.c +36 -6
100 lines not on this page · raw message
Signature · 1 line
1.7.10.4
Pablo Neira Ayuso
maintainerRe: [PATCH nf-next 3/3] netfilter: nfnetlink_log: allow to attach conntrack
Quoted 42 lines · Ken-ichirou MATSUZAWA
This patch enables to include the conntrack information together with the packet that is sent to user-space via NFLOG, then a user-space program can acquire NATed information by this
NFULA_CTattribute.Including the conntrack information is optional, you can set it via
NFULNL_CFG_F_CONNTRACKflag with theNFULA_CFG_FLAGSattribute like NFQUEUE.Signed-off-by Ken-ichirou MATSUZAWA <[email protected]>--- include/uapi/linux/netfilter/nfnetlink_log.h | 3 ++ net/netfilter/Kconfig | 8 +++++ net/netfilter/nf_conntrack_netlink.c | 8 ++--- net/netfilter/nfnetlink_log.c | 42 ++++++++++++++++++++++---- 4 files changed, 51 insertions(+), 10 deletions(-)include/uapi/linux/netfilter/nfnetlink_log.h +3
-0@@ -51,6 +51,8 @@ enum nfulnl_attr_type {NFULA_HWTYPE ,/* hardware type */ NFULA_HWHEADER ,/* hardware header */ NFULA_HWLEN ,/* hardware header length */ +NFULA_CT ,/* nf_conntrack_netlink.h */ +NFULA_CT_INFO ,/* enum ip_conntrack_info */ __NFULA_MAX };@@ -93,5 +95,6 @@ enum nfulnl_attr_config {#define NFULNL_CFG_F_SEQ 0x0001#define NFULNL_CFG_F_SEQ_GLOBAL 0x0002 +#define NFULNL_CFG_F_CONNTRACK 0x0004#endif /* _NFNETLINK_LOG_H */ net/netfilter/Kconfig +0
-0
net/netfilter/Kconfig config NETFILTER_NETLINK_QUEUE_CT · line 374
Quoted 5 lines
net/netfilter/Kconfig +2
-0@@ -370,6 +370,14 @@ config NETFILTER_NETLINK_QUEUE_CT If this option is enabled, NFQUEUE can include Connection Tracking information together with the packet is the enqueued via NFNETLINK. +config NETFILTER_NETLINK_LOG_CT + bool "NLOG integration with Connection Tracking"
^^^^^^^^
Use tabs to indent.
net/netfilter/Kconfig config NETFILTER_NETLINK_QUEUE_CT · line 375
Quoted 1 line
net/netfilter/Kconfig +1
-0+ default n
^^^^^^^^
Same here.
Quoted 80 lines
net/netfilter/Kconfig +5
-0+ depends on NETFILTER_NETLINK_LOG + help + If this option is enabled, NFLOG can include Connection Tracking + information. + config NF_NAT tristatenet/netfilter/nf_conntrack_netlink.c +4
-4@@ -2138,7 +2138,7 @@ ctnetlink_alloc_expect(const struct nlattr *const cda[], struct nf_conn *ct,struct nf_conntrack_tuple *tuple, struct nf_conntrack_tuple *mask); -#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT +#if defined(CONFIG_NETFILTER_NETLINK_QUEUE_CT ) || defined(NETFILTER_NETLINK_LOG_CT )static struct nf_conn *ctnetlink_glue_get_ct (const struct sk_buff *skb,enum ip_conntrack_info *ctinfo) {@@ -2382,7 +2382,7 @@ static struct nfnl_ct_hook ctnetlink_glue_hook = { .attach_expect = ctnetlink_glue_attach_expect, .seq_adjust = ctnetlink_glue_seqadj, }; -#endif /* CONFIG_NETFILTER_NETLINK_QUEUE_CT */ +#endif /* CONFIG_NETFILTER_NETLINK_QUEUE_CT || NETFILTER_NETLINK_LOG_CT */ /*********************************************************************** * EXPECT @@ -3366,7 +3366,7 @@ static int __init ctnetlink_init(void)pr_err ("ctnetlink_init: cannot register pernet operations\n" ); goto err_unreg_exp_subsys; } -#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT +#if defined(CONFIG_NETFILTER_NETLINK_QUEUE_CT ) || defined(NETFILTER_NETLINK_LOG_CT )/* setup interaction between nf_queue and nf_conntrack_netlink. */ RCU_INIT_POINTER (nfnl_ct_hook, &ctnetlink_glue_hook);#endif @@ -3387,7 +3387,7 @@ static void __exit ctnetlink_exit(void)unregister_pernet_subsys (&ctnetlink_net_ops);nfnetlink_subsys_unregister (&ctnl_exp_subsys);nfnetlink_subsys_unregister (&ctnl_subsys); -#ifdef CONFIG_NETFILTER_NETLINK_QUEUE_CT +#if defined(CONFIG_NETFILTER_NETLINK_QUEUE_CT ) || defined(NETFILTER_NETLINK_LOG_CT )RCU_INIT_POINTER (nfnl_ct_hook,NULL );#endif }net/netfilter/nfnetlink_log.c +5
-1@@ -27,6 +27,7 @@#include <net/netlink.h> #include <linux/netfilter/nfnetlink.h> #include <linux/netfilter/nfnetlink_log.h> +#include <linux/netfilter/nf_conntrack_common.h> #include <linux/spinlock.h> #include <linux/sysctl.h> #include <linux/proc_fs.h> @@ -401,7 +402,9 @@ __build_packet_message(struct nfnl_log_net *log,unsigned int hooknum, const struct net_device *indev, const struct net_device *outdev, - const char *prefix, unsigned int plen) + const char *prefix, unsigned int plen, + struct nf_conn *ct, enum ip_conntrack_info ctinfo) + { struct nfulnl_msg_packet_hdr pmsg;struct nlmsghdr *nlh;@@ -409,6 +412,7 @@ __build_packet_message(struct nfnl_log_net *log,sk_buff_data_t old_tail = inst->skb->tail;struct sock *sk;const unsigned char *hwhdrp; +struct nfnl_ct_hook *nflog_ct; nlh = nlmsg_put(inst->skb, 0, 0, NFNL_SUBSYS_ULOG << 8 | NFULNL_MSG_PACKET,
net/netfilter/nfnetlink_log.c __build_packet_message(struct nfnl_log_net *log, · line 582
Quoted 4 lines
net/netfilter/nfnetlink_log.c +1
-0@@ -575,6 +579,14 @@ __build_packet_message(struct nfnl_log_net *log, htonl(atomic_inc_return(&log->global_seq)))) goto nla_put_failure; +/* conntrack */
Please remove this comment.
Quoted 54 lines
net/netfilter/nfnetlink_log.c +21
-3+if (ct) { + nflog_ct =rcu_dereference (nfnl_ct_hook); +if (nflog_ct->build (inst->skb, ct, ctinfo, +NFULA_CT ,NFULA_CT_INFO ) <0 ) + goto nla_put_failure; + } +if (data_len) {struct nlattr *nla;int size =nla_attr_size (data_len);@@ -620,12 +632,16 @@ nfulnl_log_packet(struct net *net,const struct nf_loginfo *li_user, const char *prefix) { - unsigned int size, data_len; + size_t size; +unsigned int data_len;struct nfulnl_instance *inst;const struct nf_loginfo *li;unsigned int qthreshold;unsigned int plen;struct nfnl_log_net *log =nfnl_log_pernet (net); +struct nfnl_ct_hook *nflog_ct; +struct nf_conn *ct =NULL ; +enum ip_conntrack_info uninitialized_var (ctinfo );if (li_user && li_user->type ==NF_LOG_TYPE_ULOG ) li = li_user;@@ -671,7 +687,14 @@ nfulnl_log_packet(struct net *net, size +=nla_total_size (sizeof (u_int32_t));if (inst->flags &NFULNL_CFG_F_SEQ_GLOBAL ) size +=nla_total_size (sizeof (u_int32_t)); - +if (inst->flags &NFULNL_CFG_F_CONNTRACK ) { + nflog_ct =rcu_dereference (nfnl_ct_hook); +if (nflog_ct !=NULL ) { + ct = nflog_ct->get_ct (skb, &ctinfo); +if (ct !=NULL ) + size += nflog_ct->build_size (ct); + } + } qthreshold = inst->qthreshold;/* per-rule qthreshold overrides per-instance */ if (li->u.ulog.qthreshold)@@ -715,7 +738,7 @@ nfulnl_log_packet(struct net *net, inst->qlen++;__build_packet_message (log, inst, skb, data_len, pf, - hooknum, in, out, prefix, plen); + hooknum, in, out, prefix, plen, ct, ctinfo);if (inst->qlen >= qthreshold)__nfulnl_flush (inst);
net/netfilter/nfnetlink_log.c nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb, · line 925
Quoted 5 lines
net/netfilter/nfnetlink_log.c +1
-1@@ -899,13 +922,20 @@ nfulnl_recv_config(struct sock *ctnl, struct sk_buff *skb, }if (nfula[NFULA_CFG_FLAGS ]) { -__be16 flags =nla_get_be16 (nfula[NFULA_CFG_FLAGS ]); +__be16 flags =ntohs (nla_get_be16 (nfula[NFULA_CFG_FLAGS ]));
You have to use u16 instead, otherwise 'sparse' checks via make C=2 will complain.
Quoted 19 lines
net/netfilter/nfnetlink_log.c +8
-1if (!inst) { ret = -ENODEV ; goto out; } -nfulnl_set_flags (inst,ntohs (flags)); + +if (flags &NFULNL_CFG_F_CONNTRACK && +rcu_dereference (nfnl_ct_hook) ==NULL ) { + ret = -EOPNOTSUPP ; + goto out_put; + } + +nfulnl_set_flags (inst, flags); } out_put:Signature · 1 line
1.7.10.4
PATCH 3/3 utils: nf-log: attaching a conntrack information
In reply to Ken-ichirou MATSUZAWAThis patch enables nf-log in utils directory to show conntrack information if libnetfilter_conntrack exists.
--- configure.ac | 5 +++ utils/Makefile.am | 3 ++ utils/nf-log.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 110 insertions(+), 1 deletion(-)
configure.ac +5 -0
@@ -4,6 +4,7 @@ AC_INIT([libnetfilter_log], [1.0.1]) AC_CONFIG_AUX_DIR([build-aux]) AC_CANONICAL_HOST AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([-Wall foreign subdir-objects tar-pax no-dist-gzip dist-bzip2 1.6])
@@ -31,6 +32,10 @@ AM_CONDITIONAL([BUILD_IPULOG], [test "x$with_ipulog" != xno]) dnl Dependencies PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.41]) PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3]) +PKG_CHECK_MODULES([LIBNETFILTER_CONNTRACK], [libnetfilter_conntrack >= 1.0.2], + [AC_DEFINE([BUILD_NFCT], [1], [building nfct integration example]) HAVE_LNFCT=1], + [HAVE_LNFCT=0]) +AM_CONDITIONAL([BUILD_NFCT], [test "$HAVE_LNFCT" -eq 1]) dnl Output the makefile AC_CONFIG_FILES([Makefile src/Makefile include/Makefile
utils/Makefile.am +3 -0
@@ -9,6 +9,9 @@ nfulnl_test_LDFLAGS = -dynamic nf_log_SOURCES = nf-log.c nf_log_LDADD = ../src/libnetfilter_log.la nf_log_LDFLAGS = -dynamic -lmnl +if BUILD_NFCT +nf_log_LDFLAGS += $(LIBNETFILTER_CONNTRACK_LIBS) +endif if BUILD_IPULOG check_PROGRAMS += ulog_test
utils/nf-log.c +102 -1
135 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerRe: [PATCH lnf-log 3/3] utils: nf-log: attaching a conntrack information
utils/nf-log.c line 6
Quoted 10 lines · Ken-ichirou MATSUZAWA
utils/nf-log.c +1
-1@@ -3,15 +3,108 @@#include <stdlib.h> #include <arpa/inet.h> -#include <linux/netfilter/nfnetlink_log.h> +/* #include <linux/netfilter/nfnetlink_log.h> */
Do you remember why you had to comment out this line?
Quoted 12 lines
utils/nf-log.c +8
-0+#include <libnetfilter_log/linux_nfnetlink_log.h> #include <libmnl/libmnl.h> #include <libnetfilter_log/libnetfilter_log.h> +#include "../config.h" +#ifdef BUILD_NFCT +#include <linux/netfilter/nf_conntrack_common.h> +#include <libnetfilter_conntrack/libnetfilter_conntrack.h> +#endif + +#ifdef BUILD_NFCT
utils/nf-log.c line 28
Quoted 10 lines
utils/nf-log.c +10
-0+static int print_ctinfo (const struct nlattr *const attr) +{ +char *s =NULL ; + +if (attr ==NULL ) +return MNL_CB_OK ; + +switch (ntohl (mnl_attr_get_u32 (attr))) { +case IP_CT_ESTABLISHED : + s ="IP_CT_ESTABLISHED" ;
For this example, you can probably simplify this with.
case IP_CT_ESTABLISHED:
case IP_CT_ESTABLISHED_REPLY:
s = "ESTABLISHED";utils/nf-log.c line 38
Quoted 10 lines
utils/nf-log.c +10
-0+break ; +case IP_CT_RELATED : + s ="IP_CT_RELATED" ; +break ; +case IP_CT_NEW : + s ="IP_CT_NEW" ; +break ; +case IP_CT_IS_REPLY : + s ="IP_CT_IS_REPLY" ; +break ;
IP_CT_IS_REPLY is never used alone, it's is always combined with NEW, ESTABLISHED, RELATED states.
Quoted 4 lines
utils/nf-log.c +4
-0+/* case IP_CT_ESTABLISHED_REPLY: == IP_CT_IS_REPLY +* s = "IP_CT_ESTABLISHED_REPLY"; +* break; +*/
utils/nf-log.c line 52
Quoted 10 lines
utils/nf-log.c +10
-0+case IP_CT_RELATED_REPLY : + s ="IP_CT_RELATED_REPLY" ; +break ; +case IP_CT_NEW_REPLY : + s ="IP_CT_NEW_REPLY" ; +break ; +/* case IP_CT_NUMBER: == IP_CT_NEW_REPLY +* s ="IP_CT_NUMBER"; +* break; +*/
IP_CT_NUMBER should never happen. Please remove this code.
Same applied to the libnetfilter_queue example that you posted.
Thanks.
Re: [PATCH lnf-log 3/3] utils: nf-log: attaching a conntrack information
Quoted 5 lines · Pablo Neira Ayuso
utils/nf-log.c line 6
Quoted 2 lines · Ken-ichirou MATSUZAWA
utils/nf-log.c +1
-1-#include <linux/netfilter/nfnetlink_log.h> +/* #include <linux/netfilter/nfnetlink_log.h> */ Do you remember why you had to comment out this line?
I think I intended to use linux_nfnetlink_log.h synched previous and made this mistake.
Quoted 9 lines
utils/nf-log.c line 28
Quoted 3 lines
utils/nf-log.c +3
-0+switch (ntohl (mnl_attr_get_u32 (attr))) { +case IP_CT_ESTABLISHED : + s ="IP_CT_ESTABLISHED" ;For this example, you can probably simplify this with.
case IP_CT_ESTABLISHED: case IP_CT_ESTABLISHED_REPLY: s = "ESTABLISHED";
[...]
Quoted 2 lines
IP_CT_IS_REPLYis never used alone, it's is always combined with NEW, ESTABLISHED, RELATED states.
[...]
Quoted 1 line
IP_CT_NUMBERshould never happen. Please remove this code.
I try to fix aboves and would you review the following again? Thanks,
PATCH v2 1/1 utils: nf-log: attaching a conntrack information
This patch enables nf-log in utils directory to show conntrack information if libnetfilter_conntrack exists.
--- configure.ac | 5 +++ utils/Makefile.am | 3 ++ utils/nf-log.c | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 111 insertions(+), 1 deletion(-)
configure.ac +5 -0
@@ -4,6 +4,7 @@ AC_INIT([libnetfilter_log], [1.0.1]) AC_CONFIG_AUX_DIR([build-aux]) AC_CANONICAL_HOST AC_CONFIG_MACRO_DIR([m4]) +AC_CONFIG_HEADERS([config.h]) AM_INIT_AUTOMAKE([-Wall foreign subdir-objects tar-pax no-dist-gzip dist-bzip2 1.6])
@@ -31,6 +32,10 @@ AM_CONDITIONAL([BUILD_IPULOG], [test "x$with_ipulog" != xno]) dnl Dependencies PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.41]) PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3]) +PKG_CHECK_MODULES([LIBNETFILTER_CONNTRACK], [libnetfilter_conntrack >= 1.0.2], + [AC_DEFINE([BUILD_NFCT], [1], [building nfct integration example]) HAVE_LNFCT=1], + [HAVE_LNFCT=0]) +AM_CONDITIONAL([BUILD_NFCT], [test "$HAVE_LNFCT" -eq 1]) dnl Output the makefile AC_CONFIG_FILES([Makefile src/Makefile include/Makefile
utils/Makefile.am +3 -0
@@ -9,6 +9,9 @@ nfulnl_test_LDFLAGS = -dynamic nf_log_SOURCES = nf-log.c nf_log_LDADD = ../src/libnetfilter_log.la nf_log_LDFLAGS = -dynamic -lmnl +if BUILD_NFCT +nf_log_LDFLAGS += $(LIBNETFILTER_CONNTRACK_LIBS) +endif if BUILD_IPULOG check_PROGRAMS += ulog_test
utils/nf-log.c +103 -1
136 lines not on this page · raw message
Signature · 1 line
2.1.4
Pablo Neira Ayuso
maintainerRe: [PATCHv2 lnf-log] utils: nf-log: attaching a conntrack information
Quoted 5 lines · Ken-ichirou MATSUZAWA
utils/nf-log.c +0
-0
utils/nf-log.c line 11
Quoted 10 lines
utils/nf-log.c +2
-1@@ -3,15 +3,109 @@#include <stdlib.h> #include <arpa/inet.h> -#include <linux/netfilter/nfnetlink_log.h> +#include <libnetfilter_log/linux_nfnetlink_log.h> #include <libmnl/libmnl.h> #include <libnetfilter_log/libnetfilter_log.h> +#include "../config.h"
I think you can update configure.ac to update CFLAGS, like this:
CFLAGS="$CFLAGS -DBUILD_NFCT"
so we can skip this include.
I think it would be good if people can take the examples out of the tree and compile them by hand through, eg.
gcc -lnetfilter_log -lnetfilter_conntrack -lmnl -DBUILD_NFCT nf-log.c -o nf-log
Thanks.
Re: [PATCHv2 lnf-log] utils: nf-log: attaching a conntrack information
Hi, sorry for so much late.
Quoted 5 lines · Pablo Neira Ayuso
I think you can update configure.ac to update CFLAGS, like this:
CFLAGS="$CFLAGS -DBUILD_NFCT"
so we can skip this include.
We can avoid to (re)run autogen.sh without lnf-conntrack at first then install it after, but
Quoted 1 line
gcc -lnetfilter_log -lnetfilter_conntrack -lmnl -DBUILD_NFCT
nf-log.c-o nf-log
this make a sense, I follow your advice.
I have met another issue related to lnf-conntrack, could you give me some advice? The following patch is compile error:
In file included from nf-log.c:14:0:
/usr/include/libnetfilter_conntrack/libnetfilter_conntrack.h:729:6: error: nested redefinition of ‘enum ip_conntrack_status’
enum ip_conntrack_status {
^
/usr/include/libnetfilter_conntrack/libnetfilter_conntrack.h:729:6: error: redeclaration of ‘enum ip_conntrack_status’ In file included from nf-log.c:12:0:
/usr/include/linux/netfilter/nf_conntrack_common.h:37:6: note: originally defined here
enum ip_conntrack_status {
since both libnetfilter_conntrack.h and nf_conntrack_common.h defines ip_conntrack_status. Could you tell me how do I avoid such a error when using ip_conntrack_status and ip_conntrack_info?
# It seems that the prev 2 patches I posted with this
# has not applied yet?
Thanks,
Re: [PATCHv2 lnf-log] utils: nf-log: attaching a conntrack information
This patch enables nf-log in utils directory to show conntrack information if libnetfilter_conntrack exists.
configure.ac +4 -1
@@ -19,7 +19,7 @@ AM_PROG_LIBTOOL AC_PROG_INSTALL AC_PROG_LN_S -case "$host" in +case "$host" in *-*-linux* | *-*-uclinux*) ;; *) AC_MSG_ERROR([Linux only, dude!]);; esac
@@ -31,6 +31,9 @@ AM_CONDITIONAL([BUILD_IPULOG], [test "x$with_ipulog" != xno]) dnl Dependencies PKG_CHECK_MODULES([LIBNFNETLINK], [libnfnetlink >= 0.0.41]) PKG_CHECK_MODULES([LIBMNL], [libmnl >= 1.0.3]) +PKG_CHECK_MODULES([LIBNETFILTER_CONNTRACK], [libnetfilter_conntrack >= 1.0.2], + [HAVE_LNFCT=1], [HAVE_LNFCT=0]) +AM_CONDITIONAL([BUILD_NFCT], [test "$HAVE_LNFCT" -eq 1]) dnl Output the makefile AC_CONFIG_FILES([Makefile src/Makefile include/Makefile
utils/Makefile.am +4 -0
@@ -9,6 +9,10 @@ nfulnl_test_LDFLAGS = -dynamic nf_log_SOURCES = nf-log.c nf_log_LDADD = ../src/libnetfilter_log.la nf_log_LDFLAGS = -dynamic -lmnl +if BUILD_NFCT +nf_log_LDFLAGS += $(LIBNETFILTER_CONNTRACK_LIBS) +nf_log_CFLAGS = -DBUILD_NFCT +endif if BUILD_IPULOG check_PROGRAMS += ulog_test
utils/nf-log.c +102 -1
135 lines not on this page · raw message
Signature · 1 line
2.1.4
Re: [PATCHv2 lnf-log] utils: nf-log: attaching a conntrack information
Quoted 2 lines · Ken-ichirou MATSUZAWA
This patch enables nf-log in utils directory to show conntrack information if
libnetfilter_conntrackexists.
Applied, thanks Ken-ichirou.
We got already one user asking for this, so this is useful :)
Pablo Neira Ayuso
maintainerRe: [PATCHv2 lnf-log] utils: nf-log: attaching a conntrack information
In reply to Ken-ichirou MATSUZAWAQuoted 28 lines · Ken-ichirou MATSUZAWA
Hi, sorry for so much late.
Quoted 5 lines · Pablo Neira Ayuso
I think you can update configure.ac to update CFLAGS, like this:
CFLAGS="$CFLAGS -DBUILD_NFCT"
so we can skip this include.
We can avoid to (re)run
autogen.shwithout lnf-conntrack at first then install it after, butQuoted 1 line
gcc -lnetfilter_log -lnetfilter_conntrack -lmnl -DBUILD_NFCT
nf-log.c-o nf-logthis make a sense, I follow your advice.
I have met another issue related to lnf-conntrack, could you give me some advice? The following patch is compile error:
In file included from nf-log.c:14:0:
/usr/include/libnetfilter_conntrack/libnetfilter_conntrack.h:729:6: error: nested redefinition of ‘enum ip_conntrack_status’
enumip_conntrack_status{
^
/usr/include/libnetfilter_conntrack/libnetfilter_conntrack.h:729:6: error: redeclaration of ‘enum ip_conntrack_status’ In file included from nf-log.c:12:0:
/usr/include/linux/netfilter/nf_conntrack_common.h:37:6: note: originally defined here
enumip_conntrack_status{
Quoted 3 lines
since both
libnetfilter_conntrack.handnf_conntrack_common.hdefinesip_conntrack_status. Could you tell me how do I avoid such a error when usingip_conntrack_statusandip_conntrack_info?
I have just fixed this on the repository:
commit 9833df6abd4d5ef381354e32b2d7d7afa7a616fe
Author: Pablo Neira Ayuso <[email protected]> Date: Thu Nov 24 14:09:34 2016 +0100
include: expose a copy of nf_conntrack_common.h
Copy and rename nf_conntrack_common.h tolinux_nf_conntrack_common.h,
then include it from libnetfilter_conntrack.h
Please, let me know if you see any problem with such update, thanks.