Ethereal-dev: [Ethereal-dev] Optimization: remove the unconditional ip_checksum() in packet-ip

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

From: Kaul <mykaul@xxxxxxxxx>
Date: Fri, 23 Sep 2005 01:41:24 +0300
>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.