+
    i  c                   s*   R t ^ RIt^ RIHt  ]P                  ! RR4        ^ RIHt RtRs
Rs^ RIHt ^ R	IHt ^ R
IHt ^ RItR tR tR tR tR tR tR tR tR tR tR tR tR#   ]]]P                  3 d    Rt LXi ; i  ] d    Rt Lgi ; i)z(Functions for NetworkManager interactionN)GLibNMz1.0)r   TF)errors)FirewallError)logc                 sR    \         '       g   \        \        P                  R4      hR# )zICheck function to raise a MISSING_IMPORT error if the import of NM failedzgi.repository.NM = 1.0N)_nm_importedr   r   ZMISSING_IMPORT     8/usr/lib/python3.14/site-packages/firewall/core/fw_nm.pycheck_nm_importedr	   !   s     <F113KLL r   c                 s    \         # )zfReturns true if NM has been properly imported
@return True if import was successful, False otherwirse
)r   r   r   r   nm_is_importedr
   '   s
     r   c                 s    R p \         '       g!   \        P                  P                  R4      s M\        P
                  ! \        4       \        P                  ! ^V 4      s\         # )zReturns the NM client object or None if the import of NM failed
@return NM.Client instance if import was successful, None otherwise
c                 s    Rs RsR# )zf
Release the client to avoid excess memory usage when libnm pushes
irrelevant (to firewalld) updates.
N)
_nm_client_nm_client_timeoutr   r   r   _releaseZnm_get_client.<locals>._release3   s     
!r   N)r   r   ZClientZnewr    Zsource_remover   Ztimeout_add_seconds)r   s    r   nm_get_clientr   .   sJ    
" :YY]]4(
 	-.11!X>r   c                s   \        4        \        4       P                  V 4      pVf   R# VP                  4       pVf   R#  VP	                  4       \
        P                  P                  \
        P                  P                  ,          ,          '       d   R#  VP                  4       pVf   RpV#   \         d    TP                  4       '       d    R#  L>i ; i)zGet zone of connection from NM
@param connection name
@return zone string setting of connection, empty string if not set, None if connection is unknown
N )r	   r   get_connection_by_uuidget_setting_connection	get_flagsr   SettingsConnectionFlagsNM_GENERATEDNM_VOLATILEAttributeErrorget_unsavedZget_zone)
connectionconsetting_conzone   &   r   nm_get_zone_of_connectionr   K   s    
 
/
0
0
<C
{,,.K
==?&&33((445
 
 	
 !D|K   ?? s   AB0 0 CCc                s    \        4        \        4       P                  V4      pVf   R# VP                  4       pVf   R# V R8X  d   Rp VP	                  RV 4       VP                  RR4      # )zoSet the zone for a connection
@param zone name
@param connection name
@return True if zone was set, else False
NFr   r   T)r	   r   r   r   Zset_propertyZcommit_changes)r   r   r   r   s   &&  r   nm_set_zone_of_connectionr   l   sj     
/
0
0
<C
{,,.KrzVT*dD))r   c                s   V P                  4        VP                  4        \        4        \        4       P                  4       pV Fv  pVP	                  4       '       d   K  VP                  4       pVP                  4       pVP                  4       pWAV&   V F!  pVP                  4       pV'       g   K  WPV&   K#  	  Kx  	  R# )zbGet active connections from NM
@param connections return dict
@param connections_name return dict
N)	Zclearr	   r   get_active_connectionsget_vpnZget_idget_uuidget_devicesget_ip_iface)	ZconnectionsZconnections_nameZactive_connections
active_connameZuuidZdevicesdevip_ifaces	   &&       r   nm_get_connectionsr(      s     &??A(
  """$((*!%C'')Hx(,H%  )r   c                 s4   \        4        . p \        4       P                  4        F  pVP                  4       '       d   K   VP	                  4       pVP                  4       \        P                  P                  \        P                  P                  ,          ,          '       d   K   VP                  4        F.  pVP                  4       pV'       g   K  V P                  V4       K0  	  K  	  V #   \         d    XP                  4       '       d    K   Lni ; i)z?Get active interfaces from NM
@returns list of interface names
)r	   r   r   r    get_connectionr   r   r   r   r   r   r   r"   r#   append)Zactive_interfacesr$   r   r&   r'   s        r   nm_get_interfacesr+      s    
 #o<<>
	++-C}}**77,,889  	 ))+C'')Hx!((2 ,% ?.   	    !	s   A#C00 DDc                 s    . p\        4        F1  p\        V4      pV \        V4      8X  g   K   VP                  V4       K3  	  V# )N)r+   nm_get_connection_of_interfacer   r*   )r   Z
interfaces	interfaceZconnr   r   nm_get_interfaces_in_zoner.      sB    J&(	-i8,T22i( )
 r   c                s    \        4        \        4       P                  4        F#  pVP                  4       pVf   K  W 8X  g   K!  Vu # 	  R# )znGet device from NM which has the given IP interface
@param interface name
@returns NM.Device instance or None
N)r	   r   r"   r#   )r-   devicer'   s   &  r   nm_get_device_by_ip_ifacer0      sF    
 /--/&&( M 0 r   c                s   \        4        \        V 4      pVf   R# VP                  4       pVf   R#  VP                  4       pVP	                  4       \
        P                  P                  ,          '       d   R#  VP                  4       #   \         d,    XP                  4       '       d    R#  TP                  4       # i ; i)z}Get connection from NM that is using the interface
@param interface name
@returns connection that is using interface or None
N)r	   r0   Zget_active_connectionr)   r   r   r   r   r   r   r!   )r-   r/   r$   r   r   r   r,   r,      s    
 &y1F~--/J'')==?R77DDDD E      ??    s   AB  C Cc                  s   \         '       g   R #  \        P                  ! 4       p V P                  \        P
                  \        P                  4      pVP                  p?? V#   \         d    \        P                  ! R4        R # i ; i)Nz(Failed to get bus name of NetworkManager)r   dbusZ	SystemBusZ
get_objectr   DBUS_INTERFACEZ	DBUS_PATHZbus_nameZ	Exceptionr   Zdebug2)ZbusZobjr%   s      r   nm_get_bus_namer3      sg    <?nnnnR..=|| ?

=>?s   AA# #!BBc                  s>    \         '       g   R # \        P                  # )r   )r   r   r2   r   r   r   nm_get_dbus_interfacer4     s    <r   )Z__doc__ZgiZgi.repositoryr    Zrequire_versionr   r   ZImportErrorZ
ValueErrorZErrorr   r   Zfirewallr   Zfirewall.errorsr   Zfirewall.core.loggerr   r1   r	   r
   r   r   r   r(   r+   r.   r0   r,   r3   r4   r   r   r   <module>r5      s    / 	 
tU#$ 
   ) $ M:B*,-: F"!8c TZZ0   Ls"   B A* *BB	BB