Current File : /opt/alt/python311/lib/python3.11/site-packages/pyroute2/__pycache__//wiset.cpython-311.pyc
�
�;f�L � � � d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl m
Z
ddlmZ ddl
mZ dd lmZmZmZmZmZ dd
lmZ ddiZd� Z G d
� d edg d�� � � � Z G d� 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| �R i |��}|d �tt dxx dz
cc<