mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-21 03:54:59 +02:00
Import ipset-2.3.2 (kernel components)
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* 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
|
||||
* published by the Free Software Foundation.
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
/* Kernel module implementing an ip hash set */
|
||||
@@ -37,7 +37,7 @@ jhash_ip(const struct ip_set_iphash *map, uint16_t i, ip_set_ip_t ip)
|
||||
static inline __u32
|
||||
hash_id(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
struct ip_set_iphash *map = set->data;
|
||||
__u32 id;
|
||||
u_int16_t i;
|
||||
ip_set_ip_t *elem;
|
||||
@@ -68,8 +68,7 @@ static int
|
||||
testip(struct ip_set *set, const void *data, size_t size,
|
||||
ip_set_ip_t *hash_ip)
|
||||
{
|
||||
struct ip_set_req_iphash *req =
|
||||
(struct ip_set_req_iphash *) data;
|
||||
const struct ip_set_req_iphash *req = data;
|
||||
|
||||
if (size != sizeof(struct ip_set_req_iphash)) {
|
||||
ip_set_printk("data length wrong (want %zu, have %zu)",
|
||||
@@ -81,19 +80,19 @@ testip(struct ip_set *set, const void *data, size_t size,
|
||||
}
|
||||
|
||||
static int
|
||||
testip_kernel(struct ip_set *set,
|
||||
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)
|
||||
{
|
||||
return __testip(set,
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
? ip_hdr(skb)->saddr
|
||||
? ip_hdr(skb)->saddr
|
||||
: ip_hdr(skb)->daddr),
|
||||
#else
|
||||
? skb->nh.iph->saddr
|
||||
? skb->nh.iph->saddr
|
||||
: skb->nh.iph->daddr),
|
||||
#endif
|
||||
hash_ip);
|
||||
@@ -130,8 +129,7 @@ static int
|
||||
addip(struct ip_set *set, const void *data, size_t size,
|
||||
ip_set_ip_t *hash_ip)
|
||||
{
|
||||
struct ip_set_req_iphash *req =
|
||||
(struct ip_set_req_iphash *) data;
|
||||
const struct ip_set_req_iphash *req = data;
|
||||
|
||||
if (size != sizeof(struct ip_set_req_iphash)) {
|
||||
ip_set_printk("data length wrong (want %zu, have %zu)",
|
||||
@@ -139,23 +137,23 @@ addip(struct ip_set *set, const void *data, size_t size,
|
||||
size);
|
||||
return -EINVAL;
|
||||
}
|
||||
return __addip((struct ip_set_iphash *) set->data, req->ip, hash_ip);
|
||||
return __addip(set->data, req->ip, hash_ip);
|
||||
}
|
||||
|
||||
static int
|
||||
addip_kernel(struct ip_set *set,
|
||||
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)
|
||||
{
|
||||
return __addip((struct ip_set_iphash *) set->data,
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
? ip_hdr(skb)->saddr
|
||||
? ip_hdr(skb)->saddr
|
||||
: ip_hdr(skb)->daddr),
|
||||
#else
|
||||
? skb->nh.iph->saddr
|
||||
? skb->nh.iph->saddr
|
||||
: skb->nh.iph->daddr),
|
||||
#endif
|
||||
hash_ip);
|
||||
@@ -163,7 +161,7 @@ addip_kernel(struct ip_set *set,
|
||||
|
||||
static int retry(struct ip_set *set)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
struct ip_set_iphash *map = set->data;
|
||||
ip_set_ip_t hash_ip, *elem;
|
||||
void *members;
|
||||
u_int32_t i, hashsize = map->hashsize;
|
||||
@@ -185,7 +183,7 @@ static int retry(struct ip_set *set)
|
||||
"hashsize grows from %u to %u",
|
||||
set->name, map->hashsize, hashsize);
|
||||
|
||||
tmp = kmalloc(sizeof(struct ip_set_iphash)
|
||||
tmp = kmalloc(sizeof(struct ip_set_iphash)
|
||||
+ map->probes * sizeof(uint32_t), GFP_ATOMIC);
|
||||
if (!tmp) {
|
||||
DP("out of memory for %d bytes",
|
||||
@@ -207,7 +205,7 @@ static int retry(struct ip_set *set)
|
||||
memcpy(tmp->initval, map->initval, map->probes * sizeof(uint32_t));
|
||||
|
||||
write_lock_bh(&set->lock);
|
||||
map = (struct ip_set_iphash *) set->data; /* Play safe */
|
||||
map = set->data; /* Play safe */
|
||||
for (i = 0; i < map->hashsize && res == 0; i++) {
|
||||
elem = HARRAY_ELEM(map->members, ip_set_ip_t *, i);
|
||||
if (*elem)
|
||||
@@ -237,7 +235,7 @@ static int retry(struct ip_set *set)
|
||||
static inline int
|
||||
__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
struct ip_set_iphash *map = set->data;
|
||||
ip_set_ip_t id, *elem;
|
||||
|
||||
if (!ip)
|
||||
@@ -258,8 +256,7 @@ static int
|
||||
delip(struct ip_set *set, const void *data, size_t size,
|
||||
ip_set_ip_t *hash_ip)
|
||||
{
|
||||
struct ip_set_req_iphash *req =
|
||||
(struct ip_set_req_iphash *) data;
|
||||
const struct ip_set_req_iphash *req = data;
|
||||
|
||||
if (size != sizeof(struct ip_set_req_iphash)) {
|
||||
ip_set_printk("data length wrong (want %zu, have %zu)",
|
||||
@@ -271,19 +268,19 @@ delip(struct ip_set *set, const void *data, size_t size,
|
||||
}
|
||||
|
||||
static int
|
||||
delip_kernel(struct ip_set *set,
|
||||
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
|
||||
ntohl(flags[index] & IPSET_SRC
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
|
||||
? ip_hdr(skb)->saddr
|
||||
? ip_hdr(skb)->saddr
|
||||
: ip_hdr(skb)->daddr),
|
||||
#else
|
||||
? skb->nh.iph->saddr
|
||||
? skb->nh.iph->saddr
|
||||
: skb->nh.iph->daddr),
|
||||
#endif
|
||||
hash_ip);
|
||||
@@ -291,8 +288,7 @@ delip_kernel(struct ip_set *set,
|
||||
|
||||
static int create(struct ip_set *set, const void *data, size_t size)
|
||||
{
|
||||
struct ip_set_req_iphash_create *req =
|
||||
(struct ip_set_req_iphash_create *) data;
|
||||
const struct ip_set_req_iphash_create *req = data;
|
||||
struct ip_set_iphash *map;
|
||||
uint16_t i;
|
||||
|
||||
@@ -313,7 +309,7 @@ static int create(struct ip_set *set, const void *data, size_t size)
|
||||
return -ENOEXEC;
|
||||
}
|
||||
|
||||
map = kmalloc(sizeof(struct ip_set_iphash)
|
||||
map = kmalloc(sizeof(struct ip_set_iphash)
|
||||
+ req->probes * sizeof(uint32_t), GFP_KERNEL);
|
||||
if (!map) {
|
||||
DP("out of memory for %d bytes",
|
||||
@@ -341,7 +337,7 @@ static int create(struct ip_set *set, const void *data, size_t size)
|
||||
|
||||
static void destroy(struct ip_set *set)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
struct ip_set_iphash *map = set->data;
|
||||
|
||||
harray_free(map->members);
|
||||
kfree(map);
|
||||
@@ -351,16 +347,15 @@ static void destroy(struct ip_set *set)
|
||||
|
||||
static void flush(struct ip_set *set)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
struct ip_set_iphash *map = set->data;
|
||||
harray_flush(map->members, map->hashsize, sizeof(ip_set_ip_t));
|
||||
map->elements = 0;
|
||||
}
|
||||
|
||||
static void list_header(const struct ip_set *set, void *data)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
struct ip_set_req_iphash_create *header =
|
||||
(struct ip_set_req_iphash_create *) data;
|
||||
struct ip_set_iphash *map = set->data;
|
||||
struct ip_set_req_iphash_create *header = data;
|
||||
|
||||
header->hashsize = map->hashsize;
|
||||
header->probes = map->probes;
|
||||
@@ -370,14 +365,14 @@ static void list_header(const struct ip_set *set, void *data)
|
||||
|
||||
static int list_members_size(const struct ip_set *set)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
const struct ip_set_iphash *map = set->data;
|
||||
|
||||
return (map->hashsize * sizeof(ip_set_ip_t));
|
||||
}
|
||||
|
||||
static void list_members(const struct ip_set *set, void *data)
|
||||
{
|
||||
struct ip_set_iphash *map = (struct ip_set_iphash *) set->data;
|
||||
const struct ip_set_iphash *map = set->data;
|
||||
ip_set_ip_t i, *elem;
|
||||
|
||||
for (i = 0; i < map->hashsize; i++) {
|
||||
|
Reference in New Issue
Block a user