HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3.9/site-packages/tuned/plugins/__pycache__/plugin_net.cpython-39.pyc
a

Y��d{Z�@spddlZddlmZddlTddlZddlmZddlm	Z	ddl
Z
ddlZej�
�ZdZGdd	�d	ej�ZdS)
�N�)�hotplug)�*)�ethcard)�commandsZpumbagsdcs.eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
edd��Zedd��Z
edd��Zedd��Zedd��Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zed(d)��Zed*d+d,�d-d.��Zed*�did0d1��Zed2�d3d4��Zed2�d5d6��Zgfd7d8�Zdjd:d;�Z ed<d+d,�d=d>��Z!d?d@�Z"ed<�dkdAdB��Z#edCd+d,�dDdE��Z$edC�dldFdG��Z%dHdI�Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dmdVdW�Z-dXdY�Z.e/dZd+d,�d[d\��Z0e/d]d+d,�d^d_��Z1e/d`d+d,�dadb��Z2e/dcd+d,�ddde��Z3e/dfd+d,�dgdh��Z4�Z5S)n�NetTuningPlugina�
	`net`::
	
	Configures network driver, hardware and Netfilter settings.
	Dynamic change of the interface speed according to the interface
	utilization is also supported. The dynamic tuning is controlled by
	the [option]`dynamic` and the global [option]`dynamic_tuning`
	option in `tuned-main.conf`.
	+
	The [option]`wake_on_lan` option sets wake-on-lan to the specified
	value as when using the `ethtool` utility.
	+
	.Set Wake-on-LAN for device eth0 on MagicPacket(TM)
	====
	----
	[net]
	devices=eth0
	wake_on_lan=g
	----
	====
	+
	The [option]`coalesce` option allows changing coalescing settings
	for the specified network devices. The syntax is:
	+
	[subs="+quotes,+macros"]
	----
	coalesce=__param1__ __value1__ __param2__ __value2__ ... __paramN__ __valueN__
	----
	Note that not all the coalescing parameters are supported by all
	network cards. For the list of coalescing parameters of your network
	device, use `ethtool -c device`.
	+	
	.Setting coalescing parameters rx/tx-usecs for all network devices
	====
	----
	[net]
	coalesce=rx-usecs 3 tx-usecs 16
	----
	====
	+
	The [option]`features` option allows changing 
	the offload parameters and other features for the specified
	network devices. To query the features of your network device,
	use `ethtool -k device`. The syntax of the option is the same as
	the [option]`coalesce` option.
	+
	.Turn off TX checksumming, generic segmentation and receive offload 
	====
	----
	[net]
	features=tx off gso off gro off
	----
	====
	The [option]`pause` option allows changing the pause parameters for
	the specified network devices. To query the pause parameters of your
	network device, use `ethtool -a device`. The syntax of the option
	is the same as the [option]`coalesce` option.
	+
	.Disable autonegotiation
	====
	----
	[net]
	pause=autoneg off
	----
	====
	+
	The [option]`ring` option allows changing the rx/tx ring parameters
	for the specified network devices. To query the ring parameters of your
	network device, use `ethtool -g device`. The syntax of the option
	is the same as the [option]`coalesce` option.
	+	
	.Change the number of ring entries for the Rx/Tx rings to 1024/512 respectively
	=====
	-----
	[net]
	ring=rx 1024 tx 512
	-----
	=====
	+
	The [option]`channels` option allows changing the numbers of channels
	for the specified network device. A channel is an IRQ and the set
	of queues that can trigger that IRQ. To query the channels parameters of your
	network device, use `ethtool -l device`. The syntax of the option
	is the same as the [option]`coalesce` option.
	+
	.Set the number of multi-purpose channels to 16
	=====
	-----
	[net]
	channels=combined 16
	-----
	=====
	+   
	A network device either supports rx/tx or combined queue
	mode. The [option]`channels` option automatically adjusts the
	parameters based on the mode supported by the device as long as a
	valid configuration is requested.
	+
	The [option]`nf_conntrack_hashsize` option sets the size of the hash
	table which stores lists of conntrack entries by writing to
	`/sys/module/nf_conntrack/parameters/hashsize`.
	+
	.Adjust the size of the conntrack hash table
	====
	----
	[net]
	nf_conntrack_hashsize=131072
	----
	====
	+
	The [option]`txqueuelen` option allows changing txqueuelen (the length
	of the transmit queue). It uses `ip` utility that is in package	iproute
	recommended for TuneD, so the package needs to be installed for its correct
	functionality. To query the txqueuelen parameters of your network device
	use `ip link show` and the current value is shown after the qlen column.
	+
	.Adjust the length of the transmit queue
	====
	----
	[net]
	txqueuelen=5000
	----
	====
	+
	The [option]`mtu` option allows changing MTU (Maximum Transmission Unit).
	It uses `ip` utility that is in package	iproute recommended for TuneD, so
	the package needs to be installed for its correct functionality. To query
	the MTU parameters of your network device use `ip link show` and the
	current value is shown after the MTU column.
	+
	.Adjust the size of the MTU
	====
	----
	[net]
	mtu=9000
	----
	====
	cs:tt|�j|i|��d|_d|_t�|_i|_d|_dS)Ng�������?�T)	�superr�__init__�_load_smallest�_level_stepsr�_cmd�_re_ip_link_show�_use_ip)�self�args�kwargs��	__class__��</usr/lib/python3.9/site-packages/tuned/plugins/plugin_net.pyr
�szNetTuningPlugin.__init__cCsdd|_t�|_t�|_t�d�}|j�d�D]}|�|j	�r,|j�
|j�q,t�
dt|j��dS)NTz(?!.*/virtual/.*)�netzdevices: %s)Z_devices_supported�setZ
_free_devicesZ_assigned_devices�re�compile�_hardware_inventoryZget_devices�matchZdevice_path�addZsys_name�log�debug�str)rZre_not_virtual�devicerrr�
_init_devices�s
zNetTuningPlugin._init_devicescs�fdd�|D�S)Ncsg|]}�j�d|��qS)r)rZ
get_device��.0�x�rrr�
<listcomp>��z7NetTuningPlugin._get_device_objects.<locals>.<listcomp>r)rZdevicesrr&r�_get_device_objects�sz#NetTuningPlugin._get_device_objectscCsXd|_|�|jd�r<d|_|j�d|j�|_i|_i|_	nd|_d|_d|_d|_	dS)NT�dynamicrF)
Z_has_static_tuningZ_option_bool�optionsZ_has_dynamic_tuning�_monitors_repositoryZcreateZassigned_devices�
_load_monitor�_idle�_stats�r�instancerrr�_instance_init�szNetTuningPlugin._instance_initcCs"|jdur|j�|j�d|_dS�N)r-r,�deleter0rrr�_instance_cleanup�s
z!NetTuningPlugin._instance_cleanupcCs|�||�dSr3)�_instance_update_dynamic�rr1r!rrr�_instance_apply_dynamic�sz'NetTuningPlugin._instance_apply_dynamiccCs<dd�|j�|�D�}|dur"dS||jvr8|�||�|�|||�|�||�|j|}|j|}|ddkr�|d|jkr�|d|jkr�d|d<t�	d|�t
|��d	�nF|ddkr�|ddks�|ddkr�d|d<t�	d
|�t
|���t�
d||d|df�t�
d||d|d|df�dS)
NcSsg|]}t|��qSr��int)r$�valuerrrr'�r(z<NetTuningPlugin._instance_update_dynamic.<locals>.<listcomp>�levelr�read�writerz%s: setting 100Mbps�d�%s: setting max speedz %s load: read %0.2f, write %0.2fz$%s idle: read %d, write %d, level %d)r-Zget_device_loadr/�_init_stats_and_idle�
_update_stats�_update_idler.rr�inforZ	set_speed�
set_max_speedr)rr1r!�loadZstatsZidlerrrr6�s&


($z(NetTuningPlugin._instance_update_dynamiccCs2ddddddddddddddddddddddd�S)N)zadaptive-rxzadaptive-txzrx-usecsz	rx-frameszrx-usecs-irqz
rx-frames-irqztx-usecsz	tx-framesztx-usecs-irqz
tx-frames-irqzstats-block-usecszpkt-rate-lowzrx-usecs-lowz
rx-frames-lowztx-usecs-lowz
tx-frames-lowz
pkt-rate-highz
rx-usecs-highzrx-frames-highz
tx-usecs-highztx-frames-highzsample-intervalr��clsrrr�_get_config_options_coalesce�s.�z,NetTuningPlugin._get_config_options_coalescecCsdddd�S)N)�autoneg�rx�txrrGrrr�_get_config_options_pause�s�z)NetTuningPlugin._get_config_options_pausecCsddddd�S)N)rK�rx-mini�rx-jumborLrrGrrr�_get_config_options_rings
�z(NetTuningPlugin._get_config_options_ringcCsddddd�S)N)rKrL�other�combinedrrGrrr�_get_config_options_channelss
�z,NetTuningPlugin._get_config_options_channelscCsddddddddddd�
S)NT)
r*�wake_on_lan�nf_conntrack_hashsize�features�coalesce�pause�ring�channels�
txqueuelen�mturrGrrr�_get_config_optionss�z#NetTuningPlugin._get_config_optionscCsF|�t|����}ddgd|dgd�|j|<dddd�|j|<dS)N�r�r)�new�max)r<r=r>)�_calc_speedrZ
get_max_speedr/r.)rr1r!Z	max_speedrrrrAsz$NetTuningPlugin._init_stats_and_idlecCs�|j|d|j|d<}||j|d<dd�t||�D�}||j|d<|j|d}dd�t||�D�}||j|d<t|d�t|d�|j|d	<t|d
�t|d
�|j|d<dS)Nr`�oldcSsg|]}|d|d�qS)rrr)r$Znew_oldrrrr'(r(z1NetTuningPlugin._update_stats.<locals>.<listcomp>�diffracSsg|]}t|��qSr)ra)r$Zpairrrrr'-r(rr=r_r>)r/�zip�float)rr1r!Znew_loadZold_loadrdZold_max_loadZmax_loadrrrrB"s"zNetTuningPlugin._update_statscCsHdD]>}|j|||jkr4|j||d7<qd|j||<qdS)N)r=r>rr)r/rr.)rr1r!Z	operationrrrrC4szNetTuningPlugin._update_idlecCsH||jvrD|j|ddkrDd|j|d<t�d|�t|���dS)Nr<rr@)r.rrDrrEr7rrr�_instance_unapply_dynamic<sz)NetTuningPlugin._instance_unapply_dynamiccCstd|d�S)Ng333333#A�r9)rZspeedrrrrbBszNetTuningPlugin._calc_speedcCs�|j�|�}tt�dd|����}t|�}|ddkrPt�d|t|�f�dS|dkr^t	�St	t
t|ddd�|ddd����S)Nz (:\s*)|(\s+)|(\s*;\s*)|(\s*,\s*)� r_rzinvalid %s parameter: '%s'r)Z
_variables�expandr r�sub�split�lenr�error�dict�listre)rr;�context�v�lvrrr�_parse_config_parametersKsz(NetTuningPlugin._parse_config_parameterscCs||j�ddddddddd	d
ddd
dddddd�|�}dd�|�d�D�}t|�dkrXdStdd�dd�|dd�D�D��S)Nzadaptive-rx:z
adaptive-tx:zrx-frames-low:zrx-frames-high:ztx-frames-low:ztx-frames-high:zlro:zrx:ztx:zsg:ztso:zufo:zgso:zgro:zrxvlan:ztxvlan:zntuple:zrxhash:)zAdaptive RX:z\s+TX:z
rx-frame-low:zrx-frame-high:z
tx-frame-low:ztx-frame-high:zlarge-receive-offload:zrx-checksumming:ztx-checksumming:zscatter-gather:ztcp-segmentation-offload:zudp-fragmentation-offload:zgeneric-segmentation-offload:zgeneric-receive-offload:zrx-vlan-offload:ztx-vlan-offload:zntuple-filters:zreceive-hashing:cSs0g|](}tt|��dkrt�dt|��s|�qS)rz
\[fixed\]$)rmr r�search�r$rrrrrr'sr(z<NetTuningPlugin._parse_device_parameters.<locals>.<listcomp>�
r_cSsg|]}t|�dkr|�qS�r_�rm)r$�urrrr'xr(cSsg|]}t�dt|���qS�z:\s*)rrlr rvrrrr'xr(r)r
�multiple_re_replacerlrmro)rr;Zvlrrr�_parse_device_parametersZs4��z(NetTuningPlugin._parse_device_parameterscCsdS)Nz,/sys/module/nf_conntrack/parameters/hashsizerr&rrr�_nf_conntrack_hashsize_pathzsz+NetTuningPlugin._nf_conntrack_hashsize_pathrTT)Z
per_devicecCs^|durdSt�ddt|��}t�dtd|�s@t�d�dS|sZ|j�dd|d|g�|S)	N�0�dz^[z]+$zIncorrect 'wake_on_lan' value.�ethtoolz-sZwol)	rrkr r�
WOL_VALUESr�warnr
�execute)rr;r!�simrrr�_set_wake_on_lan~s
z NetTuningPlugin._set_wake_on_lanFcCsVd}z:t�dtd|j�d|g�dtj�}|r<|�d�}WntyPYn0|S)Nz.*Wake-on:\s*([z]+).*r�r)rrr�r
r��S�group�IOError)rr!�ignore_missingr;�mrrr�_get_wake_on_lan�s(z NetTuningPlugin._get_wake_on_lanrUcCs>|durdSt|�}|dkr6|s2|j�|��|�|SdSdS�Nr)r:r
Z
write_to_filer~)rr;r�Zhashsizerrr�_set_nf_conntrack_hashsize�sz*NetTuningPlugin._set_nf_conntrack_hashsizecCs(|j�|���}t|�dkr$t|�SdSr�)r
Z	read_filer~rmr:)rr;rrr�_get_nf_conntrack_hashsize�sz*NetTuningPlugin._get_nf_conntrack_hashsizecCsz|js
dSddg|}|jj|tjgdd�\}}}|tjkrRt�d�d|_dS|rvt�d�t�d||f�dS|S)	NZip�linkT)�	no_errorsZ
return_errz0ip command not found, ignoring for other devicesFzProblem calling ip commandz(rc: %s, msg: '%s'))	rr
r��errno�ENOENTrr�rDr)rr�rc�out�err_msgrrr�
_call_ip_link�s

zNetTuningPlugin._call_ip_linkNcCsdg}|r|�|�|�|�S)NZshow)�appendr�)rr!rrrr�
_ip_link_show�s
zNetTuningPlugin._ip_link_showr[cCsr|durdSzt|�Wn"ty:t�d|�YdS0|sn|�dd|d|g�}|durnt�d|�dS|S)Nz$txqueuelen value '%s' is not integerr�devr[z%Cannot set txqueuelen for device '%s'�r:�
ValueErrorrr�r��rr;r!r��resrrr�_set_txqueuelen�szNetTuningPlugin._set_txqueuelencCs(||jvrt�d|�|j|<|j|S)z@
		Return regex for int arg value from "ip link show" command
		z.*\s+%s\s+(\d+))rrr)r�argrrr�_get_re_ip_link_show�s
z$NetTuningPlugin._get_re_ip_link_showcCs`|�|�}|dur(|s$t�d|�dS|�d��|�}|durV|sRt�d|�dS|�d�S)NzECannot get 'ip link show' result for txqueuelen value for device '%s'ZqlenzFCannot get txqueuelen value from 'ip link show' result for device '%s'r�r�rrDr�rur��rr!r�r�r�rrr�_get_txqueuelen�s
zNetTuningPlugin._get_txqueuelenr\cCsr|durdSzt|�Wn"ty:t�d|�YdS0|sn|�dd|d|g�}|durnt�d|�dS|S)Nzmtu value '%s' is not integerrr�r\zCannot set mtu for device '%s'r�r�rrr�_set_mtu�szNetTuningPlugin._set_mtucCs`|�|�}|dur(|s$t�d|�dS|�d��|�}|durV|sRt�d|�dS|�d�S)Nz>Cannot get 'ip link show' result for mtu value for device '%s'r\z?Cannot get mtu value from 'ip link show' result for device '%s'rr�r�rrr�_get_mtu�s
zNetTuningPlugin._get_mtucCsl|dkrdSt|���}|j|j|j|jd�}t||����}|�|�sht�d|t	||�f�dSdS)NrVT)rWrXrYrZzunknown %s parameter(s): %sF)
r�keysrIrMrPrS�issubsetrrnr )rrqr��paramsZsupported_getterZ	supportedrrr�_check_parameters	s�
z!NetTuningPlugin._check_parameterscCsR|j�dddd�|�}|�d�dd�}dd�|D�}td	d�d
d�|D�D��S)NrJrKrL)Z
Autonegotiate�RX�TXrwrcSs$g|]}|dkrt�d|�s|�qS)�z	\[fixed\])rrur#rrrr'r(z;NetTuningPlugin._parse_pause_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qSrxryr#rrrr'r(cSsg|]}t�d|��qSr{�rrlr#rrrr'r()r
r|rlro)r�s�lrrr�_parse_pause_parameterss��z'NetTuningPlugin._parse_pause_parameterscCsjtjd|tjd�}|d}|j�ddddd�|�}|�d	�}d
d�|D�}dd�d
d�|D�D�}t|�S)N�^Current hardware settings:$��flagsrrKrNrOrL)r�zRX MinizRX Jumbor�rwcSsg|]}|dkr|�qS�r�rr#rrrr'+r(z:NetTuningPlugin._parse_ring_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qSrxryr#rrrr',r(cSsg|]}t�d|��qSr{r�r#rrrr',r(�rrl�	MULTILINEr
r|ro�rr��ar�rrr�_parse_ring_parameters"s��
z&NetTuningPlugin._parse_ring_parameterscCsjtjd|tjd�}|d}|j�ddddd�|�}|�d	�}d
d�|D�}dd�d
d�|D�D�}t|�S)Nr�r�rrKrLrQrR)r�r�ZOtherZCombinedrwcSsg|]}|dkr|�qSr�rr#rrrr'9r(z>NetTuningPlugin._parse_channels_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qSrxryr#rrrr':r(cSsg|]}t�d|��qSr{r�r#rrrr':r(r�r�rrr�_parse_channels_parameters0s��
z*NetTuningPlugin._parse_channels_parameterscCszg}d|vr(|�d|dd|dg�n,ttt|d�t|d���}|�d|g�ttt|ddd�|ddd����S)NrRrKrrL�r_)�extendr rar:rorpre)rrqZparams_list�
dev_paramsZmod_params_listZcntrrr�_replace_channels_parameters=sz,NetTuningPlugin._replace_channels_parametersc	CsNt|���}t|���}||}|D]$}t�d|||f�|�|d�q$dS)aFilter unsupported parameters and log warnings about it

		Positional parameters:
		context -- context of change
		parameters -- parameters to change
		device -- name of device on which should be parameters set
		dev_params -- dictionary of currently known parameters of device
		z-%s parameter %s is not supported by device %sN)rr�rZwarning�pop)	rrq�
parametersr!r�Zsupported_parametersZparameters_to_changeZunsupported_parameters�paramrrr�_check_device_supportFs	��z%NetTuningPlugin._check_device_supportc
Cs�dddddd�}||}|j�d||g�\}}|dksBt|�dkrFdS|j|j|j|j|jd�}||}||�}	|d	kr�|�||	�s�dS|	S)
Nz-cz-kz-az-gz-l�rWrVrXrYrZr�rrW)r
r�rmr}r�r�r�r�)
rrqr!�context2opt�opt�retr;Zcontext2parser�parserr�rrr�_get_device_parameters]s$��z&NetTuningPlugin._get_device_parametersc	Cs�|dust|�dkrdS|�||�}|dus8|�||�s<iS|r�|�||||�|dkr�t|tt|���dvr�|�||j�	|�|�}|s�t|�dkr�t
�d|t|�f�ddddd	d
�}||}|jjd||g|j�	|�dgd
�|S)NrrZ)zn/arzsetting %s: %sz-Cz-Kz-Az-Gz-Lr�r��P)r�)
rmrtr�r�r �next�iterr�r
�	dict2listrrr�)	rrqr;r!r�r�r�r�r�rrr�_set_device_parametersos" �$z&NetTuningPlugin._set_device_parameterscs�|j||d�}|r�|�||�}|dus2t|�dkr6dS|j|||||d���dus^t��dkrbdS�fdd�|��D�}t|�}|r�|j���|j�|�k}	|j||	�||d�|	S|j	�
|d�|j�|���n|j	�|�}
|�||
|d�dS)	N)Zcommand_nameZdevice_namerF)r�cs g|]\}}|�vr||f�qSrr)r$r�r;�Z
params_setrrr'�s�z6NetTuningPlugin._custom_parameters.<locals>.<listcomp>)r!ri)
Z_storage_keyr�rmr��itemsror
r�Z_log_verification_resultZ_storager�join�get)rrq�startr;r!�verifyZstorage_keyZparams_currentZrelevant_params_currentr��original_valuerr�r�_custom_parameters�sH���
�

��
�z"NetTuningPlugin._custom_parametersrVcCs|�d||||�S)NrV�r��rr�r;r!r�r�rrr�	_features�szNetTuningPlugin._featuresrWcCs|�d||||�S)NrWr�r�rrr�	_coalesce�szNetTuningPlugin._coalescerXcCs|�d||||�S)NrXr�r�rrr�_pause�szNetTuningPlugin._pauserYcCs|�d||||�S)NrYr�r�rrr�_ring�szNetTuningPlugin._ringrZcCs|�d||||�S)NrZr�r�rrr�	_channels�szNetTuningPlugin._channels)F)N)F)F)N)6�__name__�
__module__�__qualname__�__doc__r
r"r)r2r5r8r6�classmethodrIrMrPrSr]rArBrCrgrbrtr}r~Zcommand_setr�Zcommand_getr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�Zcommand_customr�r�r�r�r��
__classcell__rrrrrs�





	 












	�
&








r)r�r�rZ
decoratorsZ
tuned.logsZtunedZtuned.utils.nettoolrZtuned.utils.commandsr�osrZlogsr�rr�ZPluginrrrrr�<module>s