netfilter.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Beverley <andy@andybev.com>
To: Ed W <lists@wildgooses.com>
Cc: Netfilter <netfilter@vger.kernel.org>
Subject: Re: High accuracy bandwidth accounting?
Date: Mon, 09 May 2011 22:45:33 +0100	[thread overview]
Message-ID: <1304977533.1921.305.camel@andybev-desktop> (raw)
In-Reply-To: <4DC7F632.9020105@wildgooses.com>

On Mon, 2011-05-09 at 15:12 +0100, Ed W wrote:
> Hi, I have a slightly peculiar requirement to track very accurate *per
> user* traffic for a small remote userbase.  The internet connections
> these users have available will be one or more of: a) circuit switched
> satellite phone (ie per second billing), data volume billed (ie GPRS
> style) satellite phone or a 3G cell phone - all of these will have non
> trivial bandwidth costs and we want to attribute very exact costs back
> on a per user basis.
> 
> To do this I'm using a small custom built embedded router, and we will
> use some form of 802.11x or captive portal style user authentication but
> I have two areas I need advice on solving:
> 
> 1) Best way to do per user traffic accounting *per* internet gateway. ie
> each gateway will have quite radically different costs to run and so we
> need to also count traffic per route.  My current thinking is to use
> packet marking to choose the route and my tests suggest that I can
> pickup this mark via conntrack and therefore account using ulogd/pmacct
> or similar?  Anyone got any thoughts on other ways to slice this or
> anything I am missing?

That sounds good. Using marks is a pretty flexible way of achieving most
things. I don't think I fully understand your setup though without a
diagram. How are you identifying individual users within each route? By
IP address?

> 2) How to account for traffic passing through a "proxy".  eg I want to
> run a local DNS resolver, but try to match the external DNS traffic back
> to the user that caused it?

Obviously if you just want to know what traffic is going to/from an IP
address, then you can use the INPUT/OUTPUT chains rather than the
FORWARD chain. I assume that it is not that simple though.

>  I think I could probably modify the code of
> a suitable resolver to apply a packet mark to upstream data, but I
> wasn't able to find how to apply "marks" from userspace applications
> from a quick google - can someone point me to a reference?

Not sure of a reference, but you can use:

setsockopt(fd, SOL_SOCKET, SO_MARK, ...)

Contact the netfilter-dev list for more advice on that.

>   Does anyone
> have any other ideas on how I might do this?  I will also use a couple
> of other proxies for http (probably Squid) and email traffic - will need
> to apply a similar solution there (perhaps TPROXY with squid?)

I wrote a similar patch for Squid (released in V3.2), which allows
packets to be marked before Squid, and Squid to reapply the mark on
retransmission. Marks can also be applied for locally cached files. If
it helps the patch is at:

http://bazaar.launchpad.net/~squid/squid/3-trunk/revision/10925

Andy



  reply	other threads:[~2011-05-09 21:45 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-09 14:12 High accuracy bandwidth accounting? Ed W
2011-05-09 21:45 ` Andrew Beverley [this message]
2011-05-09 22:07   ` Ed W
2011-05-09 22:16     ` Andrew Beverley
2011-05-09 22:49   ` Ed W
2011-05-11 14:30   ` Ed W
2011-05-12  0:01     ` Andrew Beverley
2011-05-12 22:17       ` Ed W
2011-05-12 22:27         ` Andrew Beverley
2011-05-09 23:23 ` Ed W
2011-05-14  9:23   ` Andrew Beverley
2011-05-14 13:36     ` Ed W
2011-05-14 16:29       ` Andrew Beverley
2011-05-14 22:33         ` Jan Engelhardt
2011-05-15  7:23           ` Andrew Beverley
2011-05-15  9:08             ` Jan Engelhardt
2011-05-16  6:43               ` Andrew Beverley
2011-05-16  7:23                 ` Jan Engelhardt
2011-05-22 21:22                   ` Andrew Beverley
2011-05-16 14:35               ` Ed W
2011-05-16 14:59                 ` Jan Engelhardt
2011-05-16 16:53                   ` Ed W
2011-05-14  9:48   ` Marek Kierdelewicz

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=1304977533.1921.305.camel@andybev-desktop \
    --to=andy@andybev.com \
    --cc=lists@wildgooses.com \
    --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 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).