Sapan says vnet_tun is obsolete.
[iptables.git] / extensions / libxt_helper.c
1 /* Shared library add-on to iptables to add related packet matching support. */
2 #include <stdio.h>
3 #include <netdb.h>
4 #include <string.h>
5 #include <stdlib.h>
6 #include <getopt.h>
7
8 #include <xtables.h>
9 #include <linux/netfilter/xt_helper.h>
10
11 /* Function which prints out usage message. */
12 static void helper_help(void)
13 {
14         printf(
15 "helper match options:\n"
16 "[!] --helper string        Match helper identified by string\n");
17 }
18
19 static const struct option helper_opts[] = {
20         { "helper", 1, NULL, '1' },
21         { .name = NULL }
22 };
23
24 /* Function which parses command options; returns true if it
25    ate an option */
26 static int
27 helper_parse(int c, char **argv, int invert, unsigned int *flags,
28              const void *entry, struct xt_entry_match **match)
29 {
30         struct xt_helper_info *info = (struct xt_helper_info *)(*match)->data;
31
32         switch (c) {
33         case '1':
34                 if (*flags)
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';
40                 if (invert)
41                         info->invert = 1;
42                 *flags = 1;
43                 break;
44
45         default:
46                 return 0;
47         }
48         return 1;
49 }
50
51 /* Final check; must have specified --helper. */
52 static void helper_check(unsigned int flags)
53 {
54         if (!flags)
55                 exit_error(PARAMETER_PROBLEM,
56                            "helper match: You must specify `--helper'");
57 }
58
59 /* Prints out the info. */
60 static void
61 helper_print(const void *ip, const struct xt_entry_match *match, int numeric)
62 {
63         struct xt_helper_info *info = (struct xt_helper_info *)match->data;
64
65         printf("helper match %s\"%s\" ", info->invert ? "! " : "", info->name);
66 }
67
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)
70 {
71         struct xt_helper_info *info = (struct xt_helper_info *)match->data;
72
73         printf("%s--helper ",info->invert ? "! " : "");
74         save_string(info->name);
75 }
76
77 static struct xtables_match helper_match = {
78         .family         = AF_INET,
79         .name           = "helper",
80         .version        = XTABLES_VERSION,
81         .size           = XT_ALIGN(sizeof(struct xt_helper_info)),
82         .help           = helper_help,
83         .parse          = helper_parse,
84         .final_check    = helper_check,
85         .print          = helper_print,
86         .save           = helper_save,
87         .extra_opts     = helper_opts,
88 };
89
90 static struct xtables_match helper_match6 = {
91         .family         = AF_INET6,
92         .name           = "helper",
93         .version        = XTABLES_VERSION,
94         .size           = XT_ALIGN(sizeof(struct xt_helper_info)),
95         .help           = helper_help,
96         .parse          = helper_parse,
97         .final_check    = helper_check,
98         .print          = helper_print,
99         .save           = helper_save,
100         .extra_opts     = helper_opts,
101 };
102
103 void _init(void)
104 {
105         xtables_register_match(&helper_match);
106         xtables_register_match(&helper_match6);
107 }