Message ID | CAOj-5WAsU-WxdKbP1ijmhRGAO=u204ZyGM5PZNcrsJoOB1hsug@mail.gmail.com |
---|---|
State | Awaiting Upstream |
Headers | show |
Because of a diversion in my private tree patch 3 did not compile due to missing include directive. I'm doing a merge request via sourceforge for one that does. Sam On Tue, Jan 7, 2014 at 6:56 PM, Sam Liddicott <sam@liddicott.com> wrote: > 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 -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tuesday 2014-01-07 19:56, Sam Liddicott wrote: >[0003] >@@ -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; Because @input is copied to @buf and that is size-limited, a string like " +-123" would be recognizd as -12 rather than -123. So, don't bother with spaces at all. -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
True, it doesn't fix all problems. I don't mind if you strip that part before applying. Sam On Thu, Jan 9, 2014 at 9:07 AM, Jan Engelhardt <jengelh@inai.de> wrote: > > On Tuesday 2014-01-07 19:56, Sam Liddicott wrote: >>[0003] >>@@ -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; > > Because @input is copied to @buf and that is size-limited, a string like > " +-123" > would be recognizd as -12 rather than -123. So, don't bother with > spaces at all. -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Thursday 2014-01-09 14:35, Sam Liddicott wrote: >True, it doesn't fix all problems. I don't mind if you strip that part >before applying. Something better, I let you respin #3 :) -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Fri, Jan 10, 2014 at 4:44 PM, Jan Engelhardt <jengelh@inai.de> wrote: > On Thursday 2014-01-09 14:35, Sam Liddicott wrote: > >>True, it doesn't fix all problems. I don't mind if you strip that part >>before applying. > > Something better, I let you respin #3 :) > OK, I will... I didn't like fixed block reading anyway. I'll see if there is a normal nice way for "stdio" parsing in the kernel or make a basic one. Sam -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
From f456b9ebba6761e8b013f90f7c46ac814919311b Mon Sep 17 00:00:00 2001 From: Sam Liddicott <sam@liddicott.com> 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@liddicott.com> --- 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