Daniel Hartmeier 在 usenix 2002 發表過名為 「Design and Performance of the OpenBSD Stateful Packet Filter (pf)」 的文章:

http://www.benzedrine.cx/pf-paper.html


在 stateless filtering 測試中,iptables 表現最好,而 pf 和 ipfilter 差不多(pf 稍好一些)。這是因為:

"Both pf and IPFilter evaluate the rule set twice for each packet, once incoming on the first interface and once outgoing on the second interface. Iptables' performance advantage is due to the fact that it evaluates the rule set only once by using a forwarding chain. The forwarding chain evaluates the rules set based on a packet's complete path through the machine."
對於每個資料封包,pf 和 ipfilter 都做兩次過濾規則的評估,一次是資料封包進入第一個網卡時,一次是數據包離開第二個網路卡時。iptables 的優勢在於它使用 forwarding chain 對過濾規則只做一次評估。這個 forwarding chain 是基於資料封包通過機器的完整路徑來進行規則評估的。

在 stateful filtering 測試中,pf 比 ipfilter 表現要好,而 iptables 沒有用來做測試,原因是:


"Iptables has not been included in this benchmark because it does not do stateful filtering comparable to pf and IPFilter. The version of iptables that we tested employs connection tracking without any sequence number analysis for packets outside of the initial TCP handshake. While this is unsurprisingly faster, it would be an unfair performance comparison."
這個測試中沒有包括 iptables,因為它並不對資料封包進行與 pf 和 ipfilter 可以相比較的 stateful 過濾。我們測試的 iptables 的版本在做 connection tracking 時,除了最初的 TCP handshake 以外,並不對資料封包做序號分析。這樣當然會快得多,但這樣的性能比較是不公平的。

最後的結論是:對 stateless rules 來說,iptables 表現最好;而對 stateful rules 來說 pf 表現最好

stateful packet filter
stateful packet filter 比一般的 packet filter 多了一個記憶體用來記錄連線狀態。什麼是連線狀態?當外界來了一串ack封包,目標欄位是我們區網內的位址,來源埠是80,一般packet filter只能允許通過,擋掉source port 80 的話大概內部網路都不能看網頁了;問題在於內部網路一開始並沒有網頁請求,哪裡來的ack? 這是外部 port scan 的花招。如果是 stateful packet filter 的話就擋下來了,因為在它的記錄裡,內部網路沒有http request,所以不可能會有ack,這就是 stateful。


Reference:

http://www.tw.openbsd.org/faq/pf/filter.html
Netfilter and iptables: Stateful firewalling for Linux
http://home.kimo.com.tw/neurogliaa/firewall.html
防火牆概要

arrow
arrow
    全站熱搜

    Bluelove1968 發表在 痞客邦 留言(0) 人氣()