blob: 14e3d858e04c1092cfff1865c40294e44da4919c [file] [log] [blame]
Luciano Coelho0902b462010-06-15 15:04:00 +02001/*
2 * linux/net/netfilter/xt_IDLETIMER.c
3 *
4 * Netfilter module to trigger a timer when packet matches.
5 * After timer expires a kevent will be sent.
6 *
7 * Copyright (C) 2004, 2010 Nokia Corporation
JP Abgrallcf7ad6a2012-04-26 23:28:35 -07008 *
Luciano Coelho0902b462010-06-15 15:04:00 +02009 * Written by Timo Teras <ext-timo.teras@nokia.com>
10 *
11 * Converted to x_tables and reworked for upstream inclusion
12 * by Luciano Coelho <luciano.coelho@nokia.com>
13 *
14 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
15 *
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * version 2 as published by the Free Software Foundation.
19 *
20 * This program is distributed in the hope that it will be useful, but
21 * WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 * 02110-1301 USA
29 */
30
31#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
32
33#include <linux/module.h>
34#include <linux/timer.h>
35#include <linux/list.h>
36#include <linux/mutex.h>
37#include <linux/netfilter.h>
38#include <linux/netfilter/x_tables.h>
39#include <linux/netfilter/xt_IDLETIMER.h>
Randy Dunlap600069d2010-06-22 08:13:31 +020040#include <linux/kdev_t.h>
Luciano Coelho0902b462010-06-15 15:04:00 +020041#include <linux/kobject.h>
JP Abgrallcf7ad6a2012-04-26 23:28:35 -070042#include <linux/skbuff.h>
Luciano Coelho0902b462010-06-15 15:04:00 +020043#include <linux/workqueue.h>
44#include <linux/sysfs.h>
Ruchi Kandoieb168432014-03-25 16:43:28 -070045#include <linux/rtc.h>
46#include <linux/time.h>
47#include <linux/math64.h>
48#include <linux/suspend.h>
49#include <linux/notifier.h>
JP Abgrallcf7ad6a2012-04-26 23:28:35 -070050#include <net/net_namespace.h>
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -070051#include <net/sock.h>
Subash Abhinov Kasiviswanathana711fa72016-11-02 11:56:40 -060052#include <net/inet_sock.h>
Luciano Coelho0902b462010-06-15 15:04:00 +020053
54struct idletimer_tg_attr {
55 struct attribute attr;
56 ssize_t (*show)(struct kobject *kobj,
57 struct attribute *attr, char *buf);
58};
59
60struct idletimer_tg {
61 struct list_head entry;
62 struct timer_list timer;
63 struct work_struct work;
64
65 struct kobject *kobj;
66 struct idletimer_tg_attr attr;
67
Ruchi Kandoieb168432014-03-25 16:43:28 -070068 struct timespec delayed_timer_trigger;
69 struct timespec last_modified_timer;
70 struct timespec last_suspend_time;
71 struct notifier_block pm_nb;
72
73 int timeout;
Luciano Coelho0902b462010-06-15 15:04:00 +020074 unsigned int refcnt;
Ruchi Kandoieb168432014-03-25 16:43:28 -070075 bool work_pending;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -070076 bool send_nl_msg;
77 bool active;
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -070078 uid_t uid;
Subash Abhinov Kasiviswanathan3a92d7b2017-07-12 14:51:08 -060079 bool suspend_time_valid;
Luciano Coelho0902b462010-06-15 15:04:00 +020080};
81
82static LIST_HEAD(idletimer_tg_list);
83static DEFINE_MUTEX(list_mutex);
Ruchi Kandoieb168432014-03-25 16:43:28 -070084static DEFINE_SPINLOCK(timestamp_lock);
Luciano Coelho0902b462010-06-15 15:04:00 +020085
86static struct kobject *idletimer_tg_kobj;
87
Ruchi Kandoieb168432014-03-25 16:43:28 -070088static bool check_for_delayed_trigger(struct idletimer_tg *timer,
89 struct timespec *ts)
90{
91 bool state;
92 struct timespec temp;
93 spin_lock_bh(&timestamp_lock);
94 timer->work_pending = false;
95 if ((ts->tv_sec - timer->last_modified_timer.tv_sec) > timer->timeout ||
96 timer->delayed_timer_trigger.tv_sec != 0) {
97 state = false;
98 temp.tv_sec = timer->timeout;
99 temp.tv_nsec = 0;
100 if (timer->delayed_timer_trigger.tv_sec != 0) {
101 temp = timespec_add(timer->delayed_timer_trigger, temp);
102 ts->tv_sec = temp.tv_sec;
103 ts->tv_nsec = temp.tv_nsec;
104 timer->delayed_timer_trigger.tv_sec = 0;
105 timer->work_pending = true;
106 schedule_work(&timer->work);
107 } else {
108 temp = timespec_add(timer->last_modified_timer, temp);
109 ts->tv_sec = temp.tv_sec;
110 ts->tv_nsec = temp.tv_nsec;
111 }
112 } else {
113 state = timer->active;
114 }
115 spin_unlock_bh(&timestamp_lock);
116 return state;
117}
118
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700119static void notify_netlink_uevent(const char *iface, struct idletimer_tg *timer)
120{
121 char iface_msg[NLMSG_MAX_SIZE];
122 char state_msg[NLMSG_MAX_SIZE];
Ruchi Kandoieb168432014-03-25 16:43:28 -0700123 char timestamp_msg[NLMSG_MAX_SIZE];
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700124 char uid_msg[NLMSG_MAX_SIZE];
125 char *envp[] = { iface_msg, state_msg, timestamp_msg, uid_msg, NULL };
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700126 int res;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700127 struct timespec ts;
128 uint64_t time_ns;
129 bool state;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700130
131 res = snprintf(iface_msg, NLMSG_MAX_SIZE, "INTERFACE=%s",
132 iface);
133 if (NLMSG_MAX_SIZE <= res) {
134 pr_err("message too long (%d)", res);
135 return;
136 }
Ruchi Kandoieb168432014-03-25 16:43:28 -0700137
138 get_monotonic_boottime(&ts);
139 state = check_for_delayed_trigger(timer, &ts);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700140 res = snprintf(state_msg, NLMSG_MAX_SIZE, "STATE=%s",
Ruchi Kandoieb168432014-03-25 16:43:28 -0700141 state ? "active" : "inactive");
142
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700143 if (NLMSG_MAX_SIZE <= res) {
144 pr_err("message too long (%d)", res);
145 return;
146 }
Ruchi Kandoieb168432014-03-25 16:43:28 -0700147
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700148 if (state) {
149 res = snprintf(uid_msg, NLMSG_MAX_SIZE, "UID=%u", timer->uid);
150 if (NLMSG_MAX_SIZE <= res)
151 pr_err("message too long (%d)", res);
152 } else {
153 res = snprintf(uid_msg, NLMSG_MAX_SIZE, "UID=");
154 if (NLMSG_MAX_SIZE <= res)
155 pr_err("message too long (%d)", res);
156 }
157
Ruchi Kandoieb168432014-03-25 16:43:28 -0700158 time_ns = timespec_to_ns(&ts);
159 res = snprintf(timestamp_msg, NLMSG_MAX_SIZE, "TIME_NS=%llu", time_ns);
160 if (NLMSG_MAX_SIZE <= res) {
161 timestamp_msg[0] = '\0';
162 pr_err("message too long (%d)", res);
163 }
164
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700165 pr_debug("putting nlmsg: <%s> <%s> <%s> <%s>\n", iface_msg, state_msg,
166 timestamp_msg, uid_msg);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700167 kobject_uevent_env(idletimer_tg_kobj, KOBJ_CHANGE, envp);
168 return;
169
170
171}
172
Luciano Coelho0902b462010-06-15 15:04:00 +0200173static
174struct idletimer_tg *__idletimer_tg_find_by_label(const char *label)
175{
176 struct idletimer_tg *entry;
177
178 BUG_ON(!label);
179
180 list_for_each_entry(entry, &idletimer_tg_list, entry) {
181 if (!strcmp(label, entry->attr.attr.name))
182 return entry;
183 }
184
185 return NULL;
186}
187
188static ssize_t idletimer_tg_show(struct kobject *kobj, struct attribute *attr,
189 char *buf)
190{
191 struct idletimer_tg *timer;
192 unsigned long expires = 0;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700193 unsigned long now = jiffies;
Luciano Coelho0902b462010-06-15 15:04:00 +0200194
195 mutex_lock(&list_mutex);
196
197 timer = __idletimer_tg_find_by_label(attr->name);
198 if (timer)
199 expires = timer->timer.expires;
200
201 mutex_unlock(&list_mutex);
202
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700203 if (time_after(expires, now))
Luciano Coelho0902b462010-06-15 15:04:00 +0200204 return sprintf(buf, "%u\n",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700205 jiffies_to_msecs(expires - now) / 1000);
Luciano Coelho0902b462010-06-15 15:04:00 +0200206
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700207 if (timer->send_nl_msg)
208 return sprintf(buf, "0 %d\n",
209 jiffies_to_msecs(now - expires) / 1000);
210 else
211 return sprintf(buf, "0\n");
Luciano Coelho0902b462010-06-15 15:04:00 +0200212}
213
214static void idletimer_tg_work(struct work_struct *work)
215{
216 struct idletimer_tg *timer = container_of(work, struct idletimer_tg,
217 work);
218
219 sysfs_notify(idletimer_tg_kobj, NULL, timer->attr.attr.name);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700220
221 if (timer->send_nl_msg)
222 notify_netlink_uevent(timer->attr.attr.name, timer);
Luciano Coelho0902b462010-06-15 15:04:00 +0200223}
224
225static void idletimer_tg_expired(unsigned long data)
226{
227 struct idletimer_tg *timer = (struct idletimer_tg *) data;
228
229 pr_debug("timer %s expired\n", timer->attr.attr.name);
Ruchi Kandoieb168432014-03-25 16:43:28 -0700230 spin_lock_bh(&timestamp_lock);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700231 timer->active = false;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700232 timer->work_pending = true;
Luciano Coelho0902b462010-06-15 15:04:00 +0200233 schedule_work(&timer->work);
Ruchi Kandoieb168432014-03-25 16:43:28 -0700234 spin_unlock_bh(&timestamp_lock);
235}
236
237static int idletimer_resume(struct notifier_block *notifier,
238 unsigned long pm_event, void *unused)
239{
240 struct timespec ts;
241 unsigned long time_diff, now = jiffies;
242 struct idletimer_tg *timer = container_of(notifier,
243 struct idletimer_tg, pm_nb);
244 if (!timer)
245 return NOTIFY_DONE;
246 switch (pm_event) {
247 case PM_SUSPEND_PREPARE:
248 get_monotonic_boottime(&timer->last_suspend_time);
Subash Abhinov Kasiviswanathan3a92d7b2017-07-12 14:51:08 -0600249 timer->suspend_time_valid = true;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700250 break;
251 case PM_POST_SUSPEND:
Subash Abhinov Kasiviswanathan3a92d7b2017-07-12 14:51:08 -0600252 if (!timer->suspend_time_valid)
253 break;
254 timer->suspend_time_valid = false;
255
Ruchi Kandoieb168432014-03-25 16:43:28 -0700256 spin_lock_bh(&timestamp_lock);
257 if (!timer->active) {
258 spin_unlock_bh(&timestamp_lock);
259 break;
260 }
261 /* since jiffies are not updated when suspended now represents
262 * the time it would have suspended */
263 if (time_after(timer->timer.expires, now)) {
264 get_monotonic_boottime(&ts);
265 ts = timespec_sub(ts, timer->last_suspend_time);
266 time_diff = timespec_to_jiffies(&ts);
267 if (timer->timer.expires > (time_diff + now)) {
268 mod_timer_pending(&timer->timer,
269 (timer->timer.expires - time_diff));
270 } else {
271 del_timer(&timer->timer);
272 timer->timer.expires = 0;
273 timer->active = false;
274 timer->work_pending = true;
275 schedule_work(&timer->work);
276 }
277 }
278 spin_unlock_bh(&timestamp_lock);
279 break;
280 default:
281 break;
282 }
283 return NOTIFY_DONE;
Luciano Coelho0902b462010-06-15 15:04:00 +0200284}
285
286static int idletimer_tg_create(struct idletimer_tg_info *info)
287{
288 int ret;
289
Subash Abhinov Kasiviswanathan3a92d7b2017-07-12 14:51:08 -0600290 info->timer = kzalloc(sizeof(*info->timer), GFP_KERNEL);
Luciano Coelho0902b462010-06-15 15:04:00 +0200291 if (!info->timer) {
Luciano Coelho0902b462010-06-15 15:04:00 +0200292 ret = -ENOMEM;
293 goto out;
294 }
295
Dmitry Torokhov484836e2015-07-09 17:15:01 -0700296 sysfs_attr_init(&info->timer->attr.attr);
Luciano Coelho0902b462010-06-15 15:04:00 +0200297 info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL);
298 if (!info->timer->attr.attr.name) {
Luciano Coelho0902b462010-06-15 15:04:00 +0200299 ret = -ENOMEM;
300 goto out_free_timer;
301 }
302 info->timer->attr.attr.mode = S_IRUGO;
303 info->timer->attr.show = idletimer_tg_show;
304
305 ret = sysfs_create_file(idletimer_tg_kobj, &info->timer->attr.attr);
306 if (ret < 0) {
307 pr_debug("couldn't add file to sysfs");
308 goto out_free_attr;
309 }
Devi Sandeep Endluri V V3d6aa172017-06-05 16:34:11 +0530310 /* notify userspace */
311 kobject_uevent(idletimer_tg_kobj, KOBJ_ADD);
Luciano Coelho0902b462010-06-15 15:04:00 +0200312
313 list_add(&info->timer->entry, &idletimer_tg_list);
314
315 setup_timer(&info->timer->timer, idletimer_tg_expired,
316 (unsigned long) info->timer);
317 info->timer->refcnt = 1;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700318 info->timer->send_nl_msg = (info->send_nl_msg == 0) ? false : true;
319 info->timer->active = true;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700320 info->timer->timeout = info->timeout;
321
322 info->timer->delayed_timer_trigger.tv_sec = 0;
323 info->timer->delayed_timer_trigger.tv_nsec = 0;
324 info->timer->work_pending = false;
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700325 info->timer->uid = 0;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700326 get_monotonic_boottime(&info->timer->last_modified_timer);
327
328 info->timer->pm_nb.notifier_call = idletimer_resume;
329 ret = register_pm_notifier(&info->timer->pm_nb);
330 if (ret)
331 printk(KERN_WARNING "[%s] Failed to register pm notifier %d\n",
332 __func__, ret);
Luciano Coelho0902b462010-06-15 15:04:00 +0200333
334 mod_timer(&info->timer->timer,
335 msecs_to_jiffies(info->timeout * 1000) + jiffies);
336
337 INIT_WORK(&info->timer->work, idletimer_tg_work);
338
339 return 0;
340
341out_free_attr:
342 kfree(info->timer->attr.attr.name);
343out_free_timer:
344 kfree(info->timer);
345out:
346 return ret;
347}
348
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700349static void reset_timer(const struct idletimer_tg_info *info,
350 struct sk_buff *skb)
Ruchi Kandoieb168432014-03-25 16:43:28 -0700351{
352 unsigned long now = jiffies;
353 struct idletimer_tg *timer = info->timer;
354 bool timer_prev;
355
356 spin_lock_bh(&timestamp_lock);
357 timer_prev = timer->active;
358 timer->active = true;
359 /* timer_prev is used to guard overflow problem in time_before*/
360 if (!timer_prev || time_before(timer->timer.expires, now)) {
361 pr_debug("Starting Checkentry timer (Expired, Jiffies): %lu, %lu\n",
362 timer->timer.expires, now);
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700363
364 /* Stores the uid resposible for waking up the radio */
365 if (skb && (skb->sk)) {
Amit Pundir22ea73de2015-05-11 14:39:59 +0530366 timer->uid = from_kuid_munged(current_user_ns(),
Subash Abhinov Kasiviswanathana711fa72016-11-02 11:56:40 -0600367 sock_i_uid(skb_to_full_sk(skb)));
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700368 }
369
Ruchi Kandoieb168432014-03-25 16:43:28 -0700370 /* checks if there is a pending inactive notification*/
371 if (timer->work_pending)
372 timer->delayed_timer_trigger = timer->last_modified_timer;
373 else {
374 timer->work_pending = true;
375 schedule_work(&timer->work);
376 }
377 }
378
379 get_monotonic_boottime(&timer->last_modified_timer);
380 mod_timer(&timer->timer,
381 msecs_to_jiffies(info->timeout * 1000) + now);
382 spin_unlock_bh(&timestamp_lock);
383}
384
Luciano Coelho0902b462010-06-15 15:04:00 +0200385/*
386 * The actual xt_tables plugin.
387 */
388static unsigned int idletimer_tg_target(struct sk_buff *skb,
389 const struct xt_action_param *par)
390{
391 const struct idletimer_tg_info *info = par->targinfo;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700392 unsigned long now = jiffies;
Luciano Coelho0902b462010-06-15 15:04:00 +0200393
394 pr_debug("resetting timer %s, timeout period %u\n",
395 info->label, info->timeout);
396
397 BUG_ON(!info->timer);
398
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700399 info->timer->active = true;
400
401 if (time_before(info->timer->timer.expires, now)) {
402 schedule_work(&info->timer->work);
403 pr_debug("Starting timer %s (Expired, Jiffies): %lu, %lu\n",
404 info->label, info->timer->timer.expires, now);
405 }
406
407 /* TODO: Avoid modifying timers on each packet */
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700408 reset_timer(info, skb);
Luciano Coelho0902b462010-06-15 15:04:00 +0200409 return XT_CONTINUE;
410}
411
412static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
413{
414 struct idletimer_tg_info *info = par->targinfo;
415 int ret;
416
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700417 pr_debug("checkentry targinfo %s\n", info->label);
Luciano Coelho0902b462010-06-15 15:04:00 +0200418
419 if (info->timeout == 0) {
420 pr_debug("timeout value is zero\n");
421 return -EINVAL;
422 }
423
424 if (info->label[0] == '\0' ||
425 strnlen(info->label,
426 MAX_IDLETIMER_LABEL_SIZE) == MAX_IDLETIMER_LABEL_SIZE) {
427 pr_debug("label is empty or not nul-terminated\n");
428 return -EINVAL;
429 }
430
431 mutex_lock(&list_mutex);
432
433 info->timer = __idletimer_tg_find_by_label(info->label);
434 if (info->timer) {
435 info->timer->refcnt++;
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700436 reset_timer(info, NULL);
Luciano Coelho0902b462010-06-15 15:04:00 +0200437 pr_debug("increased refcnt of timer %s to %u\n",
438 info->label, info->timer->refcnt);
439 } else {
440 ret = idletimer_tg_create(info);
441 if (ret < 0) {
442 pr_debug("failed to create timer\n");
443 mutex_unlock(&list_mutex);
444 return ret;
445 }
446 }
447
448 mutex_unlock(&list_mutex);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700449
Luciano Coelho0902b462010-06-15 15:04:00 +0200450 return 0;
451}
452
453static void idletimer_tg_destroy(const struct xt_tgdtor_param *par)
454{
455 const struct idletimer_tg_info *info = par->targinfo;
456
457 pr_debug("destroy targinfo %s\n", info->label);
458
459 mutex_lock(&list_mutex);
460
461 if (--info->timer->refcnt == 0) {
462 pr_debug("deleting timer %s\n", info->label);
463
464 list_del(&info->timer->entry);
465 del_timer_sync(&info->timer->timer);
466 sysfs_remove_file(idletimer_tg_kobj, &info->timer->attr.attr);
Ruchi Kandoieb168432014-03-25 16:43:28 -0700467 unregister_pm_notifier(&info->timer->pm_nb);
Subash Abhinov Kasiviswanathan7b1124302016-11-10 19:36:15 -0700468 cancel_work_sync(&info->timer->work);
Luciano Coelho0902b462010-06-15 15:04:00 +0200469 kfree(info->timer->attr.attr.name);
470 kfree(info->timer);
471 } else {
472 pr_debug("decreased refcnt of timer %s to %u\n",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700473 info->label, info->timer->refcnt);
Luciano Coelho0902b462010-06-15 15:04:00 +0200474 }
475
476 mutex_unlock(&list_mutex);
477}
478
479static struct xt_target idletimer_tg __read_mostly = {
480 .name = "IDLETIMER",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700481 .revision = 1,
Luciano Coelho0902b462010-06-15 15:04:00 +0200482 .family = NFPROTO_UNSPEC,
483 .target = idletimer_tg_target,
484 .targetsize = sizeof(struct idletimer_tg_info),
485 .checkentry = idletimer_tg_checkentry,
486 .destroy = idletimer_tg_destroy,
487 .me = THIS_MODULE,
488};
489
490static struct class *idletimer_tg_class;
491
492static struct device *idletimer_tg_device;
493
494static int __init idletimer_tg_init(void)
495{
496 int err;
497
498 idletimer_tg_class = class_create(THIS_MODULE, "xt_idletimer");
499 err = PTR_ERR(idletimer_tg_class);
500 if (IS_ERR(idletimer_tg_class)) {
501 pr_debug("couldn't register device class\n");
502 goto out;
503 }
504
505 idletimer_tg_device = device_create(idletimer_tg_class, NULL,
506 MKDEV(0, 0), NULL, "timers");
507 err = PTR_ERR(idletimer_tg_device);
508 if (IS_ERR(idletimer_tg_device)) {
509 pr_debug("couldn't register system device\n");
510 goto out_class;
511 }
512
513 idletimer_tg_kobj = &idletimer_tg_device->kobj;
514
515 err = xt_register_target(&idletimer_tg);
516 if (err < 0) {
517 pr_debug("couldn't register xt target\n");
518 goto out_dev;
519 }
520
521 return 0;
522out_dev:
523 device_destroy(idletimer_tg_class, MKDEV(0, 0));
524out_class:
525 class_destroy(idletimer_tg_class);
526out:
527 return err;
528}
529
530static void __exit idletimer_tg_exit(void)
531{
532 xt_unregister_target(&idletimer_tg);
533
534 device_destroy(idletimer_tg_class, MKDEV(0, 0));
535 class_destroy(idletimer_tg_class);
536}
537
538module_init(idletimer_tg_init);
539module_exit(idletimer_tg_exit);
540
541MODULE_AUTHOR("Timo Teras <ext-timo.teras@nokia.com>");
542MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
543MODULE_DESCRIPTION("Xtables: idle time monitor");
544MODULE_LICENSE("GPL v2");
Jan Engelhardtf1e231a2011-01-18 06:30:13 +0100545MODULE_ALIAS("ipt_IDLETIMER");
546MODULE_ALIAS("ip6t_IDLETIMER");
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700547MODULE_ALIAS("arpt_IDLETIMER");