mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-20 19:44:56 +02:00
ipset: upgrade to ipset 2.4.3
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2005 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
|
||||
/* Copyright (C) 2005-2008 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
@@ -7,24 +7,20 @@
|
||||
|
||||
/* Kernel module implementing an IP set type: the iptree type */
|
||||
|
||||
#include <linux/version.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/moduleparam.h>
|
||||
#include <linux/ip.h>
|
||||
#include <linux/skbuff.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/netfilter_ipv4/ip_tables.h>
|
||||
#include "ip_set.h"
|
||||
#include <linux/errno.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <asm/bitops.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/timer.h>
|
||||
|
||||
/* Backward compatibility */
|
||||
#ifndef __nocast
|
||||
#define __nocast
|
||||
#endif
|
||||
|
||||
#include "ip_set.h"
|
||||
#include "ip_set_bitmaps.h"
|
||||
#include "ip_set_iptree.h"
|
||||
|
||||
static int limit = MAX_RANGE;
|
||||
@@ -35,13 +31,9 @@ static int limit = MAX_RANGE;
|
||||
* to delete the gc timer at destroying/flushing a set */
|
||||
#define IPTREE_DESTROY_SLEEP 100
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20)
|
||||
static struct kmem_cache *branch_cachep;
|
||||
static struct kmem_cache *leaf_cachep;
|
||||
#else
|
||||
static kmem_cache_t *branch_cachep;
|
||||
static kmem_cache_t *leaf_cachep;
|
||||
#endif
|
||||
static __KMEM_CACHE_T__ *branch_cachep;
|
||||
static __KMEM_CACHE_T__ *leaf_cachep;
|
||||
|
||||
|
||||
#if defined(__LITTLE_ENDIAN)
|
||||
#define ABCD(a,b,c,d,addrp) do { \
|
||||
@@ -69,7 +61,7 @@ static kmem_cache_t *leaf_cachep;
|
||||
} while (0)
|
||||
|
||||
static inline int
|
||||
__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
|
||||
iptree_test(struct ip_set *set, ip_set_ip_t *hash_ip, ip_set_ip_t ip)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
struct ip_set_iptreeb *btree;
|
||||
@@ -92,52 +84,10 @@ __testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
|
||||
|| time_after(dtree->expires[d], jiffies));
|
||||
}
|
||||
|
||||
static int
|
||||
testip(struct ip_set *set, const void *data, size_t size,
|
||||
ip_set_ip_t *hash_ip)
|
||||
{
|
||||
const struct ip_set_req_iptree *req = data;
|
||||
#define KADT_CONDITION
|
||||
|
||||
if (size != sizeof(struct ip_set_req_iptree)) {
|
||||
ip_set_printk("data length wrong (want %zu, have %zu)",
|
||||
sizeof(struct ip_set_req_iptree),
|
||||
size);
|
||||
return -EINVAL;
|
||||
}
|
||||
return __testip(set, req->ip, hash_ip);
|
||||
}
|
||||
|
||||
static int
|
||||
testip_kernel(struct ip_set *set,
|
||||
const struct sk_buff *skb,
|
||||
ip_set_ip_t *hash_ip,
|
||||
const u_int32_t *flags,
|
||||
unsigned char index)
|
||||
{
|
||||
int res;
|
||||
|
||||
DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
|
||||
flags[index] & IPSET_SRC ? "SRC" : "DST",
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
NIPQUAD(ip_hdr(skb)->saddr),
|
||||
NIPQUAD(ip_hdr(skb)->daddr));
|
||||
#else
|
||||
NIPQUAD(skb->nh.iph->saddr),
|
||||
NIPQUAD(skb->nh.iph->daddr));
|
||||
#endif
|
||||
|
||||
res = __testip(set,
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
? ip_hdr(skb)->saddr
|
||||
: ip_hdr(skb)->daddr),
|
||||
#else
|
||||
? skb->nh.iph->saddr
|
||||
: skb->nh.iph->daddr),
|
||||
#endif
|
||||
hash_ip);
|
||||
return (res < 0 ? 0 : res);
|
||||
}
|
||||
UADT(iptree, test)
|
||||
KADT(iptree, test, ipaddr)
|
||||
|
||||
#define ADDIP_WALK(map, elem, branch, type, cachep) do { \
|
||||
if ((map)->tree[elem]) { \
|
||||
@@ -155,8 +105,8 @@ testip_kernel(struct ip_set *set,
|
||||
} while (0)
|
||||
|
||||
static inline int
|
||||
__addip(struct ip_set *set, ip_set_ip_t ip, unsigned int timeout,
|
||||
ip_set_ip_t *hash_ip)
|
||||
iptree_add(struct ip_set *set, ip_set_ip_t *hash_ip,
|
||||
ip_set_ip_t ip, unsigned int timeout)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
struct ip_set_iptreeb *btree;
|
||||
@@ -179,6 +129,8 @@ __addip(struct ip_set *set, ip_set_ip_t ip, unsigned int timeout,
|
||||
if (dtree->expires[d]
|
||||
&& (!map->timeout || time_after(dtree->expires[d], jiffies)))
|
||||
ret = -EEXIST;
|
||||
if (map->timeout && timeout == 0)
|
||||
timeout = map->timeout;
|
||||
dtree->expires[d] = map->timeout ? (timeout * HZ + jiffies) : 1;
|
||||
/* Lottery: I won! */
|
||||
if (dtree->expires[d] == 0)
|
||||
@@ -189,46 +141,8 @@ __addip(struct ip_set *set, ip_set_ip_t ip, unsigned int timeout,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
addip(struct ip_set *set, const void *data, size_t size,
|
||||
ip_set_ip_t *hash_ip)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
const struct ip_set_req_iptree *req = data;
|
||||
|
||||
if (size != sizeof(struct ip_set_req_iptree)) {
|
||||
ip_set_printk("data length wrong (want %zu, have %zu)",
|
||||
sizeof(struct ip_set_req_iptree),
|
||||
size);
|
||||
return -EINVAL;
|
||||
}
|
||||
DP("%u.%u.%u.%u %u", HIPQUAD(req->ip), req->timeout);
|
||||
return __addip(set, req->ip,
|
||||
req->timeout ? req->timeout : map->timeout,
|
||||
hash_ip);
|
||||
}
|
||||
|
||||
static int
|
||||
addip_kernel(struct ip_set *set,
|
||||
const struct sk_buff *skb,
|
||||
ip_set_ip_t *hash_ip,
|
||||
const u_int32_t *flags,
|
||||
unsigned char index)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
|
||||
return __addip(set,
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
? ip_hdr(skb)->saddr
|
||||
: ip_hdr(skb)->daddr),
|
||||
#else
|
||||
? skb->nh.iph->saddr
|
||||
: skb->nh.iph->daddr),
|
||||
#endif
|
||||
map->timeout,
|
||||
hash_ip);
|
||||
}
|
||||
UADT(iptree, add, req->timeout)
|
||||
KADT(iptree, add, ipaddr, 0)
|
||||
|
||||
#define DELIP_WALK(map, elem, branch) do { \
|
||||
if ((map)->tree[elem]) { \
|
||||
@@ -238,7 +152,7 @@ addip_kernel(struct ip_set *set,
|
||||
} while (0)
|
||||
|
||||
static inline int
|
||||
__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
|
||||
iptree_del(struct ip_set *set, ip_set_ip_t *hash_ip, ip_set_ip_t ip)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
struct ip_set_iptreeb *btree;
|
||||
@@ -263,39 +177,8 @@ __delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
|
||||
return -EEXIST;
|
||||
}
|
||||
|
||||
static int
|
||||
delip(struct ip_set *set, const void *data, size_t size,
|
||||
ip_set_ip_t *hash_ip)
|
||||
{
|
||||
const struct ip_set_req_iptree *req = data;
|
||||
|
||||
if (size != sizeof(struct ip_set_req_iptree)) {
|
||||
ip_set_printk("data length wrong (want %zu, have %zu)",
|
||||
sizeof(struct ip_set_req_iptree),
|
||||
size);
|
||||
return -EINVAL;
|
||||
}
|
||||
return __delip(set, req->ip, hash_ip);
|
||||
}
|
||||
|
||||
static int
|
||||
delip_kernel(struct ip_set *set,
|
||||
const struct sk_buff *skb,
|
||||
ip_set_ip_t *hash_ip,
|
||||
const u_int32_t *flags,
|
||||
unsigned char index)
|
||||
{
|
||||
return __delip(set,
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
? ip_hdr(skb)->saddr
|
||||
: ip_hdr(skb)->daddr),
|
||||
#else
|
||||
? skb->nh.iph->saddr
|
||||
: skb->nh.iph->daddr),
|
||||
#endif
|
||||
hash_ip);
|
||||
}
|
||||
UADT(iptree, del)
|
||||
KADT(iptree, del, ipaddr)
|
||||
|
||||
#define LOOP_WALK_BEGIN(map, i, branch) \
|
||||
for (i = 0; i < 256; i++) { \
|
||||
@@ -305,7 +188,8 @@ delip_kernel(struct ip_set *set,
|
||||
|
||||
#define LOOP_WALK_END }
|
||||
|
||||
static void ip_tree_gc(unsigned long ul_set)
|
||||
static void
|
||||
ip_tree_gc(unsigned long ul_set)
|
||||
{
|
||||
struct ip_set *set = (struct ip_set *) ul_set;
|
||||
struct ip_set_iptree *map = set->data;
|
||||
@@ -375,7 +259,8 @@ static void ip_tree_gc(unsigned long ul_set)
|
||||
add_timer(&map->gc);
|
||||
}
|
||||
|
||||
static inline void init_gc_timer(struct ip_set *set)
|
||||
static inline void
|
||||
init_gc_timer(struct ip_set *set)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
|
||||
@@ -390,7 +275,8 @@ static inline void init_gc_timer(struct ip_set *set)
|
||||
add_timer(&map->gc);
|
||||
}
|
||||
|
||||
static int create(struct ip_set *set, const void *data, size_t size)
|
||||
static int
|
||||
iptree_create(struct ip_set *set, const void *data, size_t size)
|
||||
{
|
||||
const struct ip_set_req_iptree_create *req = data;
|
||||
struct ip_set_iptree *map;
|
||||
@@ -418,7 +304,8 @@ static int create(struct ip_set *set, const void *data, size_t size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __flush(struct ip_set_iptree *map)
|
||||
static inline void
|
||||
__flush(struct ip_set_iptree *map)
|
||||
{
|
||||
struct ip_set_iptreeb *btree;
|
||||
struct ip_set_iptreec *ctree;
|
||||
@@ -437,7 +324,8 @@ static void __flush(struct ip_set_iptree *map)
|
||||
map->elements = 0;
|
||||
}
|
||||
|
||||
static void destroy(struct ip_set *set)
|
||||
static void
|
||||
iptree_destroy(struct ip_set *set)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
|
||||
@@ -449,7 +337,8 @@ static void destroy(struct ip_set *set)
|
||||
set->data = NULL;
|
||||
}
|
||||
|
||||
static void flush(struct ip_set *set)
|
||||
static void
|
||||
iptree_flush(struct ip_set *set)
|
||||
{
|
||||
struct ip_set_iptree *map = set->data;
|
||||
unsigned int timeout = map->timeout;
|
||||
@@ -464,7 +353,8 @@ static void flush(struct ip_set *set)
|
||||
init_gc_timer(set);
|
||||
}
|
||||
|
||||
static void list_header(const struct ip_set *set, void *data)
|
||||
static void
|
||||
iptree_list_header(const struct ip_set *set, void *data)
|
||||
{
|
||||
const struct ip_set_iptree *map = set->data;
|
||||
struct ip_set_req_iptree_create *header = data;
|
||||
@@ -472,7 +362,8 @@ static void list_header(const struct ip_set *set, void *data)
|
||||
header->timeout = map->timeout;
|
||||
}
|
||||
|
||||
static int list_members_size(const struct ip_set *set)
|
||||
static int
|
||||
iptree_list_members_size(const struct ip_set *set)
|
||||
{
|
||||
const struct ip_set_iptree *map = set->data;
|
||||
struct ip_set_iptreeb *btree;
|
||||
@@ -497,7 +388,8 @@ static int list_members_size(const struct ip_set *set)
|
||||
return (count * sizeof(struct ip_set_req_iptree));
|
||||
}
|
||||
|
||||
static void list_members(const struct ip_set *set, void *data)
|
||||
static void
|
||||
iptree_list_members(const struct ip_set *set, void *data)
|
||||
{
|
||||
const struct ip_set_iptree *map = set->data;
|
||||
struct ip_set_iptreeb *btree;
|
||||
@@ -525,26 +417,7 @@ static void list_members(const struct ip_set *set, void *data)
|
||||
LOOP_WALK_END;
|
||||
}
|
||||
|
||||
static struct ip_set_type ip_set_iptree = {
|
||||
.typename = SETTYPE_NAME,
|
||||
.features = IPSET_TYPE_IP | IPSET_DATA_SINGLE,
|
||||
.protocol_version = IP_SET_PROTOCOL_VERSION,
|
||||
.create = &create,
|
||||
.destroy = &destroy,
|
||||
.flush = &flush,
|
||||
.reqsize = sizeof(struct ip_set_req_iptree),
|
||||
.addip = &addip,
|
||||
.addip_kernel = &addip_kernel,
|
||||
.delip = &delip,
|
||||
.delip_kernel = &delip_kernel,
|
||||
.testip = &testip,
|
||||
.testip_kernel = &testip_kernel,
|
||||
.header_size = sizeof(struct ip_set_req_iptree_create),
|
||||
.list_header = &list_header,
|
||||
.list_members_size = &list_members_size,
|
||||
.list_members = &list_members,
|
||||
.me = THIS_MODULE,
|
||||
};
|
||||
IP_SET_TYPE(iptree, IPSET_TYPE_IP | IPSET_DATA_SINGLE)
|
||||
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
|
||||
@@ -556,29 +429,15 @@ static int __init ip_set_iptree_init(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
|
||||
branch_cachep = kmem_cache_create("ip_set_iptreeb",
|
||||
sizeof(struct ip_set_iptreeb),
|
||||
0, 0, NULL);
|
||||
#else
|
||||
branch_cachep = kmem_cache_create("ip_set_iptreeb",
|
||||
sizeof(struct ip_set_iptreeb),
|
||||
0, 0, NULL, NULL);
|
||||
#endif
|
||||
branch_cachep = KMEM_CACHE_CREATE("ip_set_iptreeb",
|
||||
sizeof(struct ip_set_iptreeb));
|
||||
if (!branch_cachep) {
|
||||
printk(KERN_ERR "Unable to create ip_set_iptreeb slab cache\n");
|
||||
ret = -ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,23)
|
||||
leaf_cachep = kmem_cache_create("ip_set_iptreed",
|
||||
sizeof(struct ip_set_iptreed),
|
||||
0, 0, NULL);
|
||||
#else
|
||||
leaf_cachep = kmem_cache_create("ip_set_iptreed",
|
||||
sizeof(struct ip_set_iptreed),
|
||||
0, 0, NULL, NULL);
|
||||
#endif
|
||||
leaf_cachep = KMEM_CACHE_CREATE("ip_set_iptreed",
|
||||
sizeof(struct ip_set_iptreed));
|
||||
if (!leaf_cachep) {
|
||||
printk(KERN_ERR "Unable to create ip_set_iptreed slab cache\n");
|
||||
ret = -ENOMEM;
|
||||
|
Reference in New Issue
Block a user