mirror of
https://github.com/CumulusNetworks/ifupdown2.git
synced 2024-05-06 15:54:50 +00:00
python3: ipaddress is now part of the standard library (removing python-ipaddr)
IPNetwork doesn't exists anymore and is replaced by ip_network. IPv?Network (4 and 6) objects take an optional argument "strict" that defaults to True. If strict is set and the ip address has the host bit set it will raise an exception. This is bad for ifupdown2, so we need to replace all calls to IPNetwork and IPv?Network with function who will set strict to False. That way we can limit the number of changes for this patch. Signed-off-by: Julien Fortin <julien@cumulusnetworks.com>
This commit is contained in:
2
debian/control
vendored
2
debian/control
vendored
@@ -17,7 +17,7 @@ Architecture: all
|
|||||||
Provides: ifupdown
|
Provides: ifupdown
|
||||||
Conflicts: ifupdown
|
Conflicts: ifupdown
|
||||||
Replaces: ifupdown
|
Replaces: ifupdown
|
||||||
Depends: ${python:Depends}, ${misc:Depends}, iproute2, python-argcomplete, python-ipaddr
|
Depends: ${python:Depends}, ${misc:Depends}, iproute2, python3-argcomplete
|
||||||
Suggests: isc-dhcp-client, bridge-utils, ethtool, python-gvgen, python-mako
|
Suggests: isc-dhcp-client, bridge-utils, ethtool, python-gvgen, python-mako
|
||||||
Description: Network Interface Management tool similar to ifupdown
|
Description: Network Interface Management tool similar to ifupdown
|
||||||
ifupdown2 is ifupdown re-written in Python. It replaces ifupdown and provides
|
ifupdown2 is ifupdown re-written in Python. It replaces ifupdown and provides
|
||||||
|
@@ -6,7 +6,12 @@
|
|||||||
|
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from ipaddr import IPNetwork, IPv4Network, IPv6Network
|
from ipaddress import ip_network, IPv4Network, IPv6Network
|
||||||
|
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ifupdown2.lib.addon import Addon
|
from ifupdown2.lib.addon import Addon
|
||||||
@@ -320,6 +325,14 @@ class address(Addon, moduleBase):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def validate_ipv4network(value):
|
||||||
|
return IPv4Network(value, strict=False)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def validate_ipv6network(value):
|
||||||
|
return IPv6Network(value, strict=False)
|
||||||
|
|
||||||
def syntax_check_multiple_gateway(self, ifaceobj):
|
def syntax_check_multiple_gateway(self, ifaceobj):
|
||||||
result = True
|
result = True
|
||||||
inet = False
|
inet = False
|
||||||
@@ -328,10 +341,10 @@ class address(Addon, moduleBase):
|
|||||||
for addr in gateways if gateways else []:
|
for addr in gateways if gateways else []:
|
||||||
try:
|
try:
|
||||||
if self._syntax_check_multiple_gateway('inet', inet, addr,
|
if self._syntax_check_multiple_gateway('inet', inet, addr,
|
||||||
IPv4Network):
|
self.validate_ipv4network):
|
||||||
inet = True
|
inet = True
|
||||||
if self._syntax_check_multiple_gateway('inet6', inet6, addr,
|
if self._syntax_check_multiple_gateway('inet6', inet6, addr,
|
||||||
IPv6Network):
|
self.validate_ipv6network):
|
||||||
inet6 = True
|
inet6 = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.logger.warning('%s: address: %s' % (ifaceobj.name, str(e)))
|
self.logger.warning('%s: address: %s' % (ifaceobj.name, str(e)))
|
||||||
|
@@ -9,7 +9,10 @@ import glob
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from ipaddr import IPNetwork, IPv6Network
|
from ipaddress import ip_network, IPv6Network
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ifupdown2.lib.addon import Addon
|
from ifupdown2.lib.addon import Addon
|
||||||
|
@@ -5,7 +5,16 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
|
|
||||||
from ipaddr import IPNetwork, IPAddress, IPv4Address, IPv4Network, AddressValueError
|
from ipaddress import ip_network, ip_address, IPv4Address, IPv4Network, AddressValueError
|
||||||
|
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
|
|
||||||
|
def IPAddress(ip):
|
||||||
|
return ip_address(ip)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ifupdown2.ifupdown.policymanager as policymanager
|
import ifupdown2.ifupdown.policymanager as policymanager
|
||||||
@@ -391,7 +400,7 @@ class vxlan(Addon, moduleBase):
|
|||||||
local = IPv4Address(local)
|
local = IPv4Address(local)
|
||||||
except AddressValueError:
|
except AddressValueError:
|
||||||
try:
|
try:
|
||||||
local_ip = IPv4Network(local).ip
|
local_ip = IPv4Network(local, strict=False).network_address
|
||||||
self.logger.warning("%s: vxlan-local-tunnelip %s: netmask ignored" % (ifname, local))
|
self.logger.warning("%s: vxlan-local-tunnelip %s: netmask ignored" % (ifname, local))
|
||||||
local = local_ip
|
local = local_ip
|
||||||
except:
|
except:
|
||||||
@@ -472,7 +481,7 @@ class vxlan(Addon, moduleBase):
|
|||||||
group = IPv4Address(group)
|
group = IPv4Address(group)
|
||||||
except AddressValueError:
|
except AddressValueError:
|
||||||
try:
|
try:
|
||||||
group_ip = IPv4Network(group).ip
|
group_ip = IPv4Network(group, strict=False).network_address
|
||||||
self.logger.warning("%s: vxlan-svcnodeip %s: netmask ignored" % (ifname, group))
|
self.logger.warning("%s: vxlan-svcnodeip %s: netmask ignored" % (ifname, group))
|
||||||
group = group_ip
|
group = group_ip
|
||||||
except:
|
except:
|
||||||
@@ -492,7 +501,7 @@ class vxlan(Addon, moduleBase):
|
|||||||
mcast_grp = IPv4Address(mcast_grp)
|
mcast_grp = IPv4Address(mcast_grp)
|
||||||
except AddressValueError:
|
except AddressValueError:
|
||||||
try:
|
try:
|
||||||
group_ip = IPv4Network(mcast_grp).ip
|
group_ip = IPv4Network(mcast_grp, strict=False).network_address
|
||||||
self.logger.warning("%s: vxlan-mcastgrp %s: netmask ignored" % (ifname, mcast_grp))
|
self.logger.warning("%s: vxlan-mcastgrp %s: netmask ignored" % (ifname, mcast_grp))
|
||||||
mcast_grp = group_ip
|
mcast_grp = group_ip
|
||||||
except:
|
except:
|
||||||
|
@@ -15,7 +15,14 @@ import pprint
|
|||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from ipaddr import IPNetwork, IPv4Network, IPv6Network, IPAddress, IPv4Address, IPv6Address
|
from ipaddress import ip_network, ip_address, IPv4Network, IPv6Network, IPv4Address, IPv6Address
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
|
def IPAddress(ip):
|
||||||
|
return ip_address(ip)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import ifupdown2.lib.nlcache as nlcache
|
import ifupdown2.lib.nlcache as nlcache
|
||||||
@@ -885,17 +892,25 @@ class ifupdownMain:
|
|||||||
self.logger.debug('keyword: check list: %s' % str(e))
|
self.logger.debug('keyword: check list: %s' % str(e))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def validate_ipv4network(value):
|
||||||
|
return IPv4Network(value, strict=False)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def validate_ipv6network(value):
|
||||||
|
return IPv6Network(value, strict=False)
|
||||||
|
|
||||||
def _keyword_ipv4(self, value, validrange=None):
|
def _keyword_ipv4(self, value, validrange=None):
|
||||||
return self._keyword_check_list(value.split(), IPv4Address, limit=1)
|
return self._keyword_check_list(value.split(), IPv4Address, limit=1)
|
||||||
|
|
||||||
def _keyword_ipv4_prefixlen(self, value, validrange=None):
|
def _keyword_ipv4_prefixlen(self, value, validrange=None):
|
||||||
return self._keyword_check_list(value.split(), IPv4Network, limit=1)
|
return self._keyword_check_list(value.split(), self.validate_ipv4network, limit=1)
|
||||||
|
|
||||||
def _keyword_ipv6(self, value, validrange=None):
|
def _keyword_ipv6(self, value, validrange=None):
|
||||||
return self._keyword_check_list(value.split(), IPv6Address, limit=1)
|
return self._keyword_check_list(value.split(), IPv6Address, limit=1)
|
||||||
|
|
||||||
def _keyword_ipv6_prefixlen(self, value, validrange=None):
|
def _keyword_ipv6_prefixlen(self, value, validrange=None):
|
||||||
return self._keyword_check_list(value.split(), IPv6Network, limit=1)
|
return self._keyword_check_list(value.split(), self.validate_ipv6network, limit=1)
|
||||||
|
|
||||||
def _keyword_ip(self, value, validrange=None):
|
def _keyword_ip(self, value, validrange=None):
|
||||||
return self._keyword_check_list(value.split(), IPAddress, limit=1)
|
return self._keyword_check_list(value.split(), IPAddress, limit=1)
|
||||||
|
@@ -16,7 +16,14 @@ import logging
|
|||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from ipaddr import IPNetwork, IPAddress
|
from ipaddress import ip_network, ip_address
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
|
def IPAddress(ip):
|
||||||
|
return ip_address(ip)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ifupdown2.ifupdown.iface import *
|
from ifupdown2.ifupdown.iface import *
|
||||||
|
@@ -27,7 +27,10 @@ import shlex
|
|||||||
import signal
|
import signal
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from ipaddr import IPNetwork
|
from ipaddress import ip_network
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from ifupdown2.lib.sysfs import Sysfs
|
from ifupdown2.lib.sysfs import Sysfs
|
||||||
|
@@ -33,7 +33,11 @@ import logging
|
|||||||
import threading
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
from ipaddr import IPNetwork
|
from ipaddress import ip_network
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
from logging import DEBUG, WARNING
|
from logging import DEBUG, WARNING
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
@@ -26,7 +26,7 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from ipaddr import IPv4Address, IPv6Address
|
from ipaddress import IPv4Address, IPv6Address
|
||||||
from .nlpacket import *
|
from .nlpacket import *
|
||||||
from select import select
|
from select import select
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
|
@@ -31,7 +31,16 @@
|
|||||||
import socket
|
import socket
|
||||||
import logging
|
import logging
|
||||||
import struct
|
import struct
|
||||||
from ipaddr import IPNetwork, IPv4Address, IPv6Address, IPAddress
|
|
||||||
|
from ipaddress import ip_network, ip_address, IPv4Address, IPv6Address
|
||||||
|
|
||||||
|
def IPNetwork(ip):
|
||||||
|
return ip_network(ip, False)
|
||||||
|
|
||||||
|
def IPAddress(ip):
|
||||||
|
return ip_address(ip)
|
||||||
|
|
||||||
|
|
||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
from pprint import pformat
|
from pprint import pformat
|
||||||
from socket import AF_UNSPEC, AF_INET, AF_INET6, AF_BRIDGE, htons
|
from socket import AF_UNSPEC, AF_INET, AF_INET6, AF_BRIDGE, htons
|
||||||
@@ -1331,8 +1340,6 @@ class AttributeIPAddress(Attribute):
|
|||||||
|
|
||||||
def __init__(self, atype, string, family, logger):
|
def __init__(self, atype, string, family, logger):
|
||||||
Attribute.__init__(self, atype, string, logger)
|
Attribute.__init__(self, atype, string, logger)
|
||||||
self.value_int = None
|
|
||||||
self.value_int_str = None
|
|
||||||
self.family = family
|
self.family = family
|
||||||
|
|
||||||
if self.family == AF_INET:
|
if self.family == AF_INET:
|
||||||
@@ -1376,14 +1383,8 @@ class AttributeIPAddress(Attribute):
|
|||||||
self.value = IPNetwork('%s/%s' % (self.value, parent_msg.prefixlen))
|
self.value = IPNetwork('%s/%s' % (self.value, parent_msg.prefixlen))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
self.value = IPNetwork('%s' % self.value)
|
self.value = IPNetwork('%s' % self.value)
|
||||||
|
|
||||||
self.value_int = int(self.value)
|
|
||||||
self.value_int_str = str(self.value_int)
|
|
||||||
|
|
||||||
except struct.error:
|
except struct.error:
|
||||||
self.value = None
|
self.value = None
|
||||||
self.value_int = None
|
|
||||||
self.value_int_str = None
|
|
||||||
self.log.error("%s unpack of %s failed, data 0x%s" % (self, self.PACK, hexlify(self.data[4:])))
|
self.log.error("%s unpack of %s failed, data 0x%s" % (self, self.PACK, hexlify(self.data[4:])))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
@@ -1393,7 +1394,11 @@ class AttributeIPAddress(Attribute):
|
|||||||
if self.family not in [AF_INET, AF_INET6, AF_BRIDGE]:
|
if self.family not in [AF_INET, AF_INET6, AF_BRIDGE]:
|
||||||
raise Exception("%s is not a supported address family" % self.family)
|
raise Exception("%s is not a supported address family" % self.family)
|
||||||
|
|
||||||
raw = pack(self.HEADER_PACK, length, self.atype) + self.value.packed
|
try:
|
||||||
|
raw = pack(self.HEADER_PACK, length, self.atype) + self.value.network_address.packed
|
||||||
|
except:
|
||||||
|
raw = pack(self.HEADER_PACK, length, self.atype) + self.value.packed
|
||||||
|
|
||||||
raw = self.pad(length, raw)
|
raw = self.pad(length, raw)
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user