netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Rennie deGraaf <degraaf@cpsc.ucalgary.ca>
To: Netfilter Developer Mailing List <netfilter-devel@lists.netfilter.org>
Subject: Using libnetfilter_queue
Date: Fri, 16 Mar 2007 13:50:22 -0600	[thread overview]
Message-ID: <45FAF4FE.5000105@cpsc.ucalgary.ca> (raw)

[-- Attachment #1: Type: text/plain, Size: 2507 bytes --]

Hello all,

I am trying to write an application that uses libnetfilter_queue, and
have a few questions about its API.

If I understand correctly from the example program supplied with
libnetfilter_queue, the user is responsible for reading messages from
kernelspace with a recv() call.  At this point, the messages are still
opaque nfnetlink messages, which must be passed to nfq_handle_packet()
for parsing.  This function never returns a parsed message; the caller
only gets access to the message fields inside the callback that was
provided to nfq_create_queue().  The callback is expected to call either
nfq_set_verdict() or nfq_set_verdict_mark() before returning.

My questions follow:
1. How is the caller supposed to correctly read the message from
kernelspace, when the caller doesn't know the message size?  The caller
should know an upper bound on the size of the packet contents being
returned, but doesn't know the size of the metadata fields or the
netlink header.  The only ways that I have found to safely read messages
are to either allocate large buffers that *should* be able to fit
everything (this is the approach taken by the example program -- except
that the buffer that it allocates is too small for large packets) or to
first read a struct nlmsghdr using MSG_PEEK, decode the total message
size, allocate a buffer of appropriate size, and then read the whole
message (this breaks encapulation).  It seems to me that the better way
to do this would be for the libnetfilter_queue API to provide a function
that safely reads packets from kernelspace without exposing
implementation details to the caller.  If the callback architecture is
preserved, this could be done inside nfq_handle_packet().

2. What is the point of the callback?  It seems to me that it would be
much simpler to have nfq_handle_packet() (or better yet, a function that
reads a packet) return a parsed packet to the caller and let it handle
it as it wishes.  The only good reason that I can see for having a
callback is to require that nfq_set_verdict() gets called at some point,
but the callback doesn't actually enforce this.  I don't see what
advantage this architecture has over a simpler socket-like API where
programs can open a connection, read a packet, analyze its contents, set
a verdict, and close the connection all from the same logical block.

If I'm misunderstanding how the libnetfilter_queue API works, please let
me know.

Thanks,
Rennie deGraaf


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

             reply	other threads:[~2007-03-16 19:50 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-16 19:50 Rennie deGraaf [this message]
2007-03-16 21:25 ` SHA-2 HMAC support in linux kernel Chinh Nguyen
2007-03-16 20:31   ` YOSHIFUJI Hideaki / 吉藤英明
2007-03-16 20:32     ` Jan Engelhardt
2007-03-16 21:42       ` Chinh Nguyen
  -- strict thread matches above, loose matches on Subject: below --
2007-11-16 21:02 using libnetfilter_queue Abhijit Menon-Sen
2007-11-16 22:14 ` Eric Leblond

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=45FAF4FE.5000105@cpsc.ucalgary.ca \
    --to=degraaf@cpsc.ucalgary.ca \
    --cc=netfilter-devel@lists.netfilter.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 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).