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.93.2.1 retrieving revision 1.101 diff -u -p -r1.93.2.1 -r1.101 --- src/sys/netinet/udp_usrreq.c 2002/06/20 15:52:32 1.93.2.1 +++ src/sys/netinet/udp_usrreq.c 2003/06/23 11:02:17 1.101 @@ -1,4 +1,4 @@ -/* $NetBSD: udp_usrreq.c,v 1.93.2.1 2002/06/20 15:52:32 gehenna Exp $ */ +/* $NetBSD: udp_usrreq.c,v 1.101 2003/06/23 11:02:17 martin Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -65,12 +65,13 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.93.2.1 2002/06/20 15:52:32 gehenna Exp $"); +__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.101 2003/06/23 11:02:17 martin 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 +107,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 @@ -163,6 +162,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 @@ -197,6 +202,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,55 +222,29 @@ 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. */ if (uh->uh_dport == 0) @@ -271,13 +254,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); } /* @@ -392,9 +376,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 @@ -409,15 +390,12 @@ 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); /* * RFC2675 section 4: jumbograms will have 0 in the UDP header field, @@ -497,9 +475,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; @@ -509,7 +484,6 @@ udp4_sendup(m, off, src, so) break; #ifdef INET6 case AF_INET6: - in6p = sotoin6pcb(so); break; #endif default: @@ -615,7 +589,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 @@ -652,7 +625,6 @@ udp4_realinput(src, dst, m, off) continue; } - last = inp; udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket); rcvcnt++; @@ -721,7 +693,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 @@ -767,7 +738,6 @@ udp6_realinput(af, src, dst, m, off) continue; } - last = in6p; udp6_sendup(m, off, (struct sockaddr *)src, in6p->in6p_socket); rcvcnt++; @@ -872,6 +842,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); @@ -890,7 +861,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 +893,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++; @@ -992,6 +963,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) @@ -1032,6 +1008,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; @@ -1060,11 +1041,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; @@ -1072,11 +1050,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;