+
    Dfj1                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RI	H
t
 ^ RIHtHtHt ^ RIHtHt ^ RIHt ^ RIHtHtHtHtHt ^ RIHtHt ^ R	IHt ^ R
IH t  ^ RI!H"t" ^ RI#H$t$H%t% . R"Ot&^t']PP                  ! 4       R8X  gM   ]PP                  ! 4       PS                  R4      '       g'   ]PP                  ! 4       PS                  R4      '       d   Rt*Rt+MRt*Rt+Rt, ! R R]4      t-]! ]P\                  4       ! R R]%]$4      4       t/ ! R R]! RR4      4      t0 ! R R]4      t1 ! R R 4      t2]! ]Pf                  4       ! R! R]Ph                  4      4       t5R# )#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  iT@iT@l   T  s   /dev/net/tunc                       ] tR t^6tRt]! ^4      t]! ^4      t]! ^4      t]! ^ 4      t	]! ^@4      t
]! ^4      t]! R4      t]! R4      t]! R4      t]! R4      t]! R4      t]! R4      tRtR	# )
r   aV  
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}
   i   i       i @  i    N)__name__
__module____qualname____firstlineno____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__static_attributes__r       5/usr/lib/python3/dist-packages/twisted/pair/tuntap.pyr   r   6   s      6"G6"Gf%J!&)NV$I (Mv&K'LV$I (M'L'Lr2   c                   R   a  ] tR t^Wt o RtR
tRR 3R3t]R 4       tR t	R t
RtV tR	# )r   zM
A L{TunnelAddress} represents the tunnel to which a L{TuntapPort} is bound.
nametypec                    V P                   # N)r5   )flags   &r3   <lambda>TunnelAddress.<lambda>^   s    DIIr2   c                .    V P                   P                  # )zu
Return the integer value of the C{type} attribute.  Used to produce
correct results in the equality implementation.
)r6   valueselfs   &r3   
_typeValueTunnelAddress._typeValue`   s     yyr2   c                    Wn         W n        R# )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)r6   r5   )r?   r6   r5   s   &&&r3   __init__TunnelAddress.__init__i   s     		r2   c                f    \         P                  ! R\        ^R7       RV P                  3V,          # )zC
Deprecated accessor for the tunnel name.  Use attributes instead.
zUTunnelAddress.__getitem__ is deprecated since Twisted 14.0.0  Use attributes instead.)category
stacklevelTUNTAP)warningswarnDeprecationWarningr5   )r?   indexs   &&r3   __getitem__TunnelAddress.__getitem__t   s1     	&'		
 $))$U++r2   )r5   r6   N)r@   r5   )r    r!   r"   r#   r$   compareAttributesshowAttributespropertyr@   rC   rM   r1   __classdictcell____classdict__s   @r3   r   r   W   sC      /56?N 	
, 
,r2   c                       ] tR t^tRtRtR# )_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}
r   N)r    r!   r"   r#   r$   r1   r   r2   r3   rV   rV      s    r2   rV   zfileno namec                      a  ] tR t^t o Rt]! R4      t]! R4      t]! R4      tRR lt	RR lt
R tR	 tR
 tR tR tRtV tR# )_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                    R# )z
@see: L{os.open}
Nr   )filenamer9   modes   &&&r3   open_IInputOutputSystem.open       r2   Nc                    R# )z
@see: L{fcntl.ioctl}
Nr   )fdoptargmutate_flags   &&&&r3   ioctl_IInputOutputSystem.ioctl   r^   r2   c                    R# )z
@see: L{os.read}
Nr   )r`   limits   &&r3   read_IInputOutputSystem.read   r^   r2   c                    R# )z
@see: L{os.write}
Nr   )r`   datas   &&r3   write_IInputOutputSystem.write   r^   r2   c                    R# )z
@see: L{os.close}
Nr   )r`   s   &r3   close_IInputOutputSystem.close   r^   r2   c                    R# )aL  
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   )datagramaddresss   &&r3   sendUDP_IInputOutputSystem.sendUDP   r^   r2   c                    R# )a  
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   )filenohostports   &&&r3   
receiveUDP_IInputOutputSystem.receiveUDP   r^   r2   r   )i  )NN)r    r!   r"   r#   r$   r   O_RDWR
O_NONBLOCK	O_CLOEXECr\   rd   rh   rl   ro   rt   rz   r1   rR   rS   s   @r3   rX   rX      sU     
 +,F34J12I




 r2   rX   c                      ] tR t^tRt]! ]P                  4      t]! ]P                  4      t]! ]P                  4      t	]! ]P                  4      t
]! ]P                  4      t]P                  t]P                  t]! ]RR4      tRtR# )_RealSystemz
An interface to the parts of the operating system which L{TuntapPort}
relies on.  This is most of an implementation of L{_IInputOutputSystem}.
r~   i   r   N)r    r!   r"   r#   r$   staticmethodosr\   rh   rl   ro   fcntlrd   r|   r}   getattrr~   r1   r   r2   r3   r   r      sq    
  D D"E"E%EYYFJ K3Ir2   r   c                      a  ] tR t^t o RtRtRR ltV 3R lR ltR tR t	R t
R	 tR
 tR tR tR t]! ]! R^^ ^ 4      ]4      R 4       tRR ltR tR tRtV tR# )r   z@
A Port that reads and writes packets from/to a TUN/TAP-device.
Nc                   \         P                  P                  V4      '       d   ^V n         \        P                  V n        MC^ V n         \        P                  V n        \        P                  P                  V4      '       g   Q hVf   \        4       pWPn
        \        P                  P                  W4       Wn        W n        W0n        V P#                  V P                  4      pV RV P
                  P$                   R2V n        R# )   Nz ())r   IEthernetProtocol
providedByr   r&   _moder%   r   IRawPacketProtocolr   _systemr
   FileDescriptorrC   	interfaceprotocolmaxPacketSize_getLogPrefixr5   logstr)r?   r   protor   reactorsystem	logPrefixs   &&&&&& r3   rC   TuntapPort.__init__   s    %%0077DM$,,DJDM$,,DJ))44U;;;;> ]F((7"*&&t}}5	"2djjoo%6a8r2   c                    < V ^8  d   QhRS[ /# )   return)str)formatrT   s   "r3   __annotate__TuntapPort.__annotate__  s     2 2# 2r2   c                    \        V P                  P                  4      3pV P                  '       d   VR,           pM	VR,           pWP                  P
                  V P                  3,           pRV,          # ) z<%s %slistening on %s/%s>)r   )znot )r   r   	__class__	connectedr   r5   r   )r?   argss   & r3   __repr__TuntapPort.__repr__  sY    !3DMM4K4K!L N>>>%<D)#Dzz77*T11r2   c                |    V P                  4        V P                  P                  V 4       V P                  4        R# )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startReadingr>   s   &r3   startListeningTuntapPort.startListening  s.     	$$T*r2   c                   V P                   P                  V P                   P                  ,          V P                   P                  ,          p\        P
                  ! R\        3,          WP                  4      pV P                   P                  \        V4      pV P                   P                  V\        V4      p\        WVR\         P                  R4      4      # )a.  
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   r|   r~   r}   structpack	_IFNAMSIZr=   r\   _TUN_KO_PATHrd   
_TUNSETIFFrV   strip)r?   r5   r[   flagsconfigrw   results   &&&    r3   _openTunnelTuntapPort._openTunnel  s     ##dll&<&<<t||?V?VVVyl2D**E""<7##FJ?!&)*<*B*B7*KLLr2   c                   \         P                  ! RV P                  P                  V P                  R7        V P                  V P                  V P                  \        P                  ,          4      w  rY n        Yn        ^T n        R#   \         d(   p\        P                  ! RT P                  T4      hRp?ii ; i)z
Open the tunnel.
z&%(protocol)s starting on %(interface)s)r   r   r   N)r   msgr   r   r   r   r   r   r-   OSErrorr   CannotListenError_filenor   )r?   rw   r   es   &   r3   r   TuntapPort._bindSocket)  s     	;]],,nn	

	C $ 0 0

[-B-B B!F #  	C))$BB	Cs   =B B="B88B=c                    V P                   # r8   )r   r>   s   &r3   rw   TuntapPort.fileno>  s    ||r2   c                P   ^ pWP                   8  dd    V P                  P                  V P                  V P                  4      pT\        T4      ,          p T P                  P                  T^ R7       Ks  R#   \
         dK   pTP                  \        P                  \        P                  \        P                  39   d    Rp?R# h Rp?i\         d    h i ; i  \         d@    \        T P                  P                  4      p\         P"                  ! RRT R24        EK!  i ; i)z-
Called when my socket is ready for reading.
N)partialzUnhandled exception from z.datagramReceived)maxThroughputr   rh   r   r   r   errnoEWOULDBLOCKEAGAINEINTRBaseExceptionlenr   datagramReceivedr   r   r   err)r?   rh   rk   r   clss   &    r3   doReadTuntapPort.doReadA  s     '''||((t7I7IJ CIDR..tQ.? (  77u00%,,LL   ! R()@)@A 9#>OPQQRs6   0A8 C 8C>CCCCAD%$D%c                     V P                   P                  V P                  V4      #   \         d<   pTP                  \        P
                  8X  d   T P                  T4      u Rp?# h Rp?ii ; i)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   rl   r   r   r   r   )r?   rr   r   s   && r3   rl   TuntapPort.writeX  sT    	<<%%dllH== 	ww%++%zz(++	s    %( A./A)"A.(A))A.c                F    V P                  RP                  V4      4       R# )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}
r2   N)rl   join)r?   seqs   &&r3   writeSequenceTuntapPort.writeSequenceg  s     	

388C=!r2   c                6   V P                  4        V P                  '       d   V P                  # V P                  '       dE   \        P
                  ! V P                  ^ V P                  4      V n        RV n        V P                  # \        P                  ! R4      # )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.
TN)
stopReadingdisconnecting_stoppedDeferredr   r   
deferLaterr   connectionLostr   succeedr>   s   &r3   stopListeningTuntapPort.stopListeningq  sx     	(((^^^$(OOa!4!4%D! "&D(((==&&r2   Twistedc                `    V P                  4       P                  \        P                  4       R# )z>
Close this tunnel.  Use L{TuntapPort.stopListening} instead.
N)r   
addErrbackr   r   r>   s   &r3   loseConnectionTuntapPort.loseConnection  s    
 	''0r2   c                ,   \         P                  ! RV P                  ,          4       \        P                  P                  W4       V P                  P                  4        ^ V n        V P                  P                  V P                  4       RV n        R# )zA
Cleans up my socket.

@param reason: Ignored.  Do not use this.
z(Tuntap %s Closed)N)r   r   r   r
   r   r   r   doStopr   r   ro   r   )r?   reasons   &&r3   r   TuntapPort.connectionLost  sb     	$t~~56..t<4<<(r2   c                    V P                   # )z;
Returns the name of my class, to prefix log entries with.
)r   r>   s   &r3   r   TuntapPort.logPrefix  s     {{r2   c                B    \        V P                  V P                  4      # )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   r>   s   &r3   getHostTuntapPort.getHost  s     TZZ88r2   )r   r   r   r   r   r   r   r   r   r   r   i   )r   NNr8   )r    r!   r"   r#   r$   r   rC   r   r   r   r   rw   r   rl   r   r   r   r	   r   r   r   r   r1   rR   rS   s   @r3   r   r      s      M9*2 2	M$*R."'( 	2q!,m<1 =19 9r2   )r   r   r   )6r$   r   r   r   platformr   rI   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   rV   rX   r   IListeningPortr   r   r   r2   r3   <module>r     sE  
   	    "  < < *  E E &  / 5 ; 	("$$U++$$W-- JJJJ(% (B Z  !&,M< &, "&,R	$8-H 	C) CL4 4& Z&&'@9(( @9 (@9r2   