Commit 389ef69c authored by Florent Fourcot's avatar Florent Fourcot Committed by Peter V. Saveliev

ipset: support setting counters on ipset add (#323)

By default, counters are never reseted by ipset, even if one entry is
deleted/removed. We implement this option to allow user to set counters
manually for each entry
parent 0aff806b
......@@ -158,7 +158,8 @@ class IPSet(NetlinkSocket):
return attrs
def _add_delete_test(self, name, entry, family, cmd, exclusive,
comment=None, timeout=None, etype="ip"):
comment=None, timeout=None, etype="ip",
packets=None, bytes=None):
excl_flag = NLM_F_EXCL if exclusive else 0
data_attrs = self._entry_to_data_attrs(entry, etype, family)
......@@ -167,6 +168,10 @@ class IPSet(NetlinkSocket):
["IPSET_ATTR_CADT_LINENO", 0]]
if timeout is not None:
data_attrs += [["IPSET_ATTR_TIMEOUT", timeout]]
if bytes is not None:
data_attrs += [["IPSET_ATTR_BYTES", bytes]]
if packets is not None:
data_attrs += [["IPSET_ATTR_PACKETS", packets]]
msg = ipset_msg()
msg['attrs'] = [['IPSET_ATTR_PROTOCOL', self._proto_version],
['IPSET_ATTR_SETNAME', name],
......@@ -177,13 +182,13 @@ class IPSet(NetlinkSocket):
terminate=_nlmsg_error)
def add(self, name, entry, family=socket.AF_INET, exclusive=True,
comment=None, timeout=None, etype="ip"):
comment=None, timeout=None, etype="ip", **kwargs):
'''
Add a member to the ipset
'''
return self._add_delete_test(name, entry, family, IPSET_CMD_ADD,
exclusive, comment=comment,
timeout=timeout, etype=etype)
timeout=timeout, etype=etype, **kwargs)
def delete(self, name, entry, family=socket.AF_INET, exclusive=True,
etype="ip"):
......
......@@ -81,8 +81,8 @@ class ipset_msg(nfgen_msg):
(22, 'IPSET_ATTR_RESIZE', 'hex'),
(23, 'IPSET_ATTR_SIZE', 'hex'),
(23, 'IPSET_ATTR_IFACE', 'asciiz'),
(24, 'IPSET_ATTR_BYTES', 'be64'),
(25, 'IPSET_ATTR_PACKETS', 'be64'),
(24, 'IPSET_ATTR_BYTES', 'be64', NLA_F_NET_BYTEORDER),
(25, 'IPSET_ATTR_PACKETS', 'be64', NLA_F_NET_BYTEORDER),
(26, 'IPSET_ATTR_COMMENT', 'asciiz'),
(27, 'IPSET_ATTR_SKBMARK', 'hex'),
(28, 'IPSET_ATTR_SKBPRIO', 'be32'),
......@@ -111,8 +111,8 @@ class ipset_msg(nfgen_msg):
(21, 'IPSET_ATTR_CIDR2', 'hex'),
(22, 'IPSET_ATTR_IP2_TO', 'hex'),
(23, 'IPSET_ATTR_IFACE', 'asciiz'),
(24, 'IPSET_ATTR_BYTES', 'be64'),
(25, 'IPSET_ATTR_PACKETS', 'be64'),
(24, 'IPSET_ATTR_BYTES', 'be64', NLA_F_NET_BYTEORDER),
(25, 'IPSET_ATTR_PACKETS', 'be64', NLA_F_NET_BYTEORDER),
(26, 'IPSET_ATTR_COMMENT', 'asciiz'),
(27, 'IPSET_ATTR_SKBMARK', 'hex'),
(28, 'IPSET_ATTR_SKBPRIO', 'be32'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment