HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/twisted/pair/__pycache__/tuntap.cpython-38.pyc
U

��W[�0�@s�dZddlZddlZddlZddlZddlZddlmZddlm	Z	m
Z
ddlmZm
Z
mZddlmZmZddlmZddlmZdd	lmZdd
lmZddlmZmZmZmZmZddl m!Z!m"Z"d
ddgZ#dZ$dZ%dZ&dZ'Gdd
�d
e	�Z(eej)�Gdd�deee*��Z+Gdd�dedd��Z,Gdd�de
�Z-Gdd�de*�Z.eej/�Gdd�dej0��Z1eedddd�e1j2�e1j3�e1_3dS) zc
Support for Linux ethernet and IP tunnel devices.

@see: U{https://en.wikipedia.org/wiki/TUN/TAP}
�N)�
namedtuple)�Flags�FlagConstant)�	Attribute�	Interface�implementer)�FancyEqMixin�
FancyStrMixin)�Version)�fullyQualifiedName)�
deprecated)�log)�abstract�error�task�
interfaces�defer)�ethernet�raw�TunnelFlags�
TunnelAddress�
TuntapPort�i�T@l�Ts/dev/net/tunc@speZdZdZed�Zed�Zed�Zed�Zed�Z	ed�Z
ed�Zed	�Zed
�Z
ed�Zed�Zed
�ZdS)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_TAPZ
TUN_FASYNCZTUN_NOCHECKSUMZ	TUN_NO_PIZ
TUN_ONE_QUEUEZTUN_PERSISTZTUN_VNET_HDR�	IFF_NO_PIZ
IFF_ONE_QUEUEZIFF_VNET_HDRZIFF_TUN_EXCL�r'r'�5/usr/lib/python3/dist-packages/twisted/pair/tuntap.pyr(sc@s@eZdZdZdZddd�fdfZedd��Zd	d
�Zdd�Z	d
S)rzU
    A L{TunnelAddress} represents the tunnel to which a L{TuntapPort} is bound.
    )�
_typeValue�name�typecCs|jS�N)r*)�flagr'r'r(�<lambda>O�zTunnelAddress.<lambda>r*cCs|jjS)z�
        Return the integer value of the C{type} attribute.  Used to produce
        correct results in the equality implementation.
        )r+�value��selfr'r'r(r)QszTunnelAddress._typeValuecCs||_||_dS)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*)r2r+r*r'r'r(�__init__[szTunnelAddress.__init__cCstjdtdd�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�
stacklevelZTUNTAP)�warnings�warn�DeprecationWarningr*)r2�indexr'r'r(�__getitem__gs�zTunnelAddress.__getitem__N)
r r!r"r#ZcompareAttributesZshowAttributes�propertyr)r3r:r'r'r'r(rIs
	c@seZdZdZdS)�_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#r'r'r'r(r<ssr<zfileno namec@sdeZdZdZed�Zed�Zed�Zddd�Zdd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZdS)�_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}�cCsdS)z"
        @see: L{os.open}
        Nr')�filenamer-�moder'r'r(�open�sz_IInputOutputSystem.openNcCsdS)z&
        @see: L{fcntl.ioctl}
        Nr')�fdZopt�argZmutate_flagr'r'r(�ioctl�sz_IInputOutputSystem.ioctlcCsdS)z"
        @see: L{os.read}
        Nr')rB�limitr'r'r(�read�sz_IInputOutputSystem.readcCsdS)z#
        @see: L{os.write}
        Nr')rB�datar'r'r(�write�sz_IInputOutputSystem.writecCsdS)z#
        @see: L{os.close}
        Nr')rBr'r'r(�close�sz_IInputOutputSystem.closecCsdS)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})
        Nr')�datagramZaddressr'r'r(�sendUDP�sz_IInputOutputSystem.sendUDPcCsdS)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.
        Nr')�filenoZhostZportr'r'r(�
receiveUDP�sz_IInputOutputSystem.receiveUDP)r>)NN)r r!r"r#r�O_RDWR�
O_NONBLOCK�	O_CLOEXECrArDrFrHrIrKrMr'r'r'r(r=�s

r=c@sZeZdZdZeej�Zeej�Zeej�Zeej	�Z	ee
j�ZejZej
Z
eedd�ZdS)�_RealSystemz�
    An interface to the parts of the operating system which L{TuntapPort}
    relies on.  This is most of an implementation of L{_IInputOutputSystem}.
    rPiN)r r!r"r#�staticmethod�osrArFrHrI�fcntlrDrNrO�getattrrPr'r'r'r(rQ�s




rQc@s�eZdZdZdZd!dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd"dd�Zdd�Zdd �ZdS)#rzH
    A Port that reads and writes packets from/to a TUN/TAP-device.
    irNcCs�tj�|�rd|_tj|_nd|_tj|_tj�|�s:t	�|dkrHt
�}||_tj
�||�||_||_||_|�|j�}d||jjf|_dS)Nrrz%s (%s))rZIEthernetProtocolZ
providedByrr%�_moder$rZIRawPacketProtocol�AssertionErrorrQ�_systemr�FileDescriptorr3�	interface�protocol�
maxPacketSizeZ
_getLogPrefixr*�logstr)r2rZ�protor\�reactor�system�	logPrefixr'r'r(r3�s
zTuntapPort.__init__cCs@t|jj�f}|jr|d}n|d}||jj|jf}d|S)N)�)znot z<%s %slistening on %s/%s>)rr[�	__class__�	connectedrVr*rZ)r2�argsr'r'r(�__repr__�s
zTuntapPort.__repr__cCs |��|j�|�|��dS)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[ZmakeConnectionZstartReadingr1r'r'r(�startListeningszTuntapPort.startListeningcCsd|jj|jjB|jjB}t�dtf||j�}|j�t	|�}|j�
|t|�}t||dt��
d��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�)rXrNrPrO�structZpack�	_IFNAMSIZr0rA�_TUN_KO_PATHrD�
_TUNSETIFFr<�strip)r2r*r@�flagsZconfigrL�resultr'r'r(�_openTunnels
��zTuntapPort._openTunnelc
Cs�tjd|jj|jd�z|�|j|jtjB�\}}Wn6t	t
fk
rj}zt�d|j|��W5d}~XYnX||_||_
d|_dS)z"
        Open the tunnel.
        z&%(protocol)s starting on %(interface)s)�formatr[rZNr)r
�msgr[rcrZrqrVrr&�IOError�OSErrorrZCannotListenError�_filenord)r2rLrZ�er'r'r(rg(s�
�"zTuntapPort._bindSocketcCs|jSr,)rvr1r'r'r(rL<szTuntapPort.filenoc
Cs�d}||jkr�z|j�|j|j�}WnPtk
rh}z&|jtjtjtj	fkrVWY�
dS�W5d}~XYn�YnX|t
|�7}z|jj|dd�Wqt
|jj�}t�dd|f�YqXqdS)z=
        Called when my socket is ready for reading.
        rN)�partialz,Unhandled exception from %s.datagramReceived)�
maxThroughputrXrFrvr\�EnvironmentError�errnoZEWOULDBLOCKZEAGAIN�EINTR�lenr[ZdatagramReceivedrrcr
�err)r2rFrGrw�clsr'r'r(�doRead@s&

�zTuntapPort.doReadc
CsZz|j�|j|�WStk
rT}z$|jtjkrB|�|�WY�S�W5d}~XYnXdS)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)rXrHrvrtr{r|)r2rJrwr'r'r(rHZszTuntapPort.writecCs|�d�|��dS)z�
        Write a datagram constructed from a L{list} of L{bytes}.

        @param datagram: The data that will make up the complete datagram to be
            written.
        @type seq: L{list} of L{bytes}
        r/N)rH�join)r2�seqr'r'r(�
writeSequencejszTuntapPort.writeSequencecCsH|��|jr|jS|jr:t�|jd|j�|_d|_|jSt�	d�SdS)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)
ZstopReadingZ
disconnectingZ_stoppedDeferredrdrZ
deferLaterr_�connectionLostrZsucceedr1r'r'r(�
stopListeningus�zTuntapPort.stopListeningcCs|���tj�dS)zN
        Close this tunnel.  Use L{TuntapPort.stopListening} instead.
        N)r�Z
addErrbackr
r~r1r'r'r(�loseConnection�szTuntapPort.loseConnectioncCsFt�d|j�tj�||�|j��d|_|j	�
|j�d|_dS)zY
        Cleans up my socket.

        @param reason: Ignored.  Do not use this.
        z(Tuntap %s Closed)r���N)r
rsrZrrYr�r[ZdoStoprdrXrIrv)r2�reasonr'r'r(r��s
zTuntapPort.connectionLostcCs|jS)zK
        Returns the name of my class, to prefix log entries with.
        )r]r1r'r'r(ra�szTuntapPort.logPrefixcCst|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}
        )rrVrZr1r'r'r(�getHost�szTuntapPort.getHost)rNN)N)r r!r"r#ryr3rfrhrqrgrLr�rHr�r�r�r�rar�r'r'r'r(r�s$�


ZTwisted�)4r#rSrTr{rjr6�collectionsrZ
constantlyrrZzope.interfacerrrZtwisted.python.utilrr	Zincrementalr
Ztwisted.python.reflectrZtwisted.python.deprecaterZtwisted.pythonr
Ztwisted.internetrrrrrZtwisted.pairrr�__all__rkrmZ
_TUNGETIFFrlrZIAddress�objectrr<r=rQZIListeningPortrYrr�r�r'r'r'r(�<module>sL�!)
LP��