From af932f847f411f9765034a34e2ec33e839f3df61 Mon Sep 17 00:00:00 2001 From: Vilmos Nebehaj Date: Wed, 19 Feb 2025 09:11:02 +0530 Subject: [PATCH 1/8] 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 2/8] 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 3/8] 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 4/8] 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 5/8] 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 6/8] 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 7/8] 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 8/8] 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"