libxt_quota.c revision b65b9fe5096bd49a9ec2f0f6c2f23d274cfc88ee
1/* 2 * Shared library add-on to iptables to add quota support 3 * 4 * Sam Johnston <samj@samj.net> 5 */ 6#include <stdio.h> 7#include <xtables.h> 8#include <linux/netfilter/xt_quota.h> 9 10enum { 11 O_QUOTA = 0, 12}; 13 14static const struct xt_option_entry quota_opts[] = { 15 {.name = "quota", .id = O_QUOTA, .type = XTTYPE_UINT64, 16 .flags = XTOPT_MAND | XTOPT_INVERT}, 17 XTOPT_TABLEEND, 18}; 19 20static void quota_help(void) 21{ 22 printf("quota match options:\n" 23 "[!] --quota quota quota (bytes)\n"); 24} 25 26static void 27quota_print(const void *ip, const struct xt_entry_match *match, int numeric) 28{ 29 const struct xt_quota_info *q = (const void *)match->data; 30 printf(" quota: %llu bytes", (unsigned long long)q->quota); 31} 32 33static void 34quota_save(const void *ip, const struct xt_entry_match *match) 35{ 36 const struct xt_quota_info *q = (const void *)match->data; 37 38 if (q->flags & XT_QUOTA_INVERT) 39 printf("! "); 40 printf(" --quota %llu", (unsigned long long) q->quota); 41} 42 43static void quota_parse(struct xt_option_call *cb) 44{ 45 struct xt_quota_info *info = cb->data; 46 47 xtables_option_parse(cb); 48 if (cb->invert) 49 info->flags |= XT_QUOTA_INVERT; 50 info->quota = cb->val.u64; 51} 52 53static struct xtables_match quota_match = { 54 .family = NFPROTO_UNSPEC, 55 .name = "quota", 56 .version = XTABLES_VERSION, 57 .size = XT_ALIGN(sizeof (struct xt_quota_info)), 58 .userspacesize = offsetof(struct xt_quota_info, master), 59 .help = quota_help, 60 .print = quota_print, 61 .save = quota_save, 62 .x6_parse = quota_parse, 63 .x6_options = quota_opts, 64}; 65 66void 67_init(void) 68{ 69 xtables_register_match("a_match); 70} 71