Clean and tiddy-up files.
[tomato.git] / release / src / router / iptables / extensions / libipt_IMQ.c
blob29cfd62550007fb12924bb897605d4e56b4b1ba9
1 /* Shared library add-on to iptables to add IMQ target support. */
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <getopt.h>
7 #include <iptables.h>
8 #include <linux/netfilter_ipv4/ip_tables.h>
9 #include <linux/netfilter_ipv4/ipt_IMQ.h>
11 /* Function which prints out usage message. */
12 static void
13 help(void)
15 printf(
16 "IMQ target v%s options:\n"
17 " --todev <N> enqueue to imq<N>, defaults to 0\n",
18 IPTABLES_VERSION);
21 static struct option opts[] = {
22 { "todev", 1, 0, '1' },
23 { 0 }
26 /* Initialize the target. */
27 static void
28 init(struct ipt_entry_target *t, unsigned int *nfcache)
30 struct ipt_imq_info *mr = (struct ipt_imq_info*)t->data;
32 mr->todev = 0;
33 *nfcache |= NFC_UNKNOWN;
36 /* Function which parses command options; returns true if it
37 ate an option */
38 static int
39 parse(int c, char **argv, int invert, unsigned int *flags,
40 const struct ipt_entry *entry,
41 struct ipt_entry_target **target)
43 struct ipt_imq_info *mr = (struct ipt_imq_info*)(*target)->data;
45 switch(c) {
46 case '1':
47 if (check_inverse(optarg, &invert, NULL, 0))
48 exit_error(PARAMETER_PROBLEM,
49 "Unexpected `!' after --todev");
50 mr->todev=atoi(optarg);
51 break;
52 default:
53 return 0;
55 return 1;
58 static void
59 final_check(unsigned int flags)
63 /* Prints out the targinfo. */
64 static void
65 print(const struct ipt_ip *ip,
66 const struct ipt_entry_target *target,
67 int numeric)
69 struct ipt_imq_info *mr = (struct ipt_imq_info*)target->data;
71 printf("IMQ: todev %u ", mr->todev);
74 /* Saves the union ipt_targinfo in parsable form to stdout. */
75 static void
76 save(const struct ipt_ip *ip, const struct ipt_entry_target *target)
78 struct ipt_imq_info *mr = (struct ipt_imq_info*)target->data;
80 printf("--todev %u", mr->todev);
83 static struct iptables_target imq = {
84 .next = NULL,
85 .name = "IMQ",
86 .version = IPTABLES_VERSION,
87 .size = IPT_ALIGN(sizeof(struct ipt_imq_info)),
88 .userspacesize = IPT_ALIGN(sizeof(struct ipt_imq_info)),
89 .help = &help,
90 .init = &init,
91 .parse = &parse,
92 .final_check = &final_check,
93 .print = &print,
94 .save = &save,
95 .extra_opts = opts
98 void _init(void)
100 register_target(&imq);