From 282c790738a111b1ddc27b43ecb0acfab8b09024 Mon Sep 17 00:00:00 2001 From: Chris Heath Date: Mon, 17 Feb 2020 17:01:23 -0500 Subject: [PATCH 01/25] Don't set xtables_{matches,targets} to NULL. Protocol-independent extensions will be looked up once for each protocol and added to the protocol-specific cache. Fixes #282. --- iptc/xtables.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/iptc/xtables.py b/iptc/xtables.py index fafb6af..93bc080 100644 --- a/iptc/xtables.py +++ b/iptc/xtables.py @@ -1020,10 +1020,6 @@ def find_match(self, name): if ext is not None: return ext - xtables._xtables_matches.value = ct.c_void_p(None).value - if xtables._xtables_pending_matches: - xtables._xtables_pending_matches.value = ct.c_void_p(None).value - match = xtables._xtables_find_match(name, XTF_TRY_LOAD, None) if not match: self._try_register(name) @@ -1045,10 +1041,6 @@ def find_target(self, name): if ext is not None: return ext - xtables._xtables_targets.value = ct.c_void_p(None).value - if xtables._xtables_pending_targets: - xtables._xtables_pending_targets.value = ct.c_void_p(None).value - target = xtables._xtables_find_target(name, XTF_TRY_LOAD) if not target: self._try_register(name) From e3557528d7cdcdc2c579212be8837bc9b54635a4 Mon Sep 17 00:00:00 2001 From: Frank Vanbever Date: Thu, 20 Feb 2020 12:14:08 +0100 Subject: [PATCH 02/25] Add separate mechanism to load libc ctypes.util.find_library() always returns None for systems which do not have the tools installed to determine the location of a given shared library (i.e. ldconfig, gcc, objdump). If find_libary() fails attempt to load known libc by SONAME. Signed-off-by: Frank Vanbever --- iptc/ip4tc.py | 4 ++-- iptc/util.py | 16 ++++++++++++++++ iptc/xtables.py | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/iptc/ip4tc.py b/iptc/ip4tc.py index 4c5d690..4ddd2dc 100644 --- a/iptc/ip4tc.py +++ b/iptc/ip4tc.py @@ -9,7 +9,7 @@ import struct import weakref -from .util import find_library, load_kernel +from .util import find_library, load_kernel, find_libc from .xtables import (XT_INV_PROTO, NFPROTO_IPV4, XTablesError, xtables, xt_align, xt_counters, xt_entry_target, xt_entry_match) @@ -26,7 +26,7 @@ _IFNAMSIZ = 16 -_libc = ct.CDLL("libc.so.6") +_libc = find_libc() _get_errno_loc = _libc.__errno_location _get_errno_loc.restype = ct.POINTER(ct.c_int) _malloc = _libc.malloc diff --git a/iptc/util.py b/iptc/util.py index ae5fb9b..e6b1649 100644 --- a/iptc/util.py +++ b/iptc/util.py @@ -109,3 +109,19 @@ def find_library(*names): major = int(m.group(1)) return lib, major return None, None + + +def find_libc(): + lib = ctypes.util.find_library('c') + if lib is not None: + return ctypes.CDLL(lib, mode=ctypes.RTLD_GLOBAL) + + libnames = ['libc.so.6', 'libc.so.0', 'libc.so'] + for name in libnames: + try: + lib = ctypes.CDLL(name, mode=ctypes.RTLD_GLOBAL) + return lib + except: + pass + + return None diff --git a/iptc/xtables.py b/iptc/xtables.py index 93bc080..cf21029 100644 --- a/iptc/xtables.py +++ b/iptc/xtables.py @@ -6,7 +6,7 @@ import weakref from . import version -from .util import find_library +from .util import find_library, find_libc from .errors import * XT_INV_PROTO = 0x40 # invert the sense of PROTO @@ -792,7 +792,7 @@ class xtables_target(ct.Union): ("v12", _xtables_target_v12)] -_libc, _ = find_library("c") +_libc = find_libc() _optind = ct.c_long.in_dll(_libc, "optind") _optarg = ct.c_char_p.in_dll(_libc, "optarg") From 899d25c511c6ce779b7153e9ae2e41055b30b9c5 Mon Sep 17 00:00:00 2001 From: Frank Vanbever Date: Mon, 9 Mar 2020 12:36:47 +0100 Subject: [PATCH 03/25] Add '.so' as additional shared object suffix EXT_SUFFIX includes a platform information tag starting from Python 3.5 [0] For example: >>> sysconfig.get_config_var("EXT_SUFFIX") '.cpython-38-aarch64-linux-gnu.so' This suffix only applies to cpython extensions i.e. not to the iptables shared objects. Adding '.so' as an additional suffix for shared objects fixes the issue. Fixes: Issue #301 Signed-off-by: Frank Vanbever [0]: https://docs.python.org/3/whatsnew/3.5.html#build-and-c-api-changes --- iptc/util.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/iptc/util.py b/iptc/util.py index e6b1649..04fe905 100644 --- a/iptc/util.py +++ b/iptc/util.py @@ -80,12 +80,19 @@ def _do_find_library(name): def _find_library(*names): + exts = [] if version_info >= (3, 3): - ext = get_config_var("EXT_SUFFIX") + exts.append(get_config_var("EXT_SUFFIX")) else: - ext = get_config_var('SO') + exts.append(get_config_var('SO')) + + if version_info >= (3, 5): + exts.append('.so') + for name in names: - libnames = [name, "lib" + name, name + ext, "lib" + name + ext] + libnames = [name, "lib" + name] + for ext in exts: + libnames += [name + ext, "lib" + name + ext] libdir = os.environ.get('IPTABLES_LIBDIR', None) if libdir is not None: libdirs = libdir.split(':') From 30cd7ce19d0eb8e8d96ad3b03a9073e80b98bdd0 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 14 Jun 2020 14:10:22 -0700 Subject: [PATCH 04/25] Release v1.0.0 --- iptc/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptc/version.py b/iptc/version.py index 1ded765..2657151 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "0.15.0-dev" +__version__ = "1.0.0" From 34e5cf653aa107a0a2279936dd3f6850bb3ed0bb Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 14 Jun 2020 14:34:50 -0700 Subject: [PATCH 05/25] Start v1.0.1-dev --- iptc/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptc/version.py b/iptc/version.py index 2657151..13c18f6 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "1.0.0" +__version__ = "1.0.1-dev" From 542efdb739b4e3ef6f28274d23b506bf0027eec2 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 14 Jun 2020 14:39:01 -0700 Subject: [PATCH 06/25] Fix README.md permissions --- README.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 README.md diff --git a/README.md b/README.md old mode 100755 new mode 100644 From 8e68d16969632d629fa42a1fafc0bf2edc84e678 Mon Sep 17 00:00:00 2001 From: AZaugg Date: Thu, 13 Oct 2022 10:20:46 -0700 Subject: [PATCH 07/25] Changed regex used to ind xtables libs Updated the regular expression for ldconfig versions packaged in glibc2.28 and greater Closes #329 --- iptc/xtables.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptc/xtables.py b/iptc/xtables.py index cf21029..024779c 100644 --- a/iptc/xtables.py +++ b/iptc/xtables.py @@ -805,7 +805,7 @@ class xtables_target(ct.Union): _xtables_libdir = os.getenv("XTABLES_LIBDIR") if _xtables_libdir is None: import re - ldconfig_path_regex = re.compile('^(/.*):$') + ldconfig_path_regex = re.compile('^(/.*):($| \(.*\)$)') import subprocess ldconfig = subprocess.Popen( ('/sbin/ldconfig', '-N', '-v'), From f51bd140a7864533e286aefed0aa0c7316243015 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sat, 21 Jan 2023 18:42:37 -0800 Subject: [PATCH 08/25] Add GHA workflow --- .github/workflows/build.yaml | 32 ++++++++++++++++++++++++++++++++ .travis.yml | 16 ---------------- 2 files changed, 32 insertions(+), 16 deletions(-) create mode 100644 .github/workflows/build.yaml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml new file mode 100644 index 0000000..bedecd5 --- /dev/null +++ b/.github/workflows/build.yaml @@ -0,0 +1,32 @@ +name: Build & Test +on: + push: + branches: + - main + pull_request: +jobs: + build-and-test: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: + - "3.7" + - "3.8" + - "3.9" + - "3.10" + - "3.11" + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + - name: Build package + run: python setup.py build + - name: Install package + run: python setup.py install + - name: Install coveralls + run: sudo pip install coveralls + - name: Run tests + run: sudo PATH=$PATH coverage run setup.py test diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index e7f9a8c..0000000 --- a/.travis.yml +++ /dev/null @@ -1,16 +0,0 @@ -dist: xenial -language: python -python: - - "2.7" - - "3.4" - - "3.5" - - "3.6" - - "3.7" -install: - - python setup.py build - - python setup.py install - - sudo pip install coveralls -script: - - sudo PATH=$PATH coverage run setup.py test -after_success: - coveralls From 479b09d765988dfa52503f23bd035eb30ea6ee9c Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sat, 21 Jan 2023 16:36:06 -0800 Subject: [PATCH 09/25] Release v1.0.1 --- iptc/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptc/version.py b/iptc/version.py index 13c18f6..80ed889 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "1.0.1-dev" +__version__ = "1.0.1" From bea578318f596c94a8a263867985130068e1fd10 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 10:58:05 -0800 Subject: [PATCH 10/25] Update languages in setup.py --- setup.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/setup.py b/setup.py index 145f0c3..efefa07 100644 --- a/setup.py +++ b/setup.py @@ -38,10 +38,7 @@ "Topic :: System :: Networking :: Firewalls", "Topic :: System :: Systems Administration", "Programming Language :: Python :: 2", - "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.3", - "Programming Language :: Python :: 3.4", "Programming Language :: Python :: Implementation :: CPython", ], license="Apache License, Version 2.0", From 9bc14a02c1e6d21aa5f4cf1757154c22b5644857 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 11:39:49 -0800 Subject: [PATCH 11/25] Automate releases --- .github/workflows/build.yaml | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index bedecd5..c3b8396 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -3,6 +3,8 @@ on: push: branches: - main + tags: + - "v*" pull_request: jobs: build-and-test: @@ -23,10 +25,38 @@ jobs: with: python-version: ${{ matrix.python-version }} - name: Build package - run: python setup.py build - - name: Install package - run: python setup.py install + run: | + python -m pip install --upgrade build twine + python -m build + twine check --strict dist/* - name: Install coveralls run: sudo pip install coveralls - name: Run tests run: sudo PATH=$PATH coverage run setup.py test + + release: + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') + needs: + - build-and-test (3.7) + - build-and-test (3.8) + - build-and-test (3.9) + - build-and-test (3.10) + - build-and-test (3.11) + steps: + - name: Check out code + uses: actions/checkout@v2 + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: "3.x" + - name: Build package + run: | + python -m pip install --upgrade build twine + python -m build + twine check --strict dist/* + - name: Publish package + uses: pypa/gh-action-pypi-publish@release/v1 + with: + user: __token__ + password: ${{ secrets.PYPI_API_TOKEN }} From 5ea087f886bd74e85664d97fc4b4b79d833dc840 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 11:40:01 -0800 Subject: [PATCH 12/25] Add missing fields to setup.py --- setup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/setup.py b/setup.py index efefa07..c3e4a46 100644 --- a/setup.py +++ b/setup.py @@ -15,6 +15,8 @@ name=__pkgname__, version=__version__, description="Python bindings for iptables", + long_description="Python bindings for classic iptables", + long_description_content_type="text/x-rst", author="Vilmos Nebehaj", author_email="v.nebehaj@gmail.com", url="https://github.com/ldx/python-iptables", From d6f0faf52f2267510996db9575106a83ac34c287 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 11:42:07 -0800 Subject: [PATCH 13/25] Fix dependency --- .github/workflows/build.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index c3b8396..b530f88 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -38,11 +38,7 @@ jobs: runs-on: ubuntu-latest if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') needs: - - build-and-test (3.7) - - build-and-test (3.8) - - build-and-test (3.9) - - build-and-test (3.10) - - build-and-test (3.11) + - build-and-test steps: - name: Check out code uses: actions/checkout@v2 From 158a82a31b95d6421c12e4ae9328febd8ed7ffb9 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 11:48:15 -0800 Subject: [PATCH 14/25] Upload release to GitHub --- .github/workflows/build.yaml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index b530f88..2efe8e8 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -56,3 +56,28 @@ jobs: with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} + - name: Create GitHub release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false + - name: Set asset name + run: | + export PKG=$(ls dist/ | grep tar) + set -- $PKG + echo "name=$1" >> $GITHUB_ENV + - name: Upload release asset to GitHub + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/${{ env.name }} + asset_name: ${{ env.name }} + asset_content_type: application/zip From bb2b43b77016bb09bf1f11524a0779bdbdbe5a8e Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 11:53:12 -0800 Subject: [PATCH 15/25] Fix indentation --- .github/workflows/build.yaml | 50 ++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2efe8e8..2003385 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -56,28 +56,28 @@ jobs: with: user: __token__ password: ${{ secrets.PYPI_API_TOKEN }} - - name: Create GitHub release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: ${{ github.ref }} - draft: false - prerelease: false - - name: Set asset name - run: | - export PKG=$(ls dist/ | grep tar) - set -- $PKG - echo "name=$1" >> $GITHUB_ENV - - name: Upload release asset to GitHub - id: upload-release-asset - uses: actions/upload-release-asset@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: dist/${{ env.name }} - asset_name: ${{ env.name }} - asset_content_type: application/zip + - name: Create GitHub release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ github.ref }} + draft: false + prerelease: false + - name: Set asset name + run: | + export PKG=$(ls dist/ | grep tar) + set -- $PKG + echo "name=$1" >> $GITHUB_ENV + - name: Upload release asset to GitHub + id: upload-release-asset + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: dist/${{ env.name }} + asset_name: ${{ env.name }} + asset_content_type: application/zip From 3b0d79c6bf7f54cca36f1ddd39d3374f8542d223 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 12:50:31 -0800 Subject: [PATCH 16/25] Fix upload --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2003385..561a473 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -51,6 +51,7 @@ jobs: python -m pip install --upgrade build twine python -m build twine check --strict dist/* + rm -f dist/*.whl - name: Publish package uses: pypa/gh-action-pypi-publish@release/v1 with: From 2cd09a36f3db37d4e5fa9112dc2e2092a0560966 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 22 Jan 2023 12:57:45 -0800 Subject: [PATCH 17/25] Start v1.0.2-dev --- iptc/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptc/version.py b/iptc/version.py index 80ed889..8a2f162 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "1.0.1" +__version__ = "1.0.2-dev" From af932f847f411f9765034a34e2ec33e839f3df61 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Wed, 19 Feb 2025 09:11:02 +0530 Subject: [PATCH 18/25] Trigger build --- .github/workflows/build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 561a473..fe95d83 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -6,6 +6,7 @@ on: tags: - "v*" pull_request: + jobs: build-and-test: runs-on: ubuntu-latest From eb0fb688527cce2db0222552f1a6ae9dbd6da5e0 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Wed, 19 Feb 2025 09:14:10 +0530 Subject: [PATCH 19/25] Update actions --- .github/workflows/build.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index fe95d83..3c4fe42 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -20,9 +20,9 @@ jobs: - "3.11" steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} - name: Build package @@ -42,9 +42,9 @@ jobs: - build-and-test steps: - name: Check out code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Set up Python - uses: actions/setup-python@v2 + uses: actions/setup-python@v5 with: python-version: "3.x" - name: Build package From 4fffc0ee73273e70dff138fd76c767ff6b5d24a1 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Wed, 19 Feb 2025 09:17:30 +0530 Subject: [PATCH 20/25] Use earlier image --- .github/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 3c4fe42..efc2167 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -9,7 +9,7 @@ on: jobs: build-and-test: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 strategy: matrix: python-version: @@ -36,7 +36,7 @@ jobs: run: sudo PATH=$PATH coverage run setup.py test release: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') needs: - build-and-test From d9a70d478d118ddef8cc3ff84c4febc9a0e4e884 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 20 Feb 2025 03:49:04 +0000 Subject: [PATCH 21/25] Port to Sphinx 8.0 (#349) The old `intersphinx_mapping` format has been removed; it must now map identifiers to (target, inventory) tuples. --- doc/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/conf.py b/doc/conf.py index 6abeedf..ea780c0 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -196,6 +196,6 @@ # Example configuration for intersphinx: refer to the Python standard library. -intersphinx_mapping = {'http://docs.python.org/': None} +intersphinx_mapping = {'python': ('http://docs.python.org/', None)} autoclass_content="both" From 794aace1fc7b38756ba53c83e4c19a96f81c3763 Mon Sep 17 00:00:00 2001 From: Jeremiah Millay <5504449+floatingstatic@users.noreply.github.com> Date: Wed, 19 Feb 2025 22:51:09 -0500 Subject: [PATCH 22/25] Make python-iptables compatible with python 3.12 (#351) --- iptc/util.py | 7 ++++++- iptc/version.py | 2 +- setup.py | 1 - 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/iptc/util.py b/iptc/util.py index 04fe905..6c1592c 100644 --- a/iptc/util.py +++ b/iptc/util.py @@ -3,7 +3,6 @@ import sys import ctypes import ctypes.util -from distutils.sysconfig import get_python_lib from itertools import product from subprocess import Popen, PIPE from sys import version_info @@ -14,6 +13,12 @@ def get_config_var(name): if name == 'SO': return '.so' raise Exception('Not implemented') +try: + from distutils.sysconfig import get_python_lib +except ModuleNotFoundError: + import sysconfig + def get_python_lib(): + return sysconfig.get_path("purelib") def _insert_ko(modprobe, modname): diff --git a/iptc/version.py b/iptc/version.py index 8a2f162..e67fbc7 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "1.0.2-dev" +__version__ = "1.1.0" diff --git a/setup.py b/setup.py index c3e4a46..1929f93 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,6 @@ """python-iptables setup script""" from setuptools import setup, Extension -#from distutils.core import setup, Extension # make pyflakes happy __pkgname__ = None From 9c9b4b7b6b042e475f1c58f8bd2e939dfea3b410 Mon Sep 17 00:00:00 2001 From: Or Yaacov <48175064+oryaacov@users.noreply.github.com> Date: Tue, 4 Mar 2025 09:59:22 -0800 Subject: [PATCH 23/25] fix(ip6tc): ipv6 interface name with 15 chars is too big (#348) * fix(ip6tc): ipv6 interface name with 15 chars is too big * feat(tests): add case for max valid length network interface name --- iptc/ip6tc.py | 55 ++++++++++++++++++++-------------------------- tests/test_iptc.py | 4 +++- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/iptc/ip6tc.py b/iptc/ip6tc.py index ed10e17..ea4a1d7 100644 --- a/iptc/ip6tc.py +++ b/iptc/ip6tc.py @@ -412,22 +412,19 @@ def set_dst(self, dst): def get_in_interface(self): intf = "" if self.entry.ipv6.invflags & ip6t_ip6.IP6T_INV_VIA_IN: - intf = "".join(["!", intf]) - iface = bytearray(_IFNAMSIZ) - iface[:len(self.entry.ipv6.iniface)] = self.entry.ipv6.iniface - mask = bytearray(_IFNAMSIZ) - mask[:len(self.entry.ipv6.iniface_mask)] = self.entry.ipv6.iniface_mask - if mask[0] == 0: + intf = "!" + + iface = self.entry.ipv6.iniface.decode() + mask = self.entry.ipv6.iniface_mask + + if len(mask) == 0: return None - for i in range(_IFNAMSIZ): - if mask[i] != 0: - intf = "".join([intf, chr(iface[i])]) - else: - if iface[i - 1] != 0: - intf = "".join([intf, "+"]) - else: - intf = intf[:-1] - break + + intf += iface + if len(iface) == len(mask): + intf += '+' + intf = intf[:_IFNAMSIZ] + return intf def set_in_interface(self, intf): @@ -456,23 +453,19 @@ def set_in_interface(self, intf): def get_out_interface(self): intf = "" if self.entry.ipv6.invflags & ip6t_ip6.IP6T_INV_VIA_OUT: - intf = "".join(["!", intf]) - iface = bytearray(_IFNAMSIZ) - iface[:len(self.entry.ipv6.outiface)] = self.entry.ipv6.outiface - mask = bytearray(_IFNAMSIZ) - mask[:len(self.entry.ipv6.outiface_mask)] = \ - self.entry.ipv6.outiface_mask - if mask[0] == 0: + intf = "!" + + iface = self.entry.ipv6.outiface.decode() + mask = self.entry.ipv6.outiface_mask + + if len(mask) == 0: return None - for i in range(_IFNAMSIZ): - if mask[i] != 0: - intf = "".join([intf, chr(iface[i])]) - else: - if iface[i - 1] != 0: - intf = "".join([intf, "+"]) - else: - intf = intf[:-1] - break + + intf += iface + if len(iface) == len(mask): + intf += '+' + intf = intf[:_IFNAMSIZ] + return intf def set_out_interface(self, intf): diff --git a/tests/test_iptc.py b/tests/test_iptc.py index d630c87..816df86 100755 --- a/tests/test_iptc.py +++ b/tests/test_iptc.py @@ -423,7 +423,9 @@ def test_rule_address(self): def test_rule_interface(self): # valid interfaces rule = iptc.Rule6() - for intf in ["eth0", "eth+", "ip6tnl1", "ip6tnl+", "!ppp0", "!ppp+"]: + + max_length_valid_interface_name = "0123456789abcde" + for intf in ["eth0", "eth+", "ip6tnl1", "ip6tnl+", "!ppp0", "!ppp+", max_length_valid_interface_name]: rule.in_interface = intf self.assertEquals(intf, rule.in_interface) rule.out_interface = intf From c2d0e67abeef7dceec0a1891566dcde79889e048 Mon Sep 17 00:00:00 2001 From: jkklemm Date: Sun, 6 Apr 2025 23:26:56 +0200 Subject: [PATCH 24/25] Speed up code for arm architecture when creating new rules (#341) * speed up code for arm architecture when creating new rules * moved dict to static class variable --- iptc/ip4tc.py | 13 +++++++++++++ iptc/ip6tc.py | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/iptc/ip4tc.py b/iptc/ip4tc.py index 4ddd2dc..90f5ee7 100644 --- a/iptc/ip4tc.py +++ b/iptc/ip4tc.py @@ -42,10 +42,14 @@ def is_table_available(name): try: + if name in Table.existing_table_names: + return Table.existing_table_names[name] Table(name) + Table.existing_table_names[name] = True return True except IPTCError: pass + Table.existing_table_names[name] = False return False @@ -669,6 +673,11 @@ class Target(IPTCModule): does not take any value in the iptables extension, an empty string i.e. "" should be used. """ + + STANDARD_TARGETS = ["", "ACCEPT", "DROP", "REJECT", "RETURN", "REDIRECT", "SNAT", "DNAT", \ + "MASQUERADE", "MIRROR", "TOS", "MARK", "QUEUE", "LOG"] + """This is the constant for all standard targets.""" + def __init__(self, rule, name=None, target=None, revision=None, goto=None): """ *rule* is the Rule object this match belongs to; it can be changed @@ -784,6 +793,8 @@ def _create_buffer(self, target): self.reset() def _is_standard_target(self): + if self._name in Target.STANDARD_TARGETS: + return False for t in self._rule.tables: if t.is_chain(self._name): return True @@ -1572,6 +1583,8 @@ class Table(object): """This is the constant for all tables.""" _cache = dict() + existing_table_names = dict() + """Dictionary to check faster if a table is available.""" def __new__(cls, name, autocommit=None): obj = Table._cache.get(name, None) diff --git a/iptc/ip6tc.py b/iptc/ip6tc.py index ea4a1d7..e0d8787 100644 --- a/iptc/ip6tc.py +++ b/iptc/ip6tc.py @@ -19,10 +19,14 @@ def is_table6_available(name): try: + if name in Table6.existing_table_names: + return Table6.existing_table_names[name] Table6(name) + Table6.existing_table_names[name] = True return True except IPTCError: pass + Table6.existing_table_names[name] = False return False @@ -572,6 +576,8 @@ class Table6(Table): """This is the constant for all tables.""" _cache = dict() + existing_table_names = dict() + """Dictionary to check faster if a table is available.""" def __new__(cls, name, autocommit=None): obj = Table6._cache.get(name, None) From 2703efb3063f4b62282722f85a1a7f584d9d64c1 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Sun, 6 Apr 2025 15:11:08 -0700 Subject: [PATCH 25/25] Bump version to v1.2.0 (#355) --- iptc/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iptc/version.py b/iptc/version.py index e67fbc7..f6a5157 100644 --- a/iptc/version.py +++ b/iptc/version.py @@ -1,4 +1,4 @@ # -*- coding: utf-8 -*- __pkgname__ = "python-iptables" -__version__ = "1.1.0" +__version__ = "1.2.0"