Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. =================================================================== RCS file: /ftp/cvs/cvsroot/src/sys/netinet/udp_usrreq.c,v retrieving revision 1.93 retrieving revision 1.93.2.3 diff -u -p -r1.93 -r1.93.2.3 --- src/sys/netinet/udp_usrreq.c 2002/05/12 20:33:51 1.93 +++ src/sys/netinet/udp_usrreq.c 2002/08/29 00:56:49 1.93.2.3 @@ -1,9 +1,9 @@ -/* $NetBSD: udp_usrreq.c,v 1.93 2002/05/12 20:33:51 matt Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.93.2.3 2002/08/29 00:56:49 gehenna Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. * All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -15,7 +15,7 @@ * 3. Neither the name of the project nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -65,7 +65,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.93 2002/05/12 20:33:51 matt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.93.2.3 2002/08/29 00:56:49 gehenna Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -216,6 +216,7 @@ udp_input(m, va_alist) int iphlen, proto; int len; int n; + u_int16_t ip_len; va_start(ap, m); iphlen = va_arg(ap, int); @@ -262,6 +263,7 @@ udp_input(m, va_alist) return; } #endif + KASSERT(UDP_HDR_ALIGNED_P(uh)); /* destination port of 0 is illegal, based on RFC768. */ if (uh->uh_dport == 0) @@ -271,13 +273,14 @@ udp_input(m, va_alist) * Make mbuf data length reflect UDP length. * If not enough data to reflect UDP length, drop. */ + ip_len = ntohs(ip->ip_len); len = ntohs((u_int16_t)uh->uh_ulen); - if (ip->ip_len != iphlen + len) { - if (ip->ip_len < iphlen + len || len < sizeof(struct udphdr)) { + if (ip_len != iphlen + len) { + if (ip_len < iphlen + len || len < sizeof(struct udphdr)) { udpstat.udps_badlen++; goto bad; } - m_adj(m, iphlen + len - ip->ip_len); + m_adj(m, iphlen + len - ip_len); } /* @@ -418,6 +421,7 @@ udp6_input(mp, offp, proto) return IPPROTO_DONE; } #endif + KASSERT(UDP_HDR_ALIGNED_P(uh)); ulen = ntohs((u_short)uh->uh_ulen); /* * RFC2675 section 4: jumbograms will have 0 in the UDP header field, @@ -890,7 +894,7 @@ udp_output(m, va_alist) * Compute the packet length of the IP header, and * punt if the length looks bogus. */ - if ((len + sizeof(struct udpiphdr)) > IP_MAXPACKET) { + if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) { error = EMSGSIZE; goto release; } @@ -922,7 +926,7 @@ udp_output(m, va_alist) m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); } else ui->ui_sum = 0; - ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; + ((struct ip *)ui)->ip_len = htons(sizeof (struct udpiphdr) + len); ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */ ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */ udpstat.udps_opackets++; @@ -1137,7 +1141,7 @@ udp_sysctl(name, namelen, oldp, oldlenp, return (sysctl_int(oldp, oldlenp, newp, newlen, &udp_sendspace)); case UDPCTL_RECVSPACE: - return (sysctl_int(oldp, oldlenp, newp, newlen, + return (sysctl_int(oldp, oldlenp, newp, newlen, &udp_recvspace)); default: return (ENOPROTOOPT);