Commit e4b5ab67 authored by Olav Morken's avatar Olav Morken

fwb-sync: Fix incompatibility with ipaddress module

The ipaddress-module expects either a unicode string or a bytes
object. This patch updates fwb-sync to convert all addresses to
unicode strings before passing them to ipaddress.

This patch fixes the following error:

> ipaddress.AddressValueError: '158.38.0.168' (len 12 != 4) is not
> permitted as an IPv4 address. Did you pass in a bytes (str in
> Python 2) instead of a unicode object?
parent 56cd56f1
......@@ -82,7 +82,7 @@ def fwb_entries(objectgroup):
address = addr.get('address')
name = addr.get('name')
ref = 'fwb:' + addr.get('id')
cidr = ipaddress.IPv4Network(address).with_prefixlen
cidr = ipaddress.IPv4Network(unicode(address, 'ascii')).with_prefixlen
entries[ref] = {
'cidr': cidr,
'comment': name,
......@@ -92,7 +92,7 @@ def fwb_entries(objectgroup):
address = addr.get('address')
name = addr.get('name')
ref = 'fwb:' + addr.get('id')
cidr = ipaddress.IPv6Network(address).with_prefixlen
cidr = ipaddress.IPv6Network(unicode(address, 'ascii')).with_prefixlen
entries[ref] = {
'cidr': cidr,
'comment': name,
......@@ -103,7 +103,7 @@ def fwb_entries(objectgroup):
ref = 'fwb:' + referred.get('id')
address = referred.get('address')
netmask = referred.get('netmask')
cidr = ipaddress.IPv4Network('{}/{}'.format(address, netmask), False).with_prefixlen
cidr = ipaddress.IPv4Network(unicode('{}/{}'.format(address, netmask), 'ascii'), False).with_prefixlen
entries[ref] = {
'cidr': cidr,
'comment': name,
......@@ -115,7 +115,7 @@ def fwb_entries(objectgroup):
address = referred.get('address')
netmask = referred.get('netmask')
try:
cidr = ipaddress.IPv6Network('{}/{}'.format(address, netmask), False).with_prefixlen
cidr = ipaddress.IPv6Network(unicode('{}/{}'.format(address, netmask), 'ascii'), False).with_prefixlen
entries[ref] = {
'cidr': cidr,
'comment': name,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment