- 论坛徽章:
- 0
|
本帖最后由 mengxh3000 于 2014-08-12 10:17 编辑
在网桥的 NF_BR_POST_ROUTING 里面 把普通的ETH_P_IP包添加vlan id 变成ETH_P_8021Q的包,调用 dev_queue_xmit 返回0,但是对方并没有收到包。(本机没有配置vlan的虚拟网卡,就是用eth0发送)不知道问题出在哪里 ,代码如下:
static unsigned int brTestHookLocalPostRouting(unsigned int hooknum,
struct sk_buff **skb,
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff *))
{
int ret = 0;
struct vlan_ethhdr *veth;
struct sk_buff *pskb = *skb;
if (pskb == NULL)
return NF_DROP;
//printk("PostRouting ---- \n");
if (pskb->protocol == __constant_htons(ETH_P_8021Q))
{
return NF_ACCEPT;
}
hexDump(pskb->mac.raw, 60);
printk("PostRouting ---- PostRouting\n");
// 本机的mac地址,若是从本机发出的包就打上vlan id 为100的tag
// 00 e9 24 13 12 49
unsigned char* p = pskb->mac.raw;
if (p[6] == 0x00 && p[7] == 0xe9 &&
p[8] == 0x24 && p[9] == 0x13 &&
p[10] == 0x12 && p[11] == 0x49)
{
printk("PostRouting ---- put tag\n");
skb_push(pskb, ETH_HLEN);
struct vlan_ethhdr *veth1;
if (skb_headroom(pskb) < VLAN_HLEN)
{
struct sk_buff *sk_tmp = pskb;
pskb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);
kfree_skb(sk_tmp);
if (!pskb)
{
printk("PostRouting ---- vlan: failed to realloc headroom\n");
return NF_DROP;
}
//hexDump(pskb->mac.raw, 60);
//printk("PostRouting ---- skb_realloc_headroom \n");
}
else
{
pskb = skb_unshare(pskb, GFP_ATOMIC);
if (!pskb)
{
printk("PostRouting ---- vlan: failed to unshare skbuff\n");
return NF_DROP;
}
//hexDump(pskb->mac.raw, 60);
//printk("PostRouting ---- skb_unshare \n");
}
veth1 = (struct vlan_ethhdr *)skb_push(pskb, VLAN_HLEN);
//hexDump(pskb->mac.raw, 60);
//printk("PostRouting ---- skb_push \n");
/* Move the mac addresses to the beginning of the new header. */
memmove(pskb->data, pskb->data + VLAN_HLEN, 2 * VLAN_ETH_ALEN);
//hexDump(pskb->mac.raw, 60);
//printk("PostRouting ---- memmove \n");
veth1->h_vlan_proto = __constant_htons(ETH_P_8021Q);
veth1->h_vlan_TCI = htons(100);
pskb->protocol = __constant_htons(ETH_P_8021Q);
pskb->mac.raw -= VLAN_HLEN;
pskb->nh.raw -= VLAN_HLEN;
pskb->ip_summed = CHECKSUM_HW;
hexDump(pskb->mac.raw, 60);
//pskb = __vlan_put_tag(pskb, 10);
printk("PostRouting ---- __vlan_put_tag \n");
if (!pskb)
{
printk("PostRouting ---- __vlan_put_tag failed \n");
//stats->tx_dropped++;
return NF_DROP;
}
printk("PostRouting----- pskb->dev->name = %s\n", pskb->dev->name);
int rr = dev_queue_xmit(pskb);
printk("PostRouting ---- dev_queue_xmit = %d\n", rr);
return NF_STOLEN;
}
else
{
return NF_ACCEPT;
}
return NF_ACCEPT;
} |
|