All of lore.kernel.org
 help / color / mirror / Atom feed
From: Pablo Neira Ayuso <pablo@netfilter.org>
To: Thomas Mader <thezema@gmail.com>
Cc: Netfilter Development Mailinglist
	<netfilter-devel@vger.kernel.org>,
	Patrick McHardy <kaber@trash.net>
Subject: Re: libnetfilter_queue and libnetfilter_conntrack API questions
Date: Wed, 09 Apr 2008 16:46:02 +0200	[thread overview]
Message-ID: <47FCD6AA.8030205@netfilter.org> (raw)
In-Reply-To: <47FCCD6C.6050409@gmail.com>

Thomas Mader wrote:
> Hello,
> 
> why is it that I cannot get the conntrack ID when I set up a callback
> function for DESTROY events with libnetfilter_conntrack?
> When I do
> 
> int id = nfct_get_attr_u32(ct, ATTR_ID);
> printf("delete ID: %d\n", id);
> 
> in my callback function. The id I get is always 0.
> It works for conntrack dumps but not for events it seems.

The events do not include the ID, this is how it goes as for now.
Actually I'm not a big fun of the ID.

@Patrick: I don't remember exactly the reason why we decided to keep the
ID there, and if we have decided to do so, it seems inconsistent to me
not to include it in the events.

> The other question I have is the following.
> I need to port a kernelspace netfilter module to userspace. It deals
> with udp and icmp packets, and in kernelspace I have the match function
> as a callback and in that match function I grab the corresponding
> conntrack tuple for the incoming packet to get the conntrack id. With
> this id I can search a list, if this connection is already in that list,
> and can update information in that list or add the connection to the
> list if it is not yet in that list.
> I also have a notifier callback function where I get notified when a
> connection was deleted. I need this to get the id of the deleted
> connection and delete it as well in my list with connections.
> Now the question is, how I can do this in userspace. I managed to get
> the match function from kernelspace ported to userspace by using
> libnetfilter_queue API. But to implement the delete notifier and to get
> the conntrack id I need to use libnetfilter_conntrack API where the
> problems arise.
> I need
> 
> while ((rv = recv(fd, buf, sizeof(buf), 0)) && rv >= 0) {
>         nfq_handle_packet(h, buf, rv);
> }
> 
> to handle packets with my libnetfilter_queue callback function. But if I
> want to get notified by conntrack for delete events I need nfct_catch,
> which also blocks my program.
> So my question is, if I need to spawn multiple threads to get it done or
> if there is another solution?

I'd prefer polling from both sockets instead of using threads, you can
access the socket descriptors via nfct_fd() and nfq_fd().

Anyway, the main problem that I see is that you'll have to delay the
packet verdict until you receive the conntrack event, otherwise you risk
to have a race condition. However, I think that the solution would not
be that performant.

-- 
"Los honestos son inadaptados sociales" -- Les Luthiers

  reply	other threads:[~2008-04-09 14:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-09 14:06 libnetfilter_queue and libnetfilter_conntrack API questions Thomas Mader
2008-04-09 14:46 ` Pablo Neira Ayuso [this message]
2008-04-09 14:52   ` Patrick McHardy
2008-04-09 15:02     ` Pablo Neira Ayuso
2008-04-09 15:07       ` Patrick McHardy
2008-04-09 16:00   ` Thomas Mader

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=47FCD6AA.8030205@netfilter.org \
    --to=pablo@netfilter.org \
    --cc=kaber@trash.net \
    --cc=netfilter-devel@vger.kernel.org \
    --cc=thezema@gmail.com \
    /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.