1 /* Shared library add-on to ip6tables to add packet length matching support. */
10 #include <linux/netfilter_ipv6/ip6t_length.h>
12 /* Function which prints out usage message. */
17 "length v%s options:\n"
18 "[!] --length length[:length] Match packet length against value or range\n"
19 " of values (inclusive)\n",
24 static struct option opts[] = {
25 { "length", 1, 0, '1' },
29 /* Initialize the match. */
31 init(struct ip6t_entry_match *m, unsigned int *nfcache)
33 *nfcache |= NFC_UNKNOWN;
37 parse_length(const char *s)
42 if (string_to_number(s, 0, 0xFFFF, &len) == -1)
43 exit_error(PARAMETER_PROBLEM, "length invalid: `%s'\n", s);
45 return (u_int16_t )len;
48 /* If a single value is provided, min and max are both set to the value */
50 parse_lengths(const char *s, struct ip6t_length_info *info)
56 if ((cp = strchr(buffer, ':')) == NULL)
57 info->min = info->max = parse_length(buffer);
62 info->min = buffer[0] ? parse_length(buffer) : 0;
63 info->max = cp[0] ? parse_length(cp) : 0xFFFF;
67 if (info->min > info->max)
68 exit_error(PARAMETER_PROBLEM,
69 "length min. range value `%u' greater than max. "
70 "range value `%u'", info->min, info->max);
74 /* Function which parses command options; returns true if it
77 parse(int c, char **argv, int invert, unsigned int *flags,
78 const struct ip6t_entry *entry,
79 unsigned int *nfcache,
80 struct ip6t_entry_match **match)
82 struct ip6t_length_info *info = (struct ip6t_length_info *)(*match)->data;
87 exit_error(PARAMETER_PROBLEM,
88 "length: `--length' may only be "
90 check_inverse(optarg, &invert, &optind, 0);
91 parse_lengths(argv[optind-1], info);
103 /* Final check; must have specified --length. */
105 final_check(unsigned int flags)
108 exit_error(PARAMETER_PROBLEM,
109 "length: You must specify `--length'");
112 /* Common match printing code. */
114 print_length(struct ip6t_length_info *info)
119 if (info->max == info->min)
120 printf("%u ", info->min);
122 printf("%u:%u ", info->min, info->max);
125 /* Prints out the matchinfo. */
127 print(const struct ip6t_ip6 *ip,
128 const struct ip6t_entry_match *match,
132 print_length((struct ip6t_length_info *)match->data);
135 /* Saves the union ip6t_matchinfo in parsable form to stdout. */
137 save(const struct ip6t_ip6 *ip, const struct ip6t_entry_match *match)
140 print_length((struct ip6t_length_info *)match->data);
143 struct ip6tables_match length
147 IP6T_ALIGN(sizeof(struct ip6t_length_info)),
148 IP6T_ALIGN(sizeof(struct ip6t_length_info)),
160 register_match6(&length);