Commit 41ee13fd authored by Florent Fourcot's avatar Florent Fourcot

ipset: add support of hashsize option

parent 38a9d252
......@@ -88,7 +88,8 @@ class IPSet(NetlinkSocket):
def create(self, name, stype='hash:ip', family=socket.AF_INET,
exclusive=True, counters=False, comment=False,
maxelem=IPSET_DEFAULT_MAXELEM):
maxelem=IPSET_DEFAULT_MAXELEM,
hashsize=None):
'''
Create an ipset `name` of type `stype`, by default
`hash:ip`.
......@@ -103,13 +104,18 @@ class IPSet(NetlinkSocket):
cadt_flags |= IPSET_FLAG_WITH_COUNTERS
if comment:
cadt_flags |= IPSET_FLAG_WITH_COMMENT
data = {"attrs": [["IPSET_ATTR_CADT_FLAGS", cadt_flags],
["IPSET_ATTR_MAXELEM", maxelem]]}
if hashsize is not None:
data['attrs'] += [["IPSET_ATTR_HASHSIZE", hashsize]]
msg['attrs'] = [['IPSET_ATTR_PROTOCOL', self._proto_version],
['IPSET_ATTR_SETNAME', name],
['IPSET_ATTR_TYPENAME', stype],
['IPSET_ATTR_FAMILY', family],
['IPSET_ATTR_REVISION', self._attr_revision],
["IPSET_ATTR_DATA", {"attrs": [["IPSET_ATTR_CADT_FLAGS", cadt_flags],
["IPSET_ATTR_MAXELEM", maxelem]]}]]
["IPSET_ATTR_DATA", data]]
return self.request(msg, IPSET_CMD_CREATE,
msg_flags=NLM_F_REQUEST | NLM_F_ACK | excl_flag,
......
......@@ -73,7 +73,7 @@ class ipset_msg(nfgen_msg):
(10, 'IPSET_ATTR_MARK', 'hex'),
(11, 'IPSET_ATTR_MARKMASK', 'hex'),
(17, 'IPSET_ATTR_GC', 'hex'),
(18, 'IPSET_ATTR_HASHSIZE', 'be32'),
(18, 'IPSET_ATTR_HASHSIZE', 'be32', NLA_F_NET_BYTEORDER),
(19, 'IPSET_ATTR_MAXELEM', 'be32', NLA_F_NET_BYTEORDER),
(20, 'IPSET_ATTR_NETMASK', 'hex'),
(21, 'IPSET_ATTR_PROBES', 'hex'),
......
......@@ -172,3 +172,13 @@ class TestIPSet(object):
maxelem = data.get_attr("IPSET_ATTR_MAXELEM")
self.ip.destroy(name)
assert maxelem == 1
def test_hashsize(self):
require_user('root')
name = str(uuid4())[:16]
min_size = 64
self.ip.create(name, hashsize=min_size)
data = self.get_ipset(name)[0].get_attr("IPSET_ATTR_DATA")
hashsize = data.get_attr("IPSET_ATTR_HASHSIZE")
self.ip.destroy(name)
assert hashsize == min_size
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