X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=dummynet%2Fnew_glue.c;fp=dummynet%2Fnew_glue.c;h=ce0a5a3b4c97c0f264375f27fced58db1e2b325c;hb=5ad9fec40da13c449d50def12f9cea6e24b6a708;hp=52a1a7fb271258dc9f95e5c22812bcb17927a3df;hpb=f1a44f1ebacf274e0f35970bfc8ee5aa07aa9aca;p=ipfw.git diff --git a/dummynet/new_glue.c b/dummynet/new_glue.c index 52a1a7f..ce0a5a3 100644 --- a/dummynet/new_glue.c +++ b/dummynet/new_glue.c @@ -1,24 +1,4 @@ #include "missing.h" -//#include -//#include -//#include -// #include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include -//#include /* for ETHERTYPE_IP */ -//#include -//#include -//#include -//#include #define IPFW_INTERNAL #include @@ -35,19 +15,18 @@ struct t_o { 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); @@ -101,9 +80,9 @@ add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, printf("%s called\n", __FUNCTION__); if (i < 0 || i > size-1) /* wrong table number */ return 1; - if (global_tables[i] == NULL) { + if (ch->global_tables[i] == NULL) { printf("Creating table n %d\n", tbl); - global_tables[i] = new_table_init(size, obj_size, + ch->global_tables[i] = new_table_init(size, obj_size, simple_hash32, cmp_func32, M_IPFW_HTBL); } @@ -112,7 +91,7 @@ add_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, 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; } @@ -124,7 +103,7 @@ new_del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr) 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; } @@ -142,10 +121,10 @@ del_table_entry(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, } 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; } @@ -154,7 +133,7 @@ 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); } @@ -166,28 +145,27 @@ lookup_table(struct ip_fw_chain *ch, uint16_t tbl, in_addr_t addr, 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]; + h = ch->global_tables[tbl - IPFW_TABLES_MAX]; printf("Search %d in table number %d\n", addr, tbl); - 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; + printf("obj->addr=%d,obj->value=%d\n",obj->addr, obj->value); + 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; } @@ -196,14 +174,14 @@ 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; @@ -211,7 +189,7 @@ new_dump_table_entry(ipfw_table *tbl) int i; int n_el; int nr = tbl->tbl - IPFW_TABLES_MAX; - struct new_hash_table *t = global_tables[nr]; + struct new_hash_table *t = ch->global_tables[nr]; printf("%s called\n", __FUNCTION__); @@ -242,7 +220,7 @@ 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); @@ -256,7 +234,7 @@ init_tables(struct ip_fw_chain *ch) 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);