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.75.2.9 retrieving revision 1.109 diff -u -p -r1.75.2.9 -r1.109 --- src/sys/netinet/udp_usrreq.c 2002/08/27 23:48:07 1.75.2.9 +++ src/sys/netinet/udp_usrreq.c 2003/09/04 09:17:03 1.109 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.75.2.9 2002/08/27 23:48:07 nathanw Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.109 2003/09/04 09:17:03 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -41,11 +41,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * @@ -65,12 +61,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.75.2.9 2002/08/27 23:48:07 nathanw Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.109 2003/09/04 09:17:03 itojun Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" #include "opt_inet_csum.h" #include "opt_ipkdb.h" +#include "opt_mbuftrace.h" #include #include @@ -106,12 +103,10 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #include #endif -#ifdef PULLDOWN_TEST #ifndef INET6 /* always need ip6.h for IP6_EXTHDR_GET */ #include #endif -#endif #include "faith.h" #if defined(NFAITH) && NFAITH > 0 @@ -120,6 +115,13 @@ __KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c #include +#ifdef FAST_IPSEC +#include +#ifdef INET6 +#include +#endif +#endif /* FAST_IPSEC*/ + #ifdef IPSEC #include #include @@ -163,6 +165,12 @@ static void udp_notify __P((struct inpcb #endif int udbhashsize = UDBHASHSIZE; +#ifdef MBUFTRACE +struct mowner udp_mowner = { "udp" }; +struct mowner udp_rx_mowner = { "udp", "rx" }; +struct mowner udp_tx_mowner = { "udp", "tx" }; +#endif + #ifdef UDP_CSUM_COUNTERS #include @@ -187,9 +195,7 @@ void udp_init() { -#ifdef INET in_pcbinit(&udbtable, udbhashsize, udbhashsize); -#endif #ifdef UDP_CSUM_COUNTERS evcnt_attach_static(&udp_hwcsum_bad); @@ -197,6 +203,10 @@ udp_init() evcnt_attach_static(&udp_hwcsum_data); evcnt_attach_static(&udp_swcsum); #endif /* UDP_CSUM_COUNTERS */ + + MOWNER_ATTACH(&udp_tx_mowner); + MOWNER_ATTACH(&udp_rx_mowner); + MOWNER_ATTACH(&udp_mowner); } #ifdef INET @@ -213,56 +223,28 @@ udp_input(m, va_alist) struct sockaddr_in src, dst; struct ip *ip; struct udphdr *uh; - int iphlen, proto; + int iphlen; int len; int n; u_int16_t ip_len; va_start(ap, m); iphlen = va_arg(ap, int); - proto = va_arg(ap, int); + (void)va_arg(ap, int); /* ignore value, advance ap */ va_end(ap); + MCLAIM(m, &udp_rx_mowner); udpstat.udps_ipackets++; -#ifndef PULLDOWN_TEST - /* - * Strip IP options, if any; should skip this, - * make available to user, and use on returned packets, - * but we don't yet have a way to check the checksum - * with options still present. - */ - if (iphlen > sizeof (struct ip)) { - ip_stripoptions(m, (struct mbuf *)0); - iphlen = sizeof(struct ip); - } -#else - /* - * we may enable the above code if we save and pass IPv4 options - * to the userland. - */ -#endif - /* * Get IP and UDP header together in first mbuf. */ ip = mtod(m, struct ip *); -#ifndef PULLDOWN_TEST - if (m->m_len < iphlen + sizeof(struct udphdr)) { - if ((m = m_pullup(m, iphlen + sizeof(struct udphdr))) == 0) { - udpstat.udps_hdrops++; - return; - } - ip = mtod(m, struct ip *); - } - uh = (struct udphdr *)((caddr_t)ip + iphlen); -#else IP6_EXTHDR_GET(uh, struct udphdr *, m, iphlen, sizeof(struct udphdr)); if (uh == NULL) { udpstat.udps_hdrops++; return; } -#endif KASSERT(UDP_HDR_ALIGNED_P(uh)); /* destination port of 0 is illegal, based on RFC768. */ @@ -294,11 +276,16 @@ udp_input(m, va_alist) UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad); goto badcsum; - case M_CSUM_UDPv4|M_CSUM_DATA: + case M_CSUM_UDPv4|M_CSUM_DATA: { + u_int32_t hw_csum = m->m_pkthdr.csum_data; UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data); - if ((m->m_pkthdr.csum_data ^ 0xffff) != 0) + if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR) + hw_csum = in_cksum_phdr(ip->ip_src.s_addr, ip->ip_dst.s_addr, + htonl(hw_csum + ntohs(ip->ip_len) + IPPROTO_UDP)); + if ((hw_csum ^ 0xffff) != 0) goto badcsum; break; + } case M_CSUM_UDPv4: /* Checksum was okay. */ @@ -395,9 +382,6 @@ udp6_input(mp, offp, proto) struct udphdr *uh; u_int32_t plen, ulen; -#ifndef PULLDOWN_TEST - IP6_EXTHDR_CHECK(m, off, sizeof(struct udphdr), IPPROTO_DONE); -#endif ip6 = mtod(m, struct ip6_hdr *); #if defined(NFAITH) && 0 < NFAITH @@ -412,15 +396,11 @@ udp6_input(mp, offp, proto) /* check for jumbogram is done in ip6_input. we can trust pkthdr.len */ plen = m->m_pkthdr.len - off; -#ifndef PULLDOWN_TEST - uh = (struct udphdr *)((caddr_t)ip6 + off); -#else IP6_EXTHDR_GET(uh, struct udphdr *, m, off, sizeof(struct udphdr)); if (uh == NULL) { ip6stat.ip6s_tooshort++; return IPPROTO_DONE; } -#endif KASSERT(UDP_HDR_ALIGNED_P(uh)); ulen = ntohs((u_short)uh->uh_ulen); /* @@ -501,9 +481,6 @@ udp4_sendup(m, off, src, so) struct mbuf *opts = NULL; struct mbuf *n; struct inpcb *inp = NULL; -#ifdef INET6 - struct in6pcb *in6p = NULL; -#endif if (!so) return; @@ -513,14 +490,13 @@ udp4_sendup(m, off, src, so) break; #ifdef INET6 case AF_INET6: - in6p = sotoin6pcb(so); break; #endif default: return; } -#ifdef IPSEC +#if defined(IPSEC) || defined(FAST_IPSEC) /* check AH/ESP integrity. */ if (so != NULL && ipsec4_in_reject_so(m, so)) { ipsecstat.in_polvio++; @@ -566,7 +542,7 @@ udp6_sendup(m, off, src, so) return; in6p = sotoin6pcb(so); -#ifdef IPSEC +#if defined(IPSEC) || defined(FAST_IPSEC) /* check AH/ESP integrity. */ if (so != NULL && ipsec6_in_reject_so(m, so)) { ipsec6stat.in_polvio++; @@ -604,6 +580,7 @@ udp4_realinput(src, dst, m, off) u_int16_t *sport, *dport; int rcvcnt; struct in_addr *src4, *dst4; + struct inpcb_hdr *inph; struct inpcb *inp; rcvcnt = 0; @@ -619,7 +596,6 @@ udp4_realinput(src, dst, m, off) if (IN_MULTICAST(dst4->s_addr) || in_broadcast(*dst4, m->m_pkthdr.rcvif)) { - struct inpcb *last; /* * Deliver a multicast or broadcast datagram to *all* sockets * for which the local and remote addresses and ports match @@ -643,7 +619,11 @@ udp4_realinput(src, dst, m, off) /* * Locate pcb(s) for datagram. */ - CIRCLEQ_FOREACH(inp, &udbtable.inpt_queue, inp_queue) { + CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { + inp = (struct inpcb *)inph; + if (inp->inp_af != AF_INET) + continue; + if (inp->inp_lport != *dport) continue; if (!in_nullhost(inp->inp_laddr)) { @@ -656,7 +636,6 @@ udp4_realinput(src, dst, m, off) continue; } - last = inp; udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket); rcvcnt++; @@ -707,6 +686,7 @@ udp6_realinput(af, src, dst, m, off) int rcvcnt; struct in6_addr src6, dst6; const struct in_addr *dst4; + struct inpcb_hdr *inph; struct in6pcb *in6p; rcvcnt = 0; @@ -725,7 +705,6 @@ udp6_realinput(af, src, dst, m, off) if (IN6_IS_ADDR_MULTICAST(&dst6) || (af == AF_INET && IN_MULTICAST(dst4->s_addr))) { - struct in6pcb *last; /* * Deliver a multicast or broadcast datagram to *all* sockets * for which the local and remote addresses and ports match @@ -749,8 +728,11 @@ udp6_realinput(af, src, dst, m, off) /* * Locate pcb(s) for datagram. */ - for (in6p = udb6.in6p_next; in6p != &udb6; - in6p = in6p->in6p_next) { + CIRCLEQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { + in6p = (struct in6pcb *)inph; + if (in6p->in6p_af != AF_INET6) + continue; + if (in6p->in6p_lport != dport) continue; if (!IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) { @@ -771,7 +753,6 @@ udp6_realinput(af, src, dst, m, off) continue; } - last = in6p; udp6_sendup(m, off, (struct sockaddr *)src, in6p->in6p_socket); rcvcnt++; @@ -792,11 +773,11 @@ udp6_realinput(af, src, dst, m, off) /* * Locate pcb for datagram. */ - in6p = in6_pcblookup_connect(&udb6, &src6, sport, + in6p = in6_pcblookup_connect(&udbtable, &src6, sport, &dst6, dport, 0); if (in6p == 0) { ++udpstat.udps_pcbhashmiss; - in6p = in6_pcblookup_bind(&udb6, &dst6, dport, 0); + in6p = in6_pcblookup_bind(&udbtable, &dst6, dport, 0); if (in6p == 0) return rcvcnt; } @@ -876,6 +857,7 @@ udp_output(m, va_alist) int error = 0; va_list ap; + MCLAIM(m, &udp_tx_mowner); va_start(ap, m); inp = va_arg(ap, struct inpcb *); va_end(ap); @@ -931,16 +913,9 @@ udp_output(m, va_alist) ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */ udpstat.udps_opackets++; -#ifdef IPSEC - if (ipsec_setsocket(m, inp->inp_socket) != 0) { - error = ENOBUFS; - goto release; - } -#endif /*IPSEC*/ - return (ip_output(m, inp->inp_options, &inp->inp_route, inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST), - inp->inp_moptions)); + inp->inp_moptions, inp->inp_socket)); release: m_freem(m); @@ -996,6 +971,11 @@ udp_usrreq(so, req, m, nam, control, p) error = EISCONN; break; } +#ifdef MBUFTRACE + so->so_mowner = &udp_mowner; + so->so_rcv.sb_mowner = &udp_rx_mowner; + so->so_snd.sb_mowner = &udp_tx_mowner; +#endif if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { error = soreserve(so, udp_sendspace, udp_recvspace); if (error) @@ -1036,6 +1016,11 @@ udp_usrreq(so, req, m, nam, control, p) so->so_state &= ~SS_ISCONNECTED; /* XXX */ in_pcbdisconnect(inp); inp->inp_laddr = zeroin_addr; /* XXX */ + if (inp->inp_ia != NULL) { + LIST_REMOVE(inp, inp_ialink); + IFAFREE(&inp->inp_ia->ia_ifa); + inp->inp_ia = NULL; + } in_pcbstate(inp, INP_BOUND); /* XXX */ break; @@ -1064,11 +1049,8 @@ udp_usrreq(so, req, m, nam, control, p) goto die; } error = in_pcbconnect(inp, nam); - if (error) { - die: - m_freem(m); - break; - } + if (error) + goto die; } else { if ((so->so_state & SS_ISCONNECTED) == 0) { error = ENOTCONN; @@ -1076,11 +1058,20 @@ udp_usrreq(so, req, m, nam, control, p) } } error = udp_output(m, inp); + m = NULL; if (nam) { in_pcbdisconnect(inp); inp->inp_laddr = laddr; /* XXX */ in_pcbstate(inp, INP_BOUND); /* XXX */ } + die: + if (inp->inp_ia != NULL && in_nullhost(inp->inp_laddr)) { + LIST_REMOVE(inp, inp_ialink); + IFAFREE(&inp->inp_ia->ia_ifa); + inp->inp_ia = NULL; + } + if (m) + m_freem(m); } break;