[P4-dev] parsing variable-length fields in HTTP

Antonin Bas antonin at barefootnetworks.com
Fri Jul 14 18:30:54 EDT 2017

Hi Aldo,

Maybe others will have an idea, but I can't think of any reasonable way of
parsing a HTTP header in P4. P4 can accommodate as many Variable-length
fields as you need, providing they are in different headers (I'm not saying
this is a reasonable thing to do for realistic hardware targets). However
VL field extraction usually relies on having an easy way to compute the
length, which is not the case here (you have to look for CRLF). By design
there is no easy way to write loops in P4, even though the parser syntax
lets you create loops. I can imagine a crazy P4 program that would parse
the packet 2 bytes at a time and push these bytes into a header stack until
it reaches the CRLF. You could potentially use one header stack for Host,
one for User-Agent..., then define a table that would match on the first
few bytes of the User-Agent stack. It would be really hacky and wouldn't
scale well, but you could make it work, at least in a P4 software switch.

Finally, note that you cannot use variable-length fields in match-table
keys, so even if you could extract what you want into a VL field, you
couldn't do anything with it.

It's unlikely that the core P4 language will provide an easy way to process
the HTTP header any time soon. Of course some specific P4-programmable
targets (e.g. a firewall?) may provide extensions (as P4_16 externs) to do
pattern-matching on the payload.



On Fri, Jul 14, 2017 at 1:23 PM, Aldo Febro <af12abw at gmail.com> wrote:

> Hi All,
> I wonder if P4 is capable of parsing HTTP protocol with its
> variable-length fields?
>  e.g.
> Host: www.p4.org\r\n
> User-Agent: Mozilla/5.0\r\n
> Accept: text/html,image/apng\r\n
> etc. where each variable-length field is terminated with "\r\n" character
> (CRLF).
> As far as I know, P4 can accommodate only one variable-length field by
> using "*", which value will be derived by calculating length and
> max_length. But with HTTP, most fields are of variable length.
> What I'd like to be able to do is to parse each field individually i.e.
> doing a match based on "Hosts:, "User-Agent:", etc. Is this doable yet?
> Many thanks!
> Aldo
> _______________________________________________
> P4-dev mailing list
> P4-dev at lists.p4.org
> http://lists.p4.org/mailman/listinfo/p4-dev_lists.p4.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.p4.org/pipermail/p4-dev_lists.p4.org/attachments/20170714/c3c4a8d7/attachment-0002.html>

More information about the P4-dev mailing list