30 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32 #include <linux/module.h>
34 #include <linux/list.h>
36 #include <linux/netfilter.h>
37 #include <linux/netfilter/x_tables.h>
39 #include <linux/kdev_t.h>
64 static struct kobject *idletimer_tg_kobj;
85 unsigned long expires = 0;
89 timer = __idletimer_tg_find_by_label(attr->
name);
91 expires = timer->
timer.expires;
110 static void idletimer_tg_expired(
unsigned long data)
130 if (!info->timer->attr.attr.name) {
134 info->timer->attr.attr.mode =
S_IRUGO;
135 info->timer->attr.show = idletimer_tg_show;
139 pr_debug(
"couldn't add file to sysfs");
143 list_add(&info->timer->entry, &idletimer_tg_list);
145 setup_timer(&info->timer->timer, idletimer_tg_expired,
146 (
unsigned long) info->timer);
147 info->timer->refcnt = 1;
152 INIT_WORK(&info->timer->work, idletimer_tg_work);
157 kfree(info->timer->attr.attr.name);
167 static unsigned int idletimer_tg_target(
struct sk_buff *
skb,
172 pr_debug(
"resetting timer %s, timeout period %u\n",
183 static int idletimer_tg_checkentry(
const struct xt_tgchk_param *par)
191 pr_debug(
"timeout value is zero\n");
195 if (info->
label[0] ==
'\0' ||
198 pr_debug(
"label is empty or not nul-terminated\n");
204 info->timer = __idletimer_tg_find_by_label(info->
label);
206 info->timer->refcnt++;
210 pr_debug(
"increased refcnt of timer %s to %u\n",
211 info->
label, info->timer->refcnt);
213 ret = idletimer_tg_create(info);
215 pr_debug(
"failed to create timer\n");
233 if (--info->timer->refcnt == 0) {
239 kfree(info->timer->attr.attr.name);
242 pr_debug(
"decreased refcnt of timer %s to %u\n",
243 info->
label, info->timer->refcnt);
252 .target = idletimer_tg_target,
254 .checkentry = idletimer_tg_checkentry,
255 .destroy = idletimer_tg_destroy,
259 static struct class *idletimer_tg_class;
261 static struct device *idletimer_tg_device;
263 static int __init idletimer_tg_init(
void)
268 err = PTR_ERR(idletimer_tg_class);
269 if (IS_ERR(idletimer_tg_class)) {
270 pr_debug(
"couldn't register device class\n");
276 err = PTR_ERR(idletimer_tg_device);
277 if (IS_ERR(idletimer_tg_device)) {
278 pr_debug(
"couldn't register system device\n");
282 idletimer_tg_kobj = &idletimer_tg_device->
kobj;
286 pr_debug(
"couldn't register xt target\n");
299 static void __exit idletimer_tg_exit(
void)