Saubere Migration von IPFW auf PF+ALTQ

PatTheMav

Well-Known Member
Aktuell hyped die BSDWelt ja immer noch PF+Altq, da kommt ja keiner dran vorbei, da bei mir aber IPFW und DUMMYNET noch brav ihren Dienst tun, besteht da für mich noch kein Grund, Hals über Kopf umzusteigen.

Trotzdem würd ich zumindest aus Interesse und Neugierde mal wissen, wie "einfach" der Umstieg wäre.

Zunächst muss ich ja den Kernel neubauen mit
Code:
# PF + ALTQ
device	pf
device	pflog
device	pfsync
options 	ALTQ
options	ALTQ_CBQ
options	ALTQ_RED
options	ALTQ_RIO
options	ALTQ_PRIQ
Darf das eigentlich mit NETGRAPH und IPFIREWALL in derselben Config stehen, ich meine mich zu erinnern, dass das zu Konflikten beim Bauen des Kernels führt.

Nun hab ich NAT bisher von ppp erledigen lassen - sollte das nun auch pf übernehmen? Und wie is dieses IPFW-Regelset am besten für PF umzusetzen:

Code:
# Enable reinjecting
${fwcmd} disable one_pass

# Upload-pipe for DSL16000
${fwcmd} pipe 1 config bw 1050Kbit/s

# High-Priority queue for ACK-Packets
${fwcmd} queue 1 config pipe 1 weight 95

# Medium-Priority queue for DNS/Gaming/SSH
${fwcmd} queue 2 config pipe 1 weight 25

# Low-Priority for the dirty rest ;)
${fwcmd} queue 3 config pipe 1 weight 15

# Anti-Spoof
${fwcmd} add 00100 deny all from any to any not antispoof in via ${natd_interface}

# Localhost-Traffic erlauben
${fwcmd} add 00200 allow ip from any to any via lo0

# Internen Traffic erlauben
${fwcmd} add 00300 allow all from any to any via ${lan_interface}

# Pakete an gesperrte Server droppen
#${fwcmd} add 00400 deny all from any to ${blocked_ips} out via ${natd_interface}

# Anti-Spoofing Regeln und Blockieren vom Pseudo-Port NULL und Port 1
${fwcmd} add 00500 deny all from 10.0.0.0/8 to any in via ${natd_interface}
${fwcmd} add 00510 deny all from 172.16.0.0/12 to any in via ${natd_interface}
${fwcmd} add 00520 deny all from 192.68.0.0/16 to any in via ${natd_interface}
${fwcmd} add 00530 deny all from 127.0.0.0/8 to any in via ${natd_interface}
${fwcmd} add 00540 deny all from 0.0.0.0/8 to any in via ${natd_interface}
${fwcmd} add 00550 deny all from 169.254.0.0/16 to any in via ${natd_interface}
${fwcmd} add 00560 deny all from 192.0.2.0/24 to any in via ${natd_interface}
${fwcmd} add 00570 deny all from 204.152.64.0/23 to any in via ${natd_interface}
${fwcmd} add 00580 deny all from 224.0.0.0/3 to any in via ${natd_interface}
${fwcmd} add 00590 deny all from any to any ${closed_ports} in via ${natd_interface}

# Wichtige ICMP Types erlauben
${fwcmd} add 00600 allow icmp from any to any via ${natd_interface} icmptype 3
${fwcmd} add 00610 allow icmp from any to any via ${natd_interface} icmptype 4
${fwcmd} add 00620 allow icmp from any to any in via ${natd_interface} icmptype 0
${fwcmd} add 00630 allow icmp from any to any in via ${natd_interface} icmptype 11
${fwcmd} add 00640 allow icmp from any to any in via ${natd_interface} icmptype 30

# Fragmentierte Pakete verwerfen
${fwcmd} add 00700 deny all from any to any via ${natd_interface} frag

# Dynamische Regeln fuer ausgehende Verbindungen anlegen
${fwcmd} add 00800 queue 1 tcp from any to any out via ${natd_interface} tcpflags ack iplen 0-80
${fwcmd} add 00810 skipto 01000 tcp from any to any out via ${natd_interface} tcpflags ack iplen 0-80
${fwcmd} add 00820 queue 2 udp from any to any out via ${natd_interface}
${fwcmd} add 00830 queue 3 not udp from any to any out via ${natd_interface}

${fwcmd} add 01000 check-state
${fwcmd} add 02000 allow tcp from any to any out via ${natd_interface} setup keep-state
${fwcmd} add 02100 allow all from any to any out via ${natd_interface} keep-state
${fwcmd} add 02200 allow all from any to any via ${natd_interface} established

# Aktive FTP-Verbindungen erlauben
${fwcmd} add 02300 allow all from any 20,21 to any in via ${natd_interface} setup keep-state

# Verbindungen zum internen FTP-Server erlauben
${fwcmd} add 02400 allow tcp from any to any ${ftp_ports} in via ${natd_interface} keep-state

# Erlaubte TCP-Dienste die ausm Internet erreicht werden duerfen
${fwcmd} add 03000 allow tcp from any to any ${open_tcp_ports} in via ${natd_interface} setup keep-state

# Erlaubte UDP-Dienste die ausm Internet erreicht werden duerfen
${fwcmd} add 03100 allow udp from any to any ${open_udp_ports} in via ${natd_interface} keep-state

# Dem Rest STEALTH-Verhalten vortaeuschen
${fwcmd} add 65500 deny all from any to any in via ${natd_interface}
Wer mit IPFW noch arbeitet, oder dabei bleiben will, darf natürlich gern auch Fragen zu meinem Regelset stellen, das läuft stateful mit DUMMYNET und Co ganz sauber, einzig beim 24h Disconnect brauchten einige Programme länger, bis sie sich neu verbunden hatten.
 
So - ich hab mich mal in pf eingelesen und mir ein entsprechendes ruleset gebaut, bin beim aktivieren aber auf erhebliche Probleme gestossen.

Ich habe den Kernel mit folgenden Optionen neu gebaut:
Code:
# PF + ALTQ
device		pf
device		pflog
options		ALTQ
options		ALTQ_CBQ         # Class Bases Queuing (CBQ)
options 	ALTQ_RED         # Random Early Detection (RED)
options 	ALTQ_RIO         # RED In/Out
options 	ALTQ_HFSC        # Hierarchical Packet Scheduler (HFSC)
options 	ALTQ_PRIQ        # Priority Queuing (PRIQ)
Dummerweise funktioniert es nicht - nach dem Booten meldet mir das System, dass der Kernel kein ALTQ-Support hätte und pfctl schmettert sämtliche Versuche mit einem "Access denied" Fehler ab. Im Endeffekt ist das System dann von jedwedem Netzverkehr isoliert und da man pf nicht einmal deaktiviert bekommt, hilft nur ein Reboot und eine Reaktivierung von ipfw :(

Weiß da jemand Rat, warum ALTQ trotz entsprechender Optionen in der Kernelconfig nicht funktioniert? Laut man-Page werden alle meine Netzwerkkarten (xl0, sis0, ral0 und tun0) von AltQ unterstützt, bzw. unterstützen diese AltQ.
 
So, da wohl viele Leute den Thread fleißig lesen, aber keiner sich imstande sieht, mal zu antworten, tu ich das einfach mal selbst.

Des Rätsels Lösung war, dass Kernel und System mit unterschiedlichen Sources gebaut waren scheinbar - hatte scheinbar vergessen, dass ich in der Zwischenzeit ein cvsup der Sources gemacht hab. Nach nem Buildworld tauchen die AltQ-Fehler zumindest nicht mehr auf.

Sooo, die Rules funktionieren nun soweit ganz gut, leider liefert "pfctl -sq" immer die Meldung "No queue in use", ich weiß leider nicht, woran das liegt :(

Hier das aktuelle Ruleset:
Code:
ext_if="tun0"
dsl_if="sis0"
int_if="xl0"
lan_net= "xxxx"
me="xxxx"
icmp_types = "echoreq"

table <firewall> const { self }
table <bad_ips> { 127.0.0.0/8, 192.168.0.0/16, 172.16.0.0/12, 10.0.0.0/8, 169.254.0.0/16 }

ports_tcp_fwd = "{ xxxx }"
ports_udp_fwd = "{ xxxx }"
ports_tcp_local = "{ xxxx }"
ports_udp_local = "{ xxxx }"

ports_ftp = "{ xxxx }"

set timeout { interval 10, frag 30 }
set timeout { tcp.first 120, tcp.opening 30, tcp.established 86400 }
set timeout { tcp.closing 900, tcp.finwait 45, tcp.closed 90 }
set timeout { udp.first 60, udp.single 30, udp.multiple 60 }
set timeout { icmp.first 20, icmp.error 10 }
set timeout { other.first 60, other.single 30, other.multiple 60 }
set timeout { adaptive.start 0, adaptive.end 0 }
set limit { states 10000, frags 5000 }
set loginterface $ext_if
#set optimization normal
set optimization aggressive
set ruleset-optimization basic
set state-policy floating
set block-policy drop
set require-order yes
set fingerprints "/etc/pf.os"

set skip on lo0

scrub in all

# Enable AltQ traffic shaping
altq on $ext_if priq bandwidth 990Kb queue { std, ssh_and_im, dns_out, tcp_ack_out }
queue std priq(default)
queue ssh_and_im priority 4 priq(red)
queue dns_out priority 5
queue tck_ack_out priority 6

#nat on $ext_if from $lan_net to any -> ($ext_if)
#rdr on $ext_if proto tcp from any to ($ext_if) port 3214 -> 192.168.0.1 port 3214

block all
#pass all

block quick inet6
block in quick on $ext_if proto tcp from any to any port 0
block in quick from urpf-failed
block in log quick on $ext_if proto tcp from any to any flags FUP/FUP
block in log quick on $ext_if proto tcp from any to any flags SF/SFRA
block in log quick on $ext_if proto tcp from any to any flags /SFRA
block in log quick on $ext_if os NMAP
block in log quick from <ssh-bruteforce> to any
block in quick on $ext_if from <bad_ips> to any
block out quick on $ext_if from any to <bad_ips>

pass quick on $int_if

pass in log quick on $ext_if proto tcp from any to ($ext_if) port 34022 keep state (max-src-conn-rate 3/30,overload <ssh-bruteforce> flush global) queue (std, ssh_im_out)
pass in quick on $ext_if proto tcp from any to $lan_net port $ports_tcp_fwd synproxy state queue(std, tcp_ack_out)
pass in quick on $ext_if proto udp from any to $lan_net port $ports_udp_fwd queue(std, tcp_ack_out)
pass in quick on $ext_if proto tcp from any to ($ext_if) port $ports_tcp_local queue(std, tcp_ack_out)
pass in quick on $ext_if proto udp from any to ($ext_if) port $ports_udp_local queue(std, tcp_ack_out)
pass in quick on $ext_if proto tcp from any to ($ext_if) port $ports_ftp queue(std, tcp_ack_out)
pass in quick on $ext_if proto tcp from any port { 20, 21 } to $lan_net queue(std, tcp_ack_out)

pass out on $ext_if proto { tcp udp icmp } all modulate state queue(std, tcp_ack_out)
pass out on $ext_if proto { tcp udp } from any to any port domain modulate state queue dns_out
pass out on $ext_if proto tcp from any to any port 22 modulate state queue(std, ssh_im_out)
pass out on $ext_if proto tcp from any to any port { 1863 5190 5223 } modulate state queue(ssh_im_out, tcp_ack_out)
#pass out on $ext_if proto { tcp udp icmp } all modulate state
 
Zuletzt bearbeitet:
Zurück
Oben