Subject: Re: RFC: New BGF 'LOOP' instruction

From: Paul LeoNerd Evans <[email-masked]>
Date: Tue, 3 Aug 2010 15:34:42 +0100

On Tue, Aug 03, 2010 at 03:11:10PM +0100, Paul LeoNerd Evans wrote:
>   switch(hdrtype)
>   {
>      case 1:
>        length = someconst; break;
>      case 2:
>        length = someotherconst; break;
>      case 3:
>        length = b[someoffset]; break;
>      ...
>   }

Of course, I completely forgot about finding also the offset of the
'next header' from the current header. That results in some code which,
in C, would look like:

  int hdrtype = b[IPv6_nexthdr];

  int x = size_of_IPv6_header;

  while(hdrtype != hdr_wanted) {
       int len;
       switch(hdrtype) {
         case 1:
           len = someconst;
           hdrtype = someotherconst;
           break;
         case 2:
           len = b[x+someoffs];
           hdrtype = b[x+someotheroffs];
           break;
         /* other IPv6 header types here */
       }

       x += len;
  }

You can't compile that idea into BPF without using a scratch memory
cell, because you can't have both 'len' and 'hdrtype' live in A at the
same time, nor can you atomically x += b[x+someoffs].

In short, much much easier if the C code did this part...

-- 
Paul "LeoNerd" Evans

[email-masked]
ICQ# 4135350       |  Registered Linux# 179460
http://www.leonerd.org.uk/