From: Alex Bligh <alex@alex.org.uk>
To: netfilter@vger.kernel.org
Cc: Alex Bligh <alex@alex.org.uk>
Subject: libnfcontrack weirdness
Date: Mon, 02 Aug 2010 17:20:10 +0100 [thread overview]
Message-ID: <59381F8FA203F4555FD43BB0@Ximines.local> (raw)
I may be doing something stupid here, but I can't seem to get information
on an existing connection through libnfconntrack.
Code extract below. When passed a 4-tuple describing an existing connection,
it prints "Found connection", when passed other stuff, it does not. So
that much is working.
However, no ATTR_ stuff relating to the connection is printed out
except for ATTR_ORIG_PORT_* which are synonyms of what has been
set with nfct_set_attr.
I am having difficulty finding documentation for this, but surely
there must be a way to get the information out from the connection
itself.
--
Alex Bligh
/* Get the prenat source port associated with a connection */
u_int16_t getprenatport(struct in_addr * local_addr, struct in_addr *
remote_addr, int local_port, int remote_port)
{
struct nfct_handle *h;
struct nf_conntrack *ct;
u_int16_t port =0;
if (NULL == (ct = nfct_new()))
return 0;
nfct_set_attr_u8(ct, ATTR_L3PROTO, AF_INET);
nfct_set_attr_u32(ct, ATTR_IPV4_SRC, *((u_int32_t *)remote_addr));
nfct_set_attr_u32(ct, ATTR_IPV4_DST, *((u_int32_t *)local_addr));
nfct_set_attr_u8(ct, ATTR_L4PROTO, IPPROTO_TCP);
nfct_set_attr_u16(ct, ATTR_PORT_SRC, htons(remote_port));
nfct_set_attr_u16(ct, ATTR_PORT_DST, htons(local_port));
h = nfct_open(CONNTRACK, 0);
if (!h) {
return 0;
}
if (nfct_query(h, NFCT_Q_GET, ct)<0)
{
nfct_close(h);
return 0;
}
dolog ("Found connection "
"ATTR_ORIG_COUNTER_PACKETS=%d "
"ATTR_REPL_COUNTER_PACKETS=%d "
"ATTR_REPL_PORT_SRC=%d "
"ATTR_REPL_PORT_DST=%d "
"ATTR_ORIG_PORT_SRC=%d "
"ATTR_ORIG_PORT_DST=%d "
"ATTR_MASTER_PORT_SRC=%d "
"ATTR_MASTER_PORT_DST=%d",
ntohs(nfct_get_attr_u32(ct, ATTR_ORIG_COUNTER_PACKETS)),
ntohs(nfct_get_attr_u32(ct, ATTR_REPL_COUNTER_PACKETS)),
ntohs(nfct_get_attr_u16(ct, ATTR_REPL_PORT_SRC)),
ntohs(nfct_get_attr_u16(ct, ATTR_REPL_PORT_DST)),
ntohs(nfct_get_attr_u16(ct, ATTR_ORIG_PORT_SRC)),
ntohs(nfct_get_attr_u16(ct, ATTR_ORIG_PORT_DST)),
ntohs(nfct_get_attr_u16(ct, ATTR_MASTER_PORT_SRC)),
ntohs(nfct_get_attr_u16(ct, ATTR_MASTER_PORT_DST))
);
port = ntohs(nfct_get_attr_u16(ct, ATTR_ORIG_PORT_DST));
nfct_close(h);
return 0;
}
next reply other threads:[~2010-08-02 16:20 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-08-02 16:20 Alex Bligh [this message]
2010-08-02 18:10 ` libnfcontrack weirdness Andrew Beverley
2010-08-02 18:45 ` Pablo Neira Ayuso
2010-08-02 19:10 ` Jan Engelhardt
2010-08-03 12:43 ` Pablo Neira Ayuso
2010-08-03 14:12 ` Jan Engelhardt
2010-08-02 19:14 ` Andrew Beverley
2010-08-02 22:29 ` Alex Bligh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=59381F8FA203F4555FD43BB0@Ximines.local \
--to=alex@alex.org.uk \
--cc=netfilter@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.