[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
Sat Feb 16 02:08:56 UTC 2019


You are almost certainly dereferencing a null pointer.

On Sat, Feb 16, 2019 at 09:02:17AM +0800, Krish wrote:
> That code I showed before. It is working fine and crashing only when I
> enable debugging.
> 
> As *sruct tcp_header's tcp_src* has ovs_be16 type. How to store and print
> this value ?
> 
> Thanks
> 
> On Sat, Feb 16, 2019, 08:43 Ben Pfaff <blp at ovn.org> wrote:
> 
> > Then you're going to have to work harder since miniflow_extract() is
> > what initializes the L4 header pointer.
> >
> > On Sat, Feb 16, 2019 at 08:39:08AM +0800, Krish wrote:
> > > I am sorry, but I am trying not to use extracted flow.  I want to use
> > this
> > > information before it goes to EMC.
> > >
> > >
> > >
> > > On Sat, Feb 16, 2019, 03:44 Ben Pfaff <blp at ovn.org> wrote:
> > >
> > > > 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