1#include <stdio.h>
2#include <xtables.h>
3#include <linux/netfilter/xt_helper.h>
4
5enum {
6	O_HELPER = 0,
7};
8
9static void helper_help(void)
10{
11	printf(
12"helper match options:\n"
13"[!] --helper string        Match helper identified by string\n");
14}
15
16static 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
23static 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
32static void
33helper_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
40static 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
48static struct xtables_match helper_match = {
49	.family		= NFPROTO_UNSPEC,
50	.name		= "helper",
51	.version	= XTABLES_VERSION,
52	.size		= XT_ALIGN(sizeof(struct xt_helper_info)),
53	.help		= helper_help,
54	.print		= helper_print,
55	.save		= helper_save,
56	.x6_parse	= helper_parse,
57	.x6_options	= helper_opts,
58};
59
60void _init(void)
61{
62	xtables_register_match(&helper_match);
63}
64