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.64 retrieving revision 1.73 diff -u -p -r1.64 -r1.73 --- src/sys/netinet/udp_usrreq.c 2000/03/22 20:58:30 1.64 +++ src/sys/netinet/udp_usrreq.c 2000/12/04 11:23:04 1.73 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.64 2000/03/22 20:58:30 ws Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.73 2000/12/04 11:23:04 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -79,7 +79,7 @@ #include #include -#include +#include #include #include @@ -115,7 +115,6 @@ #ifdef IPSEC #include #include -#include #endif /*IPSEC*/ #ifdef IPKDB @@ -132,10 +131,12 @@ int udpcksum = 1; int udpcksum = 0; /* XXX */ #endif +#ifdef INET static void udp4_sendup __P((struct mbuf *, int, struct sockaddr *, struct socket *)); static int udp4_realinput __P((struct sockaddr_in *, struct sockaddr_in *, struct mbuf *, int)); +#endif #ifdef INET6 static void udp6_sendup __P((struct mbuf *, int, struct sockaddr *, struct socket *)); @@ -144,7 +145,9 @@ static int in6_mcmatch __P((struct in6pc static int udp6_realinput __P((int, struct sockaddr_in6 *, struct sockaddr_in6 *, struct mbuf *, int)); #endif +#ifdef INET static void udp_notify __P((struct inpcb *, int)); +#endif #ifndef UDBHASHSIZE #define UDBHASHSIZE 128 @@ -155,10 +158,13 @@ void udp_init() { +#ifdef INET in_pcbinit(&udbtable, udbhashsize, udbhashsize); +#endif } #ifndef UDP6 +#ifdef INET void #if __STDC__ udp_input(struct mbuf *m, ...) @@ -232,7 +238,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; } @@ -311,6 +317,7 @@ bad: if (m) m_freem(m); } +#endif #ifdef INET6 int @@ -354,6 +361,10 @@ udp6_input(mp, offp, proto) } #endif ulen = ntohs((u_short)uh->uh_ulen); + /* + * RFC2675 section 4: jumbograms will have 0 in the UDP header field, + * iff payload length > 0xffff. + */ if (ulen == 0 && plen > 0xffff) ulen = plen; @@ -390,28 +401,14 @@ udp6_input(mp, offp, proto) bzero(&src, sizeof(src)); src.sin6_family = AF_INET6; src.sin6_len = sizeof(struct sockaddr_in6); - bcopy(&ip6->ip6_src, &src.sin6_addr, sizeof(src.sin6_addr)); - if (IN6_IS_SCOPE_LINKLOCAL(&src.sin6_addr)) - src.sin6_addr.s6_addr16[1] = 0; - if (m->m_pkthdr.rcvif) { - if (IN6_IS_SCOPE_LINKLOCAL(&src.sin6_addr)) - src.sin6_scope_id = m->m_pkthdr.rcvif->if_index; - else - src.sin6_scope_id = 0; - } + /* KAME hack: recover scopeid */ + (void)in6_recoverscope(&src, &ip6->ip6_src, m->m_pkthdr.rcvif); src.sin6_port = uh->uh_sport; bzero(&dst, sizeof(dst)); dst.sin6_family = AF_INET6; dst.sin6_len = sizeof(struct sockaddr_in6); - bcopy(&ip6->ip6_dst, &dst.sin6_addr, sizeof(dst.sin6_addr)); - if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6_addr)) - dst.sin6_addr.s6_addr16[1] = 0; - if (m->m_pkthdr.rcvif) { - if (IN6_IS_SCOPE_LINKLOCAL(&dst.sin6_addr)) - dst.sin6_scope_id = m->m_pkthdr.rcvif->if_index; - else - dst.sin6_scope_id = 0; - } + /* KAME hack: recover scopeid */ + (void)in6_recoverscope(&dst, &ip6->ip6_dst, m->m_pkthdr.rcvif); dst.sin6_port = uh->uh_dport; if (udp6_realinput(AF_INET6, &src, &dst, m, off) == 0) { @@ -431,6 +428,7 @@ bad: } #endif +#ifdef INET static void udp4_sendup(m, off, src, so) struct mbuf *m; @@ -485,6 +483,7 @@ udp4_sendup(m, off, src, so) sorwakeup(so); } } +#endif #ifdef INET6 static void @@ -531,6 +530,7 @@ udp6_sendup(m, off, src, so) } #endif +#ifdef INET static int udp4_realinput(src, dst, m, off) struct sockaddr_in *src; @@ -554,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; /* @@ -575,7 +575,7 @@ udp4_realinput(src, dst, m, off) /* * KAME note: usually we drop udpiphdr from mbuf here. - * we need udpiphdr for iPsec processing so we do that later. + * we need udpiphdr for IPsec processing so we do that later. */ /* * Locate pcb(s) for datagram. @@ -667,12 +667,13 @@ udp4_realinput(src, dst, m, off) bad: return rcvcnt; } +#endif #ifdef INET6 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; @@ -721,7 +722,7 @@ udp6_realinput(af, src, dst, m, off) src4 = (struct in_addr *)&src->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 @@ -741,7 +742,7 @@ udp6_realinput(af, src, dst, m, off) /* * KAME note: usually we drop udpiphdr from mbuf here. - * we need udpiphdr for iPsec processing so we do that later. + * we need udpiphdr for IPsec processing so we do that later. */ /* * Locate pcb(s) for datagram. @@ -873,9 +874,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; @@ -925,7 +926,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; } @@ -982,7 +983,7 @@ udp_input(m, va_alist) iphlen += sizeof(struct udphdr); /* * KAME note: usually we drop udpiphdr from mbuf here. - * we need udpiphdr for iPsec processing so we do that later. + * we need udpiphdr for IPsec processing so we do that later. */ /* * Locate pcb(s) for datagram. @@ -1138,13 +1139,14 @@ bad: } #endif /*UDP6*/ +#ifdef INET /* * Notify a udp user of an asynchronous error; * just wake up so that he can collect error status. */ static void udp_notify(inp, errno) - register struct inpcb *inp; + struct inpcb *inp; int errno; { @@ -1159,9 +1161,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; @@ -1198,9 +1199,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; @@ -1279,9 +1280,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, @@ -1474,3 +1475,4 @@ udp_sysctl(name, namelen, oldp, oldlenp, } /* NOTREACHED */ } +#endif