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/iproute/__pycache__/bsd.cpython-311.pyc
�

�;f%)���dZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
mZddlm
Z
mZmZddlmZmZddlmZmZmZmZdd	lmZdd
lmZmZmZmZmZm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&m'Z'dd
l(m)Z)ddl*m+Z+ddl,m-Z-	ddl.Z.n#e/$rddl0Z.YnwxYwGd�de1��Z2Gd�de2��Z3Gd�d��Z4dS)a�
The library provides very basic RTNL API for BSD systems
via protocol emulation. Only getters are supported yet, no
setters.

BSD employs PF_ROUTE sockets to send notifications about
network object changes, but the protocol doesn not allow
changing links/addresses/etc like Netlink.

To change network setting one have to rely on system calls
or external tools. Thus IPRoute on BSD systems is not as
effective as on Linux, where all the changes are done via
Netlink.

The monitoring started with `bind()` is implemented as an
implicit thread, started by the `bind()` call. This is done
to have only one notification FD, used both for normal calls
and notifications. This allows to use IPRoute objects in
poll/select calls.

On Linux systems RTNL API is provided by the netlink protocol,
so no implicit threads are started by default to monitor the
system updates. `IPRoute.bind(...)` may start the async cache
thread, but only when asked explicitly::

    #
    # Normal monitoring. Always starts monitoring thread on
    # FreeBSD / OpenBSD, no threads on Linux.
    #
    with IPRoute() as ipr:
        ipr.bind()
        ...

    #
    # Monitoring with async cache. Always starts cache thread
    # on Linux, ignored on FreeBSD / OpenBSD.
    #
    with IPRoute() as ipr:
        ipr.bind(async_cache=True)
        ...

On all the supported platforms, be it Linux or BSD, the
`IPRoute.recv(...)` method returns valid netlink RTNL raw binary
payload and `IPRoute.get(...)` returns parsed RTNL messages.
�N)�config)�
IFF_VALUES)�	RTMSocket)�ARP�Ifconfig�Route)�AddrPool�	Namespace)�
NLM_F_DUMP�NLM_F_MULTI�
NLM_F_REQUEST�
NLMSG_DONE)�NetlinkProxy)�RTM_GETADDR�RTM_GETLINK�RTM_GETNEIGH�RTM_GETROUTE�RTM_NEWADDR�RTM_NEWLINK�RTM_NEWNEIGH�RTM_NEWROUTE)�	ifaddrmsg)�	IFF_NAMES�ifinfmsg)�MarshalRtnl)�ndmsg)�rtmsgc��eZdZd�Zd�Zd�Zd�Zejfd�Z	d�Z
d�Zd�Zd	�Z
dd�Zd�Zd
�Zdd�Zd�Zd�Zd�Zd�Zd
S)�IPRoutec�\�d|vrd|�d��g|_ng|_|�d��}t|jddgz���|_t|jddgz���|_t|jdd	gz���|_t��|_
|�d
��pd|_t|tdd
��dd���}td|���|_d|_d|_d|_t'j��\|_|_t'j��\|_|_t3j|pt6j���|_t=j��|_ t=j!��|_"dS)N�ssh�async_qsize�ifconfigz-a)�cmd�arpz-an�netstatz-rn�target�	localhostii��F)�	addr_pool�monitor�return)�policy�nl)�maxsize)#�pop�_ssh�getr�_ifcr�_arpr�_router�marshalr'r
r	r�_sproxy�_mon_th�_rtm�_brd_socket�os�pipe�_pfdr�_pfdw�_ctlr�_ctlw�queue�Queuerr"�_outq�	threading�Lock�_system_lock�Event�closed)�self�argv�kwargr"�send_nss     �G/opt/alt/python311/lib/python3.11/site-packages/pyroute2/iproute/bsd.py�__init__zIPRoute.__init__Ssr���E�>�>���	�	�%� 0� 0�1�D�I�I��D�I��i�i�
�.�.�����j�$�-?�!?�@�@�@��	��D�I����6�7�7�7��	���	�Y��,>� >�?�?�?���"�}�}����i�i��)�)�8�[�������'� :� :�u�M�M�
�
��$�8��@�@�@��������	����!#������
�D�J�!#������
�D�J��[��)J��8J�K�K�K��
�%�N�,�,����o�'�'�����c��|S�N��rHs rL�	__enter__zIPRoute.__enter__k����rNc�.�|���dSrP)�close)rH�exc_type�	exc_value�	tracebacks    rL�__exit__zIPRoute.__exit__ns���
�
�����rNc��|SrPrQrRs rL�clonez
IPRoute.cloneqrTrNc
��|j5|j���r	ddd��dS|j�Lt	j|jd��|j���|j�	��|dkr3|j
�tj
ddddd|dd����t	j|jd��|j|j|j|jfD]'}	t	j	|���#t"$rY�$wxYw|j���ddd��dS#1swxYwYdS)N�r�IHHQIQQ��)rErG�is_setr7r:�writer?�joinr8rVrB�put�struct�packr=r<r>�OSError�set)rH�code�eps   rLrVz
IPRoute.closets���
�
�	�	��{�!�!�#�#�
��	�	�	�	�	�	�	�	��|�'�����U�+�+�+���!�!�#�#�#��	���!�!�!��a�x�x��
���v�{�9�b�!�Q��4��A�N�N�O�O�O��H�T�Z��'�'�'��z�4�:�t�z�4�:�F�
�
����H�R�L�L�L�L�������D������K�O�O����#	�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	�	s;�D>�CD>�3D�D>�
D�D>�D�D>�>E�Ec�@�|j5|j�	ddd��dS|jr	ddd��dStj|jd���|_|j�d��|j���ddd��dS#1swxYwYdS)NzPF_ROUTE monitoring)r'�nameT)rEr7r0rC�Thread�_monitor_thread�	setDaemon�start�rHrIrJs   rL�bindzIPRoute.bind�s)��
�
�	!�	!��|�'��	!�	!�	!�	!�	!�	!�	!�	!��y�
��	!�	!�	!�	!�	!�	!�	!�	!�%�+��+�2G����D�L�
�L�"�"�4�(�(�(��L��� � � �	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!�	!����	!�	!�	!�	!�	!�	!s�	B�B�AB�B�Bc���td���|_|j���|jg}g}		t	j|||��\}}}n#Y�!xYw|D]�}||jkrtj|jd��dS|j���}|�M|���|j	�
|j��tj|j
d������)N�netlink)�outputT�r^)rr8�filenor>�selectr:�readr1�encoderBre�datarcr=)rH�inputs�outputs�events�_�fd�msgs       rLrozIPRoute._monitor_thread�s����Y�/�/�/��	��)�"�"�$�$�d�j�1����	4�
�%�}�V�W�f�E�E����1�1��
�������
4�
4�����#�#��G�D�J��*�*�*��F�F��)�-�-�/�/�C����
�
�����
���s�x�0�0�0�����U�3�3�3��'	4s�A�Ac��|jSrP)r<rRs rLrxzIPRoute.fileno�s��
�z�rNc�^�|���}|j�|��SrP)�recvr5�parse)rHr|s  rLr1zIPRoute.get�s%���y�y�{�{���|�!�!�$�'�'�'rNNc�h�tj|jd��|j���S)Nrw)r:rzr<rBr1)rH�bufsizes  rLr�zIPRoute.recv�s(��
���
�A�����z�~�~���rNc��dS)NirQrrs   rL�
getsockoptzIPRoute.getsockopt�s���{rNc�P�|dd}|dd}|dd}|ttzkrdS|tkrt}|���}nt|t
krt}|���}nM|tkrt}|�
��}n&|tkrt}|�
��}|D](}||dd<t|dd<||dd<�)t|����}t |dd<||dd<|�|��d}	|D] }|���|	|jz
}	�!|j�|	��t-j|jd��dS)N�header�type�flags�sequence_numberrNr^)r
rrr�	get_linksrr�get_addrrr�
get_routesrr�get_neighboursrr�r�appendr{r|rBrer:rcr=)
rHr��addrr$r��seq�rtype�ret�rr|s
          rL�sendto_gatezIPRoute.sendto_gate�s����(�m�F�#���H�
�g�&���(�m�-�.���M�J�.�.�.��F��+����E��.�.�"�"�C�C�
�K�
�
��E��-�-�/�/�C�C�
�L�
 �
 � �E��/�/�#�#�C�C�
�L�
 �
 � �E��%�%�'�'�C��	1�	1�A�"'�A�h�K���#.�A�h�K�� �-0�A�h�K�)�*�*�
�D��I�I�K�K��(��(��F��),��(��%�&��
�
�1�
�
�
����	�	�A�
�H�H�J�J�J��A�F�N�D�D��
���t����
����U�#�#�#�#�#rNc#�fK�|j|j|j|jfD]}|��D]}|V���dS)zJ
        Iterate all the objects -- links, routes, addresses etc.
        N)r�r�r�r�)rH�groups�methodr�s    rL�dumpzIPRoute.dump�s_����

�N��M����O�	
�	�	�F��v�x�x�
�
���	�	�	�	�
�
	�	rNc���g}|j���}|j�|��}|d���D]�\}}t	���|��}t|dd<|j|dd<|d=|d}	d}
tj��D]#\}}||	zr|tvr|
t|z}
�$|
|d<|�
|����|S)N�linksr�r�r'�valuer�r)r2�runr��itemsr�loadrr'rrr�)rHrIrJr�r|�parsedrm�specr�r��	new_flagsr�s            rLr�zIPRoute.get_linkss������y�}�}���������&�&�� ��/�/�/�1�1�	�	�J�D�$��*�*�/�/�$�'�'�C�$/�C��M�&�!�&*�k�C��M�(�#��G����L�E��I�)�/�1�1�
1�
1���t��5�=�1�T�Y�%6�%6���4��0�I��$�C��L��J�J�s�O�O�O�O��
rNc�l�g}|j���}|j�|��}|d���D]c\}}|D][}t	���|��}	t|	dd<|j|	dd<|	d=|�|	���\�d|S)N�addrsr�r�r'r�)	r2r�r�r�rr�rr'r�)
rHrIrJr�r|r�rm�specsr�r�s
          rLr�zIPRoute.get_addrs������y�}�}���������&�&��!�'�?�0�0�2�2�	 �	 �K�D�%��
 �
 ���k�k�&�&�t�,�,��(3��H�
�f�%�*.�+��H�
�h�'���L��
�
�3�����
 ��
rNc���|j�|j�����}|j�|j�����}g}|D]�}|d|dvr�|d|dd|d<t	���|��}t|dd<|j|dd<|d=|�|����|S)	N�ifnamer��index�ifindexr�r�r'r�)	r2r�r�r3rr�rr'r�)rHrIrJ�ifcr%r�r�r�s        rLr�zIPRoute.get_neighbours#s����i�o�o�d�i�m�m�o�o�.�.���i�o�o�d�i�m�m�o�o�.�.�����	�	�D��H�~�S��\�1�1��!�'�l�4��>�:�7�C�D��O��'�'�,�,�t�$�$�C�$0�C��M�&�!�&*�k�C��M�(�#��G���J�J�s�O�O�O�O��
rNc��|j�|j�����}|j�|j�����}g}|D]�}|d|dvr�|d|dd}|d�d|g��t���|��}t|dd<|j|dd<|d	=|�|����|S)
Nr�r�r��attrs�RTA_OIFr�r�r'r�)	r2r�r�r4r�rr�rr')	rHrIrJr��rtar�r��idxr�s	         rLr�zIPRoute.get_routes2s����i�o�o�d�i�m�m�o�o�.�.���k������� 1� 1�2�2�����		�		�D��H�~�S��\�1�1���g�,�t�H�~�.�w�7�C���M� � �)�S�!1�2�2�2��'�'�,�,�t�$�$�C�$0�C��M�&�!�&*�k�C��M�(�#��G���J�J�s�O�O�O�O��
rNrP)�__name__�
__module__�__qualname__rMrSrZr\�errno�
ECONNRESETrVrsrorxr1r�r�r�r�r�r�r�r�rQrNrLrrRs+������(�(�(�0����������)�����(!�!�!�4�4�4�6���(�(�(� � � � ����.$�.$�.$�d�������$���
�
�
�����rNrc��eZdZdS)�
RawIPRouteN)r�r�r�rQrNrLr�r�Cs�������DrNr�c��eZdZd�ZdS)�ChaoticIPRoutec��t���rP)�NotImplementedErrorrrs   rLrMzChaoticIPRoute.__init__Hs��!�#�#�#rNN)r�r�r�rMrQrNrLr�r�Gs#������$�$�$�$�$rNr�)5�__doc__r�r:ryrfrC�pyroute2r�pyroute2.bsd.pf_router�pyroute2.bsd.rtmsocketr�pyroute2.bsd.utilrrr�pyroute2.commonr	r
�pyroute2.netlinkrrr
r�pyroute2.netlink.proxyr�pyroute2.netlink.rtnlrrrrrrrr�pyroute2.netlink.rtnl.ifaddrmsgr�pyroute2.netlink.rtnl.ifinfmsgrr�pyroute2.netlink.rtnl.marshalr�pyroute2.netlink.rtnl.ndmsgr�pyroute2.netlink.rtnl.rtmsgrr@�ImportErrorrA�objectrr�r�rQrNrL�<module>r�sv��,�,�\
����	�	�	�	�
�
�
�
�
�
�
�
�����������,�,�,�,�,�,�,�,�,�,�,�,�2�2�2�2�2�2�2�2�2�2�/�/�/�/�/�/�/�/�O�O�O�O�O�O�O�O�O�O�O�O�/�/�/�/�/�/�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�	�6�5�5�5�5�5�>�>�>�>�>�>�>�>�5�5�5�5�5�5�-�-�-�-�-�-�-�-�-�-�-�-���L�L�L�L����������������n�n�n�n�n�f�n�n�n�b	�	�	�	�	��	�	�	�$�$�$�$�$�$�$�$�$�$s�B�	B�B