+
    i                       a  R! t60 t ^ RIt^ RIt^ RI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 ^ RIHtHtHtHtHtHtHt ^ RIt^ RIHtHtHt ^ RIHtHt ]P@                  ! ]!4      t"Rt#R	t$R
t%Rt& ! R R]'4      t( ! R R](4      t) ! R R](4      t* ! R R](4      t+R"R R llt,R t-R#R lt.R#R lt/ ! R R]P`                  4      t1 ! R R]14      t2 ! R R]14      t3 ! R R ]14      t4]3]2]4.t5] ^ k R# )$    N)suppress)StringIO)TimeoutExpired)AnyCallableDictListOptionalTupleType)subp
temp_utilsutil)get_interface_macis_ib_interfacez/run/systemd/netif/leasesz/var/lib/dhclientz.+\.leases?$aN  #!/bin/sh
log() {
    echo "udhcpc[$PPID]" "$interface: $2"
}
[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1
case $1 in
    bound|renew)
    cat <<JSON > "$LEASE_FILE"
{
    "interface": "$interface",
    "fixed-address": "$ip",
    "subnet-mask": "$subnet",
    "routers": "${router%% *}",
    "static_routes" : "${staticroutes}"
}
JSON
    ;;
    deconfig)
    log err "Not supported"
    exit 1
    ;;
    leasefail | nak)
    log err "configuration failed: $1: $message"
    exit 1
    ;;
    *)
    echo "$0: Unknown udhcpc command: $1" >&2
    exit 1
    ;;
esac
c                       ] tR t^AtRtRtR# )NoDHCPLeaseErrorz'Raised when unable to get a DHCP lease. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       4/usr/lib/python3/dist-packages/cloudinit/net/dhcp.pyr   r   A   s    1r   r   c                       ] tR t^EtRtRtR# )InvalidDHCPLeaseFileErrorzRaised when parsing an empty or invalid dhclient.lease file.

Current uses are DataSourceAzure and DataSourceEc2 during ephemeral
boot to scrape metadata.
r   Nr   r   r   r   r   r   E   s    r   r   c                       ] tR t^MtRtRtR# )NoDHCPLeaseInterfaceErrorz7Raised when unable to find a viable interface for DHCP.r   Nr   r   r   r   r!   r!   M   s    Ar   r!   c                       ] tR t^QtRtRtR# )NoDHCPLeaseMissingDhclientErrorz$Raised when unable to find dhclient.r   Nr   r   r   r   r#   r#   Q   s    .r   r#   c                    V ^8  d   QhR\         \        \        \        \        .R3,          ,          R\        \        \        3,          /# )   dhcp_log_funcNreturn)r
   r   strr   r   )formats   "r   __annotate__r*   U   sA     O O Hc3_d%:;<O 
#s(^	Or   c                    T;'       g    V P                   pVf    \        P                  R4       \        4       hV P                  P                  W2V 4      # )a  Perform dhcp discovery if nic valid and dhclient command exists.

If the nic is invalid or undiscoverable or dhclient command is not found,
skip dhcp_discovery and return an empty dict.

@param nic: Name of the network interface we want to run dhclient on.
@param dhcp_log_func: Callable accepting the interface and client's
    stdout, stderr streams.
@return: A list of dicts representing dhcp options for each lease obtained
    from the dhclient discovery if run, otherwise an empty list is
    returned.
z1Skip dhcp_discovery: Unable to find fallback nic.)fallback_interfaceLOGdebugr!   dhcp_clientdhcp_discovery)distronicr&   	interfaces   &&& r   maybe_perform_dhcp_discoveryr4   U   sL    " 00v00I		EF')),,YvNNr   c                V    \        \        P                  ! \        V 4      RR7      4      # )zParse a systemd lease file content as in /run/systemd/netif/leases/

Parse this (almost) ini style file even though it says:
  # This is private data. Do not parse.

Simply return a dictionary of key/values.F)list_values)dict	configobj	ConfigObjr   )contents   &r   networkd_parse_leaser;   n   s!     	##HW$55IJJr   c           	     "   V f   \         p / p\        P                  P                  V 4      '       g   V# \        P                  ! V 4       FA  p\        \        P                  ! \        P                  P                  W4      4      4      W&   KC  	  V# )zReturn a dictionary of dictionaries representing each lease
found in lease_d.i

The top level key will be the filename, which is typically the ifindex.)	NETWORKD_LEASES_DIRospathisdirlistdirr;   r   load_text_filejoin)leases_dretlfiles   &  r   networkd_load_leasesrG   y   sm     &C77==""
H%)X =>

 & Jr   c                     Vf   \         p\        VR7      p\        VP                  4       4       F&  w  r4VP	                  V 4      '       g   K  W@,          u # 	  R # )N)rD   )r=   rG   sorteditemsget)keynamerD   leases_ifindexdatas   &&   r   networkd_get_option_from_leasesrP      sJ    &!84F 088G=  1 r   c                   $  a  ] tR t^t o Rt^
tR t]R 4       t]R 4       t	]V 3R lR l4       t
]V 3R lR l4       t]P                  V 3R	 lR
 l4       t]]P                  V 3R lR l4       4       t]P                  RV 3R lR ll4       tRtV tR# )
DhcpClient c                    \         P                  ! V P                  4      V n        V P                  '       g   \	        4       hR # N)r   whichclient_namedhcp_client_pathr#   )selfs   &r   __init__DhcpClient.__init__   s3     $

4+;+; <$$$133 %r   c                R    \         P                   ! R V P                  .^ ^.R7       R# )pkillrcsN)r   rW   )clss   &r   kill_dhcp_clientDhcpClient.kill_dhcp_client   s    		7COO,1a&9r   c                    V P                  4        \        P                  ! R 4      pV F  p\        P                  ! V4       K  	  R# )z/var/lib/dhcp/*N)ra   globr>   remove)r`   filesfiles   &  r   clear_leasesDhcpClient.clear_leases   s2    		+,DIIdO r   c                    < V ^8  d   QhRS[ /# r%   dhcp_interfacer(   )r)   __classdict__s   "r   r*   DhcpClient.__annotate__   s     
 
3 
r   c                H    VP                  R V P                  V^ ^.R7       R# )startr^   Nmanage_servicerW   r`   rl   r1   s   &&&r   start_serviceDhcpClient.start_service   s&    S__n1a& 	 	
r   c                    < V ^8  d   QhRS[ /# rk   rm   )r)   rn   s   "r   r*   ro      s     C C# Cr   c                F    VP                  R V P                  ^ ^.R7       R# )stopr^   Nrr   rt   s   &&&r   stop_serviceDhcpClient.stop_service   s    fcooAq6Br   c                <   < V ^8  d   QhRS[ RS[S[ S[3,          /# r%   r3   r'   r(   r   r   )r)   rn   s   "r   r*   ro      s#      # $sCx. r   c                    / # )zGet the most recent lease from the ephemeral phase as a dict.

Return a dict of dhcp options. The dict contains key value
pairs from the most recent lease.
r   rY   r3   s   &&r   get_newest_leaseDhcpClient.get_newest_lease   s	     	r   c                L   < V ^8  d   QhRS[ RS[S[S[ S[ 3,          ,          /# r%   routesr'   r(   r	   r   )r)   rn   s   "r   r*   ro      s(      C DsCx,A r   c                    . # )a8  
parse classless static routes from string

The tuple is composed of the network_address (including net length) and
gateway for a parsed static route.

@param routes: string containing classless static routes
@returns: list of tuple(str, str) for all valid parsed routes until the
          first parsing error.
r   )r   s   &r   parse_static_routesDhcpClient.parse_static_routes   s	     	r   Nc                p   < V ^8  d   QhRS[ RS[S[S[ S[ S[ .R3,          ,          RS[S[ S[3,          /# r%   r3   r&   Nr'   r(   r
   r   r   r   )r)   rn   s   "r   r*   ro      sF        #sC$)> ?@
 
c3hr   c                    / # )a  Run dhcp client on the interface without scripts or filesystem
artifacts.

@param interface: Name of the network interface on which to send a
    dhcp request
@param dhcp_log_func: Callable accepting the interface and client's
    stdout, stderr streams.
@param distro: a distro object for network interface manipulation
@return: dict of lease options representing the most recent dhcp lease
    parsed from the dhclient.lease file
r   )rY   r3   r&   r1   s   &&&&r   r0   DhcpClient.dhcp_discovery   s	    $ 	r   )rX   NN)r   r   r   r   rW   timeoutrZ   classmethodra   rh   ru   rz   abcabstractmethodr   staticmethodr   r0   r   __classdictcell__rn   s   @r   rR   rR      s     KG4
 : :   
 

 C C 	     	  r   rR   c                      a a ] tR t^t oRtV 3R lt]V3R lR l4       t]R 4       tV3R lR lt	RV3R lR	 llt
]V3R
 lR l4       t]V3R lR l4       tV3R lR ltRtVtV ;t# )IscDhclientdhclientc                2   < \         SV `  4        R V n        R# )z/run/dhclient.leaseNsuperrZ   
lease_filerY   	__class__s   &r   rZ   IscDhclient.__init__   s    /r   c                L   < V ^8  d   QhRS[ RS[S[S[ S[3,          ,          /# )r%   lease_contentr'   )r(   r	   r   r   )r)   rn   s   "r   r*   IscDhclient.__annotate__   s(      C Dc3h,@ r   c                   \         P                  ! R\         P                  4      p. pV '       g   . # VP                  V 4       F  p. pVP	                  R4       F^  pVP                  4       P                  RR4      P                  RR4      pV'       g   K=  VP                  VP	                  R^4      4       K`  	  \        V4      pVP                  R4      pV'       d   \        P                  V4      VR&   VP                  V4       K  	  V# )zparse the content of a lease file

@param lease_content: a string containing the contents of an
    isc-dhclient lease
@return: a list of leases, most recent last
zlease {(?P<lease>.*?)}\n;"rS   zoption  unknown-245)recompileDOTALLfindallsplitstripreplaceappendr7   rK   r   get_ip_from_lease_value)r   lease_regexdhcp_leasesleaselease_optionslineoptionsopt_245s   &       r   parse_leasesIscDhclient.parse_leases   s     jj!<biiH"$I ((7EMC(zz|++C4<<YK4!((C);<	 )
 =)Gkk-0G)4)L)L*& w' 8 r   c           	     n   V P                  R R4      p\        V4      ^8  dn   RpVP                  R4       F$  p\        V4      ^8X  d
   RV,           pW#,          pK&  	  \        P                  ! R\        VP                  RR4      ^4      4      pMVP                  R4      p\        P                  ! V4      # )\rS   :0z>Lzutf-8)	r   lenr   structpackintencodesocket	inet_ntoa)fallback_lease_valueunescaped_value
hex_stringhex_pairpacked_bytess   &    r   r   #IscDhclient.get_ip_from_lease_value  s    .66tR@!#J+11#6x=A%"X~H&
 7 ";;c*,,S"5r:L +11':L--r   c                <   < V ^8  d   QhRS[ RS[S[ S[3,          /# r}   r~   )r)   rn   s   "r   r*   r     s#      # $sCx. r   c                   \        \        4      ;_uu_ 4        \        P                  ! V P                  4      pV'       d-   V P                  V4      pV'       d   VR,          uuRRR4       # RRR4       / #   + '       g   i     / # ; i)a  Get the most recent lease from the ephemeral phase as a dict.

Return a dict of dhcp options. The dict contains key value
pairs from the most recent lease.

@param interface: an interface string - not used in this class, but
    required for function signature compatibility with other classes
    that require a distro object
@raises: InvalidDHCPLeaseFileError on empty or unparsable leasefile
    content.
N)r   FileNotFoundErrorr   rB   r   r   )rY   r3   r:   r   s   &&  r   r   IscDhclient.get_newest_lease  sc     '(())$//:G"//8&r? )(( 	 )( 	s   AA7A77B	c                p   < V ^8  d   QhRS[ RS[S[S[ S[ S[ .R3,          ,          RS[S[ S[3,          /# r   r   )r)   rn   s   "r   r*   r   (  sK     E* E*E*  #sC$)> ?@E*
 
c3hE*r   c           	     @   \         P                  RV4       RpRpRp\        V P                  V,          4      p\        V P                  ^,          4      p\	        \
        4      ;_uu_ 4        \        P                  ! V4       \        P                  ! V P                  4       RRR4       VP                  P                  V4       \        V4      '       dx   R\        V4      R,          ,          p	RV: RV	: R	2p
\        P                  ! R
R7      p\        P                  P!                  WR,           4      p\"        P$                  ! WZ4        \&        P&                  ! VP)                  V P*                  V P                  VVV4      4      w  r\"        P6                  ! Y@P                  .TRR7      pT'       d/   \         P9                  RRP!                  R T 4       4      4       / # RpRpRpRp\;        T4       F  p \"        P<                  ! T4      P?                  4       p\        T4      pTPA                  T4      pT^8X  d@   \         P                  RT4       \        PB                  ! T\D        PF                  4       R
p M0 \J        PL                  ! T4       K  	  \         P                  T4       T'       g   \         PO                  RTTR4       Te
   T! YT4       T PQ                  T4      pT'       d   T# \S        4       h  + '       g   i     ELm; i  \&        P,                   dC   p\         P                  RTP.                  TP0                  TP2                  4       \4        ThRp?ii ; i  \
         d    RT R2p EL\H         d    RT R2p ELi ; i)a  Run dhclient on the interface without scripts/filesystem artifacts.

@param interface: Name of the network interface on which to send a
    dhcp request
@param dhcp_log_func: Callable accepting the interface and client's
    stdout, stderr streams.
@param distro: a distro object for network interface manipulation
@return: dict of lease options representing the most recent dhcp lease
    parsed from the dhclient.lease file
!Performing a dhcp discovery on %sz/run/dhclient.pidN{Gz?z20:%s$   NNzinterface "z" {send dhcp-client-identifier z;}T	needs_exez-dhclient.confz3dhclient exited with code: %s stderr: %r stdout: %r)maxwaitnaplenz+dhclient did not produce expected files: %sz, c              3   `   "   T F$  p\         P                  P                  V4      x  K&  	  R # 5irU   )r>   r?   basename).0fs   & r   	<genexpr>-IscDhclient.dhcp_discovery.<locals>.<genexpr>  s"     ?w!"''**1--ws   ,.unknownFrS   zkilling dhclient with pid=%sNo PID file found at z, dhclient is still runningPID file contained [z], dhclient is still runningzCdhclient(pid=%s, parentpid=%s) failed to daemonize after %s secondsg      $@)*r-   r.   r   r   r   r   r>   re   r   net_opslink_upr   r   r   get_tmp_ancestorr?   rC   r   
write_filer   build_dhclient_cmdrX   ProcessExecutionError	exit_codestderrstdoutr   wait_for_fileswarningrangerB   r   get_proc_ppidkillsignalSIGKILL
ValueErrortimesleeperrorr   r   )rY   r3   r&   r1   pid_fileconfig_file
sleep_timesleep_cyclesr   dhcp_client_identifierinterface_dhclient_contenttmp_dirouterrr   missingppid
daemonizedpid_content	debug_msg_pidr   s   &&&&                   r   r0   IscDhclient.dhcp_discovery(  s     			5yA
 '
4<<*45dllQ&' '((IIhIIdoo& ) 	y)
 9%%+I6s;; # 46 '
 !11DAG'',,w<L0LMKOOKD	.yy))))OOHC2 %%'
 KK=		?w?? I
	|$A"11(;AAC+& ++C019II<cBGGC0!%J	 
 JJz"+ %. IIi II $)#.%%i0L'))Q )((H )) 	.IIE	 #-	.D % +H: 60 0   *;- 80 0 sB   ,7L?L ?/M5L	M20=M--M25N	NNNc                L   < V ^8  d   QhRS[ RS[S[S[ S[ 3,          ,          /# r   r   )r)   rn   s   "r   r*   r     s,     u uC uDsCx,A ur   c           
       a V P                  R4      o\        P                  ! RS4       Uu. uF  q'       g   K  VNK  	  pp. pRS9   d%   V Uu. uF  p\        \	        V^4      4      NK  	  ppV3R lp^ p\        V4       EF  w  raWe8  d   K  \	        V4      pV\        ^^!4      9   dx   ^	p\        W&R 4      V8  d   V! Wx\        W&R 4      4       Vu # RP                  W&^,           V^,            4      p	RP                  W&^,           Wh,            4      p
Wh,           pEM)V\        ^^4      9   d   ^p\        W&R 4      V8  d   V! Wx\        W&R 4      4       Vu # RP                  W&^,           V^,            R.,           4      p	RP                  W&^,           Wh,            4      p
Wh,           pEMV\        ^	^4      9   d   ^p\        W&R 4      V8  d   V! Wx\        W&R 4      4       Vu # RP                  W&^,           V^,            RR.,           4      p	RP                  W&^,           Wh,            4      p
Wh,           pEMV\        ^^	4      9   d   ^p\        W&R 4      V8  d   V! Wx\        W&R 4      4       Vu # RP                  W&^,           V^,            . RO,           4      p	RP                  W&^,           Wh,            4      p
Wh,           pMxV^ 8X  dX   ^p\        W&R 4      V8  d   V! Wx\        W&R 4      4       Vu # Rp	RP                  W&^,           Wh,            4      p
Wh,           pM\        P                  R	V4       Vu # VP                  V	: R
V: 2V
34       EK  	  V# u upi u upi )aX  
parse rfc3442 format and return a list containing tuple of strings.

The tuple is composed of the network_address (including net length) and
gateway for a parsed static route.  It can parse two formats of
rfc3442, one from dhcpcd and one from dhclient (isc).

@param rfc3442: string in rfc3442 format (isc or dhcpd)
@returns: list of tuple(str, str) for all valid parsed routes until the
    first parsing error.

e.g.:

sr=parse_static_routes(        "32,169,254,169,254,130,56,248,255,0,130,56,240,1")
sr=[
    ("169.254.169.254/32", "130.56.248.255"),         ("0.0.0.0/0", "130.56.240.1")
]

sr2 = parse_static_routes(        "24.191.168.128 192.168.128.1,0 192.168.128.1")
sr2 = [
    ("191.168.128.0/24", "192.168.128.1"),        ("0.0.0.0/0", "192.168.128.1")
]

# unknown-121 option format
sr3 = parse_static_routes(        "0:a:0:0:1:20:a8:3f:81:10:a:0:0:1:20:a9:fe:a9:fe:a:0:0:1")
sr3 = [
    ("0.0.0.0/0", "10.0.0.1"),
    ("168.63.129.16/32", "10.0.0.1"),
    ("169.254.169.254/32", "10.0.0.1"),
]

Python version of isc-dhclient's hooks:
   /etc/dhcp/dhclient-exit-hooks.d/rfc3442-classless-routes
r   z[, . :]r   c                 V   < R V : RV: RV: RS: 2p\         P                  V4       R# )z5RFC3442 string malformed.  Current route has CIDR of z and requires z significant octets, but only z< remain. Verify DHCP rfc3442-classless-static-routes value: N)r-   r   )cidrrequiredremainmsgrfc3442s   &&& r   _trunc_error5IscDhclient.parse_static_routes.<locals>._trunc_error  s%    
 674  IIcNr   N.r   z0.0.0.0zSParsed invalid net length "%s".  Verify DHCP rfc3442-classless-static-routes value./)r   r   r   )rstripr   r   r(   r   	enumerater   r   rC   r-   r   r   )r   toktokensstatic_routesr  current_idxidx
net_lengthreq_toksnet_addressgatewayr  s   &          @r   r   IscDhclient.parse_static_routes  s7   T --$!#*g!>F!>####!>F/1 '>39:6Cc#c2,'6F:	 !&)HC SJU2r]*vd|$x/ s6$<7HI((!hhvAga'@A((6'CN#CD!nuR},vd|$x/ s6$<7HI((!hhvAga'@C5'HI((6'CN#CD!nuQ|+vd|$x/ s6$<7HI((!hhvAga'@C:'MN((6'CN#CD!nuQ{*vd|$x/ s6$<7HI((!hh7S1W-? ((6'CN#CD!nqvd|$x/ s6$<7HI(('((6'CN#CD!n		=
 %$  '4g>m *t W G
 ;s   	M-M-M2c                0   < V ^8  d   QhRS[ S[,          /# )r%   r'   )r
   r(   )r)   rn   s   "r   r*   r   (  s     ) )Xc] )r   c                   RpV P                   V P                  3\        \        33 F  w  r#V'       g   K  . p \        P
                  ! V4      pRpT Fk  p\        P                  ! Y64      '       g   K!  \        P                  P                  Y&4      p\        P                  P                  T4      pY8  g   Kg  TpTpKm  	  T'       g   K  Tu # 	  R#   \         d     K  i ; i)zGet the latest lease file from a distro-managed dhclient

Doesn't consider the ephemeral timeframe lease.

@param distro: used for distro-specific lease location and filename
@return: The most recent lease file, or None
Ng      )dhclient_lease_directorydhclient_lease_file_regexDHCLIENT_FALLBACK_LEASE_DIRDHCLIENT_FALLBACK_LEASE_REGEXr>   rA   r   r   searchr?   rC   getmtime)	r1   latest_file	directoryregexlease_fileslatest_mtimefnameabs_pathmtimes	   &        r   !get_newest_lease_file_from_distro-IscDhclient.get_newest_lease_file_from_distro'  s     
 //00 )*GH!
I K jj3  L$yy..77<<	9((2'#(L"*K % {"";!
< # % s   CC#"C#c                    < V ^8  d   QhRS[ /# )r%   keyrm   )r)   rn   s   "r   r*   r   S  s     & &S &r   c                    V P                  V4      pV'       da   \        P                  ! V4      pV'       dA   \        V P	                  V4      4       F   pVP                  V4      pV'       g   K  Vu # 	  R# R# R# )a  Get a key from the latest lease from distro-managed dhclient

Doesn't consider the ephemeral timeframe lease.

@param lease_dir: distro-specific lease to check
@param lease_file_regex: distro-specific regex to match lease name
@return: The most recent lease file, or None
N)r1  r   rB   reversedr   rK   )rY   r1   r4  r   r:   r   servers   &&&    r   get_key_from_latest_lease%IscDhclient.get_key_from_latest_leaseS  sf     ;;FC
))*5G%d&7&7&@AE"YYs^Fv% B  r   r   r   )r   r   r   r   rW   rZ   r   r   r   r   r0   r   r1  r8  r   r   __classcell__r   rn   s   @@r   r   r      s     K0  6 . . (E* E*N u un ) )V& & &r   r   c                      a  ] tR tRt o RtRtRV 3R lR llt]V 3R lR l4       t]V 3R	 lR
 l4       t	V 3R lR lt
]V 3R lR l4       tRtV tR# )Dhcpcdif  dhcpcdi,  Nc                p   < V ^8  d   QhRS[ RS[S[S[ S[ S[ .R3,          ,          RS[S[ S[3,          /# r   r   )r)   rn   s   "r   r*   Dhcpcd.__annotate__j  sK     v. v.v.  #sC$)> ?@v.
 
c3hv.r   c                   \         P                  RV4       Rp\        V P                  V,          4      p. pVP                  P                  V4        \        V4      '       d   R.pV P                  RRRRRR	.VOVNp\        P                  ! VV P                  R
7      w  rVe
   V! WV	4       V P                  V4      p
V
'       d   \        P                  ! . VORN4      P                  P                  4       pRpRpRp\        V4       F  p \        P                  ! V4      P                  4       p\        V4      pVP                  V4      pV'       d@   \         P                  RVV4       \         P"                  ! V\$        P&                  4        V
#  V
u # 	  \         P                  V4       V
# \3        R4      h  \(         d    \         P                  RT4         T
# \*         d
    RT R2p M\,         d
    RT R2p Mi ; i\.        P0                  ! T4       EK    \4         dC   p\         P                  RTP                  TP6                  TP                  4       \2        ThRp?i\        P8                   dC   p\         P                  RTP:                  TP6                  TP                  4       \2        ThRp?ii ; i)a  Run dhcpcd on the interface without scripts/filesystem artifacts.

@param interface: Name of the network interface on which to send a
    dhcp request
@param dhcp_log_func: Callable accepting the interface and client's
    stdout, stderr streams.
@param distro: a distro object for network interface manipulation
@return: dict of lease options representing the most recent dhcp lease
    parsed from the dhclient.lease file
r   r   z
--clientid
--ipv4onlyz--waitipz--persistentz--noarpz--debugz--script=/bin/true)r   Nz-PFrS   z!killing dhcpcd with pid=%s gid=%sz9Process group id [%s] has already exited, nothing to killr   z, dhcpcd is still runningr   z], dhcpcd is still runningzNo lease foundz8dhcpcd timed out after %s seconds: stderr: %r stdout: %r1dhcpcd exited with code: %s stderr: %r stdout: %r)r-   r.   r   r   r   r   r   rW   r   r   r   r   r   r   rB   get_proc_pgidr>   killpgr   r   ProcessLookupErrorr   r   r   r   r   r   r   r   r   )rY   r3   r&   r1   r   r   infiniband_argumentcommandr   r   r   r   r  gidr  r  r  r   s   &&&&              r   r0   Dhcpcd.dhcp_discoveryj  s     			5yA
4<<*45  	y)\	. y))'3n#  $
 %
 
G yyHC (ic2)))4E   99%5w%5%56==CCE"	|,A%&*&9&9(&C&I&I&K!+.$2237II CS# IIc6>>:!. 9 0  %; -@ IIi("#344/ . 		.
    - 3H: >6 6 " & 2;- @6 6 " JJz*  	.IIJ	 #-)) 	.IIC	 #-	.s   A4H% AH% BF?H% H% H% 4H% ?!H	 H% $H	-H	4H% 6H	?H	H% H		H% %K0=I--KK=KKc                <   < V ^8  d   QhRS[ RS[RS[S[ ,          /# )r%   rO   dhcp_option_numberr'   )bytesr   r
   )r)   rn   s   "r   r*   rA    s)     ) ))),)	%)r   c                L    ^pR R lpV! W4       F  w  rEWA8X  g   K  Vu # 	  R# )a&  get a specific option from a binary lease file

This is required until upstream dhcpcd supports unknown option 245
upstream bug: https://github.com/NetworkConfiguration/dhcpcd/issues/282

@param data: Binary lease data
@param number: Option number to return
@return: the option (bytes) or None
c                0    V ^8  d   QhR\         R\        /# )r%   rO   index)rN  r   )r)   s   "r   r*   >Dhcpcd.parse_unknown_options_from_packet.<locals>.__annotate__  s     	+ 	+u 	+S 	+r   c              3     "   \        V 4      V^,           8  dJ   W,          pV ^V,           ,          pV ^V,           ^V,           V,            pW$3x  ^V,           V,           pK`  R# 5i)zoptions are variable length, and consist of the following format

option number: 1 byte
option length: 1 byte
option data: variable length (see length field)
N)r   )rO   rQ  codelengthoptions   &&   r   iter_options>Dhcpcd.parse_unknown_options_from_packet.<locals>.iter_options  s_      d)uqy({a%ia%i!e)f*<=l"F
U* )s   A#A%Nr   )rO   rM  INDEXrW  rT  rV  s   &&    r   !parse_unknown_options_from_packet(Dhcpcd.parse_unknown_options_from_packet  s1    . 	+ )5LD) 6 r   c                ,   < V ^8  d   QhRS[ RS[ RS[/# )r%   
lease_dumpr3   r'   )r(   r   )r)   rn   s   "r   r*   rA    s'     F Fs Fs Ft Fr   c           
     V   \         P                  RW4        \        V P                  4       P	                  RR4      P                  R4       Uu. uF  pRV9   g   K  VP                  R^R7      NK!  	  up4      pV'       g)   Rp\         P                  W@4       \        W@,          4      h YR
&   TP                  4        UUu/ uF  w  rgTP	                  RR4      TbK  	  pppRRRR/pTP                  4        F   w  rY9   g   K  TP                  T	4      Y:&   K"  	  \        P                  ! RT R24      p\        P                  T^4      pT'       d   \        P                   ! T4      TR&   T# u upi   \         d#   p\         P                  RT 4       \        ThR	p?ii ; iu uppi )a  parse the output of dhcpcd --dump

map names to the datastructure we create from dhclient

example dhcpcd output:

broadcast_address='192.168.15.255'
dhcp_lease_time='3600'
dhcp_message_type='5'
dhcp_server_identifier='192.168.0.1'
domain_name='us-east-2.compute.internal'
domain_name_servers='192.168.0.2'
host_name='ip-192-168-0-212'
interface_mtu='9001'
ip_address='192.168.0.212'
network_number='192.168.0.0'
routers='192.168.0.1'
subnet_cidr='20'
subnet_mask='255.255.240.0'
z)Parsing dhcpcd lease for interface %s: %r'rS   
=)maxsplitz;No valid DHCP lease configuration found in dhcpcd lease: %rzError parsing dhcpcd lease: %rNr3   r  -z
ip-addresszfixed-addresszclassless-static-routesr  z/var/lib/dhcpcd/z.leaser   )r-   r.   r7   r   r   r   r   r   r   rJ   popr   load_binary_filer>  rZ  r   r   )r]  r3   ar   r  r   r4  valuename_mapsourcedestinationdhcp_messager   s   &&           r   parse_dhcpcd_leaseDhcpcd.parse_dhcpcd_lease  s   , 			7	

	7 (--/77R@FFtLLax -AGGC!G,LE 0  		#*/0@AA  'k AFN*#S#&-N /%
 $,>>#3F%*YYv%6" $4 ,,yk0
 ::<M#)#3#3G#<E- U  	7II6
C+6	7 Os;   6E5 	E0E03E5 (E5 F%0E5 5F" FF"c                <   < V ^8  d   QhRS[ RS[S[ S[3,          /# r}   r~   )r)   rn   s   "r   r*   rA  W  s#     . .# .$sCx. .r   c                4    V P                  \        P                  ! V P                  RRV.4      P                  V4      #   \        P                   dC   p\
        P                  RTP                  TP                  TP                  4       \        ThRp?ii ; i)zReturn a dict of dhcp options.

@param interface: which interface to dump the lease from
@raises: InvalidDHCPLeaseFileError on empty or unparsable leasefile
    content.
z--dumpleaserC  rD  N)
rl  r   rW   r   r   r-   r.   r   r   r   )rY   r3   r   s   && r   r   Dhcpcd.get_newest_leaseW  s    	.**		((%$!	 &
 
 )) 	.IIC	 #-	.s   =A   B=BBc                L   < V ^8  d   QhRS[ RS[S[S[ S[ 3,          ,          /# r   r   )r)   rn   s   "r   r*   rA  u  s(      C DsCx,A r   c                    V P                  4       pV'       d*   \        VR,          VR,          4       Uu. uF  q"NK  	  up# \        P                  RV 4       . # u upi )a  
classless static routes as returned from dhcpcd --dumplease and return
a list containing tuple of strings.

The tuple is composed of the network_address (including net length) and
gateway for a parsed static route.

@param routes: string containing classless static routes
@returns: list of tuple(str, str) for all valid parsed routes until the
          first parsing error.

e.g.:

sr=parse_static_routes(
    "0.0.0.0/0 10.0.0.1 168.63.129.16/32 10.0.0.1"
)
sr=[
    ("0.0.0.0/0", "10.0.0.1"),
    ("169.63.129.16/32", "10.0.0.1"),
]
NNr%      Nr%   z'Malformed classless static routes: [%s])r   zipr-   r   r   r  is   &  r   r   Dhcpcd.parse_static_routest  sT    . "=#5}T7JKLK!AKLL=vF	 Ms   
Ar   r   )r   r   r   r   rW   r   r0   r   rZ  rl  r   r   r   r   r   s   @r   r>  r>  f  sf     KGv. v.p ) )V F FP. .:  r   r>  c                   z   a a ] tR tRt oRtV 3R ltRV3R lR lltV3R lR lt]V3R lR	 l4       t	R
t
VtV ;t# )Udhcpci  udhcpcc                2   < \         SV `  4        R V n        R# )rS   Nr   r   s   &r   rZ   Udhcpc.__init__  s    r   c                p   < V ^8  d   QhRS[ RS[S[S[ S[ S[ .R3,          ,          RS[S[ S[3,          /# r   r   )r)   rn   s   "r   r*   Udhcpc.__annotate__  sK     F0 F0F0  #sC$)> ?@F0
 
c3hF0r   c                   \         P                  RV4       \        P                  ! RR7      p\        P
                  P                  WAR,           4      V n        \        \        4      ;_uu_ 4        \        P                  ! V P                  4       RRR4       VP                  P                  V4       \        P
                  P                  VR4      p\        P                  ! V\        R4       V P                   RR	R
VRVRRRR.p\#        V4      '       dC   VP%                  RRP'                  \)        V4      R,          P+                  RR4      4      .4        \,        P,                  ! VRV P                  /RR7      w  rxTe
   T! YT4       T P9                  T4      #   + '       g   i     EL; i  \,        P.                   dC   p	\         P                  RT	P0                  T	P2                  T	P4                  4       \6        T	hRp	?	ii ; i)aN  Run udhcpc on the interface without scripts or filesystem artifacts.

@param interface: Name of the network interface on which to run udhcpc.
@param dhcp_log_func: Callable accepting the interface and client's
    stdout, stderr streams.
@return: A list of dicts of representing the dhcp leases parsed from
    the udhcpc lease file.
r   Tr   z.lease.jsonNudhcpc_scripti  z-Ostaticroutesz-iz-sz-nz-qz-fz-vz-xz	0x3d:20{}r   r   rS   
LEASE_FILE)
update_envcapturez1udhcpc exited with code: %s stderr: %r stdout: %r)r-   r.   r   r   r>   r?   rC   r   r   r   re   r   r   r   r   UDHCPC_SCRIPTrW   r   extendr)   r   r   r   r   r   r   r   r   r   )
rY   r3   r&   r1   r   r  cmdr   r   r   s
   &&&&      r   r0   Udhcpc.dhcp_discovery  s    			5yA--='',,wM0IJ'((IIdoo& ) 	y)Wo>}e< 
$ 9%%JJ&&))4S9AA#rJ	.yyt ?HC $)#.$$Y//i )((P )) 	.IIC	 #-	.s$   0!F 'F4  F1	4H	=HHc                <   < V ^8  d   QhRS[ RS[S[ S[3,          /# r}   r~   )r)   rn   s   "r   r*   r    s'     D D# D$sCx. Dr   c                j    \         P                  ! \         P                  ! V P                  4      4      # )a  Get the most recent lease from the ephemeral phase as a dict.

Return a dict of dhcp options. The dict contains key value
pairs from the most recent lease.

@param interface: an interface name - not used in this class, but
    required for function signature compatibility with other classes
    that require a distro object
@raises: InvalidDHCPLeaseFileError on empty or unparsable leasefile
    content.
)r   	load_jsonrB   r   r   s   &&r   r   Udhcpc.get_newest_lease  s"     ~~d11$//BCCr   c                L   < V ^8  d   QhRS[ RS[S[S[ S[ 3,          ,          /# r   r   )r)   rn   s   "r   r*   r    s(      C DsCx,A r   c                    V P                  4       pV'       d*   \        VR ,          VR,          4       Uu. uF  q"NK  	  up# . # u upi )rs  rt  )r   rv  rw  s   &  r   r   Udhcpc.parse_static_routes  sC    "=#5}T7JKLK!AKLL	 Ms   
Ar:  r   )r   r   r   r   rW   rZ   r0   r   r   r   r   r   r;  r<  s   @@r   r{  r{    sA     KF0 F0PD D   r   r{  c                l    V ^8  d   Qh/ ^ \         9   d    \        \        \        ,          ,          ;R&   # )r%   ALL_DHCP_CLIENTS)__conditional_annotations__r	   r   rR   )r)   s   "r   r*   r*      s%    

d I H$tJ'( He r   r   rU   )7r  r   rd   loggingr>   r   r   r   r   r   
contextlibr   ior   
subprocessr   typingr   r   r   r	   r
   r   r   r8   	cloudinitr   r   r   cloudinit.netr   r   	getLoggerr   r-   r=   r%  r&  r  	Exceptionr   r   r!   r#   r4   r;   rG   rP   ABCrR   r   r>  r{  r  r*   )r  s   @r   <module>r     s
   
   	 	       % C C C  , , <!1 1  / B2y 2 0 B 0 B/&6 /O2K&H HVB&* B&JjZ jZ	cZ cL -3K+H  Hr   