mirror of
git://git.code.sf.net/p/xtables-addons/xtables-addons
synced 2025-09-06 12:45:13 +02:00
xt_geoip: v4/v6 name preparations
This commit is contained in:
@@ -49,9 +49,10 @@ static struct option geoip_opts[] = {
|
|||||||
{NULL},
|
{NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct geoip_subnet *geoip_get_subnets(const char *code, uint32_t *count)
|
static struct geoip_subnet4 *
|
||||||
|
geoip_get_subnets(const char *code, uint32_t *count)
|
||||||
{
|
{
|
||||||
struct geoip_subnet *subnets;
|
struct geoip_subnet4 *subnets;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
int fd;
|
int fd;
|
||||||
@@ -69,7 +70,7 @@ static struct geoip_subnet *geoip_get_subnets(const char *code, uint32_t *count)
|
|||||||
}
|
}
|
||||||
|
|
||||||
fstat(fd, &sb);
|
fstat(fd, &sb);
|
||||||
if (sb.st_size % sizeof(struct geoip_subnet) != 0)
|
if (sb.st_size % sizeof(struct geoip_subnet4) != 0)
|
||||||
xtables_error(OTHER_PROBLEM, "Database file %s seems to be "
|
xtables_error(OTHER_PROBLEM, "Database file %s seems to be "
|
||||||
"corrupted", buf);
|
"corrupted", buf);
|
||||||
subnets = malloc(sb.st_size);
|
subnets = malloc(sb.st_size);
|
||||||
@@ -77,7 +78,7 @@ static struct geoip_subnet *geoip_get_subnets(const char *code, uint32_t *count)
|
|||||||
xtables_error(OTHER_PROBLEM, "geoip: insufficient memory");
|
xtables_error(OTHER_PROBLEM, "geoip: insufficient memory");
|
||||||
read(fd, subnets, sb.st_size);
|
read(fd, subnets, sb.st_size);
|
||||||
close(fd);
|
close(fd);
|
||||||
*count = sb.st_size / sizeof(struct geoip_subnet);
|
*count = sb.st_size / sizeof(struct geoip_subnet4);
|
||||||
return subnets;
|
return subnets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ MODULE_ALIAS("ipt_geoip");
|
|||||||
*/
|
*/
|
||||||
struct geoip_country_kernel {
|
struct geoip_country_kernel {
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
struct geoip_subnet *subnets;
|
struct geoip_subnet4 *subnets;
|
||||||
atomic_t ref;
|
atomic_t ref;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
unsigned short cc;
|
unsigned short cc;
|
||||||
@@ -51,7 +51,7 @@ geoip_add_node(const struct geoip_country_user __user *umem_ptr)
|
|||||||
{
|
{
|
||||||
struct geoip_country_user umem;
|
struct geoip_country_user umem;
|
||||||
struct geoip_country_kernel *p;
|
struct geoip_country_kernel *p;
|
||||||
struct geoip_subnet *subnet;
|
struct geoip_subnet4 *subnet;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (copy_from_user(&umem, umem_ptr, sizeof(umem)) != 0)
|
if (copy_from_user(&umem, umem_ptr, sizeof(umem)) != 0)
|
||||||
@@ -64,14 +64,14 @@ geoip_add_node(const struct geoip_country_user __user *umem_ptr)
|
|||||||
p->count = umem.count;
|
p->count = umem.count;
|
||||||
p->cc = umem.cc;
|
p->cc = umem.cc;
|
||||||
|
|
||||||
subnet = vmalloc(p->count * sizeof(struct geoip_subnet));
|
subnet = vmalloc(p->count * sizeof(struct geoip_subnet4));
|
||||||
if (subnet == NULL) {
|
if (subnet == NULL) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto free_p;
|
goto free_p;
|
||||||
}
|
}
|
||||||
if (copy_from_user(subnet,
|
if (copy_from_user(subnet,
|
||||||
(const void __user *)(unsigned long)umem.subnets,
|
(const void __user *)(unsigned long)umem.subnets,
|
||||||
p->count * sizeof(struct geoip_subnet)) != 0) {
|
p->count * sizeof(struct geoip_subnet4)) != 0) {
|
||||||
ret = -EFAULT;
|
ret = -EFAULT;
|
||||||
goto free_s;
|
goto free_s;
|
||||||
}
|
}
|
||||||
@@ -128,7 +128,7 @@ static struct geoip_country_kernel *find_node(unsigned short cc)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool geoip_bsearch(const struct geoip_subnet *range,
|
static bool geoip_bsearch4(const struct geoip_subnet4 *range,
|
||||||
uint32_t addr, int lo, int hi)
|
uint32_t addr, int lo, int hi)
|
||||||
{
|
{
|
||||||
int mid;
|
int mid;
|
||||||
@@ -139,16 +139,16 @@ static bool geoip_bsearch(const struct geoip_subnet *range,
|
|||||||
if (range[mid].begin <= addr && addr <= range[mid].end)
|
if (range[mid].begin <= addr && addr <= range[mid].end)
|
||||||
return true;
|
return true;
|
||||||
if (range[mid].begin > addr)
|
if (range[mid].begin > addr)
|
||||||
return geoip_bsearch(range, addr, lo, mid);
|
return geoip_bsearch4(range, addr, lo, mid);
|
||||||
else if (range[mid].end < addr)
|
else if (range[mid].end < addr)
|
||||||
return geoip_bsearch(range, addr, mid + 1, hi);
|
return geoip_bsearch4(range, addr, mid + 1, hi);
|
||||||
|
|
||||||
WARN_ON(true);
|
WARN_ON(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
xt_geoip_mt(const struct sk_buff *skb, struct xt_action_param *par)
|
xt_geoip_mt4(const struct sk_buff *skb, struct xt_action_param *par)
|
||||||
{
|
{
|
||||||
const struct xt_geoip_match_info *info = par->matchinfo;
|
const struct xt_geoip_match_info *info = par->matchinfo;
|
||||||
const struct geoip_country_kernel *node;
|
const struct geoip_country_kernel *node;
|
||||||
@@ -164,7 +164,7 @@ xt_geoip_mt(const struct sk_buff *skb, struct xt_action_param *par)
|
|||||||
COUNTRY(info->cc[i]));
|
COUNTRY(info->cc[i]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (geoip_bsearch(node->subnets, ip, 0, node->count)) {
|
if (geoip_bsearch4(node->subnets, ip, 0, node->count)) {
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
return !(info->flags & XT_GEOIP_INV);
|
return !(info->flags & XT_GEOIP_INV);
|
||||||
}
|
}
|
||||||
@@ -232,7 +232,7 @@ static struct xt_match xt_geoip_match __read_mostly = {
|
|||||||
.name = "geoip",
|
.name = "geoip",
|
||||||
.revision = 1,
|
.revision = 1,
|
||||||
.family = NFPROTO_IPV4,
|
.family = NFPROTO_IPV4,
|
||||||
.match = xt_geoip_mt,
|
.match = xt_geoip_mt4,
|
||||||
.checkentry = xt_geoip_mt_checkentry,
|
.checkentry = xt_geoip_mt_checkentry,
|
||||||
.destroy = xt_geoip_mt_destroy,
|
.destroy = xt_geoip_mt_destroy,
|
||||||
.matchsize = sizeof(struct xt_geoip_match_info),
|
.matchsize = sizeof(struct xt_geoip_match_info),
|
||||||
|
@@ -22,7 +22,7 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Yup, an address range will be passed in with host-order */
|
/* Yup, an address range will be passed in with host-order */
|
||||||
struct geoip_subnet {
|
struct geoip_subnet4 {
|
||||||
__u32 begin;
|
__u32 begin;
|
||||||
__u32 end;
|
__u32 end;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user