Current File : //usr/lib/python3/dist-packages/sos/report/plugins/__pycache__/firewall_tables.cpython-312.pyc
�

-�_gC��0�ddlmZmZmZGd�dee�Zy)�)�Plugin�IndependentPlugin�SoSPredicatec�<�eZdZdZdZdZdZdZdZd�Z	d�Z
d	�Zd
�Zy)�FirewallTablesaCollects information about local firewall tables, such as iptables,
    and nf_tables (via nft). Note that this plugin does _not_ collect firewalld
    information, which is handled by a separate plugin.

    Collections from this plugin are largely gated byt the presence of relevant
    kernel modules - for example,  the plugin will not collect the nf_tables
    ruleset if both the `nf_tables` and `nfnetlink` kernel modules are not
    currently loaded (unless using the --allow-system-changes option).
    zfirewall tables�firewall_tables)�network�system)�
/etc/nftables)�	ip_tables�
ip6_tables�	nf_tables�	nfnetlink�ebtablesc�^�d|z}d|zdz}|j|t||dg����y)z� Collecting iptables rules for a table loads either kernel module
        of the table name (for kernel <= 3), or nf_tables (for kernel >= 4).
        If neither module is present, the rules must be empty.�iptable_ziptables -t � -nvLr��kmods��predN��add_cmd_outputr��self�	tablename�modname�cmds    �D/usr/lib/python3/dist-packages/sos/report/plugins/firewall_tables.py�collect_iptablezFirewallTables.collect_iptablesC��
�y�(���y�(�7�2�������d�7�K�*@�A�	�	C�c�^�d|z}d|zdz}|j|t||dg����y)z& Same as function above, but for ipv6 �	ip6table_z
ip6tables -t rrrrNrrs    r�collect_ip6tablezFirewallTables.collect_ip6table*sC���	�)���	�)�G�3�������d�7�K�*@�A�	�	Cr!c�N�t|ddgddi��}|jd|d��S)	zS Collects nftables rulesets with 'nft' commands if the modules
        are present rrr�all)r�requiredznft -a list rulesetT)r�changes)r�collect_cmd_output)r�nft_preds  r�collect_nftableszFirewallTables.collect_nftables3sB��
 ��'2�K�&@�*1�5�)9�;���&�&�'<�8�/3�'�5�	5r!c���|j�}ggd�}|ddk(r|dnd}|j�D]O}|j�dd}t|�dk(s�%|ddk(s�.|d|vs�6||dj	|d	��Qd
}	d}t|dd
��5}|j
�}	ddd�	j�D]$}
|ddk(s�|
|dvs�|j|
��&	d}t|dd
��5}|j
�}	ddd�|	j�D]$}
|ddk(s�|
|dvs�|j|
��&|ddk7sd|dvr |jdt|ddg����|ddk7sd|dvr |jdt|ddg����|jgd��y#1swY��xYw#t$r|}	Y��%wxYw#1swY��xYw#t$r|}	Y��wxYw)N)�ip�ip6�statusr�output���table��zmangle
filter
nat
z/proc/net/ip_tables_names�rzUTF-8)�encodingr-z/proc/net/ip6_tables_namesr.�filterziptables -vnxL�iptable_filterrrrzip6tables -vnxL�ip6table_filter)rz/etc/sysconfig/nftables.confz/etc/nftables.conf)
r+�
splitlines�split�len�append�open�read�IOErrorr r$rr�
add_copy_spec)
r�nft_list�
nft_ip_tables�	nft_lines�line�words�default_ip_tables�proc_net_ip_tables�ifile�ip_tables_namesr3�proc_net_ip6_tables�ipfiles
             r�setupzFirewallTables.setup>sW��
�(�(�*��!�"�-�
�*2�8�*<��*A�H�X�&�r�	��(�(�*�	9�D��J�J�L��1�%�E��5�z�Q��5��8�w�#6��!�H�
�-��e�A�h�'�.�.�u�Q�x�8�		9�4��	0�!<���(�#��@�
/�E�"'�*�*�,��
/�%�/�/�1�	,�E���!�Q�&�5�M�$�4G�+G��$�$�U�+�	,�	0�">���)�3��A�
0�V�"(�+�+�-��
0�%�/�/�1�	-�E���!�Q�&�5�M�%�4H�+H��%�%�e�,�	-��H���"�h�-��2E�&E���� �!�$�/?��.M�N�
 �
��H���"�h�-��2F�&F����!�!�$�/@�+�.N�O�
 �
�
	
���
�	�E
/�
/���	0�/�O�	0��
0�
0���	0�/�O�	0�sT�
G
�F=�+G
�+G(�;G�G(�=G�G
�
G�G�G%�!G(�(G6�5G6N)
�__name__�
__module__�__qualname__�__doc__�
short_desc�plugin_name�profiles�files�kernel_modsr r$r+rN�r!rrrs:���#�J�#�K�$�H��E��K�	C�C�	5�9r!rN)�sos.report.pluginsrrrrrXr!r�<module>rZs��I�H�k�V�.�kr!