[Click] Basic question about IP header fields.
Beyers Cronje
bcronje at gmail.com
Mon Oct 22 22:50:45 EDT 2007
Hi Josh,
The ip_len field is in network byte order, assuming you are running on an
Intel platform you need to convert it to host byte order using
ntohs(iph->ip_len)
Google on these terms: ntohs, ntohl, endianness, network byte order, host
byte order
See http://en.wikipedia.org/wiki/Endianness for an overview.
Beyers
On 10/23/07, Nikki <tuna_armadillo at hotmail.com> wrote:
>
> Hi guys,
>
> Firstly, many many thanks for the help, its been great - I've only just
> got round to putting it into practice now I've got most of the theory
> out of the way, but the code you gave me has worked a treat. I think I
> need to read up on pointers a bit more to fully understand it, but I
> think I see what its doing.
>
> So anyway, on to my new question. I tried messing around with the code,
> in my new element and it now looks like this:
>
> const click_ip *iph = p->ip_header(); // Get pointer to IP Header
>
> if (!iph){ // Make sure it's a valid header
> p->kill();
> return;
> }
> else if (iph->ip_len <= 1000){ // Check Total Length field
> output(0).push(p);
> }
> else{
> output(1).push(p);
> }
>
> I want to split packets through different outputs depending on packet
> size, but the code above just pushes everything through output 1. I'm
> using FromDump in my config script, and am using a dump with packets of
> varying sizes, from 40 to 1420 bytes - but they all come out of output
> 1, not output 0. Where am I going wrong?
>
> Thanks,
> Josh
>
>
> On Tue, 2007-09-11 at 01:02 +0200, Beyers Cronje wrote:
> > Josh,
> >
> > And so I inadvertently demonstrated one of the classic beginner
> > mistakes to watch out for :) Always either push/pull, kill or store
> > the packet for later use...
> >
> >
> > On 9/11/07, Eddie Kohler <kohler at cs.ucla.edu> wrote:
> > Thanks, Beyers -- but I'd either "assert(iph)" or "if (!iph) {
> > p->kill(); return; }", to avoid leaking memory.
> > E
> >
> >
> > Beyers Cronje wrote:
> > > 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
> > >>
> > > _______________________________________________
> > > click mailing list
> > > click at amsterdam.lcs.mit.edu
> > > https://amsterdam.lcs.mit.edu/mailman/listinfo/click
> >
>
>
>
More information about the click
mailing list