+
    i.                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ] P                  ! ]
4      t^t^t^t^t^tRt^t^<tRtRt]P,                  ! ]4      t]P,                  ! ]4      t]],           t^t^t^t^t^ t^t^t ^t!^t"^t#^t$]! R. RO4      t%]! RR	R
.4      t&]! R. RO4      t' ! R R](4      t)R t*R t+RR lt,R t-R t.R t/R t0R t1R t2R# )    N)
namedtuple)utili  IHHIIBHiIIRTAAttrInterfaceOperstateifname	operstateNetlinkHeaderc                       ] tR t^5tRtRtR# )NetlinkCreateSocketErrorz5Raised if netlink socket fails during create or bind. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       C/usr/lib/python3/dist-packages/cloudinit/sources/helpers/netlink.pyr   r   5   s    ?r   r   c                     \         P                   ! \         P                  \         P                  \         P                  4      p V P	                  \
        P                  ! 4       \        34       V P                  ^ 4       \        P                  R4       T #   \         P                   d   pRT,          p\        T4      ThRp?ii ; i)a]  Creates netlink socket and bind on netlink group to catch interface
down/up events. The socket will bound only on RTMGRP_LINK (which only
includes RTM_NEWLINK/RTM_DELLINK/RTM_GETLINK events). The socket is set to
non-blocking mode since we're only receiving messages.

:returns: netlink socket in non-blocking mode
:raises: NetlinkCreateSocketError
z*Exception during netlink socket create: %sNzCreated netlink socket)socket
AF_NETLINKSOCK_RAWNETLINK_ROUTEbindosgetpidRTMGRP_LINKsetblockingerrorr   LOGdebug)netlink_socketemsgs      r   create_bound_netlink_socketr'   9   s    3v0D0D
 	RYY[+67""1% II&'	 << 3:Q>&s+23s   A=B C+C  Cc                    V f   Q R4       h\        V 4      \        8  g   Q R4       h\        P                  ! \        V R\
         4      w  rr4p\        P                  RV4       \        WW4V4      # )a  Gets netlink message type and length

:param: data read from netlink socket
:returns: netlink message type
:raises: AssertionError if data is None or data is not >= NLMSGHDR_SIZE
struct nlmsghdr {
           __u32 nlmsg_len;    /* Length of message including header */
           __u16 nlmsg_type;   /* Type of message content */
           __u16 nlmsg_flags;  /* Additional flags */
           __u32 nlmsg_seq;    /* Sequence number */
           __u32 nlmsg_pid;    /* Sender port ID */
};
Ndata is nonez+data is smaller than netlink message headerzGot netlink msg of type %d)	lenNLMSGHDR_SIZEstructunpackNLMSGHDR_FMTMSG_TYPE_OFFSETr"   r#   r   )datamsg_lenmsg_typeflagsseqpids   &     r   get_netlink_msg_headerr6   O   ss     +^+D	]"545")/d+O,*&Gu3 II*H5E<<r   c                    V f   Q R4       h\         P                   ! V .. . V4      w  p pW9  d   R# \        P                  R4       V P                  \        4      pVf   \        P                  R4       V# )a  Select and read from the netlink socket if ready.

:param: netlink_socket: specify which socket object to read from
:param: timeout: specify a timeout value (integer) to wait while reading,
        if none, it will block indefinitely until socket ready for read
:returns: string of data read (max length = <MAX_SIZE>) from socket,
          if no data read, returns None
:raises: AssertionError if netlink_socket is None
Nnetlink socket is noneznetlink socket ready for readz,Reading from Netlink socket returned no data)selectr"   r#   recvMAX_SIZEr!   )r$   timeoutread_set_r0   s   &&   r   read_netlink_socketr?   h   sr     %?'??%]]N#3RWENHa %II-.x(D|		@AKr   c                   V f   Q R4       h\        V\        4      '       g   Q R4       hV\        8  g   Q R4       h^ ;r#Rp \        P                  ! RWR7      ^ ,          p\        P                  ! RW^,           R7      ^ ,          pY\        ,           Y,            p\        Y#T4      #   \        P
                   d     R# i ; i)a  Unpack a single rta attribute.

:param: data: string of data read from netlink socket
:param: offset: starting offset of RTA Attribute
:return: RTAAttr object with length, type and data. On error, return None.
:raises: AssertionError if data is None or offset is not integer.
Nr)   zoffset is not integerz'rta offset is less than expected lengthH)offset)
isinstanceintRTATTR_START_OFFSETr,   unpack_fromr!   RTA_DATA_START_OFFSETr   )r0   rB   lengthrta_type	attr_datas   &&   r   unpack_rta_attrrK      s     +^+fc"";$;;"%%101%FI##C=a@%%c4
CAF
 33foFI6Y// << s   AB' 'C ?C c                   V f   Q R4       h\        V 4      \        8  g   Q R4       hR;r\        pV\        V 4      8:  d   \        W4      pV'       d   VP                  ^ 8X  d   M\        VP                  \        ,          ,
          \        ,          pW4P                  V,           ,          pVP
                  \        8X  d   \        VP                  4      pK  VP
                  \        8X  g   K  \        P                  ! VP                  R4      pVP                  R4      pK  V'       d   Vf   R# \        P                  RW4       \        W4      # )a  Reads Interface name and operational state from RTA Data.

:param: data: string of data read from netlink socket
:returns: InterfaceOperstate object containing if_name and oper_state.
          None if data does not contain valid IFLA_OPERSTATE and
          IFLA_IFNAME messages.
:raises: AssertionError if data is None or length of data is
         smaller than RTATTR_START_OFFSET.
Nr)   z2length of data is smaller than RTATTR_START_OFFSETzutf-8 z!rta attrs: ifname %s operstate %d)r*   rE   rK   rH   PAD_ALIGNMENTrI   IFLA_OPERSTATEordr0   IFLA_IFNAMEr   decode_binarystripr"   r#   r   )r0   r	   r
   rB   attrpadleninterface_names   &      r   read_rta_oper_staterW      s    +^+D	''<;<'F F
CI
t,t{{a' T[[=89 	++&&==N*DIII]]k)!//		7CN#))$/FY&II16Ef00r   c                   aa \         P                  R4       RoVV3R lp\        V R\        .\        \
        .V4       S# )zBlock until a single nic is attached.

:param: netlink_socket: netlink_socket to receive events
:param: existing_nics: List of existing nics so that we can skip them.
:raises: AssertionError if netlink_socket is none.
z!Preparing to wait for nic attach.Nc                    < V S9   d   R # V oR# )TFr   )inamecarrierprevCarrierexisting_nicsr	   s   &&&r   should_continue_cb5wait_for_nic_attach_event.<locals>.should_continue_cb   s    M!r   )r"   r#   read_netlink_messagesRTM_NEWLINKOPER_UP	OPER_DOWN)r$   r]   r^   r	   s   &f @r   wait_for_nic_attach_eventrd      sC     II12F 		) Mr   c                t   a \         P                  R4       RoV3R lp\        V R\        .\        .V4       S# )zBlock until a single nic is detached and its operational state is down.

:param: netlink_socket: netlink_socket to receive events.
z!Preparing to wait for nic detach.Nc                    < V oR # )Fr   )rZ   r[   r\   r	   s   &&&r   r^   5wait_for_nic_detach_event.<locals>.should_continue_cb   s    r   )r"   r#   r`   RTM_DELLINKrc   )r$   r^   r	   s   & @r   wait_for_nic_detach_eventri      s=    
 II12F
 {mi[:L Mr   c                   a V f   Q R4       hSf   Q R4       h\        S4      ^ 8  g   Q R4       hV3R lp\        P                  R4       \        V S\        \
        .\        \        .V4       R# )a  Block until media disconnect and connect has happened on an interface.
Listens on netlink socket to receive netlink events and when the carrier
changes from 0 to 1, it considers event has happened and
return from this function

:param: netlink_socket: netlink_socket to receive events
:param: ifname: Interface name to lookout for netlink events
:raises: AssertionError if netlink_socket is None or ifname is None.
Nr8   zinterface name is nonezinterface name cannot be emptyc                 |   < V\         8H  ;'       d
    V\        8H  pV'       d   \        P                  R S4       R# R# )zMedia switch happened on %s.FT)rc   rb   r"   r#   )rZ   r[   r\   isVnetSwitchr	   s   &&& r   r^   =wait_for_media_disconnect_connect.<locals>.should_continue_cb   s2    #y0JJw'7III4f=r   z1Wait for media disconnect and reconnect to happen)r*   r"   r#   r`   ra   rh   rb   rc   )r$   r	   r^   s   &f r   !wait_for_media_disconnect_connectrn      st     %?'??%777v;?<<<? IIAB	k"	)r   c                   V f   \        R4      h\        4       p\        p\        p \        V \        4      pVf   K  \
        P                  R\        V4      4       WX,          p\
        P                  R\        V4      4       ^ p	\        V4      p
W8  Edn   WYR p\        V4      \        8  d   \
        P                  R4       EM>\        V4      p\        V4      VP                  8  d   \
        P                  R4       EMVP                  \        ,           ^,
          \        ^,
          ( ,          pW,           p	\
        P                  RV	4       VP                  V9  d   K  \        V4      pVf   \
        P                  RV4       K  Ve6   VP                  V8w  d%   \
        P                  R	VP                  V4       EK4  VP                  V9  d   EKH  TpVP                  pV! VP                  Wg4      '       d   EKr  R# WYR pEK  )
a  Reads from the netlink socket until the condition specified by
the continuation callback is met.

:param: netlink_socket: netlink_socket to receive events.
:param: ifname_filter: if not None, will only listen for this interface.
:param: rtm_types: Type of netlink events to listen for.
:param: operstates: Operational states to listen.
:param: should_continue_callback: Specifies when to stop listening.
NzNetlink socket is nonezread %d bytes from socketzLength of data after concat %dz#Data is smaller than netlink headerz*Partial data. Smaller than netlink messagez"offset to next netlink message: %dz!Failed to read rta attributes: %sz6Ignored netlink event on interface %s. Waiting for %s.)RuntimeErrorbytesrb   r?   SELECT_TIMEOUTr"   r#   r*   r+   r6   rH   rN   typerW   r	   r
   )r$   ifname_filter	rtm_types
operstatesshould_continue_callbackr0   r[   r\   	recv_datarB   datalennl_msgnlheaderrU   interface_states   &&&&&          r   r`   r`     s     3447DGK
'G			-s9~>		2CI>d)']F6{]*		?@-f5H6{X__,		FGoo59!> F _FII:FC}}I-1&9O&		=O)#**m;		L#**!
 ((
:!K%//G+&&  G}r   )rH   rI   r0   )rH   rs   r3   r4   r5   )N)3loggingr   r9   r   r,   collectionsr   	cloudinitr   	getLoggerr   r"   r   ra   rh   RTM_GETLINKRTM_SETLINKr;   r/   rr   r.   IFINFOMSG_FMTcalcsizer+   IFINFOMSG_SIZErE   rG   rN   rQ   rO   OPER_UNKNOWNOPER_NOTPRESENTrc   OPER_LOWERLAYERDOWNOPER_TESTINGOPER_DORMANTrb   r   r   r   rp   r   r'   r6   r?   rK   rW   rd   ri   rn   r`   r   r   r   <module>r      s0  
  	    " ! -/#n4   	 

Y >
? 4x6MN >
@| @,=2.04"1J:&@Er   