$20 GRAYBYTE WORDPRESS FILE MANAGER $17

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 91.108.106.74 | ADMIN IP 216.73.216.63
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python311/lib/python3.11/site-packages/pyroute2/__pycache__/

HOME
Current File : /opt/alt/python311/lib/python3.11/site-packages/pyroute2/__pycache__//wiset.cpython-311.pyc
�

�;f�L�	��dZddlZddlZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZmZmZmZmZdd
lmZddiZd�ZGd
�dedgd�����ZGd�de��Zededdfd���Zed d���Zed!d���Zed"d���Zed"d���Z ed"d���Z!ed"d���Z"ed"d���Z#ed"d���Z$ed"d���Z%ed"d���Z&ed"d���Z'd�Z(dS)#a�
High level ipset support.

When :doc:`ipset` is providing a direct netlink socket with low level
functions, a :class:`WiSet` object is built to map ipset objects from kernel.
It helps to add/remove entries, list content, etc.

For example, adding an entry with :class:`pyroute2.ipset.IPSet` object
implies to set a various number of parameters:

.. doctest::
    :skipif: True

    >>> ipset = IPSet()
    >>> ipset.add("foo", "1.2.3.4/24", etype="net")
    >>> ipset.close()

When they are discovered by a :class:`WiSet`:

.. doctest::
    :skipif: True

    >>> wiset = load_ipset("foo")
    >>> wiset.add("1.2.3.4/24")

Listing entries is also easier using :class:`WiSet`, since it parses for you
netlink messages:

.. doctest::
    :skipif: True

    >>> wiset.content
    {'1.2.3.0/24': IPStats(packets=None, bytes=None, comment=None,
                           timeout=None, skbmark=None, physdev=False)}
�N)�
namedtuple)�getcallargs)�AF_INET)�
basestring��IPSet)�
IPSetError)�IPSET_FLAG_IFACE_WILDCARD�IPSET_FLAG_PHYSDEV�IPSET_FLAG_WITH_COMMENT�IPSET_FLAG_WITH_COUNTERS�IPSET_FLAG_WITH_SKBINFO)�IP_PROTOCOLS�countc����fd�}|S)a�Decorator to create netlink socket if needed.

    In many of our helpers, we need to open a netlink socket. This can
    be expensive for someone using many times the functions: instead to have
    only one socket and use several requests, we will open it again and again.

    This helper allow our functions to be flexible: the caller can pass an
    optional socket, or do nothing. In this last case, this decorator
    will open a socket for the caller (and close it after call)

    It also help to mix helpers. One helper can call another one: the socket
    will be opened only once. We just have to pass the ipset variable.

    Note that all functions using this helper *must* use ipset as variable
    name for the socket.
    c�,��t�g|�Ri|��}|d�ttdxxdz
cc<t��5}||d<d|vr(|�|�d�����di|��cddd��S#1swxYwY�|i|��S)N�sockr��kwargs�)r�COUNTr�update�pop)�argsr�callargsr�funs    ��A/opt/alt/python311/lib/python3.11/site-packages/pyroute2/wiset.py�wrapzneed_ipset_socket.<locals>.wrapMs�����s�4�T�4�4�4�V�4�4���F��#��'�N�N�N�a��N�N�N����
'�D�#'��� ��x�'�'��O�O�H�L�L��$:�$:�;�;�;��s���X���

'�
'�
'�
'�
'�
'�
'�
'�
'�
'�
'�
'����
'�
'�
'�
'��s�D�#�F�#�#�#s�9B�B�
Br)rrs` r�need_ipset_socketr;s#���$
$�
$�
$�
$�
$��K�c�(��eZdZdZ		d�fd�	Z�xZS)�IPStatsrFc
�d��tt|���||||||||���S)N)�physdev�wildcard)�superr"�__new__)	�cls�packets�bytes�comment�timeout�skbmarkr$r%�	__class__s	        �rr'zIPStats.__new__osD����W�c�"�"�*�*���������+�	
�	
�		
r )FF)�__name__�
__module__�__qualname__�	__slots__r'�
__classcell__)r.s@rr"r"_sL��������I���
�
�
�
�
�
�
�
�
�
r r")r)r*r+r,r-r$r%c
���eZdZdZddedddddddf
d�Zd�Zd�Zed���Z	e	j
d	���Z	d
�Zd�Ze
dd���Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zed���Zd�Zd�ZdS)�WiSeta�Main high level ipset manipulation class.

    Every high level ipset operation should be possible with this class,
    you probably don't need other helpers of this module, except tools
    to load data from kernel (:func:`load_all_ipsets` and :func:`load_ipset`)

    For example, you can create and an entry in a ipset just with:

    .. doctest::
        :skipif: True

        >>> with WiSet(name="mysuperipset") as myset:
        >>>    myset.create()             # add the ipset in the kernel
        >>>    myset.add("198.51.100.1")  # add one IP to the set

    Netlink sockets are opened by __enter__ and __exit__ function, so you don't
    have to manage it manually if you use the "with" keyword.

    If you want to manage it manually (for example for long operation in
    a daemon), you can do the following:

    .. doctest::
        :skipif: True

        >>> myset = WiSet(name="mysuperipset")
        >>> myset.open_netlink()
        >>> # do stuff
        >>> myset.close_netlink()

    You can also don't initiate at all any netlink socket, this code will work:

    .. doctest::
        :skipif: True

        >>> myset = WiSet(name="mysuperipset")
        >>> myset.create()
        >>> myset.destroy()

    But do it very carefully. In that case, a netlink socket will be opened
    in background for any operation. No socket will be leaked, but that
    can consume resources.

    You can also instantiate WiSet objects with :func:`load_all_ipsets` and
    :func:`load_ipset`:

    .. doctest::
        :skipif: True

        >>> all_sets_dict = load_all_ipsets()
        >>> one_set = load_ipset(name="myset")

    Have a look on content variable if you need list of entries in the Set.
    Nzhash:ipFc���||_||_d|_d|_||_||_d|_||_||_||_	||_
|	|_d|_|
|_
dS�N)�name�hashsize�
_attr_type�
entry_type�	attr_type�family�_contentrr,�countersr+�revision�index�skbinfo)�selfr8r<r=rr,r?r+r9r@rBs           r�__init__zWiSet.__init__�sj����	� ��
�������"��������
���	���� ��
���� ��
���
�����r c�>�|j�t��|_dSdS)zh
        Open manually a netlink socket.

        You can use "with WiSet()" statement instead.
        N)rr�rCs r�open_netlinkzWiSet.open_netlink�s#���9�����D�I�I�I��r c�X�|j�"|j���d|_dSdS)zClone any opened netlink socketN)r�closerFs r�
close_netlinkzWiSet.close_netlink�s/���9� ��I�O�O�����D�I�I�I�!� r c��|jSr7)r:rFs rr<zWiSet.attr_type�s
����r c�V�||_|�dd��d|_dS)N�:r)r:�splitr;)rC�values  rr<zWiSet.attr_type�s'������+�+�c�1�-�-�a�0����r c�.�|���|Sr7)rGrFs r�	__enter__zWiSet.__enter__�s���������r c�.�|���dSr7)rJ)rC�exc_type�	exc_value�	tracebacks    r�__exit__zWiSet.__exit__�s���������r c��|��}|�d��|_|�d��|_|�d��|_|�d��|_|�d��|_|�d��|_|�d��}|�d��|_|�d	��}|�Tt|tz��|_
t|tz��|_t|tz��|_|r|�|��|S)
a	Create a ipset objects based on a parsed netlink message

        :param ndmsg: the netlink message to parse
        :param content: should we fill (and parse) entries info (can be slow
                        on very large set)
        :type content: bool
        �IPSET_ATTR_TYPENAME�IPSET_ATTR_SETNAME�IPSET_ATTR_HASHSIZE�IPSET_ATTR_FAMILY�IPSET_ATTR_REVISION�IPSET_ATTR_INDEX�IPSET_ATTR_DATA�IPSET_ATTR_TIMEOUT�IPSET_ATTR_CADT_FLAGS)�get_attrr<r8r9r=r@rAr,�boolr
r?rr+rrB�update_dict_content)r(�ndmsg�contentrC�data�flagss      r�from_netlinkzWiSet.from_netlink�s%���s�u�u�����(=�>�>����N�N�#7�8�8��	����'<�=�=��
��n�n�%8�9�9������'<�=�=��
��^�^�$6�7�7��
��~�~�/�0�0���}�}�%9�:�:����
�
�5�6�6���� ��)A�!A�B�B�D�M���(?� ?�@�@�D�L���(?� ?�@�@�D�L��	,��$�$�U�+�+�+��r c
���d}d}|j�i|_d}|�d���d��}|D�]"}d}|j�d��D�]�}|dkr/|�|���|��}	||	z
}�n�|d	kr^|�|���|��}	||	z
}|�d
��}
|
�|d�|
��z
}�n&|dkr||�d
��z
}�n|dkr||�d��z
}n�|dkr3|t
t|�d������z
}n�|dkr�|�d��}|�Mtj	|t
|�����
��}|d�|���z
}|t
|�d����z
}n|dkr||�d��z
}|dz
}���|�d��}|j�|�d��}|�d��}|�N|ddkr d�
d�|D����}n"t
t|d����}d d!i}
|�d"��}|�4t|tz��|
d <t|t z��|
d#<t#d(|�d$��|�d%��|�d&��||d'�|
��}||j|<��$dS))z�Update a dictionary statistics with values sent in netlink message

        :param ndmsg: the netlink message
        :type ndmsg: netlink message

        �IPSET_ATTR_IPADDR_IPV4�IPSET_ATTR_IP_FROMN�IPSET_ATTR_ADTr^��,�ip�net�IPSET_ATTR_CIDRz/{0}�iface�IPSET_ATTR_IFACE�set�IPSET_ATTR_NAME�mark�IPSET_ATTR_MARK�port�IPSET_ATTR_PROTOz{proto}:)�proto�IPSET_ATTR_PORT_FROM�mac�IPSET_ATTR_ETHERr_�IPSET_ATTR_SKBMARKrl���/c�F�g|]}tt|������Sr)�str�hex)�.0rvs  r�
<listcomp>z-WiSet.update_dict_content.<locals>.<listcomp>Is$��'K�'K�'K�4��C��I�I���'K�'K�'Kr rr$Fr`r%�IPSET_ATTR_PACKETS�IPSET_ATTR_BYTES�IPSET_ATTR_COMMENT)r)r*r+r-r,r)r>ra�	get_attrsr;rN�formatr�r�r�get�lower�stripr,�joinrbrr
r")rCrdr=�ip_attrr,�entries�entry�key�
parse_typero�cidrrzr-�entry_flag_parsedrgrOs                rrczWiSet.update_dict_contents���*��&���=� ��D�M����.�.�!1�2�2�<�<�=N�O�O���8	'�8	'�E��C�"�o�3�3�C�8�8�
�
�
���%�%�����0�0�9�9�&�A�A�B��2�I�C�C��5�(�(�����0�0�9�9�&�A�A�B��2�I�C� �>�>�*;�<�<�D��'��v�}�}�T�2�2�2����7�*�*��5�>�>�*<�=�=�=�C�C��5�(�(��5�>�>�*;�<�<�<�C�C��6�)�)��3�s�5�>�>�2C�#D�#D�E�E�F�F�F�C�C��6�)�)�!�N�N�+=�>�>�E��(� ,� 0���E�
�
� C� C� I� I� K� K���z�0�0�u�0�=�=�=���3�u�~�~�.D�E�E�F�F�F�C�C��5�(�(��5�>�>�*<�=�=�=�C��s�
����)�)�C�.�.�C��|�'��.�.�)=�>�>���n�n�%9�:�:�G��"��1�:�)�,�,�!�h�h�'K�'K�7�'K�'K�'K�L�L�G�G�!�#�g�a�j�/�/�2�2�G�!*�E� 2���N�N�#:�;�;�E�� �/3�E�<N�4N�/O�/O�!�)�,�04��5�5�1�1�!�*�-������';�<�<��n�n�%7�8�8����';�<�<�����$�
��E�"'�D�M�#���q8	'�8	'r c��t|jf|j|j|j|j|j|j|j|j	d�|��dS)z�Insert this Set in the kernel

        Many options are set with python object attributes (like comments,
        counters, etc). For non-supported type, kwargs are provided. See
        :doc:`ipset` documentation for more information.
        )�styper=rr,r+r?r9rBN)
�create_ipsetr8r<r=rr,r+r?r9rB)rCrs  r�createzWiSet.create^sa��	��I�	
��.��;����L��L��]��]��L�	
�	
��	
�	
�	
�	
�	
r c�<�t|j|j���dS)aDestroy this ipset in the kernel list.

        It does not delete this python object (any content or other stored
        values are keep in memory). This function will fail if the ipset is
        still referenced (by example in iptables rules), you have been warned.
        �rN)�
destroy_ipsetr8rrFs r�destroyz
WiSet.destroyrs!��	�d�i�d�i�0�0�0�0�0�0r c�^�t|t��r*|�|��|�d��}|jr2|�dd��|d<|�dd��|d<|�d��}t|t��rj|�d��}t|dd��}	t|dd��}n #t$rtd	d��}YnwxYw||f|d<t|j|f|j|j
d
�|��dS)z�Add an entry in this ipset.

        If counters are enabled on the set, reset by default the value when
        we add the element. Without this reset, kernel sometimes store old
        values and can add very strange behavior on counters.
        r�r)rr*r-r�r�
0xffffffff��etyperN)�
isinstance�dictrrr?r�rrN�int�
IndexError�add_ipset_entryr8r;r)rCr�rr-rv�masks      r�addz	WiSet.add{sM���e�T�"�"�	(��M�M�%� � � ��J�J�w�'�'�E��=�	5� &�
�
�9�a� 8� 8�F�9��$�j�j��!�4�4�F�7�O��*�*�Y�'�'���g�z�*�*�	-��m�m�C�(�(�G��w�q�z�2�&�&�D�
-��7�1�:�r�*�*�����
-�
-�
-��<��,�,����
-����!%�t��F�9����I�u�	
�$(�O�$�)�	
�	
�GM�	
�	
�	
�	
�	
s�C&�&D�Dc�F�t|j|f|j|jd�|��dS)z$Delete/remove an entry in this ipsetr�N)�delete_ipset_entryr8r;r�rCr�rs   r�deletezWiSet.delete�s@����I�u�	
�$(�O�$�)�	
�	
�GM�	
�	
�	
�	
�	
r c�B�t|j|f|j|jd�|��S)z!Test if an entry is in this ipsetr�)�test_ipset_entryr8r;rr�s   r�testz
WiSet.test�s6����I�u�
�$(�O�$�)�
�
�GM�
�
�	
r c�B�t|j|f|j|jd�|��S)zpTest if a list of a set of entries is in this ipset

        Return a set of entries found in the IPSet
        r�)�test_ipset_entriesr8r;r)rCr�rs   r�	test_listzWiSet.test_list�s8��
"��I�w�
�&*�o�D�I�
�
�IO�
�
�	
r c�@�i|_t||j���dS)z5Update the content dictionary with values from kernelr�N)r>�update_wiset_contentrrFs r�update_contentzWiSet.update_content�s$����
��T��	�2�2�2�2�2�2r c�<�t|j|j���dS)zFlush entries of the ipsetr�N)�flush_ipsetr8rrFs r�flushzWiSet.flush�s���D�I�D�I�.�.�.�.�.�.r c�F�|j�|���|jS)zqDictionary of entries in the set.

        Keys are IP addresses (as string), values are IPStats tuples.
        )r>r�rFs rrez
WiSet.content�s&���=� ����!�!�!��}�r c�:�|D]}|�|���dS)z?Just a small helper to reduce the number of loops in main code.N�r�)rCr�r�s   r�insert_listzWiSet.insert_list�s,���	�	�E��H�H�U�O�O�O�O�	�	r c�d�ttj����dd�}t|j|j���}||_|j|_|���|�|��t|j||j���|�	��dS)a}Replace the content of an ipset with a new list of entries.

        This operation is like a flush() and adding all entries one by one. But
        this call is atomic: it creates a temporary ipset and swap the content.

        :param new_list: list of entries to add
        :type new_list: list or :py:class:`set` of basestring or of
            keyword arguments dict
        r�r�N)
r��uuid�uuid4�
load_ipsetr8rr�r��swap_ipsetsr�)rC�new_list�	temp_name�temps    r�replace_entrieszWiSet.replace_entries�s�����
���%�%�a��c�*�	��$�)�$�)�4�4�4����	��I��	����
�
�
�����"�"�"��D�I�y�t�y�9�9�9�9��������r )F)r/r0r1�__doc__rrDrGrJ�propertyr<�setterrQrV�classmethodrhrcr�r�r�r�r�r�r�r�rer�r�rr rr5r5�s�������4�4�r���
�����������8 � � ��������X����1�1���1������������[��8F'�F'�F'�P
�
�
�(1�1�1�
�
�
�4
�
�
�
�
�
�
�
�
�3�3�3�
/�/�/�����X�����
����r r5Fc�*�|j|f|||d�|��dS)zCreate an ipset.)r�r=�	exclusiveN)r�)r8r�r=r�rrs      rr�r��s@��
�D�K����&�I���AG�����r c�>�i}|���D]�}|�d��}|�|�|��s�/||vr0t�||���}|r||_|||j<�c|r ||j�|����|S)aLList all ipset as WiSet objects.

    Get full ipset data from kernel and parse it in WiSet objects. Result is
    a dictionary with ipset names as keys, and WiSet objects as values.

    :param content: parse the list of entries and fill it in WiSet content
                    dictionary
    :type content: bool
    :param inherit_sock: use the netlink sock passed in ipset arg to
                         fill WiSets sock
    :type inherit_sock: bool
    :param prefix: filter out all ipset with a name not beginning by this
                   prefix
    :type prefix: str or None
    rYN�re)�listra�
startswithr5rhrr8rc)rer�inherit_sock�prefix�res�mysetr8�wisets        r�load_all_ipsetsr��s���"
�C������7�7���~�~�2�3�3����d�o�o�f�&=�&=����s�?�?��&�&�u�g�&�>�>�E��
"�!��
�#�C��
�O�O�
�	7���
�O�/�/��6�6�6���Jr c� �d}	|�|���}n/#t$r"}|jtjkr|cYd}~S�d}~wwxYw|D]A}|�&t
�||���}|r||_�*|r|�|���B|S)a�Get one ipset as WiSet object

    Helper to get current WiSet object. More efficient that
    :func:`load_all_ipsets` since the kernel does the filtering itself.

    Return None if the ipset does not exist

    :param name: name of the ipset
    :type name: str
    :param content: parse or not content and statistics on entries
    :type content: bool
    :param inherit_sock: use the netlink sock passed in ipset arg to
                         fill WiSet sock
    :type inherit_sock: bool
    N�r8r�)	r�r	�code�errno�ENOENTr5rhrrc)r8rerr�r��messages�e�msgs        rr�r�s���"�C���9�9�$�9�'�'���������6�U�\�!�!��J�J�J�J�J�J�
����������)�)���;��$�$�S�'�$�:�:�C��
 �����
�	)��#�#�C�(�(�(���Js��
A�A�A�A�Ac�l�|�|j���D]}|�|���dS)z�Update content/statistics of a wiset.

    You should never call yourself this function. It is only a helper to use
    the :func:`need_ipset_socket` decorator out of WiSet object.
    r�N)r�r8rc)r�rr�s   rr�r�%sD���y�y�e�j�y�)�)�'�'��
�!�!�#�&�&�&�&�'�'r c�0�|�|��dS)zRemove an ipset in the kernel.N)r��r8rs  rr�r�0s��	�L�L������r c�$�|j||fi|��dS)zAdd an entryNr��r8r�rrs    rr�r�6s&��
�D�H�T�5�#�#�F�#�#�#�#�#r c�$�|j||fi|��dS)zRemove one entryN)r�r�s    rr�r�<s&���D�K��e�&�&�v�&�&�&�&�&r c��	|�|��dS#t$r!}|jtjkrYd}~dS�d}~wwxYw)zTest if the given ipset existTNF)�headersr	r�r�r�)r8rr�s   r�test_ipset_existr�Bs\������T�����t�������6�U�\�!�!��5�5�5�5�5�
��������s��
A�?�?�Ac� �|j||fi|��S)z Test if an entry is in one ipset)r�r�s    rr�r�Ns ���4�9�T�5�+�+�F�+�+�+r c�t�t��}|D]&}|j||fi|��r|�|���'|S)z"Test a list (or a set) of entries.)rtr�r�)r8r�rrr�r�s      rr�r�TsO���%�%�C������4�9�T�5�+�+�F�+�+�	��G�G�E�N�N�N���Jr c�0�|�|��dS)zFlush all ipset contentN)r�r�s  rr�r�^s��	�J�J�t�����r c�2�|�||��dS)zQSwap the content of ipset a and b.

    ipsets must have compatible content.
    N)�swap)�name_a�name_brs   rr�r�ds��	�I�I�f�f�����r c��tdi|��S)z7Get a socket that one can pass to several WiSet objectsrr)rs r�get_ipset_socketr�ms���?�?�6�?�?�r )FNFN)FNFr7))r�r�r��collectionsr�inspectr�socketr�pyroute2.commonr�pyroute2.ipsetr�pyroute2.netlink.exceptionsr	� pyroute2.netlink.nfnetlink.ipsetr
rrr
r�%pyroute2.netlink.nfnetlink.nfctsocketrrrr"�objectr5r�r�r�r�r�r�r�r�r�r�r�r�r�rr r�<module>r�s2��"�"�H
��������"�"�"�"�"�"�������������&�&�&�&�&�&� � � � � � �2�2�2�2�2�2���������������?�>�>�>�>�>�
�!���!�!�!�H#
�#
�#
�#
�#
��J��	
�	
�	
���#
�#
�#
�NO�O�O�O�O�F�O�O�O�d
��W��D��������������@�������B�'�'�'���'��������
�$�$�$���$�
�'�'�'���'�
��������,�,�,���,�
��������������
�����������r 

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
8 May 2024 6.33 PM
root / root
0755
__init__.cpython-311.pyc
4.103 KB
8 May 2024 6.33 PM
root / root
0644
arp.cpython-311.pyc
1.955 KB
8 May 2024 6.33 PM
root / root
0644
common.cpython-311.pyc
29.103 KB
8 May 2024 6.33 PM
root / root
0644
conntrack.cpython-311.pyc
10.456 KB
8 May 2024 6.33 PM
root / root
0644
devlink.cpython-311.pyc
2.967 KB
8 May 2024 6.33 PM
root / root
0644
ipset.cpython-311.pyc
26.145 KB
8 May 2024 6.33 PM
root / root
0644
iwutil.cpython-311.pyc
26.673 KB
8 May 2024 6.33 PM
root / root
0644
lab.cpython-311.pyc
1.465 KB
8 May 2024 6.33 PM
root / root
0644
loader.cpython-311.pyc
1.324 KB
8 May 2024 6.33 PM
root / root
0644
minimal.cpython-311.pyc
2.321 KB
8 May 2024 6.33 PM
root / root
0644
wiset.cpython-311.pyc
25.866 KB
8 May 2024 6.33 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF