Merge pull request #300 from zbrdge/freebsd-platform

Freebsd 10 platform
This commit is contained in:
Maximilian Hils 2014-07-03 02:24:00 +02:00
commit b0c366aa45
5 changed files with 25 additions and 6 deletions

View File

@ -7,3 +7,6 @@ if sys.platform == "linux2":
elif sys.platform == "darwin":
import osx
resolver = osx.Resolver
elif sys.platform == "freebsd10":
import osx
resolver = osx.Resolver

View File

@ -7,6 +7,10 @@ import pf
structures returned, and compiling userspace tools to test and work with
this turns out to be a pain in the ass. Parsing pfctl output is short,
simple, and works.
Note: Also Tested with FreeBSD 10 pkgng Python 2.7.x.
Should work almost exactly as on Mac OS X and except with some changes to
the output processing of pfctl (see pf.py).
"""
class Resolver:

View File

@ -1,3 +1,4 @@
import sys
def lookup(address, port, s):
"""
@ -11,6 +12,11 @@ def lookup(address, port, s):
if "ESTABLISHED:ESTABLISHED" in i and spec in i:
s = i.split()
if len(s) > 4:
s = s[4].split(":")
if sys.platform == "freebsd10":
# strip parentheses for FreeBSD pfctl
s = s[3][1:-1].split(":")
else:
s = s[4].split(":")
if len(s) == 2:
return s[0], int(s[1])

4
test/data/pf02 Normal file
View File

@ -0,0 +1,4 @@
No ALTQ support in kernel
ALTQ related functions disabled
all tcp 127.0.0.1:8080 (5.5.5.6:80) <- 192.168.1.111:40001 FIN_WAIT_2:FIN_WAIT_2
all tcp 127.0.0.1:8080 (5.5.5.5:80) <- 192.168.1.111:40000 ESTABLISHED:ESTABLISHED

View File

@ -1,13 +1,15 @@
import tutils
import tutils, sys
from libmproxy.platform import pf
class TestLookup:
def test_simple(self):
p = tutils.test_data.path("data/pf01")
d = open(p,"rb").read()
if sys.platform == "freebsd10":
p = tutils.test_data.path("data/pf02")
d = open(p,"rb").read()
else:
p = tutils.test_data.path("data/pf01")
d = open(p,"rb").read()
assert pf.lookup("192.168.1.111", 40000, d) == ("5.5.5.5", 80)
assert not pf.lookup("192.168.1.112", 40000, d)
assert not pf.lookup("192.168.1.111", 40001, d)