Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Select on BPF file descriptor : (8 Items)
   
Select on BPF file descriptor  
hi,

I am working on a BPF device which has a filter set for detecting packets with the tag: 0x9999. 
The code has a select call before reading from the file descriptor: code snippet below
If ((select_return = select( (1+fd), &fdset, NULL , NULL , NULL) ))
  {
              printf("\n select return %d \n", select_return);
        if( (FD_ISSET(fd, &fdset) ))
        {
          printf("\n reading from bfp -- device socket is set \n");
          if ((BytesRead = read(fd, buf, PktLen)) < 0)
          {
                  perror("read");
                  exit(EXIT_FAILURE);
          }
but even when  there is data available on the socket  the select always returns
Hence the program gets blocked on the read (which in turn calls MsgSend () internally) as they is no data available when
 you try to read. 

Pidin –p displays the following 

     pid tid name               prio STATE       Blocked
  561191   1 ./a.out             10r REPLY       114706

Does the select call does not support bpf fd’s  or am  I going wrong at some point.


Re: Select on BPF file descriptor  
On Fri, Feb 13, 2009 at 09:00:19AM -0500, Rosen Rosen wrote:
> hi,
> 
> I am working on a BPF device which has a filter set for detecting packets with the tag: 0x9999. 
> The code has a select call before reading from the file descriptor: code snippet below
> If ((select_return = select( (1+fd), &fdset, NULL , NULL , NULL) ))
>   {
>               printf("\n select return %d \n", select_return);
>         if( (FD_ISSET(fd, &fdset) ))
>         {
>           printf("\n reading from bfp -- device socket is set \n");
>           if ((BytesRead = read(fd, buf, PktLen)) < 0)
>           {
>                   perror("read");
>                   exit(EXIT_FAILURE);
>           }
> but even when  there is data available on the socket  the select always returns
> Hence the program gets blocked on the read (which in turn calls MsgSend () internally) as they is no data available 
when you try to read. 
> 
> Pidin ???p displays the following 
> 
>      pid tid name               prio STATE       Blocked
>   561191   1 ./a.out             10r REPLY       114706
> 
> Does the select call does not support bpf fd???s  or am  I going wrong at some point.
> 

Hmm, is the select failing (-1 with ENOSYS)?  If so
it's probably a bug.  Can you conjure up a complete
test case?

-seanb
Re: Select on BPF file descriptor  
Hi Sean,

attaching the code.

the stack trace is as follows

#0  0xb033aeae in MsgSend () from /usr/qnx640/target/qnx6/x86/lib/libc.so.3

#1  0xb0319087 in read () from /usr/qnx640/target/qnx6/x86/lib/libc.so.3

#2  0x08048bb0 in main ()

 

Attachment: Text test.c 2.32 KB
Re: Select on BPF file descriptor  
The issue is that only when on the interface en0 i receive a packet with the ethernet header ox9999 ( this is the filter
 setting)  only then the select should return, else the select should block.

but in this case the select returns even thought no packet with a tag 0x9999 has been received hence the code blocks on 
read.

If there is something wrong in my understanding please correct me.
Re: Select on BPF file descriptor  
On Sat, Feb 14, 2009 at 08:49:06AM -0500, Rosen Rosen wrote:
> Hi Sean,
> 
> attaching the code.
> 
> the stack trace is as follows
> 
> #0  0xb033aeae in MsgSend () from /usr/qnx640/target/qnx6/x86/lib/libc.so.3
> 
> #1  0xb0319087 in read () from /usr/qnx640/target/qnx6/x86/lib/libc.so.3
> 
> #2  0x08048bb0 in main ()
> 
>  
> 

This is a bug.  I've made PR 65617 on it.

-seanb
Re: Select on BPF file descriptor  
> On Sat, Feb 14, 2009 at 08:49:06AM -0500, Rosen Rosen wrote:
> > Hi Sean,
> > 
> > attaching the code.
> > 
> > the stack trace is as follows
> > 
> > #0  0xb033aeae in MsgSend () from /usr/qnx640/target/qnx6/x86/lib/libc.so.3
> > 
> > #1  0xb0319087 in read () from /usr/qnx640/target/qnx6/x86/lib/libc.so.3
> > 
> > #2  0x08048bb0 in main ()
> > 
> >  
> > 
> 
> This is a bug.  I've made PR 65617 on it.
> 
> -seanb


Should be fixed now (rev 836).

-seanb
Re: Select on BPF file descriptor  
Actually rev 837.

-seanb
Re: Select on BPF file descriptor  
Thanks ..  i'll try recompiling.