blob: 21004a4b151c2e1637dd863ad0fa2a79cdb2a3cd [file] [log] [blame]
Luciano Coelhod96993e2010-06-15 16:54:50 +02001/*
2 * Shared library add-on for iptables to add IDLETIMER support.
3 *
4 * Copyright (C) 2010 Nokia Corporation. All rights reserved.
5 *
6 * Contact: Luciano Coelho <luciano.coelho@nokia.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * version 2 as published by the Free Software Foundation.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA
21 *
22 */
Luciano Coelhod96993e2010-06-15 16:54:50 +020023#include <stdio.h>
Luciano Coelhod96993e2010-06-15 16:54:50 +020024#include <xtables.h>
25#include <linux/netfilter/xt_IDLETIMER.h>
26
27enum {
Jan Engelhardta0b2fac2011-05-01 16:11:31 +020028 O_TIMEOUT = 0,
29 O_LABEL,
Luciano Coelhod96993e2010-06-15 16:54:50 +020030};
31
Jan Engelhardta0b2fac2011-05-01 16:11:31 +020032#define s struct idletimer_tg_info
33static const struct xt_option_entry idletimer_tg_opts[] = {
34 {.name = "timeout", .id = O_TIMEOUT, .type = XTTYPE_UINT32,
35 .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)},
36 {.name = "label", .id = O_LABEL, .type = XTTYPE_STRING,
37 .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)},
38 XTOPT_TABLEEND,
Luciano Coelhod96993e2010-06-15 16:54:50 +020039};
Jan Engelhardta0b2fac2011-05-01 16:11:31 +020040#undef s
Luciano Coelhod96993e2010-06-15 16:54:50 +020041
42static void idletimer_tg_help(void)
43{
44 printf(
45"IDLETIMER target options:\n"
46" --timeout time Timeout until the notification is sent (in seconds)\n"
47" --label string Unique rule identifier\n"
48"\n");
49}
50
Luciano Coelhod96993e2010-06-15 16:54:50 +020051static void idletimer_tg_print(const void *ip,
52 const struct xt_entry_target *target,
53 int numeric)
54{
55 struct idletimer_tg_info *info =
56 (struct idletimer_tg_info *) target->data;
57
Jan Engelhardt73866352010-12-18 02:04:59 +010058 printf(" timeout:%u", info->timeout);
59 printf(" label:%s", info->label);
Luciano Coelhod96993e2010-06-15 16:54:50 +020060}
61
62static void idletimer_tg_save(const void *ip,
63 const struct xt_entry_target *target)
64{
65 struct idletimer_tg_info *info =
66 (struct idletimer_tg_info *) target->data;
67
Jan Engelhardt73866352010-12-18 02:04:59 +010068 printf(" --timeout %u", info->timeout);
69 printf(" --label %s", info->label);
Luciano Coelhod96993e2010-06-15 16:54:50 +020070}
71
72static struct xtables_target idletimer_tg_reg = {
73 .family = NFPROTO_UNSPEC,
74 .name = "IDLETIMER",
75 .version = XTABLES_VERSION,
76 .revision = 0,
77 .size = XT_ALIGN(sizeof(struct idletimer_tg_info)),
78 .userspacesize = offsetof(struct idletimer_tg_info, timer),
79 .help = idletimer_tg_help,
Jan Engelhardta0b2fac2011-05-01 16:11:31 +020080 .x6_parse = xtables_option_parse,
Luciano Coelhod96993e2010-06-15 16:54:50 +020081 .print = idletimer_tg_print,
82 .save = idletimer_tg_save,
Jan Engelhardta0b2fac2011-05-01 16:11:31 +020083 .x6_options = idletimer_tg_opts,
Luciano Coelhod96993e2010-06-15 16:54:50 +020084};
85
Jan Engelhardt0428e5a2010-08-03 19:58:38 +020086void _init(void)
Luciano Coelhod96993e2010-06-15 16:54:50 +020087{
88 xtables_register_target(&idletimer_tg_reg);
89}