Commit 5a56f881 authored by Chen Wei's avatar Chen Wei

generalize the dict_node structure

add a void *obj to contain any pointer.
parent e0abe3ad
......@@ -129,8 +129,7 @@ struct dict_node * new_dictnode (char *label, int label_len)
node->sub_loadmax = 0;
node->sub_maxjump = 0;
node->sub = NULL;
node->sets = NULL;
node->sets_count = 0;
node->obj = NULL;
return node;
}
......@@ -304,7 +303,7 @@ struct dict_node * match_domain_ipsets (struct dict_node *root, char *domain)
if (node == NULL)
break;
if (node->sets != NULL)
if (node->obj != NULL)
res = node;
}
......@@ -406,8 +405,8 @@ void free_dicttree (struct dict_node *node)
if (np->label != NULL)
free (np->label);
if (np->sets != NULL)
free (np->sets);
if (np->obj != NULL)
free (np->obj);
free_dicttree (np);
}
......
......@@ -517,23 +517,28 @@ struct ipsets {
};
/* a dictionary node for open addressing hash table
* it has a key, "label", and several values.
* it has a key, "label", and a value "obj" as container, there are several
* other values for maintaining the hash table and lookup
*
* For ipsets match, only INSERT and LOOKUP operation needed
*/
struct dict_node {
char *label; /* key */
void *obj; /* the value, can point to anything */
uint32_t h1; /* from hash function 1, fnv_32_hash */
uint32_t h2; /* from hash function 2, bernstein_odd */
int sub_count; /* items stored in sub */
unsigned sub_slots; /* size of hash table sub */
int sub_count; /* items stored in sub */
int sub_loadmax; /* max items stored before upsize sub */
int sub_maxjump; /* max jumps for insertion, upsize when reach */
char **sets; /* ipsets names end with NULL ptr */
int sets_count;
struct dict_node **sub;
};
struct ipsets_names {
char **sets; /* ipsets names end with NULL ptr */
int count;
};
struct irec {
union mysockaddr addr;
struct in_addr netmask; /* only valid for IPv4 */
......
......@@ -535,6 +535,7 @@ static size_t process_reply(struct dns_header *header, time_t now, struct server
int munged = 0, is_sign;
size_t plen;
struct dict_node *np;
struct ipsets_names *obj;
(void)ad_reqd;
(void) do_bit;
......@@ -544,7 +545,10 @@ static size_t process_reply(struct dns_header *header, time_t now, struct server
{
np = match_domain_ipsets(daemon->dh_ipsets, daemon->namebuff);
if (np != NULL)
sets = np->sets;
{
obj = (struct ipsets_names *) np->obj;
sets = obj->sets;
}
}
#endif
......
......@@ -2208,6 +2208,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
case LOPT_LOCAL: /* --local */
case 'A': /* --address */
case LOPT_NO_REBIND: /* --rebind-domain-ok */
//TODO fast hash lookup
{
struct server *serv, *newlist = NULL;
......@@ -2343,7 +2344,8 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
char **sets, **sets_pos;
int sets_count = 0;
unhide_metas (arg);
struct dict_node *np;
struct dict_node *np = NULL;
struct ipsets_names *obj;
char *domain = NULL;
if (daemon->dh_ipsets == NULL)
......@@ -2366,7 +2368,7 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
option = '?';
if (domain != NULL)
add_domain (daemon->dh_ipsets, domain);
np = add_domain (daemon->dh_ipsets, domain);
arg = end;
}
......@@ -2394,11 +2396,12 @@ static int one_opt(int option, char *arg, char *errstr, char *gen_err, int comma
while (end);
*sets_pos = NULL;
if (domain != NULL)
if (np != NULL)
{
np = lookup_domain (daemon->dh_ipsets, domain);
np->sets = sets;
np->sets_count = sets_count;
obj = opt_malloc(sizeof(struct ipsets_names));
obj->sets = sets;
obj->count = sets_count;
np->obj = (void *) obj;
}
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment