udp_usrreq.c (55009) | udp_usrreq.c (58698) |
---|---|
1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 | 1/* 2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 |
34 * $FreeBSD: head/sys/netinet/udp_usrreq.c 55009 1999-12-22 19:13:38Z shin $ | 34 * $FreeBSD: head/sys/netinet/udp_usrreq.c 58698 2000-03-27 19:14:27Z jlemon $ |
35 */ 36 37#include "opt_ipsec.h" 38#include "opt_inet6.h" 39 | 35 */ 36 37#include "opt_ipsec.h" 38#include "opt_inet6.h" 39 |
40#include <stddef.h> |
|
40#include <sys/param.h> 41#include <sys/systm.h> 42#include <sys/kernel.h> 43#include <sys/malloc.h> 44#include <sys/mbuf.h> 45#include <sys/domain.h> 46#include <sys/proc.h> 47#include <sys/protosw.h> --- 23 unchanged lines hidden (view full) --- 71#include <netinet/icmp_var.h> 72#include <netinet/udp.h> 73#include <netinet/udp_var.h> 74 75#ifdef IPSEC 76#include <netinet6/ipsec.h> 77#endif /*IPSEC*/ 78 | 41#include <sys/param.h> 42#include <sys/systm.h> 43#include <sys/kernel.h> 44#include <sys/malloc.h> 45#include <sys/mbuf.h> 46#include <sys/domain.h> 47#include <sys/proc.h> 48#include <sys/protosw.h> --- 23 unchanged lines hidden (view full) --- 72#include <netinet/icmp_var.h> 73#include <netinet/udp.h> 74#include <netinet/udp_var.h> 75 76#ifdef IPSEC 77#include <netinet6/ipsec.h> 78#endif /*IPSEC*/ 79 |
80#include <machine/in_cksum.h> 81 |
|
79/* 80 * UDP protocol implementation. 81 * Per RFC 768, August, 1980. 82 */ 83#ifndef COMPAT_42 84static int udpcksum = 1; 85#else 86static int udpcksum = 0; /* XXX */ --- 116 unchanged lines hidden (view full) --- 203 * for sending an ICMP error message in response. 204 */ 205 save_ip = *ip; 206 207 /* 208 * Checksum extended UDP header and data. 209 */ 210 if (uh->uh_sum) { | 82/* 83 * UDP protocol implementation. 84 * Per RFC 768, August, 1980. 85 */ 86#ifndef COMPAT_42 87static int udpcksum = 1; 88#else 89static int udpcksum = 0; /* XXX */ --- 116 unchanged lines hidden (view full) --- 206 * for sending an ICMP error message in response. 207 */ 208 save_ip = *ip; 209 210 /* 211 * Checksum extended UDP header and data. 212 */ 213 if (uh->uh_sum) { |
211 bzero(((struct ipovly *)ip)->ih_x1, 9); 212 ((struct ipovly *)ip)->ih_len = uh->uh_ulen; 213 uh->uh_sum = in_cksum(m, len + sizeof (struct ip)); | 214 if (m->m_pkthdr.csum_flags & CSUM_DATA_VALID) { 215 if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR) 216 uh->uh_sum = m->m_pkthdr.csum_data; 217 else 218 uh->uh_sum = in_pseudo(ip->ip_src.s_addr, 219 ip->ip_dst.s_addr, htonl(ip->ip_len + 220 m->m_pkthdr.csum_data + IPPROTO_UDP)); 221 uh->uh_sum ^= 0xffff; 222 } else { 223 bzero(((struct ipovly *)ip)->ih_x1, 9); 224 ((struct ipovly *)ip)->ih_len = uh->uh_ulen; 225 uh->uh_sum = in_cksum(m, len + sizeof (struct ip)); 226 } |
214 if (uh->uh_sum) { 215 udpstat.udps_badsum++; 216 m_freem(m); 217 return; 218 } 219 } 220 221 if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) || --- 452 unchanged lines hidden (view full) --- 674 goto release; 675 } 676 677 /* 678 * Fill in mbuf with extended UDP header 679 * and addresses and length put into network format. 680 */ 681 ui = mtod(m, struct udpiphdr *); | 227 if (uh->uh_sum) { 228 udpstat.udps_badsum++; 229 m_freem(m); 230 return; 231 } 232 } 233 234 if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) || --- 452 unchanged lines hidden (view full) --- 687 goto release; 688 } 689 690 /* 691 * Fill in mbuf with extended UDP header 692 * and addresses and length put into network format. 693 */ 694 ui = mtod(m, struct udpiphdr *); |
682 bzero(ui->ui_x1, sizeof(ui->ui_x1)); | 695 bzero(ui->ui_x1, sizeof(ui->ui_x1)); /* XXX still needed? */ |
683 ui->ui_pr = IPPROTO_UDP; | 696 ui->ui_pr = IPPROTO_UDP; |
684 ui->ui_len = htons((u_short)len + sizeof (struct udphdr)); | |
685 ui->ui_src = inp->inp_laddr; 686 ui->ui_dst = inp->inp_faddr; 687 ui->ui_sport = inp->inp_lport; 688 ui->ui_dport = inp->inp_fport; | 697 ui->ui_src = inp->inp_laddr; 698 ui->ui_dst = inp->inp_faddr; 699 ui->ui_sport = inp->inp_lport; 700 ui->ui_dport = inp->inp_fport; |
689 ui->ui_ulen = ui->ui_len; | 701 ui->ui_ulen = htons((u_short)len + sizeof(struct udphdr)); |
690 691 /* | 702 703 /* |
692 * Stuff checksum and output datagram. | 704 * Set up checksum and output datagram. |
693 */ | 705 */ |
694 ui->ui_sum = 0; | |
695 if (udpcksum) { | 706 if (udpcksum) { |
696 if ((ui->ui_sum = in_cksum(m, sizeof (struct udpiphdr) + len)) == 0) 697 ui->ui_sum = 0xffff; | 707 ui->ui_sum = in_pseudo(ui->ui_src.s_addr, ui->ui_dst.s_addr, 708 htons((u_short)len + sizeof(struct udphdr) + IPPROTO_UDP)); 709 m->m_pkthdr.csum_flags = CSUM_UDP; 710 m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); 711 } else { 712 ui->ui_sum = 0; |
698 } 699 ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; 700 ((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl; /* XXX */ 701 ((struct ip *)ui)->ip_tos = inp->inp_ip_tos; /* XXX */ 702 udpstat.udps_opackets++; 703 704#ifdef IPSEC 705 m->m_pkthdr.rcvif = (struct ifnet *)inp->inp_socket; --- 188 unchanged lines hidden --- | 713 } 714 ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; 715 ((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl; /* XXX */ 716 ((struct ip *)ui)->ip_tos = inp->inp_ip_tos; /* XXX */ 717 udpstat.udps_opackets++; 718 719#ifdef IPSEC 720 m->m_pkthdr.rcvif = (struct ifnet *)inp->inp_socket; --- 188 unchanged lines hidden --- |