#!/bin/sh
ipfw='/sbin/ipfw -q'
ournet='192.168.0.0/16'
ifuser='rl1'
ifout='rl0'
ip_out='172.16.0.2'
#----CONFIG----
${ipfw} flush
${ipfw} queue flush
${ipfw} pipe flush
${ipfw} add 100 check-state
${ipfw} add 1000 allow all from any to any via lo0
${ipfw} add 1400 deny tcp from any to any not established tcpflags fin
${ipfw} add 1500 deny tcp from any to any tcpflags fin,syn,rst,psh,ack,urg
${ipfw} add 4300 reject ip from ${ournet} to any in via ${ifout}
${ipfw} add 4330 allow udp from 192.168.0.20 to any domain keep-state
#${ipfw} add 4340 allow upd from any to 192.168.0.20 domain
${ipfw} add 4350 allow ip from me to any
${ipfw} add 6000 divert 8669 ip from any to ${ip_out} in via ${ifout}
${ipfw} add 65534 allow all from any to any
#----PIPES----
${ipfw} pipe 1 config bw 384Kbit/s
${ipfw} queue 1 config pipe 1 weight 90
${ipfw} pipe 2 config bw 128Kbit/s
${ipfw} queue 2 config pipe 2 weight 90
#${ipfw} pipe 3 config bw 128Rbit/s delay 0 queue 4096KBytes plr 0
#${ipfw} queue 3 config pipe 3 weight 90
#-пользователь-1
#${ipfw} add 6012 pipe 1 ip from any to 192.168.4.1 via ${ifout}
${ipfw} add 6013 allow ip from any to 192.168.4.1 via ${ifout}
${ipfw} add 6010 divert 8669 ip from 192.168.4.1 to any out via ${ifout}
${ipfw} add 6011 queue 1 ip from any to 192.168.4.1 via ${ifout}
#-пользователь-2
${ipfw} add 6022 pipe 2 ip from any to 192.168.2.2 via ${ifout}
${ipfw} add 6023 allow ip from any to 192.168.2.2 via ${ifout}
${ipfw} add 6020 divert 8669 ip from 192.168.2.2 to any out via ${ifout}
#${ipfw} add 6021 queue 2 ip from any to 192.168.2.2 via ${ifout}
#-пользователь-3
#${ipfw} add 6032 pipe 1 ip from any to 192.168.4.2 via ${ifout}
${ipfw} add 6033 allow ip from any to 192.168.4.2 via ${ifout}
${ipfw} add 6030 divert 8669 ip from 192.168.4.2 to any out via ${ifout}
${ipfw} add 6031 queue 1 ip from any to 192.168.4.2 via ${ifout}