Vlan modifications

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Greetings,

I am working on a kernel module that uses netfilter to catch packets, modify
its vlan tag or remove it or even add one, all depending on the user input.



I am able to catch the packets like this:

netfilter_ops.hook                          =                            
main_hook;
netfilter_ops.pf                            =                            
PF_INET;                             
netfilter_ops.hooknum                       =                            
NF_IP_PRE_ROUTING;
netfilter_ops.priority                      =                            
NF_IP_PRI_FIRST;
err = nf_register_hook(&netfilter_ops);

It is working fine.

The issue I have is the following:

The vlan headers on other parts of the kernel are managed the data field of
the skb, for example:

static inline int thesis_vlan_get_tag(struct sk_buff *skb)
{
    struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->data;
    unsigned short tag;
    
    if (veth->h_vlan_proto != __constant_htons(ETH_P_8021Q)) {
        printk("\n thesis_vlan_get_tag no Vlan\n");
        return -EINVAL;
    }
    
    tag = ntohs(veth->h_vlan_TCI);
    
    printk("\n thesis_vlan_get_tag VID2 %d\n",tag);
    
    return 0;
}

But, on the skb that I get that info is actually on the raw of the mac, so
to print the vlan I have to do this:

static inline int thesis_vlan_get_tag2(struct sk_buff *skb)
{
    struct vlan_ethhdr *veth = (struct vlan_ethhdr *)skb->mac.raw;
    unsigned short tag;
    
    if (veth->h_vlan_proto != __constant_htons(ETH_P_8021Q)) {
        printk("\n thesis_vlan_get_tag2 no Vlan\n");
        return -EINVAL;
    }
    
    tag = ntohs(veth->h_vlan_TCI) & VLAN_VID_MASK;
    
    printk("\n thesis_vlan_get_tag VID2 %d\n",tag);
    
    return 0;
}

Can someone explain me why? I would like to reuse some of the kernel
functions but they all use the data field.

I use linux-2.6.20 on a MIPS CPU.

Any help would be amazing.


Best Regards,
Augusto Salazar
Software Engineer
Proscend Communications Inc.



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

--
To unsubscribe from this list: send the line "unsubscribe netfilter" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Netfilter Development]     [Linux Kernel Networking Development]     [Netem]     [Berkeley Packet Filter]     [Linux Kernel Development]     [Advanced Routing & Traffice Control]     [Bugtraq]

  Powered by Linux