[ovs-discuss] Fwd: Packet marking in kernel

Gregory Rose gvrose8192 at gmail.com
Wed Aug 8 17:17:05 UTC 2018


On 7/24/2018 10:59 PM, sougol gheissi wrote:
>
> Hello,
> I want to add a short piece of code to the OVS source code so that I 
> can mark the packet based on some meta data in the packet. I have add 
> the snippet code below to the /datapath/vport-netdev.c
> void netdev_port_receive(struct sk_buff *skb, struct ip_tunnel_info 
> *tun_info){
>     struct iphdr *ip_header = (struct iphdr *)skb_network_header(skb);
>     struct udphdr *udp_header;
>         if (ip_header->protocol == 17) //UDP protocol
>         {
>             udp_header = (struct udphdr *)((__u32 *)ip_header+ 
> ip_header->ihl);
>             if ((udp_header->dest == 50195)
>             {
>                 mark = 
> /setMark/((char*)udp_header,htons(ip_header->tot_len)- 20);
>                 if(mark != -1){
>                     skb->mark = mark;
>                 }
>             }
>         }
> }
> which /setMark/ is an function in the same file. Then I managed my 
> controller in floodlight to set the rules based on pkt_mark first time 
> these kind of packets come to the switch. After that I expect packets 
> to be routed based on that rules and not going to the controller 
> anymore, however some of them do not hit the rules related to them and 
> go to the controllers. I have to mention that I made the rules coming 
> from the controller to last forever. I have some questions here. As 
> the packet do not hit the rules associated to them, I concluded that 
> the packets do not get the marks. (Is it right?)
> 1. Is the vport-netdev.c the right place to add my snippet? Actually I 
> mean is it the first place I can mangle the packet in kernel?

Probably not - most packets in the kernel arrive at a device receive 
function and then get routed
up through the kernel network stack to protocol drivers that take action 
on the packet before
sending it on to applications or to be forwarded by some other interface.

> 2. If no, where should I add my snippet?

Depends on the type of traffic you want to get.  For ipv4 you might want 
to look at the kernel ../net/ipv4/ip_input.c module.

- Greg

> Thanks in advance
>
>
> _______________________________________________
> discuss mailing list
> discuss at openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-discuss/attachments/20180808/9670ca72/attachment.html>


More information about the discuss mailing list