HEX
Server: LiteSpeed
System: Linux us-phx-web629.main-hosting.eu 5.14.0-503.23.2.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 12 05:52:18 EST 2025 x86_64
User: u756937133 (756937133)
PHP: 8.2.30
Disabled: passthru,chgrp
Upload Files
File: //lib/python3.9/site-packages/tuned/plugins/__pycache__/plugin_net.cpython-39.pyc
a

�Գf[�@spddlZddlmZddlTddlZddlmZddlm	Z	ddl
Z
ddlZej�
�ZdZGdd	�d	ej�ZdS)
�N�)�hotplug)�*)�ethcard)�commandsZpumbagsdcs:eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z�fdd
�Z	dd�Z
dd�Zedd��Z
edd��Zedd��Zedd��Zedd��Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zed*d+��Zed,d-d.�d/d0��Zed,�dkd2d3��Zed4�d5d6��Zed4�d7d8��Zgfd9d:�Z dld<d=�Z!ed>d-d.�d?d@��Z"dAdB�Z#ed>�dmdCdD��Z$edEd-d.�dFdG��Z%edE�dndHdI��Z&dJdK�Z'dLdM�Z(dNdO�Z)dPdQ�Z*dRdS�Z+dTdU�Z,dVdW�Z-dodXdY�Z.dZd[�Z/e0d\d-d.�d]d^��Z1e0d_d-d.�d`da��Z2e0dbd-d.�dcdd��Z3e0ded-d.�dfdg��Z4e0dhd-d.�didj��Z5�Z6S)p�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_objectscCs.d|_d|_d|_d|_|�|jd�|_dS)NT�dynamic)Z_has_static_tuning�
_load_monitor�_idle�_statsZ_option_bool�optionsZ_has_dynamic_tuning�r�instancerrr�_instance_init�s
zNetTuningPlugin._instance_initcCs"|jdur|j�|j�d|_dS�N)r+�_monitors_repository�deleter/rrr�_instance_cleanup�s
z!NetTuningPlugin._instance_cleanupcs2tt|��|�i|_i|_|j�d|j�|_dS)Nr)	r	r�_instance_init_dynamicr,r-r3ZcreateZassigned_devicesr+r/rrrr6�sz&NetTuningPlugin._instance_init_dynamiccCs|�||�dSr2)�_instance_update_dynamic�rr0r!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)rr0r!�loadZstatsZidlerrrr7�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�txrrHrrr�_get_config_options_pause�s�z)NetTuningPlugin._get_config_options_pausecCsddddd�S)N)rL�rx-mini�rx-jumborMrrHrrr�_get_config_options_rings
�z(NetTuningPlugin._get_config_options_ringcCsddddd�S)N)rLrM�other�combinedrrHrrr�_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�mturrHrrr�_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,)rr0r!Z	max_speedrrrrBsz$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)Nra�oldcSsg|]}|d|d�qS)rrr)r$Znew_oldrrrr'(r(z1NetTuningPlugin._update_stats.<locals>.<listcomp>�diffrbcSsg|]}t|��qSr)rb)r$Zpairrrrr'-r(rr>r`r?)r-�zip�float)rr0r!Znew_loadZold_loadreZold_max_loadZmax_loadrrrrC"s"zNetTuningPlugin._update_statscCsHdD]>}|j|||jkr4|j||d7<qd|j||<qdS)N)r>r?rr)r-rr,)rr0r!Z	operationrrrrD4szNetTuningPlugin._update_idlecCsH||jvrD|j|ddkrDd|j|d<t�d|�t|���dS)Nr=rrA)r,rrErrFr8rrr�_instance_unapply_dynamic<sz)NetTuningPlugin._instance_unapply_dynamiccCstd|d�S)Ng333333#A�r:)rZspeedrrrrcBszNetTuningPlugin._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�listrf)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\]$)rnr r�search�r$rsrrrr'sr(z<NetTuningPlugin._parse_device_parameters.<locals>.<listcomp>�
r`cSsg|]}t|�dkr|�qS�r`�rn)r$�urrrr'xr(cSsg|]}t�dt|���qS�z:\s*)rrmr rwrrrr'xr(r)r
�multiple_re_replacermrnrp)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_pathrUT)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)	rrlr r�
WOL_VALUESr�warningr
�execute)rr<r!�sim�removerrr�_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_lanrVcCsN|durdSt|�}|dkrF|sB|jj|��||r:tjgndd�|SdSdS)NrF)Zno_error)r;r
Z
write_to_filer�errno�ENOENT)rr<r�r�Zhashsizerrr�_set_nf_conntrack_hashsize�s�z*NetTuningPlugin._set_nf_conntrack_hashsizecCs(|j�|���}t|�dkr$t|�SdS)Nr)r
Z	read_filerrnr;)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�r�r�rr�rEr)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�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�rrEr�rvr��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)NrWT)rXrYrZr[zunknown %s parameter(s): %sF)
r�keysrJrNrQrT�issubsetrror )rrrr��paramsZsupported_getterZ	supportedrrr�_check_parameters
s�
z!NetTuningPlugin._check_parameterscCsR|j�dddd�|�}|�d�dd�}dd�|D�}td	d�d
d�|D�D��S)NrKrLrM)Z
Autonegotiate�RX�TXrxrcSs$g|]}|dkrt�d|�s|�qS)�z	\[fixed\])rrvr#rrrr'r(z;NetTuningPlugin._parse_pause_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qSryrzr#rrrr' r(cSsg|]}t�d|��qSr|�rrmr#rrrr' r()r
r}rmrp)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:$��flagsrrLrOrPrM)r�zRX MinizRX Jumbor�rxcSsg|]}|dkr|�qS�r�rr#rrrr',r(z:NetTuningPlugin._parse_ring_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qSryrzr#rrrr'-r(cSsg|]}t�d|��qSr|r�r#rrrr'-r(�rrm�	MULTILINEr
r}rp�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�rrLrMrRrS)r�r�ZOtherZCombinedrxcSsg|]}|dkr|�qSr�rr#rrrr':r(z>NetTuningPlugin._parse_channels_parameters.<locals>.<listcomp>cSsg|]}t|�dkr|�qSryrzr#rrrr';r(cSsg|]}t�d|��qSr|r�r#rrrr';r(r�r�rrr�_parse_channels_parameters1s��
z*NetTuningPlugin._parse_channels_parameterscCszg}d|vr(|�d|dd|dg�n,ttt|d�t|d���}|�d|g�ttt|ddd�|ddd����S)NrSrLrrM�r`)�extendr rbr;rprqrf)rrrZparams_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�rr��pop)	rrr�
parametersr!r�Zsupported_parametersZparameters_to_changeZunsupported_parameters�paramrrr�_check_device_supportGs	��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�rXrWrYrZr[r�rrX)r
r�rnr~r�r�r�r�)
rrrr!�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)Nrr[)zn/ar�zsetting %s: %sz-Cz-Kz-Az-Gz-Lr�r��P)r�)
rnrur�r�r �next�iterr�r
�	dict2listrrr�)	rrrr<r!r�r�r�r�r�rrr�_set_device_parametersps" �$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!rj)
Z_storage_keyr�rnr��itemsrpr
r�Z_log_verification_resultZ_storager�join�get)rrr�startr<r!�verifyZstorage_keyZparams_currentZrelevant_params_currentr��original_valuerr�r�_custom_parameters�sH���
�

��
�z"NetTuningPlugin._custom_parametersrWcCs|�d||||�S)NrW�r��rr�r<r!r�r�rrr�	_features�szNetTuningPlugin._featuresrXcCs|�d||||�S)NrXr�r�rrr�	_coalesce�szNetTuningPlugin._coalescerYcCs|�d||||�S)NrYr�r�rrr�_pause�szNetTuningPlugin._pauserZcCs|�d||||�S)NrZr�r�rrr�_ring�szNetTuningPlugin._ringr[cCs|�d||||�S)Nr[r�r�rrr�	_channels�szNetTuningPlugin._channels)F)N)F)F)N)7�__name__�
__module__�__qualname__�__doc__r
r"r)r1r5r6r9r7�classmethodrJrNrQrTr^rBrCrDrhrcrur~rZcommand_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