***************************************************************************/
#include <linux/module.h>
+#include <linux/version.h>
#include <linux/skbuff.h>
#include <linux/ip.h>
#include <net/icmp.h>
/* Free for 16 bit network */
if (depth == 1) {
struct ipt_acc_mask_16 *mask_16 = (struct ipt_acc_mask_16 *)data;
- u_int32_t b;
+ unsigned int b;
for (b=0; b <= 255; b++) {
- if (mask_16->mask_24[b] != 0) {
+ if (mask_16->mask_24[b]) {
free_page((unsigned long)mask_16->mask_24[b]);
}
}
/* Free for 24 bit network */
if (depth == 2) {
- u_int32_t a, b;
+ unsigned int a, b;
for (a=0; a <= 255; a++) {
if (((struct ipt_acc_mask_8 *)data)->mask_16[a]) {
struct ipt_acc_mask_16 *mask_16 = (struct ipt_acc_mask_16*)
Return internal ID or -1 on error */
static int ipt_acc_table_insert(char *name, u_int32_t ip, u_int32_t netmask)
{
- u_int32_t i;
+ unsigned int i;
DEBUGP("ACCOUNT: ipt_acc_table_insert: %s, %u.%u.%u.%u/%u.%u.%u.%u\n",
name, NIPQUAD(ip), NIPQUAD(netmask));
for (i = 0; i < ACCOUNT_MAX_TABLES; i++) {
/* Found free slot */
if (ipt_acc_tables[i].name[0] == 0) {
- u_int32_t calc_mask, netsize=0;
+ unsigned int netsize=0;
+ u_int32_t calc_mask;
int j; /* needs to be signed, otherwise we risk endless loop */
DEBUGP("ACCOUNT: Found free slot: %d\n", i);
}
static int ipt_acc_checkentry(const char *tablename,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
const void *e,
+#else
+ const struct ipt_entry *e,
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
const struct xt_target *target,
+#endif
void *targinfo,
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
unsigned int targinfosize,
+#endif
unsigned int hook_mask)
{
struct ipt_acc_info *info = targinfo;
int table_nr;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
+ if (targinfosize != IPT_ALIGN(sizeof(struct ipt_acc_info))) {
+ DEBUGP("ACCOUNT: targinfosize %u != %u\n",
+ targinfosize, IPT_ALIGN(sizeof(struct ipt_acc_info)));
+ return 0;
+ }
+#endif
+
spin_lock_bh(&ipt_acc_lock);
table_nr = ipt_acc_table_insert(info->table_name, info->net_ip,
info->net_mask);
return 1;
}
-static void ipt_acc_destroy(const struct xt_target *target, void *targinfo, unsigned int targinfosize)
+static void ipt_acc_destroy(
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
+ const struct xt_target *target,
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
+ void *targinfo)
+#else
+ void *targinfo,
+ unsigned int targinfosize)
+#endif
{
- u_int32_t i;
+ unsigned int i;
struct ipt_acc_info *info = targinfo;
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,17)
if (targinfosize != IPT_ALIGN(sizeof(struct ipt_acc_info))) {
DEBUGP("ACCOUNT: targinfosize %u != %u\n",
targinfosize, IPT_ALIGN(sizeof(struct ipt_acc_info)));
}
+#endif
spin_lock_bh(&ipt_acc_lock);
const struct net_device *in,
const struct net_device *out,
unsigned int hooknum,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
const struct xt_target *target,
+#endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,19)
+ const void *targinfo)
+#else
const void *targinfo,
void *userinfo)
+#endif
{
const struct ipt_acc_info *info =
(const struct ipt_acc_info *)targinfo;
*/
static int ipt_acc_handle_find_slot(void)
{
- u_int32_t i;
+ unsigned int i;
/* Insert new table */
for (i = 0; i < ACCOUNT_MAX_HANDLES; i++) {
/* Found free slot */
return -1;
}
-static int ipt_acc_handle_free(u_int32_t handle)
+static int ipt_acc_handle_free(unsigned int handle)
{
if (handle >= ACCOUNT_MAX_HANDLES) {
printk("ACCOUNT: Invalid handle for ipt_acc_handle_free() specified:"
(struct ipt_acc_mask_16 *)ipt_acc_tables[table_nr].data;
struct ipt_acc_mask_16 *network_16 =
(struct ipt_acc_mask_16 *)dest->data;
- u_int32_t b;
+ unsigned int b;
for (b = 0; b <= 255; b++) {
if (src_16->mask_24[b]) {
struct ipt_acc_mask_8 *network_8 =
(struct ipt_acc_mask_8 *)dest->data;
struct ipt_acc_mask_16 *src_16, *network_16;
- u_int32_t a, b;
+ unsigned int a, b;
for (a = 0; a <= 255; a++) {
if (src_8->mask_16[a]) {
/* Copy 8 bit network data into a prepared buffer.
We only copy entries != 0 to increase performance.
*/
-static int ipt_acc_handle_copy_data(void *to_user, u_int32_t *to_user_pos,
- u_int32_t *tmpbuf_pos,
+static int ipt_acc_handle_copy_data(void *to_user, unsigned long *to_user_pos,
+ unsigned long *tmpbuf_pos,
struct ipt_acc_mask_24 *data,
u_int32_t net_ip, u_int32_t net_OR_mask)
{
struct ipt_acc_handle_ip handle_ip;
- u_int32_t handle_ip_size = sizeof (struct ipt_acc_handle_ip);
- u_int32_t i;
+ size_t handle_ip_size = sizeof (struct ipt_acc_handle_ip);
+ unsigned int i;
for (i = 0; i <= 255; i++) {
if (data->ip[i].src_packets || data->ip[i].dst_packets) {
*/
static int ipt_acc_handle_get_data(u_int32_t handle, void *to_user)
{
- u_int32_t to_user_pos=0, tmpbuf_pos=0, net_ip;
+ unsigned long to_user_pos=0, tmpbuf_pos=0;
+ u_int32_t net_ip;
unsigned char depth;
if (handle >= ACCOUNT_MAX_HANDLES) {
if (depth == 1) {
struct ipt_acc_mask_16 *network_16 =
(struct ipt_acc_mask_16*)ipt_acc_handles[handle].data;
- u_int32_t b;
+ unsigned int b;
for (b = 0; b <= 255; b++) {
if (network_16->mask_24[b]) {
struct ipt_acc_mask_24 *network =
if (depth == 2) {
struct ipt_acc_mask_8 *network_8 =
(struct ipt_acc_mask_8*)ipt_acc_handles[handle].data;
- u_int32_t a, b;
+ unsigned int a, b;
for (a = 0; a <= 255; a++) {
if (network_8->mask_16[a]) {
struct ipt_acc_mask_16 *network_16 =
}
static int ipt_acc_set_ctl(struct sock *sk, int cmd,
- void *user, u_int32_t len)
+ void *user, unsigned int len)
{
struct ipt_acc_handle_sockopt handle;
int ret = -EINVAL;
up(&ipt_acc_userspace_mutex);
break;
case IPT_SO_SET_ACCOUNT_HANDLE_FREE_ALL: {
- u_int32_t i;
+ unsigned int i;
down(&ipt_acc_userspace_mutex);
for (i = 0; i < ACCOUNT_MAX_HANDLES; i++)
ipt_acc_handle_free(i);
ret = 0;
break;
case IPT_SO_GET_ACCOUNT_GET_HANDLE_USAGE: {
- u_int32_t i;
+ unsigned int i;
if (*len < sizeof(struct ipt_acc_handle_sockopt)) {
printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %u)"
" for IPT_SO_GET_ACCOUNT_GET_HANDLE_USAGE\n",
return ret;
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
+static struct xt_target xt_acc_reg = {
+#else
static struct ipt_target ipt_acc_reg = {
+#endif
.name = "ACCOUNT",
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
+ .family = AF_INET,
+#endif
.target = ipt_acc_target,
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,17)
.targetsize = sizeof(struct ipt_acc_info),
+#endif
.checkentry = ipt_acc_checkentry,
.destroy = ipt_acc_destroy,
.me = THIS_MODULE
printk("ACCOUNT: Out of memory allocating account_tables structure");
goto error_cleanup;
}
- memset(ipt_acc_tables, 0,
+ memset(ipt_acc_tables, 0,
ACCOUNT_MAX_TABLES * sizeof(struct ipt_acc_table));
if ((ipt_acc_handles =
printk("ACCOUNT: Out of memory allocating account_handles structure");
goto error_cleanup;
}
- memset(ipt_acc_handles, 0,
+ memset(ipt_acc_handles, 0,
ACCOUNT_MAX_HANDLES * sizeof(struct ipt_acc_handle));
/* Allocate one page as temporary storage */
goto error_cleanup;
}
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
+ if (xt_register_target(&xt_acc_reg))
+#else
if (ipt_register_target(&ipt_acc_reg))
+#endif
goto error_cleanup;
return 0;
static void __exit fini(void)
{
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,21)
+ xt_unregister_target(&xt_acc_reg);
+#else
ipt_unregister_target(&ipt_acc_reg);
+#endif
nf_unregister_sockopt(&ipt_acc_sockopts);