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, |
Jan Engelhardt | 67db761 | 2011-05-20 16:01:18 +0200 | [diff] [blame] | 16 | .flags = XTOPT_MAND | XTOPT_INVERT | XTOPT_PUT, |
| 17 | XTOPT_POINTER(struct xt_quota_info, quota)}, |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame] | 18 | XTOPT_TABLEEND, |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 19 | }; |
| 20 | |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 21 | static void quota_help(void) |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 22 | { |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 23 | printf("quota match options:\n" |
Jan Engelhardt | ce06c99 | 2010-07-02 12:19:18 +0200 | [diff] [blame] | 24 | "[!] --quota quota quota (bytes)\n"); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 25 | } |
| 26 | |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 27 | static void |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 28 | 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] | 29 | { |
Jan Engelhardt | 69f564e | 2009-05-26 13:14:06 +0200 | [diff] [blame] | 30 | const struct xt_quota_info *q = (const void *)match->data; |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 31 | printf(" quota: %llu bytes", (unsigned long long)q->quota); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 32 | } |
| 33 | |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 34 | static void |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 35 | quota_save(const void *ip, const struct xt_entry_match *match) |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 36 | { |
Jan Engelhardt | 69f564e | 2009-05-26 13:14:06 +0200 | [diff] [blame] | 37 | const struct xt_quota_info *q = (const void *)match->data; |
Jan Engelhardt | 9c60365 | 2011-01-18 11:02:04 +0100 | [diff] [blame] | 38 | |
| 39 | if (q->flags & XT_QUOTA_INVERT) |
Arturo Borrero | 379bd7b | 2015-02-23 11:31:11 +0100 | [diff] [blame^] | 40 | printf(" !"); |
Jan Engelhardt | 7386635 | 2010-12-18 02:04:59 +0100 | [diff] [blame] | 41 | printf(" --quota %llu", (unsigned long long) q->quota); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 42 | } |
| 43 | |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame] | 44 | static void quota_parse(struct xt_option_call *cb) |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 45 | { |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame] | 46 | struct xt_quota_info *info = cb->data; |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 47 | |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame] | 48 | xtables_option_parse(cb); |
| 49 | if (cb->invert) |
| 50 | info->flags |= XT_QUOTA_INVERT; |
Jan Engelhardt | 8a5270b | 2011-02-20 20:30:56 +0100 | [diff] [blame] | 51 | } |
| 52 | |
Patrick McHardy | 0ea82bc | 2008-06-07 15:15:29 +0200 | [diff] [blame] | 53 | static struct xtables_match quota_match = { |
Jan Engelhardt | 4297936 | 2009-06-01 11:56:23 +0200 | [diff] [blame] | 54 | .family = NFPROTO_UNSPEC, |
Yasuyuki KOZAKAI | 2bcb160 | 2007-07-24 07:03:59 +0000 | [diff] [blame] | 55 | .name = "quota", |
Jan Engelhardt | 8b7c64d | 2008-04-15 11:48:25 +0200 | [diff] [blame] | 56 | .version = XTABLES_VERSION, |
Yasuyuki KOZAKAI | 2bcb160 | 2007-07-24 07:03:59 +0000 | [diff] [blame] | 57 | .size = XT_ALIGN(sizeof (struct xt_quota_info)), |
Changli Gao | 422342e | 2010-08-02 18:03:20 +0200 | [diff] [blame] | 58 | .userspacesize = offsetof(struct xt_quota_info, master), |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 59 | .help = quota_help, |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 60 | .print = quota_print, |
| 61 | .save = quota_save, |
Jan Engelhardt | 1e6c1ee | 2011-03-06 16:58:24 +0100 | [diff] [blame] | 62 | .x6_parse = quota_parse, |
| 63 | .x6_options = quota_opts, |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | void |
| 67 | _init(void) |
| 68 | { |
Jan Engelhardt | 181dead | 2007-10-04 16:27:07 +0000 | [diff] [blame] | 69 | xtables_register_match("a_match); |
Harald Welte | e746abb | 2001-12-03 22:22:55 +0000 | [diff] [blame] | 70 | } |