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'},
19 static void quota_help(void)
21 printf("quota match options:\n"
22 " --quota quota quota (bytes)\n");
26 quota_print(const void *ip, const struct xt_entry_match *match, int numeric)
28 struct xt_quota_info *q = (struct xt_quota_info *) match->data;
29 printf("quota: %llu bytes", (unsigned long long) q->quota);
33 quota_save(const void *ip, const struct xt_entry_match *match)
35 struct xt_quota_info *q = (struct xt_quota_info *) match->data;
36 printf("--quota %llu ", (unsigned long long) q->quota);
39 /* parse quota option */
41 parse_quota(const char *s, u_int64_t * quota)
43 *quota = strtoull(s, NULL, 10);
46 printf("Quota: %llu\n", *quota);
49 if (*quota == UINT64_MAX)
50 xtables_error(PARAMETER_PROBLEM, "quota invalid: '%s'\n", s);
56 quota_parse(int c, char **argv, int invert, unsigned int *flags,
57 const void *entry, struct xt_entry_match **match)
59 struct xt_quota_info *info = (struct xt_quota_info *) (*match)->data;
63 if (xtables_check_inverse(optarg, &invert, NULL, 0))
64 xtables_error(PARAMETER_PROBLEM, "quota: unexpected '!'");
65 if (!parse_quota(optarg, &info->quota))
66 xtables_error(PARAMETER_PROBLEM,
67 "bad quota: '%s'", optarg);
76 static struct xtables_match quota_match = {
79 .version = XTABLES_VERSION,
80 .size = XT_ALIGN(sizeof (struct xt_quota_info)),
81 .userspacesize = offsetof(struct xt_quota_info, quota),
86 .extra_opts = quota_opts,
92 xtables_register_match("a_match);