Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 5416219e authored by Jozsef Kadlecsik's avatar Jozsef Kadlecsik Committed by Patrick McHardy
Browse files

netfilter: ipset: timeout can be modified for already added elements



When an element to a set with timeout added, one can change the timeout
by "readding" the element with the "-exist" flag. That means the timeout
value is reset to the specified one (or to the default from the set
specification if the "timeout n" option is not used). Example

ipset add foo 1.2.3.4 timeout 10
ipset add foo 1.2.3.4 timeout 600 -exist

Signed-off-by: default avatarJozsef Kadlecsik <kadlec@blackhole.kfki.hu>
Signed-off-by: default avatarPatrick McHardy <kaber@trash.net>
parent 619c1517
Loading
Loading
Loading
Loading
+2 −1
Original line number Original line Diff line number Diff line
@@ -214,7 +214,8 @@ enum ip_set_feature {


struct ip_set;
struct ip_set;


typedef int (*ipset_adtfn)(struct ip_set *set, void *value, u32 timeout);
typedef int (*ipset_adtfn)(struct ip_set *set, void *value,
			   u32 timeout, u32 flags);


/* Set type, variant-specific part */
/* Set type, variant-specific part */
struct ip_set_type_variant {
struct ip_set_type_variant {
+8 −7
Original line number Original line Diff line number Diff line
@@ -349,7 +349,7 @@ type_pf_resize(struct ip_set *set, bool retried)
/* Add an element to a hash and update the internal counters when succeeded,
/* Add an element to a hash and update the internal counters when succeeded,
 * otherwise report the proper error code. */
 * otherwise report the proper error code. */
static int
static int
type_pf_add(struct ip_set *set, void *value, u32 timeout)
type_pf_add(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct ip_set_hash *h = set->data;
	struct ip_set_hash *h = set->data;
	struct htable *t;
	struct htable *t;
@@ -388,7 +388,7 @@ type_pf_add(struct ip_set *set, void *value, u32 timeout)
 * and free up space if possible.
 * and free up space if possible.
 */
 */
static int
static int
type_pf_del(struct ip_set *set, void *value, u32 timeout)
type_pf_del(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct ip_set_hash *h = set->data;
	struct ip_set_hash *h = set->data;
	struct htable *t = h->table;
	struct htable *t = h->table;
@@ -463,7 +463,7 @@ type_pf_test_cidrs(struct ip_set *set, struct type_pf_elem *d, u32 timeout)


/* Test whether the element is added to the set */
/* Test whether the element is added to the set */
static int
static int
type_pf_test(struct ip_set *set, void *value, u32 timeout)
type_pf_test(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct ip_set_hash *h = set->data;
	struct ip_set_hash *h = set->data;
	struct htable *t = h->table;
	struct htable *t = h->table;
@@ -776,7 +776,7 @@ type_pf_tresize(struct ip_set *set, bool retried)
}
}


static int
static int
type_pf_tadd(struct ip_set *set, void *value, u32 timeout)
type_pf_tadd(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct ip_set_hash *h = set->data;
	struct ip_set_hash *h = set->data;
	struct htable *t = h->table;
	struct htable *t = h->table;
@@ -784,6 +784,7 @@ type_pf_tadd(struct ip_set *set, void *value, u32 timeout)
	struct hbucket *n;
	struct hbucket *n;
	struct type_pf_elem *data;
	struct type_pf_elem *data;
	int ret = 0, i, j = AHASH_MAX_SIZE + 1;
	int ret = 0, i, j = AHASH_MAX_SIZE + 1;
	bool flag_exist = flags & IPSET_FLAG_EXIST;
	u32 key;
	u32 key;


	if (h->elements >= h->maxelem)
	if (h->elements >= h->maxelem)
@@ -799,7 +800,7 @@ type_pf_tadd(struct ip_set *set, void *value, u32 timeout)
	for (i = 0; i < n->pos; i++) {
	for (i = 0; i < n->pos; i++) {
		data = ahash_tdata(n, i);
		data = ahash_tdata(n, i);
		if (type_pf_data_equal(data, d)) {
		if (type_pf_data_equal(data, d)) {
			if (type_pf_data_expired(data))
			if (type_pf_data_expired(data) || flag_exist)
				j = i;
				j = i;
			else {
			else {
				ret = -IPSET_ERR_EXIST;
				ret = -IPSET_ERR_EXIST;
@@ -833,7 +834,7 @@ type_pf_tadd(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
type_pf_tdel(struct ip_set *set, void *value, u32 timeout)
type_pf_tdel(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct ip_set_hash *h = set->data;
	struct ip_set_hash *h = set->data;
	struct htable *t = h->table;
	struct htable *t = h->table;
@@ -905,7 +906,7 @@ type_pf_ttest_cidrs(struct ip_set *set, struct type_pf_elem *d, u32 timeout)
#endif
#endif


static int
static int
type_pf_ttest(struct ip_set *set, void *value, u32 timeout)
type_pf_ttest(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct ip_set_hash *h = set->data;
	struct ip_set_hash *h = set->data;
	struct htable *t = h->table;
	struct htable *t = h->table;
+10 −10
Original line number Original line Diff line number Diff line
@@ -54,7 +54,7 @@ ip_to_id(const struct bitmap_ip *m, u32 ip)
}
}


static int
static int
bitmap_ip_test(struct ip_set *set, void *value, u32 timeout)
bitmap_ip_test(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	const struct bitmap_ip *map = set->data;
	const struct bitmap_ip *map = set->data;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;
@@ -63,7 +63,7 @@ bitmap_ip_test(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ip_add(struct ip_set *set, void *value, u32 timeout)
bitmap_ip_add(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ip *map = set->data;
	struct bitmap_ip *map = set->data;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;
@@ -75,7 +75,7 @@ bitmap_ip_add(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ip_del(struct ip_set *set, void *value, u32 timeout)
bitmap_ip_del(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ip *map = set->data;
	struct bitmap_ip *map = set->data;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;
@@ -131,7 +131,7 @@ bitmap_ip_list(const struct ip_set *set,
/* Timeout variant */
/* Timeout variant */


static int
static int
bitmap_ip_ttest(struct ip_set *set, void *value, u32 timeout)
bitmap_ip_ttest(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	const struct bitmap_ip *map = set->data;
	const struct bitmap_ip *map = set->data;
	const unsigned long *members = map->members;
	const unsigned long *members = map->members;
@@ -141,13 +141,13 @@ bitmap_ip_ttest(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ip_tadd(struct ip_set *set, void *value, u32 timeout)
bitmap_ip_tadd(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ip *map = set->data;
	struct bitmap_ip *map = set->data;
	unsigned long *members = map->members;
	unsigned long *members = map->members;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;


	if (ip_set_timeout_test(members[id]))
	if (ip_set_timeout_test(members[id]) && !(flags & IPSET_FLAG_EXIST))
		return -IPSET_ERR_EXIST;
		return -IPSET_ERR_EXIST;


	members[id] = ip_set_timeout_set(timeout);
	members[id] = ip_set_timeout_set(timeout);
@@ -156,7 +156,7 @@ bitmap_ip_tadd(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ip_tdel(struct ip_set *set, void *value, u32 timeout)
bitmap_ip_tdel(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ip *map = set->data;
	struct bitmap_ip *map = set->data;
	unsigned long *members = map->members;
	unsigned long *members = map->members;
@@ -231,7 +231,7 @@ bitmap_ip_kadt(struct ip_set *set, const struct sk_buff *skb,


	ip = ip_to_id(map, ip);
	ip = ip_to_id(map, ip);


	return adtfn(set, &ip, map->timeout);
	return adtfn(set, &ip, map->timeout, flags);
}
}


static int
static int
@@ -266,7 +266,7 @@ bitmap_ip_uadt(struct ip_set *set, struct nlattr *tb[],


	if (adt == IPSET_TEST) {
	if (adt == IPSET_TEST) {
		id = ip_to_id(map, ip);
		id = ip_to_id(map, ip);
		return adtfn(set, &id, timeout);
		return adtfn(set, &id, timeout, flags);
	}
	}


	if (tb[IPSET_ATTR_IP_TO]) {
	if (tb[IPSET_ATTR_IP_TO]) {
@@ -293,7 +293,7 @@ bitmap_ip_uadt(struct ip_set *set, struct nlattr *tb[],


	for (; !before(ip_to, ip); ip += map->hosts) {
	for (; !before(ip_to, ip); ip += map->hosts) {
		id = ip_to_id(map, ip);
		id = ip_to_id(map, ip);
		ret = adtfn(set, &id, timeout);
		ret = adtfn(set, &id, timeout, flags);


		if (ret && !ip_set_eexist(ret, flags))
		if (ret && !ip_set_eexist(ret, flags))
			return ret;
			return ret;
+11 −10
Original line number Original line Diff line number Diff line
@@ -99,7 +99,7 @@ bitmap_ipmac_exist(const struct ipmac_telem *elem)
/* Base variant */
/* Base variant */


static int
static int
bitmap_ipmac_test(struct ip_set *set, void *value, u32 timeout)
bitmap_ipmac_test(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	const struct bitmap_ipmac *map = set->data;
	const struct bitmap_ipmac *map = set->data;
	const struct ipmac *data = value;
	const struct ipmac *data = value;
@@ -117,7 +117,7 @@ bitmap_ipmac_test(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ipmac_add(struct ip_set *set, void *value, u32 timeout)
bitmap_ipmac_add(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ipmac *map = set->data;
	struct bitmap_ipmac *map = set->data;
	const struct ipmac *data = value;
	const struct ipmac *data = value;
@@ -146,7 +146,7 @@ bitmap_ipmac_add(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ipmac_del(struct ip_set *set, void *value, u32 timeout)
bitmap_ipmac_del(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ipmac *map = set->data;
	struct bitmap_ipmac *map = set->data;
	const struct ipmac *data = value;
	const struct ipmac *data = value;
@@ -212,7 +212,7 @@ bitmap_ipmac_list(const struct ip_set *set,
/* Timeout variant */
/* Timeout variant */


static int
static int
bitmap_ipmac_ttest(struct ip_set *set, void *value, u32 timeout)
bitmap_ipmac_ttest(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	const struct bitmap_ipmac *map = set->data;
	const struct bitmap_ipmac *map = set->data;
	const struct ipmac *data = value;
	const struct ipmac *data = value;
@@ -231,15 +231,16 @@ bitmap_ipmac_ttest(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ipmac_tadd(struct ip_set *set, void *value, u32 timeout)
bitmap_ipmac_tadd(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ipmac *map = set->data;
	struct bitmap_ipmac *map = set->data;
	const struct ipmac *data = value;
	const struct ipmac *data = value;
	struct ipmac_telem *elem = bitmap_ipmac_elem(map, data->id);
	struct ipmac_telem *elem = bitmap_ipmac_elem(map, data->id);
	bool flag_exist = flags & IPSET_FLAG_EXIST;


	switch (elem->match) {
	switch (elem->match) {
	case MAC_UNSET:
	case MAC_UNSET:
		if (!data->ether)
		if (!(data->ether || flag_exist))
			/* Already added without ethernet address */
			/* Already added without ethernet address */
			return -IPSET_ERR_EXIST;
			return -IPSET_ERR_EXIST;
		/* Fill the MAC address and activate the timer */
		/* Fill the MAC address and activate the timer */
@@ -251,7 +252,7 @@ bitmap_ipmac_tadd(struct ip_set *set, void *value, u32 timeout)
		elem->timeout = ip_set_timeout_set(timeout);
		elem->timeout = ip_set_timeout_set(timeout);
		break;
		break;
	case MAC_FILLED:
	case MAC_FILLED:
		if (!bitmap_expired(map, data->id))
		if (!(bitmap_expired(map, data->id) || flag_exist))
			return -IPSET_ERR_EXIST;
			return -IPSET_ERR_EXIST;
		/* Fall through */
		/* Fall through */
	case MAC_EMPTY:
	case MAC_EMPTY:
@@ -273,7 +274,7 @@ bitmap_ipmac_tadd(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_ipmac_tdel(struct ip_set *set, void *value, u32 timeout)
bitmap_ipmac_tdel(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_ipmac *map = set->data;
	struct bitmap_ipmac *map = set->data;
	const struct ipmac *data = value;
	const struct ipmac *data = value;
@@ -359,7 +360,7 @@ bitmap_ipmac_kadt(struct ip_set *set, const struct sk_buff *skb,
	data.id -= map->first_ip;
	data.id -= map->first_ip;
	data.ether = eth_hdr(skb)->h_source;
	data.ether = eth_hdr(skb)->h_source;


	return adtfn(set, &data, map->timeout);
	return adtfn(set, &data, map->timeout, flags);
}
}


static int
static int
@@ -399,7 +400,7 @@ bitmap_ipmac_uadt(struct ip_set *set, struct nlattr *tb[],


	data.id -= map->first_ip;
	data.id -= map->first_ip;


	ret = adtfn(set, &data, timeout);
	ret = adtfn(set, &data, timeout, flags);


	return ip_set_eexist(ret, flags) ? 0 : ret;
	return ip_set_eexist(ret, flags) ? 0 : ret;
}
}
+10 −10
Original line number Original line Diff line number Diff line
@@ -40,7 +40,7 @@ struct bitmap_port {
/* Base variant */
/* Base variant */


static int
static int
bitmap_port_test(struct ip_set *set, void *value, u32 timeout)
bitmap_port_test(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	const struct bitmap_port *map = set->data;
	const struct bitmap_port *map = set->data;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;
@@ -49,7 +49,7 @@ bitmap_port_test(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_port_add(struct ip_set *set, void *value, u32 timeout)
bitmap_port_add(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_port *map = set->data;
	struct bitmap_port *map = set->data;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;
@@ -61,7 +61,7 @@ bitmap_port_add(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_port_del(struct ip_set *set, void *value, u32 timeout)
bitmap_port_del(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_port *map = set->data;
	struct bitmap_port *map = set->data;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;
@@ -119,7 +119,7 @@ bitmap_port_list(const struct ip_set *set,
/* Timeout variant */
/* Timeout variant */


static int
static int
bitmap_port_ttest(struct ip_set *set, void *value, u32 timeout)
bitmap_port_ttest(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	const struct bitmap_port *map = set->data;
	const struct bitmap_port *map = set->data;
	const unsigned long *members = map->members;
	const unsigned long *members = map->members;
@@ -129,13 +129,13 @@ bitmap_port_ttest(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_port_tadd(struct ip_set *set, void *value, u32 timeout)
bitmap_port_tadd(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_port *map = set->data;
	struct bitmap_port *map = set->data;
	unsigned long *members = map->members;
	unsigned long *members = map->members;
	u16 id = *(u16 *)value;
	u16 id = *(u16 *)value;


	if (ip_set_timeout_test(members[id]))
	if (ip_set_timeout_test(members[id]) && !(flags & IPSET_FLAG_EXIST))
		return -IPSET_ERR_EXIST;
		return -IPSET_ERR_EXIST;


	members[id] = ip_set_timeout_set(timeout);
	members[id] = ip_set_timeout_set(timeout);
@@ -144,7 +144,7 @@ bitmap_port_tadd(struct ip_set *set, void *value, u32 timeout)
}
}


static int
static int
bitmap_port_tdel(struct ip_set *set, void *value, u32 timeout)
bitmap_port_tdel(struct ip_set *set, void *value, u32 timeout, u32 flags)
{
{
	struct bitmap_port *map = set->data;
	struct bitmap_port *map = set->data;
	unsigned long *members = map->members;
	unsigned long *members = map->members;
@@ -225,7 +225,7 @@ bitmap_port_kadt(struct ip_set *set, const struct sk_buff *skb,


	port -= map->first_port;
	port -= map->first_port;


	return adtfn(set, &port, map->timeout);
	return adtfn(set, &port, map->timeout, flags);
}
}


static int
static int
@@ -259,7 +259,7 @@ bitmap_port_uadt(struct ip_set *set, struct nlattr *tb[],


	if (adt == IPSET_TEST) {
	if (adt == IPSET_TEST) {
		id = port - map->first_port;
		id = port - map->first_port;
		return adtfn(set, &id, timeout);
		return adtfn(set, &id, timeout, flags);
	}
	}


	if (tb[IPSET_ATTR_PORT_TO]) {
	if (tb[IPSET_ATTR_PORT_TO]) {
@@ -277,7 +277,7 @@ bitmap_port_uadt(struct ip_set *set, struct nlattr *tb[],


	for (; port <= port_to; port++) {
	for (; port <= port_to; port++) {
		id = port - map->first_port;
		id = port - map->first_port;
		ret = adtfn(set, &id, timeout);
		ret = adtfn(set, &id, timeout, flags);


		if (ret && !ip_set_eexist(ret, flags))
		if (ret && !ip_set_eexist(ret, flags))
			return ret;
			return ret;
Loading