blob: 736cd0f150e69309dc441a91385b00642884d5ad [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
Taehee Yoof184d302018-10-21 00:00:08 +0900286static int idletimer_check_sysfs_name(const char *name, unsigned int size)
287{
288 int ret;
289
290 ret = xt_check_proc_name(name, size);
291 if (ret < 0)
292 return ret;
293
294 if (!strcmp(name, "power") ||
295 !strcmp(name, "subsystem") ||
296 !strcmp(name, "uevent"))
297 return -EINVAL;
298
299 return 0;
300}
301
Luciano Coelho0902b462010-06-15 15:04:00 +0200302static int idletimer_tg_create(struct idletimer_tg_info *info)
303{
304 int ret;
305
Subash Abhinov Kasiviswanathan3a92d7b2017-07-12 14:51:08 -0600306 info->timer = kzalloc(sizeof(*info->timer), GFP_KERNEL);
Luciano Coelho0902b462010-06-15 15:04:00 +0200307 if (!info->timer) {
Luciano Coelho0902b462010-06-15 15:04:00 +0200308 ret = -ENOMEM;
309 goto out;
310 }
311
Taehee Yoof184d302018-10-21 00:00:08 +0900312 ret = idletimer_check_sysfs_name(info->label, sizeof(info->label));
313 if (ret < 0)
314 goto out_free_timer;
315
Dmitry Torokhov484836e2015-07-09 17:15:01 -0700316 sysfs_attr_init(&info->timer->attr.attr);
Luciano Coelho0902b462010-06-15 15:04:00 +0200317 info->timer->attr.attr.name = kstrdup(info->label, GFP_KERNEL);
318 if (!info->timer->attr.attr.name) {
Luciano Coelho0902b462010-06-15 15:04:00 +0200319 ret = -ENOMEM;
320 goto out_free_timer;
321 }
322 info->timer->attr.attr.mode = S_IRUGO;
323 info->timer->attr.show = idletimer_tg_show;
324
325 ret = sysfs_create_file(idletimer_tg_kobj, &info->timer->attr.attr);
326 if (ret < 0) {
327 pr_debug("couldn't add file to sysfs");
328 goto out_free_attr;
329 }
Devi Sandeep Endluri V V3d6aa172017-06-05 16:34:11 +0530330 /* notify userspace */
331 kobject_uevent(idletimer_tg_kobj, KOBJ_ADD);
Luciano Coelho0902b462010-06-15 15:04:00 +0200332
333 list_add(&info->timer->entry, &idletimer_tg_list);
334
335 setup_timer(&info->timer->timer, idletimer_tg_expired,
336 (unsigned long) info->timer);
337 info->timer->refcnt = 1;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700338 info->timer->send_nl_msg = (info->send_nl_msg == 0) ? false : true;
339 info->timer->active = true;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700340 info->timer->timeout = info->timeout;
341
342 info->timer->delayed_timer_trigger.tv_sec = 0;
343 info->timer->delayed_timer_trigger.tv_nsec = 0;
344 info->timer->work_pending = false;
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700345 info->timer->uid = 0;
Ruchi Kandoieb168432014-03-25 16:43:28 -0700346 get_monotonic_boottime(&info->timer->last_modified_timer);
347
348 info->timer->pm_nb.notifier_call = idletimer_resume;
349 ret = register_pm_notifier(&info->timer->pm_nb);
350 if (ret)
351 printk(KERN_WARNING "[%s] Failed to register pm notifier %d\n",
352 __func__, ret);
Luciano Coelho0902b462010-06-15 15:04:00 +0200353
Eric Dumazet034ad9d2018-02-16 19:36:28 -0800354 INIT_WORK(&info->timer->work, idletimer_tg_work);
355
Luciano Coelho0902b462010-06-15 15:04:00 +0200356 mod_timer(&info->timer->timer,
357 msecs_to_jiffies(info->timeout * 1000) + jiffies);
358
Luciano Coelho0902b462010-06-15 15:04:00 +0200359 return 0;
360
361out_free_attr:
362 kfree(info->timer->attr.attr.name);
363out_free_timer:
364 kfree(info->timer);
365out:
366 return ret;
367}
368
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700369static void reset_timer(const struct idletimer_tg_info *info,
370 struct sk_buff *skb)
Ruchi Kandoieb168432014-03-25 16:43:28 -0700371{
372 unsigned long now = jiffies;
373 struct idletimer_tg *timer = info->timer;
374 bool timer_prev;
375
376 spin_lock_bh(&timestamp_lock);
377 timer_prev = timer->active;
378 timer->active = true;
379 /* timer_prev is used to guard overflow problem in time_before*/
380 if (!timer_prev || time_before(timer->timer.expires, now)) {
381 pr_debug("Starting Checkentry timer (Expired, Jiffies): %lu, %lu\n",
382 timer->timer.expires, now);
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700383
384 /* Stores the uid resposible for waking up the radio */
385 if (skb && (skb->sk)) {
Amit Pundir22ea73de2015-05-11 14:39:59 +0530386 timer->uid = from_kuid_munged(current_user_ns(),
Subash Abhinov Kasiviswanathana711fa72016-11-02 11:56:40 -0600387 sock_i_uid(skb_to_full_sk(skb)));
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700388 }
389
Ruchi Kandoieb168432014-03-25 16:43:28 -0700390 /* checks if there is a pending inactive notification*/
391 if (timer->work_pending)
392 timer->delayed_timer_trigger = timer->last_modified_timer;
393 else {
394 timer->work_pending = true;
395 schedule_work(&timer->work);
396 }
397 }
398
399 get_monotonic_boottime(&timer->last_modified_timer);
400 mod_timer(&timer->timer,
401 msecs_to_jiffies(info->timeout * 1000) + now);
402 spin_unlock_bh(&timestamp_lock);
403}
404
Luciano Coelho0902b462010-06-15 15:04:00 +0200405/*
406 * The actual xt_tables plugin.
407 */
408static unsigned int idletimer_tg_target(struct sk_buff *skb,
409 const struct xt_action_param *par)
410{
411 const struct idletimer_tg_info *info = par->targinfo;
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700412 unsigned long now = jiffies;
Luciano Coelho0902b462010-06-15 15:04:00 +0200413
414 pr_debug("resetting timer %s, timeout period %u\n",
415 info->label, info->timeout);
416
417 BUG_ON(!info->timer);
418
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700419 info->timer->active = true;
420
421 if (time_before(info->timer->timer.expires, now)) {
422 schedule_work(&info->timer->work);
423 pr_debug("Starting timer %s (Expired, Jiffies): %lu, %lu\n",
424 info->label, info->timer->timer.expires, now);
425 }
426
427 /* TODO: Avoid modifying timers on each packet */
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700428 reset_timer(info, skb);
Luciano Coelho0902b462010-06-15 15:04:00 +0200429 return XT_CONTINUE;
430}
431
432static int idletimer_tg_checkentry(const struct xt_tgchk_param *par)
433{
434 struct idletimer_tg_info *info = par->targinfo;
435 int ret;
436
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700437 pr_debug("checkentry targinfo %s\n", info->label);
Luciano Coelho0902b462010-06-15 15:04:00 +0200438
439 if (info->timeout == 0) {
440 pr_debug("timeout value is zero\n");
441 return -EINVAL;
442 }
Eric Dumazet034ad9d2018-02-16 19:36:28 -0800443 if (info->timeout >= INT_MAX / 1000) {
444 pr_debug("timeout value is too big\n");
445 return -EINVAL;
446 }
Luciano Coelho0902b462010-06-15 15:04:00 +0200447 if (info->label[0] == '\0' ||
448 strnlen(info->label,
449 MAX_IDLETIMER_LABEL_SIZE) == MAX_IDLETIMER_LABEL_SIZE) {
450 pr_debug("label is empty or not nul-terminated\n");
451 return -EINVAL;
452 }
453
454 mutex_lock(&list_mutex);
455
456 info->timer = __idletimer_tg_find_by_label(info->label);
457 if (info->timer) {
458 info->timer->refcnt++;
Ruchi Kandoi5ecc8072015-04-23 12:09:09 -0700459 reset_timer(info, NULL);
Luciano Coelho0902b462010-06-15 15:04:00 +0200460 pr_debug("increased refcnt of timer %s to %u\n",
461 info->label, info->timer->refcnt);
462 } else {
463 ret = idletimer_tg_create(info);
464 if (ret < 0) {
465 pr_debug("failed to create timer\n");
466 mutex_unlock(&list_mutex);
467 return ret;
468 }
469 }
470
471 mutex_unlock(&list_mutex);
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700472
Luciano Coelho0902b462010-06-15 15:04:00 +0200473 return 0;
474}
475
476static void idletimer_tg_destroy(const struct xt_tgdtor_param *par)
477{
478 const struct idletimer_tg_info *info = par->targinfo;
479
480 pr_debug("destroy targinfo %s\n", info->label);
481
482 mutex_lock(&list_mutex);
483
484 if (--info->timer->refcnt == 0) {
485 pr_debug("deleting timer %s\n", info->label);
486
487 list_del(&info->timer->entry);
488 del_timer_sync(&info->timer->timer);
489 sysfs_remove_file(idletimer_tg_kobj, &info->timer->attr.attr);
Ruchi Kandoieb168432014-03-25 16:43:28 -0700490 unregister_pm_notifier(&info->timer->pm_nb);
Subash Abhinov Kasiviswanathan7b1124302016-11-10 19:36:15 -0700491 cancel_work_sync(&info->timer->work);
Luciano Coelho0902b462010-06-15 15:04:00 +0200492 kfree(info->timer->attr.attr.name);
493 kfree(info->timer);
494 } else {
495 pr_debug("decreased refcnt of timer %s to %u\n",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700496 info->label, info->timer->refcnt);
Luciano Coelho0902b462010-06-15 15:04:00 +0200497 }
498
499 mutex_unlock(&list_mutex);
500}
501
502static struct xt_target idletimer_tg __read_mostly = {
503 .name = "IDLETIMER",
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700504 .revision = 1,
Luciano Coelho0902b462010-06-15 15:04:00 +0200505 .family = NFPROTO_UNSPEC,
506 .target = idletimer_tg_target,
507 .targetsize = sizeof(struct idletimer_tg_info),
508 .checkentry = idletimer_tg_checkentry,
509 .destroy = idletimer_tg_destroy,
510 .me = THIS_MODULE,
511};
512
513static struct class *idletimer_tg_class;
514
515static struct device *idletimer_tg_device;
516
517static int __init idletimer_tg_init(void)
518{
519 int err;
520
521 idletimer_tg_class = class_create(THIS_MODULE, "xt_idletimer");
522 err = PTR_ERR(idletimer_tg_class);
523 if (IS_ERR(idletimer_tg_class)) {
524 pr_debug("couldn't register device class\n");
525 goto out;
526 }
527
528 idletimer_tg_device = device_create(idletimer_tg_class, NULL,
529 MKDEV(0, 0), NULL, "timers");
530 err = PTR_ERR(idletimer_tg_device);
531 if (IS_ERR(idletimer_tg_device)) {
532 pr_debug("couldn't register system device\n");
533 goto out_class;
534 }
535
536 idletimer_tg_kobj = &idletimer_tg_device->kobj;
537
538 err = xt_register_target(&idletimer_tg);
539 if (err < 0) {
540 pr_debug("couldn't register xt target\n");
541 goto out_dev;
542 }
543
544 return 0;
545out_dev:
546 device_destroy(idletimer_tg_class, MKDEV(0, 0));
547out_class:
548 class_destroy(idletimer_tg_class);
549out:
550 return err;
551}
552
553static void __exit idletimer_tg_exit(void)
554{
555 xt_unregister_target(&idletimer_tg);
556
557 device_destroy(idletimer_tg_class, MKDEV(0, 0));
558 class_destroy(idletimer_tg_class);
559}
560
561module_init(idletimer_tg_init);
562module_exit(idletimer_tg_exit);
563
564MODULE_AUTHOR("Timo Teras <ext-timo.teras@nokia.com>");
565MODULE_AUTHOR("Luciano Coelho <luciano.coelho@nokia.com>");
566MODULE_DESCRIPTION("Xtables: idle time monitor");
567MODULE_LICENSE("GPL v2");
Jan Engelhardtf1e231a2011-01-18 06:30:13 +0100568MODULE_ALIAS("ipt_IDLETIMER");
569MODULE_ALIAS("ip6t_IDLETIMER");
JP Abgrallcf7ad6a2012-04-26 23:28:35 -0700570MODULE_ALIAS("arpt_IDLETIMER");