Linux Netfilter discussions
 help / color / mirror / Atom feed
From: "Taylor, Grant" <gtaylor@riverviewtech.net>
To: christopher.f.ulherr@exgate.tek.com
Cc: netfilter@lists.netfilter.org
Subject: Re: logging of successful tcp connections
Date: Thu, 21 Apr 2005 14:58:34 -0500	[thread overview]
Message-ID: <426805EA.3000901@riverviewtech.net> (raw)
In-Reply-To: <F97948CF897D7B46802A18845A8B9BFD471A59@us-rich-m01.global.tektronix.net>

> I would like to know if there is a way I can log only successful tcp
> connections. I'm only interested in successful (established) connections,
> and not just syn "connection attempts". I guess what I need is a way to log
> a single packet if it caused a state transition from NEW to ESTABLISHED. It
> would also be helpful to log the packet that terminated the connection
> (state change from established). In this manner, we could easily tell what
> connections were made, and their duration (and not rely on the userland
> application to log this info).

You don't ask for any thing easy do you.  ;)

> I've looked into using the state matching, but couldn't achieve this
> specific functionality with that.

I think this is something that is beyond basic state matching as state matching is just matching on the current state of the packet / connection.  This does not have any thing to do with the prior state of the packet / connection.

> Is there some trivial way to accomplish this I am overlooking?

No, I don't think there is a ""trivial way to do this.  What initially comes to mind is to use the recent match extension for the history mechanism that is needed in this scenario.  I think you will need to so something along these lines to come even close to what you are after:

1)  Put all traffic in a NEW state in to a recent list (recent_NEW) and continue to handle it like you normally would.
2)  Put all traffic in an ESTABLISHED state in to a (different) recent list (recent_ESTABLISHED) and continue to handle it like you normally would.
3)  If traffic is ESTABLISHED that is on the recent_NEW list but not on the recent_ESTABLISHED list you know that this connection recently (as in this connection) transitioned from the NEW state to the ESTABLISHED state and thus would be added to the recent_ESTABLISHED list.  I would be tempted to jump to a new sub chain where you could log and do any other actions on the packet that you wanted to.
4)  If traffic is ESTABLISHED that is on the recent_ESTABLISHED list and has the FIN flag set in the header you know that this connection recently (as in this connection) transitioned from the ESTABLISHED state to a closing (FIN) state and thus would be added to the recent_FIN list.  I would be tempted to jump to a new sub chain where you could log and do any other actions on the packet that you wanted to.

You would also want to watch for any traffic that came in with the RST flag set as well as traffic that never goes through a FIN state.

Keep in mind that this is all theoretical and had not even been cooded out (IPTables script written) and thus should be taken as what I would try first to set something like this up.  If you would like to give me some network config that you are working with I would be happy to see if I could not come up with working examples for you to use.



Grant. . . .


  reply	other threads:[~2005-04-21 19:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-21 17:28 logging of successful tcp connections christopher.f.ulherr
2005-04-21 19:58 ` Taylor, Grant [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-04-21 22:28 christopher.f.ulherr
2005-04-21 23:55 ` Taylor Grant
2005-04-21 16:38 christopher.f.ulherr
2005-04-22 15: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=426805EA.3000901@riverviewtech.net \
    --to=gtaylor@riverviewtech.net \
    --cc=christopher.f.ulherr@exgate.tek.com \
    --cc=netfilter@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