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 static void __TCPMSS_help(int hdrsize)
22 "TCPMSS target mutually-exclusive options:\n"
23 " --set-mss value explicitly set MSS option to specified value\n"
24 " --clamp-mss-to-pmtu automatically clamp MSS value to (path_MTU - %d)\n",
28 static void TCPMSS_help(void)
33 static void TCPMSS_help6(void)
38 static const struct option TCPMSS_opts[] = {
39 { "set-mss", 1, NULL, '1' },
40 { "clamp-mss-to-pmtu", 0, NULL, '2' },
44 static int __TCPMSS_parse(int c, char **argv, int invert, unsigned int *flags,
45 const void *entry, struct xt_entry_target **target,
48 struct xt_tcpmss_info *mssinfo
49 = (struct xt_tcpmss_info *)(*target)->data;
56 xtables_error(PARAMETER_PROBLEM,
57 "TCPMSS target: Only one option may be specified");
58 if (!xtables_strtoui(optarg, NULL, &mssval,
59 0, UINT16_MAX - hdrsize))
60 xtables_error(PARAMETER_PROBLEM, "Bad TCPMSS value \"%s\"", optarg);
62 mssinfo->mss = mssval;
68 xtables_error(PARAMETER_PROBLEM,
69 "TCPMSS target: Only one option may be specified");
70 mssinfo->mss = XT_TCPMSS_CLAMP_PMTU;
81 static int TCPMSS_parse(int c, char **argv, int invert, unsigned int *flags,
82 const void *entry, struct xt_entry_target **target)
84 return __TCPMSS_parse(c, argv, invert, flags, entry, target, 40);
87 static int TCPMSS_parse6(int c, char **argv, int invert, unsigned int *flags,
88 const void *entry, struct xt_entry_target **target)
90 return __TCPMSS_parse(c, argv, invert, flags, entry, target, 60);
93 static void TCPMSS_check(unsigned int flags)
96 xtables_error(PARAMETER_PROBLEM,
97 "TCPMSS target: At least one parameter is required");
100 static void TCPMSS_print(const void *ip, const struct xt_entry_target *target,
103 const struct xt_tcpmss_info *mssinfo =
104 (const struct xt_tcpmss_info *)target->data;
105 if(mssinfo->mss == XT_TCPMSS_CLAMP_PMTU)
106 printf("TCPMSS clamp to PMTU ");
108 printf("TCPMSS set %u ", mssinfo->mss);
111 static void TCPMSS_save(const void *ip, const struct xt_entry_target *target)
113 const struct xt_tcpmss_info *mssinfo =
114 (const struct xt_tcpmss_info *)target->data;
116 if(mssinfo->mss == XT_TCPMSS_CLAMP_PMTU)
117 printf("--clamp-mss-to-pmtu ");
119 printf("--set-mss %u ", mssinfo->mss);
122 static struct xtables_target tcpmss_target = {
123 .family = NFPROTO_IPV4,
125 .version = XTABLES_VERSION,
126 .size = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
127 .userspacesize = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
129 .parse = TCPMSS_parse,
130 .final_check = TCPMSS_check,
131 .print = TCPMSS_print,
133 .extra_opts = TCPMSS_opts,
136 static struct xtables_target tcpmss_target6 = {
137 .family = NFPROTO_IPV6,
139 .version = XTABLES_VERSION,
140 .size = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
141 .userspacesize = XT_ALIGN(sizeof(struct xt_tcpmss_info)),
142 .help = TCPMSS_help6,
143 .parse = TCPMSS_parse6,
144 .final_check = TCPMSS_check,
145 .print = TCPMSS_print,
147 .extra_opts = TCPMSS_opts,
152 xtables_register_target(&tcpmss_target);
153 xtables_register_target(&tcpmss_target6);