1 #include <stdio.h>
2 #include <xtables.h>
3 #include <linux/netfilter/xt_helper.h>
4
5 enum {
6 O_HELPER = 0,
7 };
8
helper_help(void)9 static void helper_help(void)
10 {
11 printf(
12 "helper match options:\n"
13 "[!] --helper string Match helper identified by string\n");
14 }
15
16 static 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,
21 };
22
helper_parse(struct xt_option_call * cb)23 static void helper_parse(struct xt_option_call *cb)
24 {
25 struct xt_helper_info *info = cb->data;
26
27 xtables_option_parse(cb);
28 if (cb->invert)
29 info->invert = 1;
30 }
31
32 static void
helper_print(const void * ip,const struct xt_entry_match * match,int numeric)33 helper_print(const void *ip, const struct xt_entry_match *match, int numeric)
34 {
35 const struct xt_helper_info *info = (const void *)match->data;
36
37 printf(" helper match %s\"%s\"", info->invert ? "! " : "", info->name);
38 }
39
helper_save(const void * ip,const struct xt_entry_match * match)40 static void helper_save(const void *ip, const struct xt_entry_match *match)
41 {
42 const struct xt_helper_info *info = (const void *)match->data;
43
44 printf("%s --helper", info->invert ? " !" : "");
45 xtables_save_string(info->name);
46 }
47
helper_xlate(struct xt_xlate * xl,const struct xt_xlate_mt_params * params)48 static int helper_xlate(struct xt_xlate *xl,
49 const struct xt_xlate_mt_params *params)
50 {
51 const struct xt_helper_info *info = (const void *)params->match->data;
52
53 if (params->escape_quotes)
54 xt_xlate_add(xl, "ct helper%s \\\"%s\\\"",
55 info->invert ? " !=" : "", info->name);
56 else
57 xt_xlate_add(xl, "ct helper%s \"%s\"",
58 info->invert ? " !=" : "", info->name);
59
60 return 1;
61 }
62
63 static struct xtables_match helper_match = {
64 .family = NFPROTO_UNSPEC,
65 .name = "helper",
66 .version = XTABLES_VERSION,
67 .size = XT_ALIGN(sizeof(struct xt_helper_info)),
68 .help = helper_help,
69 .print = helper_print,
70 .save = helper_save,
71 .x6_parse = helper_parse,
72 .x6_options = helper_opts,
73 .xlate = helper_xlate,
74 };
75
_init(void)76 void _init(void)
77 {
78 xtables_register_match(&helper_match);
79 }
80