示例#1
0
文件: bloom.c 项目: pfq/PFQ
static int bloom_init(arguments_t args)
{
	unsigned int m = GET_ARG_0(unsigned int, args);
	size_t n = LEN_ARRAY_1(args);
	__be32 *ips = GET_ARRAY_1(__be32, args);
	__be32 mask;
	size_t i;

	char *mem;

	m = clp2(m);

	/* set bloom filter fold mask */

	SET_ARG_0(args, m-1);

	if (m > (1UL << 24)) {
		printk(KERN_INFO "[PFQ|init] bloom filter: maximum number of bins exceeded (2^24)!\n");
		return -EPERM;
	}

	mem = kzalloc(m >> 3, GFP_KERNEL);
	if (!mem) {
		printk(KERN_INFO "[PFQ|init] bloom filter: out of memory!\n");
		return -ENOMEM;
	}

	/* set bloom filter memory */

	SET_ARG_1(args, mem);

	mask = inet_make_mask(GET_ARG_2(int, args));

	/* set network mask */

	SET_ARG_2(args, mask);

	pr_devel("[PFQ|init] bloom filter@%p: k=4, n=%zu, m=%u size=%u netmask=%pI4 bytes.\n", mem, n, m, m>>3, &mask);

	for(i = 0; i < n; i++)
	{
		uint32_t h1 = hfun1(be32_to_cpu(ips[i] & mask)) & (m-1);
		uint32_t h2 = hfun2(be32_to_cpu(ips[i] & mask)) & (m-1);
		uint32_t h3 = hfun3(be32_to_cpu(ips[i] & mask)) & (m-1);
		uint32_t h4 = hfun4(be32_to_cpu(ips[i] & mask)) & (m-1);

		BF_SET(mem, h1);
		BF_SET(mem, h2);
		BF_SET(mem, h3);
		BF_SET(mem, h4);

		pr_devel("[PFQ|init] bloom filter: -> set address %pI4\n", ips+i);
	}

	return 0;
}
示例#2
0
文件: filter.c 项目: pandaychen/PFQ
static int filter_addr_init(arguments_t args)
{
	__be32 mask, ipv4 = GET_ARG_0(__be32, args);
	int prefix  = GET_ARG_1(int, args);

	mask = inet_make_mask(prefix);

	SET_ARG_0(args, ipv4 & mask);
	SET_ARG_1(args, mask);

	pr_devel("[PFQ|init] filter: addr:%pI4 mask:%pI4\n", &ipv4, &mask);

	return 0;
}