X-Git-Url: http://developer.intra2net.com/git/?p=ipt_ACCOUNT;a=blobdiff_plain;f=linux-2.6%2Fnet%2Fipv4%2Fnetfilter%2Fipt_ACCOUNT.c;h=5a5f03ffa5d6f67285c81503dcd58504d5a08251;hp=78f2bb345d62b65b81b4d8f047712612b8689902;hb=32efca6f6d8fa23b3654a875a33fefa121982d08;hpb=7dc57d446364757855083e0111f43e51616ad815 diff --git a/linux-2.6/net/ipv4/netfilter/ipt_ACCOUNT.c b/linux-2.6/net/ipv4/netfilter/ipt_ACCOUNT.c index 78f2bb3..5a5f03f 100644 --- a/linux-2.6/net/ipv4/netfilter/ipt_ACCOUNT.c +++ b/linux-2.6/net/ipv4/netfilter/ipt_ACCOUNT.c @@ -13,6 +13,7 @@ ***************************************************************************/ #include +#include #include #include #include @@ -188,15 +189,31 @@ static int ipt_acc_table_insert(char *name, u_int32_t ip, u_int32_t netmask) } 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); @@ -213,15 +230,26 @@ static int ipt_acc_checkentry(const char *tablename, 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 { 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); @@ -413,15 +441,27 @@ static unsigned int ipt_acc_target(struct sk_buff **pskb, 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; +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) + u_int32_t src_ip = ip_hdr(*pskb)->saddr; + u_int32_t dst_ip = ip_hdr(*pskb)->daddr; + u_int32_t size = ntohs(ip_hdr(*pskb)->tot_len); +#else u_int32_t src_ip = (*pskb)->nh.iph->saddr; u_int32_t dst_ip = (*pskb)->nh.iph->daddr; u_int32_t size = ntohs((*pskb)->nh.iph->tot_len); +#endif spin_lock_bh(&ipt_acc_lock); @@ -815,7 +855,7 @@ static int ipt_acc_set_ctl(struct sock *sk, int cmd, switch (cmd) { case IPT_SO_SET_ACCOUNT_HANDLE_FREE: if (len != sizeof(struct ipt_acc_handle_sockopt)) { - printk("ACCOUNT: ipt_acc_set_ctl: wrong data size (%u != %lu) " + printk("ACCOUNT: ipt_acc_set_ctl: wrong data size (%u != %u) " "for IPT_SO_SET_HANDLE_FREE\n", len, sizeof(struct ipt_acc_handle_sockopt)); break; @@ -861,7 +901,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len) struct ipt_acc_handle dest; if (*len < sizeof(struct ipt_acc_handle_sockopt)) { - printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %lu) " + printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %u) " "for IPT_SO_GET_ACCOUNT_PREPARE_READ/READ_FLUSH\n", *len, sizeof(struct ipt_acc_handle_sockopt)); break; @@ -906,7 +946,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len) } case IPT_SO_GET_ACCOUNT_GET_DATA: if (*len < sizeof(struct ipt_acc_handle_sockopt)) { - printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %lu)" + printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %u)" " for IPT_SO_GET_ACCOUNT_PREPARE_READ/READ_FLUSH\n", *len, sizeof(struct ipt_acc_handle_sockopt)); break; @@ -925,7 +965,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len) if (*len < ipt_acc_handles[handle.handle_nr].itemcount * sizeof(struct ipt_acc_handle_ip)) { - printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %lu)" + printk("ACCOUNT: ipt_acc_get_ctl: not enough space (%u < %u)" " to store data from IPT_SO_GET_ACCOUNT_GET_DATA\n", *len, ipt_acc_handles[handle.handle_nr].itemcount * sizeof(struct ipt_acc_handle_ip)); @@ -947,7 +987,7 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len) case IPT_SO_GET_ACCOUNT_GET_HANDLE_USAGE: { unsigned int i; if (*len < sizeof(struct ipt_acc_handle_sockopt)) { - printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %lu)" + printk("ACCOUNT: ipt_acc_get_ctl: wrong data size (%u != %u)" " for IPT_SO_GET_ACCOUNT_GET_HANDLE_USAGE\n", *len, sizeof(struct ipt_acc_handle_sockopt)); break; @@ -1017,10 +1057,19 @@ static int ipt_acc_get_ctl(struct sock *sk, int cmd, void *user, int *len) 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 @@ -1046,7 +1095,7 @@ static int __init init(void) 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 = @@ -1055,7 +1104,7 @@ static int __init init(void) 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 */ @@ -1070,7 +1119,11 @@ static int __init init(void) 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; @@ -1088,7 +1141,11 @@ error_cleanup: 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);