Patches to xtables-addons xt_quota2

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



0001,0002 fix bugs, 0003 adds new feature of incremental changes to quota files.

They apply to HEAD of xtables-addons on sourceforge

These patches should be self explanatory but may need some review as I
have tried to preserve existing style rather than refactor but you may
prefer to refactor. There was also some confusion on locking in the
increment support patch and I'm not sure if I have it right.

Sam
From e72465d66814b9c4ac7de7ed5c273fbefd91d551 Mon Sep 17 00:00:00 2001
From: Sam Liddicott <sam@xxxxxxxxxxxxx>
Date: Tue, 7 Jan 2014 09:21:53 -0800
Subject: [PATCH 2/3] Remove trailing junk which MIGHT have a digit in it!


Signed-off-by: Sam Liddicott <sam@xxxxxxxxxxxxx>
---
 extensions/xt_quota2.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/extensions/xt_quota2.c b/extensions/xt_quota2.c
index aa00207..f1b64d0 100644
--- a/extensions/xt_quota2.c
+++ b/extensions/xt_quota2.c
@@ -76,6 +76,8 @@ quota_proc_write(struct file *file, const char __user *input,
 	if (copy_from_user(buf, input, size) != 0)
 		return -EFAULT;
 	buf[sizeof(buf)-1] = '\0';
+	if (size < sizeof(buf))
+		buf[size]=0;
 
 	spin_lock_bh(&e->lock);
 	e->quota = simple_strtoull(buf, NULL, 0);
-- 
1.8.1.2

From 5a79867843306db9fec9fb423c09a2b2b0101483 Mon Sep 17 00:00:00 2001
From: Sam Liddicott <sam@xxxxxxxxxxxxx>
Date: Tue, 7 Jan 2014 09:11:07 -0800
Subject: [PATCH 1/3] Fix 2 bugs when not in grow mode

1. XT_QUOTA_NO_CHANGE should not alter quota to zero ever
2. XT_QUOTA_PACKET should not be set to zero based on skb->len

Signed-off-by: Sam Liddicott <sam@xxxxxxxxxxxxx>
---
 extensions/xt_quota2.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/extensions/xt_quota2.c b/extensions/xt_quota2.c
index ff91fcb..aa00207 100644
--- a/extensions/xt_quota2.c
+++ b/extensions/xt_quota2.c
@@ -219,13 +219,14 @@ quota_mt2(const struct sk_buff *skb, struct xt_action_param *par)
 		}
 		ret = true;
 	} else {
-		if (e->quota >= skb->len) {
+		if (e->quota >= ((q->flags & XT_QUOTA_PACKET) ? 1 : skb->len)) {
 			if (!(q->flags & XT_QUOTA_NO_CHANGE))
 				e->quota -= (q->flags & XT_QUOTA_PACKET) ? 1 : skb->len;
 			ret = !ret;
 		} else {
 			/* we do not allow even small packets from now on */
-			e->quota = 0;
+			if (!(q->flags & XT_QUOTA_NO_CHANGE))
+				e->quota = 0;
 		}
 		q->quota = e->quota;
 	}
-- 
1.8.1.2

From f456b9ebba6761e8b013f90f7c46ac814919311b Mon Sep 17 00:00:00 2001
From: Sam Liddicott <sam@xxxxxxxxxxxxx>
Date: Tue, 7 Jan 2014 09:48:19 -0800
Subject: [PATCH 3/3] Allow incremental value to be written to quota proc file

As well as writing absolute numeric values to the quota file you
can also write numbers preceded by a + sign or a - sign
e.g.
  +30
would increase the quota by 30
  +-20
would increase the quota by negative 20 which is the same as decrease
by 20

  -5
would decrease the quota by 5

Signed-off-by: Sam Liddicott <sam@xxxxxxxxxxxxx>
---
 extensions/xt_quota2.c | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/extensions/xt_quota2.c b/extensions/xt_quota2.c
index f1b64d0..1711260 100644
--- a/extensions/xt_quota2.c
+++ b/extensions/xt_quota2.c
@@ -69,7 +69,8 @@ quota_proc_write(struct file *file, const char __user *input,
                  size_t size, loff_t *loff)
 {
 	struct xt_quota_counter *e = PDE_DATA(file_inode(file));
-	char buf[sizeof("18446744073709551616")];
+	char buf[sizeof("+-18446744073709551616")];
+	char *c = buf;
 
 	if (size > sizeof(buf))
 		size = sizeof(buf);
@@ -79,9 +80,35 @@ quota_proc_write(struct file *file, const char __user *input,
 	if (size < sizeof(buf))
 		buf[size]=0;
 
-	spin_lock_bh(&e->lock);
-	e->quota = simple_strtoull(buf, NULL, 0);
-	spin_unlock_bh(&e->lock);
+	while (isspace(*c))
+		c++;
+
+	if (size - (c - buf) < 1) /* min string length */
+		return c - buf;
+
+	if (*c == '+') { printk(KERN_ERR "+++\n");
+		int64_t temp = simple_strtoll(c+1, NULL, 0);
+		spin_lock_bh(&e->lock);
+		/* Don't let quota become negative if tmp is very negative */
+		if (temp > 0 || -temp < e->quota)
+			e->quota += temp;
+		else
+			e->quota = 0;
+		spin_unlock_bh(&e->lock);
+	} else if (*c == '-') { printk(KERN_ERR "---\n");
+		int64_t temp = simple_strtoll(c+1, NULL, 0);
+		spin_lock_bh(&e->lock);
+		/* Don't let quota become negative if tmp is very big */
+		if (temp < 0 || temp < e->quota)
+			e->quota -= temp;
+		else
+			e->quota = 0;
+		spin_unlock_bh(&e->lock);
+	} else { printk(KERN_ERR "===\n");
+		spin_lock_bh(&e->lock);
+		e->quota = simple_strtoull(buf, NULL, 0);
+		spin_unlock_bh(&e->lock);
+	}
 	return size;
 }
 
-- 
1.8.1.2


[Index of Archives]     [Netfitler Users]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux