2 * Shared library add-on to iptables to add quota support
4 * Sam Johnston <samj@samj.net>
12 #include <linux/netfilter/xt_quota.h>
14 static const struct option quota_opts[] = {
15 {"quota", 1, NULL, '1'},
20 static void quota_help(void)
22 printf("quota match options:\n"
23 " --quota quota quota (bytes)\n");
28 quota_print(const void *ip, const struct xt_entry_match *match, int numeric)
30 struct xt_quota_info *q = (struct xt_quota_info *) match->data;
31 printf("quota: %llu bytes", (unsigned long long) q->quota);
36 quota_save(const void *ip, const struct xt_entry_match *match)
38 struct xt_quota_info *q = (struct xt_quota_info *) match->data;
39 printf("--quota %llu ", (unsigned long long) q->quota);
42 /* parse quota option */
44 parse_quota(const char *s, u_int64_t * quota)
46 *quota = strtoull(s, NULL, 10);
49 printf("Quota: %llu\n", *quota);
52 if (*quota == (u_int64_t)-1)
53 exit_error(PARAMETER_PROBLEM, "quota invalid: '%s'\n", s);
58 /* parse all options, returning true if we found any for us */
60 quota_parse(int c, char **argv, int invert, unsigned int *flags,
61 const void *entry, struct xt_entry_match **match)
63 struct xt_quota_info *info = (struct xt_quota_info *) (*match)->data;
67 if (check_inverse(optarg, &invert, NULL, 0))
68 exit_error(PARAMETER_PROBLEM, "quota: unexpected '!'");
69 if (!parse_quota(optarg, &info->quota))
70 exit_error(PARAMETER_PROBLEM,
71 "bad quota: '%s'", optarg);
80 static struct xtables_match quota_match = {
83 .version = XTABLES_VERSION,
84 .size = XT_ALIGN(sizeof (struct xt_quota_info)),
85 .userspacesize = offsetof(struct xt_quota_info, quota),
90 .extra_opts = quota_opts,
96 xtables_register_match("a_match);