HOME


Mini Shell 1.0
DIR: /usr/lib/python3/dist-packages/twisted/pair/__pycache__/
Upload File :
Current File : //usr/lib/python3/dist-packages/twisted/pair/__pycache__/tuntap.cpython-312.pyc
�

Ϫ�f�1���dZddlZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZm
Z
mZddlmZmZddlmZddlmZmZmZmZmZdd	lmZmZdd
lmZddlm Z ddl!m"Z"dd
l#m$Z$m%Z%gd�Z&dZ'ejP�dk(s@ejP�jSd�s ejP�jSd�rdZ*dZ+ndZ*dZ+dZ,Gd�de�Z-eej\�Gd�de%e$��Z/Gd�dedd��Z0Gd�d e
�Z1Gd!�d"�Z2eejf�Gd#�d$ejh��Z5y)%zc
Support for Linux ethernet and IP tunnel devices.

@see: U{https://en.wikipedia.org/wiki/TUN/TAP}
�N)�
namedtuple)�Tuple)�	Attribute�	Interface�implementer)�FlagConstant�Flags)�Version)�abstract�defer�error�
interfaces�task)�ethernet�raw)�log)�
deprecated)�fullyQualifiedName)�FancyEqMixin�
FancyStrMixin)�TunnelFlags�
TunnelAddress�
TuntapPort��parisc�ppc�sparcl�Ti�T@i�T@l�Ts/dev/net/tunc���eZdZdZed�Zed�Zed�Zed�Zed�Z	ed�Z
ed�Zed	�Zed
�Z
ed�Zed�Zed
�Zy)ra~
    L{TunnelFlags} defines more flags which are used to configure the behavior
    of a tunnel device.

    @cvar IFF_TUN: This indicates a I{tun}-type device.  This type of tunnel
        carries IP datagrams.  This flag is mutually exclusive with C{IFF_TAP}.

    @cvar IFF_TAP: This indicates a I{tap}-type device.  This type of tunnel
        carries ethernet frames.  This flag is mutually exclusive with C{IFF_TUN}.

    @cvar IFF_NO_PI: This indicates the I{protocol information} header will
        B{not} be included in data read from the tunnel.

    @see: U{https://www.kernel.org/doc/Documentation/networking/tuntap.txt}
    ��r� �@��ii� i@i�N)�__name__�
__module__�__qualname__�__doc__r�IFF_TUN�IFF_TAP�
TUN_FASYNC�TUN_NOCHECKSUM�	TUN_NO_PI�
TUN_ONE_QUEUE�TUN_PERSIST�TUN_VNET_HDR�	IFF_NO_PI�
IFF_ONE_QUEUE�IFF_VNET_HDR�IFF_TUN_EXCL���5/usr/lib/python3/dist-packages/twisted/pair/tuntap.pyrr6s���� �6�"�G��6�"�G��f�%�J�!�&�)�N��V�$�I� ��(�M��v�&�K���'�L��V�$�I� ��(�M���'�L���'�Lr7rc�>�eZdZdZdZdd�fdfZed��Zd�Zd�Z	y	)
rzU
    A L{TunnelAddress} represents the tunnel to which a L{TuntapPort} is bound.
    )�
_typeValue�name�typec��|jS�N)r;)�flags r8�<lambda>zTunnelAddress.<lambda>^s
��D�I�I�r7r;c�.�|jjS)z�
        Return the integer value of the C{type} attribute.  Used to produce
        correct results in the equality implementation.
        )r<�value��selfs r8r:zTunnelAddress._typeValue`s���y�y���r7c� �||_||_y)z�
        @param type: Either L{TunnelFlags.IFF_TUN} or L{TunnelFlags.IFF_TAP},
            representing the type of this tunnel.

        @param name: The system name of the tunnel.
        @type name: L{bytes}
        N)r<r;)rDr<r;s   r8�__init__zTunnelAddress.__init__is����	���	r7c�\�tjdtd��d|jf|S)zS
        Deprecated accessor for the tunnel name.  Use attributes instead.
        zUTunnelAddress.__getitem__ is deprecated since Twisted 14.0.0  Use attributes instead.r )�category�
stacklevel�TUNTAP)�warnings�warn�DeprecationWarningr;)rD�indexs  r8�__getitem__zTunnelAddress.__getitem__ts1��	�
�
�
&�'��		
��$�)�)�$�U�+�+r7N)
r&r'r(r)�compareAttributes�showAttributes�propertyr:rFrOr6r7r8rrWs;���/���5�6��?�N�
����	�
,r7rc��eZdZdZy)�_TunnelDescriptionz�
    Describe an existing tunnel.

    @ivar fileno: the file descriptor associated with the tunnel
    @type fileno: L{int}

    @ivar name: the name of the tunnel
    @type name: L{bytes}
    N)r&r'r(r)r6r7r8rTrT�s��r7rTzfileno namec�n�eZdZdZed�Zed�Zed�Zd
d�Zdd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy)�_IInputOutputSystemz�
    An interface for performing some basic kinds of I/O (particularly that I/O
    which might be useful for L{twisted.pair.tuntap}-using code).
    z@see: L{os.O_RDWR}z@see: L{os.O_NONBLOCK}z@see: L{os.O_CLOEXEC}c��y)z"
        @see: L{os.open}
        Nr6)�filenamer?�modes   r8�openz_IInputOutputSystem.open���r7Nc��y)z&
        @see: L{fcntl.ioctl}
        Nr6)�fd�opt�arg�mutate_flags    r8�ioctlz_IInputOutputSystem.ioctl�r[r7c��y)z"
        @see: L{os.read}
        Nr6)r]�limits  r8�readz_IInputOutputSystem.read�r[r7c��y)z#
        @see: L{os.write}
        Nr6)r]�datas  r8�writez_IInputOutputSystem.write�r[r7c��y)z#
        @see: L{os.close}
        Nr6)r]s r8�closez_IInputOutputSystem.close�r[r7c��y)a�
        Send a datagram to a certain address.

        @param datagram: The payload of a UDP datagram to send.
        @type datagram: L{bytes}

        @param address: The destination to which to send the datagram.
        @type address: L{tuple} of (L{bytes}, L{int})

        @return: The local address from which the datagram was sent.
        @rtype: L{tuple} of (L{bytes}, L{int})
        Nr6)�datagram�addresss  r8�sendUDPz_IInputOutputSystem.sendUDP�r[r7c��y)af
        Return a socket which can be used to receive datagrams sent to the
        given address.

        @param fileno: A file descriptor representing a tunnel device which the
            datagram was either sent via or will be received via.
        @type fileno: L{int}

        @param host: The IPv4 address at which the datagram will be received.
        @type host: L{bytes}

        @param port: The UDP port number at which the datagram will be
            received.
        @type port: L{int}

        @return: A L{socket.socket} which can be used to receive the specified
            datagram.
        Nr6)�fileno�host�ports   r8�
receiveUDPz_IInputOutputSystem.receiveUDP�r[r7)i�)NN)r&r'r(r)r�O_RDWR�
O_NONBLOCK�	O_CLOEXECrZrardrgrirmrrr6r7r8rVrV�sM���
�+�
,�F��3�4�J��1�2�I��
�
�
�
�
�r7rVc��eZdZdZeej�Zeej�Zeej�Zeej�Z	ee
j�ZejZejZ
eedd�Zy)�_RealSystemz�
    An interface to the parts of the operating system which L{TuntapPort}
    relies on.  This is most of an implementation of L{_IInputOutputSystem}.
    ruiN)r&r'r(r)�staticmethod�osrZrdrgri�fcntlrarsrt�getattrrur6r7r8rwrw�sq���
���� �D����� �D�����"�E�����"�E�����%�E�
�Y�Y�F����J���K��3�Ir7rwc��eZdZdZdZdd�Zdefd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zeedddd�e�d��Zdd�Zd�Zd�Zy)rzH
    A Port that reads and writes packets from/to a TUN/TAP-device.
    iNc��tjj|�rd|_tj|_n=d|_tj|_tjj|�sJ�|�
t�}||_
tjj||�||_||_||_|j#|j�}|�d|j
j$�d�|_y)Nrrz (�))r�IEthernetProtocol�
providedByrr+�_moder*r�IRawPacketProtocolrw�_systemr�FileDescriptorrF�	interface�protocol�
maxPacketSize�
_getLogPrefixr;�logstr)rDr��protor��reactor�system�	logPrefixs       r8rFzTuntapPort.__init__�s����%�%�0�0��7��D�M�$�,�,�D�J��D�M�$�,�,�D�J��)�)�4�4�U�;�;�;��>� �]�F�������(�(��w�7�"�����
�*����&�&�t�}�}�5�	�"��2�d�j�j�o�o�%6�a�8��r7�returnc���t|jj�f}|jr|dz}n|dz}||jj
|jfz}d|zS)N)�)znot z<%s %slistening on %s/%s>)rr��	__class__�	connectedr�r;r�)rD�argss  r8�__repr__zTuntapPort.__repr__sY��!3�D�M�M�4K�4K�!L� N���>�>��%�<�D��)�#�D��t�z�z������7�7��*�T�1�1r7c�z�|j�|jj|�|j�y)z�
        Create and bind my socket, and begin listening on it.

        This must be called after creating a server to begin listening on the
        specified tunnel.
        N)�_bindSocketr��makeConnection�startReadingrCs r8�startListeningzTuntapPort.startListenings.��	
�����
�
�$�$�T�*����r7c��|jj|jjz|jjz}t	j
dtfz||j�}|jjt|�}|jj|t|�}t||dtjd��S)af
        Open the named tunnel using the given mode.

        @param name: The name of the tunnel to open.
        @type name: L{bytes}

        @param mode: Flags from L{TunnelFlags} with exactly one of
            L{TunnelFlags.IFF_TUN} or L{TunnelFlags.IFF_TAP} set.

        @return: A L{_TunnelDescription} representing the newly opened tunnel.
        z%dsHN�)r�rsrurt�struct�pack�	_IFNAMSIZrBrZ�_TUN_KO_PATHra�
_TUNSETIFFrT�strip)rDr;rY�flags�configro�results       r8�_openTunnelzTuntapPort._openTunnels������#�#�d�l�l�&<�&<�<�t�|�|�?V�?V�V�����V�y�l�2�D�$�*�*�E�����"�"�<��7�����#�#�F�J��?��!�&�&��)�*<�*B�*B�7�*K�L�Lr7c�t�tjd|jj|j��	|j|j|jtjz�\}}||_||_d|_
y#t$r&}tjd|j|��d}~wwxYw)z"
        Open the tunnel.
        z&%(protocol)s starting on %(interface)s)�formatr�r�Nr)r�msgr�r�r�r�r�rr2�OSErrorr
�CannotListenError�_filenor�)rDror��es    r8r�zTuntapPort._bindSocket)s���	���;��]�]�,�,��n�n�	
�
	C� $� 0� 0�����
�
�[�-B�-B� B�!��F�I�#����������
�	C��)�)�$�����B�B��	C�s�:B�	B7�!B2�2B7c��|jSr>)r�rCs r8rozTuntapPort.fileno>s���|�|�r7c�H�d}||jkrn	|jj|j|j�}|t|�z
}	|jj|d��||jkr�myy#t
$rF}|jtjtjtjfvrYd}~y�d}~wt$r�wxYw#t$r<t|jj�}t!j"dd|�d��Y��wxYw)z=
        Called when my socket is ready for reading.
        rN)�partialzUnhandled exception from z.datagramReceived)�
maxThroughputr�rdr�r�r��errno�EWOULDBLOCK�EAGAIN�EINTR�
BaseException�lenr��datagramReceivedrr�r�err)rDrdrfr��clss     r8�doReadzTuntapPort.doReadAs������T�'�'�'�
��|�|�(�(����t�7I�7I�J��
�C��I��D�
R��
�
�.�.�t�Q�.�?��T�'�'�'���
��7�7�u�0�0�%�,�,����L�L���� �
��
��!�
R�(����)@�)@�A������ 9�#��>O�P�Q�
R�s0�0B�C�	C�
;C�
C�C�AD!� D!c���	|jj|j|�S#t$r9}|jtj
k(r|j|�cYd}~S�d}~wwxYw)z�
        Write the given data as a single datagram.

        @param datagram: The data that will make up the complete datagram to be
            written.
        @type datagram: L{bytes}
        N)r�rgr�r�r�r�)rDrkr�s   r8rgzTuntapPort.writeXsT��	��<�<�%�%�d�l�l�H�=�=���	��w�w�%�+�+�%��z�z�(�+�+���	�s �%(�	A*�-A%�A*�$A%�%A*c�D�|jdj|��y)z�
        Write a datagram constructed from a L{list} of L{bytes}.

        @param seq: The data that will make up the complete datagram to be
            written.
        @type seq: L{list} of L{bytes}
        r7N)rg�join)rD�seqs  r8�
writeSequencezTuntapPort.writeSequencegs��	
�
�
�3�8�8�C�=�!r7c��|j�|jr|jS|jrCt	j
|jd|j�|_d|_|jStjd�S)z�
        Stop accepting connections on this port.

        This will shut down my socket and call self.connectionLost().

        @return: A L{Deferred} that fires when this port has stopped.
        rTN)
�stopReading�
disconnecting�_stoppedDeferredr�r�
deferLaterr��connectionLostr�succeedrCs r8�
stopListeningzTuntapPort.stopListeningqss��	
��������(�(�(�
�^�^�$(�O�O����a��!4�!4�%�D�!�"&�D���(�(�(��=�=��&�&r7�Twisted�rc�^�|j�jtj�y)zN
        Close this tunnel.  Use L{TuntapPort.stopListening} instead.
        N)r��
addErrbackrr�rCs r8�loseConnectionzTuntapPort.loseConnection�s��
	
����'�'����0r7c�"�tjd|jz�tjj||�|jj�d|_|jj|j�d|_y)zY
        Cleans up my socket.

        @param reason: Ignored.  Do not use this.
        z(Tuntap %s Closed)r���N)rr�r�rr�r�r��doStopr�r�rir�)rD�reasons  r8r�zTuntapPort.connectionLost�sd��	���$�t�~�~�5�6����.�.�t�V�<��
�
������������4�<�<�(���r7c��|jS)zK
        Returns the name of my class, to prefix log entries with.
        )r�rCs r8r�zTuntapPort.logPrefix�s���{�{�r7c�B�t|j|j�S)z�
        Get the local address of this L{TuntapPort}.

        @return: A L{TunnelAddress} which describes the tunnel device to which
            this object is bound.
        @rtype: L{TunnelAddress}
        )rr�r�rCs r8�getHostzTuntapPort.getHost�s���T�Z�Z����8�8r7)r%NNr>)r&r'r(r)r�rF�strr�r�r�r�ror�rgr�r�rr
r�r�r�r�r6r7r8rr�s~����M�9�*2�#�2�	�M�$�*�R�.
�"�'�(��	�2�q�!�,�m�<�1�=�1���9r7r)6r)r�rzry�platformr�rK�collectionsr�typingr�zope.interfacerrr�
constantlyrr	�incrementalr
�twisted.internetrrr
rr�twisted.pairrr�twisted.pythonr�twisted.python.deprecater�twisted.python.reflectr�twisted.python.utilrr�__all__r��machine�
startswithr��
_TUNGETIFFr�r�IAddressrrTrVrw�IListeningPortr�rr6r7r8�<module>r�sE��
�
��	��
��"��<�<�*��E�E�&��/�5�;���
�	��H����(�"��x����$�$�U�+��x����$�$�W�-��J��J��J��J���(�%�(�B
�Z�
 �
 �!�&,�M�<�&,�"�&,�R	��$8�-�H�	�C�)�C�L4�4�&
�Z�
&�
&�'�@9��(�(�@9�(�@9r7