403Webshell
Server IP : 202.155.9.38  /  Your IP : 216.73.216.124
Web Server : LiteSpeed
System : Linux srv733443859 5.15.0-179-generic #189-Ubuntu SMP Tue May 5 18:20:56 UTC 2026 x86_64
User : rabbi4843 ( 1044)
PHP Version : 8.1.34
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /proc/752016/root/usr/share/netplan/netplan_cli/cli/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /proc/752016/root/usr/share/netplan/netplan_cli/cli/__pycache__/sriov.cpython-310.pyc
o

��itS�@sZddlZddlZddlZddlZddlZddlmZmZmZmZddl	m
Z
ddlmZddl
Z
ddlZGdd�de�Zd	ejefd
d�Zd	ejedejefd
d�Zde
jdedefdd�Zde
jdeefdd�Zdd�Zde
jdeeeffdd�Zde
jdeeeffdd�Zde
jdeefdd�Zdd�Zd d!�Z d'd#d$�Z!d'd%d&�Z"dS)(�N)�Dict�List�Optional�Set�)�utils�)�ConfigurationErrorc@s�eZdZdZdefdd�Zedefdd��Zedefdd	��Zd
edefdd�Z	edefd
d��Z
edefdd��Zedefdd��Z
edefdd��Zedefdd��Zedefdd��Zdededefdd�Zdefdd�Zdefd d!�Zd"S)#�	PCIDevicez.Helper class for interaction with a PCI device�pci_addrcCs
||_dS)znInitialise a new PCI device handler
        :param pci_addr: PCI address of device
        :type: str
        N�r)�selfr�r�+/usr/share/netplan/netplan_cli/cli/sriov.py�__init__'s
zPCIDevice.__init__�returncCsdS)zusysfs path (can be overridden for testing)
        :return: full path to /sys filesystem
        :rtype: str
        z/sysr�r
rrr�sys.sz
PCIDevice.syscCstj�|jd|j�S)zq/sys path for PCI device
        :return: full path to PCI device in /sys filesystem
        :rtype: str
        zbus/pci/devices)�os�path�joinrrrrrrr6szPCIDevice.path�subpathcCstj�|j|�S)z�/sys subpath helper for PCI device
        :param subpath: subpath to construct path for
        :type: str
        :return: self.path + subpath
        :rtype: str
        )rrr)r
rrrrr>szPCIDevice.subpathcCs2d}tj�|�d��rtj�t�|�d���}|S)zjKernel driver for PCI device
        :return: kernel driver in use for device
        :rtype: str
        ��driver)rr�existsr�basename�readlink)r
rrrrrGszPCIDevice.drivercC�tj�|�d��S)z�Determine if device is bound to a kernel driver
        :return: whether device is bound to a kernel driver
        :rtype: bool
        r�rrrrrrrr�boundR�zPCIDevice.boundcCr)zwDetermine if device is a SR-IOV Physical Function
        :return: whether device is a PF
        :rtype: bool
        �sriov_numvfsrrrrr�is_pfZr zPCIDevice.is_pfcCr)zvDetermine if device is a SR-IOV Virtual Function
        :return: whether device is a VF
        :rtype: bool
        �physfnrrrrr�is_vfbr zPCIDevice.is_vfcCsRg}d}	z|�tj�t�|�d�|�����Wn
ty#Y|Sw|d7}q)z�List Virtual Function addresses associated with a Physical Function
        :return: List of PCI addresses of Virtual Functions
        :rtype: list[str]
        rTzvirtfn{}r)�appendrrrrr�format�FileNotFoundError)r
�vf_addrs�irrrr(js����zPCIDevice.vf_addrscCsdd�|jD�S)z�List Virtual Function associated with a Physical Function
        :return: List of PCI devices of Virtual Functions
        :rtype: list[PCIDevice]
        cSsg|]}t|��qSr)r
)�.0�addrrrr�
<listcomp>�sz!PCIDevice.vfs.<locals>.<listcomp>)r(rrrr�vfs~sz
PCIDevice.vfs�obj_name�prop�valuec	Cs$t�dd|dd�|j�||g�dS)z�Set devlink options for the PCI device
        :param obj_name: devlink object to set options on
        :type: str
        :param prop: property to set
        :type: str
        :param value: value to set for property
        :type: str
        �
/sbin/devlink�dev�setzpci/{}N)�
subprocess�
check_callr&r)r
r.r/r0rrr�devlink_set�s	
��zPCIDevice.devlink_setcCsjd|j��}ztjddddd|gtjd�}Wntjy!YdSwt�|�}|�di��|i��d	d�S)
z�Query eswitch mode via devlink for the PCI device
        :return: the eswitch mode or '__undetermined' if it can't be retrieved
        :rtype: str
        zpci/r1z-jr2�eswitch�show)�stderr�__undetermined�mode)rr4�check_output�DEVNULL�CalledProcessError�json�loads�get)r
�pci�output�json_outputrrr�devlink_eswitch_mode�s"�
��
zPCIDevice.devlink_eswitch_modecCs|jS)zbString represenation of object
        :return: PCI address of string
        :rtype: str
        rrrrr�__str__�szPCIDevice.__str__N)�__name__�
__module__�__qualname__�__doc__�strr�propertyrrrr�boolrr"r$�listr(r-r6rErFrrrrr
$s.	
r
r-c	Cs^g}|D](}|js,td�|�d��}|�|j�|�|�Wd�n1s'wYq|S)zBind unbound VFs to driver.z/sys/bus/pci/drivers/{}/bind�wtN�r�openr&�writerr%)r-r�	bound_vfs�vf�frrr�bind_vfs����rVrc	Cs^g}|D](}|jr,td�|�d��}|�|j�|�|�Wd�n1s'wYq|S)zUnbind bound VFs from driver.z/sys/bus/pci/drivers/{}/unbindrONrP)r-r�unbound_vfsrTrUrrr�
unbind_vfs�rWrY�netdef�	interfacecCs|j|t�|�t�|�d�S)N)�
iface_name�iface_driver�	iface_mac)�_match_interfacer�get_interface_driver_name�get_interface_macaddress)rZr[rrr�_interface_matches�s
�rbcCs�t��}|jr<|j}|r||vr|St�}|D]}t||�sqt|�dkr,td|j��|�	|�q|r:t
|�dSdS|j|vrD|jSdS)z�
    Try to match a netdef with the real system network interface.
    Throws ConfigurationError if there is more than one match.
    rz3matched more than one interface for a PF device: %srN)�	netifaces�
interfaces�
_has_match�set_namer3rb�lenr	�id�addrN)rZrdrf�matchesr[rrr�_get_interface_name_for_netdef�s$

�rkc
Cs�tj�d|d�}z?t|��0}d}|��D]}|��}|�d�r3|�dd�d}|Wd�WSqWd�WdS1s@wYWdSty]}z
t	d|t
|�f��d}~ww)	z5
    Read PCI slot name for given interface name
    �/sys/class/netz
device/ueventNzPCI_SLOT_NAME=�=rrz'failed parsing PCI slot name for %s: %s)rrrrQ�	readlines�strip�
startswith�split�IOError�RuntimeErrorrK)�netdev�uevent_pathrU�
pci_slot_name�line�errr�_get_pci_slot_names"

��&���ry�np_statecCs�i}|j��D]O}|j�d�}r t||j�}r|||j<q|jr.t|�}r.|||j<z|j}Wntj	yF}zt
t|���d}~ww|dkrVt|�}rV|||j<q|S)z�
    Go through the list of netplan ethernet devices and identify which are
    PFs matching them with actual network interfaces.
    �sriovNr)�	ethernets�values�linksrArkrh�_embedded_switch_mode�	_vf_count�netplan�NetplanExceptionr	rK)rz�pfsrZ�link�iface�countrxrrr�_get_physical_functionss(
�

��
�r�cCsfi}|j��D])}z|j}Wntjy!}ztt|���d}~ww|dkr0t|�}r0|||<q|S)z�
    Go through the list of netplan ethernet devices and identify which ones
    have VFs. netdef._vf_count ultimately calls _netplan_state_get_vf_count_for_def
    from libnetplan which return MAX(sriov_explicit_vf_count, number of VF netdefs).
    Nr)r|r}r�r�r�r	rKrk)rz�	vf_countsrZr�rxr�rrr�_get_vf_number_per_pf0s
���r�cCsDt�}|j��D]}|j�d�}rt||j�r|�|j�q|S)zk
    Go through the list of netplan ethernet devices and identify which ones
    are virtual functions
    r{)r3r|r}r~rArkrhri)rzr-rZr�rrr�_get_virtual_functionsCs�r�c

Cs"|dkrtd||f��tj�d|d�}tj�|d�}tj�|d�}zt|��}t|�����}Wd�n1s:wYWn"tyV}z
t	d|t
|�f��d}~wtybt	d	|��w||krptd
|||f��z!t|d��}|�t
|��Wd�WdS1s�wYWdSt�y}zrd}|j
d
kr�t�d|�z8t|d��
}|�d�Wd�n1s�wYt|d��}|�t
|��Wd�n1s�wYWnty�}	z|	}WYd}	~	nd}	~	wwd}|�rt	d||t
|�f��WYd}~dSd}~ww)zB
    Allocate the required number of VFs for the selected PF.
    �zDcannot allocate more VFs for PF %s than the SR-IOV maximum: %s > 256rl�devicer!�sriov_totalvfsNz(failed parsing sriov_totalvfs for %s: %sz#invalid sriov_totalvfs value for %szKcannot allocate more VFs for PF %s than supported: %s > %s (sriov_totalvfs)�wT�zLdevice or resource busy while setting sriov_numvfs for %s, trying workaround�0Fz,failed setting sriov_numvfs to %s for %s: %s)r	rrrrQ�int�readrorrrsrK�
ValueErrorrR�errno�logging�warning)
�pf�vf_count�devdir�numvfs_path�
totalvfs_pathrU�vf_maxrx�bail�e_innerrrr�set_numvfs_for_pfQsh
�
��������
�����
���r�c
Cs�tj�d|d�}zHttj�|d���}|����dd�}Wd�n1s'wYttj�|d���}|����dd�}Wd�n1sJwYWntyf}z
td|t|�f��d}~wwd�||g�}d}||vrw	dSdS)	z�
    Perform any hardware-specific quirks for the given SR-IOV device to make
    sure all the VF-count changes are applied.
    rlr��vendorrNz2could not determine vendor and device ID of %s: %s�:r)	rrrrQr�rorrrsrK)r�r�rU�	device_id�	vendor_idrx�combined_id�
quirk_devicesrrr� perform_hardware_specific_quirks�s$�����
�r��/cCs�d}tj�|d|d�}tj�t�|��}tj�|d|d�}t�|�D]"}	d|	vrDtj�||	�}
tj�t�|
��}||krD|	dd�}nq"|sOtd||f��ztjddd	d
|d|dt	|�g	tj
tj
d
�WdStjyutd|��w)z@
    Apply the hardware VLAN filtering for the selected VF.
    Nz
sys/class/netr��virtfn�zAcould not determine the VF index for %s while configuring vlan %s�ipr�r3r2rT�vlan)�stdoutr9zJfailed setting SR-IOV VLAN filter for vlan %s (ip link set command failed))rrrrr�listdirrsr4r5rKr=r>)r�rT�	vlan_name�vlan_id�prefix�vf_index�	vf_devdir�	vf_dev_id�	pf_devdirrU�dev_path�dev_idrrr�apply_vlan_filter_for_vf�s<�
�
����r�cCs�t��}|�|�t��}|�|�|��t��}|j}t	|�}t
|�}t|�}g}|rA|��D]\}	}
t
|	|
�s;q1|�|	�q1|rP|D]}	t|	�qEt��}i}|D]/}||}
|
jr{|D]}|
j|d�ry||vru||rutd|��|||<q_qT||vr�|||<qT|��D]\}}||}
|
j}|dv�rt|�}t|�}|��}||k�r|j�rt�d�||j��|jr�z	t|j|j�Wnty�}zt� d|�dt!|����WYd}~nd}~wwt�d|�d	|�d
|���|�"dd|�|j�r|
j#�st$|j|j�q�t%�}|j&��D]L\}}
|
j'�r[|
j(�)d
�}|
j*}|�)|j+�}|�s6t� d||j+f��q|�)|j(�)d�j+�}	||v�rOtd||j+|f��t,|	|||�|�-|��qdS)z
    Go through all interfaces, identify which ones are SR-IOV VFs, create
    them and perform all other necessary setup.
    )r\z3matched more than one interface for a VF device: %s)�	switchdev�legacyzFound VFs of {}: {}zUnbinding of VFs for z	 failed: NzChanging eswitch mode from z to z for: r7r;r�zKSR-IOV vlan defined for %s but link %s is either not a VF or has no matchesr{zJinterface %s for netplan device %s (%s) already has an SR-IOV vlan defined).r��Parser�load_yaml_hierarchy�State�import_parser_results�parsercrdrzr�r�r��itemsr�r%r�rer_r	rryr
rEr"r��debugr&r(r-rYr�	Exceptionr�rKr6�_delay_virtual_functions_rebindrVr3�vlans�_has_sriov_vlan_filterr~rA�_vlan_idrhr�ri)�config_manager�rootdir�parserrzrdr��vfs_setr��vf_count_changedr�r�r-rTrZr[�	netdef_idr��eswitch_moder�pcidev�current_eswitch_mode_systemrx�filtered_vlans_setr�r�r�rrr�apply_sriov_config�s�



���

&����
�
��r�)r�)#r?r�rr4�typingrrrrrr�
configmanagerr	r�rc�objectr
�IterablerVrY�
NetDefinitionrKrMrbrkryr�r�r�r�r�r�r�r�r�rrrr�<module>s0$/
'

Youez - 2016 - github.com/yon3zu
LinuXploit