Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Shared library add-on to iptables to add quota support |
| 3 | * |
| 4 | * Sam Johnston <samj@samj.net> |
| 5 | */ |
| 6 | #include <stdio.h> |
Yasuyuki KOZAKAI | 2bcb160 | 2007-07-24 07:03:59 +0000 | [diff] [blame] | 7 | #include <xtables.h> |
Phil Oester | ae35309 | 2006-08-08 09:59:59 +0000 | [diff] [blame] | 8 | #include <linux/netfilter/xt_quota.h> |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 9 | |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame^] | 10 | enum { |
| 11 | O_QUOTA = 0, |
| 12 | }; |
| 13 | |
| 14 | static 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, |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 18 | }; |
| 19 | |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 20 | static void quota_help(void) |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 21 | { |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 22 | printf("quota match options:\n" |
Jan Engelhardt | ce06c99 | 2010-07-02 12:19:18 +0200 | [diff] [blame] | 23 | "[!] --quota quota quota (bytes)\n"); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 24 | } |
| 25 | |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 26 | static void |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 27 | quota_print(const void *ip, const struct xt_entry_match *match, int numeric) |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 28 | { |
Jan Engelhardt | 69f564e | 2009-05-26 13:14:06 +0200 | [diff] [blame] | 29 | const struct xt_quota_info *q = (const void *)match->data; |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 30 | printf(" quota: %llu bytes", (unsigned long long)q->quota); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 31 | } |
| 32 | |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 33 | static void |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 34 | quota_save(const void *ip, const struct xt_entry_match *match) |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 35 | { |
Jan Engelhardt | 69f564e | 2009-05-26 13:14:06 +0200 | [diff] [blame] | 36 | const struct xt_quota_info *q = (const void *)match->data; |
Jan Engelhardt | 9c60365 | 2011-01-18 11:02:04 +0100 | [diff] [blame] | 37 | |
| 38 | if (q->flags & XT_QUOTA_INVERT) |
| 39 | printf("! "); |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 40 | printf(" --quota %llu", (unsigned long long) q->quota); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 41 | } |
| 42 | |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame^] | 43 | static void quota_parse(struct xt_option_call *cb) |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 44 | { |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame^] | 45 | struct xt_quota_info *info = cb->data; |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 46 | |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame^] | 47 | xtables_option_parse(cb); |
| 48 | if (cb->invert) |
| 49 | info->flags |= XT_QUOTA_INVERT; |
Jan Engelhardt | 8a5270b | 2011-02-20 20:30:56 +0100 | [diff] [blame] | 50 | } |
| 51 | |
Patrick McHardy | 0ea82bc | 2008-06-07 15:15:29 +0200 | [diff] [blame] | 52 | static struct xtables_match quota_match = { |
Jan Engelhardt | 4297936 | 2009-06-01 11:56:23 +0200 | [diff] [blame] | 53 | .family = NFPROTO_UNSPEC, |
Yasuyuki KOZAKAI | 2bcb160 | 2007-07-24 07:03:59 +0000 | [diff] [blame] | 54 | .name = "quota", |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 55 | .version = XTABLES_VERSION, |
Yasuyuki KOZAKAI | 2bcb160 | 2007-07-24 07:03:59 +0000 | [diff] [blame] | 56 | .size = XT_ALIGN(sizeof (struct xt_quota_info)), |
Changli Gao | 422342e | 2010-08-02 18:03:20 +0200 | [diff] [blame] | 57 | .userspacesize = offsetof(struct xt_quota_info, master), |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 58 | .help = quota_help, |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 59 | .print = quota_print, |
| 60 | .save = quota_save, |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame^] | 61 | .x6_parse = quota_parse, |
| 62 | .x6_options = quota_opts, |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | void |
| 66 | _init(void) |
| 67 | { |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 68 | xtables_register_match("a_match); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 69 | } |