Permalink
Browse files

improved mdb.c by reading pset_mask from .conf; improved pset_hash;

  • Loading branch information...
gnocuil committed Oct 6, 2012
1 parent c9c9cdc commit a449f085f5807df58dac8711fcd9b3281196342c
@@ -211,7 +211,7 @@ static struct option dhcp_options[] = {
{ "vivco", "Evendor-class.", &dhcp_universe, 124, 1 },
{ "vivso", "Evendor.", &dhcp_universe, 125, 1 },
/* pset option, newly defined. */
- { "port-set", "SA", &dhcp_universe, 198, 1 },
+ { "port-set", "S", &dhcp_universe, 224, 1 },//[pset] modified by Liu Cong
#if 0
/* Referenced by RFC 4578.
@@ -3277,6 +3277,7 @@ int find_lease_by_ip_addr (struct lease **, struct iaddr,
const char *, int);
int find_lease_by_ip_pset (struct lease **, struct iaddr_pset,
const char *, int); //[pset] modified by Liu Cong
+int mask_bits_pset(u_int16_t);//[pset] added by Liu Cong
void uid_hash_add (struct lease *);
void uid_hash_delete (struct lease *);
void hw_hash_add (struct lease *);
@@ -367,15 +367,26 @@ piaddr222(const struct iaddr addr) {
addr.len);
// quell compiler warnings
return NULL;
+}*/
+
+int mask_bits_pset(u_int16_t mask)//[pset] added by Liu Cong
+{
+ int result = 16;
+ while (mask && (mask & 1) == 0) {
+ --result;
+ mask >>= 1;
+ }
+ return result;
}
-*/
+
unsigned
do_ip4_pset_hash(const void *key, unsigned len, unsigned size)//[pset] added by Liu Cong
{
struct iaddr_pset* ip_pset = (struct iaddr_pset*) key;
u_int32_t number = do_ip4_hash(ip_pset->ip_addr.iabuf, len, size);
- number = (number << 2) | ip_pset->pset_index;
- //printf("do_ip4_pset_hash! ip=%s port=%d number=%d\n", piaddr222 (ip_pset->ip_addr), ip_pset->pset_index, number);
+ int bits = mask_bits_pset(ip_pset->pset_mask);
+ number = (number << bits) | (ip_pset->pset_index >> (16 - bits));
+ //printf("do_ip4_pset_hash! ip=%s port=%x mask=%x number=%d\n", piaddr222 (ip_pset->ip_addr), ip_pset->pset_index, ip_pset->pset_mask, number);
return number % size;
}
Oops, something went wrong.

0 comments on commit a449f08

Please sign in to comment.