§
    ÈtºfÕ1  ã                   óÐ  — d Z ddlZddlZddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZmZmZ ddlmZmZ ddlmZ ddlmZmZmZmZmZ dd	lmZmZ dd
lmZ ddlm Z  ddl!m"Z" ddl#m$Z$m%Z% g d¢Z&dZ' ej(        ¦   «         dk    sD ej(        ¦   «          )                    d¦  «        s" ej(        ¦   «          )                    d¦  «        rdZ*dZ+ndZ*dZ+dZ, G d„ de¦  «        Z- eej.        ¦  «         G d„ de%e$¦  «        ¦   «         Z/ G d„ d edd¦  «        ¦  «        Z0 G d„ d e¦  «        Z1 G d!„ d"¦  «        Z2 eej3        ¦  «         G d#„ d$ej4        ¦  «        ¦   «         Z5dS )%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   ÊT  iÒT@iÊT@l   ÒT  s   /dev/net/tunc                   ó  — e Zd ZdZ ed¦  «        Z ed¦  «        Z ed¦  «        Z ed¦  «        Z ed¦  «        Z	 ed¦  «        Z
 ed¦  «        Z ed	¦  «        Z ed
¦  «        Z ed¦  «        Z ed¦  «        Z ed¦  «        ZdS )r   a~  
    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   é    é@   é€   é   i   i   é    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© ó    úR/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/pair/tuntap.pyr   r   6   sÎ   € € € € € ðð ð  ˆl˜6Ñ"Ô"€GØˆl˜6Ñ"Ô"€Gà�˜fÑ%Ô%€JØ!�\ &Ñ)Ô)€NØ�˜VÑ$Ô$€IØ �L Ñ(Ô(€MØ�,˜vÑ&Ô&€KØ�< Ñ'Ô'€Là�˜VÑ$Ô$€IØ �L Ñ(Ô(€MØ�< Ñ'Ô'€LØ�< Ñ'Ô'€L€L€Lr7   r   c                   óF   — e Zd ZdZdZdd„ fdfZed„ ¦   «         Zd„ Zd„ Z	d	S )
r   zU
    A L{TunnelAddress} represents the tunnel to which a L{TuntapPort} is bound.
    )Ú
_typeValueÚnameÚtypec                 ó   — | j         S ©N)r;   )Úflags    r8   ú<lambda>zTunnelAddress.<lambda>^   s   € ¨D¬I€ r7   r;   c                 ó   — | j         j        S )z�
        Return the integer value of the C{type} attribute.  Used to produce
        correct results in the equality implementation.
        )r<   Úvalue©Úselfs    r8   r:   zTunnelAddress._typeValue`   s   € ð ŒyŒÐr7   c                 ó"   — || _         || _        dS )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;   )rD   r<   r;   s      r8   Ú__init__zTunnelAddress.__init__i   s   € ð ˆŒ	ØˆŒ	ˆ	ˆ	r7   c                 óX   — t          j        dt          d¬¦  «         d| j        f|         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__zTunnelAddress.__getitem__t   s<   € õ 	Œð&å'Øð		
ñ 	
ô 	
ð 	
ð ˜$œ)Ð$ UÔ+Ð+r7   N)
r&   r'   r(   r)   ÚcompareAttributesÚshowAttributesÚpropertyr:   rF   rO   r6   r7   r8   r   r   W   sp   € € € € € ðð ð /ÐØÐ5Ð5Ð6¸Ð?€Nàðð ñ „Xðð	ð 	ð 	ð
,ð 
,ð 
,ð 
,ð 
,r7   r   c                   ó   — e Zd ZdZdS )Ú_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)   r6   r7   r8   rT   rT   �   s   € € € € € ðð ð ð r7   rT   zfileno namec                   ó‚   — e Zd ZdZ ed¦  «        Z ed¦  «        Z ed¦  «        Zdd„Zdd„Z	d	„ Z
d
„ Zd„ Zd„ Zd„ ZdS )Ú_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                 ó   — dS )z"
        @see: L{os.open}
        Nr6   )Úfilenamer?   Úmodes      r8   Úopenz_IInputOutputSystem.open—   ó   € € € r7   Nc                 ó   — dS )z&
        @see: L{fcntl.ioctl}
        Nr6   )ÚfdÚoptÚargÚmutate_flags       r8   Úioctlz_IInputOutputSystem.ioctlœ   r\   r7   c                 ó   — dS )z"
        @see: L{os.read}
        Nr6   )r^   Úlimits     r8   Úreadz_IInputOutputSystem.read¡   r\   r7   c                 ó   — dS )z#
        @see: L{os.write}
        Nr6   )r^   Údatas     r8   Úwritez_IInputOutputSystem.write¦   r\   r7   c                 ó   — dS )z#
        @see: L{os.close}
        Nr6   )r^   s    r8   Úclosez_IInputOutputSystem.close«   r\   r7   c                 ó   — dS )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\   r7   c                 ó   — dS )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   )rW   )NN)r&   r'   r(   r)   r   ÚO_RDWRÚ
O_NONBLOCKÚ	O_CLOEXECr[   rb   re   rh   rj   rn   rs   r6   r7   r8   rV   rV   �   sÃ   € € € € € ðð ð
 ˆYÐ+Ñ,Ô,€FØ�Ð3Ñ4Ô4€JØ�	Ð1Ñ2Ô2€Iðð ð ð ð
ð ð ð ð
ð ð ð
ð ð ð
ð ð ð
ð ð ðð ð ð ð r7   rV   c                   óè   — e Zd ZdZ eej        ¦  «        Z eej        ¦  «        Z eej        ¦  «        Z eej	        ¦  «        Z	 ee
j        ¦  «        Zej        Zej        Z eedd¦  «        ZdS )Ú_RealSystemzœ
    An interface to the parts of the operating system which L{TuntapPort}
    relies on.  This is most of an implementation of L{_IInputOutputSystem}.
    rv   i   N)r&   r'   r(   r)   ÚstaticmethodÚosr[   re   rh   rj   Úfcntlrb   rt   ru   Úgetattrrv   r6   r7   r8   rx   rx   Ó   s’   € € € € € ðð ð
 ˆ<˜œÑ Ô €DØˆ<˜œÑ Ô €DØˆL˜œÑ"Ô"€EØˆL˜œÑ"Ô"€EØˆL˜œÑ%Ô%€EàŒY€FØ”€Jð �˜˜K¨Ñ3Ô3€I€I€Ir7   rx   c                   ó°   — e Zd ZdZdZdd„Zdefd„Zd„ Zd	„ Z	d
„ Z
d„ Zd„ Zd„ Zd„ Zd„ Z e edddd¦  «        e¦  «        d„ ¦   «         Zdd„Zd„ Zd„ ZdS )r   zH
    A Port that reads and writes packets from/to a TUN/TAP-device.
    i   r%   Nc                 óâ  — t           j                             |¦  «        rd| _         t          j        | _        n9d| _         t          j        | _        t          j                             |¦  «        sJ ‚|€t          ¦   «         }|| _
        t          j                             | |¦  «         || _        || _        || _        |                      | j        ¦  «        }|› d| j        j        › d�| _        d S )Nr   r   z (ú))r   ÚIEthernetProtocolÚ
providedByr   r+   Ú_moder*   r   ÚIRawPacketProtocolrx   Ú_systemr   ÚFileDescriptorrF   Ú	interfaceÚprotocolÚmaxPacketSizeÚ_getLogPrefixr;   Úlogstr)rD   r†   Úprotorˆ   ÚreactorÚsystemÚ	logPrefixs          r8   rF   zTuntapPort.__init__î   sÕ   € ÝÔ%×0Ò0°Ñ7Ô7ð 	<ØˆDŒMÝ$Ô,ˆDŒJˆJàˆDŒMÝ$Ô,ˆDŒJÝÔ)×4Ò4°UÑ;Ô;Ð;Ð;Ð;àˆ>Ý ‘]”]ˆFØˆŒåÔ×(Ò(¨¨wÑ7Ô7Ð7Ø"ˆŒØˆŒØ*ˆÔà×&Ò& t¤}Ñ5Ô5ˆ	Ø"Ð8Ð8 d¤j¤oÐ8Ð8Ð8ˆŒˆˆr7   Úreturnc                 ó�   — t          | j        j        ¦  «        f}| j        r|dz   }n|dz   }|| j        j        | j        fz   }d|z  S )N)Ú )znot z<%s %slistening on %s/%s>)r   r‡   Ú	__class__Ú	connectedr‚   r;   r†   )rD   Úargss     r8   Ú__repr__zTuntapPort.__repr__  sV   € Ý!3°D´MÔ4KÑ!LÔ!LÐ NˆØŒ>ð 	$Ø˜%‘<ˆDˆDà˜)Ñ#ˆDØ�t”z”¨¬Ð7Ñ7ˆØ*¨TÑ1Ð1r7   c                 óŠ   — |                       ¦   «          | j                             | ¦  «         |                      ¦   «          dS )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ÚstartReadingrC   s    r8   ÚstartListeningzTuntapPort.startListening  sD   € ð 	×ÒÑÔÐØŒ×$Ò$ TÑ*Ô*Ð*Ø×ÒÑÔÐÐÐr7   c                 óx  — | j         j        | j         j        z  | j         j        z  }t	          j        dt          fz  ||j        ¦  «        }| j                              t          |¦  «        }| j          
                    |t          |¦  «        }t          ||dt          …                              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ó    )r„   rt   rv   ru   ÚstructÚpackÚ	_IFNAMSIZrB   r[   Ú_TUN_KO_PATHrb   Ú
_TUNSETIFFrT   Ústrip)rD   r;   rZ   ÚflagsÚconfigrp   Úresults          r8   Ú_openTunnelzTuntapPort._openTunnel  s•   € ð ”Ô# d¤lÔ&<Ñ<¸t¼|Ô?VÑVˆÝ”˜V¥y lÑ2°D¸$¼*ÑEÔEˆØ”×"Ò"¥<°Ñ7Ô7ˆØ”×#Ò# F­J¸Ñ?Ô?ˆÝ! &¨&°µ)°Ô*<×*BÒ*BÀ7Ñ*KÔ*KÑLÔLÐLr7   c                 ó:  — t          j        d| j        j        | j        ¬¦  «         	 |                      | j        | j        t          j        z  ¦  «        \  }}n-# t          $ r }t          j        d| j        |¦  «        ‚d}~ww xY w|| _        || _        d| _        dS )z"
        Open the tunnel.
        z&%(protocol)s starting on %(interface)s)Úformatr‡   r†   Nr   )r   Úmsgr‡   r’   r†   r¦   r‚   r   r2   ÚOSErrorr   ÚCannotListenErrorÚ_filenor“   )rD   rp   r†   Úes       r8   r—   zTuntapPort._bindSocket)  s·   € õ 	ŒØ;Ø”]Ô,Ø”nð	
ñ 	
ô 	
ð 	
ð
	CØ $× 0Ò 0Ø” ¤
­[Ô-BÑ Bñ!ô !ÑˆF�I�Iøõ ð 	Cð 	Cð 	CÝÔ)¨$°´ÀÑBÔBÐBøøøøð	Cøøøð #ˆŒØˆŒàˆŒˆˆs   ¨0A Á
BÁ#A>Á>Bc                 ó   — | j         S r>   )r¬   rC   s    r8   rp   zTuntapPort.fileno>  s
   € ØŒ|Ðr7   c                 ó  — d}|| j         k     ró	 | j                             | j        | j        ¦  «        }nM# t
          $ r6}|j        t          j        t          j        t          j	        fv rY d}~dS ‚ d}~wt          $ r ‚ w xY w|t          |¦  «        z  }	 | j                             |d¬¦  «         nB# t          $ r5 t          | j        j        ¦  «        }t!          j        dd|› d�¦  «         Y nw xY w|| j         k     °ñdS dS )z=
        Called when my socket is ready for reading.
        r   N)ÚpartialzUnhandled exception from z.datagramReceived)ÚmaxThroughputr„   re   r¬   rˆ   rª   ÚerrnoÚEWOULDBLOCKÚEAGAINÚEINTRÚBaseExceptionÚlenr‡   ÚdatagramReceivedr   r’   r   Úerr)rD   re   rg   r­   Úclss        r8   ÚdoReadzTuntapPort.doReadA  s>  € ð ˆØ�TÔ'Ò'Ð'ðØ”|×(Ò(¨¬°tÔ7IÑJÔJ��øÝð ð ð Ø”7�uÔ0µ%´,ÅÄÐLÐLÐLØ�F�F�F�F�FàøøøøÝ ð ð ð Øðøøøà•C˜‘I”IÑˆDðRØ”×.Ò.¨t¸QÐ.Ñ?Ô?Ð?Ð?øÝ ð Rð Rð RÝ(¨¬Ô)@ÑAÔA�Ý”˜ÐP¸#ÐPÐPÐPÑQÔQÐQÐQÐQðRøøøð �TÔ'Ò'Ð'Ð'Ð'Ð'Ð's,   �%5 µ
A?¿*A0Á/A0Á0A?ÂB2 Â2<C1Ã0C1c                 óÈ   — 	 | j                              | j        |¦  «        S # t          $ r5}|j        t          j        k    r|                      |¦  «        cY d}~S ‚ d}~ww xY w)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„   rh   r¬   rª   r²   rµ   )rD   rl   r­   s      r8   rh   zTuntapPort.writeX  ss   € ð	Ø”<×%Ò% d¤l°HÑ=Ô=Ð=øÝð 	ð 	ð 	ØŒw�%œ+Ò%Ð%Ø—z’z (Ñ+Ô+Ð+Ð+Ð+Ð+Ð+Ð+Øøøøøð	øøøs    ‚" ¢
A!¬)AÁA!ÁAÁA!c                 óV   — |                       d                     |¦  «        ¦  «         dS )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}
        r7   N)rh   Újoin)rD   Úseqs     r8   ÚwriteSequencezTuntapPort.writeSequenceg  s&   € ð 	�
Š
�3—8’8˜C‘=”=Ñ!Ô!Ð!Ð!Ð!r7   c                 óâ   — |                       ¦   «          | j        r| j        S | j        r3t	          j        | j        d| j        ¦  «        | _        d| _        | j        S t          j	        d¦  «        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.
        r   TN)
ÚstopReadingÚdisconnectingÚ_stoppedDeferredr“   r   Ú
deferLaterrŒ   ÚconnectionLostr   ÚsucceedrC   s    r8   ÚstopListeningzTuntapPort.stopListeningq  sw   € ð 	×ÒÑÔÐØÔð 		'ØÔ(Ð(ØŒ^ð 	'Ý$(¤OØ”˜a Ô!4ñ%ô %ˆDÔ!ð "&ˆDÔØÔ(Ð(å”= Ñ&Ô&Ð&r7   ÚTwistedé   r   c                 óh   — |                       ¦   «                              t          j        ¦  «         dS )zN
        Close this tunnel.  Use L{TuntapPort.stopListening} instead.
        N)rÈ   Ú
addErrbackr   r¹   rC   s    r8   ÚloseConnectionzTuntapPort.loseConnection…  s,   € ð
 	×ÒÑÔ×'Ò'­¬Ñ0Ô0Ð0Ð0Ð0r7   c                 ó
  — t          j        d| j        z  ¦  «         t          j                             | |¦  «         | j                             ¦   «          d| _        | j	         
                    | j        ¦  «         d| _        dS )zY
        Cleans up my socket.

        @param reason: Ignored.  Do not use this.
        z(Tuntap %s Closed)r   éÿÿÿÿN)r   r©   r†   r   r…   rÆ   r‡   ÚdoStopr“   r„   rj   r¬   )rD   Úreasons     r8   rÆ   zTuntapPort.connectionLostŒ  ss   € õ 	ŒÐ$ t¤~Ñ5Ñ6Ô6Ð6ÝÔ×.Ò.¨t°VÑ<Ô<Ð<ØŒ×ÒÑÔÐØˆŒØŒ×Ò˜4œ<Ñ(Ô(Ð(ØˆŒˆˆr7   c                 ó   — | j         S )zK
        Returns the name of my class, to prefix log entries with.
        )rŠ   rC   s    r8   rŽ   zTuntapPort.logPrefix™  s   € ð Œ{Ðr7   c                 ó6   — 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}
        )r   r‚   r†   rC   s    r8   ÚgetHostzTuntapPort.getHostŸ  s   € õ ˜TœZ¨¬Ñ8Ô8Ð8r7   )r%   NNr>   )r&   r'   r(   r)   r±   rF   Ústrr•   rš   r¦   r—   rp   r»   rh   rÀ   rÈ   r   r
   rÍ   rÆ   rŽ   rÔ   r6   r7   r8   r   r   æ   s<  € € € € € ðð ð €Mð9ð 9ð 9ð 9ð*2˜#ð 2ð 2ð 2ð 2ð	ð 	ð 	ðMð Mð Mð$ð ð ð*ð ð ðRð Rð Rð.ð ð ð"ð "ð "ð'ð 'ð 'ð( €Z��˜	 2 q¨!Ñ,Ô,¨mÑ<Ô<ð1ð 1ñ =Ô<ð1ðð ð ð ðð ð ð9ð 9ð 9ð 9ð 9r7   r   )6r)   r²   r{   rz   Úplatformr�   rK   Úcollectionsr   Útypingr   Úzope.interfacer   r   r   Ú
constantlyr   r	   Úincrementalr
   Útwisted.internetr   r   r   r   r   Útwisted.pairr   r   Útwisted.pythonr   Útwisted.python.deprecater   Útwisted.python.reflectr   Útwisted.python.utilr   r   Ú__all__rŸ   ÚmachineÚ
startswithr¡   Ú
_TUNGETIFFr    r   ÚIAddressr   rT   rV   rx   ÚIListeningPortr…   r   r6   r7   r8   ú<module>rè      s/  ðð
ð ð €€€Ø €€€Ø 	€	€	€	Ø €€€Ø €€€Ø €€€Ø "Ð "Ð "Ð "Ð "Ð "Ø Ð Ð Ð Ð Ð à <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <à *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ø Ð Ð Ð Ð Ð à EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EÐ EØ &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø Ð Ð Ð Ð Ð Ø /Ð /Ð /Ð /Ð /Ð /Ø 5Ð 5Ð 5Ð 5Ð 5Ð 5Ø ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;Ð ;ðð ð €ð €	à€HÔÑÔ˜(Ò"Ð"Ø€xÔÑÔ×$Ò$ UÑ+Ô+ð #à€xÔÑÔ×$Ò$ WÑ-Ô-ð #ð
 €JØ€J€Jà€JØ€JØ€ð(ð (ð (ð (ð (�%ñ (ô (ð (ðB €ˆZÔ Ñ!Ô!ð&,ð &,ð &,ð &,ð &,�M <ñ &,ô &,ñ "Ô!ð&,ðR	ð 	ð 	ð 	ð 	˜˜Ð$8¸-ÑHÔHñ 	ô 	ð 	ðCð Cð Cð Cð C˜)ñ Cô Cð CðL4ð 4ð 4ð 4ð 4ñ 4ô 4ð 4ð& €ˆZÔ&Ñ'Ô'ð@9ð @9ð @9ð @9ð @9�Ô(ñ @9ô @9ñ (Ô'ð@9ð @9ð @9r7   