Re: [PATCH] netfilter: Xtables: idletimer target implementation

Previous thread: [PATCH 2/2] pktgen: receive packets and process incoming rate by Daniel Turull on Wednesday, June 2, 2010 - 4:49 am. (6 messages)

Next thread: sysfs class/net/ problem by Johannes Berg on Wednesday, June 2, 2010 - 6:16 am. (58 messages)
From: Luciano Coelho
Date: Wednesday, June 2, 2010 - 4:58 am

This patch implements an idletimer Xtables target that can be used to
identify when interfaces have been idle for a certain period of time.

Timers are identified by labels and are created when a rule is set with a new
label.  The rules also take a timeout value (in seconds) as an option.  If
more than one rule uses the same timer label, the timer will be restarted
whenever any of the rules get a hit.

One entry for each timer is created in sysfs.  This attribute contains the
timer remaining for the timer to expire.  The attributes are located under
the module's object:

/sys/module/xt_IDLETIMER/idletimer/<label>

When the timer expires, the target module sends a sysfs notification to the
userspace, which can then decide what to do (eg. disconnect to save power).

Cc: Timo Teras <timo.teras@iki.fi>
Signed-off-by: Luciano Coelho <luciano.coelho@nokia.com>
---
 include/linux/netfilter/xt_IDLETIMER.h |   40 ++++
 net/netfilter/Kconfig                  |   11 +
 net/netfilter/Makefile                 |    1 +
 net/netfilter/xt_IDLETIMER.c           |  347 ++++++++++++++++++++++++++++++++
 4 files changed, 399 insertions(+), 0 deletions(-)
 create mode 100644 include/linux/netfilter/xt_IDLETIMER.h
 create mode 100644 net/netfilter/xt_IDLETIMER.c

diff --git a/include/linux/netfilter/xt_IDLETIMER.h b/include/linux/netfilter/xt_IDLETIMER.h
new file mode 100644
index 0000000..5958b31
--- /dev/null
+++ b/include/linux/netfilter/xt_IDLETIMER.h
@@ -0,0 +1,40 @@
+/*
+ * linux/include/linux/netfilter/xt_IDLETIMER.h
+ *
+ * Header file for Xtables timer target module.
+ *
+ * Copyright (C) 2004, 2010 Nokia Corporation
+ * Written by Timo Teras <ext-timo.teras@nokia.com>
+ *
+ * Converted to x_tables and forward-ported to 2.6.34
+ * by Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * Contact: Luciano Coelho <luciano.coelho@nokia.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * ...
From: Jan Engelhardt
Date: Wednesday, June 2, 2010 - 5:54 am

I have only ever seen interfaces in /sys/class/net, so it might be
wise to keep it that way in light of scripts doing 
echo /sys/class/net/*  to get a list of interfaces.


Looks quite ok.
--

From: Luciano Coelho
Date: Wednesday, June 2, 2010 - 6:37 am

Hi Jan,

Thanks for your prompt review! I'll send v2 with the fixes you
suggested.






Oops! Fixed in v2.  Also added sysfs_remove_file_from_group() if the


Yeps, this is a remain from the previous (and ugly) read from ipt_ip.

Yes, this is the only reason why I haven't put it under the net class,
which would probably look cleaner.  In other classes it seems to be
common to add misc attributes, but the net class (as of now) only
contains interface subclasses, as you said.


Thanks!


-- 
Cheers,
Luca.

--

Previous thread: [PATCH 2/2] pktgen: receive packets and process incoming rate by Daniel Turull on Wednesday, June 2, 2010 - 4:49 am. (6 messages)

Next thread: sysfs class/net/ problem by Johannes Berg on Wednesday, June 2, 2010 - 6:16 am. (58 messages)