ebt_vnat: Adding VLAN tag target
"Jon Petralanda" <[email protected]> Thu, 16 Oct 2008 11:18:52 +0200
| Newsgroups | gmane.linux.network.bridge.ebtables.devel |
|---|---|
| Message-ID | <[email protected]> |
--===============4214952539608742869==
Content-Type: multipart/alternative;
boundary="----=_Part_77336_7269935.1224148732166"
------=_Part_77336_7269935.1224148732166
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi! I'm trying to do a new target module for ebtables to add the VLAN tag
depending on some parameters with this kind of rule:
# ebtables -t nat -A OUTPUT/POSTROUTING -s sourceMAC -j vnat --to-vlan
Like Ashwin did it here:
http://osdir.com/ml/linux.network.bridge.ebtables.devel/2003-12/msg00026.html
I'm using 2.6.22-15 kernel and ebtables-v2.0.8-1. I have copied the dnat
code on userspace and kernel and I have read the vlan_dev.c/if_vlan.h codes
and I have this on mi ebt_vnat_target function:
static int ebt_target_vnat(struct sk_buff **pskb, unsigned int hooknr,
const struct net_device *in, const struct net_device *out,
const void *data, unsigned int datalen)
{
struct ebt_nat_info *info = (struct ebt_nat_info *)data;
unsigned short veth_TCI = 0;
struct vlan_ethhdr *veth;
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 == NULL) {
printk(KERN_ERR "vlan: failed to realloc headroom\n");
return EBT_DROP;
}
} else {
*pskb = skb_unshare(*pskb, GFP_ATOMIC);
if (!*pskb) {
printk(KERN_ERR "vlan: failed to unshare skbuff\n");
return EBT_DROP;
}
}
veth = (struct vlan_ethhdr *)skb_push(*pskb, VLAN_HLEN);
/* Move the mac addresses to the beginning of the new header. */
memmove((*pskb)->data, (*pskb)->data + VLAN_HLEN, 2 * VLAN_ETH_ALEN);
/* first, the ethernet type */
veth->h_vlan_proto = __constant_htons(ETH_P_8021Q);
/* now, the tag */
veth->h_vlan_TCI = htons(veth_TCI);
(*pskb)->protocol = __constant_htons(ETH_P_8021Q);
(*pskb)->mac_header -= VLAN_HLEN;
(*pskb)->network_header -= VLAN_HLEN;
return info->target;
}
If I execute my target with the PREROUTING chain when I see some strange
packets on br0 with Wireshark (for example if I do a 98 bytes ping to my
computer I receive 102 bytes but the other things like Ethertype or the
source/destination MACs goes bad).
If I execute it with OUTPUT... I have Kernel panic. I have tried different
combinations of commenting lines, adding some functions but nothing.
My questions are:
1. How can I debug (with printks or something like that) the module to see
what its doing exactly line by line?
2. It seems like I have to debug the kernel, do you know a form to debug it
more or less easily?
3. Do you know what I'm doing wrong on my target? It seems like the code is
apparently ok.
PD: If the things goes well... Bart, are you interested on a patch of this
target adding the options of choosing an vlan-id and vlan-priority?
I'm sorry for my poor english, thank you very much.
Regards,
Jon
------=_Part_77336_7269935.1224148732166
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
<div dir="ltr">Hi! I'm trying to do a new target module for ebtables to add the VLAN tag depending on some parameters with this kind of rule:<br><br># ebtables -t nat -A OUTPUT/POSTROUTING -s sourceMAC -j vnat --to-vlan<br>
<br>Like Ashwin did it here: <a href="http://osdir.com/ml/linux.network.bridge.ebtables.devel/2003-12/msg00026.html" target="_blank">http://osdir.com/ml/linux.network.bridge.ebtables.devel/2003-12/msg00026.html</a><br>
<br>I'm using 2.6.22-15 kernel and ebtables-v2.0.8-1. I have copied the dnat code on userspace and kernel and I have read the vlan_dev.c/if_vlan.h codes and I have this on mi ebt_vnat_target function:<br><br> static int ebt_target_vnat(struct sk_buff **pskb, unsigned int hooknr,<br>
const struct net_device *in, const struct net_device *out,<br> const void *data, unsigned int datalen)<br> {<br><br> struct ebt_nat_info *info = (struct ebt_nat_info *)data;<br> unsigned short veth_TCI = 0;<br>
struct vlan_ethhdr *veth;<br><br> if (skb_headroom(*pskb) < VLAN_HLEN) {<br> struct sk_buff *sk_tmp = *pskb;<br> *pskb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);<br> kfree_skb(sk_tmp);<br> if (*pskb == NULL) {<br>
printk(KERN_ERR "vlan: failed to realloc headroom\n");<br> return EBT_DROP;<br> }<br> } else {<br> *pskb = skb_unshare(*pskb, GFP_ATOMIC);<br> if (!*pskb) {<br> printk(KERN_ERR "vlan: failed to unshare skbuff\n");<br>
return EBT_DROP;<br> }<br> }<br><br> veth = (struct vlan_ethhdr *)skb_push(*pskb, VLAN_HLEN);<br><br> /* Move the mac addresses to the beginning of the new header. */<br> memmove((*pskb)->data, (*pskb)->data + VLAN_HLEN, 2 * VLAN_ETH_ALEN);<br>
<br> /* first, the ethernet type */<br> veth->h_vlan_proto = __constant_htons(ETH_P_8021Q);<br><br> /* now, the tag */<br> veth->h_vlan_TCI = htons(veth_TCI);<br><br> (*pskb)->protocol = __constant_htons(ETH_P_8021Q);<br>
(*pskb)->mac_header -= VLAN_HLEN;<br> (*pskb)->network_header -= VLAN_HLEN;<br><br> return info->target;<br> }<br><br>If I execute my target with the PREROUTING chain when I see some strange packets on br0 with Wireshark (for example if I do a 98 bytes ping to my computer I receive 102 bytes but the other things like Ethertype or the source/destination MACs goes bad).<br>
<br>If I execute it with OUTPUT... I have Kernel panic. I have tried different combinations of commenting lines, adding some functions but nothing.<br><br><br>My questions are:<br><br>1. How can I debug (with printks or something like that) the module to see what its doing exactly line by line? <br>
<br>2. It seems like I have to debug the kernel, do you know a form to debug it more or less easily?<br><br>3. Do you know what I'm doing wrong on my target? It seems like the code is apparently ok.<br><br>PD: If the things goes well... Bart, are you interested on a patch of this target adding the options of choosing an vlan-id and vlan-priority?<br>
<br>I'm sorry for my poor english, thank you very much.<br><br>Regards,<br><br>Jon<br>
</div>
------=_Part_77336_7269935.1224148732166--
--===============4214952539608742869==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
--===============4214952539608742869==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Ebtables-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ebtables-devel
--===============4214952539608742869==--