402b889de94545234a2d7a1cfa71636d4740b5ba
[ipt_ACCOUNT] / linux / include / linux / netfilter_ipv4 / ipt_ACCOUNT.h
1 /***************************************************************************
2  *   Copyright (C) 2004 by Intra2net AG                                    *
3  *   opensource@intra2net.com                                              *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License                  *
7  *   version 2 as published by the Free Software Foundation;               *
8  *                                                                         *
9  ***************************************************************************/
10
11 #ifndef _IPT_ACCOUNT_H
12 #define _IPT_ACCOUNT_H
13
14 #define ACCOUNT_MAX_TABLES 32
15 #define ACCOUNT_TABLE_NAME_LEN 32
16 #define ACCOUNT_MAX_HANDLES 10
17
18 /* Structure for the userspace part of ipt_ACCOUNT */
19 struct ipt_account_info {
20         u_int32_t net_ip;
21         u_int32_t net_mask;
22         char table_name[ACCOUNT_TABLE_NAME_LEN];
23         int32_t table_nr;
24 };
25
26 /* Internal table structure, generated by check_entry() */
27 struct ipt_account_table
28 {
29     char name[ACCOUNT_TABLE_NAME_LEN];        /* name of the table */
30     unsigned int ip;                          /* base IP of network */
31     unsigned int netmask;                     /* netmask of the network */
32     unsigned char depth;                      /* size of network: 0: 8 bit, 1: 16bit, 2: 24 bit */
33     unsigned int refcount;                    /* refcount of this table. if zero, destroy it */
34     unsigned int itemcount;                   /* number of IPs in this table */
35     void *data;                               /* pointer to the actual data, depending on netmask */
36 };
37
38 /* Internal handle structure */
39 struct ipt_account_handle
40 {
41     unsigned int ip;                          /* base IP of network. Used for caculating the final IP during get_data() */
42     unsigned char depth;                      /* size of network. See above for details */
43     unsigned int itemcount;                   /* number of IPs in this table */
44     void *data;                               /* pointer to the actual data, depending on size */
45 };
46
47 /* Handle structure for communication with the userspace library */
48 struct ipt_account_handle_sockopt
49 {
50     unsigned int handle_nr;                   /* Used for HANDLE_FREE */
51     char name[ACCOUNT_TABLE_NAME_LEN];        /* Used for HANDLE_PREPARE_READ/READ_FLUSH */
52     unsigned int itemcount;                   /* Used for HANDLE_PREPARE_READ/READ_FLUSH */
53 };
54
55 /* Used for every IP entry */
56 /* Size is 16 bytes so that 256 (class C network) * 16 fits in one kernel (zero) page */
57 struct ipt_account_ip
58 {
59     unsigned int src_packets;
60     unsigned int src_bytes;
61     unsigned int dst_packets;
62     unsigned int dst_bytes;
63 };
64
65 /*
66     Used for every IP when returning data
67 */
68 struct ipt_account_handle_ip
69 {
70     unsigned int ip;
71     unsigned int src_packets;
72     unsigned int src_bytes;
73     unsigned int dst_packets;
74     unsigned int dst_bytes;
75 };
76
77 /*
78     The IPs are organized as an array so that direct slot
79     calculations are possible.
80     Only 8 bit networks are preallocated, 16/24 bit networks
81     allocate their slots when needed -> very efficent.
82 */
83 struct ipt_account_mask_24
84 {
85     struct ipt_account_ip ip[256];    
86 };
87
88 struct ipt_account_mask_16
89 {
90     struct ipt_account_mask_24 *mask_24[256];
91 };
92
93 struct ipt_account_mask_8
94 {
95     struct ipt_account_mask_16 *mask_16[256];
96 };
97
98 #endif /*_IPT_ACCOUNT_H*/