d2edac019d6960ed46d8bf565a1c4f4bdf7c946b
[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     char name[ACCOUNT_TABLE_NAME_LEN];        /* name of the table */
29     unsigned int ip;                          /* base IP of network */
30     unsigned int netmask;                     /* netmask of the network */
31     unsigned char depth;                      /* size of network: 
32                                                  0: 8 bit, 1: 16bit, 2: 24 bit */
33     unsigned int refcount;                    /* refcount of this table. 
34                                                  if zero, destroy it */
35     unsigned int itemcount;                   /* number of IPs in this table */
36     void *data;                               /* pointer to the actual data, 
37                                                  depending on netmask */
38 };
39
40 /* Internal handle structure */
41 struct ipt_account_handle {
42     unsigned int ip;                          /* base IP of network. Used for 
43                                                  caculating the final IP during
44                                                  get_data() */
45     unsigned char depth;                      /* size of network. See above for 
46                                                  details */
47     unsigned int itemcount;                   /* number of IPs in this table */
48     void *data;                               /* pointer to the actual data, 
49                                                  depending on size */
50 };
51
52 /* Handle structure for communication with the userspace library */
53 struct ipt_account_handle_sockopt {
54     unsigned int handle_nr;                   /* Used for HANDLE_FREE */
55     char name[ACCOUNT_TABLE_NAME_LEN];        /* Used for HANDLE_PREPARE_READ/
56                                                  HANDLE_READ_FLUSH */
57     unsigned int itemcount;                   /* Used for HANDLE_PREPARE_READ/
58                                                  HANDLE_READ_FLUSH */
59 };
60
61 /* Used for every IP entry 
62    Size is 16 bytes so that 256 (class C network) * 16 
63    fits in one kernel (zero) page */
64 struct ipt_account_ip {
65     unsigned int src_packets;
66     unsigned int src_bytes;
67     unsigned int dst_packets;
68     unsigned int dst_bytes;
69 };
70
71 /*
72     Used for every IP when returning data
73 */
74 struct ipt_account_handle_ip {
75     unsigned int ip;
76     unsigned int src_packets;
77     unsigned int src_bytes;
78     unsigned int dst_packets;
79     unsigned int dst_bytes;
80 };
81
82 /*
83     The IPs are organized as an array so that direct slot
84     calculations are possible.
85     Only 8 bit networks are preallocated, 16/24 bit networks
86     allocate their slots when needed -> very efficent.
87 */
88 struct ipt_account_mask_24 {
89     struct ipt_account_ip ip[256];
90 };
91
92 struct ipt_account_mask_16 {
93     struct ipt_account_mask_24 *mask_24[256];
94 };
95
96 struct ipt_account_mask_8 {
97     struct ipt_account_mask_16 *mask_16[256];
98 };
99
100 #endif /*_IPT_ACCOUNT_H*/