blob: 43e2d04e6267efb6a2b15a8631a68f6dc9c2c276 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/* 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>
6
7#include <xtables.h>
8#include <linux/netfilter_ipv4/ipt_IMQ.h>
9
10static void
11help(void)
12{
13 printf(
14"IMQ target options:\n"
15" --todev <N> enqueue to imq<N>, defaults to 0\n");
16}
17
18static struct option opts[] = {
19 { "todev", 1, 0, '1' },
20 { .name = NULL }
21};
22
23static void
24init(struct xt_entry_target *t)
25{
26 struct ipt_imq_info *mr = (struct ipt_imq_info*)t->data;
27
28 mr->todev = 0;
29}
30
31static int
32parse(int c, char **argv, int invert, unsigned int *flags,
33 const void *entry,
34 struct xt_entry_target **target)
35{
36 struct ipt_imq_info *mr = (struct ipt_imq_info*)(*target)->data;
37
38 switch(c) {
39 case '1':
40 if (xtables_check_inverse(optarg, &invert, NULL, 0))
41 xtables_error(PARAMETER_PROBLEM,
42 "Unexpected `!' after --todev");
43 mr->todev=atoi(optarg);
44 break;
45 default:
46 return 0;
47 }
48 return 1;
49}
50
51static void
52final_check(unsigned int flags)
53{
54}
55
56static void
57print(const void *ip,
58 const struct xt_entry_target *target,
59 int numeric)
60{
61 struct ipt_imq_info *mr = (struct ipt_imq_info*)target->data;
62
63 printf("IMQ: todev %u ", mr->todev);
64}
65
66static void
67save(const void *ip, const struct xt_entry_target *target)
68{
69 struct ipt_imq_info *mr = (struct ipt_imq_info*)target->data;
70
71 printf("--todev %u", mr->todev);
72}
73
74static
75struct xtables_target imq
76= {
77 .name = "IMQ",
78 .version = XTABLES_VERSION,
79 .family = NFPROTO_IPV4,
80 .size = XT_ALIGN(sizeof(struct ipt_imq_info)),
81 .userspacesize = XT_ALIGN(sizeof(struct ipt_imq_info)),
82 .help = &help,
83 .init = &init,
84 .parse = &parse,
85 .final_check = &final_check,
86 .print = &print,
87 .save = &save,
88 .extra_opts = opts
89};
90
91void _init(void)
92{
93 xtables_register_target(&imq);
94}