File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/__pycache__/iptables.cpython-310.pyc
o
�N�g�� � @ sh d Z ddlZddlZddlZddlZddlZddlZddlZddl Zddl
ZddlmZ ddl
mZ e�e�Zdd� Zd9dd �Zd9d
d�Zd9dd
�Zdd� Zd:dd�Zd9dd�Z d;dd�Zd<dd�Zd9dd�Zd=dd�Zd>dd�Zd=d d!�Zd<d"d#�Z d=d$d%�Z!d>d&d'�Z"d>d(d)�Z#d>d*d+�Z$d=d,d-�Z%d?d.d/�Z&d@d0d1�Z'dAd2d3�Z(dBd5d6�Z)d7d8� Z*dS )Ca�
Support for iptables
Configuration Options
---------------------
The following options can be set in the minion config, grains, pillar, or
master config. The configuration is read using :py:func:`config.get
<salt.modules.config.get>`.
- ``iptables.save_filters``: List of REGEX strings to FILTER OUT matching lines
This is useful for filtering out chains, rules, etc that you do not wish to
persist, such as ephemeral Docker rules.
The default is to not filter out anything.
.. code-block:: yaml
iptables.save_filters:
- "-j CATTLE_PREROUTING"
- "-j DOCKER"
- "-A POSTROUTING"
- "-A CATTLE_POSTROUTING"
- "-A FORWARD"
� N)�
SaltException)�STATE_INTERNAL_KEYWORDSc C s t jj�d�s dS dS )z7
Only load the module if iptables is installed
�iptables)FzGThe iptables execution module cannot be loaded: iptables not installed.T��salt�utils�path�which� r
r
�I/opt/saltstack/salt/lib/python3.10/site-packages/salt/modules/iptables.py�__virtual__, s r �ipv4c C s$ | dkrt jj�d�S t jj�d�S )zG
Return correct command based on the family, e.g. ipv4 or ipv6
�ipv6Z ip6tablesr r ��familyr
r
r �
_iptables_cmd9 s r c C s* t |�� d�}| td |dd�v rdS dS )z�
Return truth of whether iptables has `option`. For example:
.. code-block:: python
_has_option('--wait')
_has_option('--check', family='ipv6')
z --help�cmd.run_stdout�quiet�Zoutput_loglevelTF)r �__salt__)�optionr �cmdr
r
r �_has_optionC s r c C s� t d dkr| dkrdS dS t d dkr| dkrdS dS t d d kr*| dkr(d
S dS t d d
kr8| dkr6dS dS t d dkr@dS t d dkrN| dkrLdS dS t d dkr\| dkrZdS dS t d dkrj| dkrhdS dS tdd�t d � d ��)z@
Some distros have a specific location for config files
Z os_familyZRedHatr z/etc/sysconfig/ip6tablesz/etc/sysconfig/iptablesZArchz/etc/iptables/ip6tables.rulesz/etc/iptables/iptables.rulesZDebianz/etc/iptables/rules.v6z/etc/iptables/rules.v4�osZGentooz/var/lib/ip6tables/rules-savez/var/lib/iptables/rules-saveZSusez+/etc/sysconfig/scripts/SuSEfirewall2-customZVoidr
ZAlpinez/etc/iptables/rules6-savez/etc/iptables/rules-saveZ NILinuxRTz!/etc/natinst/share/ip6tables.confz /etc/natinst/share/iptables.confzSaving iptables to file is notz supported on {}.z$ Please file an issue with SaltStack)Z
__grains__r �formatr r
r
r �_confR sJ ���r c C s t d dg �} | S )a
Return array of strings from `save_filters` in config.
This array will be pulled from minion config, minion grains,
minion pillar, or master config. The default value returned is [].
.. code-block:: python
_conf_save_filters()
z
config.option�iptables.save_filters)r )Zconfigr
r
r �_conf_save_filters� s r c C s� dt vr6g t d<