diff options
Diffstat (limited to 'extensions/libxt_IDLETIMER.c')
-rw-r--r-- | extensions/libxt_IDLETIMER.c | 113 |
1 files changed, 94 insertions, 19 deletions
diff --git a/extensions/libxt_IDLETIMER.c b/extensions/libxt_IDLETIMER.c index 5f1b9fe7..c414801c 100644 --- a/extensions/libxt_IDLETIMER.c +++ b/extensions/libxt_IDLETIMER.c @@ -27,6 +27,7 @@ enum { O_TIMEOUT = 0, O_LABEL, + O_ALARM, O_NETLINK, }; @@ -36,8 +37,18 @@ static const struct xt_option_entry idletimer_tg_opts[] = { .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)}, {.name = "label", .id = O_LABEL, .type = XTTYPE_STRING, .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)}, - {.name = "send_nl_msg", .id = O_NETLINK, .type = XTTYPE_UINT8, - .flags = XTOPT_PUT, XTOPT_POINTER(s, send_nl_msg)}, + XTOPT_TABLEEND, +}; +#undef s + +#define s struct idletimer_tg_info_v1 +static const struct xt_option_entry idletimer_tg_opts_v1[] = { + {.name = "timeout", .id = O_TIMEOUT, .type = XTTYPE_UINT32, + .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, timeout)}, + {.name = "label", .id = O_LABEL, .type = XTTYPE_STRING, + .flags = XTOPT_MAND | XTOPT_PUT, XTOPT_POINTER(s, label)}, + {.name = "alarm", .id = O_ALARM, .type = XTTYPE_NONE}, + {.name = "send_nl_msg", .id = O_NETLINK, .type = XTTYPE_NONE}, XTOPT_TABLEEND, }; #undef s @@ -48,8 +59,17 @@ static void idletimer_tg_help(void) "IDLETIMER target options:\n" " --timeout time Timeout until the notification is sent (in seconds)\n" " --label string Unique rule identifier\n" -" --send_nl_msg (0/1) Enable netlink messages," - " and show remaining time in sysfs. Defaults to 0.\n" +"\n"); +} + +static void idletimer_tg_help_v1(void) +{ + printf( +"IDLETIMER target options:\n" +" --timeout time Timeout until the notification is sent (in seconds)\n" +" --label string Unique rule identifier\n" +" --alarm Use alarm instead of default timer\n" +" --send_nl_msg Enable netlink messages and show remaining time in sysfs.\n" "\n"); } @@ -62,9 +82,24 @@ static void idletimer_tg_print(const void *ip, printf(" timeout:%u", info->timeout); printf(" label:%s", info->label); - printf(" send_nl_msg:%u", info->send_nl_msg); } +static void idletimer_tg_print_v1(const void *ip, + const struct xt_entry_target *target, + int numeric) +{ + struct idletimer_tg_info_v1 *info = + (struct idletimer_tg_info_v1 *) target->data; + + printf(" timeout:%u", info->timeout); + printf(" label:%s", info->label); + if (info->timer_type == XT_IDLETIMER_ALARM) + printf(" alarm"); + if (info->send_nl_msg) + printf(" send_nl_msg"); +} + + static void idletimer_tg_save(const void *ip, const struct xt_entry_target *target) { @@ -73,24 +108,64 @@ static void idletimer_tg_save(const void *ip, printf(" --timeout %u", info->timeout); printf(" --label %s", info->label); - printf(" --send_nl_msg %u", info->send_nl_msg); } -static struct xtables_target idletimer_tg_reg = { - .family = NFPROTO_UNSPEC, - .name = "IDLETIMER", - .version = XTABLES_VERSION, - .revision = 1, - .size = XT_ALIGN(sizeof(struct idletimer_tg_info)), - .userspacesize = offsetof(struct idletimer_tg_info, timer), - .help = idletimer_tg_help, - .x6_parse = xtables_option_parse, - .print = idletimer_tg_print, - .save = idletimer_tg_save, - .x6_options = idletimer_tg_opts, +static void idletimer_tg_save_v1(const void *ip, + const struct xt_entry_target *target) +{ + struct idletimer_tg_info_v1 *info = + (struct idletimer_tg_info_v1 *) target->data; + + printf(" --timeout %u", info->timeout); + printf(" --label %s", info->label); + if (info->timer_type == XT_IDLETIMER_ALARM) + printf(" --alarm"); + if (info->send_nl_msg) + printf(" --send_nl_msg"); +} + +static void idletimer_tg_parse_v1(struct xt_option_call *cb) +{ + struct idletimer_tg_info_v1 *info = cb->data; + + xtables_option_parse(cb); + if (cb->entry->id == O_ALARM) + info->timer_type = XT_IDLETIMER_ALARM; + if (cb->entry->id == O_NETLINK) + info->send_nl_msg = 1; +} + +static struct xtables_target idletimer_tg_reg[] = { + { + .family = NFPROTO_UNSPEC, + .name = "IDLETIMER", + .version = XTABLES_VERSION, + .revision = 0, + .size = XT_ALIGN(sizeof(struct idletimer_tg_info)), + .userspacesize = offsetof(struct idletimer_tg_info, timer), + .help = idletimer_tg_help, + .x6_parse = xtables_option_parse, + .print = idletimer_tg_print, + .save = idletimer_tg_save, + .x6_options = idletimer_tg_opts, + }, + { + .family = NFPROTO_UNSPEC, + .name = "IDLETIMER", + .version = XTABLES_VERSION, + .revision = 1, + .size = XT_ALIGN(sizeof(struct idletimer_tg_info_v1)), + .userspacesize = offsetof(struct idletimer_tg_info_v1, timer), + .help = idletimer_tg_help_v1, + .x6_parse = idletimer_tg_parse_v1, + .print = idletimer_tg_print_v1, + .save = idletimer_tg_save_v1, + .x6_options = idletimer_tg_opts_v1, + }, + }; void _init(void) { - xtables_register_target(&idletimer_tg_reg); + xtables_register_targets(idletimer_tg_reg, ARRAY_SIZE(idletimer_tg_reg)); } |