- int nf_register_hook(struct nf_hook_ops *reg)
-
{
-
struct nf_hook_ops *elem;
-
int err;
-
-
err = mutex_lock_interruptible(&nf_hook_mutex);
-
if (err < 0)
-
return err;
-
list_for_each_entry(elem, &nf_hooks[reg->pf][reg->hooknum], list) {
-
if (reg->priority < elem->priority)
-
break;
-
}
-
list_add_rcu(®->list, elem->list.prev);
-
mutex_unlock(&nf_hook_mutex);
-
return 0;
-
}
-
-
int nf_register_hook(struct nf_hook_ops *reg)
-
{
-
struct nf_hook_ops *elem;
-
int err;
-
-
err = mutex_lock_interruptible(&nf_hook_mutex);
-
if (err < 0)
-
return err;
/*
通过reg->pf即协议,和reg->hooknum即挂载点,来确定二维数组nf_hooks的节点。
每个节点为某一协议的某一挂载点的netfiler匹配规则的链表。
*/
-
list_for_each_entry(elem, &nf_hooks[reg->pf][reg->hooknum], list) {
- /* 匹配规则按优先级排序,数值越小,优先级越高 */
-
if (reg->priority < elem->priority)
-
break;
-
}
- /* 将新的规则hook加入到list中 */
-
list_add_rcu(®->list, elem->list.prev);
-
mutex_unlock(&nf_hook_mutex);
-
return 0;
-
}