blob: c9f9435ecd2eb0a023775f0eb967fa003589ecbc [file] [log] [blame]
Martin Josefsson110610b2002-01-11 18:41:02 +00001#include <stdio.h>
Yasuyuki KOZAKAIf8137b12007-08-04 08:26:59 +00002#include <xtables.h>
3#include <linux/netfilter/xt_helper.h>
Martin Josefsson110610b2002-01-11 18:41:02 +00004
Jan Engelhardt76e18ae2011-03-02 18:55:32 +01005enum {
6 O_HELPER = 0,
7};
8
Jan Engelhardt181dead2007-10-04 16:27:07 +00009static void helper_help(void)
Martin Josefsson110610b2002-01-11 18:41:02 +000010{
11 printf(
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020012"helper match options:\n"
13"[!] --helper string Match helper identified by string\n");
Martin Josefsson110610b2002-01-11 18:41:02 +000014}
15
Jan Engelhardt76e18ae2011-03-02 18:55:32 +010016static const struct xt_option_entry helper_opts[] = {
17 {.name = "helper", .id = O_HELPER, .type = XTTYPE_STRING,
18 .flags = XTOPT_MAND | XTOPT_INVERT | XTOPT_PUT,
19 XTOPT_POINTER(struct xt_helper_info, name)},
20 XTOPT_TABLEEND,
Martin Josefsson110610b2002-01-11 18:41:02 +000021};
22
Jan Engelhardt76e18ae2011-03-02 18:55:32 +010023static void helper_parse(struct xt_option_call *cb)
Martin Josefsson110610b2002-01-11 18:41:02 +000024{
Jan Engelhardt76e18ae2011-03-02 18:55:32 +010025 struct xt_helper_info *info = cb->data;
Martin Josefsson110610b2002-01-11 18:41:02 +000026
Jan Engelhardt76e18ae2011-03-02 18:55:32 +010027 xtables_option_parse(cb);
28 if (cb->invert)
29 info->invert = 1;
Martin Josefsson110610b2002-01-11 18:41:02 +000030}
31
Martin Josefsson110610b2002-01-11 18:41:02 +000032static void
Jan Engelhardt181dead2007-10-04 16:27:07 +000033helper_print(const void *ip, const struct xt_entry_match *match, int numeric)
Martin Josefsson110610b2002-01-11 18:41:02 +000034{
Jan Engelhardt69f564e2009-05-26 13:14:06 +020035 const struct xt_helper_info *info = (const void *)match->data;
Martin Josefsson110610b2002-01-11 18:41:02 +000036
Jan Engelhardt73866352010-12-18 02:04:59 +010037 printf(" helper match %s\"%s\"", info->invert ? "! " : "", info->name);
Martin Josefsson110610b2002-01-11 18:41:02 +000038}
39
Jan Engelhardt181dead2007-10-04 16:27:07 +000040static void helper_save(const void *ip, const struct xt_entry_match *match)
Martin Josefsson110610b2002-01-11 18:41:02 +000041{
Jan Engelhardt69f564e2009-05-26 13:14:06 +020042 const struct xt_helper_info *info = (const void *)match->data;
Martin Josefsson110610b2002-01-11 18:41:02 +000043
Jan Engelhardt73866352010-12-18 02:04:59 +010044 printf("%s --helper", info->invert ? " !" : "");
Jan Engelhardta0baae82009-01-30 04:32:50 +010045 xtables_save_string(info->name);
Martin Josefsson110610b2002-01-11 18:41:02 +000046}
47
Jan Engelhardt181dead2007-10-04 16:27:07 +000048static struct xtables_match helper_match = {
Jan Engelhardtc5e85732009-06-12 20:55:44 +020049 .family = NFPROTO_UNSPEC,
Yasuyuki KOZAKAIf8137b12007-08-04 08:26:59 +000050 .name = "helper",
Jan Engelhardt8b7c64d2008-04-15 11:48:25 +020051 .version = XTABLES_VERSION,
Yasuyuki KOZAKAIf8137b12007-08-04 08:26:59 +000052 .size = XT_ALIGN(sizeof(struct xt_helper_info)),
Jan Engelhardt181dead2007-10-04 16:27:07 +000053 .help = helper_help,
Jan Engelhardt181dead2007-10-04 16:27:07 +000054 .print = helper_print,
55 .save = helper_save,
Jan Engelhardt76e18ae2011-03-02 18:55:32 +010056 .x6_parse = helper_parse,
57 .x6_options = helper_opts,
Martin Josefsson110610b2002-01-11 18:41:02 +000058};
59
60void _init(void)
61{
Jan Engelhardt181dead2007-10-04 16:27:07 +000062 xtables_register_match(&helper_match);
Martin Josefsson110610b2002-01-11 18:41:02 +000063}