Re: click element customization
Ruetee Chitpranee <[email protected]>
| Newsgroups | gmane.network.routing.click |
|---|---|
| Message-ID | <CABG77Ofw0K46a+rHgSgP8HUsZHm+6j=rCCHZ0KukU7o7GSKnxw@mail.gmail.com> |
Thank you very much for your answer :) Now, It's clear. On Fri, Dec 23, 2011 at 12:12 PM, Beyers Cronje <[email protected]> wrote: > Hi Ruetee, > > Your first problem is that you are assuming the IP Header annotation is set > when you call "p->ip_header()", which in your case it has not. I.e. > p->has_network_header() == false. The packet header annotations are > typically set through MarkIPHeader or CheckIPHeader, and only elements > downstream of these elements can use p->ip_header(). Have a look at > MarkIPHeader on how to set the annotation. Keep in mind MarkIPHeader and > CheckIPHeader assumes input packets are valid IP packets. > > Possibly a better approach to familiarize yourself with Click and test > custom elements would be something like: > > InfiniteSource -> Classifier(12/0800) -> MarkIPHeader(14) -> YourElement -> > Discard; > > Or even easier: > > FromDump(/path/to/dump.pcap) -> Classifier(12/0800) -> MarkIPHeader(14) -> > YourElement -> Discard; > > Beyers > > On Fri, Dec 23, 2011 at 12:51 AM, Ruetee Chitpranee <[email protected] > >wrote: > > > Hi, > > > > First of all, I'm really a beginner for Click. Now, I'm trying to > customize > > InfiniteSource to correct IP Header checksum as always (..for trying and > > make me understand better about click elements :) > > > > My idea is on function run_task (or function setup_packet() -- but seems > > cannot manage anything here :-/, before push result packet out, I will > > extract "click_ip" from the packet and process checksum update, then set > > the header back. > > > > Look simple but I still got Segmentation fault :( > > > > Here is what I did ... > > > > bool > > InfiniteSourcex::run_task(Task *) > > { > > if (!_active || !_nonfull_signal) > > return false; > > int n = _burstsize; > > if (_limit >= 0 && _count + n >= (ucounter_t) _limit) > > n = (_count > (ucounter_t) _limit ? 0 : _limit - _count); > > for (int i = 0; i < n; i++) { > > Packet *p = _packet->clone(); > > if (_timestamp) > > p->timestamp_anno().assign_now(); > > > > ///////// customize here ///////// > > > > click_ip *ip = const_cast<click_ip *>(p->ip_header()); > > > > //// solution1: code from SetIPChecksum element//// > > unsigned plen, hlen; > > plen = p->network_length(); > > hlen = ip->ip_hl << 2; > > click_chatter("network len is %u", plen); > > click_chatter("ip len is %u", hlen); > > ip->ip_sum = 0; > > ip->ip_sum = click_in_cksum((unsigned char *)ip, hlen); > > > > p->set_ip_header(ip, sizeof(click_ip)); > > > > > > //// solution2: code from IPEncap element//// > > > > if (ip->ip_len) { // use_dst_anno > > ip->ip_dst = p->dst_ip_anno(); > > update_cksum(ip, 16); > > update_cksum(ip, 18); > > } else > > p->set_dst_ip_anno(IPAddress(ip->ip_dst)); > > ip->ip_len = htons(p->length()); > > ip->ip_id = htons(0); > > update_cksum(ip, 2); > > update_cksum(ip, 4); > > > > p->set_ip_header(ip, sizeof(click_ip)); > > > > ///////// customize end ///////// > > > > output(0).push(p); > > } > > _count += n; > > if (n > 0) > > _task.fast_reschedule(); > > else if (_end_h && _limit >= 0 && _count >= (ucounter_t) _limit) > > (void) _end_h->call_write(); > > return n > 0; > > } > > > > > > Please advise what I should do.... > > Thank you very much in advance. > > > > Regards, > > > > Ruetee C. > > _______________________________________________ > > click mailing list > > [email protected] > > https://amsterdam.lcs.mit.edu/mailman/listinfo/click > > > _______________________________________________ > click mailing list > [email protected] > https://amsterdam.lcs.mit.edu/mailman/listinfo/click > -- Ruetee C.