(三)ip_queue报文入队处理函数的注册
在上面分析的模块注册代码中,IP Queue的报文入队处理函数的注册是通过调用nf_register_queue_handler()来实现的。因此,有必要了解一下该函数的源码,源码位于nf_queue.c中:
- /* return EBUSY when somebody else is registered, return EEXIST if the
- * same handler is registered, return 0 in case of success. */
- int nf_register_queue_handler(int pf, struct nf_queue_handler *qh)
- {
- int ret;
- /*IP协议族的值必须在当前指定的范围内*/
- if (pf >= NPROTO)
- return -EINVAL;
- write_lock_bh(&queue_handler_lock);
- /*该queue handler已经被注册过了*/
- if (queue_handler[pf] == qh)
- ret = -EEXIST;
- /*该协议族已经被注册了handler了*/
- else if (queue_handler[pf])
- ret = -EBUSY;
- /*将该协议的queue hanler指向参数qh*/
- else {
- queue_handler[pf] = qh;
- ret = 0;
- }
- write_unlock_bh(&queue_handler_lock);
- return ret;
- }