Ethereal-dev: Re: [Ethereal-dev] Optimization: remove the unconditional ip_checksum() in packe

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Ulf Lamping <ulf.lamping@xxxxxx>
Date: Fri, 23 Sep 2005 01:06:47 +0200
Kaul wrote:

>From packet-ip.c:
  if (tvb_bytes_exist(tvb, offset, hlen)) {
    ipsum = ip_checksum(tvb_get_ptr(tvb, offset, hlen), hlen);
    if (tree) {
      if (ipsum == 0) {
...
I suggest here calculating the checksum only if the tree exists:
if (tree & tvb_bytes_exist(tvb, offset, hlen) {
           ipsum = ip_checksum(tvb_get_ptr(tvb, offset, hlen), hlen);
            if(ipsum == 0) {
...

I'm aware that later on ipsum is needed:
  if (ip_defragment && (iph->ip_off & (IP_MF|IP_OFFSET)) &&
      tvb_bytes_exist(tvb, offset, pinfo->iplen - pinfo->iphdrlen) &&
      ipsum == 0) {

but here I suggest changing this to:

  if (ip_defragment && (iph->ip_off & (IP_MF|IP_OFFSET)) &&
      tvb_bytes_exist(tvb, offset, pinfo->iplen - pinfo->iphdrlen) &&
      (ip_checksum(tvb_get_ptr(tvb, offset, hlen), hlen)) == 0) {

So, if there's no tree and there's no need for defragmentation, the checksum is not calculated at all! I'd be happy to supply a small patch that does just that, along with other minor optimizations to packet-ip.c, if this seems reasonable to the list.

Y.

Sounds reasonable. BTW: What's the intentions for this, a slight performance improvement?

In addition, you might consider adding a Preference setting (it's not too difficult) to switch off checksum checking completely, just as we already have it for TCP.

Regards, ULFL