2 * Shared library add-on to iptables to add quota support
4 * Sam Johnston <samj@samj.net>
11 #include <linux/netfilter_ipv4/ipt_quota.h>
12 #include <linux/netfilter_ipv4/ip_tables.h>
14 static struct option opts[] = {
23 printf("quota options:\n"
24 " --quota quota quota (bytes)\n" "\n");
27 /* initialise match */
29 init(struct ipt_entry_match *m, unsigned int *nfcache)
32 *nfcache |= NFC_UNKNOWN;
37 print(const struct ipt_ip *ip, const struct ipt_entry_match *match, int numeric)
39 struct ipt_quota_info *q = (struct ipt_quota_info *) match->data;
40 printf("quota: %llu bytes", (unsigned long long) q->quota);
45 save(const struct ipt_ip *ip, const struct ipt_entry_match *match)
47 struct ipt_quota_info *q = (struct ipt_quota_info *) match->data;
48 printf("--quota %llu ", (unsigned long long) q->quota);
51 /* parse quota option */
53 parse_quota(const char *s, u_int64_t * quota)
55 *quota = strtoull(s, (char **) NULL, 10);
57 #ifdef DEBUG_IPT_QUOTA
58 printf("Quota: %llu\n", *quota);
62 exit_error(PARAMETER_PROBLEM, "quota invalid: '%s'\n", s);
67 /* parse all options, returning true if we found any for us */
69 parse(int c, char **argv, int invert, unsigned int *flags,
70 const struct ipt_entry *entry,
71 unsigned int *nfcache, struct ipt_entry_match **match)
73 struct ipt_quota_info *info = (struct ipt_quota_info *) (*match)->data;
77 if (check_inverse(optarg, &invert, NULL, 0))
78 exit_error(PARAMETER_PROBLEM, "quota: unexpected '!'");
79 if (!parse_quota(optarg, &info->quota))
80 exit_error(PARAMETER_PROBLEM,
81 "bad quota: '%s'", optarg);
92 final_check(unsigned int flags)
96 struct iptables_match quota = { NULL,
99 IPT_ALIGN(sizeof (struct ipt_quota_info)),
100 IPT_ALIGN(sizeof (struct ipt_quota_info)),
113 register_match("a);