Subject: Re: UDP checksum trouble in -current
To: YAMAMOTO Takashi <yamt@mwd.biglobe.ne.jp>
From: john heasley <heas@shrubbery.net>
List: tech-net
Date: 01/20/2005 15:06:59
Thu, Jan 20, 2005 at 11:34:45PM +0900, YAMAMOTO Takashi:
> hi,
> 
> > Studying the traffic with tethereal, I soon realized that it was only
> > UDP traffic that was affected, and I couldn't even get it to happen
> > for other UDP traffic: it was just DNS responses that were damaged.
> > Furthermore, the packets seemed to be quite correct; only the checksum
> > field was obviously wrong.  Looking at the traffic *leaving barsoom*,
> > I saw that the checksums were wrong as it put them into the tunnel!
> 
> i think the attached diff fixes your problem
> although i'm not sure if it's an ideal fix.
> 
> YAMAMOTO Takashi

> Index: udp_usrreq.c
> ===================================================================
> --- udp_usrreq.c	(revision 1000)
> +++ udp_usrreq.c	(working copy)
> @@ -969,9 +969,11 @@ udp_output(struct mbuf *m, ...)
>  		    ui->ui_dst.s_addr, htons((u_int16_t)len +
>  		    sizeof(struct udphdr) + IPPROTO_UDP));
>  		if (__predict_true(ro->ro_rt == NULL ||
> -				   !(ro->ro_rt->rt_ifp->if_flags &
> -				     IFF_LOOPBACK) ||
> -				   udp_do_loopback_cksum))
> +		    !(ro->ro_rt->rt_ifp->if_flags & IFF_LOOPBACK) ||
> +		    !(ro->ro_rt->rt_flags & RTF_UP) ||
> +		    satosin(&ro->ro_dst)->sin_family != AF_INET ||
> +		    !in_hosteq(satosin(&ro->ro_dst)->sin_addr, ui->ui_dst) ||
> +		    udp_do_loopback_cksum))
>  			m->m_pkthdr.csum_flags = M_CSUM_UDPv4;
>  		else
>  			m->m_pkthdr.csum_flags = 0;

i think you also need zero ui->ui_sum in the else {}, otherwise you could
just have garbage.