
    /I_)a                     6   S SK r  S SKJr  S SKJs  Jr  S SKJs  Jr  S SKJs  Jr  S SKJs  J	r	  S SK
7  S SKJr  S SKJr  S SK7  S SKJr   " S S\\5      rg! \\4 a7    S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK7  S SKJr  S SKJr  S SK7  S SKJr   NKf = f)	    N)Addon)*)utils)moduleNotSupported)
moduleBasec                   p   \ rS rSrSrSS/ SQS/SS.S	S
/SS/SS.SS// SQSS.SS// SQSS.SS/SS/SS.SS/SS/SS.SS/SS/SS.SS/SS/SS.SS/SS/SS.S S!/SS/SS.S"S#/SS/SS.S$.S%.rS& rS' rS( rS8S) jr	S8S* jr
S+ rS, rS9S. jrS9S/ jrS0 rS:S1 jrS9S2 jrS3 r\\
\\\S4.rS5 rS9S6 jrS7rg-);ethtool&   z7ifupdown2 addon module to configure ethtool attributes z+ethtool configuration module for interfaceszset link speed)
10100100010000250004000050000100000200000400000zlink-speed 1000zvaries by platform and port)help	validvalsexampledefaultzset link duplexzlink-duplex fullhalffull)r   r   r   r   zset autonegotiationzlink-autoneg on)yesnoonoffz!set forward error correction modezlink-fec rs)rsbaserautor   zGeneric Receive Offloadzgro-offload onr   r   zvaries by interfacezLarge Receive Offloadzlro-offload onzGeneric Segmentation Offloadztso-offload onzTCP Segmentation OffloadzUDP Fragmentation Offloadzufo-offload onzTX Checksum Offloadztx-offload onzRX Checksum Offloadzrx-offload on)
link-speedlink-duplexlink-autoneglink-fecgro-offloadlro-offloadgso-offloadtso-offloadufo-offload
tx-offload
rx-offload)mhelpattrsc                    [         R                  " U 5        [        R                  " U /UQ70 UD6  [        R                  R                  [        R                  5      (       d  [        S[        R                  -  5      e/ U l	        S U l
        [        R                  R                  U R                  R                  SS9U l        g )Nz!module init failed: %s: not foundethtool_ignore_errorsmodule_nameattr)r   __init__r   ospathexistsr   ethtool_cmdr   ifaceobjs_modified_configsfeature_cachepolicymanagerpolicymanager_apiget_module_globals	__class____name__r0   )selfargskargss      &/usr/share/ifupdown2/addons/ethtool.pyr4   ethtool.__init__|   s    tD14151ww~~e//00$%H5K\K\%\]]*,'!%2%D%D%W%W//( &X &
"    c                 $   SU-   nUR                  U5      nS n[        R                  R                  UR                  5      nU(       a  US   R                  U5      nU(       d  U(       a  [        U R                  X15      5      R                  5       nU(       d  U/UR                  U'   OU(       a  U/UR                  U'   U(       d  UnU(       aE  XX:w  a@   [        R                  < SUR                  < SU< SU< 3n	[        R                  " U	5        [        R                  R!                  U R"                  R$                  SS9U l        g ! [         a6  n
U R                  UR                  < S[        U
5      < 3U5         S n
A
NsS n
A
ff = f)Ndefault_r   z -K  : r0   r1   )get_attr_value_firststatemanagerstatemanager_apiget_ifaceobjsnamestrget_running_attrlowerconfigr   r8   exec_command	Exception	log_errorr;   r<   r=   r>   r?   r0   )r@   ifaceobj	attr_nameeth_namer   
config_valdefault_valsaved_ifaceobjsrunning_valcmdes              rC   do_offload_settingsethtool.do_offload_settings   sB   x'229=
&77EEhmmT)!,AA'JK d33HGHNNPK ,7=(,7=((
j7P"..xUC&&s+ &3%D%D%W%W//( &X &
" ! PNNhmmSV#DhOOPs   ?E 
F,F

Fc                    SnUR                  S5      n[        R                  R                  SUR                  SS9nU(       d  U(       d  g [        U R                  SU5      5      R                  5       nU(       a  UR                  5       nU(       a  UR                  5       nU(       a  X5:X  a  g U(       d  U(       a  XE:X  a  g U(       a  X5:w  a  SS< SU< 3nOU(       a  XE:w  a
  SS< SU< 3nU(       a=   [        R                  < SUR                  < SU< 3n[        R                  " U5        g g ! [         aL  nU R                  (       d1  U R                  UR                  < S	[        U5      < 3U5         S nAg  S nAg S nAff = f)
N r%   r	   r2   ifnamer3   fecrH   encodingz --set-fec rI   )rJ   r;   r<   get_iface_defaultrN   rO   rP   rQ   r   r8   rS   rT   r0   rU   )r@   rV   feccmdrY   rZ   r\   r^   s          rC   do_fec_settingsethtool.do_fec_settings   sG    22:>
#55GG(1#+==!+ H -
 :  $//x@AGGI#))+J%++-K *3kk.H :4!+Z8Fk8!+[9FP!--x}}fF""6*
 	  P11NNhmmSV#DhOO 2Ps   9;D6 6
F =FFc                    SnS nS nS nUR                  S5      nUR                  S5      nUR                  S5      n	[        R                  R                  SUR                  SS9n
[        R                  R                  SUR                  SS9n[        R                  R                  SUR                  SS9nU	(       a"  [
        R                  " U	5      (       a  U	nS nS nO~U(       a  S nUnUnU(       d  UnOgU	(       a  [
        R                  " U	5      (       d  SnU(       a6  [
        R                  " U5      (       a  [
        R                  " U5      nS nS nOS nU
nUnU(       a6  [
        R                  " U5      nU R                  SU5      nXM:w  a  US	U-  -  nOS
nU(       a^  [
        R                  " U R                  SU5      =(       d    S5      (       a  SnSnU R                  SU5      nU(       d  X]:w  a  USU-  -  nU(       a&  U R                  SU5      nU(       d  Xm:w  a  USU-  -  nU(       a=   [
        R                  < SUR                  < SU< 3n[
        R                  " U5        g g ! [         aL  nU R                  (       d1  U R                  UR                  < S[        U5      < 3U5         S nAg  S nAg S nAff = f)Nrb   r"   r#   r$   r	   rc   r   autonegz autoneg %sFzautoneg offTspeedz	 speed %sduplexz
 duplex %sz -s rH   rI   )rJ   r;   r<   rg   rN   r   get_boolean_from_stringget_onoff_boolrP   r8   rS   rT   r0   rU   rO   )r@   rV   	operationr]   autoneg_to_configurespeed_to_configureduplex_to_configureconfig_speedconfig_duplexconfig_autonegdefault_speeddefault_duplexdefault_autonegr\   	force_setr^   s                   rC   do_speed_settingsethtool.do_speed_settings   s   #!"44\B 55mD!66~F%77II%}}! J  '88JJ%}}" K  (99KK%}}# L 
 e;;NKK#1 !%"&#' !-"/ &4# e&C&CN&S&S"'5#@#@#Q#Q',';';O'L$%)"&*#'+$%2"&4##(#7#78L#M //	8DK#2}';;;I!001F1FyRZ1[1d_dee'C !%I"33GXF!3!B;);;;C""33HhG!4!C<*===CQ(-(9(98==#N""3'   Q11NNx}}c!f#ExPP 2Qs   7;I4 4
K
>=KK
c                    U R                   R                  UR                  5      (       d  gU R                  U5        U R	                  U5        U R                  USS5        U R                  USS5        U R                  USS5        U R                  USS	5        U R                  US
S5        U R                  USS5        U R                  USS5        g)zU
_pre_up and _pre_down will reset the layer 2 attributes to default policy
settings.
Nr&   gror'   lror(   gsor)   tsor*   ufor+   txr,   rx)cachelink_existsrN   r|   ri   r_   )r@   rV   rq   s      rC   _pre_upethtool._pre_up>  s    
 zz%%hmm44x(X&  =%@  =%@  =%@  =%@  =%@  <>  <>rE   c                     g N )r@   rV   s     rC   	_pre_downethtool._pre_downP  s    rE   c                    S GH{  nUR                  SU-  5      nU(       d!  [        R                  R                  (       d  M@  [        R
                  R                  SUR                  SU-  S9nU(       d  Mu  U R                  X15      nU(       d!  U(       d  M  UR                  SU-  SS5        M  US:X  a  US:X  a	  US	:X  a  SnOUS
:X  a  US:X  a  S
nU(       a$  U(       a  Xd:X  a  UR                  SU-  US5        M  U(       a%  U(       a  Xd:w  a  UR                  SU-  US5        GM(  U(       a%  U(       a  Xe:X  a  UR                  SU-  US5        GMT  U(       d
  U(       d  GMe  UR                  SU-  US5        GM~     g)a7  
_query_check() needs to compare the configured (or running)
attribute with the running attribute.

If there is nothing configured, we compare the default attribute with
the running attribute and FAIL if they are different.
This is because a reboot will lose their running attribute
(the default will get set).
rm   rn   rl   re   link-%sr	   rc   unknown   rl   r   r   r   r   r   N)
rJ   ifupdownflagsflagsWITHDEFAULTSr;   r<   rg   rN   rP   update_config_with_status)r@   rV   ifaceobjcurrr3   
configuredr   running_attrs          rC   _query_checkethtool._query_checkS  si    :D!66y~FJ$**77#55GG%}}t^ H %G 00@L!66y47G7@!Ey &<4+?#(L4'LE,A#'L 0J66y~7CQH:,2L66y~7CQH7|/F66y~7CQHZZ66y~7CQHY :\ 	rE   Nc                 \    UR                  5       nSU;   a  X"R                  S5      S-      $ g)zP
get_autoneg simply calls the ethtool command and parses out
the autoneg value.
zAuto-negotiation:r   N)splitindex)r@   ethtool_outputethtool_attrss      rC   get_autonegethtool.get_autoneg  s7    
 ',,.=0 !4!45H!I!!KLMrE   c           	      R    UR                  5        HA  nUR                  S5      (       d  M  UR                  5       nX3R                  S5      S-      s  $    g! [         aD  nU R
                  R                  SUR                  5       < S[        U5      < 35         SnAgSnAff = f)zc
get_fec_encoding simply calls the ethtool show-fec command and parses out
the fec encoding value.
zConfigured FEC encodings:z
encodings:r   z,ethtool: problems in ethtool set-fec output rI   N)
splitlines
startswithr   r   rT   loggerdebugrO   )r@   r   r3   	fec_attrsr^   s        rC   get_fec_encodingethtool.get_fec_encoding  s    
	Q&113??#>?? $

I$__\%B1%DEF 4 	  	QKK+9+D+D+FAP Q Q 		Qs"   'A 'A A 
B&":B!!B&c                 j    S nUR                  5        H  nX$;   d  M
  SU;   a  SnOSU;   a  Sn  U$    U$ )Nr   r   )r   )r@   r   settingvaluelines        rC   get_offload_settingethtool.get_offload_setting  sF    "--/D4< Ed]!E 0 rE   c                 h   U(       a  U(       d  g S n US:X  aA  [         R                  " [         R                  UR                  /5      nU R	                  US9nU$ US:X  aF  [         R
                  " [         R                  < SUR                  < 35      nU R                  US9nU$ US:X  ag  U R                  (       d:  [         R
                  " [         R                  < SUR                  < 35      U l        U R                  U R                  SS9nU$ US	:X  ag  U R                  (       d:  [         R
                  " [         R                  < SUR                  < 35      U l        U R                  U R                  S
S9nU$ US:X  ag  U R                  (       d:  [         R
                  " [         R                  < SUR                  < 35      U l        U R                  U R                  SS9nU$ US:X  ag  U R                  (       d:  [         R
                  " [         R                  < SUR                  < 35      U l        U R                  U R                  SS9nU$ US:X  ag  U R                  (       d:  [         R
                  " [         R                  < SUR                  < 35      U l        U R                  U R                  SS9nU$ US:X  ag  U R                  (       d:  [         R
                  " [         R                  < SUR                  < 35      U l        U R                  U R                  SS9nU$ US:X  ag  U R                  (       d:  [         R
                  " [         R                  < SUR                  < 35      U l        U R                  U R                  SS9nU$ U R                  R                  SUR                  < SU< 35      n U$ ! [         aV  nU R                  (       d:  U R                  R                  SUR                  < SU< S[        U5      < 35         S nAU$ S nAff = f)Nrl   )r   re   z --show-fec r   z --show-features zgeneric-receive-offload)r   r   r   zlarge-receive-offloadr   zgeneric-segmentation-offloadr   ztcp-segmentation-offloadr   zudp-fragmentation-offloadr   zrx-checksummingr   ztx-checksummingz/sys/class/net//zAethtool: problems calling ethtool or reading /sys/class on iface z
 for attr rI   )r   exec_commandlr8   rN   r   rS   r   r:   r   ioread_file_onelinerT   r0   r   r   rO   )r@   r3   rV   r   outputr^   s         rC   rP   ethtool.get_running_attr  s   t3	Ay ,,e.?.?-OP#//v/Fb a ++-2->->-O P#44F4KZ Y ))).););-2->->=O *PD&#77tGYGYc|7}P O ))).););-2->->=O *PD&#77tGYGYcz7{F E ))).););-2->->=O *PD&#77tGYGY  dB7   C< ; ))).););-2->->=O *PD&#77tGYGYc}7~2 1 ))).););-2->->=O *PD&#77tGYGYc~7( ' ))).););-2->->=O *PD&#77tGYGYct7u  ))).););-2->->=O *PD&#77tGYGYct7u   $ww887?}}d:L  M   	A--!!#+==$A#@ A 	AsW   AO A
O &A+O A+O  A+O -A+O A+O A+O 4A+O !-O 
P1AP,,P1c                 l   U R                   R                  UR                  5      (       d  gS H  n[        R                  R                  SUR                  SU-  S9nU(       d  M8  U R                  X15      nXE:X  a  MP  US:X  a  U(       a  US:X  a    gU(       d  Mn  UR                  SU-  U5        M     g)z
_query_running looks at the speed and duplex from /sys/class
and retreives autoneg from ethtool.  We do not report autoneg
if speed is not available because this usually means the link is
down and the autoneg value is not reliable when the link is down.
N)rm   rn   rl   r	   r   rc   rm   0)r   
link_is_uprN   r;   r<   rg   rP   update_config)r@   rV   ifaceobj_getfuncr3   rZ   r   s         rC   _query_runningethtool._query_running  s     zz$$X]]332D'99KK%}}t^ L %K 00@L * w<LC4G|&&y~|D) 3, 	rE   c                     S Hh  nUR                  SU-  5      (       a  M  [        R                  R                  SUR                  SU-  S9nU(       d  MS  UR                  SU-  U5        Mj     g)z6add default policy attributes supported by the module r   r   r	   rc   N)rJ   r;   r<   rg   rN   r   )r@   rV   kwargsr3   r   s        rC   _queryethtool._query  sm    9D,,Yt^<<#55GG$-'}}&_ H .G ""9d?G< :rE   )zpre-downzpre-upquery-checkcurrzquery-runningqueryc                 H    [        U R                  R                  5       5      $ )z-returns list of ops supported by this module )list_run_opskeys)r@   s    rC   get_opsethtool.get_ops(  s    DMM&&())rE   c                     UR                   (       d"  UR                  [        R                  -  (       a  gU R                  R                  U5      nU(       d  gUS:X  a
  U" XU5        gU" X5        g)as  run ethtool configuration on the interface object passed as
    argument

Args:
    **ifaceobj** (object): iface object

    **operation** (str): any of 'post-up', 'query-checkcurr',
        'query-running'
Kwargs:
    **query_ifaceobj** (object): query check ifaceobject. This is only
        valid when op is 'query-checkcurr'. It is an object same as
        ifaceobj, but contains running attribute values and its config
        status. The modules can use it to return queried running state
        of interfaces. status is success if the running state is same
        as user required state in ifaceobj. error otherwise.
Nr   )	link_kindlink_privflagsifaceLinkPrivFlagsLOOPBACKr   get)r@   rV   rq   query_ifaceobj
extra_args
op_handlers         rC   runethtool.run,  sZ    " ++.@.I.II]]&&y1
))t~6t&rE   )r0   r:   r9   )post_upr   )rb   N)r?   
__module____qualname____firstlineno____doc___modinfor4   r_   ri   r|   r   r   r   r   r   r   rP   r   r   r   r   r   __static_attributes__r   rE   rC   r	   r	   &   s   C ? ) ..8$ *./$f-!	 .-.78	 <)?;8	 2,-"E]0	 0,-"E]0	 7,-"E]0	 3,-"E]0	 4,-"E]0	 .+,"E]0	 .+,"E]0	QN
QHf
"
H0d[Qz?$8t	 8v!F= '"$0"0 	"H*'rE   r	   )r5   ifupdown2.lib.addonr    ifupdown2.ifupdown.ifupdownflagsifupdownr    ifupdown2.ifupdown.policymanagerr;   ifupdown2.ifupdown.statemanagerrK   ifupdown2.ifupdown.ifaceifupdown2.ifupdown.utilsr   ifupdown2.ifupdown.exceptionsr   "ifupdown2.ifupdownaddons.utilsbase#ifupdown2.ifupdownaddons.modulebaser   ImportErrorModuleNotFoundError	lib.addonifupdown.ifupdownflagsifupdown.policymanagerifupdown.statemanagerifupdown.ifaceifupdown.utilsifupdown.exceptionsifupdownaddons.utilsbaseifupdownaddons.modulebaser	   r   rE   rC   <module>r      s{    
5)<<<<<<::*.@4> `'eZ `' 	() 5220 $6*45s   AA <BB