2 * Shared library add-on to iptables to add quota support
4 * Sam Johnston <samj@samj.net>
12 #include <linux/netfilter/xt_quota.h>
13 #include <linux/netfilter_ipv4/ip_tables.h>
15 static struct option opts[] = {
24 printf("quota options:\n"
25 " --quota quota quota (bytes)\n" "\n");
30 print(const struct ipt_ip *ip, const struct ipt_entry_match *match, int numeric)
32 struct xt_quota_info *q = (struct xt_quota_info *) match->data;
33 printf("quota: %llu bytes", (unsigned long long) q->quota);
38 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
40 struct xt_quota_info *q = (struct xt_quota_info *) match->data;
41 printf("--quota %llu ", (unsigned long long) q->quota);
44 /* parse quota option */
46 parse_quota(const char *s, u_int64_t * quota)
48 *quota = strtoull(s, (char **) NULL, 10);
50 #ifdef DEBUG_IPT_QUOTA
51 printf("Quota: %llu\n", *quota);
55 exit_error(PARAMETER_PROBLEM, "quota invalid: '%s'\n", s);
60 /* parse all options, returning true if we found any for us */
62 parse(int c, char **argv, int invert, unsigned int *flags,
63 const struct ipt_entry *entry,
64 unsigned int *nfcache, struct ipt_entry_match **match)
66 struct xt_quota_info *info = (struct xt_quota_info *) (*match)->data;
70 if (check_inverse(optarg, &invert, NULL, 0))
71 exit_error(PARAMETER_PROBLEM, "quota: unexpected '!'");
72 if (!parse_quota(optarg, &info->quota))
73 exit_error(PARAMETER_PROBLEM,
74 "bad quota: '%s'", optarg);
85 final_check(unsigned int flags)
89 struct iptables_match quota = {
92 .version = IPTABLES_VERSION,
93 .size = IPT_ALIGN(sizeof (struct xt_quota_info)),
94 .userspacesize = offsetof(struct xt_quota_info, quota),
97 .final_check = &final_check,
106 register_match("a);