From 8686edcafc887d6b780a5e810282e132e77a44da Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Fri, 8 Jul 2011 14:14:08 -0400 Subject: [PATCH 1/5] Add a proper version to the code. Signed-off-by: Chris Lalancette --- iptc/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptc/version.py b/iptc/version.py index f52b723..2f3175c 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "0.0.0" +__version__ = "0.1.0" From 8f987d93b91cfc2b79d31d42ddcfbfb0e2a05de4 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Sun, 10 Jul 2011 19:58:31 -0400 Subject: [PATCH 2/5] Switch to using an Extension. Signed-off-by: Chris Lalancette --- setup.py | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/setup.py b/setup.py index acafc04..0c5255c 100644 --- a/setup.py +++ b/setup.py @@ -3,23 +3,10 @@ """python-iptables setup script""" import os -from distutils import ccompiler -from distutils.core import setup +from distutils.core import setup, Extension execfile("iptc/version.py") -# libxtwrapper sources -LIBDIR="libxtwrapper" -csources = [os.path.join(LIBDIR, src) - for src in os.listdir("libxtwrapper") if src.endswith(".c")] - -# compile and link libxtwrapper as a shared library -compiler = ccompiler.new_compiler(compiler="unix") -objs = compiler.compile(csources, extra_preargs=["-fPIC"]) -compiler.link_shared_lib(objs, "xtwrapper", output_dir=LIBDIR) -lib = [os.path.join(LIBDIR, - compiler.library_filename("xtwrapper", lib_type="shared"))] - # build/install python-iptables setup( name = __pkgname__, @@ -30,7 +17,7 @@ url = "http://nilvec.com/", packages = ["iptc"], package_dir = {"iptc" : "iptc"}, - data_files = [("lib", lib)], + ext_modules = [Extension("libxtwrapper", ["libxtwrapper/wrapper.c"])], classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", From a2684a7cac1dbea7a16d918b53f639300cd98e4c Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Sun, 10 Jul 2011 20:04:49 -0400 Subject: [PATCH 3/5] Be more dynamic in the location of libraries. First, look for the xtables, iptc, and c libraries in the standard locations so we don't have hard-coded versions. Second, because we switched to an extension, the libxtwrapper code is probably in different places on different architectures (/usr/lib/python2.7 in i386, /usr/lib64/python2.7 in x86_64). Therefore, use the python arch sitelib to locate the library. Signed-off-by: Chris Lalancette --- iptc/__init__.py | 8 +++++--- iptc/xtables.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/iptc/__init__.py b/iptc/__init__.py index 5be98ef..fd7d2df 100644 --- a/iptc/__init__.py +++ b/iptc/__init__.py @@ -13,6 +13,7 @@ import socket import struct import weakref +import ctypes.util from xtables import XT_INV_PROTO, NFPROTO_IPV4, XTF_TRY_LOAD, XTablesError, xtables, xtables_globals, xt_align, xt_counters, xt_entry_target, xt_entry_match @@ -76,7 +77,7 @@ class ipt_entry_match(xt_entry_match): ipt_align = xt_align -_libiptc = ct.CDLL("libiptc.so.0", use_errno = True) +_libiptc = ct.CDLL(ctypes.util.find_library("iptc"), use_errno = True) class iptc(object): """This class contains all libiptc API calls.""" @@ -229,11 +230,12 @@ class IPTCError(Exception): executing an iptables operation. """ -_libc = ct.CDLL("libc.so.6") +_libc = ct.CDLL(ctypes.util.find_library("c")) _optind = ct.c_long.in_dll(_libc, "optind") _optarg = ct.c_char_p.in_dll(_libc, "optarg") -_lib_xtwrapper = ct.CDLL('libxtwrapper.so') +from distutils.sysconfig import get_python_lib +_lib_xtwrapper = ct.CDLL(get_python_lib(1) + '/libxtwrapper.so') #_lib_xtwrapper.use_errno = True _wrap_parse = _lib_xtwrapper.wrap_parse _wrap_save = _lib_xtwrapper.wrap_save diff --git a/iptc/xtables.py b/iptc/xtables.py index 2201003..ad5e1ba 100644 --- a/iptc/xtables.py +++ b/iptc/xtables.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- import ctypes as ct +import ctypes.util import version XT_INV_PROTO = 0x40 # Invert the sense of PROTO @@ -144,10 +145,11 @@ class xtables_target(ct.Structure): class XTablesError(Exception): """Raised when an xtables call fails for some reason.""" -_lib_xtables = ct.CDLL('libxtables.so.2', mode=ct.RTLD_GLOBAL) +_lib_xtables = ct.CDLL(ctypes.util.find_library("xtables"), mode=ct.RTLD_GLOBAL) -_lib_xtwrapper = ct.CDLL('libxtwrapper.so') -_throw = _lib_xtwrapper.throw_exception +from distutils.sysconfig import get_python_lib +_lib_xtwrapper = ct.CDLL(get_python_lib(1) + '/libxtwrapper.so') +throw = _lib_xtwrapper.throw_exception def xt_exit(status, *args): _throw(status) From 84032924617e79b748f826657315043e26b913e5 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Sun, 10 Jul 2011 21:12:11 -0400 Subject: [PATCH 4/5] Add a key for "all" to the protocols table. Signed-off-by: Chris Lalancette --- iptc/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iptc/__init__.py b/iptc/__init__.py index fd7d2df..3bb0a96 100644 --- a/iptc/__init__.py +++ b/iptc/__init__.py @@ -605,7 +605,8 @@ class Rule(object): * One target. This determines what happens with the packet if it is matched. """ - protocols = { socket.IPPROTO_TCP: "tcp", + protocols = { 0: "all", + socket.IPPROTO_TCP: "tcp", socket.IPPROTO_UDP: "udp", socket.IPPROTO_ICMP: "icmp", socket.IPPROTO_ESP: "esp", From 91825a5cc476dffcf47daef765f9402fbee3feb8 Mon Sep 17 00:00:00 2001 From: Chris Lalancette Date: Wed, 27 Jul 2011 05:06:54 -0400 Subject: [PATCH 5/5] Add a manifest. Signed-off-by: Chris Lalancette --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..10ff4e4 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include doc/* iptc/* libxtwrapper/* NOTICE README setup.py test.py