1 /* Shared library add-on to iptables to add related packet matching support. */
9 #include <linux/netfilter/xt_helper.h>
11 /* Function which prints out usage message. */
12 static void helper_help(void)
15 "helper match options:\n"
16 "[!] --helper string Match helper identified by string\n");
19 static const struct option helper_opts[] = {
20 { "helper", 1, NULL, '1' },
24 /* Function which parses command options; returns true if it
27 helper_parse(int c, char **argv, int invert, unsigned int *flags,
28 const void *entry, struct xt_entry_match **match)
30 struct xt_helper_info *info = (struct xt_helper_info *)(*match)->data;
35 exit_error(PARAMETER_PROBLEM,
36 "helper match: Only use --helper ONCE!");
37 check_inverse(optarg, &invert, &invert, 0);
38 strncpy(info->name, optarg, 29);
39 info->name[29] = '\0';
51 /* Final check; must have specified --helper. */
52 static void helper_check(unsigned int flags)
55 exit_error(PARAMETER_PROBLEM,
56 "helper match: You must specify `--helper'");
59 /* Prints out the info. */
61 helper_print(const void *ip, const struct xt_entry_match *match, int numeric)
63 struct xt_helper_info *info = (struct xt_helper_info *)match->data;
65 printf("helper match %s\"%s\" ", info->invert ? "! " : "", info->name);
68 /* Saves the union ipt_info in parsable form to stdout. */
69 static void helper_save(const void *ip, const struct xt_entry_match *match)
71 struct xt_helper_info *info = (struct xt_helper_info *)match->data;
73 printf("%s--helper ",info->invert ? "! " : "");
74 save_string(info->name);
77 static struct xtables_match helper_match = {
80 .version = XTABLES_VERSION,
81 .size = XT_ALIGN(sizeof(struct xt_helper_info)),
83 .parse = helper_parse,
84 .final_check = helper_check,
85 .print = helper_print,
87 .extra_opts = helper_opts,
90 static struct xtables_match helper_match6 = {
93 .version = XTABLES_VERSION,
94 .size = XT_ALIGN(sizeof(struct xt_helper_info)),
96 .parse = helper_parse,
97 .final_check = helper_check,
98 .print = helper_print,
100 .extra_opts = helper_opts,
105 xtables_register_match(&helper_match);
106 xtables_register_match(&helper_match6);