Skip to content

Commit c3b6a9f

Browse files
author
ldx
committed
Accept parameter values with whitespace.
E.g. the tcp match extension uses --tcp-flags in this way: # iptables -I INPUT -p 23 -m tcp --tcp-flags ACK SYN -j REJECT Parameters like this need to be passed quoted in python-iptables: >>> rule.create_match("tcp") >>> match.tcp_flags = "\"ACK SYN\""
1 parent ecb8d47 commit c3b6a9f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

iptc/ip4tc.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import os
44
import re
55
import ctypes as ct
6+
import shlex
67
import socket
78
import struct
89
import weakref
@@ -258,9 +259,14 @@ def parse(self, parameter, value):
258259
else:
259260
inv = ct.c_int(0)
260261

261-
argv = (ct.c_char_p * 2)()
262+
args = shlex.split(value)
263+
if not args:
264+
args = [value]
265+
N = len(args)
266+
argv = (ct.c_char_p * (N + 1))()
262267
argv[0] = parameter
263-
argv[1] = value
268+
for i in xrange(N):
269+
argv[i + 1] = args[i]
264270

265271
entry = self._rule.entry and ct.pointer(self._rule.entry) or None
266272

0 commit comments

Comments
 (0)