Date: Sun, 21 Apr 1996 23:51:03 +1000 (EST) From: Darren Reed <darrenr@vitruvius.arbld.unimelb.edu.au> To: hackers@freebsd.org Subject: one less checksum ? (fwd) Message-ID: <199604211351.XAA10529@vitruvius.arbld.unimelb.EDU.AU>
next in thread | raw e-mail | index | archive | help
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;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199604211351.XAA10529>