+
    im                        ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtHtH	t	H
t
Ht ^ RIHtHt ^ RIHt ]P"                  ! ]4      tRtRt. RrOt. RsOt]P0                  ! R4      3R ltR	 tRtR
 ltRuR ltRvR ltR tR tR t R t!R t"R t#R t$R t%]PL                  ! RR7      R R l4       t']PL                  ! RR7      R R l4       t(R R lt)RvR lt*R t+R t,RvR R  llt-RvR! lt.RvR" lt/R# t0R$ t1R% t2R& t3R' t4 ! R( R)]54      t6R* t7R+ R, lt8R- R. lt9R/ R0 lt:R1 R2 lt;R3 R4 lt<R5 R6 lt=R7 R8 lt>R9 R: lt?RvR; R< llt@R= tARwR> ltBRxR? ltCRyR@ ltDRA tERB tFRC RD ltGRE RF ltHRG RH ltIRI RJ ltJRK RL ltKRM RN ltLRzRO RP lltMRQ RR ltNRS tORT RU ltPRV RW ltQRX RY ltRRZ R[ ltSR\ R] ltTR^ R_ ltUR` Ra ltVRb Rc ltWRd Re ltXRf Rg ltYRh Ri ltZRj Rk lt[Rl Rm lt\Rn Ro lt] ! Rp Rq]^4      t_R# ){    N)CallableDictListOptionalTuple)subputil)Iproute2z/sys/class/net/eth0z([0-9]+)c                    \         P                  ! W4       Uu. uF4  pVP                  4       '       d   \        V4      MVP	                  4       NK6  	  up# u upi )a0  Sorting for Humans: natural sort order. Can be use as the key to sort
functions.
This will sort ['eth0', 'ens3', 'ens10', 'ens12', 'ens8', 'ens0'] as
['ens0', 'ens3', 'ens8', 'ens10', 'ens12', 'eth0'] instead of the simple
python way which will produce ['ens0', 'ens10', 'ens12', 'ens3', 'ens8',
'eth0'].)resplitisdigitintlower)s_nsretexts   && 8/usr/lib/python3/dist-packages/cloudinit/net/__init__.pynatural_sort_keyr   +   sK     HHU&&D \\^^D	5&  s
   AAc                     \         # )z3Simple function to return the global SYS_CLASS_NET.)SYS_CLASS_NET     r   get_sys_class_pathr   8   s    r   c                 @    \        4       V ,           R ,           V,           # )/)r   devnamepaths   &&r   sys_dev_pathr!   =   s    ')C/$66r   c                    \        W4      p \        P                  ! V4      pTP                  4       pTf   T#  Y',          #   \        \        3 dq   p\        TR R4      p	T	\        P                  \        P                  39   d   Te   T! T4      u Rp?# T	\        P                  39   d   Te   T! T4      u Rp?# h Rp?ii ; i  \         d/   pTe   T! T4      u Rp?# \        P                  RTT4       h Rp?ii ; i)errnoNz5Found unexpected (not translatable) value '%s' in '%s)r!   r	   load_text_fileOSErrorIOErrorgetattrr#   ENOENTENOTDIREINVALstripKeyErrorLOGdebug)
r   r    	translate	on_enoenton_keyerror	on_einvaldev_pathcontentsee_errnos
   &&&&&&    r   read_sys_netr7   A   s     G*H
&&x0 ~~H"" W !Wd+u||U]]33$ |#u||o%$ |#  	"q>!IIG
 	sR   A C C=B>C!B>7C=B>>CC?C:C?"C::C?c           	      *    R  p\        V VVVVVR7      # )c                     R # Fr   )r5   s   &r   on_excp_false(read_sys_net_safe.<locals>.on_excp_falseg   s    r   )r1   r0   r2   r/   )r7   )ifacefieldr/   r;   s   &&& r   read_sys_net_safer?   f   s(     ! r   c                 d    \        W4      pVR J d   R#  \        V4      #   \         d     R# i ; i)FN)r?   r   
ValueError)r=   r>   vals   && r   read_sys_net_intrC   t   s6    
E
)C
e|3x s   
  //c                 .    R RRRRR/p\        V RVR7      # )upTunknowndownF	operstate)r/   r?   )r   r/   s   & r   is_uprJ   ~   s%     tYfe<IWkYGGr   c                 T    \         P                  P                  \        V R 4      4      # )bridgeosr    existsr!   r   s   &r   	is_bridgerQ      s    77>>,w9::r   c                 T    \         P                  P                  \        V R 4      4      # )bondingrM   rP   s   &r   is_bondrT      s    77>>,w	:;;r   c                n    \        V RR7      p\        P                  P                  V4      '       d   V# R# )z8Return the master path for devname, or None if no mastermasterr    N)r!   rN   r    rO   r   s   & r   
get_masterrX      s)    h/D	ww~~dr   c                0   \        V 4      pVf   R# \        P                  P                  VR4      p\        P                  P                  VR4      p\        P                  P	                  V4      ;'       g     \        P                  P	                  V4      # )z@Return a bool indicating if devname's master is a bridge or bondFrS   rL   )rX   rN   r    joinrO   )r   master_pathbonding_pathbridge_paths   &   r   master_is_bridge_or_bondr^      se    W%K77<<Y7L'',,{H5K77>>,'FF277>>++FFr   c                |    \        V 4      pVf   R# \        V RR7      p\        P                  P	                  V4      # )z;Return a bool indicating if devname's master is openvswitchFzupper_ovs-systemrW   )rX   r!   rN   r    rO   )r   r[   ovs_paths   &  r   master_is_openvswitchra      s5    W%KG*<=H77>>(##r   c                      \        V R 4      R8H  # )type32rI   rP   s   &r   is_ib_interfacere      s    Wf-55r   )maxsizec                $    V ^8  d   QhR\         /#    returnbool)formats   "r   __annotate__rn      s      $ r   c                 ~    \        \        P                  ! R4      4      p V '       g   \        P	                  R4       V # )zDReturn a bool indicating if Open vSwitch is installed in the system.	ovs-vsctlz<ovs-vsctl not in PATH; not detecting Open vSwitch interfaces)rl   r   whichr-   r.   )rets    r   openvswitch_is_installedrs      s0     tzz+&
'C		J	
 Jr   c                $    V ^8  d   QhR\         /# rh   )list)rm   s   "r   rn   rn      s        T  r   c                      \         P                   ! \        4      w  rV P                  4       #   \         P                   d4   pRTP                  9   d   \
        P                  R4       . u Rp?# h Rp?ii ; i)zReturn a list of the names of OVS internal interfaces on the system.

These will all be strings, and are used to exclude OVS-specific interface
from cloud-init's network configuration handling.
zdatabase connection failedzJOpen vSwitch is not yet up; no interfaces will be detected as OVS-internalN)r   !OVS_INTERNAL_INTERFACE_LOOKUP_CMD
splitlinesProcessExecutionErrorstderrr-   info)out_errexcs      r   get_ovs_internal_interfacesr      sf     II?@	 ~~ %% '3::5HH  Is!   . A6'A1*A60A11A6c                0    V ^8  d   QhR\         R\        /# )ri   r   rj   strrl   )rm   s   "r   rn   rn      s      s t r   c                z    \        4       '       g   R# \        4       pW9   d   \        P                  RV 4       R# R# )zxReturns True if this is an OVS internal interface.

If OVS is not installed or not yet running, this will return False.
FzDetected %s as an OVS interfaceT)rs   r   r-   r.   )r   ovs_bridgess   & r   !is_openvswitch_internal_interfacer      s3    
 $%%-/K		3W=r   c                l    Vf   \        V 4      p\        W4      '       g   \        W4      '       d   R# R# )znetfailover driver uses 3 nics, master, primary and standby.
this returns True if the device is either the primary or standby
as these devices are to be ignored.
TF)device_driveris_netfail_primaryis_netfail_standbyr   drivers   &&r   is_netfailoverr      s6    
 ~w''**.@/ / r   c                H    Rp \        V R4      pV#   \         d     T# i ; i)zDReturns a str from reading /sys/class/net/<devname>/device/features. zdevice/features)r7   	Exceptionr   featuress   & r   get_dev_featuresr      s9    H):; O  Os    !!c                d    \        V 4      pV'       d   \        V4      ^@8  d   R# V^>,          R8H  # )zReturn True if VIRTIO_NET_F_STANDBY bit (62) is set.

https://github.com/torvalds/linux/blob/         089cf7f6ecb266b6a4164919a2e69bd2f938374a/         include/uapi/linux/virtio_net.h#L60
F1)r   lenr   s   & r   has_netfail_standby_featurer      s.      (Hs8}r)B<3r   c                $    V ^8  d   QhR\         /# rh   rk   )rm   s   "r   rn   rn      s      t r   c                z    \        V 4      e   R# Vf   \        V 4      pVR8w  d   R# \        V 4      '       g   R# R# )zA device is a "netfail master" device if:

- The device does NOT have the 'master' sysfs attribute
- The device driver is 'virtio_net'
- The device has the standby feature bit set

Return True if all of the above is True.
F
virtio_netTrX   r   r   r   s   &&r   is_netfail_masterr      s=     '&~w'&w//r   c                h   \        V RR7      p\        P                  P                  V4      '       g   R# Vf   \	        V 4      pVR8X  d   R# \        P                  P                  \        P                  P                  V4      4      p\	        V4      pVR8w  d   R# \        V4      pV'       g   R# R# )a  A device is a "netfail primary" device if:

- the device has a 'master' sysfs file
- the device driver is not 'virtio_net'
- the 'master' sysfs file points to device with virtio_net driver
- the 'master' device has the 'standby' feature bit set

Return True if all of the above is True.
rV   rW   Fr   T)r!   rN   r    rO   r   basenamerealpathr   )r   r   master_sysfs_pathmaster_devnamemaster_drivermaster_has_standbys   &&    r   r   r     s     %W8<77>>+,,~w'WW%%bgg&6&67H&IJN!.1M$4^Dr   c                z    \        V 4      f   R# Vf   \        V 4      pVR8w  d   R# \        V 4      '       g   R# R# )zA device is a "netfail standby" device if:

- The device has a 'master' sysfs attribute
- The device driver is 'virtio_net'
- The device has the standby feature bit set

Return True if all of the above is True.
Fr   Tr   r   s   &&r   r   r   9  s=     '"~w'&w//r   c                @    \        V R4      pV'       d
   VR9   d   R# R# )a  
/* interface name assignment types (sysfs name_assign_type attribute) */
#define NET_NAME_UNKNOWN      0  /* unknown origin (not exposed to user) */
#define NET_NAME_ENUM         1  /* enumerated by kernel */
#define NET_NAME_PREDICTABLE  2  /* predictably named by the kernel */
#define NET_NAME_USER         3  /* provided by user-space */
#define NET_NAME_RENAMED      4  /* renamed by user-space */
name_assign_typeTF)34rI   )r   r   s   & r   
is_renamedr   Q  s#     )2DE,
:r   c                 R    \        \        V R 4      4      pRVP                  4       9   # )ueventzDEVTYPE=vlan)r   r?   rx   )r   r   s   & r   is_vlanr   `  s(    "7H56FV..000r   c                    Rp\        V R4      p\        P                  P                  V4      '       d4   \        P                  P	                  \        P
                  ! V4      4      pV# )z8Return the device driver for net device named 'devname'.Nzdevice/driver)r!   rN   r    islinkr   readlink)r   r   driver_paths   &  r   r   r   e  sH    Fw8K	ww~~k""!!"++k":;Mr   c                .    \        V R4      pVRJ d   R# V# )z;Return the device id string for net device named 'devname'.zdevice/deviceFNrI   )r   dev_ids   & r   device_devidr   p  s    w8FMr   c                  h   \         P                  ! 4       '       g   \         P                  ! 4       '       d"   \        \	        4       P                  4       4      #  \        P                  ! \        4       4      p V #   \         d.   pTP                  \        P                  8X  d	   . p  R p?T # h R p?ii ; iN)r	   
is_FreeBSDis_DragonFlyBSDru   get_interfaces_by_macvaluesrN   listdirr   r%   r#   r(   )devsr5   s     r   get_devicelistr   y  s    D0022)+22455zz,./ K  77ell"D K 	s   A9 9B1!B,+B,,B1c                       ] tR tRtRtRtR# )ParserErrori  z6Raised when a parser has issue parsing a file/content.r   N)__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r     s    @r   r   c                 j    V '       d   \        V \        4      '       g   R # V P                  R4      R8H  # )Fconfigdisabled)
isinstancedictget)cfgs   &r   is_disabled_cfgr     s(    jd++778
**r   c                :    V ^8  d   QhR\         \        ,          /# rh   r   r   )rm   s   "r   rn   rn     s     
. 
.T#Y 
.r   c                    \         P                  ! 4       '       g   \         P                  ! 4       '       d   \        4       # \         P                  ! 4       '       g   \         P
                  ! 4       '       d   \        4       # \        4       # )ziGet the list of network interfaces viable for networking.

@return List of interfaces, sorted naturally.
)r	   r   r   find_candidate_nics_on_freebsd	is_NetBSD
is_OpenBSD(find_candidate_nics_on_netbsd_or_openbsdfind_candidate_nics_on_linuxr   r   r   find_candidate_nicsr     sS    
 D0022-//			T__..799+--r   c                :    V ^8  d   QhR\         \        ,          /# rh   r   r   )rm   s   "r   rn   rn     s     , ,8C= ,r   c                    \         P                  ! 4       '       g   \         P                  ! 4       '       d   \        4       # \         P                  ! 4       '       g   \         P
                  ! 4       '       d   \        4       # \        4       # )z.Get the name of the 'fallback' network device.)r	   r   r   find_fallback_nic_on_freebsdr   r   &find_fallback_nic_on_netbsd_or_openbsdfind_fallback_nic_on_linuxr   r   r   find_fallback_nicr     sQ    D0022+--			T__..577)++r   c                :    V ^8  d   QhR\         \        ,          /# rh   r   )rm   s   "r   rn   rn     s     J J$s) Jr   c                 P    \        \        4       P                  4       \        R7      # )zeGet the names of the candidate network devices on NetBSD/OpenBSD.

@return list of sorted interfaces
key)sortedr   r   r   r   r   r   r   r     s    
 ')0028HIIr   c                :    V ^8  d   QhR\         \        ,          /# rh   r   )rm   s   "r   rn   rn     s     	 	 	r   c                 <    \        4       p V '       d
   V ^ ,          # R# )z^Get the 'fallback' network device name on NetBSD/OpenBSD.

@return default interface, or None
N)r   namess    r   r   r     s    
 56EQxr   c                :    V ^8  d   QhR\         \        ,          /# rh   r   )rm   s   "r   rn   rn     s     J JS	 Jr   c                     \         P                   ! . RO4      w  rV P                  4       pV'       d   V# \        \        4       P	                  4       \
        R7      # )z_Get the names of the candidate network devices on FreeBSD.

@return List of sorted interfaces.
r   )ifconfigz-lz-uether)r   r   r   r   r   r   )stdout_stderrr   s      r   r   r     sE    
 ii ABOF\\^F ')0028HIIr   c                :    V ^8  d   QhR\         \        ,          /# rh   r   )rm   s   "r   rn   rn     s     	 	hsm 	r   c                 <    \        4       p V '       d
   V ^ ,          # R# )zWGet the 'fallback' network device name on FreeBSD.

@return List of sorted interfaces.
N)r   r   s    r   r   r     s    
 +,EQxr   c                :    V ^8  d   QhR\         \        ,          /# rh   r   )rm   s   "r   rn   rn     s     O Od3i Or   c            	        R\         P                  ! 4       9   d   \        P                  R4       Mr\	        4        U u. uF!  p V R8w  g   K  \        V 4      '       d   K  V NK#  	  pp \        V4      '       d-   \        P                  RV4        \         P                  ! 4        . p. p\        RRRRRRR	7       F  w  p  pVR8X  d   K  VP!                  R
4      '       d   \        P                  RV4       K@  \#        VR4      pV'       d   VP%                  V4       Kg  \        P                  RV4       \#        VR4      pV'       d   VP%                  V4       K  \'        VR4      p	V	R9   d   VP%                  V4       K  \        P                  RV4       K  	  . p
W43 FR  p\)        V\*        R7      p\,        V9   d,   VP/                  \,        4       VP1                  ^ \,        4       W,          p
KT  	  V
# u up i   \        P                   dM   p\        P                  RTP                  TP                  TP                  TP                  4        Rp?ELRp?ii ; i)z]Get the names of the candidate network devices on Linux.

@return List of sorted interfaces.
znet.ifnames=0z9Stable ifnames disabled by net.ifnames=0 in /proc/cmdlineloz4Found unstable nic names: %s; calling udevadm settlezAudevadm failed to settle: cmd=%r stderr=%r stdout=%r exit_code=%sNFT)filter_openvswitch_internal2filter_slave_if_master_not_bridge_bond_openvswitchfilter_vlanfilter_without_own_macfilter_zero_maclog_filtered_reasonsvethzIgnoring veth interface: %scarrierzInterface has no carrier: %sdormantrH   zInterface ignored: %sr   )r   rG   lowerlayerdownrF   )r	   get_cmdliner-   r.   r   r   r   udevadm_settler   ry   warningcmdrz   r   	exit_codeget_interfaces
startswithrC   appendr?   r   r   DEFAULT_PRIMARY_INTERFACEremoveinsert)deviceunstableerror	connectedpossibly_connected	interface_r   r   rH   sorted_interfaces
interfacess               r   r   r     s$   
 $**,,		MN )*
*~ &0&8 F* 	 

 x==IIF
##% I,$);@$!	1a ''II3Y?"9i8Y'		0)< #9i8%%i0%i=	HH%%i0		)95=J  5
J,<=
$
278a!:;' 6 O
 -- >IILLLLOO s*   	G9G9G9G> >IAIIc                :    V ^8  d   QhR\         \        ,          /# rh   r   )rm   s   "r   rn   rn   )  s     	 	HSM 	r   c                 <    \        4       p V '       d
   V ^ ,          # R# )zUGet the 'fallback' network device name on Linux.

@return List of sorted interfaces.
N)r   r   s    r   r   r   )  s    
 )*EQxr   c                :    V ^8  d   QhR\         \        ,          /# rh   )r   r   )rm   s   "r   rn   rn   5  s      HTN r   c                    \        4       pV'       g   R# \        V4      '       d   RV/pMR\        VR4      P                  4       /pV '       d   \	        V4      pV'       d   W2R&   RRRRR	VR
V/pRW/R^/pV# )zBGenerate network cfg v2 for dhcp on the NIC most likely connected.Nname
macaddressaddressr   dhcp4Tdhcp6set-namematch	ethernetsversion)r   r   r?   r   r   )config_drivertarget_namer  r   r   nconfs   &     r   generate_fallback_configr  5  s     $%K %%% +KCIIK
 {+$(OK	C ;,i;ELr   c                     R  pR pV P                  R4      pV^8X  d	   V! V 4      # V^8X  d	   V! V 4      # \        RV,          4      h)c                    . pV P                  R / 4       F  pVP                  R4      R8w  d   K  VP                  R4      pV'       g   K6  VP                  R4      pVP                  R/ 4      P                  R4      pVP                  R/ 4      P                  R4      pV'       g   \        V4      pV'       g   \        V4      pVP                  W4WV.4       K  	  V# )r   rc   physicalmac_addressr  paramsr   	device_id)r   r   r   r  )netcfgphysdevsentmacr  r   r$  s   &      r   
_version_1$extract_physdevs.<locals>._version_1S  s    ::h+Cwwv*,''-(C776?DWWXr*..x8F"-11+>I&t,(.	OOS:; , r   c                    . pV P                  R / 4      P                  4        F  pVP                  R4      pV'       g   K  VP                  R/ 4      P                  R4      pV'       g   KI  VP                  R/ 4      P                  R4      pVP                  R/ 4      P                  R4      pV'       g   \        V4      pV'       g   \        V4      pVP	                  WCWV.4       K  	  V# )r  r  r  r  r   r$  )r   r   r   r   r  )r%  r&  r'  r  r(  r   r$  s   &      r   
_version_2$extract_physdevs.<locals>._version_2e  s    ::k2.557C77:&D'''2&**<8CWWWb)--h7F,00=I&t,(.	OOS:; 8  r   r  z"Unknown network config version: %s)r   RuntimeError)r%  r)  r,  r  s   &   r   extract_physdevsr/  R  sQ    $( jj#G!|&!!	A&!!
;gE
FFr   c                V    \        V R4      pVf   V'       d   \        R4      hR# VR9   # )a  return True if the provided interface has its own address.

Based on addr_assign_type in /sys.  Return true for any interface
that does not have a 'stolen' address. Examples of such devices
are bonds or vlans that inherit their mac from another device.
Possible values are:
  0: permanent address    2: stolen from another device
1: randomly generated   3: set using dev_set_mac_addressaddr_assign_typez%s had no addr_assign_type.T)r         )rC   rA   )ifnamestrictassign_types   && r   interface_has_own_macr7    s6     #6+=>K :;;)##r   c                   / p\        4        F-  w  r#rERRRVRVRVP                  4       RVR\        V4      /W&   K/  	  V '       d   \        P                  ! R4      p\
        P
                  ! . ROR	R
7      w  rx\
        P
                  ! . ROR	R
7      w  r\        4       p
Wy3 F#  pV
P                  VP                  V4      4       K%  	  VP                  4        F%  pVR,          RJ ;'       g    VR,          V
9  VR&   K'  	  V# )a  Collect information necessary for rename_interfaces.

returns a dictionary by mac address like:
   {name:
     {
      'downable': None or boolean indicating that the
                  device has only automatically assigned ip addrs.
      'device_id': Device id value (if it has one)
      'driver': Device driver (if it has one)
      'mac': mac address (in lower case)
      'name': name
      'up': boolean: is_up(name)
     }}
downableNr$  r   r(  r  rE   z[0-9]+:\s+(\w+)[@:]T)captureF)ipz-6addrshow	permanentscopeglobal)r;  z-4r<  r=  )
r   r   rJ   r   compiler   setupdatefindallr   )check_downablecur_infor  r(  r   r$  nmatchipv6r}   ipv4nics_with_addresses	bytes_outds   &            r   _get_current_rename_inforM    s     H(6(8$6f399;D%+
 )9 23YYH

 YY;TJ
!eI&&v~~i'@A & "A$5 HHAfI5H$H jM #
 Or   c                 F  aa \        V 4      '       g   \        P                  R 4       R# Vf   \        4       p/ oVP	                  4        FO  w  rEVP                  4       pVP                  R4      '       d   VR,          P                  4       VR&   WFR&   VSV&   KQ  	  \        P                  RS4       R p. p. p	. p
V! S4      pRpRpR oVV3R lpV  EF  w  ppppV'       d   VP                  4       p. pV! VVV4      pV'       g%   V'       d   V	P                  R	V: R
V: R24       KY  VP                  R4      pVV8X  d   Ks  V'       g%   V'       d   V	P                  R	V: R
V: R24       K  VR,          '       dh   RpVR,          '       g&   V'       d   V	P                  VVVV3,          4       K  RVR&   VP                  RVVV334       V
P                  RVVV334       VV9   d   VV,          pVR,          '       dN   RpVR,          '       g'   V'       d   V	P                  VVVV3,          4       EKk  VP                  RVVV334       RpVe   VV9   d   V^,          pW,          pK  VP                  RVVVV334       VVR&   V! S4      pVR,          '       d   V
P                  RVVV334       VP                  RVVVR,          V334       VVR&   V! S4      pVV,          pEK!  	  R\        P                  R\        P                  R\        P                  /pV'       gI   V
'       gA   \        V	4      '       d   \        P                  RV V	4       MV\        P                  RV 4       M?\        P                  RWV
,           4       W,            F  w  pppp VV,          ! V!   K  	  \        V	4      '       d   \        RP!                  V	4      4      hR#   \         d0   pT	P                  RT: T: RT: RT: RT: 2	4        Rp?K|  Rp?ii ; i)zno interfaces to renameNr(  r  zDetected interfaces %sc                 B    \        R  V P                  4        4       4      # )c              3   6   "   T F  qR ,          V3x  K  	  R# 5i)r  Nr   ).0datas   & r   	<genexpr><_rename_interfaces.<locals>.update_byname.<locals>.<genexpr>  s     D^T&\4(^s   )r   r   )bymacs   &r   update_byname)_rename_interfaces.<locals>.update_byname  s    DU\\^DDDr   z
cirename%dc                &   V'       dE   V'       d=   V'       d5   V R,          V8H  ;'       d!    V R,          V8H  ;'       d    V R,          V8H  # V'       d)   V'       d!   V R,          V8H  ;'       d    V R,          V8H  # V'       d   V R,          V8H  # R# )zmatch if set and in datar(  r   r$  Fr   )rR  r(  r   r$  s   &&&&r   entry_match'_rename_interfaces.<locals>.entry_match  s    6iUs" 3 3Nf,3 3%2
 V;#%BB$x.F*BB;#%%r   c           	        < SP                  4        Uu. uF  pS! W0W4      '       g   K  VNK  	  pp\        V4      '       d8   \        V4      ^8  d   RV: RV : RV: RV: R2	p\        V4      hV^ ,          # R# u upi )r2  z2Failed to match a single device. Matched devices "z" with search values "(mac:z driver:z device_id:z)"N)r   r   rA   )r(  r   r$  rR  r  msgrF  rY  s   &&&   r   
find_entry&_rename_interfaces.<locals>.find_entry  s     !)
)4f8 D) 	 

 u::5zA~ c696 
 !o%8O
s
   A<A<z$[nic not present] Cannot rename mac=z to z, not available.rE   z*[busy] Error renaming mac=%s from %s to %sr9  FrG   z2[busy-target] Error renaming mac=%s from %s to %s.renamez1Unable to rename interfaces: %s due to errors: %sz$no work necessary for renaming of %szRenamed %s with ops %sz[unknown] Error performing z for z, z: 
)r   r-   r.   rM  itemscopyr   r   r  r
   link_rename	link_downlink_upr   r   r.  rZ   )renamesstrict_presentstrict_busycurrent_infor  rR  currV  opserrorsups
cur_bynametmpname_fmttmpir]  r(  new_namer   r$  cur_opscur_namer\  targettmp_nameopmapopr#  r5   rF  rY  s   &&&&                        @@r   _rename_interfacesry    s    w<<		+,/1H"((*
iik775>>U))+CJF + II&1E CF
Cx(JKD$ -4(Xvy))+Cfi0*-x9 776?x*-x9 t99>Cz??MM#h(A"ABCINNFCH;?@JJc8h[9:z!)Fd||Jj))"cS(H,E&EFNNFCH;#GH&*H"h*&<	&-NNHc8h5IJK%F6N&x0Jd||

D#x(=>#x#f+x1HIJF"8,
w{ -4@ 	(&&""h"E #v;;KKC II<gF		*G3Y?),%BXvb	6" *3 6{{499V,--   63!5 s   (O&&P 1$PP c                ~    Rp\         P                  P                  \        V R4      4      '       d   Rp\	        W4      # )z6Returns the string value of an interface's MAC Addressr  bonding_slavezbonding_slave/perm_hwaddr)rN   r    isdirr!   r?   )r4  r    s   & r   get_interface_macr}  b  s3    D	ww}}\&/:;; +V**r   c                    \        V R4      R8X  d1   \        V 4      pV'       d   V'       d   V^$R VR,          ,           pV# R# )zReturns the string value of an Infiniband interface's hardware
address. If ethernet_format is True, an Ethernet MAC-style 6 byte
representation of the address will be returned.
rc   rd   :3   NNNi)r?   r}  )r4  ethernet_formatr(  s   && r   get_ib_interface_hwaddrr  l  s@     (D0'?b+C(C
 1r   c                $    V ^8  d   QhR\         /# rh   r   )rm   s   "r   rn   rn   z  s     0 0t 0r   c                  *   \         P                  ! 4       '       g   \         P                  ! 4       '       d   \        4       # \         P                  ! 4       '       d   \        4       # \         P                  ! 4       '       d   \        4       # \        4       # r   )	r	   r   r    get_interfaces_by_mac_on_freebsdr   get_interfaces_by_mac_on_netbsdr    get_interfaces_by_mac_on_openbsdget_interfaces_by_mac_on_linuxr   r   r   r   r   z  s[    D0022/11			.00			/11-//r   c                F    V ^8  d   QhR\         R\        \         ,          /# )ri   r(  rj   )r   r   )rm   s   "r   rn   rn     s      c hsm r   c                     \        4       P                  4        F,  w  rV P                  4       VP                  4       8X  g   K*  Vu # 	  R # r   )r   rb  r   )r(  interface_macinterface_names   &  r   find_interface_name_from_macr    s>    )>)@)F)F)H%99;---//!! *I r   c                $    V ^8  d   QhR\         /# rh   r  )rm   s   "r   rn   rn     s      $ r   c                      \         P                   ! . RO4      w  rR pR pV! V! V 4      4       UUu/ uF  w  rEWEbK	  	  pppV# u uppi )r   c              3      "   R pV P                  R4       F2  pVP                  R4      '       d   W,          pK$  V'       d   Vx  TpK4  	  Vx  R# 5i)r   r`  	N)r   r   )r|   
curr_blocklines   &  r   flatten1get_interfaces_by_mac_on_freebsd.<locals>.flatten  sI     
IIdODt$$"
$$!
 $ s   ?AAc              3      "   V  FH  p\         P                  ! R V4      pV'       g   K$  VP                  R4      VP                  R4      3x  KJ  	  R# 5i)z2^(?P<ifname>\S*): .*ether\s(?P<mac>[\da-f:]{17}).*r(  r4  N)r   searchgroup)	flat_listblockms   &  r   find_mac2get_interfaces_by_mac_on_freebsd.<locals>.find_mac  sE     E		EuA qwwu~qwwx'899 s
   "A*A)r   -ar   )r   )r|   r  r  r  r(  r4  resultss          r   r  r    sM    yy45HS	: /7ws|.DE.D{ss{.DGEN Fs   Ac                $    V ^8  d   QhR\         /# rh   r  )rm   s   "r   rn   rn     s       r   c                  $   / p R p\         P                   ! RR.4      w  r#\        P                  ! RRV4      P                  4       pV FE  p\        P                  ! W4      pV'       g   K#  VP                  4       pVR,          WR,          &   KG  	  V # )zE(?P<ifname>\w+).*address:\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r   r  \n\s+ r4  r(  r   r   subrx   r  	groupdictrr   re_field_matchr|   r  if_linesr  r  fieldss           r   r  r        
C	6  yy*d+,HSvvhS)446HHH^*1[[]F!'!1Cu	 
 Jr   c                $    V ^8  d   QhR\         /# rh   r  )rm   s   "r   rn   rn     s      $ r   c                  $   / p R p\         P                   ! RR.4      w  r#\        P                  ! RRV4      P                  4       pV FE  p\        P                  ! W4      pV'       g   K#  VP                  4       pVR,          WR,          &   KG  	  V # )zC(?P<ifname>\w+).*lladdr\s(?P<mac>([\da-f]{2}[:-]){5}([\da-f]{2})).*r   r  r  r  r4  r(  r  r  s           r   r  r    r  r   c                $    V ^8  d   QhR\         /# rh   r  )rm   s   "r   rn   rn     s     D D Dr   c                 T   / p \        4        F  w  rr4W 9   dH   VR9   d!   \        P                  RVW,          V4       K3  RV: RW,          : RV: R2p\        V4      hWV&   \	        VR4      pV'       g   Km  W`9  d   WV&   Ky  \        P                  RVW,          V4       K  	  V # )	ziBuild a dictionary of tuples {mac: name}.

Bridges and any devices that have a 'stolen' mac are excluded.z>Ignoring duplicate macs from '%s' and '%s' due to driver '%s'.duplicate mac found! both '' and '' have mac 'z'.Tz^Ethernet and InfiniBand interfaces have the same address both '%s' and '%s' have address '%s'.)	fsl_enetc
mscc_felixqmi_wwan)r   r-   r.   r.  r  r   )rr   r  r(  r   _devidr\  ib_macs          r   r  r    s     C%3%5!6: @@		#H  A C
 s##C
 )t46*  "F=Ko &6| Jr   c                x    V ^8  d   QhR\         R\         R\         R\         R\         R\         R\         R\        /# )	ri   filter_hyperv_vf_with_syntheticr   r   r   r   r   r   rj   )rl   ru   )rm   s   "r   rn   rn     sX     : :%):!%: 9=: 	:
 !: : : 
:r   c           	     V   V'       d   \         P                  MR p. p\        4       p	RP                  R
4      p
V	 EFV  p\	        V4      '       d   V! RV4       K   V'       d   \        V4      '       d   K;  \        V4      '       d   V! RV4       KW  V'       d   \        V4      '       g   V! RV4       K{  V'       d2   \        V4      e%   \        V4      '       g   \        V4      '       g   K  \        V4      '       d   V! RV4       K  \        V4      pV'       g   V! RV4       K  V'       d   VR	8w  d   WR\        V4       8X  d   EK  V'       d   \        V4      '       d   EK.  \        V4      pVP!                  WV\#        V4      34       EKY  	  V '       d   \%        Wx4       V# )z~Return list of interface tuples (name, mac, driver, device_id)

Bridges and any devices that have a 'stolen' mac are excluded.c                      R # r   r   )argss   *r   <lambda> get_interfaces.<locals>.<lambda>  s    4r   :zIgnoring bridge interface: %szIgnoring bond interface: %sz)Ignoring interface with inherited MAC: %sNzIgnoring failover interface: %sz"Ignoring interface without mac: %sr   )00r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  )r-   r.   r   rZ   rQ   r   rT   r7  rX   r^   ra   r   r}  r   r   r   r  r   )filter_hyperv_vf_with_synthetic_interface)r  r   r   r   r   r   r   filtered_loggerrr   r   zero_macr  r(  r   s   &&&&&&&       r   r   r     sT    $8cii=OO
CDxx%HT??;TB74==4==94@!*?*E*EGN>4 ,,T22)$//$=tD%@$Gtt|
#c(7K0K&+L,
 ,
 t$

Dv|D'9:;G L '1/GJr   c          	          V ^8  d   QhR\         R,          R\        \        \        \        \        \        3,          ,          RR/# )ri   r  Nr  rj   ).N)r   r   r   r   )rm   s   "r   rn   rn   L  s>     '% '%i('%U3S#-./'% 
'%r   c                <   V Uu/ uF#  q"^,          R8X  g   K  V^,          V^ ,          bK%  	  ppV Uu. uF%  pV^,          V9   g   K  V^,          R8w  g   K#  VNK'  	  ppV F+  pVw  rgrV ! RVVW7,          V4       VP                  V4       K-  	  R# u upi u upi )ai  Filter Hyper-V SR-IOV/VFs when used with synthetic hv_netvsc.

Hyper-V's netvsc driver may register an SR-IOV/VF interface with a mac
that matches the synthetic (hv_netvsc) interface.  This VF will be
enslaved to the synthetic interface, but cloud-init may be racing this
process.  The [perhaps-yet-to-be-enslaved] VF should never be directly
configured, so we filter interfaces that duplicate any hv_netvsc mac
address, as this the most reliable indicator that it is meant to be
subordinate to the synthetic interface.

VF drivers will be mlx4_core, mlx5_core, or mana.  However, given that
this list of drivers has changed over time and mana's dependency on
hv_netvsc is expected to be removed in the future, we no longer rely
on these names. Note that this will not affect mlx4/5 instances outside
of Hyper-V, as it only affects environments where hv_netvsc is present.
	hv_netvsczdIgnoring %r VF interface with driver %r due to synthetic hv_netvsc interface %r with mac address %r.N)r  )
r  r  ihv_netvsc_mac_to_nameinterfaces_to_remover
  r  r(  r   r  s
   &&        r   r  r  L  s    * '&qA$+*=
!ad
J  
 AQ4(( 	
-.qT[-@ 	
   *	(6D!&	
 	)$ *s   BBB	BBc            
         / p \        4        FF  w  p  p\        VR4      pV'       g   K  W09   d   \        RV: RW,          : RV: R24      hW0V&   KH  	  V # )zPBuild a dictionary mapping Infiniband interface names to their hardware
address.Fr  r  r  ')r   r  r.  )rr   r  r  r  s       r   get_ib_hwaddrs_by_interfacer  v  sa     C')aA(u56}"S[[&2  I * Jr   c                0    V ^8  d   QhR\         R\        /# )ri   convert_to_addressr  )r   r   )rm   s   "r   rn   rn     s      ( S r   c                :     V ! V3/ VB #   \          d     R# i ; i)zUse a function to return an address. If conversion throws a ValueError
exception return False.

:param check_cb:
    Test function, must return a truthy value
:param address:
    The string to test.

:return:
    Address or False

F)rA   )r  r  kwargss   &&,r   maybe_get_addressr    s)    !'4V44 s    c                0    V ^8  d   QhR\         R\        /# ri   r  rj   r   )rm   s   "r   rn   rn     s     	B 	B3 	B4 	Br   c                H    \        \        \        P                  V 4      4      # )zReturns a bool indicating if ``s`` is an IP address.

:param address:
    The string to test.

:return:
    A bool indicating if the string is an IP address or not.
)rl   r  	ipaddress
ip_addressr  s   &r   is_ip_addressr    s     !)"6"6@AAr   c                0    V ^8  d   QhR\         R\        /# r  r   )rm   s   "r   rn   rn          	C 	CS 	CT 	Cr   c                H    \        \        \        P                  V 4      4      # )zReturns a bool indicating if ``s`` is an IPv4 address.

:param address:
    The string to test.

:return:
    A bool indicating if the string is an IPv4 address or not.
)rl   r  r  IPv4Addressr  s   &r   is_ipv4_addressr         !)"7"7ABBr   c                0    V ^8  d   QhR\         R\        /# r  r   )rm   s   "r   rn   rn     r  r   c                H    \        \        \        P                  V 4      4      # )zReturns a bool indicating if ``s`` is an IPv6 address.

:param address:
    The string to test.

:return:
    A bool indicating if the string is an IPv4 address or not.
)rl   r  r  IPv6Addressr  s   &r   is_ipv6_addressr    r  r   c                0    V ^8  d   QhR\         R\        /# r  r   )rm   s   "r   rn   rn     s     	P 	P3 	P4 	Pr   c                L    \        \        \        P                  V RR7      4      # )zReturns a bool indicating if ``s`` is an IPv4 or IPv6 network.

:param address:
    The string to test.

:return:
    A bool indicating if the string is an IPv4 address or not.
Fr5  )rl   r  r  
ip_networkr  s   &r   is_ip_networkr    s     !)"6"6NOOr   c                0    V ^8  d   QhR\         R\        /# r  r   )rm   s   "r   rn   rn           S T r   c                L    \        \        \        P                  V RR7      4      # )zReturns a bool indicating if ``s`` is an IPv4 network.

:param address:
    The string to test.

:return:
    A bool indicating if the string is an IPv4 address or not.
Fr  )rl   r  r  IPv4Networkr  s   &r   is_ipv4_networkr    #     )//G r   c                0    V ^8  d   QhR\         R\        /# r  r   )rm   s   "r   rn   rn     r  r   c                L    \        \        \        P                  V RR7      4      # )zReturns a bool indicating if ``s`` is an IPv6 network.

:param address:
    The string to test.

:return:
    A bool indicating if the string is an IPv4 address or not.
Fr  )rl   r  r  IPv6Networkr  s   &r   is_ipv6_networkr    r  r   c                <    V ^8  d   QhR\         R\         R\        /# )ri   r  subnetrj   r   )rm   s   "r   rn   rn     s!     ( (S (# ($ (r   c                f    \         P                  ! V 4      p\         P                  ! VRR7      pW#9   # )zReturns a bool indicating if ``s`` is in subnet.

:param address:
    The string of IP address.

:param subnet:
    The string of subnet.

:return:
    A bool indicating if the string is in subnet.
Fr  )r  r  r  )r  r  r  subnet_networks   &&  r   is_ip_in_subnetr    s/     %%g.J))&?N''r   c                <    V ^8  d   QhR\         R\         R\        /# )ri   gatewayr  rj   r   )rm   s   "r   rn   rn     s!      C   r   c                     \        W4      '       * #   \         d$   p\        P                  RT TT4        Rp?R# Rp?ii ; i)zReturns a bool indicating if should add gateway onlink flag.

:param gateway:
    The string of gateway address.

:param subnet:
    The string of subnet.

:return:
    A bool indicating if the string is in subnet.
zDFailed to check whether gateway %s is contained within subnet %s: %sNF)r  rA   r-   r   )r  r  r5   s   && r   should_add_gateway_onlink_flagr    sD    
"7333 1	
 s    A ;A c                $    V ^8  d   QhR\         /# rh   rk   )rm   s   "r   rn   rn     s      d r   c                    V R,          P                  R4      '       g   V R,          \        9   d   R# V R,          R8X  d#   \        V P                  R4      4      '       d   R# R# )z:Common helper for checking network_state subnets for ipv6.rc   6Tstaticr  F)endswithIPV6_DYNAMIC_TYPESr  r   )r  s   &r   subnet_is_ipv6r    sM     f~s##vf~9K'K	8	#

98M(N(Nr   c                $    V ^8  d   QhR\         /# rh   r   )rm   s   "r   rn   rn     s     C Cs Cr   c                Z    \        \        P                  ! RV  24      P                  4      # )zConvert a network prefix to an ipv4 netmask.

This is the inverse of ipv4_mask_to_net_prefix.
    24 -> "255.255.255.0"
Also supports input as a string.0.0.0.0/)r   r  r  netmask)prefixs   &r   net_prefix_to_ipv4_maskr    s'     y$$xx%89AABBr   c                $    V ^8  d   QhR\         /# rh   r   )rm   s   "r   rn   rn   &  s     	= 	=S 	=r   c                H    \         P                  ! RV  24      P                  # )zConvert an ipv4 netmask into a network prefix length.

If the input is already an integer or a string representation of
an integer, then int(mask) will be returned.
   "255.255.255.0" => 24
   str(24)         => 24
   "24"            => 24
r  )r  r  	prefixlen)masks   &r   ipv4_mask_to_net_prefixr  &  s"     (4& 12<<<r   c                $    V ^8  d   QhR\         /# rh   r
  )rm   s   "r   rn   rn   2  s        S  r   c                    \         P                  ! RV  24      P                  pV#   \         d     Mi ; i\         P                  ! T 4      p\        T4      pT^ 8X  d   T# \        \         P                  T( T^,
          ,          P                  4       4      pY4,	          p\         P                  T,
          p^T,          ^,
          pYV8w  d   \        RT ,          4      hT# )zConvert an ipv6 netmask (very uncommon) or prefix (64) to prefix.

If the input is already an integer or a string representation of
an integer, then int(mask) will be returned.
   "ffff:ffff:ffff::"  => 48
   "48"                => 48
z::/zInvalid network mask '%s')	r  r  r  rA   r  r   min
IPV6LENGTH
bit_length)r  r  r  mask_inttrailing_zeroesleading_onesall_oness   &      r   ipv6_mask_to_net_prefixr  2  s    ((3tf6@@	  	
 ""4(G7|H1}yHqL9EEGO .L$$6IY!#H4t;<<s   $' 55c                <    V ^8  d   QhR\         R\         R\         /# )ri   r  r;  rj   r  )rm   s   "r   rn   rn   U  s!      c s s r   c                b    \        \        P                  ! V RV  2RR7      P                  4      # )zCGet string representation of broadcast address from an ip/mask pairr   Fr  )r   r  r  broadcast_address)r  r;  s   &&r   mask_and_ipv4_to_bcast_addrr  U  s/    AdVnU;MM r   c                       ] tR tRtRtR# )RendererNotFoundErrori\  r   N)r   r   r   r   r   r   r   r   r  r  \  s    r   r  )r  
ipv6_slaaczipv6_dhcpv6-statelesszipv6_dhcpv6-stateful)rp   z--formatcsvz--no-headingsz	--timeout10z	--columnsr  findr
  ztype=internal)r   )NNNNr   r:   )T)TTN)TTTTTTF)`r#   	functoolsr  loggingrN   r   typingr   r   r   r   r   	cloudinitr   r	   cloudinit.net.netops.iproute2r
   	getLoggerr   r-   r   r  r   rw   rA  r   r   r!   r7   r?   rC   rJ   rQ   rT   rX   r^   ra   re   	lru_cachers   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r/  r7  rM  ry  r}  r  r   r  r  r  r  r  r   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r.  r  r   r   r   <module>r*     s       	 	 8 8   2!!"  % ! !jj4 

7"JH;<G$6 T" # T"  # (
0B01
A) A+
.,J	J	Od	:-G`$(+\[.|+08  DN:z'%T &	B	C	C	P("2C	= F	L 	r   