🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: bit.listserv.openbsd-pf
Article #182

Re: throttle traffic by amount of time or amount of used traffic in GB?

#182
From: Peter N. M. Hansteen
Date: Sat, 13 Apr 2013 06:20
50 lines
3911 bytes
Sebastian Singer <sebastian.singer@kesslar.de> writes:

> So I do not want to cut him off the internet completely,  just limit
> his bandwidth so much that he is throttled if he has reached a set
> time limit or else if he reaches a certain amount of gb used.
>
> So the question is: is pf (ALTQ especially) able to cope with these
> requirements? And if how would such rules in pf.conf look? I am by far
> no pf guru but have run a OpenBSD SOHO server for about 10 years. So I
> think I do have a basic unterstanding of pf matters.

Most if not all queueing options that come to mind (mostly the hfsc
ones) only operate on a per connection (per state) level, but it's
possible to collect statistics on traffic from a specific IP address,
either via rules with labels (see eg [1] onwards) or if the address is
part of a table, from the statistics collected on table entries, ie do a
pfctl -vt tablename -T show and you'll get something like this per table
entry:

   219.142.91.125
        Cleared:            Mon Apr  1 14:54:30 2013
        In/Block:           [ Packets: 874                Bytes: 51983              ]
        In/Pass:            [ Packets: 0                  Bytes: 0                  ]
        Out/Block:          [ Packets: 0                  Bytes: 0                  ]
        Out/Pass:           [ Packets: 0                  Bytes: 0                  ]

You could then whip up a script that parses either that or pfctl -vsl
output for the labels scenario and if your rules assign traffic to
queues based on membership in tables, have your script shift the source
address to the table whose traffic gets assigned to a smaller bandwidth
queue, and run your script at short intervals from a system crontab.

Or in a 'no online games after 10 PM' or similar scenario, have a
slightly simpler script do the tables shuffling at a specific time
(again assuming you slice your traffic according to table membership).

Off the top of my head, I think those are the most workable options, I
hope this was a tiny bit helpful.

- Peter

[1] http://home.nuug.no/~peter/pf/newest/labelstats.html and also
    covered in The Book of PF (http://nostarch.com/pf2.htm and at 
    better bookstores)

-- 
Peter N. M. Hansteen, member of the first RFC 1149 implementation team
http://bsdly.blogspot.com/ http://www.bsdly.net/ http://www.nuug.no/
"Remember to set the evil bit on all malicious network traffic"
delilah spamd[29949]: 85.152.224.147: disconnected after 42673 seconds.
Technical Details
Message-ID: <87a9p3zjsr.fsf@deeperthought.bsdly.net>
Path: arc1-ca.pugleaf.net!hg5ni15378wib.1!nntp.google.com!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.nobody.at!usenet.blueworldhosting.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!newsgate.newsguy.com!newsp.newsguy.com!mdrn
References: <640f1d1d2f4d8709af0e499c17a42466@www.kesslar.de>

Show Full Headers
Complete Article Headers
X-Google-Thread: bffa70e3,a3cf27524871199c
X-Google-Attributes: gidbffa70e3,public,usenet
X-Google-NewGroupId: yes
X-Google-Language: ENGLISH,UTF8
X-Received: by 10.180.106.232 with SMTP id gx8mr3083970wib.2.1366252845652;
        Wed, 17 Apr 2013 19:40:45 -0700 (PDT)
Path: arc1-ca.pugleaf.net!hg5ni15378wib.1!nntp.google.com!feeder1.cambriumusenet.nl!82.197.223.108.MISMATCH!feeder2.cambriumusenet.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!border2.nntp.ams2.giganews.com!border1.nntp.ams2.giganews.com!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!news.nobody.at!usenet.blueworldhosting.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!spln!newsgate.newsguy.com!newsp.newsguy.com!mdrn
From: peter@bsdly.net (Peter N. M. Hansteen)
Newsgroups: bit.listserv.openbsd-pf
Subject: Re: throttle traffic by amount of time or amount of used traffic in GB?
Date: 12 Apr 2013 23:20:05 -0700
Organization: None
Lines: 50
Message-ID: <87a9p3zjsr.fsf@deeperthought.bsdly.net>
References: <640f1d1d2f4d8709af0e499c17a42466@www.kesslar.de>
NNTP-Posting-Host: sonofskinny.bsdly.net
Mime-Version: 1.0
NNTP-Posting-Date: 13 Apr 2013 06:20:06 GMT
X-Received-Bytes: 3181
Bytes: 3372
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit