All of lore.kernel.org
 help / color / mirror / Atom feed
* libnfcontrack weirdness
@ 2010-08-02 16:20 Alex Bligh
  2010-08-02 18:10 ` Andrew Beverley
  0 siblings, 1 reply; 8+ messages in thread
From: Alex Bligh @ 2010-08-02 16:20 UTC (permalink / raw)
  To: netfilter; +Cc: Alex Bligh

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;

}


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-08-03 14:12 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-02 16:20 libnfcontrack weirdness Alex Bligh
2010-08-02 18:10 ` 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

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.