From patchwork Tue Jan 7 18:56:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sam Liddicott X-Patchwork-Id: 307737 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id C8BEF2C00E4 for ; Wed, 8 Jan 2014 05:56:56 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750857AbaAGS4y (ORCPT ); Tue, 7 Jan 2014 13:56:54 -0500 Received: from mail-qa0-f49.google.com ([209.85.216.49]:45940 "EHLO mail-qa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750766AbaAGS4y (ORCPT ); Tue, 7 Jan 2014 13:56:54 -0500 Received: by mail-qa0-f49.google.com with SMTP id k4so910702qaq.8 for ; Tue, 07 Jan 2014 10:56:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=xooEVYPvt59pMKBHzndN2wxPU9a3TyFfzXIclqyapQY=; b=lX20N9kLikG0rKhd/8OIRjCes6LZHLaW5bifLrrr9mzrmBkED/RQImZMooPuQNlzaB WMnt5f3HntU+wkDRDKKupiG7yjefaMfe80FtaQxTA6199UGli+IA2Bhy1Xfafgw/giPh S0HHdZHXCMfzRGLpFfvBqrEWmEI+nsRvM0Au9/SAr7XKbJLkKC4XcTNWtE4nDM66NJgU bcx+SV3ZQloeuWsyIZqbxVq3sK36sGDQrbO97mLK61oDlsyL6m/WXydZ+0th8uEEI13X RYrzvimZbCDxq/1AJtCcASWceOT98I5h4aAlbGss7DWfboroDt49RyR9QiSh5SrfTifq AVAQ== X-Gm-Message-State: ALoCoQk4SKSVV1Sl+/03o3QzWKDp0PnBXc6rvv7E4csabfchnRtGx6mj3qILYp2NmZHFfS+9SdST MIME-Version: 1.0 X-Received: by 10.49.15.202 with SMTP id z10mr199837078qec.46.1389121013412; Tue, 07 Jan 2014 10:56:53 -0800 (PST) Received: by 10.224.88.10 with HTTP; Tue, 7 Jan 2014 10:56:53 -0800 (PST) Date: Tue, 7 Jan 2014 18:56:53 +0000 Message-ID: Subject: Patches to xtables-addons xt_quota2 From: Sam Liddicott To: netfilter-devel@vger.kernel.org Sender: netfilter-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netfilter-devel@vger.kernel.org 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 f456b9ebba6761e8b013f90f7c46ac814919311b Mon Sep 17 00:00:00 2001 From: Sam Liddicott 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 --- 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