Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 1 | /* |
| 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 Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 23 | #include <stdio.h> |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 24 | #include <xtables.h> |
| 25 | #include <linux/netfilter/xt_IDLETIMER.h> |
| 26 | |
| 27 | enum { |
Jan Engelhardt | a0b2fac | 2011-05-01 16:11:31 +0200 | [diff] [blame] | 28 | O_TIMEOUT = 0, |
| 29 | O_LABEL, |
Ashish Sharma | e07e0d3 | 2012-03-29 19:51:43 -0700 | [diff] [blame] | 30 | O_NETLINK, |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 31 | }; |
| 32 | |
Jan Engelhardt | a0b2fac | 2011-05-01 16:11:31 +0200 | [diff] [blame] | 33 | #define s struct idletimer_tg_info |
| 34 | static const struct xt_option_entry idletimer_tg_opts[] = { |
| 35 | {.name = "timeout", .id = O_TIMEOUT, .type = XTTYPE_UINT32, |
| 36 | .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)}, |
| 37 | {.name = "label", .id = O_LABEL, .type = XTTYPE_STRING, |
| 38 | .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)}, |
Ashish Sharma | e07e0d3 | 2012-03-29 19:51:43 -0700 | [diff] [blame] | 39 | {.name = "send_nl_msg", .id = O_NETLINK, .type = XTTYPE_UINT8, |
| 40 | .flags = XTOPT_PUT, XTOPT_POINTER(s, send_nl_msg)}, |
Jan Engelhardt | a0b2fac | 2011-05-01 16:11:31 +0200 | [diff] [blame] | 41 | XTOPT_TABLEEND, |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 42 | }; |
Jan Engelhardt | a0b2fac | 2011-05-01 16:11:31 +0200 | [diff] [blame] | 43 | #undef s |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 44 | |
| 45 | static void idletimer_tg_help(void) |
| 46 | { |
| 47 | printf( |
| 48 | "IDLETIMER target options:\n" |
| 49 | " --timeout time Timeout until the notification is sent (in seconds)\n" |
| 50 | " --label string Unique rule identifier\n" |
Ashish Sharma | e07e0d3 | 2012-03-29 19:51:43 -0700 | [diff] [blame] | 51 | " --send_nl_msg (0/1) Enable netlink messages," |
| 52 | " and show remaining time in sysfs. Defaults to 0.\n" |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 53 | "\n"); |
| 54 | } |
| 55 | |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 56 | static void idletimer_tg_print(const void *ip, |
| 57 | const struct xt_entry_target *target, |
| 58 | int numeric) |
| 59 | { |
| 60 | struct idletimer_tg_info *info = |
| 61 | (struct idletimer_tg_info *) target->data; |
| 62 | |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 63 | printf(" timeout:%u", info->timeout); |
| 64 | printf(" label:%s", info->label); |
Ashish Sharma | e07e0d3 | 2012-03-29 19:51:43 -0700 | [diff] [blame] | 65 | printf(" send_nl_msg:%u", info->send_nl_msg); |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static void idletimer_tg_save(const void *ip, |
| 69 | const struct xt_entry_target *target) |
| 70 | { |
| 71 | struct idletimer_tg_info *info = |
| 72 | (struct idletimer_tg_info *) target->data; |
| 73 | |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 74 | printf(" --timeout %u", info->timeout); |
| 75 | printf(" --label %s", info->label); |
Ashish Sharma | e07e0d3 | 2012-03-29 19:51:43 -0700 | [diff] [blame] | 76 | printf(" --send_nl_msg %u", info->send_nl_msg); |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static struct xtables_target idletimer_tg_reg = { |
| 80 | .family = NFPROTO_UNSPEC, |
| 81 | .name = "IDLETIMER", |
| 82 | .version = XTABLES_VERSION, |
Ashish Sharma | e07e0d3 | 2012-03-29 19:51:43 -0700 | [diff] [blame] | 83 | .revision = 1, |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 84 | .size = XT_ALIGN(sizeof(struct idletimer_tg_info)), |
| 85 | .userspacesize = offsetof(struct idletimer_tg_info, timer), |
| 86 | .help = idletimer_tg_help, |
Jan Engelhardt | a0b2fac | 2011-05-01 16:11:31 +0200 | [diff] [blame] | 87 | .x6_parse = xtables_option_parse, |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 88 | .print = idletimer_tg_print, |
| 89 | .save = idletimer_tg_save, |
Jan Engelhardt | a0b2fac | 2011-05-01 16:11:31 +0200 | [diff] [blame] | 90 | .x6_options = idletimer_tg_opts, |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 91 | }; |
| 92 | |
Jan Engelhardt | 0428e5a | 2010-08-03 19:58:38 +0200 | [diff] [blame] | 93 | void _init(void) |
Luciano Coelho | d96993e | 2010-06-15 16:54:50 +0200 | [diff] [blame] | 94 | { |
| 95 | xtables_register_target(&idletimer_tg_reg); |
| 96 | } |