- 論壇徽章:
- 0
|
看了九賤兄寫的hashlimit模塊的理解,大有收獲,但還是有一些細節(jié)沒有搞清楚,代碼如下:
2.6.35/net/netfilter/xt_hashlimit.c中的static int htable_create()函數(shù)中:
{
.....
/* FIXME: don't use vmalloc() here or anywhere else -HW */
hinfo = vmalloc(sizeof(struct xt_hashlimit_htable) + sizeof(struct list_head) * size);
if (hinfo == NULL)
return -ENOMEM;
minfo->hinfo = hinfo;
/* copy match config into hashtable config */
memcpy(&hinfo->cfg, &minfo->cfg, sizeof(hinfo->cfg));
hinfo->cfg.size = size;
if (hinfo->cfg.max == 0)
hinfo->cfg.max = 8 * hinfo->cfg.size;
else if (hinfo->cfg.max < hinfo->cfg.size)
hinfo->cfg.max = hinfo->cfg.size;
for (i = 0; i < hinfo->cfg.size; i++)
INIT_HLIST_HEAD(&hinfo->hash[i]);
.....
}
上面代碼中是用sizeof(struct list_head) 類型來申請的空間,而后面卻是用哈希表頭的初始化INIT_HLIST_HEAD(&hinfo->hash[i])函數(shù)來進行初始化的,
這樣就相當于多申請了一倍的空間,不知為什么?用8字節(jié)的類型來申請的空間,卻用4字節(jié)的類型來進行初始化,不理解為什么?請大家?guī)臀铱纯催@兒是怎么一
回事? |
|