千家信息网

NetFilter

发表于:2025-01-20 作者:千家信息网编辑
千家信息网最后更新 2025年01月20日,typedef unsigned int nf_hookfn(unsigned int hooknum,struct sk_buff *skb,const struct net_device *in,
千家信息网最后更新 2025年01月20日NetFilter


  1. typedef unsigned int nf_hookfn(unsigned int hooknum,

  2. struct sk_buff *skb,

  3. const struct net_device *in,

  4. const struct net_device *out,

  5. int (*okfn) (struct sk_buff *));

  6. /* 处理函数返回值 */

  7. #define NF_DROP 0 /* drop the packet, don't continue traversal */

  8. #define NF_ACCEPT 1 /* continue traversal as normal */

  9. #define NF_STOLEN 2 /* I've taken over the packet, don't continue traversal */

  10. #define NF_QUEUE 3 /* queue the packet (usually for userspace handling) */

  11. #define NF_REPEAT 4 /* call this hook again */

  12. #define NF_STOP 5

  13. #define NF_MAX_VERDICT NF_STOP


在使用Netfilter时,需要定义一个nf_hook_ops实例。

  1. struct nf_hook_ops {

  2. struct list_head list;

  3. /* User fills in from here down. */

  4. nf_hookfn *hook; /* 要注册的钩子函数 */

  5. struct module *owner;

  6. u_int8_t pf; /* 协议类型 */

  7. unsigned int hooknum; /* 哪个钓鱼台 */

  8. /* Hooks are ordered in asending priority. */

  9. int priority; /* 数值越小,优先级越高 */

  10. };

  11. typedef __u8 u_int8_t;


0