| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 1 | /* Shared library add-on to iptables to add string matching support. |
| 2 | * |
| 3 | * Copyright (C) 2000 Emmanuel Roger <winfield@freegates.be> |
| András Kis-Szabó | 764316a | 2001-02-26 17:31:20 +0000 | [diff] [blame] | 4 | * |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 5 | * 2005-08-05 Pablo Neira Ayuso <pablo@eurodev.net> |
| 6 | * - reimplemented to use new string matching iptables match |
| 7 | * - add functionality to match packets by using window offsets |
| 8 | * - add functionality to select the string matching algorithm |
| 9 | * |
| András Kis-Szabó | 764316a | 2001-02-26 17:31:20 +0000 | [diff] [blame] | 10 | * ChangeLog |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 11 | * 29.12.2003: Michael Rash <mbr@cipherdyne.org> |
| 12 | * Fixed iptables save/restore for ascii strings |
| 13 | * that contain space chars, and hex strings that |
| 14 | * contain embedded NULL chars. Updated to print |
| 15 | * strings in hex mode if any non-printable char |
| 16 | * is contained within the string. |
| 17 | * |
| András Kis-Szabó | 764316a | 2001-02-26 17:31:20 +0000 | [diff] [blame] | 18 | * 27.01.2001: Gianni Tedesco <gianni@ecsc.co.uk> |
| 19 | * Changed --tos to --string in save(). Also |
| 20 | * updated to work with slightly modified |
| 21 | * ipt_string_info. |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 22 | */ |
| 23 | #include <stdio.h> |
| 24 | #include <netdb.h> |
| 25 | #include <string.h> |
| 26 | #include <stdlib.h> |
| 27 | #include <getopt.h> |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 28 | #include <ctype.h> |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 29 | #include <xtables.h> |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 30 | #include <stddef.h> |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 31 | #include <linux/netfilter/xt_string.h> |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 32 | |
| 33 | /* Function which prints out usage message. */ |
| 34 | static void |
| 35 | help(void) |
| 36 | { |
| 37 | printf( |
| 38 | "STRING match v%s options:\n" |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 39 | "--from Offset to start searching from\n" |
| 40 | "--to Offset to stop searching\n" |
| 41 | "--algo Algorithm\n" |
| Michael Rash | 96d8593 | 2003-04-21 07:27:03 +0000 | [diff] [blame] | 42 | "--string [!] string Match a string in a packet\n" |
| 43 | "--hex-string [!] string Match a hex string in a packet\n", |
| Harald Welte | 80fe35d | 2002-05-29 13:08:15 +0000 | [diff] [blame] | 44 | IPTABLES_VERSION); |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| Jan Engelhardt | 661f112 | 2007-07-30 14:46:51 +0000 | [diff] [blame] | 47 | static const struct option opts[] = { |
| Patrick McHardy | 500f483 | 2007-09-08 15:59:04 +0000 | [diff] [blame] | 48 | { "from", 1, NULL, '1' }, |
| 49 | { "to", 1, NULL, '2' }, |
| 50 | { "algo", 1, NULL, '3' }, |
| 51 | { "string", 1, NULL, '4' }, |
| 52 | { "hex-string", 1, NULL, '5' }, |
| 53 | { } |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 56 | static void |
| Peter Riley | ea146a9 | 2007-09-02 13:09:07 +0000 | [diff] [blame] | 57 | init(struct xt_entry_match *m) |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 58 | { |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 59 | struct xt_string_info *i = (struct xt_string_info *) m->data; |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 60 | |
| 61 | if (i->to_offset == 0) |
| 62 | i->to_offset = (u_int16_t) ~0UL; |
| 63 | } |
| 64 | |
| 65 | static void |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 66 | parse_string(const char *s, struct xt_string_info *info) |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 67 | { |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 68 | if (strlen(s) <= XT_STRING_MAX_PATTERN_SIZE) { |
| 69 | strncpy(info->pattern, s, XT_STRING_MAX_PATTERN_SIZE); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 70 | info->patlen = strlen(s); |
| 71 | return; |
| 72 | } |
| 73 | exit_error(PARAMETER_PROBLEM, "STRING too long `%s'", s); |
| Michael Rash | 96d8593 | 2003-04-21 07:27:03 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 76 | static void |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 77 | parse_algo(const char *s, struct xt_string_info *info) |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 78 | { |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 79 | if (strlen(s) <= XT_STRING_MAX_ALGO_NAME_SIZE) { |
| 80 | strncpy(info->algo, s, XT_STRING_MAX_ALGO_NAME_SIZE); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 81 | return; |
| 82 | } |
| 83 | exit_error(PARAMETER_PROBLEM, "ALGO too long `%s'", s); |
| 84 | } |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 85 | |
| Michael Rash | 96d8593 | 2003-04-21 07:27:03 +0000 | [diff] [blame] | 86 | static void |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 87 | parse_hex_string(const char *s, struct xt_string_info *info) |
| Michael Rash | 96d8593 | 2003-04-21 07:27:03 +0000 | [diff] [blame] | 88 | { |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 89 | int i=0, slen, sindex=0, schar; |
| 90 | short hex_f = 0, literal_f = 0; |
| 91 | char hextmp[3]; |
| 92 | |
| 93 | slen = strlen(s); |
| 94 | |
| 95 | if (slen == 0) { |
| 96 | exit_error(PARAMETER_PROBLEM, |
| 97 | "STRING must contain at least one char"); |
| 98 | } |
| 99 | |
| 100 | while (i < slen) { |
| 101 | if (s[i] == '\\' && !hex_f) { |
| 102 | literal_f = 1; |
| 103 | } else if (s[i] == '\\') { |
| 104 | exit_error(PARAMETER_PROBLEM, |
| 105 | "Cannot include literals in hex data"); |
| 106 | } else if (s[i] == '|') { |
| 107 | if (hex_f) |
| 108 | hex_f = 0; |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 109 | else { |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 110 | hex_f = 1; |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 111 | /* get past any initial whitespace just after the '|' */ |
| 112 | while (s[i+1] == ' ') |
| 113 | i++; |
| 114 | } |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 115 | if (i+1 >= slen) |
| 116 | break; |
| 117 | else |
| 118 | i++; /* advance to the next character */ |
| 119 | } |
| 120 | |
| 121 | if (literal_f) { |
| 122 | if (i+1 >= slen) { |
| 123 | exit_error(PARAMETER_PROBLEM, |
| 124 | "Bad literal placement at end of string"); |
| 125 | } |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 126 | info->pattern[sindex] = s[i+1]; |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 127 | i += 2; /* skip over literal char */ |
| 128 | literal_f = 0; |
| 129 | } else if (hex_f) { |
| 130 | if (i+1 >= slen) { |
| 131 | exit_error(PARAMETER_PROBLEM, |
| 132 | "Odd number of hex digits"); |
| 133 | } |
| 134 | if (i+2 >= slen) { |
| 135 | /* must end with a "|" */ |
| 136 | exit_error(PARAMETER_PROBLEM, "Invalid hex block"); |
| 137 | } |
| Michael Rash | 96d8593 | 2003-04-21 07:27:03 +0000 | [diff] [blame] | 138 | if (! isxdigit(s[i])) /* check for valid hex char */ |
| 139 | exit_error(PARAMETER_PROBLEM, "Invalid hex char `%c'", s[i]); |
| 140 | if (! isxdigit(s[i+1])) /* check for valid hex char */ |
| 141 | exit_error(PARAMETER_PROBLEM, "Invalid hex char `%c'", s[i+1]); |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 142 | hextmp[0] = s[i]; |
| 143 | hextmp[1] = s[i+1]; |
| 144 | hextmp[2] = '\0'; |
| 145 | if (! sscanf(hextmp, "%x", &schar)) |
| 146 | exit_error(PARAMETER_PROBLEM, |
| 147 | "Invalid hex char `%c'", s[i]); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 148 | info->pattern[sindex] = (char) schar; |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 149 | if (s[i+2] == ' ') |
| 150 | i += 3; /* spaces included in the hex block */ |
| 151 | else |
| 152 | i += 2; |
| 153 | } else { /* the char is not part of hex data, so just copy */ |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 154 | info->pattern[sindex] = s[i]; |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 155 | i++; |
| 156 | } |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 157 | if (sindex > XT_STRING_MAX_PATTERN_SIZE) |
| Michael Rash | f8ac329 | 2003-02-26 17:34:13 +0000 | [diff] [blame] | 158 | exit_error(PARAMETER_PROBLEM, "STRING too long `%s'", s); |
| 159 | sindex++; |
| 160 | } |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 161 | info->patlen = sindex; |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 164 | #define STRING 0x1 |
| 165 | #define ALGO 0x2 |
| 166 | #define FROM 0x4 |
| 167 | #define TO 0x8 |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 168 | |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 169 | /* Function which parses command options; returns true if it |
| 170 | ate an option */ |
| 171 | static int |
| 172 | parse(int c, char **argv, int invert, unsigned int *flags, |
| Yasuyuki KOZAKAI | c0a9ab9 | 2007-07-24 06:02:05 +0000 | [diff] [blame] | 173 | const void *entry, |
| Yasuyuki KOZAKAI | 193df8e | 2007-07-24 05:57:28 +0000 | [diff] [blame] | 174 | struct xt_entry_match **match) |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 175 | { |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 176 | struct xt_string_info *stringinfo = (struct xt_string_info *)(*match)->data; |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 177 | |
| 178 | switch (c) { |
| 179 | case '1': |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 180 | if (*flags & FROM) |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 181 | exit_error(PARAMETER_PROBLEM, |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 182 | "Can't specify multiple --from"); |
| 183 | stringinfo->from_offset = atoi(optarg); |
| 184 | *flags |= FROM; |
| 185 | break; |
| 186 | case '2': |
| 187 | if (*flags & TO) |
| 188 | exit_error(PARAMETER_PROBLEM, |
| 189 | "Can't specify multiple --to"); |
| 190 | stringinfo->to_offset = atoi(optarg); |
| 191 | *flags |= TO; |
| 192 | break; |
| 193 | case '3': |
| 194 | if (*flags & ALGO) |
| 195 | exit_error(PARAMETER_PROBLEM, |
| 196 | "Can't specify multiple --algo"); |
| 197 | parse_algo(optarg, stringinfo); |
| 198 | *flags |= ALGO; |
| 199 | break; |
| 200 | case '4': |
| 201 | if (*flags & STRING) |
| 202 | exit_error(PARAMETER_PROBLEM, |
| 203 | "Can't specify multiple --string"); |
| Harald Welte | b77f1da | 2002-03-14 11:35:58 +0000 | [diff] [blame] | 204 | check_inverse(optarg, &invert, &optind, 0); |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 205 | parse_string(argv[optind-1], stringinfo); |
| 206 | if (invert) |
| 207 | stringinfo->invert = 1; |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 208 | stringinfo->patlen=strlen((char *)&stringinfo->pattern); |
| 209 | *flags |= STRING; |
| Michael Rash | 96d8593 | 2003-04-21 07:27:03 +0000 | [diff] [blame] | 210 | break; |
| 211 | |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 212 | case '5': |
| 213 | if (*flags & STRING) |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 214 | exit_error(PARAMETER_PROBLEM, |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 215 | "Can't specify multiple --hex-string"); |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 216 | |
| Michael Rash | 96d8593 | 2003-04-21 07:27:03 +0000 | [diff] [blame] | 217 | check_inverse(optarg, &invert, &optind, 0); |
| 218 | parse_hex_string(argv[optind-1], stringinfo); /* sets length */ |
| 219 | if (invert) |
| 220 | stringinfo->invert = 1; |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 221 | *flags |= STRING; |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 222 | break; |
| 223 | |
| 224 | default: |
| 225 | return 0; |
| 226 | } |
| 227 | return 1; |
| 228 | } |
| 229 | |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 230 | |
| 231 | /* Final check; must have specified --string. */ |
| 232 | static void |
| 233 | final_check(unsigned int flags) |
| 234 | { |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 235 | if (!(flags & STRING)) |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 236 | exit_error(PARAMETER_PROBLEM, |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 237 | "STRING match: You must specify `--string' or " |
| 238 | "`--hex-string'"); |
| 239 | if (!(flags & ALGO)) |
| 240 | exit_error(PARAMETER_PROBLEM, |
| 241 | "STRING match: You must specify `--algo'"); |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 244 | /* Test to see if the string contains non-printable chars or quotes */ |
| 245 | static unsigned short int |
| 246 | is_hex_string(const char *str, const unsigned short int len) |
| 247 | { |
| 248 | unsigned int i; |
| 249 | for (i=0; i < len; i++) |
| 250 | if (! isprint(str[i])) |
| 251 | return 1; /* string contains at least one non-printable char */ |
| 252 | /* use hex output if the last char is a "\" */ |
| 253 | if ((unsigned char) str[len-1] == 0x5c) |
| 254 | return 1; |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | /* Print string with "|" chars included as one would pass to --hex-string */ |
| 259 | static void |
| 260 | print_hex_string(const char *str, const unsigned short int len) |
| 261 | { |
| 262 | unsigned int i; |
| 263 | /* start hex block */ |
| 264 | printf("\"|"); |
| 265 | for (i=0; i < len; i++) { |
| 266 | /* see if we need to prepend a zero */ |
| 267 | if ((unsigned char) str[i] <= 0x0F) |
| 268 | printf("0%x", (unsigned char) str[i]); |
| 269 | else |
| 270 | printf("%x", (unsigned char) str[i]); |
| 271 | } |
| 272 | /* close hex block */ |
| 273 | printf("|\" "); |
| 274 | } |
| 275 | |
| 276 | static void |
| 277 | print_string(const char *str, const unsigned short int len) |
| 278 | { |
| 279 | unsigned int i; |
| 280 | printf("\""); |
| 281 | for (i=0; i < len; i++) { |
| 282 | if ((unsigned char) str[i] == 0x22) /* escape any embedded quotes */ |
| 283 | printf("%c", 0x5c); |
| 284 | printf("%c", (unsigned char) str[i]); |
| 285 | } |
| 286 | printf("\" "); /* closing space and quote */ |
| 287 | } |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 288 | |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 289 | /* Prints out the matchinfo. */ |
| 290 | static void |
| Yasuyuki KOZAKAI | c0a9ab9 | 2007-07-24 06:02:05 +0000 | [diff] [blame] | 291 | print(const void *ip, |
| Yasuyuki KOZAKAI | 193df8e | 2007-07-24 05:57:28 +0000 | [diff] [blame] | 292 | const struct xt_entry_match *match, |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 293 | int numeric) |
| 294 | { |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 295 | const struct xt_string_info *info = |
| 296 | (const struct xt_string_info*) match->data; |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 297 | |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 298 | if (is_hex_string(info->pattern, info->patlen)) { |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 299 | printf("STRING match %s", (info->invert) ? "!" : ""); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 300 | print_hex_string(info->pattern, info->patlen); |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 301 | } else { |
| 302 | printf("STRING match %s", (info->invert) ? "!" : ""); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 303 | print_string(info->pattern, info->patlen); |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 304 | } |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 305 | printf("ALGO name %s ", info->algo); |
| 306 | if (info->from_offset != 0) |
| 307 | printf("FROM %u ", info->from_offset); |
| 308 | if (info->to_offset != 0) |
| Patrick McHardy | 8a0b6ea | 2007-01-11 08:23:17 +0000 | [diff] [blame] | 309 | printf("TO %u ", info->to_offset); |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 310 | } |
| 311 | |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 312 | |
| 313 | /* Saves the union ipt_matchinfo in parseable form to stdout. */ |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 314 | static void |
| Yasuyuki KOZAKAI | c0a9ab9 | 2007-07-24 06:02:05 +0000 | [diff] [blame] | 315 | save(const void *ip, const struct xt_entry_match *match) |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 316 | { |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 317 | const struct xt_string_info *info = |
| 318 | (const struct xt_string_info*) match->data; |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 319 | |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 320 | if (is_hex_string(info->pattern, info->patlen)) { |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 321 | printf("--hex-string %s", (info->invert) ? "! ": ""); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 322 | print_hex_string(info->pattern, info->patlen); |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 323 | } else { |
| 324 | printf("--string %s", (info->invert) ? "! ": ""); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 325 | print_string(info->pattern, info->patlen); |
| Michael Rash | b807fb3 | 2004-01-05 09:50:12 +0000 | [diff] [blame] | 326 | } |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 327 | printf("--algo %s ", info->algo); |
| 328 | if (info->from_offset != 0) |
| Michael Rash | 0829a2b | 2006-01-30 09:02:45 +0000 | [diff] [blame] | 329 | printf("--from %u ", info->from_offset); |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 330 | if (info->to_offset != 0) |
| Michael Rash | 0829a2b | 2006-01-30 09:02:45 +0000 | [diff] [blame] | 331 | printf("--to %u ", info->to_offset); |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 332 | } |
| 333 | |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 334 | |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 335 | static struct xtables_match string = { |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 336 | .name = "string", |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 337 | .family = AF_INET, |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 338 | .version = IPTABLES_VERSION, |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 339 | .size = XT_ALIGN(sizeof(struct xt_string_info)), |
| 340 | .userspacesize = offsetof(struct xt_string_info, config), |
| Pablo Neira | c6fbf41 | 2005-08-28 08:09:44 +0000 | [diff] [blame] | 341 | .help = help, |
| 342 | .init = init, |
| 343 | .parse = parse, |
| 344 | .final_check = final_check, |
| 345 | .print = print, |
| 346 | .save = save, |
| 347 | .extra_opts = opts |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 348 | }; |
| 349 | |
| Stephane Ouellette | 451f3ea | 2003-04-27 12:59:00 +0000 | [diff] [blame] | 350 | |
| Yasuyuki KOZAKAI | 4ccb6f5 | 2007-07-24 06:52:16 +0000 | [diff] [blame] | 351 | static struct xtables_match string6 = { |
| 352 | .name = "string", |
| 353 | .family = AF_INET6, |
| 354 | .version = IPTABLES_VERSION, |
| 355 | .size = XT_ALIGN(sizeof(struct xt_string_info)), |
| 356 | .userspacesize = offsetof(struct xt_string_info, config), |
| 357 | .help = help, |
| 358 | .init = init, |
| 359 | .parse = parse, |
| 360 | .final_check = final_check, |
| 361 | .print = print, |
| 362 | .save = save, |
| 363 | .extra_opts = opts |
| 364 | }; |
| 365 | |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 366 | void _init(void) |
| 367 | { |
| Yasuyuki KOZAKAI | 6ac58e3 | 2007-07-24 06:50:03 +0000 | [diff] [blame] | 368 | xtables_register_match(&string); |
| Yasuyuki KOZAKAI | 4ccb6f5 | 2007-07-24 06:52:16 +0000 | [diff] [blame] | 369 | xtables_register_match(&string6); |
| Emmanuel Roger | 3071913 | 2000-10-04 15:19:31 +0000 | [diff] [blame] | 370 | } |