#include "missing.h"
-//#include <sys/param.h>
-//#include <sys/systm.h>
-//#include <sys/malloc.h>
-// #include <sys/mbuf.h>
-//#include <sys/kernel.h>
-//#include <sys/lock.h>
-//#include <sys/jail.h>
-//#include <sys/module.h>
-//#include <sys/priv.h>
-//#include <sys/proc.h>
-//#include <sys/socket.h>
-//#include <sys/socketvar.h>
-//#include <sys/sysctl.h>
-//#include <sys/syslog.h>
-//#include <sys/ucred.h>
-//#include <net/ethernet.h> /* for ETHERTYPE_IP */
-//#include <net/if.h>
-//#include <net/radix.h>
-//#include <net/route.h>
-//#include <net/pf_mtag.h>
#define IPFW_INTERNAL
#include <netinet/ip_fw.h>
MALLOC_DEFINE(M_IPFW_HTBL, "ipfw_tbl", "IpFw tables");
-static struct new_hash_table *global_tables[128];
int add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
uint8_t mlen, uint32_t value);
int new_del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr);
int del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
uint8_t mlen);
-int new_flush_table(uint16_t tbl);
+int new_flush_table(struct ip_fw_chain *ch, uint16_t tbl);
int flush_table(struct ip_fw_chain *ch, uint16_t tbl);
int lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
uint32_t *val);
-int new_count_table_entry(uint32_t tbl, uint32_t *cnt);
+int new_count_table_entry(struct ip_fw_chain *ch, uint32_t tbl, uint32_t *cnt);
int count_table(struct ip_fw_chain *ch, uint32_t tbl, uint32_t *cnt);
-int new_dump_table_entry(ipfw_table *tbl);
+int new_dump_table_entry(struct ip_fw_chain *ch, ipfw_table *tbl);
int dump_table(struct ip_fw_chain *ch, ipfw_table *tbl);
int init_tables(struct ip_fw_chain *ch);
simple_hash32(const void *key, uint32_t size)
{
uint32_t ret = *(const uint32_t *)key % size;
- printf("%s called\n", __FUNCTION__);
- printf("Hash returns %d\n", ret);
return ret;
}
static int
-cmp_func32(const void *key1, const void *key2)
+cmp_func32(const void *key1, const void *key2, int sz)
{
int k1 = *(const int *)key1;
int k2 = *(const int *)key2;
int ret;
- printf("(%s) k1=%d, k2=%d\n", __FUNCTION__, k1, k2);
+
if (k1 < k2)
ret = -1;
else if (k1 > k2)
else
ret = 0;
- printf("compare returns %d\n", ret);
-
return ret;
}
int size = 128;
int obj_size = sizeof(struct t_o);
- printf("%s called\n", __FUNCTION__);
if (i < 0 || i > size-1) /* wrong table number */
return 1;
- if (global_tables[i] == NULL) {
- printf("Creating table n %d\n", tbl);
- global_tables[i] = new_table_init(size, obj_size,
+ if (ch->global_tables[i] == NULL) {
+ ch->global_tables[i] = new_table_init(size, obj_size,
simple_hash32, cmp_func32, M_IPFW_HTBL);
}
obj.mask = mlen;
/* Insert the object in the table */
- ret = new_table_insert_obj(global_tables[i], &obj);
+ ret = new_table_insert_obj(ch->global_tables[i], &obj);
return ret;
}
int ret;
int nr = tbl - IPFW_TABLES_MAX;
- printf("%s called\n", __FUNCTION__);
-
- ret = new_table_delete_obj(global_tables[nr], &addr);
+ ret = new_table_delete_obj(ch->global_tables[nr], &addr);
return ret;
}
del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
uint8_t mlen)
{
- printf("%s called\n", __FUNCTION__);
if (tbl >= IPFW_TABLES_MAX && tbl < IPFW_NEWTABLES_MAX) {
new_del_table_entry(ch, tbl, addr);
return 0;
}
int
-new_flush_table(uint16_t tbl)
+new_flush_table(struct ip_fw_chain *ch, uint16_t tbl)
{
- printf("%s called\n", __FUNCTION__);
- new_table_destroy(global_tables[tbl - IPFW_TABLES_MAX]);
+ new_table_destroy(ch->global_tables[tbl - IPFW_TABLES_MAX]);
return 0;
}
int
flush_table(struct ip_fw_chain *ch, uint16_t tbl)
{
- printf("%s called\n", __FUNCTION__);
if (tbl >= IPFW_TABLES_MAX && tbl < IPFW_NEWTABLES_MAX)
- return new_flush_table(tbl);
+ return new_flush_table(ch, tbl);
return (EINVAL);
}
lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr,
uint32_t *val)
{
- printf("%s called\n", __FUNCTION__);
if (tbl >= IPFW_TABLES_MAX && tbl < IPFW_NEWTABLES_MAX) {
struct new_hash_table *h;
- struct t_o *obj;
+ const struct t_o *obj;
- h = global_tables[tbl - IPFW_NEWTABLES_MAX];
- printf("Search %d in table number %d\n", addr, tbl);
+ h = ch->global_tables[tbl - IPFW_TABLES_MAX];
- obj = (struct t_o *)new_table_extract_obj(h, (void *)&addr);
+ obj = new_table_extract_obj(h, (void *)&addr);
if (obj == NULL)
- return 0;
+ return 0; /* no match */
*val = obj->value;
-
- return 1;
+ return 1; /* match */
}
-
- return 1;
+ return 0;
}
int
-new_count_table_entry(uint32_t tbl, uint32_t *cnt)
+new_count_table_entry(struct ip_fw_chain *ch, uint32_t tbl, uint32_t *cnt)
{
- printf("%s called\n", __FUNCTION__);
- *cnt = new_table_get_element(global_tables[tbl - IPFW_TABLES_MAX]);
+ *cnt = new_table_get_element(ch->global_tables[tbl - IPFW_TABLES_MAX]);
return 0;
}
int
count_table(struct ip_fw_chain *ch, uint32_t tbl, uint32_t *cnt)
{
- printf("%s called\n", __FUNCTION__);
if (tbl >= IPFW_TABLES_MAX && tbl < IPFW_NEWTABLES_MAX) {
- new_count_table_entry(tbl, cnt);
+ new_count_table_entry(ch, tbl, cnt);
return (0);
}
return (EINVAL);
}
int
-new_dump_table_entry(ipfw_table *tbl)
+new_dump_table_entry(struct ip_fw_chain *ch, ipfw_table *tbl)
{
/* fill the tbl with all entryes */
ipfw_table_entry *ent;
int i;
int n_el;
int nr = tbl->tbl - IPFW_TABLES_MAX;
- struct new_hash_table *t = global_tables[nr];
-
- printf("%s called\n", __FUNCTION__);
+ struct new_hash_table *t = ch->global_tables[nr];
i = 0;
tbl->cnt = 0;
obj = table_next(t, obj);
if (obj == NULL)
break;
- printf("Found \n");
ent = &tbl->ent[tbl->cnt];
ent->addr = obj->addr;
ent->masklen = obj->mask;
tbl->cnt++;
}
- printf("\n");
return 0;
}
int
dump_table(struct ip_fw_chain *ch, ipfw_table *tbl)
{
- printf("%s called\n", __FUNCTION__);
if (tbl->tbl >= IPFW_TABLES_MAX && tbl->tbl < IPFW_NEWTABLES_MAX) {
- new_dump_table_entry(tbl);
+ new_dump_table_entry(ch, tbl);
return (0);
}
return (EINVAL);
{
int i;
- printf("%s called\n", __FUNCTION__);
/* Initialize new tables XXXMPD */
for (i = 0; i < IPFW_NEWTABLES_MAX - IPFW_TABLES_MAX; i++) {
- memset(&global_tables[i], sizeof(struct new_hash_table*), 0);
+ memset(&ch->global_tables[i], sizeof(struct new_hash_table*), 0);
}
return (0);