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&#39;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&#39;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>&nbsp;static int ebt_target_vnat(struct sk_buff **pskb, unsigned int hooknr,<br>

&nbsp;&nbsp;&nbsp; const struct net_device *in, const struct net_device *out,<br>&nbsp;&nbsp;&nbsp; const void *data, unsigned int datalen)<br>&nbsp;{<br><br>&nbsp;&nbsp;&nbsp; struct ebt_nat_info *info = (struct ebt_nat_info *)data;<br>&nbsp;&nbsp;&nbsp; unsigned short veth_TCI = 0;<br>

&nbsp;&nbsp;&nbsp; struct vlan_ethhdr *veth;<br><br>&nbsp;&nbsp;&nbsp; if (skb_headroom(*pskb) &lt; VLAN_HLEN) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; struct sk_buff *sk_tmp = *pskb;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *pskb = skb_realloc_headroom(sk_tmp, VLAN_HLEN);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; kfree_skb(sk_tmp);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (*pskb == NULL) {<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printk(KERN_ERR &quot;vlan: failed to realloc headroom\n&quot;);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return EBT_DROP;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; } else {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *pskb = skb_unshare(*pskb, GFP_ATOMIC);<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if (!*pskb) {<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; printk(KERN_ERR &quot;vlan: failed to unshare skbuff\n&quot;);<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; return EBT_DROP;<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; }<br><br>&nbsp;&nbsp;&nbsp; veth = (struct vlan_ethhdr *)skb_push(*pskb, VLAN_HLEN);<br><br>&nbsp;&nbsp;&nbsp; /* Move the mac addresses to the beginning of the new header. */<br>&nbsp;&nbsp;&nbsp; memmove((*pskb)-&gt;data, (*pskb)-&gt;data + VLAN_HLEN, 2 * VLAN_ETH_ALEN);<br>

<br>&nbsp;&nbsp;&nbsp; /* first, the ethernet type */<br>&nbsp;&nbsp;&nbsp; veth-&gt;h_vlan_proto = __constant_htons(ETH_P_8021Q);<br><br>&nbsp;&nbsp;&nbsp; /* now, the tag */<br>&nbsp;&nbsp;&nbsp; veth-&gt;h_vlan_TCI = htons(veth_TCI);<br><br>&nbsp;&nbsp;&nbsp; (*pskb)-&gt;protocol = __constant_htons(ETH_P_8021Q);<br>

&nbsp;&nbsp;&nbsp; (*pskb)-&gt;mac_header -= VLAN_HLEN;<br>&nbsp;&nbsp;&nbsp; (*pskb)-&gt;network_header -= VLAN_HLEN;<br><br>&nbsp;&nbsp;&nbsp;&nbsp; return info-&gt;target;<br>&nbsp;}<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&#39;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&#39;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==--