netfilter: xtables: Add snapshot of hardidletimer target
Subsystems (3)
PATCH 1/1 netfilter: xtables: Add snapshot of hardidletimer target
This is a snapshot of hardifletimer netfilter target as of msm-4.4 commit 469a150b7426 ("netfilter: xtables: hardidletimer target implementation")
This patch implements a hardidletimer 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 xt_idletimer class:
/sys/class/xt_hardidletimer/timers/<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)
Compared to xt_IDLETIMER, xt_HARDIDLETIMER can send notifications when CPU is in suspend too, to notify the timer expiry.
CRs-Fixed: 1078373
--- .../uapi/linux/netfilter/xt_HARDIDLETIMER.h | 51 +++ net/netfilter/Kconfig | 14 + net/netfilter/Makefile | 1 + net/netfilter/xt_HARDIDLETIMER.c | 381 ++++++++++++++++++ net/netfilter/xt_IDLETIMER.c | 2 + 5 files changed, 449 insertions(+) create mode 100644 include/uapi/linux/netfilter/xt_HARDIDLETIMER.h create mode 100644 net/netfilter/xt_HARDIDLETIMER.c
include/uapi/linux/netfilter/xt_HARDIDLETIMER.h new file +51 -0
@@ -0,0 +1,51 @@ +/* +* linux/include/linux/netfilter/xt_HARDIDLETIMER.h +* +* Header file for Xtables timer target module. +* +* Copyright (c) 2014, 2017 The Linux Foundation. All rights reserved. +* +* Copyright (C) 2004, 2010 Nokia Corporation +* +* Written by Timo Teras <[email protected]> +* +* Converted to x_tables and forward-ported to 2.6.34 +* by Luciano Coelho <[email protected]> +* +* Contact: Luciano Coelho <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, but +* WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* General Public License for more details. +* +*/ + +#ifndef _XT_HARDIDLETIMER_H +#define _XT_HARDIDLETIMER_H + +#include <linux/types.h> + +#define MAX_HARDIDLETIMER_LABEL_SIZE 28 +#define NLMSG_MAX_SIZE 64 + +#define NL_EVENT_TYPE_INACTIVE 0 +#define NL_EVENT_TYPE_ACTIVE 1 + +struct hardidletimer_tg_info { +__u32 timeout; + +char label[MAX_HARDIDLETIMER_LABEL_SIZE ]; + +/* Use netlink messages for notification in addition to sysfs */ +__u8 send_nl_msg; + +/* for kernel module internal use only */ +struct hardidletimer_tg *timer __attribute__((aligned (8 ))); +}; + +#endif
net/netfilter/Kconfig +14 -0
@@ -893,6 +893,20 @@ config NETFILTER_XT_TARGET_IDLETIMER To compile it as a module, choose M here. If unsure, say N. +config NETFILTER_XT_TARGET_HARDIDLETIMER + tristate "HARDIDLETIMER target support" + depends on NETFILTER_ADVANCED + help + + This option adds the `HARDIDLETIMER' target. Each matching packet + resets the timer associated with label specified when the rule is + added. When the timer expires, it triggers a sysfs notification. + The remaining time for expiration can be read via sysfs. + Compared to IDLETIMER HARDIDLETIMER will send notification when + CPU in suspend too. + + To compile it as a module, choose M here. If unsure, say N. + config NETFILTER_XT_TARGET_LED tristate '"LED" target support' depends on LEDS_CLASS && LEDS_TRIGGERS
net/netfilter/Makefile +1 -0
@@ -157,6 +157,7 @@ obj-$(CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP) += xt_TCPOPTSTRIP.o obj-$(CONFIG_NETFILTER_XT_TARGET_TEE) += xt_TEE.o obj-$(CONFIG_NETFILTER_XT_TARGET_TRACE) += xt_TRACE.o obj-$(CONFIG_NETFILTER_XT_TARGET_IDLETIMER) += xt_IDLETIMER.o +obj-$(CONFIG_NETFILTER_XT_TARGET_HARDIDLETIMER) += xt_HARDIDLETIMER.o # matches obj-$(CONFIG_NETFILTER_XT_MATCH_ADDRTYPE) += xt_addrtype.o
net/netfilter/xt_HARDIDLETIMER.c new file +381 -0
381 lines not on this page · raw message
net/netfilter/xt_IDLETIMER.c +2 -0
@@ -139,6 +139,8 @@ static int idletimer_tg_create(struct idletimer_tg_info *info)pr_debug ("couldn't add file to sysfs" ); goto out_free_attr; } +/* notify userspace */ +kobject_uevent (idletimer_tg_kobj,KOBJ_ADD );list_add (&info->timer->entry, &idletimer_tg_list);
Signature · 1 line
2.23.0