Subject: one less checksum ?
To: None <current-users@NetBSD.ORG>
From: Darren Reed <darrenr@vitruvius.arbld.unimelb.edu.au>
List: current-users
Date: 04/21/1996 20:24:03
Is there any reason why the result of in_cksum() is stored in ip_sum in
ipintr() ?

A small gain can be observed if this is not done, for forwarded packets,
by altering the checksum in ip_output() if IP_FORWARDING is set rather
than recalculating the entire header checksum.  Is this worthwhile ?

darren

*** ip_input.c.orig	Wed Sep  6 20:31:35 1995
--- ip_input.c	Sun Apr 21 12:12:53 1996
***************
*** 197,204 ****
		}
		ip = mtod(m, struct ip *);
	}
!	ip->ip_sum = in_cksum(m, hlen);
!	if (ip->ip_sum) {
		ipstat.ips_badsum++;
		goto bad;
	}
--- 201,207 ----
		}
		ip = mtod(m, struct ip *);
	}
!	if (in_cksum(m, hlen)) {
		ipstat.ips_badsum++;
		goto bad;
	}
*** ip_output.c.orig	Wed Sep  6 20:31:40 1995
--- ip_output.c	Sun Apr 21 19:41:53 1996
***************
*** 319,326 ****
	if ((u_short)ip->ip_len <= ifp->if_mtu) {
		ip->ip_len = htons((u_short)ip->ip_len);
		ip->ip_off = htons((u_short)ip->ip_off);
!		ip->ip_sum = 0;
!		ip->ip_sum = in_cksum(m, hlen);
		error = (*ifp->if_output)(ifp, m,
				(struct sockaddr *)dst, ro->ro_rt);
		goto done;
--- 338,352 ----
	if ((u_short)ip->ip_len <= ifp->if_mtu) {
		ip->ip_len = htons((u_short)ip->ip_len);
		ip->ip_off = htons((u_short)ip->ip_off);
!		if (flags & IP_FORWARDING) {
!			u_long sum = (u_long)ip->ip_sum;
!			sum++;
!			sum += (sum >> 16);
!			ip->ip_sum = (u_short)(sum & 0x0000ffff);
!		} else {
!			ip->ip_sum = 0;
!			ip->ip_sum = in_cksum(m, hlen);
!		}
		error = (*ifp->if_output)(ifp, m,
				(struct sockaddr *)dst, ro->ro_rt);
		goto done;