]> git.ipfire.org Git - ipfire-2.x.git/blame - src/patches/iptables-1.4.12-IMQ-test4.diff
Merge branch 'ipsec' into next
[ipfire-2.x.git] / src / patches / iptables-1.4.12-IMQ-test4.diff
CommitLineData
df137470
AF
1diff -Naur iptables-1.4.12.1/extensions/libxt_IMQ.c iptables-1.4.12.1-imq/extensions/libxt_IMQ.c
2--- iptables-1.4.12.1/extensions/libxt_IMQ.c 1970-01-01 02:00:00.000000000 +0200
3+++ iptables-1.4.12.1-imq/extensions/libxt_IMQ.c 2011-09-30 13:53:21.000000000 +0300
4@@ -0,0 +1,105 @@
3dad5558
AF
5+/* Shared library add-on to iptables to add IMQ target support. */
6+#include <stdio.h>
7+#include <string.h>
8+#include <stdlib.h>
9+#include <getopt.h>
10+
11+#include <xtables.h>
12+#include <linux/netfilter/x_tables.h>
13+#include <linux/netfilter/xt_IMQ.h>
14+
15+/* Function which prints out usage message. */
16+static void IMQ_help(void)
17+{
18+ printf(
19+"IMQ target options:\n"
20+" --todev <N> enqueue to imq<N>, defaults to 0\n");
21+
22+}
23+
24+static struct option IMQ_opts[] = {
25+ { "todev", 1, 0, '1' },
26+ { 0 }
27+};
28+
29+/* Initialize the target. */
30+static void IMQ_init(struct xt_entry_target *t)
31+{
32+ struct xt_imq_info *mr = (struct xt_imq_info*)t->data;
33+
34+ mr->todev = 0;
35+}
36+
37+/* Function which parses command options; returns true if it
38+ ate an option */
39+static int IMQ_parse(int c, char **argv, int invert, unsigned int *flags,
40+ const void *entry, struct xt_entry_target **target)
41+{
42+ struct xt_imq_info *mr = (struct xt_imq_info*)(*target)->data;
43+
44+ switch(c) {
45+ case '1':
df137470 46+/* if (xtables_check_inverse(optarg, &invert, NULL, 0, argv))
3dad5558 47+ xtables_error(PARAMETER_PROBLEM,
df137470
AF
48+ "Unexpected `!' after --todev");
49+*/
3dad5558
AF
50+ mr->todev=atoi(optarg);
51+ break;
df137470 52+
3dad5558
AF
53+ default:
54+ return 0;
55+ }
56+ return 1;
57+}
58+
59+/* Prints out the targinfo. */
60+static void IMQ_print(const void *ip,
61+ const struct xt_entry_target *target,
62+ int numeric)
63+{
64+ struct xt_imq_info *mr = (struct xt_imq_info*)target->data;
65+
66+ printf("IMQ: todev %u ", mr->todev);
67+}
68+
69+/* Saves the union ipt_targinfo in parsable form to stdout. */
70+static void IMQ_save(const void *ip, const struct xt_entry_target *target)
71+{
72+ struct xt_imq_info *mr = (struct xt_imq_info*)target->data;
73+
df137470 74+ printf(" --todev %u", mr->todev);
3dad5558
AF
75+}
76+
77+static struct xtables_target imq_target = {
78+ .name = "IMQ",
79+ .version = XTABLES_VERSION,
80+ .family = NFPROTO_IPV4,
81+ .size = XT_ALIGN(sizeof(struct xt_imq_info)),
82+ .userspacesize = XT_ALIGN(sizeof(struct xt_imq_info)),
83+ .help = IMQ_help,
84+ .init = IMQ_init,
85+ .parse = IMQ_parse,
86+ .print = IMQ_print,
87+ .save = IMQ_save,
88+ .extra_opts = IMQ_opts,
89+};
90+
91+static struct xtables_target imq_target6 = {
92+ .name = "IMQ",
93+ .version = XTABLES_VERSION,
94+ .family = NFPROTO_IPV6,
95+ .size = XT_ALIGN(sizeof(struct xt_imq_info)),
96+ .userspacesize = XT_ALIGN(sizeof(struct xt_imq_info)),
97+ .help = IMQ_help,
98+ .init = IMQ_init,
99+ .parse = IMQ_parse,
100+ .print = IMQ_print,
101+ .save = IMQ_save,
102+ .extra_opts = IMQ_opts,
103+};
104+
105+// void __attribute((constructor)) nf_ext_init(void){
106+void _init(void){
107+ xtables_register_target(&imq_target);
108+ xtables_register_target(&imq_target6);
109+}
df137470
AF
110diff -Naur iptables-1.4.12.1/extensions/libxt_IMQ.man iptables-1.4.12.1-imq/extensions/libxt_IMQ.man
111--- iptables-1.4.12.1/extensions/libxt_IMQ.man 1970-01-01 02:00:00.000000000 +0200
112+++ iptables-1.4.12.1-imq/extensions/libxt_IMQ.man 2011-09-30 13:53:21.000000000 +0300
113@@ -0,0 +1,15 @@
114+This target is used to redirect the traffic to the IMQ driver and you can apply
115+QoS rules like HTB or CBQ.
116+For example you can select only traffic comming from a specific interface or
117+is going out on a specific interface.
118+Also it permits to capture the traffic BEFORE NAT in the case of outgoing traffic
119+or AFTER NAT in the case of incomming traffic.
120+.TP
121+\fB\-\-to\-dev\fP \fIvalue\fP
122+Set the IMQ interface where to send this traffic
123+.TP
124+Example:
125+.TP
126+Redirect incomming traffic from interface eth0 to imq0 and outgoing traffic to imq1:
127+iptables \-t mangle \-A FORWARD \-i eth0 \-j IMQ \-\-to\-dev 0
128+iptables \-t mangle \-A FORWARD \-o eth0 \-j IMQ \-\-to\-dev 1
129diff -Naur iptables-1.4.12.1/include/linux/netfilter/xt_IMQ.h iptables-1.4.12.1-imq/include/linux/netfilter/xt_IMQ.h
130--- iptables-1.4.12.1/include/linux/netfilter/xt_IMQ.h 1970-01-01 02:00:00.000000000 +0200
131+++ iptables-1.4.12.1-imq/include/linux/netfilter/xt_IMQ.h 2011-09-30 13:53:21.000000000 +0300
3dad5558
AF
132@@ -0,0 +1,9 @@
133+#ifndef _XT_IMQ_H
134+#define _XT_IMQ_H
135+
136+struct xt_imq_info {
137+ unsigned int todev; /* target imq device */
138+};
139+
140+#endif /* _XT_IMQ_H */
141+