Current File : //proc/self/root/lib/python3/dist-packages/sos/cleaner/mappings/__pycache__/ip_map.cpython-312.pyc |
�
-�_gv � �6 � d dl Z d dlZd dlmZ G d� de� Zy)� N)�SoSMapc �\ � e Zd ZdZg d�Zi ZdZg d�ZdZd� Z d� Z
d� Zd � Zd
� Z
d� Zd� Zd
� Zy)�SoSIPMapa� A mapping store for IP addresses
Each IP address added to this map is chcked for subnet membership. If that
subnet already exists in the map, then IP addresses are deterministically
generated sequentially within that subnet. For example, if a given IP is
matched to subnet 192.168.1.0/24 then 192.168.1 may be obfuscated to
100.11.12.0/24. Each IP address in the original 192.168.1.0/24 subnet
will then be assigned an address in 100.11.12.0/24 sequentially, such as
100.11.12.1, 100.11.12.2, etc...
Internally, the ipaddress library is used to manipulate the address objects
however, when retrieved by SoSCleaner any values will be strings.
)z127.*z::1z0\.(.*)?z1\.(.*)?z8.8.8.8z8.8.4.4z 169.254.*z255.*�d )�127�169�172�192Fc � � | j j � D ]8 }t |� j dd�� d |j d� d k( s�8 y y)a There are multiple ways in which an ip address could be handed to us
in a way where we're matching against a previously obfuscated address.
Here, match the ip address to any of the obfuscated addresses we've
already created
�/� )�maxsplitr TF)�dataset�values�str�split)�self�ipaddr�_ips �=/usr/lib/python3/dist-packages/sos/cleaner/mappings/ip_map.py�
ip_in_datasetzSoSIPMap.ip_in_dataset1 sV � � �<�<�&�&�(� �C��6�{� � ��q� �1�!�4�� � �#��q�8I�I�� � � c � � d}|j |� r |j dj |� � }|| j v r| j | S | j |� s| j |� r|S d|vrI| j j
� D ], \ }}|j |� s�|j d� d c S | j |� S )zEnsure that when requesting an obfuscated address, we return a str
object instead of an IPv(4|6)Address object
)r �=�]�)� r r ) �
startswith�lstrip�joinr �ignore_itemr �itemsr �add)r �item�
filt_start�key�values r �getzSoSIPMap.get= s� � � *�
��?�?�:�&��;�;�r�w�w�z�2�3�D��4�<�<���<�<��%�%����D�!�T�%7�%7��%=��K�
�d�?�"�l�l�0�0�2�
/�
��U��>�>�$�'� �;�;�s�+�A�.�.�
/�
�x�x��~�r c �� � g }| j D ]D }|j |j k( r ||_ y|j |v s�4|j |� �F |r|j d� d�� |d |_ yy)a/ Determine if a given address is in a subnet of an already obfuscated
network and if it is, then set the address' network to the network
object we're tracking. This allows us to match ip addresses with or
without a CIDR notation and maintain proper network relationships.
Nc � � | j S )N)� prefixlen)�ns r �<lambda>z;SoSIPMap.set_ip_cidr_from_existing_subnet.<locals>.<lambda>h s
� �A�K�K� r T)r&