Esempio n. 1
0
static void
hostfrag_create(struct ip * iph)
{
	// mknew函数最终调用了malloc以字节为单位分配内存
	struct hostfrags *hf = mknew(struct hostfrags);
	// 生成hash index
	int hash_index = frag_index(iph);

	// 填充hostfrags 结构体
	hf->prev = 0;
	// 插入到hash表头
	hf->next = fragtable[hash_index];
	// 维护双向链表
	if (hf->next)
		hf->next->prev = hf;
	// 挂到hash表上
	fragtable[hash_index] = hf;

	// 填充ip
	hf->ip = iph->ip_dst.s_addr;
	// 数据报队列初始化为空
	hf->ipqueue = 0;
	// 占用内存大小初始化为0
	hf->ip_frag_mem = 0;
	hf->hash_index = hash_index;
	// 设置当前host为刚刚创建的host
	this_host = hf;
}
Esempio n. 2
0
static void
hostfrag_create(struct ip * iph)
{
  struct hostfrags *hf = mknew(struct hostfrags);
  int hash_index = frag_index(iph);

  hf->prev = 0;
  hf->next = fragtable[hash_index];
  if (hf->next)
    hf->next->prev = hf;
  fragtable[hash_index] = hf;
  hf->ip = iph->ip_dst.s_addr;
  hf->ipqueue = 0;
  hf->ip_frag_mem = 0;
  hf->hash_index = hash_index;
  this_host = hf;
}
Esempio n. 3
0
static int
hostfrag_find(struct ip * iph)
{
  int hash_index = frag_index(iph);
  struct hostfrags *hf;

  this_host = 0;
  for (hf = fragtable[hash_index]; hf; hf = hf->next)
    if (hf->ip == iph->ip_dst.s_addr) {
      this_host = hf;
      break;
    }
  if (!this_host)
    return 0;
  else
    return 1;
}
Esempio n. 4
0
static void
//! hostfrag_create(struct ip * iph)
hostfrag_create(struct ip * iph,IP_THREAD_LOCAL_P  ip_thread_local_p)
{
	struct hostfrags *hf = mknew(struct hostfrags);
//!   int hash_index = frag_index(iph);
	int hash_index = frag_index(iph,ip_thread_local_p);

	hf->prev = 0;
//!   hf->next = fragtable[hash_index];
	hf->next = ip_thread_local_p->fragtable[hash_index];
	if (hf->next)
		hf->next->prev = hf;
//!   fragtable[hash_index] = hf;
	ip_thread_local_p->fragtable[hash_index] = hf;
	hf->ip = iph->ip_dst.s_addr;
	hf->ipqueue = 0;
	hf->ip_frag_mem = 0;
	hf->hash_index = hash_index;
//!   this_host = hf;
	ip_thread_local_p->this_host = hf;
}
Esempio n. 5
0
// 根据所给的ip头,找到与这个ip碎片对应的主机相关信息
// 这个主机相关信息,由全局变量this_host保存
// 成功更新this_host,返回1,否则返回0, this_host也为0
//
// 从这个函数可以看出,每一个host被放在一个hash项中,
// 采用的是链表法解决hash冲突
static int
hostfrag_find(struct ip * iph)
{
	// 首先生成一个hash index
	int hash_index = frag_index(iph);
	struct hostfrags *hf;

	// 将全局变量清零,这个全局变量总是指向当前报文对应的host
	this_host = 0;
	// 
	for (hf = fragtable[hash_index]; hf; hf = hf->next)
		if (hf->ip == iph->ip_dst.s_addr)
		{
			this_host = hf;
			break;
		}
	// 如果找不到,则返回0,否则返回1
	if (!this_host)
		return 0;
	else
		return 1;
}
Esempio n. 6
0
static int
//! hostfrag_find(struct ip * iph)
hostfrag_find(struct ip * iph,IP_THREAD_LOCAL_P  ip_thread_local_p)
{
//!   int hash_index = frag_index(iph);
	int hash_index = frag_index(iph,ip_thread_local_p);
	struct hostfrags *hf;

//!   this_host = 0;
	ip_thread_local_p->this_host = NULL;
//!   for (hf = fragtable[hash_index]; hf; hf = hf->next)
	for (hf = ip_thread_local_p->fragtable[hash_index]; hf; hf = hf->next)
		if (hf->ip == iph->ip_dst.s_addr) {
//!       this_host = hf;
			ip_thread_local_p->this_host = hf;
			break;
		}
//!   if (!this_host)
	if (!ip_thread_local_p->this_host)
		return 0;
	else
		return 1;
}