当前位置: 技术问答>linux和unix
netfilter如何实现双网卡间数据包转发
来源: 互联网 发布时间:2016-08-12
本文导语: 这是我用的hook程序,请问实现双网卡间数据包转发要怎么修改? static void send_cs8900_skb(struct sk_buff *skb) { int k; struct sk_buff *skb1; unsigned char *d,*s; unsigned short proto; struct ethhdr *eth=skb->mac.etherne...
这是我用的hook程序,请问实现双网卡间数据包转发要怎么修改?
static void send_cs8900_skb(struct sk_buff *skb)
{
int k;
struct sk_buff *skb1;
unsigned char *d,*s;
unsigned short proto;
struct ethhdr *eth=skb->mac.ethernet;
d=eth->h_dest;
s=eth->h_source;
proto=eth->h_proto;
skb_push(skb,14);
for(k=0;kdata[k]=d[k];
skb->data[k+6]=s[k];
}
memcpy(skb->data+12,&proto,2);
skb->dev->cirrus_send_start(skb,skb->dev);(这里如何修改)}
static void send_dm9000_skb(struct sk_buff *skb)
{
int k;
unsigned char *d, *s;
unsigned short proto;
struct ethhdr *eth = skb->mac.ethernet;
d = eth->h_dest;
s = eth->h_source;
proto = eth->h_proto;
skb_push(skb,14);
for (k=0; kdata[k] = d[k];
skb->data[k+6] = s[k];
}
memcpy(skb->data+12, &proto, 2);
skb->dev->dmfe_start_xmit(skb,skb->dev);(这里如何修改)}
static unsigned int pf_hook_forward(unsigned int hooknum, struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (okfn)(struct sk_buff *));
struct nf_hook_ops pf_hook_ops=
{
.owner = THIS_MODULE,
.list = {NULL,NULL},
.hook = pf_hook_forward,
.pf = PF_INET,
.hooknum = NF_IP_PRE_ROUTING,
.priority= NF_IP_PRI_FIRST,
};
static int Skb_From_DM9000(char *mac_addr)
{
if((mac_addr[0]==0)&&(mac_addr[1]==12)&&(mac_addr[2]==34)&&(mac_addr[3]==56)&&(mac_addr[4]==80)&&(mac_addr[5]==49))
return 1;
else
return 0;
}
static unsigned int pf_hook_forward(unsigned int hooknum, struct sk_buff **skb,const struct net_device
*in,const struct net_device *out,int (okfn)(struct sk_buff *))
{
struct sk_buff *pskb= *skb;
unsigned char *d,*s;
unsigned short proto;
struct ethhdr *eth=pskb->mac.ethernet;
d=eth->h_dest;
s=eth->h_source;
/*判断数据包源是DM9000还是CS8900?*/
if(Skb_From_DM9000(s))
{
if(pf_filter_match_in(pskb))
send_cs8900_skb(pskb);
}
else
{
if(pf_filter_match_out(pskb))
send_dm9000_skb(pskb);
}
return NF_DROP;
}
static int __init fw_init(void)
{
int ret=0;
ret = nf_register_hook(&pf_hook_ops);
if(ret
static void send_cs8900_skb(struct sk_buff *skb)
{
int k;
struct sk_buff *skb1;
unsigned char *d,*s;
unsigned short proto;
struct ethhdr *eth=skb->mac.ethernet;
d=eth->h_dest;
s=eth->h_source;
proto=eth->h_proto;
skb_push(skb,14);
for(k=0;kdata[k]=d[k];
skb->data[k+6]=s[k];
}
memcpy(skb->data+12,&proto,2);
skb->dev->cirrus_send_start(skb,skb->dev);(这里如何修改)}
static void send_dm9000_skb(struct sk_buff *skb)
{
int k;
unsigned char *d, *s;
unsigned short proto;
struct ethhdr *eth = skb->mac.ethernet;
d = eth->h_dest;
s = eth->h_source;
proto = eth->h_proto;
skb_push(skb,14);
for (k=0; kdata[k] = d[k];
skb->data[k+6] = s[k];
}
memcpy(skb->data+12, &proto, 2);
skb->dev->dmfe_start_xmit(skb,skb->dev);(这里如何修改)}
static unsigned int pf_hook_forward(unsigned int hooknum, struct sk_buff **skb,const struct net_device *in,const struct net_device *out,int (okfn)(struct sk_buff *));
struct nf_hook_ops pf_hook_ops=
{
.owner = THIS_MODULE,
.list = {NULL,NULL},
.hook = pf_hook_forward,
.pf = PF_INET,
.hooknum = NF_IP_PRE_ROUTING,
.priority= NF_IP_PRI_FIRST,
};
static int Skb_From_DM9000(char *mac_addr)
{
if((mac_addr[0]==0)&&(mac_addr[1]==12)&&(mac_addr[2]==34)&&(mac_addr[3]==56)&&(mac_addr[4]==80)&&(mac_addr[5]==49))
return 1;
else
return 0;
}
static unsigned int pf_hook_forward(unsigned int hooknum, struct sk_buff **skb,const struct net_device
*in,const struct net_device *out,int (okfn)(struct sk_buff *))
{
struct sk_buff *pskb= *skb;
unsigned char *d,*s;
unsigned short proto;
struct ethhdr *eth=pskb->mac.ethernet;
d=eth->h_dest;
s=eth->h_source;
/*判断数据包源是DM9000还是CS8900?*/
if(Skb_From_DM9000(s))
{
if(pf_filter_match_in(pskb))
send_cs8900_skb(pskb);
}
else
{
if(pf_filter_match_out(pskb))
send_dm9000_skb(pskb);
}
return NF_DROP;
}
static int __init fw_init(void)
{
int ret=0;
ret = nf_register_hook(&pf_hook_ops);
if(ret
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
站内导航:
特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!