1 /* Shared library add-on to iptables to add TCPMSS target support.
3 * Copyright (c) 2000 Marc Boucher
11 #include <linux/netfilter/x_tables.h>
12 #include <linux/netfilter/xt_TCPMSS.h>
15 struct xt_entry_target t;
16 struct xt_tcpmss_info mss;
19 /* Function which prints out usage message. */
20 static void __TCPMSS_help(int hdrsize)
23 "TCPMSS target mutually-exclusive options:\n"
24 " --set-mss value explicitly set MSS option to specified value\n"
25 " --clamp-mss-to-pmtu automatically clamp MSS value to (path_MTU - %d)\n",
29 static void TCPMSS_help(void)
34 static void TCPMSS_help6(void)
39 static const struct option TCPMSS_opts[] = {
40 { "set-mss", 1, NULL, '1' },
41 { "clamp-mss-to-pmtu", 0, NULL, '2' },
45 /* Function which parses command options; returns true if it
47 static int __TCPMSS_parse(int c, char **argv, int invert, unsigned int *flags,
48 const void *entry, struct xt_entry_target **target,
51 struct xt_tcpmss_info *mssinfo
52 = (struct xt_tcpmss_info *)(*target)->data;
59 exit_error(PARAMETER_PROBLEM,
60 "TCPMSS target: Only one option may be specified");
61 if (string_to_number(optarg, 0, 65535 - hdrsize, &mssval) == -1)
62 exit_error(PARAMETER_PROBLEM, "Bad TCPMSS value `%s'", optarg);
64 mssinfo->mss = mssval;
70 exit_error(PARAMETER_PROBLEM,
71 "TCPMSS target: Only one option may be specified");
72 mssinfo->mss = XT_TCPMSS_CLAMP_PMTU;
83 static int TCPMSS_parse(int c, char **argv, int invert, unsigned int *flags,
84 const void *entry, struct xt_entry_target **target)
86 return __TCPMSS_parse(c, argv, invert, flags, entry, target, 40);
89 static int TCPMSS_parse6(int c, char **argv, int invert, unsigned int *flags,
90 const void *entry, struct xt_entry_target **target)
92 return __TCPMSS_parse(c, argv, invert, flags, entry, target, 60);
95 static void TCPMSS_check(unsigned int flags)
98 exit_error(PARAMETER_PROBLEM,
99 "TCPMSS target: At least one parameter is required");
102 /* Prints out the targinfo. */
103 static void TCPMSS_print(const void *ip, const struct xt_entry_target *target,
106 const struct xt_tcpmss_info *mssinfo =
107 (const struct xt_tcpmss_info *)target->data;
108 if(mssinfo->mss == XT_TCPMSS_CLAMP_PMTU)
109 printf("TCPMSS clamp to PMTU ");
111 printf("TCPMSS set %u ", mssinfo->mss);
114 /* Saves the union ipt_targinfo in parsable form to stdout. */
115 static void TCPMSS_save(const void *ip, const struct xt_entry_target *target)
117 const struct xt_tcpmss_info *mssinfo =
118 (const struct xt_tcpmss_info *)target->data;
120 if(mssinfo->mss == XT_TCPMSS_CLAMP_PMTU)
121 printf("--clamp-mss-to-pmtu ");
123 printf("--set-mss %u ", mssinfo->mss);
126 static struct xtables_target tcpmss_target = {
129 .version = XTABLES_VERSION,
130 .size = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
131 .userspacesize = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
133 .parse = TCPMSS_parse,
134 .final_check = TCPMSS_check,
135 .print = TCPMSS_print,
137 .extra_opts = TCPMSS_opts,
140 static struct xtables_target tcpmss_target6 = {
143 .version = XTABLES_VERSION,
144 .size = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
145 .userspacesize = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
146 .help = TCPMSS_help6,
147 .parse = TCPMSS_parse6,
148 .final_check = TCPMSS_check,
149 .print = TCPMSS_print,
151 .extra_opts = TCPMSS_opts,
156 xtables_register_target(&tcpmss_target);
157 xtables_register_target(&tcpmss_target6);