blob: ec47aaf3fbd69ca8aa23e32f0671d98ad4995b69 [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 <ip6tables.h>
8#include <linux/netfilter_ipv6/ip6_tables.h>
9#include <linux/netfilter_ipv6/ip6t_IMQ.h>
10
11/* Function which prints out usage message. */
12static void
13help(void)
14{
15 printf(
16"IMQ target v%s options:\n"
17" --todev <N> enqueue to imq<N>, defaults to 0\n",
18IPTABLES_VERSION);
19}
20
21static struct option opts[] = {
22 { "todev", 1, 0, '1' },
23 { 0 }
24};
25
26/* Initialize the target. */
27static void
28init(struct ip6t_entry_target *t, unsigned int *nfcache)
29{
30 struct ip6t_imq_info *mr = (struct ip6t_imq_info*)t->data;
31
32 mr->todev = 0;
33 *nfcache |= NFC_UNKNOWN;
34}
35
36/* Function which parses command options; returns true if it
37 ate an option */
38static int
39parse(int c, char **argv, int invert, unsigned int *flags,
40 const struct ip6t_entry *entry,
41 struct ip6t_entry_target **target)
42{
43 struct ip6t_imq_info *mr = (struct ip6t_imq_info*)(*target)->data;
44
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;
54 }
55 return 1;
56}
57
58static void
59final_check(unsigned int flags)
60{
61}
62
63/* Prints out the targinfo. */
64static void
65print(const struct ip6t_ip6 *ip,
66 const struct ip6t_entry_target *target,
67 int numeric)
68{
69 struct ip6t_imq_info *mr = (struct ip6t_imq_info*)target->data;
70
71 printf("IMQ: todev %u ", mr->todev);
72}
73
74/* Saves the union ipt_targinfo in parsable form to stdout. */
75static void
76save(const struct ip6t_ip6 *ip, const struct ip6t_entry_target *target)
77{
78 struct ip6t_imq_info *mr = (struct ip6t_imq_info*)target->data;
79
80 printf("--todev %u", mr->todev);
81}
82
83static
84struct ip6tables_target imq
85= { NULL,
86 "IMQ",
87 IPTABLES_VERSION,
88 IP6T_ALIGN(sizeof(struct ip6t_imq_info)),
89 IP6T_ALIGN(sizeof(struct ip6t_imq_info)),
90 &help,
91 &init,
92 &parse,
93 &final_check,
94 &print,
95 &save,
96 opts
97};
98
99void _init(void)
100{
101 register_target6(&imq);
102}