[ovs-discuss] How to store the tcp_src or tcp_dst field value in a variable and then print in vlogs?

Ben Pfaff blp at ovn.org
Fri Feb 15 19:44:38 UTC 2019


On Fri, Feb 15, 2019 at 03:48:22PM +0800, Krish wrote:
> Hi
> 
> I want to store tcp_src, dst port in a variable.
> This is what I am doing:
> 1. Retrieve packet from dp_packet_batch one by one.
> 2. Retrieving field values by extracting packets headers:
> 
> struct ip_header *ip = dp_packet_l3(packet);
> nw_proto = ip->ip_proto;
> if(nw_proto == 6)
> {
> struct tcp_header *th = dp_packet_l4(packet);
> // The following are the 2 different ways I am trying to print the tcp_src.
> I have tried it 1 and 2 separately not at the same time.
>                 //1 . Ovs crash at the below statement
>                 uint16_t src = (uint16_t) ntohs(th->tcp_src);
>                 VLOG_DBG( "tcp_src ---> %d", src );
>                 //2. When I enable logging ovs crashes at this point
>                 VLOG_DBG( "tcp_src ---> %d", ntohs(th->tcp_src) );
> 
> 
>                  }
> 
> Can anyone please help how to store tcp_src port value in a variable and
> print it in vlogs?
> Statement 2 is working fine if vlogs are disabled, but I want the port
> value to be stored in a variable and then print.

I'd just get it from the extracted flow instead of inventing new code to
extract it.


More information about the discuss mailing list