Skip to contentSkip to conversation

iptables: string extension case insensitive matching

PATCH In review Joonwoo Park 1 participant 1 message Jun 21, 2008 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 8/8 iptables: string extension case insensitive matching

The string extension can search patterns case insensitively with --icase option.

---
 extensions/libxt_string.c           |   12 ++++++++++++
 include/linux/netfilter/xt_string.h |    1 +
 2 files changed, 13 insertions(+), 0 deletions(-)
extensions/libxt_string.c +13 -1
index 5eec44b..b8220ef 100644
@@ -38,6 +38,7 @@ static void string_help(void)
 "--from                       Offset to start searching from\n"
 "--to                         Offset to stop searching\n"
-"--algo	                      Algorithm\n"
+"--algo                       Algorithm\n"
+"--icase                      Ignore case (default: 0)\n"
 "[!] --string string          Match a string in a packet\n"
 "[!] --hex-string string      Match a hex string in a packet\n");
 }
@@ -48,6 +49,7 @@ static const struct option string_opts[] = {
 	{ "algo", 1, NULL, '3' },
 	{ "string", 1, NULL, '4' },
 	{ "hex-string", 1, NULL, '5' },
+	{ "icase", 0, NULL, '6' },
 	{ .name = NULL }
 };
 
@@ -162,6 +164,7 @@ parse_hex_string(const char *s, struct xt_string_info *info)
 #define ALGO   0x2
 #define FROM   0x4
 #define TO     0x8
+#define ICASE  0x10
 
 /* Function which parses command options; returns true if it
    ate an option */
@@ -217,6 +220,11 @@ string_parse(int c, char **argv, int invert, unsigned int *flags,
 		*flags |= STRING;
 		break;
 
+	case '6':
+		stringinfo->icase = 1;
+		*flags |= ICASE;
+		break;
+
 	default:
 		return 0;
 	}
@@ -300,6 +308,8 @@ string_print(const void *ip, const struct xt_entry_match *match, int numeric)
 		printf("FROM %u ", info->from_offset);
 	if (info->to_offset != 0)
 		printf("TO %u ", info->to_offset);
+	if (info->icase != 0)
+		printf("ICASE ");
 }
 
 
@@ -321,6 +331,8 @@ static void string_save(const void *ip, const struct xt_entry_match *match)
 		printf("--from %u ", info->from_offset);
 	if (info->to_offset != 0)
 		printf("--to %u ", info->to_offset);
+	if (info->icase != 0)
+		printf("--icase ");
 }
 
 
include/linux/netfilter/xt_string.h +1 -0
index bb21dd1..dfd347f 100644
@@ -12,6 +12,7 @@ struct xt_string_info
 	char 	  pattern[XT_STRING_MAX_PATTERN_SIZE];
 	u_int8_t  patlen;
 	u_int8_t  invert;
+	u_int8_t  icase;
 
 	/* Used internally by the kernel */
 	struct ts_config __attribute__((aligned(8))) *config;
Signature · 1 line
1.5.4.3