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 rcsdiff: /ftp/cvs/cvsroot/src/sys/netinet/udp_usrreq.c,v: warning: Unknown phrases like `commitid ...;' are present. retrieving revision 1.60 retrieving revision 1.66.4.3 diff -u -p -r1.60 -r1.66.4.3 --- src/sys/netinet/udp_usrreq.c 2000/02/02 23:28:09 1.60 +++ src/sys/netinet/udp_usrreq.c 2000/12/15 03:29:16 1.66.4.3 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.60 2000/02/02 23:28:09 thorpej Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.66.4.3 2000/12/15 03:29:16 he Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -65,8 +65,7 @@ */ #include "opt_ipsec.h" - -#include "ipkdb.h" +#include "opt_ipkdb.h" #include #include @@ -119,6 +118,10 @@ #include #endif /*IPSEC*/ +#ifdef IPKDB +#include +#endif + /* * UDP protocol implementation. * Per RFC 768, August, 1980. @@ -229,7 +232,7 @@ udp_input(m, va_alist) */ len = ntohs((u_int16_t)uh->uh_ulen); if (ip->ip_len != iphlen + len) { - if (ip->ip_len < iphlen + len) { + if (ip->ip_len < iphlen + len || len < sizeof(struct udphdr)) { udpstat.udps_badlen++; goto bad; } @@ -240,32 +243,11 @@ udp_input(m, va_alist) * Checksum extended UDP header and data. */ if (uh->uh_sum) { -#ifndef PULLDOWN_TEST - struct ip save_ip; - - /* - * Save a copy of the IP header in case we want restore it - * for sending an ICMP error message in response. - */ - save_ip = *ip; - - bzero(((struct ipovly *)ip)->ih_x1, - sizeof ((struct ipovly *)ip)->ih_x1); - ((struct ipovly *)ip)->ih_len = uh->uh_ulen; - if (in_cksum(m, len + sizeof (struct ip)) != 0) { - udpstat.udps_badsum++; - m_freem(m); - return; - } - - *ip = save_ip; -#else if (in4_cksum(m, IPPROTO_UDP, iphlen, len) != 0) { udpstat.udps_badsum++; m_freem(m); return; } -#endif } /* construct source and dst sockaddrs. */ @@ -305,12 +287,12 @@ udp_input(m, va_alist) #endif if (n == 0) { - udpstat.udps_noport++; if (m->m_flags & (M_BCAST | M_MCAST)) { udpstat.udps_noportbcast++; goto bad; } -#if NIPKDB > 0 + udpstat.udps_noport++; +#ifdef IPKDB if (checkipkdb(&ip->ip_src, uh->uh_sport, uh->uh_dport, m, iphlen + sizeof(struct udphdr), m->m_pkthdr.len - iphlen - sizeof(struct udphdr))) { @@ -433,11 +415,11 @@ udp6_input(mp, offp, proto) dst.sin6_port = uh->uh_dport; if (udp6_realinput(AF_INET6, &src, &dst, m, off) == 0) { - udp6stat.udp6s_noport++; if (m->m_flags & M_MCAST) { udp6stat.udp6s_noportmcast++; goto bad; } + udp6stat.udp6s_noport++; icmp6_error(m, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0); m = NULL; } @@ -572,7 +554,7 @@ udp4_realinput(src, dst, m, off) dst4 = &dst->sin_addr; dport = &dst->sin_port; - if (IN_MULTICAST(src4->s_addr) || + if (IN_MULTICAST(dst4->s_addr) || in_broadcast(*dst4, m->m_pkthdr.rcvif)) { struct inpcb *last; /* @@ -638,7 +620,6 @@ udp4_realinput(src, dst, m, off) * (No need to send an ICMP Port Unreachable * for a broadcast or multicast datgram.) */ - udpstat.udps_noport++; udpstat.udps_noportbcast++; goto bad; } @@ -655,12 +636,12 @@ udp4_realinput(src, dst, m, off) #if 0 struct mbuf *n; - udpstat.udps_noport++; if (m->m_flags & (M_BCAST | M_MCAST)) { udpstat.udps_noportbcast++; goto bad; } -#if NIPKDB > 0 + udpstat.udps_noport++; +#ifdef IPKDB if (checkipkdb(src4, *sport, *dport, m, off, m->m_pkthdr.len - off)) { /* @@ -691,7 +672,7 @@ bad: static int in6_mcmatch(in6p, ia6, ifp) struct in6pcb *in6p; - register struct in6_addr *ia6; + struct in6_addr *ia6; struct ifnet *ifp; { struct ip6_moptions *im6o = in6p->in6p_moptions; @@ -722,7 +703,7 @@ udp6_realinput(af, src, dst, m, off) u_int16_t *sport, *dport; int rcvcnt; struct in6_addr *src6, *dst6; - struct in_addr *src4; + struct in_addr *dst4; struct in6pcb *in6p; rcvcnt = 0; @@ -737,10 +718,10 @@ udp6_realinput(af, src, dst, m, off) sport = &src->sin6_port; dst6 = &dst->sin6_addr; dport = &dst->sin6_port; - src4 = (struct in_addr *)&src->sin6_addr.s6_addr32[12]; + dst4 = (struct in_addr *)&dst->sin6_addr.s6_addr32[12]; if (IN6_IS_ADDR_MULTICAST(dst6) - || (af == AF_INET && IN_MULTICAST(src4->s_addr))) { + || (af == AF_INET && IN_MULTICAST(dst4->s_addr))) { struct in6pcb *last; /* * Deliver a multicast or broadcast datagram to *all* sockets @@ -821,11 +802,9 @@ udp6_realinput(af, src, dst, m, off) */ switch (af) { case AF_INET: - udpstat.udps_noport++; udpstat.udps_noportbcast++; break; case AF_INET6: - udp6stat.udp6s_noport++; udp6stat.udp6s_noportmcast++; break; } @@ -847,21 +826,21 @@ udp6_realinput(af, src, dst, m, off) n = m_copy(m, 0, M_COPYALL); switch (af) { case AF_INET: - udpstat.udps_noport++; if (m->m_flags & (M_BCAST | M_MCAST)) { udpstat.udps_noportbcast++; goto bad; } + udpstat.udps_noport++; if (n != NULL) icmp_error(n, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0); break; case AF_INET6: - udp6stat.udp6s_noport++; if (m->m_flags & M_MCAST) { udp6stat.udp6s_noportmcast++; goto bad; } + udp6stat.udp6s_noport++; if (n != NULL) icmp6_error(n, ICMP6_DST_UNREACH, ICMP6_DST_UNREACH_NOPORT, 0); @@ -894,9 +873,9 @@ udp_input(m, va_alist) #endif { int proto; - register struct ip *ip; - register struct udphdr *uh; - register struct inpcb *inp; + struct ip *ip; + struct udphdr *uh; + struct inpcb *inp; struct mbuf *opts = 0; int len; struct ip save_ip; @@ -946,7 +925,7 @@ udp_input(m, va_alist) */ len = ntohs((u_int16_t)uh->uh_ulen); if (ip->ip_len != iphlen + len) { - if (ip->ip_len < iphlen + len) { + if (ip->ip_len < iphlen + len || len < sizeof(struct udphdr)) { udpstat.udps_badlen++; goto bad; } @@ -1075,7 +1054,6 @@ udp_input(m, va_alist) * (No need to send an ICMP Port Unreachable * for a broadcast or multicast datgram.) */ - udpstat.udps_noport++; udpstat.udps_noportbcast++; goto bad; } @@ -1109,13 +1087,13 @@ udp_input(m, va_alist) ++udpstat.udps_pcbhashmiss; inp = in_pcblookup_bind(&udbtable, ip->ip_dst, uh->uh_dport); if (inp == 0) { - udpstat.udps_noport++; if (m->m_flags & (M_BCAST | M_MCAST)) { udpstat.udps_noportbcast++; goto bad; } + udpstat.udps_noport++; *ip = save_ip; -#if NIPKDB > 0 +#ifdef IPKDB if (checkipkdb(&ip->ip_src, uh->uh_sport, uh->uh_dport, @@ -1166,7 +1144,7 @@ bad: */ static void udp_notify(inp, errno) - register struct inpcb *inp; + struct inpcb *inp; int errno; { @@ -1181,9 +1159,8 @@ udp_ctlinput(cmd, sa, v) struct sockaddr *sa; void *v; { - register struct ip *ip = v; - register struct udphdr *uh; - extern int inetctlerrmap[]; + struct ip *ip = v; + struct udphdr *uh; void (*notify) __P((struct inpcb *, int)) = udp_notify; int errno; @@ -1220,9 +1197,9 @@ udp_output(m, va_alist) va_dcl #endif { - register struct inpcb *inp; - register struct udpiphdr *ui; - register int len = m->m_pkthdr.len; + struct inpcb *inp; + struct udpiphdr *ui; + int len = m->m_pkthdr.len; int error = 0; va_list ap; @@ -1277,7 +1254,7 @@ udp_output(m, va_alist) udpstat.udps_opackets++; #ifdef IPSEC - m->m_pkthdr.rcvif = (struct ifnet *)inp->inp_socket; + ipsec_setsocket(m, inp->inp_socket); #endif /*IPSEC*/ return (ip_output(m, inp->inp_options, &inp->inp_route, @@ -1301,9 +1278,9 @@ udp_usrreq(so, req, m, nam, control, p) struct mbuf *m, *nam, *control; struct proc *p; { - register struct inpcb *inp; + struct inpcb *inp; int s; - register int error = 0; + int error = 0; if (req == PRU_CONTROL) return (in_control(so, (long)m, (caddr_t)nam,