HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb/__pycache__/source.cpython-311.pyc
�

�;f?B��`�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddlm
Z
ddlmZddlmZddlmZddlmZd	d
lmZmZd	dlmZmZmZej�d��rdd
lm Z ddl!m"Z"ddl#m$Z$ndZ$dZ"d	Z%dZ&Gd�de'��Z(Gd�de)��Z*dS)aa	

Local RTNL
----------

Local RTNL source is a simple `IPRoute` instance. By default NDB
starts with one local RTNL source names `localhost`::

    >>> ndb = NDB()
    >>> ndb.sources.summary().format("json")
    [
        {
            "name": "localhost",
            "spec": "{'target': 'localhost', 'nlm_generator': 1}",
            "state": "running"
        },
        {
            "name": "localhost/nsmanager",
            "spec": "{'target': 'localhost/nsmanager'}",
            "state": "running"
        }
    ]
    >>> ndb.sources['localhost']
    [running] <IPRoute {'target: 'localhost', 'nlm_generator': 1}>

The `localhost` RTNL source starts an additional async cache thread.
The `nlm_generator` option means that instead of collections the
`IPRoute` object returns generators, so `IPRoute` responses will not
consume memory regardless of the RTNL objects number::

    >>> ndb.sources['localhost'].nl.link('dump')
    <generator object RTNL_API.filter_messages at 0x7f61a99a34a0>

See also: :ref:`iproute`

Network namespaces
------------------

There are two ways to connect additional sources to an NDB instance.
One is to specify sources when creating an NDB object::

    ndb = NDB(sources=[{'target': 'localhost'}, {'netns': 'test01'}])

Another way is to call `ndb.sources.add()` method::

    ndb.sources.add(netns='test01')

This syntax: `{target': 'localhost'}` and `{'netns': 'test01'}` is the
short form. The full form would be::

    {'target': 'localhost', # the label for the DB
     'kind': 'local',       # use IPRoute class to start the source
     'nlm_generator': 1}    #

    {'target': 'test01',    # the label
     'kind': 'netns',       # use NetNS class
     'netns': 'test01'}     #

See also: :ref:`netns`

Remote systems
--------------

It is possible also to connect to remote systems using SSH. In order to
use this kind of sources it is required to install the
`mitogen <https://github.com/dw/mitogen>`_ module. The `remote` kind
of sources uses the `RemoteIPRoute` class. The short form::

    ndb.sources.add(hostname='worker1.example.com')


In some more extended form::

    ndb.sources.add(**{'target': 'worker1.example.com',
                       'kind': 'remote',
                       'hostname': 'worker1.example.com',
                       'username': 'jenkins',
                       'check_host_keys': False})

See also: :ref:`remote`
�N)�
basestring)�IPRoute)�NetlinkError)�NetlinkSocketBase)�ifinfmsg)�
RemoteIPRoute�)�ShutdownException�State)�
cmsg_event�cmsg_failed�cmsg_sstart�linux)�netns)�NetNSManager)�NetNS�c��eZdZd�Zd�ZdS)�SourceProxyc�R�||_tj��|_||_dS�N)�ndb�queue�Queue�events�target)�selfrrs   �F/opt/alt/python311/lib/python3.11/site-packages/pyroute2/ndb/source.py�__init__zSourceProxy.__init__ts!������k�m�m��������c	��ttj��j��}t	j��x|jj|<}|���|jj	�
d|j||||d���|���|jj�
|��}d|vr|dSd|vr|d�dS)N�api)�typer�call_id�name�argv�kwarg�return�	exception)�str�uuid�uuid4�hex�	threading�Eventr�_call_registry�clear�	messenger�emitr�wait�pop)rr%r&r'r$�event�responses       rr"zSourceProxy.apiys����d�j�l�l�&�'�'��3<�?�3D�3D�D�����(�5�
���
�
�
��H��#�#�!�"�k�&� � �"�
��	
�	
�	
�	�
�
�����8�*�.�.�w�7�7���x����H�%�%�
�H�
$�
$��;�'�'�%�
$r N)�__name__�
__module__�__qualname__rr"�r rrrss2���������
(�(�(�(�(r rc�`�eZdZdZdZdZdZdZdZe	e
eed�Z
d�Zed���Zed���Zed	���Zd
�Zed���Zd�Zed
���Zed���Zed���Zed���Zed���Zd�Zd�Zd�Zd�Zd�Z d�Z!e"j#dfd�Z$dd�Z%d�Z&d�Z'd�Z(dS) �Sourcez�
    The RNTL source. The source that is used to init the object
    must comply to IPRoute API, must support the async_cache. If
    the source starts additional threads, they must be joined
    in the source.close()
    �srcN�sources)�localr�remote�	nsmanagerc��d|_d|_||_|jj|_|d|_|�dd��|_|�dt��|_	|�d��|_
|�|j��|_||_
|jj�)|jjj�|j��d|_t%j��|_t%j��|_t%j��|_t%j��|_|j���|j�d|jz��|_t9|jdg�	��|_|j�d
��|jj� |j|j|��|�!��dS)Nr�kindr@�
max_errorsr6rz
sources.%s�running)�log�	wait_list�init)"�th�nlr�_event_queue�evqrr5rD�SOURCE_MAX_ERRORSrEr6�	get_prime�nl_prime�nl_kwargr2�targets�add�errors_counterr.r/�shutdown�started�RLock�lock�
shutdown_lockr1rG�channelr�state�set�task_manager�db_add_nl_source�load_sql)rr�specs   rrzSource.__init__�s�������������8�(����8�n����H�H�V�W�-�-��	��(�(�<�1B�C�C����X�X�g�&�&��
����t�y�1�1��
���
��8��)��H��&�*�*�4�;�7�7�7����!��)�)��
� ��(�(����O�%�%��	�&�_�.�.�����������7�?�?�<�$�+�#=�>�>����t�x�I�;�?�?�?��
��
���v�������.�.�t�{�D�I�t�L�L�L��
�
�����r c�P�|jj�d|jz��S)NzSELECT count(*) FROM %s)rr]�db_fetchone�table��cls�views  r�_countz
Source._count�s)���x�$�0�0�%��
�2�
�
�	
r c�@�|jdks|j|jkrdSdS)NrTF)rErT�rs r�must_restartzSource.must_restart�s(���?�Q���$�"5���"H�"H��4��ur c�x�ttd�ddd|j�d��ff����S)Nc��|dduS)Nr	r;)�xs r�<lambda>z'Source.bind_arguments.<locals>.<lambda>�s��!�A�$�d�*�r )�async_cacheT)�clone_socketT�groups)�dict�filterrQ�getris r�bind_argumentszSource.bind_arguments�sJ����*�*�)�*��t�}�0�0��:�:�;��
�
�	
�	
�		
r c�L�	|j�;|j�t|j|j��f|j���n4|j�t|j��f|j���n+#t$r|j�d��YdSwxYwdS)N��source�stopFT)	r6rM�putrrrr
r[r\ris r�	set_readyzSource.set_ready�s���		��z�%��������T�Z�8�8�:�4�;����������k�$�+�6�6�8����M�M�M��� �	�	�	��J�N�N�6�"�"�"��5�5�	�����ts�A6A9�9$B!� B!c���t|��}i}d|vrd|d<d|d<|d|d<d|vr-d|d<|d|d<tj|d��|d<|D]}||vr||||<�|S)N�hostnamerArD�ssh�protocolrr)rrr�_get_netnspath)rer`�ret�defaults�keys     rr�zSource.defaults�s����4�j�j��������'�H�V��#(�H�Z� �!%�j�!1�H�X���d�?�?�&�H�V��!%�g��H�X�� �/��W�
�>�>�C��L��	)�	)�C��#�~�~�#�C�=��C����
r c��t|jt��r|jjj}n&t|jt
��r|jj}d|j����d|�d|j�d�S)N�[z] <� �>)	�
isinstancerPr�	__class__r8r#r[rtrQ�rr%s  r�__repr__zSource.__repr__�sn���d�m�%6�7�7�	*��=�*�3�D�D�
��
�t�
,�
,�	*��=�)�D��!%����!1�!1�!1�!1�4�4�4�����G�Gr c��|Srr;�rer%s  r�nla2namezSource.nla2name����r c��|Srr;r�s  r�name2nlazSource.name2nlar�r c#�K�dV�|���D]2}||j���|||j�fV��3dS)N)r[r%r`)�keysr[rtrQ)rerfr�s   r�summaryzSource.summary
si����'�'�'�'��9�9�;�;�	M�	M�C���9�?�&�&�(�(�#�t�C�y�7I�7I�L�L�L�L�L�	M�	Mr c�,�|�|��Sr)r�rds  r�dumpzSource.dumps���{�{�4� � � r c�H�t|t��r||dkSdS)Nr%)r�r)r�left�rights   r�compare_recordzSource.compare_records/���e�Z�(�(�	)��D��L�(�(�	)�	)r c��|j�|jd��p&tt	jd��|j��S)N�pyroute2)�vmaprtrD�getattr�	importlib�
import_moduler�s  rrOzSource.get_primes?���y�}�}�T�Y��-�-�
���#�J�/�/���2
�2
�	
r c�F�td��D�]}|j5	|j�d|�d|�d|����t	|j|��|i|��cddd��cS#ttttttjtjf$r�t$rL}|xjdz
c_|j�d|�d���t!jd��Yd}~nd}~wwxYw	ddd��n#1swxYwY��t%d���)N�dzsource api run r�r	zsource api error: <r�zapi call failed)�rangerXrG�debugr�rKr�AttributeError�
ValueError�KeyError�	TypeError�socket�error�struct�	ExceptionrT�time�sleep�RuntimeError)rr%r&r'�_�es      rr"z
Source.apis����s���	"�	"�A���
"�
"�"��H�N�N�#J�T�#J�#J�D�#J�#J�5�#J�#J�K�K�K�1�7�4�7�D�1�1�4�A�5�A�A�
"�
"�
"�
"�
"�
"�
"�
"�
"�
"��
!�"�����L��L��	�	�	�� �"�"�"��'�'�1�,�'�'��H�N�N�#=��#=�#=�#=�>�>�>��J�q�M�M�M�M�M�M�M�M�����	"����"�%
"�
"�
"�
"�
"�
"�
"�
"�
"�
"�
"����
"�
"�
"�
"��&�,�-�-�-s6�D�=A(�(AC7�+AC2�-D�2C7�7D�D	�D	c��d}t��}d|d<d|d<d|d<d|d	d<d
|d	d<|j|d	d<d
|d<d|fdg|d<|���|j�|g|j���dS)Nz.https://github.com/svinota/pyroute2/issues/737r�index�upr[r	�flags��header�r#r�RTM_NEWLINKr6�IFLA_IFNAME)�IFLA_ADDRESSz00:00:00:00:00:00�attrsrw)rr�encoderMrz)r�url�zero_ifs   r�fake_zero_ifzSource.fake_zero_if6s���>���*�*��������������%&����'�"�$&����&�!�&*�k����(�#�(����
�C� �1�
����	����������g�Y�t�{��3�3�3�3�3r c�
�|j���dk�r'|j���r�n|j5|j�Q	|j�d���n4#t$r'}|j�	d|z��Yd}~nd}~wwxYw	|j�
d��t|jt��rGi}|�|j��|jdvr|jj|d<|jdi|��|_nt'd���|j�
d	��|jjdi|j��	|jj�|j��|jd
vr|���|j�|j���|j���n#wxYwd|_�n�#t$�r�}|xjdz
c_|j�
��|j�
d
|j����|j�dt|���d|����	|j�tA|j��f|j���n:#tB$r-|j�
d��YYd}~ddd���nxwxYw|j"r�|j�#d��|j�
d��|j�$tJ��|j���rE|j�#d��|j�
d��Yd}~ddd���n�n%|�&��cYd}~cddd��SYd}~ddd�����d}~wwxYw	ddd��n#1swxYwY|j5|j���d	krn|�&��s	ddd���n|j�
��|j�'��|j�
d��ddd��n#1swxYwY|j���dv�r�	tQ|j�����}n�#t$r�}|xjdz
c_|j�dt|���d|����d}|j"r|j�
d��n|j�
d��Yd}~n�d}~wwxYwd}|r-|dddr|dddj)}|�|tTj+kr|j�
d��ni	|j�||j���n*#tB$r|j�
d��Yn wxYw|j���dv���|j���dk��'	|�,��|j�#d��|jj�|j��n*#tB$r|j�#d��YnwxYw|j�
d��dS)Nryr��codezsource restart: %s�
connecting)rB�libczsource channel not supported�loading)r@rrArwr	zfailed, counter zsource error: r�zsleeping before restart�restart�source shutdownrF)ryr�r�r�zflush DB for the targetz#shutdown handled by the main thread�stoppedr;)-r[rtrU�is_setrXrK�closer�rG�warningr\r�rPr#�updaterQrDrr�r��bindrur]�db_flushrr�rMrzr�rTrVr�r
r
rjr�r4�SOURCE_FAIL_PAUSEr{r1�tupler��errno�
ECONNRESET�sync)rr�r`�msgr�s     r�receiverzSource.receiverGs����j�n�n���&�(�(��}�#�#�%�%�
����4
�4
��7�&�C���
�
�1�
�-�-�-�-��$�C�C�C���(�(�)=��)A�B�B�B�B�B�B�B�B�����C����.��J�N�N�<�0�0�0�!�$�-��6�6�H�!�����D�M�2�2�2��9��6�6�+/�8�=�D��L�"/�$�-�"7�"7�$�"7�"7����'�(F�G�G�G��J�N�N�9�-�-�-� �D�G�L�7�7�4�#6�7�7�7����-�6�6�t�{�C�C�C��9�(D�D�D� �-�-�/�/�/�����T�W�\�\�^�^�D�K��H�H�H�������*+�D�'�'�� �����'�'�1�,�'�'��L�$�$�&�&�&��J�N�N�#K�d�6I�#K�#K�L�L�L��H�N�N�#A�D��G�G�#A�#A�a�#A�#A�B�B�B������(���5�5�7���%������-�����
���v�.�.�.������S4
�4
�4
�4
�4
�4
�4
�N�����(�	0�����'@�A�A�A��
���y�1�1�1��
�*�*�+<�=�=�=��=�/�/�1�1�"� �H�N�N�+<�=�=�=� �J�N�N�6�2�2�2�!�E�E�E�c4
�4
�4
�4
�4
�4
�4
�\"�
 $�~�~�/�/�/�/�/�/�/�g4
�4
�4
�4
�4
�4
�4
�4
�h�H�H�H�i4
�4
�4
�4
�4
�4
�4
�����<����(�;4
�4
�4
�4
�4
�4
�4
�4
�4
�4
�4
����4
�4
�4
�4
�l��
.�
.��:�>�>�#�#�y�0�0��>�>�+�+���
.�
.�
.�
.�
.�
.�
.��L�$�$�&�&�&��M�'�'�)�)�)��J�N�N�9�-�-�-�

.�
.�
.�
.�
.�
.�
.�
.�
.�
.�
.����
.�
.�
.�
.��*�.�.�"�"�*=�=�=�
������
�
�.�.�C�C�� �����'�'�1�,�'�'��H�N�N�N�D��G�G�G�G�Q�Q�#G�H�H�H��C��(�/��
���y�1�1�1�1��
���v�.�.�.��E�E�E�E������������:�3�q�6�(�+�G�4�:��q�6�(�+�G�4�9�D��;�$�%�*:�":�":��J�N�N�6�*�*�*����H�L�L��T�[�L�9�9�9�9��(�����J�N�N�6�*�*�*��E�����/�*�.�.�"�"�*=�=�=�E�j�n�n���&�(�(�@	��I�I�K�K�K��H�N�N�4�5�5�5��H�!�*�*�4�;�7�7�7�7�� �	�	�	��H�N�N�@�A�A�A��D�	����	
�
���y�!�!�!�!�!s�O�
A&�%O�&
B�0B�
O�B�O�B;G�A9G�G�G�
G�O�O�*A8O�#4J�O�$K�<O�=O�K�B*O�9O�
O�O�O�0O�O�O�O�O�(3R�(AR�R�R�(&S�
U�A;U�U�!W"�"$X	�X	�AZ�$[�[c���|j�d��tj��}|j�t
|j|��f|j���|���dS)Nr�rw)	rGr�r.r/rMrzrrr4)rr�s  rr�zSource.sync�s]������v������ � ������j���d�3�3�5�d�k��J�J�J��	�	�����r c�\�|j5|j�d��|j�(|j���rtd���t
j|jd|j	z���|_|j�
��|cddd��S#1swxYwYdS)Nzstarting the sourcezsource is runningzNDB event source: %s)rr%)rXrGr�rJ�is_aliver�r.�Threadr�r�startris rr�zSource.start�s����Y�
	�
	��H�N�N�0�1�1�1���#���)9�)9�);�);�#�"�#6�7�7�7��&��}�+�t�{�;����D�G�
�G�M�M�O�O�O��
	�
	�
	�
	�
	�
	�
	�
	�
	�
	�
	�
	����
	�
	�
	�
	�
	�
	s�BB!�!B%�(B%Tc�j�|j5|j���r(|j�d��	ddd��dS|j�d��|j���|j�Q	|j�|���n4#t$r'}|j�	d|z��Yd}~nd}~wwxYwddd��n#1swxYwY|rE|j
�"|j
���d|_
dS|j�d��dSdS)Nzalready stoppedr�r�zsource close: %szreceiver thread missing)rYrUr�rGr�r\rKr�r�r�rJ�join)rr�r�r�s    rr�zSource.close�s���
�
�
	;�
	;��}�#�#�%�%�
�����0�1�1�1��
	;�
	;�
	;�
	;�
	;�
	;�
	;�
	;�
�H�N�N�,�-�-�-��M�������w�"�;��G�M�M�t�M�,�,�,�,�� �;�;�;��H�N�N�#5��#9�:�:�:�:�:�:�:�:�����;����
	;�
	;�
	;�
	;�
	;�
	;�
	;�
	;�
	;�
	;�
	;����
	;�
	;�
	;�
	;��	:��w�"�����������������8�9�9�9�9�9�	:�	:sA�5C!�
:C!�B!� C!�!
C�+C
�C!�
C�C!�!C%�(C%�unknownc���|j5|j5|j�d|z��|j���	|���|jr|j���|j	���|�
��n#wxYw	ddd��n#1swxYwYddd��n#1swxYwY|j���dS)Nz"restarting the source, reason <%s>)rXrYrGr�rVr1r�rJr�rUr�r4)r�reasons  rr�zSource.restart�sa��
�Y�	�	��#�

�

�����C�v�N�O�O�O���"�"�$�$�$���J�J�L�L�L��w�'���������M�'�'�)�)�)��J�J�L�L�L���D�D�D�D�D�

�

�

�

�

�

�

�

�

�

�

����

�

�

�

�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	
��������sM�C�7B<�A!B*�)B<�*B,�,B<�0C�<C	�C�C	�C�C�Cc��|Srr;ris r�	__enter__zSource.__enter__�s���r c�.�|���dSr)r�)r�exc_type�	exc_value�	tracebacks    r�__exit__zSource.__exit__�s���
�
�����r c�D�|jj�d|jjjz|jf��}|\|d<|d<|jj�d|jjjz|jf��D]#}|\}}}}|dkrt|��n|||<�$dS)Nz�
                                        SELECT * FROM sources
                                        WHERE f_target = %s
                                        rrDz�
                                          SELECT * FROM sources_options
                                          WHERE f_target = %s
                                          �int)rr]rb�schema�plchr�db_fetchr�)rr`�f_target�f_name�f_type�f_values      rr_zSource.load_sql�s����x�$�0�0�
,��h�o�"�	
#�
�[�N�

�
��(,�$��X���V���H�)�2�2�
.��h�o�"�	
#�
�[�N�

�
�		H�		H�D�15�-�H�f�f�g�+1�U�?�?�3�w�<�<�<��D��L�L�		H�		Hr )r�))r8r9r:�__doc__�table_alias�dump_header�summary_headerrfrcrrrrr�r�classmethodrg�propertyrjrur{r�r�r�r�r�r�r�rOr"r�r�r�r�r�r�r�r�r�r�r_r;r rr=r=�s9���������K��K��N��D��E����!�	��D����:�
�
��[�
�
����X��
�

�

��X�

��������[�� H�H�H�����[������[���M�M��[�M�
�!�!��[�!��)�)��[�)�

�
�
�
.�.�.�.4�4�4�"n"�n"�n"�`���
�
�
��)��:�:�:�:�&
�
�
�
�������H�H�H�H�Hr r=)+r�r�r�rr�r��sysr.r�r+�pyroute2.commonr�pyroute2.iprouter�pyroute2.netlink.exceptionsr�pyroute2.netlink.nlsocketr�pyroute2.netlink.rtnl.ifinfmsgr�pyroute2.remoterrr
r�messagesrr
r�platform�
startswithr�r�pyroute2.netns.managerr�pyroute2.nslink.nslinkrr�rN�objectrrrr=r;r r�<module>rs���P�P�d
������������
�
�
�
�
�
�
�
�
�
�
�
�������������&�&�&�&�&�&�$�$�$�$�$�$�4�4�4�4�4�4�7�7�7�7�7�7�3�3�3�3�3�3�)�)�)�)�)�)�,�,�,�,�,�,�,�,�:�:�:�:�:�:�:�:�:�:��<���7�#�#��������3�3�3�3�3�3�,�,�,�,�,�,�,��E��L�����(�(�(�(�(�&�(�(�(�>vH�vH�vH�vH�vH�T�vH�vH�vH�vH�vHr