All of lore.kernel.org
 help / color / mirror / Atom feed
* Segmentation Fault on printf()
@ 2014-03-14 10:27 sabu kurian
       [not found] ` <CAJ2bnfDcs9OiycSFcC9CvSihJ=u6vQt5ema_VMjseq-CiDsqBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: sabu kurian @ 2014-03-14 10:27 UTC (permalink / raw)
  To: dev-VfR2kkLFssw

Hello friends,

I'm trying to print the ether_type for a packet that I captured from a port
on my machine. Suppose 'm' holds the packet. 'm' is of type 'struct
rte_mbuf'. Intels API reference for DPDK says 'ether_type' is of uint16_t.
I used the following code to retrieve ether_type.

void * eth_type;
struct ether_hdr *eth;

eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
eth_type = &eth->ether_type;

printf("\n Type is %" PRIu16 , *((uint16_t *)eth_type));

rte_pktmbuf_free(m);

I get a 'Segmentation fault' when the printf() statement gets executed.
Where am I going wrong ?

Thanks in advance

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Segmentation Fault on printf()
       [not found] ` <CAJ2bnfDcs9OiycSFcC9CvSihJ=u6vQt5ema_VMjseq-CiDsqBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-03-14 16:10   ` Chris Wright
       [not found]     ` <20140314161047.GD1390-SwUeJysX96B82hYKe6nXyg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Chris Wright @ 2014-03-14 16:10 UTC (permalink / raw)
  To: sabu kurian; +Cc: dev-VfR2kkLFssw

* sabu kurian (sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote:
> Hello friends,
> 
> I'm trying to print the ether_type for a packet that I captured from a port
> on my machine. Suppose 'm' holds the packet. 'm' is of type 'struct
> rte_mbuf'. Intels API reference for DPDK says 'ether_type' is of uint16_t.
> I used the following code to retrieve ether_type.
> 
> void * eth_type;
> struct ether_hdr *eth;
> 
> eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
> eth_type = &eth->ether_type;
> 
> printf("\n Type is %" PRIu16 , *((uint16_t *)eth_type));

Looks ok, albeit slightly overly complicated.

struct ether_hdr *eth;
uint16_t eth_type;

eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
eth_type = eth->ether_type;
printf("\n Type is %" PRIu16 , eth_type));

This would remove all the extra casting.  Perhaps the mbuf is the problem
here.  And if so, the above snippet would segfault on eth->ether_type
showing you that mbuf is invalid.

You could try to (above mtod):

rte_pktmbuf_dump(m, sizeof(struct ether_hdr));

as that will show key contents of mbuf and packet data (and do some
basic validation along the way).

thanks,
-chris

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Segmentation Fault on printf()
       [not found]     ` <20140314161047.GD1390-SwUeJysX96B82hYKe6nXyg@public.gmane.org>
@ 2014-03-16 13:03       ` sabu kurian
       [not found]         ` <CAJ2bnfAt=guObm2VZuLrAfXiOGWdCZHhg4A_Ek-YdtwDbRS-bQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: sabu kurian @ 2014-03-16 13:03 UTC (permalink / raw)
  To: Chris Wright; +Cc: dev-VfR2kkLFssw

Hello chris,

Thanks for your reply. I tried dumping the contents of mbuf as you have
suggested.
This is what I get:

dump mbuf at 0x0x6c7620, phys=7f34d91eba28, buf_len=59488
pkt_len=0, ol_flags=0, nb_segs=0, in_port=0

and soon after that I get a segmentation fault. Do you have any idea on
what could be causing it ?

Regards



On Fri, Mar 14, 2014 at 9:40 PM, Chris Wright <chrisw-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:

> * sabu kurian (sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote:
> > Hello friends,
> >
> > I'm trying to print the ether_type for a packet that I captured from a
> port
> > on my machine. Suppose 'm' holds the packet. 'm' is of type 'struct
> > rte_mbuf'. Intels API reference for DPDK says 'ether_type' is of
> uint16_t.
> > I used the following code to retrieve ether_type.
> >
> > void * eth_type;
> > struct ether_hdr *eth;
> >
> > eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
> > eth_type = &eth->ether_type;
> >
> > printf("\n Type is %" PRIu16 , *((uint16_t *)eth_type));
>
> Looks ok, albeit slightly overly complicated.
>
> struct ether_hdr *eth;
> uint16_t eth_type;
>
> eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
> eth_type = eth->ether_type;
> printf("\n Type is %" PRIu16 , eth_type));
>
> This would remove all the extra casting.  Perhaps the mbuf is the problem
> here.  And if so, the above snippet would segfault on eth->ether_type
> showing you that mbuf is invalid.
>
> You could try to (above mtod):
>
> rte_pktmbuf_dump(m, sizeof(struct ether_hdr));
>
> as that will show key contents of mbuf and packet data (and do some
> basic validation along the way).
>
> thanks,
> -chris
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Segmentation Fault on printf()
       [not found]         ` <CAJ2bnfAt=guObm2VZuLrAfXiOGWdCZHhg4A_Ek-YdtwDbRS-bQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-03-17 19:45           ` Daniel Kaminsky
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kaminsky @ 2014-03-17 19:45 UTC (permalink / raw)
  To: sabu kurian; +Cc: dev-VfR2kkLFssw

Sabu,

I think that in this case the packet length is zero which will result in
nothing from mtod.

Daniel


On Sun, Mar 16, 2014 at 3:03 PM, sabu kurian <sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:

> Hello chris,
>
> Thanks for your reply. I tried dumping the contents of mbuf as you have
> suggested.
> This is what I get:
>
> dump mbuf at 0x0x6c7620, phys=7f34d91eba28, buf_len=59488
> pkt_len=0, ol_flags=0, nb_segs=0, in_port=0
>
> and soon after that I get a segmentation fault. Do you have any idea on
> what could be causing it ?
>
> Regards
>
>
>
> On Fri, Mar 14, 2014 at 9:40 PM, Chris Wright <chrisw-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org> wrote:
>
> > * sabu kurian (sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org) wrote:
> > > Hello friends,
> > >
> > > I'm trying to print the ether_type for a packet that I captured from a
> > port
> > > on my machine. Suppose 'm' holds the packet. 'm' is of type 'struct
> > > rte_mbuf'. Intels API reference for DPDK says 'ether_type' is of
> > uint16_t.
> > > I used the following code to retrieve ether_type.
> > >
> > > void * eth_type;
> > > struct ether_hdr *eth;
> > >
> > > eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
> > > eth_type = &eth->ether_type;
> > >
> > > printf("\n Type is %" PRIu16 , *((uint16_t *)eth_type));
> >
> > Looks ok, albeit slightly overly complicated.
> >
> > struct ether_hdr *eth;
> > uint16_t eth_type;
> >
> > eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
> > eth_type = eth->ether_type;
> > printf("\n Type is %" PRIu16 , eth_type));
> >
> > This would remove all the extra casting.  Perhaps the mbuf is the problem
> > here.  And if so, the above snippet would segfault on eth->ether_type
> > showing you that mbuf is invalid.
> >
> > You could try to (above mtod):
> >
> > rte_pktmbuf_dump(m, sizeof(struct ether_hdr));
> >
> > as that will show key contents of mbuf and packet data (and do some
> > basic validation along the way).
> >
> > thanks,
> > -chris
> >
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-03-17 19:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-14 10:27 Segmentation Fault on printf() sabu kurian
     [not found] ` <CAJ2bnfDcs9OiycSFcC9CvSihJ=u6vQt5ema_VMjseq-CiDsqBQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-14 16:10   ` Chris Wright
     [not found]     ` <20140314161047.GD1390-SwUeJysX96B82hYKe6nXyg@public.gmane.org>
2014-03-16 13:03       ` sabu kurian
     [not found]         ` <CAJ2bnfAt=guObm2VZuLrAfXiOGWdCZHhg4A_Ek-YdtwDbRS-bQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-17 19:45           ` Daniel Kaminsky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.