+
    iA"  c                   s0    ^ RI t ^ RIHt  ! R R]4      tR# )    N)SoSMapc                   s   a a ] tR t^t oRt. ROt/ t]! 4       t^dt	. ROt
RtRtV 3R ltR tR tR tR tR	 tR
 tR tR tR tRtVtV ;t# )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.
Fl     "X c                s   < VP                  4        F6  pV P                  P                  VP                  R^R7      ^ ,          4       K8  	  \        SV `  V4       R# )zNOverride the base conf_update() so that we can add items into
obfuscated_ips.
/ZmaxsplitN)valuesobfuscated_ipsaddsplitZsuperconf_update)selfZconfigvalue	__class__s   && @/usr/lib/python3.14/site-packages/sos/cleaner/mappings/ip_map.pyr	   ZSoSIPMap.conf_update6   sH     ]]_E##EKKaK$@$CD %F#    c                s    V P                   P                  VP                  R ^R7      ^ ,          4       W P                  V&   R# )r   r   N)r   r   r   dataset)r
   itemr   s   &&&r   insert_to_datasetZSoSIPMap.insert_to_dataset>   s4    C! <Q ?@"Tr   c                sd    \        V4      P                  R^R7      ^ ,          pW P                  9   # )zThere 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
r   r   )strr   r   )r
   ZipaddrZaddr_strs   && r   ip_in_datasetZSoSIPMap.ip_in_datasetB   s1     v;$$S1$5a8....r   c                s   RpVP                  V4      '       d!   VP                  RP                  V4      4      pWP                  9   d   V P                  V,          # V P	                  V4      '       g   V P                  V4      '       d   V# RV9  dU   V P                  P                  4        F6  w  r4VP                  V4      '       g   K  VP                  R4      ^ ,          u # 	  V P                  V4      # )zoEnsure that when requesting an obfuscated address, we return a str
object instead of an IPv(4|6)Address object
r   Z )r   Z=Z]Z))	Z
startswithZlstripZjoinr   Zignore_itemr   Zitemsr   r   )r
   r   Z
filt_startkeyr   s   &&   r   getZSoSIPMap.getL   s     *
??:&&;;rwwz23D<<<<%%D!!T%7%7%=%=K
 d?"ll002
>>$'' ;;s+A.. 3
 xx~r   c                s   . pV P                    FK  pVP                  VP                  8X  d
   W1n         R# VP                  V9   g   K:  VP	                  V4       KM  	  V'       d%   VP                  R RR7       V^ ,          Vn        R# R# )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                 s    V P                   # )N)	prefixlen)Zns   &r   Z<lambda>Z;SoSIPMap.set_ip_cidr_from_existing_subnet.<locals>.<lambda>w   s    AKKr   T)r   Zreverse)	_networksipbroadcast_addressnetworkappendZsort)r
   addrZnetsZnet   &&  r    set_ip_cidr_from_existing_subnetZ)SoSIPMap.set_ip_cidr_from_existing_subnete   sn     >>Cww#///"ww#~C  " II/I>7DL r   c                s:    \         P                  ! V4      pTP
                  p\        TP                  4      R8X  d   T P                  T4       MT P                  T4       T P                  T4      #   \         d    T P                  P	                  T4       h i ; i)zYGiven an IP address, sanitize it to an obfuscated network or host
address as appropriate
z255.255.255.255)	ipaddressZip_interfaceZ
ValueErrorignore_matchesr   r   r   Znetmaskr   sanitize_networksanitize_ipaddr)r
   r   r   r   r   r   sanitize_itemZSoSIPMap.sanitize_itemz   s    
	))$/D
 ,,w#44 11$7
 !!'*##D))!  	&&t,	s   A2 2(Bc                sL    WP                   9  d   V P                  V4       R# R# )zoObfuscate the network address provided, and if there are host bits
in the address then obfuscate those as well
N)r   _new_obfuscated_network)r
   r   s   &&r   r!   ZSoSIPMap.sanitize_network   s!    
 ..(((1 )r   c                s   VP                   V P                  9   d   V P                  VP                   ,          pVP                  VP                   P                  8X  d   \	        VP                  4      # VP                  4        F6  pV P                  V4      '       d   K  \	        V4       RVP                   2u # 	  V P                  4       # )zEObfuscate the IP address within the known obfuscated network
        r   )	r   r   r   r   r   Zhostsr   r   _new_obfuscated_single_address)r
   r   _obf_networkZ_ipr   r   r"   ZSoSIPMap.sanitize_ipaddr   s     <<4>>)>>$,,7L
 ww$,,888<99:: $))+))#.. "#hZq)?)?(@AA	 , 2244r   c                s   V ;P                   ^,          un         V P                   R,          R9   d   V ;P                   ^,          un         K3  V P                   ^,	           RV P                   ^,	          R,           RV P                   ^,	          R,           RV P                   R,           2pWP                  P                  4       9   d   V P                  4       # V# )i   i   Z.)r    i   )
_saddr_cntr   r   r%   )r
   Z_addrs   & r   r%   Z'SoSIPMap._new_obfuscated_single_address   s    1oo#x/OOq O ??b()DOOr,AS+H*I1$+,Adoo.C-DFLL''))6688r   c                s   Rp\        V\        P                  4      '       d   V P                  V P                  9   d   V ;P                  ^,          un        V P                   R2pVP
                  P                  R4      ^,          p\        P                  ! V RV 24      pV ;P                  ^,          un        \        V\        P                  4      '       d    V'       df   \        V4      pW P                  V&   WPP                  \        V4      &   V P                  P                  VP                  R^R7      ^ ,          4       R# R# )zGenerate an obfuscated network address for the network address given
which will allow us to maintain network relationships without divulging
actual network details

Positional arguments:

    :param network:     An ipaddress.IPv{4|6)Network object
Nz.0.0.0r   r   )Z
isinstancer   ZIPv4Networknetwork_first_octetskip_network_octetsZwith_netmaskr   ZIPv6Networkr   r   r   r   r   )r
   r   r&   Z_obf_addressZ	_obf_maskZ_obf_network_ss   &&    r   r$   Z SoSIPMap._new_obfuscated_network   s    gy4455''4+C+CC((A-("667v>L,,2237:I$00L>9+1NOL$$)$gy4455 .N&2NN7#)7LLW&##N$8$8q$8$I!$LM	 r    )z127.*z::1z0\.(.*)?z1\.(.*)?z8.8.8.8z8.8.4.4z	169.254.*z255.*)Z127Z169Z172Z192)Z__name__Z
__module__Z__qualname__Z__firstlineno__Z__doc__r    r   Zsetr   r(   r)   Zcompile_regexesr'   r	   r   r   r   r   r#   r!   r"   r%   r$   Z__static_attributes__Z__classdictcell__Z__classcell__)r   Z__classdict__s   @@r   r   r      sp     	N IUN6O
 J$#/2#**2250N Nr   r   )r   Zsos.cleaner.mappingsr   r   r*   r   r   <module>r+      s     'KNv KNr   