Skip to content

Commit 75a5d1e

Browse files
authored
Merge branch 'master' into speed_improvement
2 parents 7bdd451 + 9c9b4b7 commit 75a5d1e

File tree

2 files changed

+27
-32
lines changed

2 files changed

+27
-32
lines changed

iptc/ip6tc.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -416,22 +416,19 @@ def set_dst(self, dst):
416416
def get_in_interface(self):
417417
intf = ""
418418
if self.entry.ipv6.invflags & ip6t_ip6.IP6T_INV_VIA_IN:
419-
intf = "".join(["!", intf])
420-
iface = bytearray(_IFNAMSIZ)
421-
iface[:len(self.entry.ipv6.iniface)] = self.entry.ipv6.iniface
422-
mask = bytearray(_IFNAMSIZ)
423-
mask[:len(self.entry.ipv6.iniface_mask)] = self.entry.ipv6.iniface_mask
424-
if mask[0] == 0:
419+
intf = "!"
420+
421+
iface = self.entry.ipv6.iniface.decode()
422+
mask = self.entry.ipv6.iniface_mask
423+
424+
if len(mask) == 0:
425425
return None
426-
for i in range(_IFNAMSIZ):
427-
if mask[i] != 0:
428-
intf = "".join([intf, chr(iface[i])])
429-
else:
430-
if iface[i - 1] != 0:
431-
intf = "".join([intf, "+"])
432-
else:
433-
intf = intf[:-1]
434-
break
426+
427+
intf += iface
428+
if len(iface) == len(mask):
429+
intf += '+'
430+
intf = intf[:_IFNAMSIZ]
431+
435432
return intf
436433

437434
def set_in_interface(self, intf):
@@ -460,23 +457,19 @@ def set_in_interface(self, intf):
460457
def get_out_interface(self):
461458
intf = ""
462459
if self.entry.ipv6.invflags & ip6t_ip6.IP6T_INV_VIA_OUT:
463-
intf = "".join(["!", intf])
464-
iface = bytearray(_IFNAMSIZ)
465-
iface[:len(self.entry.ipv6.outiface)] = self.entry.ipv6.outiface
466-
mask = bytearray(_IFNAMSIZ)
467-
mask[:len(self.entry.ipv6.outiface_mask)] = \
468-
self.entry.ipv6.outiface_mask
469-
if mask[0] == 0:
460+
intf = "!"
461+
462+
iface = self.entry.ipv6.outiface.decode()
463+
mask = self.entry.ipv6.outiface_mask
464+
465+
if len(mask) == 0:
470466
return None
471-
for i in range(_IFNAMSIZ):
472-
if mask[i] != 0:
473-
intf = "".join([intf, chr(iface[i])])
474-
else:
475-
if iface[i - 1] != 0:
476-
intf = "".join([intf, "+"])
477-
else:
478-
intf = intf[:-1]
479-
break
467+
468+
intf += iface
469+
if len(iface) == len(mask):
470+
intf += '+'
471+
intf = intf[:_IFNAMSIZ]
472+
480473
return intf
481474

482475
def set_out_interface(self, intf):

tests/test_iptc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,9 @@ def test_rule_address(self):
423423
def test_rule_interface(self):
424424
# valid interfaces
425425
rule = iptc.Rule6()
426-
for intf in ["eth0", "eth+", "ip6tnl1", "ip6tnl+", "!ppp0", "!ppp+"]:
426+
427+
max_length_valid_interface_name = "0123456789abcde"
428+
for intf in ["eth0", "eth+", "ip6tnl1", "ip6tnl+", "!ppp0", "!ppp+", max_length_valid_interface_name]:
427429
rule.in_interface = intf
428430
self.assertEquals(intf, rule.in_interface)
429431
rule.out_interface = intf

0 commit comments

Comments
 (0)