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");
29 print(const struct ipt_ip
*ip
, const struct ipt_entry_match
*match
, int numeric
)
31 struct ipt_quota_info
*q
= (struct ipt_quota_info
*) match
->data
;
32 printf("quota: %llu bytes", (unsigned long long) q
->quota
);
37 save(const struct ipt_ip
*ip
, const struct ipt_entry_match
*match
)
39 struct ipt_quota_info
*q
= (struct ipt_quota_info
*) match
->data
;
40 printf("--quota %llu ", (unsigned long long) q
->quota
);
43 /* parse quota option */
45 parse_quota(const char *s
, u_int64_t
* quota
)
47 *quota
= strtoull(s
, (char **) NULL
, 10);
49 #ifdef DEBUG_IPT_QUOTA
50 printf("Quota: %llu\n", *quota
);
54 exit_error(PARAMETER_PROBLEM
, "quota invalid: '%s'\n", s
);
59 /* parse all options, returning true if we found any for us */
61 parse(int c
, char **argv
, int invert
, unsigned int *flags
,
62 const struct ipt_entry
*entry
,
63 unsigned int *nfcache
, struct ipt_entry_match
**match
)
65 struct ipt_quota_info
*info
= (struct ipt_quota_info
*) (*match
)->data
;
69 if (check_inverse(optarg
, &invert
, NULL
, 0))
70 exit_error(PARAMETER_PROBLEM
, "quota: unexpected '!'");
71 if (!parse_quota(optarg
, &info
->quota
))
72 exit_error(PARAMETER_PROBLEM
,
73 "bad quota: '%s'", optarg
);
84 final_check(unsigned int flags
)
88 struct iptables_match quota
= {
91 .version
= IPTABLES_VERSION
,
92 .size
= IPT_ALIGN(sizeof (struct ipt_quota_info
)),
93 .userspacesize
= IPT_ALIGN(sizeof (struct ipt_quota_info
)),
96 .final_check
= &final_check
,
105 register_match("a
);