All of lore.kernel.org
 help / color / mirror / Atom feed
* libxt_TCPOPTSTRIP(iptables) 20071014
@ 2007-10-14 14:23 Jan Engelhardt
  2007-10-14 15:19 ` Krzysztof Oledzki
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Engelhardt @ 2007-10-14 14:23 UTC (permalink / raw)
  To: Netfilter Developer Mailing List; +Cc: kaber


This version folds in tcp option descriptions.

=== Patch begins here ===

Add libxt_TCPOPTSTRIP.

Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>

---
 extensions/Makefile                      |    2 
 extensions/libxt_TCPOPTSTRIP.c           |  205 +++++++++++++++++++++++++++++++
 include/linux/netfilter/xt_TCPOPTSTRIP.h |   13 +
 3 files changed, 219 insertions(+), 1 deletion(-)

Index: iptables/extensions/Makefile
===================================================================
--- iptables.orig/extensions/Makefile
+++ iptables/extensions/Makefile
@@ -7,7 +7,7 @@
 #
 PF_EXT_SLIB:=ah addrtype conntrack ecn icmp iprange owner policy realm recent tos ttl unclean CLUSTERIP DNAT ECN LOG MASQUERADE MIRROR NETMAP REDIRECT REJECT SAME SNAT TOS TTL ULOG
 PF6_EXT_SLIB:=ah dst eui64 frag hbh hl icmp6 ipv6header mh owner policy rt HL LOG REJECT
-PFX_EXT_SLIB:=connbytes connmark connlimit comment dccp dscp esp hashlimit helper length limit mac mark multiport physdev pkttype quota sctp state statistic standard string tcp tcpmss time u32 udp CLASSIFY CONNMARK DSCP MARK NFLOG NFQUEUE NOTRACK TCPMSS TRACE
+PFX_EXT_SLIB:=connbytes connmark connlimit comment dccp dscp esp hashlimit helper length limit mac mark multiport physdev pkttype quota sctp state statistic standard string tcp tcpmss time u32 udp CLASSIFY CONNMARK DSCP MARK NFLOG NFQUEUE NOTRACK TCPMSS TCPOPTSTRIP TRACE
 
 PF_EXT_SELINUX_SLIB:=
 PF6_EXT_SELINUX_SLIB:=
Index: iptables/extensions/libxt_TCPOPTSTRIP.c
===================================================================
--- /dev/null
+++ iptables/extensions/libxt_TCPOPTSTRIP.c
@@ -0,0 +1,205 @@
+/*
+ * Shared library add-on to iptables to add TCPOPTSTRIP target support.
+ * Copyright (c) 2007 Sven Schnelle <svens@bitebene.org>
+ * Copyright © Jan Engelhardt <jengelh@computergmbh.de>
+ */
+#include <getopt.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <xtables.h>
+#include <linux/netfilter/x_tables.h>
+#include <linux/netfilter/xt_TCPOPTSTRIP.h>
+#ifndef TCPOPT_MD5SIG
+#	define TCPOPT_MD5SIG 19
+#endif
+
+enum {
+	F_STRIP = 1 << 0,
+};
+
+struct tcp_optionmap {
+	const char *name, *desc;
+	const int option;
+};
+
+static const struct option tcpoptstrip_opts[] = {
+	{"strip-options", true, NULL, '0'},
+	{NULL},
+};
+
+static const struct tcp_optionmap tcp_optionmap[] = {
+	{"wscale",         "Window scale",         TCPOPT_WINDOW},
+	{"mss",            "Maximum Segment Size", TCPOPT_MAXSEG},
+	{"sack-permitted", "SACK permitted",       TCPOPT_SACK_PERMITTED},
+	{"sack",           "Selective ACK",        TCPOPT_SACK},
+	{"timestamp",      "Timestamp",            TCPOPT_TIMESTAMP},
+	{"md5",            "MD5 signature",        TCPOPT_MD5SIG},
+	{NULL},
+};
+
+static void tcpoptstrip_help(void)
+{
+	const struct tcp_optionmap *w;
+
+	printf(
+"TCPOPTSTRIP target options:\n"
+"  --strip-options value     strip specified TCP options denoted by value\n"
+"                            (separated by comma) from TCP header\n"
+"  Instead of the numeric value, you can also use the following names:\n"
+	);
+
+	for (w = tcp_optionmap; w->name != NULL; ++w)
+		printf("    %-14s    strip \"%s\" option\n", w->name, w->desc);
+}
+
+static void tcpoptstrip_init(struct xt_entry_target *t)
+{
+	struct xt_tcpoptstrip_info *info = (void *)t->data;
+
+	/* strictly necessary? play safe for now. */
+	memset(info->strip_bmap, 0, sizeof(info->strip_bmap));
+}
+
+static void parse_list(struct xt_tcpoptstrip_info *info, char *arg)
+{
+	unsigned int option;
+	char *p;
+	int i;
+
+	while (true) {
+		p = strchr(arg, ',');
+		if (p != NULL)
+			*p = '\0';
+
+		option = 0;
+		for (i = 0; tcp_optionmap[i].name != NULL; ++i)
+			if (strcmp(tcp_optionmap[i].name, arg) == 0) {
+				option = tcp_optionmap[i].option;
+				break;
+			}
+
+		if (option == 0 && string_to_number(arg, 0, 255, &option) == -1)
+			exit_error(PARAMETER_PROBLEM,
+			           "Bad TCP option value \"%s\"", arg);
+
+		if (option < 2)
+			exit_error(PARAMETER_PROBLEM,
+			           "Option value may not be 0 or 1");
+
+		if (tcpoptstrip_test_bit(info->strip_bmap, option))
+			exit_error(PARAMETER_PROBLEM,
+			           "Option \"%s\" already specified", arg);
+
+		tcpoptstrip_set_bit(info->strip_bmap, option);
+		if (p == NULL)
+			break;
+		arg = p + 1;
+	}
+}
+
+static int tcpoptstrip_parse(int c, char **argv, int invert,
+                             unsigned int *flags, const void *entry,
+                             struct xt_entry_target **target)
+{
+	struct xt_tcpoptstrip_info *info = (void *)(*target)->data;
+
+	switch (c) {
+	case '0':
+		if (*flags & F_STRIP)
+			exit_error(PARAMETER_PROBLEM,
+			           "You can specify --strip-options only once");
+		parse_list(info, optarg);
+		*flags |= F_STRIP;
+		return 1;
+	}
+
+	return 0;
+}
+
+static void tcpoptstrip_check(unsigned int flags)
+{
+	if (flags == 0)
+		exit_error(PARAMETER_PROBLEM,
+		           "TCPOPTSTRIP: At least one of the strip options must be specified");
+}
+
+static void tcpoptstrip_print_list(const struct xt_tcpoptstrip_info *info,
+                                   bool numeric)
+{
+	unsigned int i, j;
+	const char *name;
+	bool first = true;
+
+	for (i = 0; i < 256; ++i) {
+		if (!tcpoptstrip_test_bit(info->strip_bmap, i))
+			continue;
+		if (!first)
+			printf(",");
+
+		first = false;
+		name  = NULL;
+		if (!numeric)
+			for (j = 0; tcp_optionmap[j].name != NULL; ++j)
+				if (tcp_optionmap[j].option == i)
+					name = tcp_optionmap[j].name;
+
+		if (name != NULL)
+			printf("%s", name);
+		else
+			printf("%u", i);
+	}
+}
+
+static void tcpoptstrip_print(const void *ip,
+                              const struct xt_entry_target *target, int numeric)
+{
+	const struct xt_tcpoptstrip_info *info = (const void *)target->data;
+	printf("TCPOPTSTRIP options ");
+	tcpoptstrip_print_list(info, numeric);
+}
+
+static void tcpoptstrip_save(const void *ip,
+                             const struct xt_entry_target *target)
+{
+	const struct xt_tcpoptstrip_info *info = (const void *)target->data;
+	printf("--strip-options ");
+	tcpoptstrip_print_list(info, true);
+}
+
+static struct xtables_target tcpoptstrip_target = {
+	.name          = "TCPOPTSTRIP",
+	.family        = AF_INET,
+	.version       = IPTABLES_VERSION,
+	.size          = XT_ALIGN(sizeof(struct xt_tcpoptstrip_info)),
+	.userspacesize = XT_ALIGN(sizeof(struct xt_tcpoptstrip_info)),
+	.help          = tcpoptstrip_help,
+	.init          = tcpoptstrip_init,
+	.parse         = tcpoptstrip_parse,
+	.final_check   = tcpoptstrip_check,
+	.print         = tcpoptstrip_print,
+	.save          = tcpoptstrip_save,
+	.extra_opts    = tcpoptstrip_opts,
+};
+
+static struct xtables_target tcpoptstrip_target6 = {
+	.name          = "TCPOPTSTRIP",
+	.family        = AF_INET6,
+	.version       = IPTABLES_VERSION,
+	.size          = XT_ALIGN(sizeof(struct xt_tcpoptstrip_info)),
+	.userspacesize = XT_ALIGN(sizeof(struct xt_tcpoptstrip_info)),
+	.help          = tcpoptstrip_help,
+	.init          = tcpoptstrip_init,
+	.parse         = tcpoptstrip_parse,
+	.final_check   = tcpoptstrip_check,
+	.print         = tcpoptstrip_print,
+	.save          = tcpoptstrip_save,
+	.extra_opts    = tcpoptstrip_opts,
+};
+
+void _init(void)
+{
+	xtables_register_target(&tcpoptstrip_target);
+	xtables_register_target(&tcpoptstrip_target6);
+}
Index: iptables/include/linux/netfilter/xt_TCPOPTSTRIP.h
===================================================================
--- /dev/null
+++ iptables/include/linux/netfilter/xt_TCPOPTSTRIP.h
@@ -0,0 +1,13 @@
+#ifndef _XT_TCPOPTSTRIP_H
+#define _XT_TCPOPTSTRIP_H
+
+#define tcpoptstrip_set_bit(bmap, idx) \
+	(bmap[(idx) >> 5] |= 1UL << (idx & 31))
+#define tcpoptstrip_test_bit(bmap, idx) \
+	(((1UL << (idx & 31)) & bmap[(idx) >> 5]) != 0)
+
+struct xt_tcpoptstrip_info {
+	u_int32_t strip_bmap[8];
+};
+
+#endif /* _XT_TCPOPTSTRIP_H */

-
To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libxt_TCPOPTSTRIP(iptables) 20071014
  2007-10-14 14:23 libxt_TCPOPTSTRIP(iptables) 20071014 Jan Engelhardt
@ 2007-10-14 15:19 ` Krzysztof Oledzki
  2007-10-16 14:48   ` Jan Engelhardt
  0 siblings, 1 reply; 3+ messages in thread
From: Krzysztof Oledzki @ 2007-10-14 15:19 UTC (permalink / raw)
  To: Jan Engelhardt; +Cc: Netfilter Developer Mailing List, kaber

[-- Attachment #1: Type: TEXT/PLAIN, Size: 1206 bytes --]



On Sun, 14 Oct 2007, Jan Engelhardt wrote:

>
> This version folds in tcp option descriptions.
>
> === Patch begins here ===
>
> Add libxt_TCPOPTSTRIP.
>
> Signed-off-by: Jan Engelhardt <jengelh@computergmbh.de>
<CUT>
> +struct tcp_optionmap {
> +	const char *name, *desc;
> +	const int option;
> +};
> +
> +static const struct option tcpoptstrip_opts[] = {
> +	{"strip-options", true, NULL, '0'},
> +	{NULL},
> +};
> +
> +static const struct tcp_optionmap tcp_optionmap[] = {
> +	{"wscale",         "Window scale",         TCPOPT_WINDOW},
> +	{"mss",            "Maximum Segment Size", TCPOPT_MAXSEG},
> +	{"sack-permitted", "SACK permitted",       TCPOPT_SACK_PERMITTED},
> +	{"sack",           "Selective ACK",        TCPOPT_SACK},
> +	{"timestamp",      "Timestamp",            TCPOPT_TIMESTAMP},
> +	{"md5",            "MD5 signature",        TCPOPT_MD5SIG},
> +	{NULL},
> +};

Ahh, good. Thank you for considering my suggestions.

Just cosmetic: what about making it up to 
http://www.iana.org/assignments/tcp-parameters:

s/Window scale/Window Scale/
s/SACK permitted/SACK Permitted/
s/MD5 signature/MD5 Signature/

Best regards,

 				Krzysztof Olędzki

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: libxt_TCPOPTSTRIP(iptables) 20071014
  2007-10-14 15:19 ` Krzysztof Oledzki
@ 2007-10-16 14:48   ` Jan Engelhardt
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Engelhardt @ 2007-10-16 14:48 UTC (permalink / raw)
  To: Krzysztof Oledzki; +Cc: Netfilter Developer Mailing List, kaber


On Oct 14 2007 17:19, Krzysztof Oledzki wrote:
> On Sun, 14 Oct 2007, Jan Engelhardt wrote:
>
>> +static const struct tcp_optionmap tcp_optionmap[] = {
>> +	{"wscale",         "Window scale",         TCPOPT_WINDOW},
>> +	{"mss",            "Maximum Segment Size", TCPOPT_MAXSEG},
>> +	{"sack-permitted", "SACK permitted",       TCPOPT_SACK_PERMITTED},
>> +	{"sack",           "Selective ACK",        TCPOPT_SACK},
>> +	{"timestamp",      "Timestamp",            TCPOPT_TIMESTAMP},
>> +	{"md5",            "MD5 signature",        TCPOPT_MD5SIG},
>> +	{NULL},
>> +};
>
> Ahh, good. Thank you for considering my suggestions.
>
> Just cosmetic: what about making it up to
> http://www.iana.org/assignments/tcp-parameters:
>
> s/Window scale/Window Scale/
> s/SACK permitted/SACK Permitted/
> s/MD5 signature/MD5 Signature/

I think there is a limit to pedantry :)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-10-16 14:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-14 14:23 libxt_TCPOPTSTRIP(iptables) 20071014 Jan Engelhardt
2007-10-14 15:19 ` Krzysztof Oledzki
2007-10-16 14:48   ` Jan Engelhardt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.