- 论坛徽章:
- 0
|
回复 4# GFree_Wind
unsigned int rcv_func(unsigned int hooknum, struct sk_buff *skb, const struct net_device *in, const struct net_device *out ,int (*okfn)(struct sk_buff *))
{
if(is_ports(in))
{
nskb=skb_clone(skb,GFP_ATOMIC);
if(!nskb)
return NF_ACCEPT;
mirror = dev_get_by_name(&init_net, dst);
nskb->dev=mirror;
dev_put(mirror);
skb_push(nskb, nskb->mac_len);
dev_queue_xmit(nskb);
}
return NF_ACCEPT;
}
unsigned int send_func(...)
{
if(is_ports(skb->dev)
{
nskb=skb_clone(skb,GFP_ATOMIC);
if(!nskb)
return NF_ACCEPT;
mirror = dev_get_by_name(&init_net, dst);
nskb->dev=mirror;
dev_put(mirror);
ip_finish_output(nskb);
}
return NF_ACCEPT;
}
以上两个函数分别是在NF_INET_PRE_ROUTING和NF_INET_POST_ROUTING两个netfilter的hook点挂的钩子函数
省略数据声明。其中is_ports判断是否是要监听的端口,如判断skb->dev是否是eth1。dst是要镜像到的端口名称,如"eth0"
|
|