%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cloudinit/net/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cloudinit/net/__pycache__/__init__.cpython-312.pyc

�

x[h�����ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	m
Z
mZddlm
Z
mZddlmZej"e�ZdZdZgd�Zgd�Zej0d	�fd
�Zd�Zddd�Z				ded
�Zdfd�Zd�Zd�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%ejLd��de'fd��Z(ejLd��de)fd��Z*de+de'fd�Z,dfd�Z-d�Z.d�Z/dfde'fd �Z0dfd!�Z1dfd"�Z2d#�Z3d$�Z4d%�Z5d&�Z6d'�Z7Gd(�d)e8�Z9d*�Z:de	e+fd+�Z;de
e+fd,�Z<de	e+fd-�Z=de
e+fd.�Z>de	e+fd/�Z?de
e+fd0�Z@de	e+fd1�ZAde
e+fd2�ZBdfde
eCfd3�ZDd4�ZEdgd5�ZFdhd6�ZG	did7�ZHd8�ZId9�ZJdeCfd:�ZKd;e+de
e+fd<�ZLdeCfd=�ZMdeCfd>�ZNdeCfd?�ZOdeCfd@�ZP							djdAe'dBe'dCe'dDe'dEe'dFe'dGe'de)fdH�ZQdIedJdKe	ee+e+e+e+fddfdL�ZRdM�ZSdNedOe+fdP�ZTdOe+de'fdQ�ZUdOe+de'fdR�ZVdOe+de'fdS�ZWdOe+de'fdT�ZXdOe+de'fdU�ZYdOe+de'fdV�ZZdOe+dWe+de'fdX�Z[dYe+dWe+de'fdZ�Z\de'fd[�Z]de+fd\�Z^de_fd]�Z`de_fd^�Zad_e+d`e+de+fda�ZbGdb�dcec�Zdy)k�N)�Callable�Dict�List�Optional�Tuple)�subp�util)�Iproute2z/sys/class/net/�eth0)�dhcp6�
ipv6_slaaczipv6_dhcpv6-statelesszipv6_dhcpv6-stateful)�	ovs-vsctlz--format�csvz
--no-headingsz	--timeout�10z	--columns�name�find�	interfacez
type=internalz([0-9]+)c��tj||�D�cgc]-}|j�rt|�n|j	���/c}Scc}w)aDSorting for Humans: natural sort order. Can be use as the key to sort
    functions.
    This will sort ['eth0', 'ens3', 'ens10', 'ens12', 'ens8', 'ens0'] as
    ['ens0', 'ens3', 'ens8', 'ens10', 'ens12', 'eth0'] instead of the simple
    python way which will produce ['ens0', 'ens10', 'ens12', 'ens3', 'ens8',
    'eth0'].)�re�split�isdigit�int�lower)�s�_nsre�texts   �8/usr/lib/python3/dist-packages/cloudinit/net/__init__.py�natural_sort_keyr+sF���H�H�U�A�&����\�\�^��D�	�����5����s�2Ac��tS)z3Simple function to return the global SYS_CLASS_NET.)�
SYS_CLASS_NET��r�get_sys_class_pathr#8s���r"c�(�t�|zdz|zS)N�/)r#��devname�paths  r�sys_dev_pathr)=s����'�)�C�/�$�6�6r"c���t||�}	tj|�}|j�}|�|S	||S#ttf$rf}t|dd�}	|	tjtjfvr|�
||�cYd}~S|	tjfvr|�
||�cYd}~S�d}~wwxYw#t$r,}|�
||�cYd}~Stjd||��d}~wwxYw)N�errnoz5Found unexpected (not translatable) value '%s' in '%s)r)r	�load_text_file�OSError�IOError�getattrr+�ENOENT�ENOTDIR�EINVAL�strip�KeyError�LOG�debug)
r'r(�	translate�	on_enoent�on_keyerror�	on_einval�dev_path�contents�e�e_errnos
          r�read_sys_netr?As����G�T�*�H�
��&�&�x�0���~�~��H��������"�"��
�W����!�W�d�+���u�|�|�U�]�]�3�3��$� ��|�#��u�|�|�o�%��$� ��|�#�
�����	��"��q�>�!��I�I�G���
�

��	�sP�=�B5�B2�8B-�B2�
B-�&B2�,B-�-B2�5	C*�>	C%�C*�
C%�%C*c�*�d�}t||||||��S)Nc��y�NFr!)r=s r�
on_excp_falsez(read_sys_net_safe.<locals>.on_excp_falsegs��r")r9r8r:r7)r?)�iface�fieldr7rCs    r�read_sys_net_saferFfs(����
�
�!����
�r"c�Z�t||�}|dury	t|�S#t$rYywxYwrB)rFr�
ValueError)rDrE�vals   r�read_sys_net_intrJts8��
�E�5�
)�C�
�e�|����3�x�������s�
�	*�*c�*�dddd�}t|d|��S)NTF)�up�unknown�down�	operstate)r7�rF)r'r7s  r�is_uprQ~s����e�<�I��W�k�Y�G�Gr"c�T�tjjt|d��S)N�bridge��osr(�existsr)�r's r�	is_bridgerX�s��
�7�7�>�>�,�w��9�:�:r"c�T�tjjt|d��S)N�bondingrTrWs r�is_bondr[�s��
�7�7�>�>�,�w�	�:�;�;r"c�`�t|d��}tjj|�r|Sy)z8Return the master path for devname, or None if no master�master�r(N)r)rUr(rVr&s  r�
get_masterr_�s&����h�/�D�	�w�w�~�~�d����r"c��t|�}|�ytjj|d�}tjj|d�}tjj	|�xstjj	|�S)z@Return a bool indicating if devname's master is a bridge or bondFrZrS)r_rUr(�joinrV)r'�master_path�bonding_path�bridge_paths    r�master_is_bridge_or_bondre�sb���W�%�K�����7�7�<�<��Y�7�L��'�'�,�,�{�H�5�K�
�7�7�>�>�,�'�F�2�7�7�>�>�+�+F�Fr"c�v�t|�}|�yt|d��}tjj	|�S)z;Return a bool indicating if devname's master is openvswitchFzupper_ovs-systemr^)r_r)rUr(rV)r'rb�ovs_paths   r�master_is_openvswitchrh�s5���W�%�K�����G�*<�=�H�
�7�7�>�>�(�#�#r"c� �t|d�dk(S)N�type�32rPrWs r�is_ib_interfacerl�s���W�f�-��5�5r")�maxsize�returnc�p�ttjd��}|stj	d�|S)zDReturn a bool indicating if Open vSwitch is installed in the system.rz<ovs-vsctl not in PATH; not detecting Open vSwitch interfaces)�boolr�whichr5r6)�rets r�openvswitch_is_installedrs�s0���t�z�z�+�&�
'�C���	�	�J�	
��Jr"c���	tjt�\}}|j�S#tj$r0}d|jvrt
j
d�gcYd}~S�d}~wwxYw)z�Return a list of the names of OVS internal interfaces on the system.

    These will all be strings, and are used to exclude OVS-specific interface
    from cloud-init's network configuration handling.
    zdatabase connection failedzJOpen vSwitch is not yet up; no interfaces will be detected as OVS-internalN)r�!OVS_INTERNAL_INTERFACE_LOOKUP_CMD�
splitlines�ProcessExecutionError�stderrr5�info)�out�_err�excs   r�get_ovs_internal_interfacesr}�sh�� ��I�I�?�@�	��T��~�~�����%�%��'�3�:�:�5��H�H� �
��I�
���s!�.�A1�$A,�%A1�+A,�,A1r'c�d�t�syt�}||vrtjd|�yy)z�Returns True if this is an OVS internal interface.

    If OVS is not installed or not yet running, this will return False.
    FzDetected %s as an OVS interfaceT)rsr}r5r6)r'�ovs_bridgess  r�!is_openvswitch_internal_interfacer��s2��
$�%��-�/�K��+���	�	�3�W�=��r"c�P�|�t|�}t||�st||�ryy)z�netfailover driver uses 3 nics, master, primary and standby.
    this returns True if the device is either the primary or standby
    as these devices are to be ignored.
    TF)�
device_driver�is_netfail_primary�is_netfail_standby�r'�drivers  r�is_netfailoverr��s2��
�~��w�'���'�6�*�.@���/��r"c�D�d}	t|d�}|S#t$rY|SwxYw)zDReturns a str from reading /sys/class/net/<devname>/device/features.�zdevice/features)r?�	Exception�r'�featuress  r�get_dev_featuresr��s9���H�
���):�;���O���
���O�
�s��	�c�J�t|�}|rt|�dkry|ddk(S)z�Return True if VIRTIO_NET_F_STANDBY bit (62) is set.

    https://github.com/torvalds/linux/blob/         089cf7f6ecb266b6a4164919a2e69bd2f938374a/         include/uapi/linux/virtio_net.h#L60
    �@F�>�1)r��lenr�s  r�has_netfail_standby_featurer��s.�� ��(�H��s�8�}�r�)���B�<�3��r"c�Z�t|��y|�t|�}|dk7ryt|�syy)z�A device is a "netfail master" device if:

    - The device does NOT have the 'master' sysfs attribute
    - The device driver is 'virtio_net'
    - The device has the standby feature bit set

    Return True if all of the above is True.
    F�
virtio_netT�r_r�r�r�s  r�is_netfail_masterr�s:���'��&��
�~��w�'��
����&�w�/��r"c�:�t|d��}tjj|�sy|�t	|�}|dk(rytjjtjj
|��}t	|�}|dk7ryt|�}|syy)a7A device is a "netfail primary" device if:

    - the device has a 'master' sysfs file
    - the device driver is not 'virtio_net'
    - the 'master' sysfs file points to device with virtio_net driver
    - the 'master' device has the 'standby' feature bit set

    Return True if all of the above is True.
    r]r^Fr�T)r)rUr(rVr��basename�realpathr�)r'r��master_sysfs_path�master_devname�
master_driver�master_has_standbys      rr�r�s���%�W�8�<��
�7�7�>�>�+�,��
�~��w�'��
�����W�W�%�%�b�g�g�&6�&6�7H�&I�J�N�!�.�1�M���$��4�^�D����r"c�Z�t|��y|�t|�}|dk7ryt|�syy)z�A device is a "netfail standby" device if:

    - The device has a 'master' sysfs attribute
    - The device driver is 'virtio_net'
    - The device has the standby feature bit set

    Return True if all of the above is True.
    Fr�Tr�r�s  rr�r�9s:���'��"��
�~��w�'��
����&�w�/��r"c�*�t|d�}|r|dvryy)a�
    /* interface name assignment types (sysfs name_assign_type attribute) */
    #define NET_NAME_UNKNOWN      0  /* unknown origin (not exposed to user) */
    #define NET_NAME_ENUM         1  /* enumerated by kernel */
    #define NET_NAME_PREDICTABLE  2  /* predictably named by the kernel */
    #define NET_NAME_USER         3  /* provided by user-space */
    #define NET_NAME_RENAMED      4  /* renamed by user-space */
    �name_assign_type)�3�4TFrP)r'r�s  r�
is_renamedr�Qs#��)��2D�E���,�
�:��r"c�P�tt|d��}d|j�vS)N�ueventzDEVTYPE=vlan)�strrFrv)r'r�s  r�is_vlanr�`s(��
�"�7�H�5�
6�F��V�.�.�0�0�0r"c���d}t|d�}tjj|�r2tjj	tj
|��}|S)z8Return the device driver for net device named 'devname'.Nz
device/driver)r)rUr(�islinkr��readlink)r'r��driver_paths   rr�r�esE��
�F��w��8�K�	�w�w�~�~�k�"����!�!�"�+�+�k�":�;���Mr"c�(�t|d�}|dury|S)z;Return the device id string for net device named 'devname'.z
device/deviceFNrP)r'�dev_ids  r�device_devidr�ps��
�w��
8�F�
�����Mr"c�D�tj�stj�r!tt	�j��S	t
jt��}|S#t$r,}|jtjk(rg}n�Yd}~|Sd}~wwxYw�N)r	�
is_FreeBSD�is_DragonFlyBSD�list�get_interfaces_by_mac�valuesrU�listdirr#r-r+r0)�devsr=s  r�get_devicelistr�ys�������D�0�0�2��)�+�2�2�4�5�5���z�z�,�.�/���K�����7�7�e�l�l�"��D��
��K���s�A*�*	B�3!B�Bc��eZdZdZy)�ParserErrorz6Raised when a parser has issue parsing a file/content.N)�__name__�
__module__�__qualname__�__doc__r!r"rr�r��s��@r"r�c�P�|rt|t�sy|jd�dk(S)NF�config�disabled)�
isinstance�dict�get)�cfgs r�is_disabled_cfgr��s%���j��d�+���7�7�8��
�*�*r"c���tj�stj�r
t�Stj�stj
�r
t
�St�S)zqGet the list of network interfaces viable for networking.

    @return List of interfaces, sorted naturally.
    )r	r�r��find_candidate_nics_on_freebsd�	is_NetBSD�
is_OpenBSD�(find_candidate_nics_on_netbsd_or_openbsd�find_candidate_nics_on_linuxr!r"r�find_candidate_nicsr��sG��
����D�0�0�2�-�/�/�	
���	�T�_�_�.�7�9�9�+�-�-r"c���tj�stj�r
t�Stj�stj
�r
t
�St�S)z.Get the name of the 'fallback' network device.)r	r�r��find_fallback_nic_on_freebsdr�r��&find_fallback_nic_on_netbsd_or_openbsd�find_fallback_nic_on_linuxr!r"r�find_fallback_nicr��sE������D�0�0�2�+�-�-�	
���	�T�_�_�.�5�7�7�)�+�+r"c�P�tt�j�t��S)zmGet the names of the candidate network devices on NetBSD/OpenBSD.

    @return list of sorted interfaces
    ��key)�sortedr�r�rr!r"rr�r��s��
�'�)�0�0�2�8H�I�Ir"c�&�t�}|r|dSy)zfGet the 'fallback' network device name on NetBSD/OpenBSD.

    @return default interface, or None
    rN)r���namess rr�r��s��

5�6�E���Q�x��r"c��tjgd��\}}|j�}|r|Stt�j	�t
��S)zgGet the names of the candidate network devices on FreeBSD.

    @return List of sorted interfaces.
    )�ifconfigz-lz-u�etherr�)rrr�r�r�r)�stdout�_stderrr�s   rr�r��sG��
�i�i� A�B�O�F�G�
�\�\�^�F�
��
��'�)�0�0�2�8H�I�Ir"c�&�t�}|r|dSy)z_Get the 'fallback' network device name on FreeBSD.

    @return List of sorted interfaces.
    rN)r�r�s rr�r��s��

+�,�E���Q�x��r"c�~�dtj�vrtjd�n\t	�D�cgc]}|dk7r
t|�s|��}}t
|�r*tjd|�tj�g}g}tdddddd��D]�\}}}}|dk(r�|jd�rtjd	|��6t|d
�}|r|j|��Vtjd|�t|d�}|r|j|���t|d
�}|dvr|j|���tjd|���g}	||fD]K}
t|
t��}
t|
vr+|
j!t�|
j#dt�|	|
z
}	�M|	Scc}w)zeGet the names of the candidate network devices on Linux.

    @return List of sorted interfaces.
    z
net.ifnames=0z9Stable ifnames disabled by net.ifnames=0 in /proc/cmdline�loz4Found unstable nic names: %s; calling udevadm settleFT)�filter_openvswitch_internal�2filter_slave_if_master_not_bridge_bond_openvswitch�filter_vlan�filter_without_own_mac�filter_zero_mac�log_filtered_reasons�vethzIgnoring veth interface: %s�carrierzInterface has no carrier: %s�dormantrO)r�rN�lowerlayerdownrMzInterface ignored: %sr�r)r	�get_cmdliner5r6r�r�r��udevadm_settle�get_interfaces�
startswithrJ�appendrFr�r�DEFAULT_PRIMARY_INTERFACE�remove�insert)�device�unstable�	connected�possibly_connectedr�_r�r�rO�sorted_interfaces�
interfacess           rr�r��s���
�$�*�*�,�,��	�	�M�N�)�*�
����~�j��&8�
�
��
�
�x�=��I�I�F��
�
���!��I���,�$)�;@��$��!�
�6��	�1�a����������'��I�I�3�Y�?��"�9�i�8������Y�'���	�	�0�)�<�#�9�i�8����%�%�i�0��%�i��=�	��H�H��%�%�i�0���	�	�)�9�5�=6�J�� �"4�5�(�
��J�,<�=�
�$�
�2����7�8����a�!:�;��Z�'��(����{
s�F:c�&�t�}|r|dSy)z]Get the 'fallback' network device name on Linux.

    @return List of sorted interfaces.
    rN)r�r�s rr�r�s��

)�*�E���Q�x��r"c��t�}|syt|�rd|i}ndt|d�j�i}|rt	|�}|r||d<dd||d�}||idd	�}|S)
zBGenerate network cfg v2 for dhcp on the NIC most likely connected.Nr�
macaddress�addressr�T)�dhcp4r�set-name�match�)�	ethernets�version)r�r�rFrr�)�
config_driver�target_namerr�r��nconfs      r�generate_fallback_configr	+s���$�%�K�����%���%��
�+�K��C�I�I�K�
����{�+���$�E�(�O�����	�C�'��,��;�E��Lr"c��d�}d�}|jd�}|dk(r||�S|dk(r||�Std|z��)Nc��g}|jdi�D]�}|jd�dk7r�|jd�}|s�,|jd�}|jdi�jd�}|jdi�jd�}|st|�}|st|�}|j||||g���|S)	Nr�rj�physical�mac_addressr�paramsr��	device_id)r�r�r�r�)�netcfg�physdevs�ent�macrr�rs       r�
_version_1z$extract_physdevs.<locals>._version_1Is������:�:�h��+�
	<�C��w�w�v��*�,���'�'�-�(�C����7�7�6�?�D��W�W�X�r�*�.�.�x�8�F�����"�-�1�1�+�>�I��&�t�,���(��.�	��O�O�S�$��	�:�;�
	<��r"c��g}|jdi�j�D]�}|jd�}|s�|jdi�jd�}|s�;|jdi�jd�}|jdi�jd�}|st|�}|st|�}|j	||||g���|S)Nrrrr�r�r)r�r�r�r�r�)rrrrrr�rs       r�
_version_2z$extract_physdevs.<locals>._version_2[s������:�:�k�2�.�5�5�7�	<�C��7�7�:�&�D����'�'�'�2�&�*�*�<�8�C����W�W�W�b�)�-�-�h�7�F������,�0�0��=�I��&�t�,���(��.�	��O�O�S�$��	�:�;�	<� �r"r�rz"Unknown network config version: %s)r��RuntimeError)rrrrs    r�extract_physdevsrHsQ���$�(�j�j��#�G��!�|��&�!�!�	�A���&�!�!�
�;�g�E�
F�Fr"c�B�t|d�}|�|rtd��y|dvS)a�return True if the provided interface has its own address.

    Based on addr_assign_type in /sys.  Return true for any interface
    that does not have a 'stolen' address. Examples of such devices
    are bonds or vlans that inherit their mac from another device.
    Possible values are:
      0: permanent address    2: stolen from another device
    1: randomly generated   3: set using dev_set_mac_address�addr_assign_typez%s had no addr_assign_type.T)rr�)rJrH)�ifname�strict�assign_types   r�interface_has_own_macr xs6��#�6�+=�>�K�����:�;�;���)�#�#r"c	���i}t�D]*\}}}}d|||j�|t|�d�||<�,|r�tjd�}tj
gd�d��\}}tj
gd�d��\}	}t
�}
||	fD]"}|
j|j|���$|j�D]}|dd	uxs|d
|
v|d<�|S)a�Collect information necessary for rename_interfaces.

    returns a dictionary by mac address like:
       {name:
         {
          'downable': None or boolean indicating that the
                      device has only automatically assigned ip addrs.
          'device_id': Device id value (if it has one)
          'driver': Device driver (if it has one)
          'mac': mac address (in lower case)
          'name': name
          'up': boolean: is_up(name)
         }}
    N)�downablerr�rrrLz[0-9]+:\s+(\w+)[@:])�ipz-6�addr�show�	permanent�scope�globalT)�capture)r#z-4r$r%rLFrr")
r�rrQr�compiler�set�update�findallr�)
�check_downable�cur_inforrr�r�nmatch�ipv6r{�ipv4�nics_with_addresses�	bytes_out�ds
             r�_get_current_rename_infor6�s���H�(6�(8�
�$��c�6�9��"���9�9�;����+�

����
�����2�3���Y�Y�H��
�
��d��Y�Y�;�T�J�
��d�!�e�����	B�I��&�&�v�~�~�i�'@�A�	B����"�	�A��$��5� �H�A�f�I�5H�$H�
�j�M�	�
�Or"c
����t|�stjd�y|�
t�}i�|j	�D]F\}}|j�}|j
d�r|dj�|d<||d<|�|<�Htjd��d�}g}g}	g}
|��}d}d}
d����fd	�}|D�]�\}}}}|r|j�}g}||||�}|s|r|	jd
|�d|�d���D|j
d�}||k(r�[|s|r|	jd
|�d|�d���x|d
rRd}|ds|r|	j||||fz���d|d
<|jd|||ff�|
jd
|||ff�||vr�||}|d
r7d}|ds|r|	j||||fz���|jd|||ff�d}|�||vr|
dz
}
||
z}|��
||vr�|jd||||ff�||d<|��}|d
r|
jd
|||ff�|jd|||d|ff�||d<|��}||z
}���tjtjtjd�}|s<|
s:t|	�rtjd||	�nItjd|�n2tjd|||
z�||
zD]\}}}}	|||��t|	�rtdj!|	���y#t$r)}|	jd|�|�d|�d|�d|��	�Yd}~�fd}~wwxYw)Nzno interfaces to renamerrzDetected interfaces %sc�B�td�|j�D��S)Nc3�*K�|]}|d|f���
y�w)rNr!)�.0�datas  r�	<genexpr>z<_rename_interfaces.<locals>.update_byname.<locals>.<genexpr>�s����D�T�T�&�\�4�(�D�s�)r�r�)�bymacs r�
update_bynamez)_rename_interfaces.<locals>.update_byname�s���D�U�\�\�^�D�D�Dr"z
cirename%d���c��|r |r|r|d|k(xr|d|k(xr|d|k(S|r|r|d|k(xr|d|k(S|r|d|k(Sy)zmatch if set and in datarr�rFr!)r;rr�rs    r�entry_matchz'_rename_interfaces.<locals>.entry_match�sv���6�i��U��s�"�3���N�f�,�3���%��2�
�
�V���;�#�%�B�$�x�.�F�*B�B�
���;�#�%�%�r"c	�����j�D�cgc]}�||||�r|��}}t|�r-t|�dkDrd|�d|�d|�d|�d�	}t|��|dSycc}w)Nrz2Failed to match a single device. Matched devices "z" with search values "(mac:z driver:z device_id:z)"r)r�r�rH)rr�rr;r�msgr/rAs      ��r�
find_entryz&_rename_interfaces.<locals>.find_entry�s}���!���)�
���4��f�i�8�
�
��
�
�u�:��5�z�A�~��c�6�9�6��
!��o�%���8�O���
s�A#z$[nic not present] Cannot rename mac=z to z, not available.rLz*[busy] Error renaming mac=%s from %s to %sr"FrNz2[busy-target] Error renaming mac=%s from %s to %s.r�rename)rErNrLz1Unable to rename interfaces: %s due to errors: %sz$no work necessary for renaming of %szRenamed %s with ops %sznknown] Error performing z for z, z: �
)r�r5r6r6�items�copyr�rr�r
�link_rename�	link_down�link_up�warningr�rra)�renames�strict_present�strict_busy�current_inforr;�curr>�ops�errors�ups�
cur_byname�tmpname_fmt�tmpirDr�new_namer�r�cur_ops�cur_namerC�target�tmp_name�opmap�oprr=r/rAs                            @@r�_rename_interfacesr_�s�����w�<��	�	�+�,����/�1���H�"�(�(�*��
��d��i�i�k���7�7�5�>��U��)�)�+�C��J���F��������I�I�&��1�E�
�C�
�F�
�C��x�(�J��K�
�D�
��$-4�=�(��X�v�y���)�)�+�C�����f�i�0�����
�
�*-�x�9��
��7�7�6�?���x������
�
�*-�x�9��
��t�9�>�C��z�?���M�M�#��h��(A�"A�B���C��I��N�N�F�C��H�;�?�@��J�J��c�8�h�[�9�:��z�!���)�F��d�|�J���j�)�"��
�
�c�S�(�H�,E�&E�F���N�N�F�C��H�;�#G�H�&*�H��"�h�*�&<���	��&��-���"�h�*�&<�
�N�N�H�c�8�h��5I�J�K�%�F�6�N�&�x�0�J��d�|��
�
�D�#�x�(��=�>�����#�x�#�f�+�x�1H�I�J���F��"�8�,�
��w���{=�@�&�&��"�"����"�E�
�#��v�;��K�K�C���
�
�I�I�<�g�F��	�	�*�G�S�3�Y�?�),�s��	�%�B��X�v�
���b�	�6�"�	��6�{��4�9�9�V�,�-�-���
�
��
�
��6�3��!�5����
�s�3L#�#	M�,M�Mc�t�d}tjjt|d��rd}t	||�S)z6Returns the string value of an interface's MAC Addressr��
bonding_slavezbonding_slave/perm_hwaddr)rUr(�isdirr)rF)rr(s  r�get_interface_macrcXs2���D�	�w�w�}�}�\�&�/�:�;�+���V�T�*�*r"c�Z�t|d�dk(rt|�}|r
|r|dd|ddz}|Sy)z�Returns the string value of an Infiniband interface's hardware
    address. If ethernet_format is True, an Ethernet MAC-style 6 byte
    representation of the address will be returned.
    rjrk�$i��3N)rFrc)r�ethernet_formatrs   r�get_ib_interface_hwaddrrhbsB�����(�D�0���'���?��b��+��B�C��(�C��
�1r"c���tj�stj�r
t�Stj�r
t�Stj�r
t�St�Sr�)	r	r�r�� get_interfaces_by_mac_on_freebsdr��get_interfaces_by_mac_on_netbsdr�� get_interfaces_by_mac_on_openbsd�get_interfaces_by_mac_on_linuxr!r"rr�r�psO������D�0�0�2�/�1�1�	
���	�.�0�0�	
���	�/�1�1�-�/�/r"rc��t�j�D]*\}}|j�|j�k(s�(|cSyr�)r�rGr)r�
interface_mac�interface_names   r�find_interface_name_from_macrq{sD��)>�)@�)F�)F�)H�"�%�
�~��9�9�;�-�-�-�/�/�!�!�"�r"c��tjgd��\}}d�}d�}|||��D��cic]\}}||��
}}}|Scc}}w)N)r��-ar�c3�K�d}|jd�D]!}|jd�r||z
}�|r|��|}�#|��y�w)Nr�rF�	)rr�)rz�
curr_block�lines   r�flattenz1get_interfaces_by_mac_on_freebsd.<locals>.flatten�sN�����
��I�I�d�O�	"�D����t�$��d�"�
��$�$�!�
�
	"���s�=?c3�K�|D]?}tjd|�}|s�|jd�|jd�f���Ay�w)Nz2^(?P<ifname>\S*): .*ether\s(?P<mac>[\da-f:]{17}).*rr)r�search�group)�	flat_list�block�ms   r�find_macz2get_interfaces_by_mac_on_freebsd.<locals>.find_mac�sI�����	:�E��	�	�E�u��A���w�w�u�~�q�w�w�x�'8�9�9�	:�s
�A�'A)r)rzr�rxrrr�resultss       rrjrj�sP���y�y�4�5�H�S�!�	�:�/7�w�s�|�.D�E�{�s�F�s�F�{�E�G�E��N��Fs�
Ac��i}d}tjddg�\}}tjdd|�j�}|D]6}tj||�}|s�|j�}|d||d<�8|S)NzE(?P<ifname>\w+).*address:\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�rs�\n\s+� rr�rr�subrvr�	groupdict�rr�re_field_matchrzr��if_linesrwr~�fieldss        rrkrk����
�C�	6���y�y�*�d�+�,�H�S�!��v�v�h��S�)�4�4�6�H��2���H�H�^�T�*����[�[�]�F�!'��!1�C��u�
��	2�
�Jr"c��i}d}tjddg�\}}tjdd|�j�}|D]6}tj||�}|s�|j�}|d||d<�8|S)NzC(?P<ifname>\w+).*lladdr\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r�rsr�r�rrr�r�s        rrlrl�r�r"c� �i}t�D]~\}}}}||vr:|dvrtjd||||��,d|�d||�d|�d�}t|��|||<t	|d�}|s�Z||vr|||<�dtjd||||���|S)	zmBuild a dictionary of tuples {mac: name}.

    Bridges and any devices that have a 'stolen' mac are excluded.)�	fsl_enetc�
mscc_felix�qmi_wwanz>Ignoring duplicate macs from '%s' and '%s' due to driver '%s'.�duplicate mac found! both '�' and '�' have mac 'z'.Tz^Ethernet and InfiniBand interfaces have the same address both '%s' and '%s' have address '%s'.)r�r5r6rrhrL)rrrrr��_devidrC�ib_macs       rrmrm�s����C�%3�%5�=�!��c�6�6��#�:��@�@��	�	�#����H����A���C����C�
�s�#�#���C��
)��t�4���*�S� �"��F�����=����K���o=�|�Jr"�filter_hyperv_vf_with_syntheticr�r�r�r�r�r�c	�`�|rtjnd�}g}t�}	djd�}
|	D]�}|rt	|�s�t|�r
|d|��&|rt
|�r�4t|�r
|d|��I|r"t|��t|�st|�s�mt|�r
|d|���t|�}|s
|d|���|r|d	k7r||
dt|�k(r��|rt|�r��t|�}
|j!|||
t#|�f���|rt%||�|S)
z�Return list of interface tuples (name, mac, driver, device_id)

    Bridges and any devices that have a 'stolen' mac are excluded.c��yr�r!)�argss r�<lambda>z get_interfaces.<locals>.<lambda>s�r"�:)�00r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�zIgnoring bridge interface: %szIgnoring bond interface: %sNzIgnoring failover interface: %sz"Ignoring interface without mac: %sr�)r5r6r�rar rXr�r[r_rerhr�rcr�r�r�r�r��)filter_hyperv_vf_with_synthetic_interface)r�r�r�r�r�r�r��filtered_loggerrrr��zero_macrrr�s              rr�r�s=��$8�c�i�i�=O�O�
�C���D��x�x��%�H��"<��!�*?��*E���T�?��;�T�B���7�4�=���4�=��9�4�@��>��4� �,�,�T�2�)�$�/���$���=�t�D����%����@�$�G���t�t�|��x�
�#�c�(�7K�0K��&�+L��,
�
��t�$���
�
�D�#�v�|�D�'9�:�;�E"<�J'�1�/�3�G��Jr"r�).Nr�c���|D�cic]}|ddk(s�|d|d��}}|D�cgc]}|d|vr
|ddk7r|��}}|D])}|\}}}}	|d|||||�|j|��+ycc}wcc}w)a�Filter Hyper-V SR-IOV/VFs when used with synthetic hv_netvsc.

    Hyper-V's netvsc driver may register an SR-IOV/VF interface with a mac
    that matches the synthetic (hv_netvsc) interface.  This VF will be
    enslaved to the synthetic interface, but cloud-init may be racing this
    process.  The [perhaps-yet-to-be-enslaved] VF should never be directly
    configured, so we filter interfaces that duplicate any hv_netvsc mac
    address, as this the most reliable indicator that it is meant to be
    subordinate to the synthetic interface.

    VF drivers will be mlx4_core, mlx5_core, or mana.  However, given that
    this list of drivers has changed over time and mana's dependency on
    hv_netvsc is expected to be removed in the future, we no longer rely
    on these names. Note that this will not affect mlx4/5 instances outside
    of Hyper-V, as it only affects environments where hv_netvsc is present.
    r�	hv_netvscrrzdIgnoring %r VF interface with driver %r due to synthetic hv_netvsc interface %r with mac address %r.N)r�)
r�r��i�hv_netvsc_mac_to_name�interfaces_to_removerrrr�r�s
          rr�r�As���*'���!�A�$�+�*=��!��a��d�
����
��
��Q�4�(�(�Q�q�T�[�-@�	
����*�
%�	�(���c�6�1��
D���!�#�&��
	
�	���)�$�
%����s�
A-�A-�A2c
��i}t�D]7\}}}}t|d�}|s�||vrtd|�d||�d|�d���|||<�9|S)zTBuild a dictionary mapping Infiniband interface names to their hardware
    address.Fr�r�r��')r�rhr)rrrr�r�s    r�get_ib_hwaddrs_by_interfacer�ksh���C�'�)��
��a��A�(��u�5�����}�"��S��[�&�2����C��I���Jr"�convert_to_addressr�c�4�	||fi|��S#t$rYywxYw)aUse a function to return an address. If conversion throws a ValueError
    exception return False.

    :param check_cb:
        Test function, must return a truthy value
    :param address:
        The string to test.

    :return:
        Address or False

    F)rH)r�r��kwargss   r�maybe_get_addressr�{s)���!�'�4�V�4�4������s��	�c�H�tttj|��S)z�Returns a bool indicating if ``s`` is an IP address.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IP address or not.
    )rpr��	ipaddress�
ip_address�r�s r�
is_ip_addressr��s���!�)�"6�"6��@�A�Ar"c�H�tttj|��S)z�Returns a bool indicating if ``s`` is an IPv4 address.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    )rpr�r��IPv4Addressr�s r�is_ipv4_addressr������!�)�"7�"7��A�B�Br"c�H�tttj|��S)z�Returns a bool indicating if ``s`` is an IPv6 address.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    )rpr�r��IPv6Addressr�s r�is_ipv6_addressr��r�r"c�L�tttj|d���S)z�Returns a bool indicating if ``s`` is an IPv4 or IPv6 network.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    F�r)rpr�r��
ip_networkr�s r�
is_ip_networkr��s���!�)�"6�"6���N�O�Or"c�L�tttj|d���S)z�Returns a bool indicating if ``s`` is an IPv4 network.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    Fr�)rpr�r��IPv4Networkr�s r�is_ipv4_networkr���#����)�/�/���G��r"c�L�tttj|d���S)z�Returns a bool indicating if ``s`` is an IPv6 network.

    :param address:
        The string to test.

    :return:
        A bool indicating if the string is an IPv4 address or not.
    Fr�)rpr�r��IPv6Networkr�s r�is_ipv6_networkr��r�r"�subnetc�b�tj|�}tj|d��}||vS)z�Returns a bool indicating if ``s`` is in subnet.

    :param address:
        The string of IP address.

    :param subnet:
        The string of subnet.

    :return:
        A bool indicating if the string is in subnet.
    Fr�)r�r�r�)r�r�r��subnet_networks    r�is_ip_in_subnetr��s1���%�%�g�.�J��)�)�&��?�N���'�'r"�gatewayc�z�	t||�S#t$r"}tjd|||�Yd}~yd}~wwxYw)z�Returns a bool indicating if should add gateway onlink flag.

    :param gateway:
        The string of gateway address.

    :param subnet:
        The string of subnet.

    :return:
        A bool indicating if the string is in subnet.
    zDFailed to check whether gateway %s is contained within subnet %s: %sNF)r�rHr5rL)r�r�r=s   r�should_add_gateway_onlink_flagr��sF��
�"�7�F�3�3�3�������
1���
�	
����s��	:�5�:c��|djd�s|dtvry|ddk(rt|jd��ryy)z:Common helper for checking network_state subnets for ipv6.rj�6T�staticr�F)�endswith�IPV6_DYNAMIC_TYPESr�r�)r�s r�subnet_is_ipv6r�sG���f�~���s�#�v�f�~�9K�'K��	���8�	#���
�
�9�8M�(N��r"c�X�ttjd|���j�S)z�Convert a network prefix to an ipv4 netmask.

    This is the inverse of ipv4_mask_to_net_prefix.
        24 -> "255.255.255.0"
    Also supports input as a string.�0.0.0.0/)r�r�r��netmask)�prefixs r�net_prefix_to_ipv4_maskr�s'���y�$�$�x��x�%8�9�A�A�B�Br"c�F�tjd|���jS)aConvert an ipv4 netmask into a network prefix length.

    If the input is already an integer or a string representation of
    an integer, then int(mask) will be returned.
       "255.255.255.0" => 24
       str(24)         => 24
       "24"            => 24
    r�)r�r��	prefixlen)�masks r�ipv4_mask_to_net_prefixr�s"�����(�4�&� 1�2�<�<�<r"c��	tjd|���j}|S#t$rYnwxYwtj|�}t|�}|dk(r|St
tj||dz
zj��}||z	}tj|z
}d|zdz
}||k7rtd|z��|S)z�Convert an ipv6 netmask (very uncommon) or prefix (64) to prefix.

    If the input is already an integer or a string representation of
    an integer, then int(mask) will be returned.
       "ffff:ffff:ffff::"  => 48
       "48"                => 48
    z::/rrzInvalid network mask '%s')	r�r�r�rHr�r�min�
IPV6LENGTH�
bit_length)r�r�r��mask_int�trailing_zeroes�leading_ones�all_oness       r�ipv6_mask_to_net_prefixr�'s���
��(�(�3�t�f��6�@�@�	�����
�	
�
��
�"�"�4�(�G��7�|�H��1�}��������y�H�q�L�9�E�E�G��O���.�L��$�$��6�I��Y��!�#�H��x���4�t�;�<�<��s�#&�	2�2r�r#c�`�ttj|�d|��d��j�S)zCGet string representation of broadcast address from an ip/mask pairr%Fr�)r�r�r��broadcast_address)r�r#s  r�mask_and_ipv4_to_bcast_addrr�Js/��������A�d�V�n�U�;�M�M��r"c��eZdZy)�RendererNotFoundErrorN)r�r�r�r!r"rr�r�Qs��r"r�)r�)NNNNr�)F)T)TTN)TTTTTTF)er+�	functoolsr��loggingrUr�typingrrrrr�	cloudinitrr	�cloudinit.net.netops.iproute2r
�	getLoggerr�r5r r�r�rur*rr#r)r?rFrJrQrXr[r_rerhrl�	lru_cacherprsr�r}r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	rr r6r_rcrhr�rqrjrkrlrmr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�rr�r!r"r�<module>r�sD��
����	�	�8�8� �2��g����!��!�
�"����%�!�)�b�j�j��4�
��
7�����
"�J��H�;�<��G�$�6�����T�"��$��#������T�"� �T� �#� �(�s��t����
��t��0�B�0�1�
���A�)�A�+�
.�T�#�Y�
.�,�8�C�=�,�J�$�s�)�J�	���
�	�J��S�	�J�	�h�s�m�	�E�d�3�i�E�P	�H�S�M�	��H�T�N��:-G�`$�(+�^BF�[.�|+��0�t�0��c��h�s�m���$��8
��
� 
�$�
� D��D�P-1�(,�?C��#'� �!&�9�%)�9�!%�9�9=�9��	9�
!�9��
9��9�
�9�x'%��i�(�'%��U�3��S�#�-�.�/�'%�
�'%�T
� �(��S��&	B�3�	B�4�	B�	C�S�	C�T�	C�	C�S�	C�T�	C�	P�3�	P�4�	P��S��T���S��T��(�S�(�#�(�$�(�"�C������2�d��C�s�C�	=�S�	=� �S� �F�c��s��s��	�L�	r"

Zerion Mini Shell 1.0