PageRenderTime 57ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/iptables-2.6/107-libxt_ecn.patch

http://wl500g.googlecode.com/
Patch | 432 lines | 431 code | 1 blank | 0 comment | 0 complexity | 7d7615db5edd1c75aea96c8cda270e92 MD5 | raw file
Possible License(s): GPL-2.0
  1. extensions: add IPv6 capable ECN match extension
  2. diff -urNBp iptables/extensions/libipt_ecn.c iptables.ecn/extensions/libipt_ecn.c
  3. --- iptables/extensions/libipt_ecn.c 2009-04-06 15:09:17.000000000 +0400
  4. +++ /dev/null
  5. @@ -1,160 +0,0 @@
  6. -/* Shared library add-on to iptables for ECN matching
  7. - *
  8. - * (C) 2002 by Harald Welte <laforge@gnumonks.org>
  9. - *
  10. - * This program is distributed under the terms of GNU GPL v2, 1991
  11. - *
  12. - * libipt_ecn.c borrowed heavily from libipt_dscp.c
  13. - *
  14. - */
  15. -#include <stdio.h>
  16. -#include <string.h>
  17. -#include <stdlib.h>
  18. -#include <getopt.h>
  19. -
  20. -#include <xtables.h>
  21. -#include <linux/netfilter_ipv4/ipt_ecn.h>
  22. -
  23. -static void ecn_help(void)
  24. -{
  25. - printf(
  26. -"ECN match options\n"
  27. -"[!] --ecn-tcp-cwr Match CWR bit of TCP header\n"
  28. -"[!] --ecn-tcp-ece Match ECE bit of TCP header\n"
  29. -"[!] --ecn-ip-ect [0..3] Match ECN codepoint in IPv4 header\n");
  30. -}
  31. -
  32. -static const struct option ecn_opts[] = {
  33. - { .name = "ecn-tcp-cwr", .has_arg = 0, .val = 'F' },
  34. - { .name = "ecn-tcp-ece", .has_arg = 0, .val = 'G' },
  35. - { .name = "ecn-ip-ect", .has_arg = 1, .val = 'H' },
  36. - { .name = NULL }
  37. -};
  38. -
  39. -static int ecn_parse(int c, char **argv, int invert, unsigned int *flags,
  40. - const void *entry, struct xt_entry_match **match)
  41. -{
  42. - unsigned int result;
  43. - struct ipt_ecn_info *einfo
  44. - = (struct ipt_ecn_info *)(*match)->data;
  45. -
  46. - switch (c) {
  47. - case 'F':
  48. - if (*flags & IPT_ECN_OP_MATCH_CWR)
  49. - xtables_error(PARAMETER_PROBLEM,
  50. - "ECN match: can only use parameter ONCE!");
  51. - xtables_check_inverse(optarg, &invert, &optind, 0);
  52. - einfo->operation |= IPT_ECN_OP_MATCH_CWR;
  53. - if (invert)
  54. - einfo->invert |= IPT_ECN_OP_MATCH_CWR;
  55. - *flags |= IPT_ECN_OP_MATCH_CWR;
  56. - break;
  57. -
  58. - case 'G':
  59. - if (*flags & IPT_ECN_OP_MATCH_ECE)
  60. - xtables_error(PARAMETER_PROBLEM,
  61. - "ECN match: can only use parameter ONCE!");
  62. - xtables_check_inverse(optarg, &invert, &optind, 0);
  63. - einfo->operation |= IPT_ECN_OP_MATCH_ECE;
  64. - if (invert)
  65. - einfo->invert |= IPT_ECN_OP_MATCH_ECE;
  66. - *flags |= IPT_ECN_OP_MATCH_ECE;
  67. - break;
  68. -
  69. - case 'H':
  70. - if (*flags & IPT_ECN_OP_MATCH_IP)
  71. - xtables_error(PARAMETER_PROBLEM,
  72. - "ECN match: can only use parameter ONCE!");
  73. - xtables_check_inverse(optarg, &invert, &optind, 0);
  74. - if (invert)
  75. - einfo->invert |= IPT_ECN_OP_MATCH_IP;
  76. - *flags |= IPT_ECN_OP_MATCH_IP;
  77. - einfo->operation |= IPT_ECN_OP_MATCH_IP;
  78. - if (!xtables_strtoui(optarg, NULL, &result, 0, 3))
  79. - xtables_error(PARAMETER_PROBLEM,
  80. - "ECN match: Value out of range");
  81. - einfo->ip_ect = result;
  82. - break;
  83. - default:
  84. - return 0;
  85. - }
  86. -
  87. - return 1;
  88. -}
  89. -
  90. -static void ecn_check(unsigned int flags)
  91. -{
  92. - if (!flags)
  93. - xtables_error(PARAMETER_PROBLEM,
  94. - "ECN match: some option required");
  95. -}
  96. -
  97. -static void ecn_print(const void *ip, const struct xt_entry_match *match,
  98. - int numeric)
  99. -{
  100. - const struct ipt_ecn_info *einfo =
  101. - (const struct ipt_ecn_info *)match->data;
  102. -
  103. - printf("ECN match ");
  104. -
  105. - if (einfo->operation & IPT_ECN_OP_MATCH_ECE) {
  106. - if (einfo->invert & IPT_ECN_OP_MATCH_ECE)
  107. - fputc('!', stdout);
  108. - printf("ECE ");
  109. - }
  110. -
  111. - if (einfo->operation & IPT_ECN_OP_MATCH_CWR) {
  112. - if (einfo->invert & IPT_ECN_OP_MATCH_CWR)
  113. - fputc('!', stdout);
  114. - printf("CWR ");
  115. - }
  116. -
  117. - if (einfo->operation & IPT_ECN_OP_MATCH_IP) {
  118. - if (einfo->invert & IPT_ECN_OP_MATCH_IP)
  119. - fputc('!', stdout);
  120. - printf("ECT=%d ", einfo->ip_ect);
  121. - }
  122. -}
  123. -
  124. -static void ecn_save(const void *ip, const struct xt_entry_match *match)
  125. -{
  126. - const struct ipt_ecn_info *einfo =
  127. - (const struct ipt_ecn_info *)match->data;
  128. -
  129. - if (einfo->operation & IPT_ECN_OP_MATCH_ECE) {
  130. - if (einfo->invert & IPT_ECN_OP_MATCH_ECE)
  131. - printf("! ");
  132. - printf("--ecn-tcp-ece ");
  133. - }
  134. -
  135. - if (einfo->operation & IPT_ECN_OP_MATCH_CWR) {
  136. - if (einfo->invert & IPT_ECN_OP_MATCH_CWR)
  137. - printf("! ");
  138. - printf("--ecn-tcp-cwr ");
  139. - }
  140. -
  141. - if (einfo->operation & IPT_ECN_OP_MATCH_IP) {
  142. - if (einfo->invert & IPT_ECN_OP_MATCH_IP)
  143. - printf("! ");
  144. - printf("--ecn-ip-ect %d", einfo->ip_ect);
  145. - }
  146. -}
  147. -
  148. -static struct xtables_match ecn_mt_reg = {
  149. - .name = "ecn",
  150. - .version = XTABLES_VERSION,
  151. - .family = NFPROTO_IPV4,
  152. - .size = XT_ALIGN(sizeof(struct ipt_ecn_info)),
  153. - .userspacesize = XT_ALIGN(sizeof(struct ipt_ecn_info)),
  154. - .help = ecn_help,
  155. - .parse = ecn_parse,
  156. - .final_check = ecn_check,
  157. - .print = ecn_print,
  158. - .save = ecn_save,
  159. - .extra_opts = ecn_opts,
  160. -};
  161. -
  162. -void _init(void)
  163. -{
  164. - xtables_register_match(&ecn_mt_reg);
  165. -}
  166. diff -urNBp iptables/extensions/libipt_ecn.man iptables.ecn/extensions/libipt_ecn.man
  167. --- iptables/extensions/libipt_ecn.man 2009-04-06 15:09:17.000000000 +0400
  168. +++ /dev/null
  169. @@ -1,11 +0,0 @@
  170. -This allows you to match the ECN bits of the IPv4 and TCP header. ECN is the Explicit Congestion Notification mechanism as specified in RFC3168
  171. -.TP
  172. -[\fB!\fP] \fB\-\-ecn\-tcp\-cwr\fP
  173. -This matches if the TCP ECN CWR (Congestion Window Received) bit is set.
  174. -.TP
  175. -[\fB!\fP] \fB\-\-ecn\-tcp\-ece\fP
  176. -This matches if the TCP ECN ECE (ECN Echo) bit is set.
  177. -.TP
  178. -[\fB!\fP] \fB\-\-ecn\-ip\-ect\fP \fInum\fP
  179. -This matches a particular IPv4 ECT (ECN-Capable Transport). You have to specify
  180. -a number between `0' and `3'.
  181. diff -urNBp iptables/extensions/libxt_ecn.c iptables.ecn/extensions/libxt_ecn.c
  182. --- /dev/null
  183. +++ iptables.ecn/extensions/libxt_ecn.c 2012-03-13 14:48:03.000000000 +0400
  184. @@ -0,0 +1,158 @@
  185. +/* Shared library add-on to iptables for ECN matching
  186. + *
  187. + * (C) 2002 by Harald Welte <laforge@gnumonks.org>
  188. + *
  189. + * This program is distributed under the terms of GNU GPL v2, 1991
  190. + *
  191. + * libipt_ecn.c borrowed heavily from libipt_dscp.c
  192. + *
  193. + */
  194. +#include <stdio.h>
  195. +#include <string.h>
  196. +#include <stdlib.h>
  197. +#include <getopt.h>
  198. +
  199. +#include <xtables.h>
  200. +#include <linux/netfilter/xt_ecn.h>
  201. +
  202. +static void ecn_help(void)
  203. +{
  204. + printf(
  205. +"ECN match options\n"
  206. +"[!] --ecn-tcp-cwr Match CWR bit of TCP header\n"
  207. +"[!] --ecn-tcp-ece Match ECE bit of TCP header\n"
  208. +"[!] --ecn-ip-ect [0..3] Match ECN codepoint in IPv4/IPv6 header\n");
  209. +}
  210. +
  211. +static const struct option ecn_opts[] = {
  212. + { .name = "ecn-tcp-cwr", .has_arg = 0, .val = 'F' },
  213. + { .name = "ecn-tcp-ece", .has_arg = 0, .val = 'G' },
  214. + { .name = "ecn-ip-ect", .has_arg = 1, .val = 'H' },
  215. + { .name = NULL }
  216. +};
  217. +
  218. +static int ecn_parse(int c, char **argv, int invert, unsigned int *flags,
  219. + const void *entry, struct xt_entry_match **match)
  220. +{
  221. + unsigned int result;
  222. + struct xt_ecn_info *einfo
  223. + = (struct xt_ecn_info *)(*match)->data;
  224. +
  225. + switch (c) {
  226. + case 'F':
  227. + if (*flags & XT_ECN_OP_MATCH_CWR)
  228. + xtables_error(PARAMETER_PROBLEM,
  229. + "ECN match: can only use parameter ONCE!");
  230. + xtables_check_inverse(optarg, &invert, &optind, 0);
  231. + einfo->operation |= XT_ECN_OP_MATCH_CWR;
  232. + if (invert)
  233. + einfo->invert |= XT_ECN_OP_MATCH_CWR;
  234. + *flags |= XT_ECN_OP_MATCH_CWR;
  235. + break;
  236. +
  237. + case 'G':
  238. + if (*flags & XT_ECN_OP_MATCH_ECE)
  239. + xtables_error(PARAMETER_PROBLEM,
  240. + "ECN match: can only use parameter ONCE!");
  241. + xtables_check_inverse(optarg, &invert, &optind, 0);
  242. + einfo->operation |= XT_ECN_OP_MATCH_ECE;
  243. + if (invert)
  244. + einfo->invert |= XT_ECN_OP_MATCH_ECE;
  245. + *flags |= XT_ECN_OP_MATCH_ECE;
  246. + break;
  247. +
  248. + case 'H':
  249. + if (*flags & XT_ECN_OP_MATCH_IP)
  250. + xtables_error(PARAMETER_PROBLEM,
  251. + "ECN match: can only use parameter ONCE!");
  252. + xtables_check_inverse(optarg, &invert, &optind, 0);
  253. + if (invert)
  254. + einfo->invert |= XT_ECN_OP_MATCH_IP;
  255. + *flags |= XT_ECN_OP_MATCH_IP;
  256. + einfo->operation |= XT_ECN_OP_MATCH_IP;
  257. + if (!xtables_strtoui(optarg, NULL, &result, 0, 3))
  258. + xtables_error(PARAMETER_PROBLEM,
  259. + "ECN match: Value out of range");
  260. + einfo->ip_ect = result;
  261. + break;
  262. + default:
  263. + return 0;
  264. + }
  265. +
  266. + return 1;
  267. +}
  268. +
  269. +static void ecn_check(unsigned int flags)
  270. +{
  271. + if (!flags)
  272. + xtables_error(PARAMETER_PROBLEM,
  273. + "ECN match: some option required");
  274. +}
  275. +
  276. +static void ecn_print(const void *ip, const struct xt_entry_match *match,
  277. + int numeric)
  278. +{
  279. + const struct xt_ecn_info *einfo =
  280. + (const struct xt_ecn_info *)match->data;
  281. +
  282. + printf(" ECN match ");
  283. +
  284. + if (einfo->operation & XT_ECN_OP_MATCH_ECE) {
  285. + printf(" %sECE",
  286. + (einfo->invert & XT_ECN_OP_MATCH_ECE) ? "!" : "");
  287. + }
  288. +
  289. + if (einfo->operation & XT_ECN_OP_MATCH_CWR) {
  290. + printf(" %sCWR",
  291. + (einfo->invert & XT_ECN_OP_MATCH_CWR) ? "!" : "");
  292. + }
  293. +
  294. + if (einfo->operation & XT_ECN_OP_MATCH_IP) {
  295. + printf(" %sECT=%d",
  296. + (einfo->invert & XT_ECN_OP_MATCH_IP) ? "!" : "",
  297. + einfo->ip_ect);
  298. + }
  299. +}
  300. +
  301. +static void ecn_save(const void *ip, const struct xt_entry_match *match)
  302. +{
  303. + const struct xt_ecn_info *einfo =
  304. + (const struct xt_ecn_info *)match->data;
  305. +
  306. + if (einfo->operation & XT_ECN_OP_MATCH_ECE) {
  307. + if (einfo->invert & XT_ECN_OP_MATCH_ECE)
  308. + printf("! ");
  309. + printf("--ecn-tcp-ece ");
  310. + }
  311. +
  312. + if (einfo->operation & XT_ECN_OP_MATCH_CWR) {
  313. + if (einfo->invert & XT_ECN_OP_MATCH_CWR)
  314. + printf("! ");
  315. + printf("--ecn-tcp-cwr ");
  316. + }
  317. +
  318. + if (einfo->operation & XT_ECN_OP_MATCH_IP) {
  319. + if (einfo->invert & XT_ECN_OP_MATCH_IP)
  320. + printf("! ");
  321. + printf("--ecn-ip-ect %d", einfo->ip_ect);
  322. + }
  323. +}
  324. +
  325. +static struct xtables_match ecn_mt_reg = {
  326. + .name = "ecn",
  327. + .version = XTABLES_VERSION,
  328. + .family = NFPROTO_UNSPEC,
  329. + .size = XT_ALIGN(sizeof(struct xt_ecn_info)),
  330. + .userspacesize = XT_ALIGN(sizeof(struct xt_ecn_info)),
  331. + .help = ecn_help,
  332. + .parse = ecn_parse,
  333. + .final_check = ecn_check,
  334. + .print = ecn_print,
  335. + .save = ecn_save,
  336. + .extra_opts = ecn_opts,
  337. +};
  338. +
  339. +void _init(void)
  340. +{
  341. + xtables_register_match(&ecn_mt_reg);
  342. +}
  343. diff -urNBp iptables/extensions/libxt_ecn.man iptables.ecn/extensions/libxt_ecn.man
  344. --- /dev/null
  345. +++ iptables.ecn/extensions/libxt_ecn.man 2012-03-13 14:40:11.000000000 +0400
  346. @@ -0,0 +1,11 @@
  347. +This allows you to match the ECN bits of the IPv4/IPv6 and TCP header. ECN is the Explicit Congestion Notification mechanism as specified in RFC3168
  348. +.TP
  349. +[\fB!\fP] \fB\-\-ecn\-tcp\-cwr\fP
  350. +This matches if the TCP ECN CWR (Congestion Window Received) bit is set.
  351. +.TP
  352. +[\fB!\fP] \fB\-\-ecn\-tcp\-ece\fP
  353. +This matches if the TCP ECN ECE (ECN Echo) bit is set.
  354. +.TP
  355. +[\fB!\fP] \fB\-\-ecn\-ip\-ect\fP \fInum\fP
  356. +This matches a particular IPv4/IPv6 ECT (ECN-Capable Transport). You have to specify
  357. +a number between `0' and `3'.
  358. diff -urNBp iptables/include/linux/netfilter/xt_ecn.h iptables.ecn/include/linux/netfilter/xt_ecn.h
  359. --- /dev/null
  360. +++ iptables.ecn/include/linux/netfilter/xt_ecn.h 2012-03-13 14:40:11.000000000 +0400
  361. @@ -0,0 +1,33 @@
  362. +/* iptables module for matching the ECN header in IPv4 and TCP header
  363. + *
  364. + * (C) 2002 Harald Welte <laforge@netfilter.org>
  365. + *
  366. + * This software is distributed under GNU GPL v2, 1991
  367. +*/
  368. +#ifndef _XT_ECN_H
  369. +#define _XT_ECN_H
  370. +
  371. +#include <linux/types.h>
  372. +#include <linux/netfilter/xt_dscp.h>
  373. +
  374. +#define XT_ECN_IP_MASK (~XT_DSCP_MASK)
  375. +
  376. +#define XT_ECN_OP_MATCH_IP 0x01
  377. +#define XT_ECN_OP_MATCH_ECE 0x10
  378. +#define XT_ECN_OP_MATCH_CWR 0x20
  379. +
  380. +#define XT_ECN_OP_MATCH_MASK 0xce
  381. +
  382. +/* match info */
  383. +struct xt_ecn_info {
  384. + __u8 operation;
  385. + __u8 invert;
  386. + __u8 ip_ect;
  387. + union {
  388. + struct {
  389. + __u8 ect;
  390. + } tcp;
  391. + } proto;
  392. +};
  393. +
  394. +#endif /* _XT_ECN_H */
  395. diff -urNBp iptables/include/linux/netfilter_ipv4/ipt_ecn.h iptables.ecn/include/linux/netfilter_ipv4/ipt_ecn.h
  396. --- iptables/include/linux/netfilter_ipv4/ipt_ecn.h 2009-04-06 15:09:17.000000000 +0400
  397. +++ /dev/null
  398. @@ -1,33 +0,0 @@
  399. -/* iptables module for matching the ECN header in IPv4 and TCP header
  400. - *
  401. - * (C) 2002 Harald Welte <laforge@gnumonks.org>
  402. - *
  403. - * This software is distributed under GNU GPL v2, 1991
  404. - *
  405. - * ipt_ecn.h,v 1.4 2002/08/05 19:39:00 laforge Exp
  406. -*/
  407. -#ifndef _IPT_ECN_H
  408. -#define _IPT_ECN_H
  409. -#include <linux/netfilter_ipv4/ipt_dscp.h>
  410. -
  411. -#define IPT_ECN_IP_MASK (~IPT_DSCP_MASK)
  412. -
  413. -#define IPT_ECN_OP_MATCH_IP 0x01
  414. -#define IPT_ECN_OP_MATCH_ECE 0x10
  415. -#define IPT_ECN_OP_MATCH_CWR 0x20
  416. -
  417. -#define IPT_ECN_OP_MATCH_MASK 0xce
  418. -
  419. -/* match info */
  420. -struct ipt_ecn_info {
  421. - u_int8_t operation;
  422. - u_int8_t invert;
  423. - u_int8_t ip_ect;
  424. - union {
  425. - struct {
  426. - u_int8_t ect;
  427. - } tcp;
  428. - } proto;
  429. -};
  430. -
  431. -#endif /* _IPT_ECN_H */