3 bcount match (experimental)
4 Copyright (C) 2006 Jonathan Zarate
6 Licensed under GNU GPL v2 or later.
15 #include <linux/netfilter_ipv4/ipt_bcount.h>
21 static void help(void)
24 "bcount match v0.00\n"
25 "[!] --range min:max (upper range of 0x0FFFFFFF or more means unlimited)\n"
29 static void init(struct ipt_entry_match
*match
, unsigned int *nfcache
)
31 struct ipt_bcount_match
*info
= (struct ipt_bcount_match
*)match
->data
;
32 info
->min
= 0xFFFFFFFF;
33 info
->max
= 0x0FFFFFFF;
34 *nfcache
|= NFC_UNKNOWN
;
37 static struct option opts
[] = {
38 { .name
= "range", .has_arg
= 1, .flag
= 0, .val
= '1' },
42 static int parse(int c
, char **argv
, int invert
, unsigned int *flags
,
43 const struct ipt_entry
*entry
, unsigned int *nfcache
,
44 struct ipt_entry_match
**match
)
47 struct ipt_bcount_match
*info
;
49 if (c
!= '1') return 0;
51 info
= (struct ipt_bcount_match
*)(*match
)->data
;
54 check_inverse(optarg
, &invert
, &optind
, 0);
55 if (invert
) info
->invert
= 1;
57 info
->min
= strtoul(argv
[optind
- 1], &p
, 0);
61 else if ((*p
== '-') || (*p
== ':')) {
63 if ((*p
== 0) || (strcmp(p
, "max") == 0)) {
64 info
->max
= 0x0FFFFFFF;
67 info
->max
= strtoul(p
, &p
, 0);
68 if (info
->max
> 0x0FFFFFFF) info
->max
= 0x0FFFFFFF;
72 if ((*p
!= 0) || (info
->min
> info
->max
))
73 exit_error(PARAMETER_PROBLEM
, "Invalid range");
77 static void final_check(unsigned int flags
)
80 exit_error(PARAMETER_PROBLEM
, "Invalid range");
84 static void print_match(const struct ipt_bcount_match
*info
)
86 if (info
->min
!= 0xFFFFFFFF) {
87 if (info
->invert
) printf("! ");
88 printf("--range %u", info
->min
);
89 if (info
->max
== 0x0FFFFFFF) printf("+ ");
90 else printf(":%u ", info
->max
);
94 static void print(const struct ipt_ip
*ip
, const struct ipt_entry_match
*match
, int numeric
)
97 print_match((const struct ipt_bcount_match
*)match
->data
);
100 static void save(const struct ipt_ip
*ip
, const struct ipt_entry_match
*match
)
103 print_match((const struct ipt_bcount_match
*)match
->data
);
108 static struct iptables_match bcount_match
= {
110 .version
= IPTABLES_VERSION
,
111 .size
= IPT_ALIGN(sizeof(struct ipt_bcount_match
)),
112 .userspacesize
= IPT_ALIGN(sizeof(struct ipt_bcount_match
)),
116 .final_check
= &final_check
,
124 register_match(&bcount_match
);