From: Shen Qiyu Subject: For netfilter ipt_ops, init() and nf_register_hook() Date: Wed, 23 Oct 2002 14:57:33 +0800 Sender: netfilter-devel-admin@lists.netfilter.org Message-ID: <002701c27a61$766f7eb0$c801a8c0@network1.sh.cn> Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="Boundary_(ID_QBtkecoD4uASjDVVU0saEA)" Return-path: To: netfilter-devel@lists.netfilter.org Errors-To: netfilter-devel-admin@lists.netfilter.org List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: List-Id: netfilter-devel.vger.kernel.org This is a multi-part message in MIME format. --Boundary_(ID_QBtkecoD4uASjDVVU0saEA) Content-type: text/plain; charset=gb2312 Content-transfer-encoding: 7BIT Hi, guys, When I read the source of netfilter(withe kernel 2.4.18), something pullzed me. net/ipv4/netfilter/Iptable_filter.c .... static struct nf_hook_ops ipt_ops[] = { { { NULL, NULL }, ipt_hook, PF_INET, NF_IP_LOCAL_IN, NF_IP_PRI_FILTER }, { { NULL, NULL }, ipt_hook, PF_INET, NF_IP_FORWARD, NF_IP_PRI_FILTER }, { { NULL, NULL }, ipt_local_out_hook, PF_INET, NF_IP_LOCAL_OUT, NF_IP_PRI_FILTER } }; ... static int __init init(void) { ... ret = nf_register_hook(&ipt_ops[0]); ... } net\core\Netfilter.c int nf_register_hook(struct nf_hook_ops *reg) { struct list_head *i; br_write_lock_bh(BR_NETPROTO_LOCK); for (i = nf_hooks[reg->pf][reg->hooknum].next; i != &nf_hooks[reg->pf][reg->hooknum]; i = i->next) { if (reg->priority < ((struct nf_hook_ops *)i)->priority) break; } list_add(®->list, i->prev); br_write_unlock_bh(BR_NETPROTO_LOCK); return 0; } It seems that in list_add(®->list, i->prev), only a {NULL, NULL} list head is added, so how it run? Regards. Paul. 2002.10.23 --Boundary_(ID_QBtkecoD4uASjDVVU0saEA) Content-type: text/html; charset=gb2312 Content-transfer-encoding: 7BIT
Hi, guys,
 
When I read the source of netfilter(withe kernel 2.4.18), something pullzed me.
 
net/ipv4/netfilter/Iptable_filter.c
....
static struct nf_hook_ops ipt_ops[]
= { { { NULL, NULL }, ipt_hook, PF_INET, NF_IP_LOCAL_IN, NF_IP_PRI_FILTER },
    { { NULL, NULL }, ipt_hook, PF_INET, NF_IP_FORWARD, NF_IP_PRI_FILTER },
    { { NULL, NULL }, ipt_local_out_hook, PF_INET, NF_IP_LOCAL_OUT,
  NF_IP_PRI_FILTER }
};
...
static int __init init(void)
{
 ...
 ret = nf_register_hook(&ipt_ops[0]);
...
}
 
net\core\Netfilter.c
 
int nf_register_hook(struct nf_hook_ops *reg)
{
 struct list_head *i;
 
 br_write_lock_bh(BR_NETPROTO_LOCK);
 for (i = nf_hooks[reg->pf][reg->hooknum].next;
      i != &nf_hooks[reg->pf][reg->hooknum];
      i = i->next) {
  if (reg->priority < ((struct nf_hook_ops *)i)->priority)
   break;
 }
 list_add(&reg->list, i->prev);
 br_write_unlock_bh(BR_NETPROTO_LOCK);
 return 0;
}
 
It seems that in list_add(&reg->list, i->prev), only a {NULL, NULL} list head is added, so how it run?
 
Regards.
 
Paul.
2002.10.23

--Boundary_(ID_QBtkecoD4uASjDVVU0saEA)--