[Click] Basic question about IP header fields.

Beyers Cronje bcronje at gmail.com
Mon Sep 10 12:04:37 EDT 2007


Hi Josh,

You need to get a pointer to the IP Header. A simple example:

const click_ip *iph = p->ip_header();   // Get pointer to IP Header
if (!iph)   // Make sure it's a valid header
  return;

if (iph->ip_tos <= n)   // Check TOS field
  output(0).push(p);
else
  output(1).push(p)

The above example expects IP packets. So you'll have to filter on IP packets
and also set the IP header annotations i.e.:

FromDevice(eth0) -> Classifier(12/0800) -> MarkIPHeader(14) -> YourElement;

Classifier to filter IP packets, and MarkIPHeader to set annotations. You
can also use CheckIPHeader instead of MarkIPHeader.

Hope this helps.

Beyers

On 9/10/07, Josh Butler <tuna_armadillo at hotmail.com> wrote:
>
> Hi,
>
> This is my first question and probably won't be my last. I've been doing a
> project involving Click for a while, but owing to my very basic programming
> skills have struggled quite a lot, though I've enjoyed messing about with
> click in the process - I've been writing a bit of an idiot's guide as I've
> gone along!
>
> I've got my head round creating the router configuration scripts by
> combining elements and am now looking to go inside the elements and make
> some changes. I've chosen the tee element as one of the easier elements to
> look at and modify, and have a good understanding of what it does in push
> mode.
>
> I now want to modify this element in a very basic way, using a simple if
> statement if possible so that I can push packets through either the
> element's first or second output port depending on some criteria such as the
> type of service field within the IP header. Here's what I mean in
> pseudocode, if that's the correct term;
>
> if (type_of_service_field <= n){
>     output(0).push(p);
>     }
>     else {
>     output(1).push(p);
>     }
>
> I've looked through all the material on the click site and can't find a
> simple answer to the question of how to access the different fields within
> the IP header. Maybe I'm being stupid, but a bit of help would be awesome.
>
> Thanks,
> Josh
>
> _________________________________________________________________
> 100's of Music vouchers to be won with MSN Music
> https://www.musicmashup.co.uk
> _______________________________________________
> click mailing list
> click at amsterdam.lcs.mit.edu
> https://amsterdam.lcs.mit.edu/mailman/listinfo/click
>


More information about the click mailing list