Re: NetBSD and sysmon

From: Bengt Gördé (bengan@sunet.se)
Date: Tue Jun 11 2002 - 15:01:00 EDT


On Tue, Jun 11, 2002 at 08:40:32AM -0400, Jared Mauch wrote:

> Ok..
>
> try this icmp.c instead.
>
> That should fix it.

Nope. But we have a guy at our work that is multilingual when it comes
to computer-languages and I asked him to help out. 10h later he comes
up with this. (He's name is Björn Danielsson, bd@sunet.se).

There is nothing wrong with the in_cksum() algorithm, and there was
nothing wrong with the earlier version of it. The problem was that
when the pingdata structures were re-used after the first ping,
the previous checksum field was not cleared before the new checksum
calculation, resulting in an incorrect checksum. This patch fixes that:

----------------------------------------------------------------
*** icmp.c~ 2002/06/11 17:26:48
--- icmp.c 2002/06/11 17:28:12
***************
*** 417,422 ****
--- 417,423 ----
          localdata->icp = (struct ICMPHDR *)localdata->outpack;/* cast it */
          localdata->icp->ICMP_TYPE = ICMP_ECHO; /* It's an ICMP_ECHO */
          localdata->icp->ICMP_CODE = 0; /* icmp_code subtype */
+ localdata->icp->ICMP_CHECKSUM = 0;
  
                  /* put the sequence in the packet */
          localdata->icp->ICMP_SEQ = localdata->packetsent;
----------------------------------------------------------------

I found another strange thing which I think is a bug, but it turned
out to have nothing to do with the checksum problem. The outgoing
icmp packets are 136 bytes, while ICMP_PACKET_SIZE (used for reading)
is set to 60. So I made the following change in pinger_v4():

----------------------------------------------------------------
*** icmp.c~ 2002/06/11 15:00:50
--- icmp.c 2002/06/11 17:26:48
***************
*** 426,432 ****
  
          CLR(localdata->icp->ICMP_SEQ % 1024); /* Clear it */
  
! cc = (128+ICMP_PHDR_LEN); /* skips ICMP portion */
  
          /* compute ICMP checksum here */
          localdata->icp->ICMP_CHECKSUM = in_cksum((u_short *)localdata->icp, cc);
--- 426,432 ----
  
          CLR(localdata->icp->ICMP_SEQ % 1024); /* Clear it */
  
! cc = ICMP_PACKET_SIZE;
  
          /* compute ICMP checksum here */
          localdata->icp->ICMP_CHECKSUM = in_cksum((u_short *)localdata->icp, cc);
----------------------------------------------------------------

Even if this has no other effect, it should at least save some bandwidth.

-- 
Björn Danielsson  KTHNOC  <bd@sunet.se>  

--

/Bengan

Bengt Görden KTHNOC/SUNET/NORDUnet http://www.sunet.se/~bengan



This archive was generated by hypermail 2b29 : Sun Aug 04 2002 - 04:14:07 EDT