blob: 44c42a7fa7bc28f292bd26f76e117c0f26c293a6 [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;
Luciano Coelho0902b462010-06-15 15:04:00 +020079};
80
81static LIST_HEAD(idletimer_tg_list);
82static DEFINE_MUTEX(list_mutex);
Ruchi Kandoieb168432014-03-25 16:43:28 -070083static DEFINE_SPINLOCK(timestamp_lock);
Luciano Coelho0902b462010-06-15 15:04:00 +020084
85static struct kobject *idletimer_tg_kobj;
86
Ruchi Kandoieb168432014-03-25 16:43:28 -070087static bool check_for_delayed_trigger(struct idletimer_tg *timer,
88 struct timespec *ts)
89{
90 bool state;
91 struct timespec temp;
92 spin_lock_bh(&timestamp_lock);
93 timer->work_pending = false;
94 if ((ts->tv_sec - timer->last_modified_timer.tv_sec) > timer->timeout ||
95 timer->delayed_timer_trigger.tv_sec != 0) {
96 state = false;
97 temp.tv_sec = timer->timeout;
98 temp.tv_nsec = 0;
99 if (timer->delayed_timer_trigger.tv_sec != 0) {
100 temp = timespec_add(timer->delayed_timer_trigger, temp);
101 ts->tv_sec = temp.tv_sec;
102 ts->tv_nsec = temp.tv_nsec;
103 timer->delayed_timer_trigger.tv_sec = 0;
104 timer->work_pending = true;
105 schedule_work(&timer->work);
106 } else {
107 temp = timespec_add(timer->last_modified_timer, temp);
108 ts->tv_sec = temp.tv_sec;
109 ts->tv_nsec = temp.tv_nsec;
110 }
111 } else {
112 state = timer->active;
113 }
114 spin_unlock_bh(&timestamp_lock);
115 return state;
116}
117
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700118static void notify_netlink_uevent(const char *iface, struct idletimer_tg *timer)
119{
120 char iface_msg[NLMSG_MAX_SIZE];
121 char state_msg[NLMSG_MAX_SIZE];
Ruchi Kandoieb168432014-03-25 16:43:28 -0700122 char timestamp_msg[NLMSG_MAX_SIZE];
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700123 char uid_msg[NLMSG_MAX_SIZE];
124 char *envp[] = { iface_msg, state_msg, timestamp_msg, uid_msg, NULL };
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700125 int res;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700126 struct timespec ts;
127 uint64_t time_ns;
128 bool state;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700129
130 res = snprintf(iface_msg, NLMSG_MAX_SIZE, "INTERFACE=%s",
131 iface);
132 if (NLMSG_MAX_SIZE <= res) {
133 pr_err("message too long (%d)", res);
134 return;
135 }
Ruchi Kandoieb168432014-03-25 16:43:28 -0700136
137 get_monotonic_boottime(&ts);
138 state = check_for_delayed_trigger(timer, &ts);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700139 res = snprintf(state_msg, NLMSG_MAX_SIZE, "STATE=%s",
Ruchi Kandoieb168432014-03-25 16:43:28 -0700140 state ? "active" : "inactive");
141
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700142 if (NLMSG_MAX_SIZE <= res) {
143 pr_err("message too long (%d)", res);
144 return;
145 }
Ruchi Kandoieb168432014-03-25 16:43:28 -0700146
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700147 if (state) {
148 res = snprintf(uid_msg, NLMSG_MAX_SIZE, "UID=%u", timer->uid);
149 if (NLMSG_MAX_SIZE <= res)
150 pr_err("message too long (%d)", res);
151 } else {
152 res = snprintf(uid_msg, NLMSG_MAX_SIZE, "UID=");
153 if (NLMSG_MAX_SIZE <= res)
154 pr_err("message too long (%d)", res);
155 }
156
Ruchi Kandoieb168432014-03-25 16:43:28 -0700157 time_ns = timespec_to_ns(&ts);
158 res = snprintf(timestamp_msg, NLMSG_MAX_SIZE, "TIME_NS=%llu", time_ns);
159 if (NLMSG_MAX_SIZE <= res) {
160 timestamp_msg[0] = '\0';
161 pr_err("message too long (%d)", res);
162 }
163
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700164 pr_debug("putting nlmsg: <%s> <%s> <%s> <%s>\n", iface_msg, state_msg,
165 timestamp_msg, uid_msg);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700166 kobject_uevent_env(idletimer_tg_kobj, KOBJ_CHANGE, envp);
167 return;
168
169
170}
171
Luciano Coelho0902b462010-06-15 15:04:00 +0200172static
173struct idletimer_tg *__idletimer_tg_find_by_label(const char *label)
174{
175 struct idletimer_tg *entry;
176
177 BUG_ON(!label);
178
179 list_for_each_entry(entry, &idletimer_tg_list, entry) {
180 if (!strcmp(label, entry->attr.attr.name))
181 return entry;
182 }
183
184 return NULL;
185}
186
187static ssize_t idletimer_tg_show(struct kobject *kobj, struct attribute *attr,
188 char *buf)
189{
190 struct idletimer_tg *timer;
191 unsigned long expires = 0;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700192 unsigned long now = jiffies;
Luciano Coelho0902b462010-06-15 15:04:00 +0200193
194 mutex_lock(&list_mutex);
195
196 timer = __idletimer_tg_find_by_label(attr->name);
197 if (timer)
198 expires = timer->timer.expires;
199
200 mutex_unlock(&list_mutex);
201
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700202 if (time_after(expires, now))
Luciano Coelho0902b462010-06-15 15:04:00 +0200203 return sprintf(buf, "%u\n",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700204 jiffies_to_msecs(expires - now) / 1000);
Luciano Coelho0902b462010-06-15 15:04:00 +0200205
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700206 if (timer->send_nl_msg)
207 return sprintf(buf, "0 %d\n",
208 jiffies_to_msecs(now - expires) / 1000);
209 else
210 return sprintf(buf, "0\n");
Luciano Coelho0902b462010-06-15 15:04:00 +0200211}
212
213static void idletimer_tg_work(struct work_struct *work)
214{
215 struct idletimer_tg *timer = container_of(work, struct idletimer_tg,
216 work);
217
218 sysfs_notify(idletimer_tg_kobj, NULL, timer->attr.attr.name);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700219
220 if (timer->send_nl_msg)
221 notify_netlink_uevent(timer->attr.attr.name, timer);
Luciano Coelho0902b462010-06-15 15:04:00 +0200222}
223
224static void idletimer_tg_expired(unsigned long data)
225{
226 struct idletimer_tg *timer = (struct idletimer_tg *) data;
227
228 pr_debug("timer %s expired\n", timer->attr.attr.name);
Ruchi Kandoieb168432014-03-25 16:43:28 -0700229 spin_lock_bh(&timestamp_lock);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700230 timer->active = false;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700231 timer->work_pending = true;
Luciano Coelho0902b462010-06-15 15:04:00 +0200232 schedule_work(&timer->work);
Ruchi Kandoieb168432014-03-25 16:43:28 -0700233 spin_unlock_bh(&timestamp_lock);
234}
235
236static int idletimer_resume(struct notifier_block *notifier,
237 unsigned long pm_event, void *unused)
238{
239 struct timespec ts;
240 unsigned long time_diff, now = jiffies;
241 struct idletimer_tg *timer = container_of(notifier,
242 struct idletimer_tg, pm_nb);
243 if (!timer)
244 return NOTIFY_DONE;
245 switch (pm_event) {
246 case PM_SUSPEND_PREPARE:
247 get_monotonic_boottime(&timer->last_suspend_time);
248 break;
249 case PM_POST_SUSPEND:
250 spin_lock_bh(&timestamp_lock);
251 if (!timer->active) {
252 spin_unlock_bh(&timestamp_lock);
253 break;
254 }
255 /* since jiffies are not updated when suspended now represents
256 * the time it would have suspended */
257 if (time_after(timer->timer.expires, now)) {
258 get_monotonic_boottime(&ts);
259 ts = timespec_sub(ts, timer->last_suspend_time);
260 time_diff = timespec_to_jiffies(&ts);
261 if (timer->timer.expires > (time_diff + now)) {
262 mod_timer_pending(&timer->timer,
263 (timer->timer.expires - time_diff));
264 } else {
265 del_timer(&timer->timer);
266 timer->timer.expires = 0;
267 timer->active = false;
268 timer->work_pending = true;
269 schedule_work(&timer->work);
270 }
271 }
272 spin_unlock_bh(&timestamp_lock);
273 break;
274 default:
275 break;
276 }
277 return NOTIFY_DONE;
Luciano Coelho0902b462010-06-15 15:04:00 +0200278}
279
Taehee Yoof184d302018-10-21 00:00:08 +0900280static int idletimer_check_sysfs_name(const char *name, unsigned int size)
281{
282 int ret;
283
284 ret = xt_check_proc_name(name, size);
285 if (ret < 0)
286 return ret;
287
288 if (!strcmp(name, "power") ||
289 !strcmp(name, "subsystem") ||
290 !strcmp(name, "uevent"))
291 return -EINVAL;
292
293 return 0;
294}
295
Luciano Coelho0902b462010-06-15 15:04:00 +0200296static int idletimer_tg_create(struct idletimer_tg_info *info)
297{
298 int ret;
299
300 info->timer = kmalloc(sizeof(*info->timer), GFP_KERNEL);
301 if (!info->timer) {
Luciano Coelho0902b462010-06-15 15:04:00 +0200302 ret = -ENOMEM;
303 goto out;
304 }
305
Taehee Yoof184d302018-10-21 00:00:08 +0900306 ret = idletimer_check_sysfs_name(info->label, sizeof(info->label));
307 if (ret < 0)
308 goto out_free_timer;
309
Dmitry Torokhov484836e2015-07-09 17:15:01 -0700310 sysfs_attr_init(&info->timer->attr.attr);
Luciano Coelho0902b462010-06-15 15:04:00 +0200311 info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL);
312 if (!info->timer->attr.attr.name) {
Luciano Coelho0902b462010-06-15 15:04:00 +0200313 ret = -ENOMEM;
314 goto out_free_timer;
315 }
316 info->timer->attr.attr.mode = S_IRUGO;
317 info->timer->attr.show = idletimer_tg_show;
318
319 ret = sysfs_create_file(idletimer_tg_kobj, &info->timer->attr.attr);
320 if (ret < 0) {
321 pr_debug("couldn't add file to sysfs");
322 goto out_free_attr;
323 }
324
325 list_add(&info->timer->entry, &idletimer_tg_list);
326
327 setup_timer(&info->timer->timer, idletimer_tg_expired,
328 (unsigned long) info->timer);
329 info->timer->refcnt = 1;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700330 info->timer->send_nl_msg = (info->send_nl_msg == 0) ? false : true;
331 info->timer->active = true;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700332 info->timer->timeout = info->timeout;
333
334 info->timer->delayed_timer_trigger.tv_sec = 0;
335 info->timer->delayed_timer_trigger.tv_nsec = 0;
336 info->timer->work_pending = false;
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700337 info->timer->uid = 0;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700338 get_monotonic_boottime(&info->timer->last_modified_timer);
339
340 info->timer->pm_nb.notifier_call = idletimer_resume;
341 ret = register_pm_notifier(&info->timer->pm_nb);
342 if (ret)
343 printk(KERN_WARNING "[%s] Failed to register pm notifier %d\n",
344 __func__, ret);
Luciano Coelho0902b462010-06-15 15:04:00 +0200345
Eric Dumazet034ad9d2018-02-16 19:36:28 -0800346 INIT_WORK(&info->timer->work, idletimer_tg_work);
347
Luciano Coelho0902b462010-06-15 15:04:00 +0200348 mod_timer(&info->timer->timer,
349 msecs_to_jiffies(info->timeout * 1000) + jiffies);
350
Luciano Coelho0902b462010-06-15 15:04:00 +0200351 return 0;
352
353out_free_attr:
354 kfree(info->timer->attr.attr.name);
355out_free_timer:
356 kfree(info->timer);
357out:
358 return ret;
359}
360
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700361static void reset_timer(const struct idletimer_tg_info *info,
362 struct sk_buff *skb)
Ruchi Kandoieb168432014-03-25 16:43:28 -0700363{
364 unsigned long now = jiffies;
365 struct idletimer_tg *timer = info->timer;
366 bool timer_prev;
367
368 spin_lock_bh(&timestamp_lock);
369 timer_prev = timer->active;
370 timer->active = true;
371 /* timer_prev is used to guard overflow problem in time_before*/
372 if (!timer_prev || time_before(timer->timer.expires, now)) {
373 pr_debug("Starting Checkentry timer (Expired, Jiffies): %lu, %lu\n",
374 timer->timer.expires, now);
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700375
376 /* Stores the uid resposible for waking up the radio */
377 if (skb && (skb->sk)) {
Amit Pundir22ea73de2015-05-11 14:39:59 +0530378 timer->uid = from_kuid_munged(current_user_ns(),
Subash Abhinov Kasiviswanathana711fa72016-11-02 11:56:40 -0600379 sock_i_uid(skb_to_full_sk(skb)));
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700380 }
381
Ruchi Kandoieb168432014-03-25 16:43:28 -0700382 /* checks if there is a pending inactive notification*/
383 if (timer->work_pending)
384 timer->delayed_timer_trigger = timer->last_modified_timer;
385 else {
386 timer->work_pending = true;
387 schedule_work(&timer->work);
388 }
389 }
390
391 get_monotonic_boottime(&timer->last_modified_timer);
392 mod_timer(&timer->timer,
393 msecs_to_jiffies(info->timeout * 1000) + now);
394 spin_unlock_bh(&timestamp_lock);
395}
396
Luciano Coelho0902b462010-06-15 15:04:00 +0200397/*
398 * The actual xt_tables plugin.
399 */
400static unsigned int idletimer_tg_target(struct sk_buff *skb,
401 const struct xt_action_param *par)
402{
403 const struct idletimer_tg_info *info = par->targinfo;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700404 unsigned long now = jiffies;
Luciano Coelho0902b462010-06-15 15:04:00 +0200405
406 pr_debug("resetting timer %s, timeout period %u\n",
407 info->label, info->timeout);
408
409 BUG_ON(!info->timer);
410
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700411 info->timer->active = true;
412
413 if (time_before(info->timer->timer.expires, now)) {
414 schedule_work(&info->timer->work);
415 pr_debug("Starting timer %s (Expired, Jiffies): %lu, %lu\n",
416 info->label, info->timer->timer.expires, now);
417 }
418
419 /* TODO: Avoid modifying timers on each packet */
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700420 reset_timer(info, skb);
Luciano Coelho0902b462010-06-15 15:04:00 +0200421 return XT_CONTINUE;
422}
423
424static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
425{
426 struct idletimer_tg_info *info = par->targinfo;
427 int ret;
428
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700429 pr_debug("checkentry targinfo %s\n", info->label);
Luciano Coelho0902b462010-06-15 15:04:00 +0200430
431 if (info->timeout == 0) {
432 pr_debug("timeout value is zero\n");
433 return -EINVAL;
434 }
Eric Dumazet034ad9d2018-02-16 19:36:28 -0800435 if (info->timeout >= INT_MAX / 1000) {
436 pr_debug("timeout value is too big\n");
437 return -EINVAL;
438 }
Luciano Coelho0902b462010-06-15 15:04:00 +0200439 if (info->label[0] == '\0' ||
440 strnlen(info->label,
441 MAX_IDLETIMER_LABEL_SIZE) == MAX_IDLETIMER_LABEL_SIZE) {
442 pr_debug("label is empty or not nul-terminated\n");
443 return -EINVAL;
444 }
445
446 mutex_lock(&list_mutex);
447
448 info->timer = __idletimer_tg_find_by_label(info->label);
449 if (info->timer) {
450 info->timer->refcnt++;
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700451 reset_timer(info, NULL);
Luciano Coelho0902b462010-06-15 15:04:00 +0200452 pr_debug("increased refcnt of timer %s to %u\n",
453 info->label, info->timer->refcnt);
454 } else {
455 ret = idletimer_tg_create(info);
456 if (ret < 0) {
457 pr_debug("failed to create timer\n");
458 mutex_unlock(&list_mutex);
459 return ret;
460 }
461 }
462
463 mutex_unlock(&list_mutex);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700464
Luciano Coelho0902b462010-06-15 15:04:00 +0200465 return 0;
466}
467
468static void idletimer_tg_destroy(const struct xt_tgdtor_param *par)
469{
470 const struct idletimer_tg_info *info = par->targinfo;
471
472 pr_debug("destroy targinfo %s\n", info->label);
473
474 mutex_lock(&list_mutex);
475
476 if (--info->timer->refcnt == 0) {
477 pr_debug("deleting timer %s\n", info->label);
478
479 list_del(&info->timer->entry);
480 del_timer_sync(&info->timer->timer);
481 sysfs_remove_file(idletimer_tg_kobj, &info->timer->attr.attr);
Ruchi Kandoieb168432014-03-25 16:43:28 -0700482 unregister_pm_notifier(&info->timer->pm_nb);
Subash Abhinov Kasiviswanathan7b1124302016-11-10 19:36:15 -0700483 cancel_work_sync(&info->timer->work);
Luciano Coelho0902b462010-06-15 15:04:00 +0200484 kfree(info->timer->attr.attr.name);
485 kfree(info->timer);
486 } else {
487 pr_debug("decreased refcnt of timer %s to %u\n",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700488 info->label, info->timer->refcnt);
Luciano Coelho0902b462010-06-15 15:04:00 +0200489 }
490
491 mutex_unlock(&list_mutex);
492}
493
494static struct xt_target idletimer_tg __read_mostly = {
495 .name = "IDLETIMER",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700496 .revision = 1,
Luciano Coelho0902b462010-06-15 15:04:00 +0200497 .family = NFPROTO_UNSPEC,
498 .target = idletimer_tg_target,
499 .targetsize = sizeof(struct idletimer_tg_info),
500 .checkentry = idletimer_tg_checkentry,
501 .destroy = idletimer_tg_destroy,
502 .me = THIS_MODULE,
503};
504
505static struct class *idletimer_tg_class;
506
507static struct device *idletimer_tg_device;
508
509static int __init idletimer_tg_init(void)
510{
511 int err;
512
513 idletimer_tg_class = class_create(THIS_MODULE, "xt_idletimer");
514 err = PTR_ERR(idletimer_tg_class);
515 if (IS_ERR(idletimer_tg_class)) {
516 pr_debug("couldn't register device class\n");
517 goto out;
518 }
519
520 idletimer_tg_device = device_create(idletimer_tg_class, NULL,
521 MKDEV(0, 0), NULL, "timers");
522 err = PTR_ERR(idletimer_tg_device);
523 if (IS_ERR(idletimer_tg_device)) {
524 pr_debug("couldn't register system device\n");
525 goto out_class;
526 }
527
528 idletimer_tg_kobj = &idletimer_tg_device->kobj;
529
530 err = xt_register_target(&idletimer_tg);
531 if (err < 0) {
532 pr_debug("couldn't register xt target\n");
533 goto out_dev;
534 }
535
536 return 0;
537out_dev:
538 device_destroy(idletimer_tg_class, MKDEV(0, 0));
539out_class:
540 class_destroy(idletimer_tg_class);
541out:
542 return err;
543}
544
545static void __exit idletimer_tg_exit(void)
546{
547 xt_unregister_target(&idletimer_tg);
548
549 device_destroy(idletimer_tg_class, MKDEV(0, 0));
550 class_destroy(idletimer_tg_class);
551}
552
553module_init(idletimer_tg_init);
554module_exit(idletimer_tg_exit);
555
556MODULE_AUTHOR("Timo Teras <ext-timo.teras@nokia.com>");
557MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
558MODULE_DESCRIPTION("Xtables: idle time monitor");
559MODULE_LICENSE("GPL v2");
Jan Engelhardtf1e231a2011-01-18 06:30:13 +0100560MODULE_ALIAS("ipt_IDLETIMER");
561MODULE_ALIAS("ip6t_IDLETIMER");
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700562MODULE_ALIAS("arpt_IDLETIMER");