1df8bae1dSRodney W. Grimes /* 26dfab5b1SGarrett Wollman * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 6df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 7df8bae1dSRodney W. Grimes * are met: 8df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 9df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 10df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 11df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 12df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 13df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 14df8bae1dSRodney W. Grimes * must display the following acknowledgement: 15df8bae1dSRodney W. Grimes * This product includes software developed by the University of 16df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 17df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 18df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 19df8bae1dSRodney W. Grimes * without specific prior written permission. 20df8bae1dSRodney W. Grimes * 21df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31df8bae1dSRodney W. Grimes * SUCH DAMAGE. 32df8bae1dSRodney W. Grimes * 336dfab5b1SGarrett Wollman * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 3416f7f31fSGeoff Rehmet * $Id: udp_usrreq.c,v 1.53 1999/07/11 18:32:46 green Exp $ 35df8bae1dSRodney W. Grimes */ 36df8bae1dSRodney W. Grimes 37df8bae1dSRodney W. Grimes #include <sys/param.h> 3826f9a767SRodney W. Grimes #include <sys/systm.h> 39b110a8a2SGarrett Wollman #include <sys/kernel.h> 40df8bae1dSRodney W. Grimes #include <sys/malloc.h> 41df8bae1dSRodney W. Grimes #include <sys/mbuf.h> 42490d50b6SBrian Feldman #include <sys/proc.h> 43df8bae1dSRodney W. Grimes #include <sys/protosw.h> 44df8bae1dSRodney W. Grimes #include <sys/socket.h> 45df8bae1dSRodney W. Grimes #include <sys/socketvar.h> 46b5e8ce9fSBruce Evans #include <sys/sysctl.h> 47816a3d83SPoul-Henning Kamp #include <sys/syslog.h> 488781d8e9SBruce Evans 493d4d47f3SGarrett Wollman #include <vm/vm_zone.h> 50df8bae1dSRodney W. Grimes 51df8bae1dSRodney W. Grimes #include <net/if.h> 52df8bae1dSRodney W. Grimes #include <net/route.h> 53df8bae1dSRodney W. Grimes 54df8bae1dSRodney W. Grimes #include <netinet/in.h> 55df8bae1dSRodney W. Grimes #include <netinet/in_systm.h> 56df8bae1dSRodney W. Grimes #include <netinet/ip.h> 57df8bae1dSRodney W. Grimes #include <netinet/in_pcb.h> 58b5e8ce9fSBruce Evans #include <netinet/in_var.h> 59df8bae1dSRodney W. Grimes #include <netinet/ip_var.h> 60df8bae1dSRodney W. Grimes #include <netinet/ip_icmp.h> 6151508de1SMatthew Dillon #include <netinet/icmp_var.h> 62df8bae1dSRodney W. Grimes #include <netinet/udp.h> 63df8bae1dSRodney W. Grimes #include <netinet/udp_var.h> 64df8bae1dSRodney W. Grimes 65df8bae1dSRodney W. Grimes /* 66df8bae1dSRodney W. Grimes * UDP protocol implementation. 67df8bae1dSRodney W. Grimes * Per RFC 768, August, 1980. 68df8bae1dSRodney W. Grimes */ 69df8bae1dSRodney W. Grimes #ifndef COMPAT_42 700312fbe9SPoul-Henning Kamp static int udpcksum = 1; 71df8bae1dSRodney W. Grimes #else 720312fbe9SPoul-Henning Kamp static int udpcksum = 0; /* XXX */ 73df8bae1dSRodney W. Grimes #endif 740312fbe9SPoul-Henning Kamp SYSCTL_INT(_net_inet_udp, UDPCTL_CHECKSUM, checksum, CTLFLAG_RW, 750312fbe9SPoul-Henning Kamp &udpcksum, 0, ""); 76df8bae1dSRodney W. Grimes 77d78a37adSPaul Traina static int log_in_vain = 0; 78816a3d83SPoul-Henning Kamp SYSCTL_INT(_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_RW, 793d177f46SBill Fumerola &log_in_vain, 0, "Log all incoming UDP packets"); 80816a3d83SPoul-Henning Kamp 8116f7f31fSGeoff Rehmet static int blackhole = 0; 8216f7f31fSGeoff Rehmet SYSCTL_INT(_net_inet_udp, OID_AUTO, blackhole, CTLFLAG_RW, 8316f7f31fSGeoff Rehmet &blackhole, 0, "Do not send port unreachables for refused connects"); 8416f7f31fSGeoff Rehmet 85f708ef1bSPoul-Henning Kamp static struct inpcbhead udb; /* from udp_var.h */ 867a2aab80SBrian Feldman struct inpcbinfo udbinfo; 8715bd2b43SDavid Greenman 8815bd2b43SDavid Greenman #ifndef UDBHASHSIZE 89c3229e05SDavid Greenman #define UDBHASHSIZE 16 9015bd2b43SDavid Greenman #endif 9115bd2b43SDavid Greenman 92f708ef1bSPoul-Henning Kamp static struct udpstat udpstat; /* from udp_var.h */ 930312fbe9SPoul-Henning Kamp SYSCTL_STRUCT(_net_inet_udp, UDPCTL_STATS, stats, CTLFLAG_RD, 943d177f46SBill Fumerola &udpstat, udpstat, "UDP statistics (struct udpstat, netinet/udp_var.h)"); 95f2ea20e6SGarrett Wollman 960312fbe9SPoul-Henning Kamp static struct sockaddr_in udp_in = { sizeof(udp_in), AF_INET }; 97df8bae1dSRodney W. Grimes 9857bf258eSGarrett Wollman static int udp_output __P((struct inpcb *, struct mbuf *, struct sockaddr *, 99a29f300eSGarrett Wollman struct mbuf *, struct proc *)); 100df8bae1dSRodney W. Grimes static void udp_notify __P((struct inpcb *, int)); 101df8bae1dSRodney W. Grimes 102df8bae1dSRodney W. Grimes void 103df8bae1dSRodney W. Grimes udp_init() 104df8bae1dSRodney W. Grimes { 10515bd2b43SDavid Greenman LIST_INIT(&udb); 10615bd2b43SDavid Greenman udbinfo.listhead = &udb; 107ddd79a97SDavid Greenman udbinfo.hashbase = hashinit(UDBHASHSIZE, M_PCB, &udbinfo.hashmask); 1088781d8e9SBruce Evans udbinfo.porthashbase = hashinit(UDBHASHSIZE, M_PCB, 1098781d8e9SBruce Evans &udbinfo.porthashmask); 11098271db4SGarrett Wollman udbinfo.ipi_zone = zinit("udpcb", sizeof(struct inpcb), maxsockets, 1113d4d47f3SGarrett Wollman ZONE_INTERRUPT, 0); 112df8bae1dSRodney W. Grimes } 113df8bae1dSRodney W. Grimes 114df8bae1dSRodney W. Grimes void 115df8bae1dSRodney W. Grimes udp_input(m, iphlen) 116df8bae1dSRodney W. Grimes register struct mbuf *m; 117df8bae1dSRodney W. Grimes int iphlen; 118df8bae1dSRodney W. Grimes { 119df8bae1dSRodney W. Grimes register struct ip *ip; 120df8bae1dSRodney W. Grimes register struct udphdr *uh; 121df8bae1dSRodney W. Grimes register struct inpcb *inp; 122df8bae1dSRodney W. Grimes struct mbuf *opts = 0; 123df8bae1dSRodney W. Grimes int len; 124df8bae1dSRodney W. Grimes struct ip save_ip; 125df8bae1dSRodney W. Grimes 126df8bae1dSRodney W. Grimes udpstat.udps_ipackets++; 127df8bae1dSRodney W. Grimes 128df8bae1dSRodney W. Grimes /* 129df8bae1dSRodney W. Grimes * Strip IP options, if any; should skip this, 130df8bae1dSRodney W. Grimes * make available to user, and use on returned packets, 131df8bae1dSRodney W. Grimes * but we don't yet have a way to check the checksum 132df8bae1dSRodney W. Grimes * with options still present. 133df8bae1dSRodney W. Grimes */ 134df8bae1dSRodney W. Grimes if (iphlen > sizeof (struct ip)) { 135df8bae1dSRodney W. Grimes ip_stripoptions(m, (struct mbuf *)0); 136df8bae1dSRodney W. Grimes iphlen = sizeof(struct ip); 137df8bae1dSRodney W. Grimes } 138df8bae1dSRodney W. Grimes 139df8bae1dSRodney W. Grimes /* 140df8bae1dSRodney W. Grimes * Get IP and UDP header together in first mbuf. 141df8bae1dSRodney W. Grimes */ 142df8bae1dSRodney W. Grimes ip = mtod(m, struct ip *); 143df8bae1dSRodney W. Grimes if (m->m_len < iphlen + sizeof(struct udphdr)) { 144df8bae1dSRodney W. Grimes if ((m = m_pullup(m, iphlen + sizeof(struct udphdr))) == 0) { 145df8bae1dSRodney W. Grimes udpstat.udps_hdrops++; 146df8bae1dSRodney W. Grimes return; 147df8bae1dSRodney W. Grimes } 148df8bae1dSRodney W. Grimes ip = mtod(m, struct ip *); 149df8bae1dSRodney W. Grimes } 150df8bae1dSRodney W. Grimes uh = (struct udphdr *)((caddr_t)ip + iphlen); 151df8bae1dSRodney W. Grimes 152df8bae1dSRodney W. Grimes /* 153df8bae1dSRodney W. Grimes * Make mbuf data length reflect UDP length. 154df8bae1dSRodney W. Grimes * If not enough data to reflect UDP length, drop. 155df8bae1dSRodney W. Grimes */ 156df8bae1dSRodney W. Grimes len = ntohs((u_short)uh->uh_ulen); 157df8bae1dSRodney W. Grimes if (ip->ip_len != len) { 1587eb7a449SAndras Olah if (len > ip->ip_len || len < sizeof(struct udphdr)) { 159df8bae1dSRodney W. Grimes udpstat.udps_badlen++; 160df8bae1dSRodney W. Grimes goto bad; 161df8bae1dSRodney W. Grimes } 162df8bae1dSRodney W. Grimes m_adj(m, len - ip->ip_len); 163df8bae1dSRodney W. Grimes /* ip->ip_len = len; */ 164df8bae1dSRodney W. Grimes } 165df8bae1dSRodney W. Grimes /* 166df8bae1dSRodney W. Grimes * Save a copy of the IP header in case we want restore it 167df8bae1dSRodney W. Grimes * for sending an ICMP error message in response. 168df8bae1dSRodney W. Grimes */ 169df8bae1dSRodney W. Grimes save_ip = *ip; 170df8bae1dSRodney W. Grimes 171df8bae1dSRodney W. Grimes /* 172df8bae1dSRodney W. Grimes * Checksum extended UDP header and data. 173df8bae1dSRodney W. Grimes */ 1746dfab5b1SGarrett Wollman if (uh->uh_sum) { 1756effc713SDoug Rabson bzero(((struct ipovly *)ip)->ih_x1, 9); 176df8bae1dSRodney W. Grimes ((struct ipovly *)ip)->ih_len = uh->uh_ulen; 177623ae52eSPoul-Henning Kamp uh->uh_sum = in_cksum(m, len + sizeof (struct ip)); 178623ae52eSPoul-Henning Kamp if (uh->uh_sum) { 179df8bae1dSRodney W. Grimes udpstat.udps_badsum++; 180df8bae1dSRodney W. Grimes m_freem(m); 181df8bae1dSRodney W. Grimes return; 182df8bae1dSRodney W. Grimes } 183df8bae1dSRodney W. Grimes } 184df8bae1dSRodney W. Grimes 185df8bae1dSRodney W. Grimes if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) || 186df8bae1dSRodney W. Grimes in_broadcast(ip->ip_dst, m->m_pkthdr.rcvif)) { 18782c23ebaSBill Fenner struct inpcb *last; 188df8bae1dSRodney W. Grimes /* 189df8bae1dSRodney W. Grimes * Deliver a multicast or broadcast datagram to *all* sockets 190df8bae1dSRodney W. Grimes * for which the local and remote addresses and ports match 191df8bae1dSRodney W. Grimes * those of the incoming datagram. This allows more than 192df8bae1dSRodney W. Grimes * one process to receive multi/broadcasts on the same port. 193df8bae1dSRodney W. Grimes * (This really ought to be done for unicast datagrams as 194df8bae1dSRodney W. Grimes * well, but that would cause problems with existing 195df8bae1dSRodney W. Grimes * applications that open both address-specific sockets and 196df8bae1dSRodney W. Grimes * a wildcard socket listening to the same port -- they would 197df8bae1dSRodney W. Grimes * end up receiving duplicates of every unicast datagram. 198df8bae1dSRodney W. Grimes * Those applications open the multiple sockets to overcome an 199df8bae1dSRodney W. Grimes * inadequacy of the UDP socket interface, but for backwards 200df8bae1dSRodney W. Grimes * compatibility we avoid the problem here rather than 201df8bae1dSRodney W. Grimes * fixing the interface. Maybe 4.5BSD will remedy this?) 202df8bae1dSRodney W. Grimes */ 203df8bae1dSRodney W. Grimes 204df8bae1dSRodney W. Grimes /* 205df8bae1dSRodney W. Grimes * Construct sockaddr format source address. 206df8bae1dSRodney W. Grimes */ 207df8bae1dSRodney W. Grimes udp_in.sin_port = uh->uh_sport; 208df8bae1dSRodney W. Grimes udp_in.sin_addr = ip->ip_src; 209df8bae1dSRodney W. Grimes m->m_len -= sizeof (struct udpiphdr); 210df8bae1dSRodney W. Grimes m->m_data += sizeof (struct udpiphdr); 211df8bae1dSRodney W. Grimes /* 212df8bae1dSRodney W. Grimes * Locate pcb(s) for datagram. 213df8bae1dSRodney W. Grimes * (Algorithm copied from raw_intr().) 214df8bae1dSRodney W. Grimes */ 215df8bae1dSRodney W. Grimes last = NULL; 21615bd2b43SDavid Greenman for (inp = udb.lh_first; inp != NULL; inp = inp->inp_list.le_next) { 217df8bae1dSRodney W. Grimes if (inp->inp_lport != uh->uh_dport) 218df8bae1dSRodney W. Grimes continue; 219df8bae1dSRodney W. Grimes if (inp->inp_laddr.s_addr != INADDR_ANY) { 220df8bae1dSRodney W. Grimes if (inp->inp_laddr.s_addr != 221df8bae1dSRodney W. Grimes ip->ip_dst.s_addr) 222df8bae1dSRodney W. Grimes continue; 223df8bae1dSRodney W. Grimes } 224df8bae1dSRodney W. Grimes if (inp->inp_faddr.s_addr != INADDR_ANY) { 225df8bae1dSRodney W. Grimes if (inp->inp_faddr.s_addr != 226df8bae1dSRodney W. Grimes ip->ip_src.s_addr || 227df8bae1dSRodney W. Grimes inp->inp_fport != uh->uh_sport) 228df8bae1dSRodney W. Grimes continue; 229df8bae1dSRodney W. Grimes } 230df8bae1dSRodney W. Grimes 231df8bae1dSRodney W. Grimes if (last != NULL) { 232df8bae1dSRodney W. Grimes struct mbuf *n; 233df8bae1dSRodney W. Grimes 234df8bae1dSRodney W. Grimes if ((n = m_copy(m, 0, M_COPYALL)) != NULL) { 23582c23ebaSBill Fenner if (last->inp_flags & INP_CONTROLOPTS 23682c23ebaSBill Fenner || last->inp_socket->so_options & SO_TIMESTAMP) 23782c23ebaSBill Fenner ip_savecontrol(last, &opts, ip, n); 23882c23ebaSBill Fenner if (sbappendaddr(&last->inp_socket->so_rcv, 239df8bae1dSRodney W. Grimes (struct sockaddr *)&udp_in, 24082c23ebaSBill Fenner n, opts) == 0) { 241df8bae1dSRodney W. Grimes m_freem(n); 24282c23ebaSBill Fenner if (opts) 24382c23ebaSBill Fenner m_freem(opts); 244df8bae1dSRodney W. Grimes udpstat.udps_fullsock++; 245df8bae1dSRodney W. Grimes } else 24682c23ebaSBill Fenner sorwakeup(last->inp_socket); 24782c23ebaSBill Fenner opts = 0; 248df8bae1dSRodney W. Grimes } 249df8bae1dSRodney W. Grimes } 25082c23ebaSBill Fenner last = inp; 251df8bae1dSRodney W. Grimes /* 252df8bae1dSRodney W. Grimes * Don't look for additional matches if this one does 253df8bae1dSRodney W. Grimes * not have either the SO_REUSEPORT or SO_REUSEADDR 254df8bae1dSRodney W. Grimes * socket options set. This heuristic avoids searching 255df8bae1dSRodney W. Grimes * through all pcbs in the common case of a non-shared 256df8bae1dSRodney W. Grimes * port. It * assumes that an application will never 257df8bae1dSRodney W. Grimes * clear these options after setting them. 258df8bae1dSRodney W. Grimes */ 259694ad0a9SSteve Price if ((last->inp_socket->so_options&(SO_REUSEPORT|SO_REUSEADDR)) == 0) 260df8bae1dSRodney W. Grimes break; 261df8bae1dSRodney W. Grimes } 262df8bae1dSRodney W. Grimes 263df8bae1dSRodney W. Grimes if (last == NULL) { 264df8bae1dSRodney W. Grimes /* 265df8bae1dSRodney W. Grimes * No matching pcb found; discard datagram. 266df8bae1dSRodney W. Grimes * (No need to send an ICMP Port Unreachable 267df8bae1dSRodney W. Grimes * for a broadcast or multicast datgram.) 268df8bae1dSRodney W. Grimes */ 269df8bae1dSRodney W. Grimes udpstat.udps_noportbcast++; 270df8bae1dSRodney W. Grimes goto bad; 271df8bae1dSRodney W. Grimes } 27282c23ebaSBill Fenner if (last->inp_flags & INP_CONTROLOPTS 27382c23ebaSBill Fenner || last->inp_socket->so_options & SO_TIMESTAMP) 27482c23ebaSBill Fenner ip_savecontrol(last, &opts, ip, m); 27582c23ebaSBill Fenner if (sbappendaddr(&last->inp_socket->so_rcv, 27682c23ebaSBill Fenner (struct sockaddr *)&udp_in, 27782c23ebaSBill Fenner m, opts) == 0) { 278df8bae1dSRodney W. Grimes udpstat.udps_fullsock++; 279df8bae1dSRodney W. Grimes goto bad; 280df8bae1dSRodney W. Grimes } 28182c23ebaSBill Fenner sorwakeup(last->inp_socket); 282df8bae1dSRodney W. Grimes return; 283df8bae1dSRodney W. Grimes } 284df8bae1dSRodney W. Grimes /* 2856d6a026bSDavid Greenman * Locate pcb for datagram. 286df8bae1dSRodney W. Grimes */ 287c3229e05SDavid Greenman inp = in_pcblookup_hash(&udbinfo, ip->ip_src, uh->uh_sport, 2886d6a026bSDavid Greenman ip->ip_dst, uh->uh_dport, 1); 28915bd2b43SDavid Greenman if (inp == NULL) { 29075cfc95fSAndrey A. Chernov if (log_in_vain) { 291df5c0b8aSBill Fenner char buf[4*sizeof "123"]; 29275cfc95fSAndrey A. Chernov 29375cfc95fSAndrey A. Chernov strcpy(buf, inet_ntoa(ip->ip_dst)); 294592071e8SBruce Evans log(LOG_INFO, 295592071e8SBruce Evans "Connection attempt to UDP %s:%d from %s:%d\n", 296592071e8SBruce Evans buf, ntohs(uh->uh_dport), inet_ntoa(ip->ip_src), 297592071e8SBruce Evans ntohs(uh->uh_sport)); 29875cfc95fSAndrey A. Chernov } 299df8bae1dSRodney W. Grimes udpstat.udps_noport++; 300df8bae1dSRodney W. Grimes if (m->m_flags & (M_BCAST | M_MCAST)) { 301df8bae1dSRodney W. Grimes udpstat.udps_noportbcast++; 302df8bae1dSRodney W. Grimes goto bad; 303df8bae1dSRodney W. Grimes } 304df8bae1dSRodney W. Grimes *ip = save_ip; 30551508de1SMatthew Dillon #ifdef ICMP_BANDLIM 30651508de1SMatthew Dillon if (badport_bandlim(0) < 0) 30751508de1SMatthew Dillon goto bad; 30851508de1SMatthew Dillon #endif 30916f7f31fSGeoff Rehmet if(!blackhole) 310df8bae1dSRodney W. Grimes icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0); 311df8bae1dSRodney W. Grimes return; 312df8bae1dSRodney W. Grimes } 313df8bae1dSRodney W. Grimes 314df8bae1dSRodney W. Grimes /* 315df8bae1dSRodney W. Grimes * Construct sockaddr format source address. 316df8bae1dSRodney W. Grimes * Stuff source address and datagram in user buffer. 317df8bae1dSRodney W. Grimes */ 318df8bae1dSRodney W. Grimes udp_in.sin_port = uh->uh_sport; 319df8bae1dSRodney W. Grimes udp_in.sin_addr = ip->ip_src; 32082dab6ceSGarrett Wollman if (inp->inp_flags & INP_CONTROLOPTS 32182c23ebaSBill Fenner || inp->inp_socket->so_options & SO_TIMESTAMP) 32282c23ebaSBill Fenner ip_savecontrol(inp, &opts, ip, m); 323df8bae1dSRodney W. Grimes iphlen += sizeof(struct udphdr); 324df8bae1dSRodney W. Grimes m->m_len -= iphlen; 325df8bae1dSRodney W. Grimes m->m_pkthdr.len -= iphlen; 326df8bae1dSRodney W. Grimes m->m_data += iphlen; 327df8bae1dSRodney W. Grimes if (sbappendaddr(&inp->inp_socket->so_rcv, (struct sockaddr *)&udp_in, 328df8bae1dSRodney W. Grimes m, opts) == 0) { 329df8bae1dSRodney W. Grimes udpstat.udps_fullsock++; 330df8bae1dSRodney W. Grimes goto bad; 331df8bae1dSRodney W. Grimes } 332df8bae1dSRodney W. Grimes sorwakeup(inp->inp_socket); 333df8bae1dSRodney W. Grimes return; 334df8bae1dSRodney W. Grimes bad: 335df8bae1dSRodney W. Grimes m_freem(m); 336df8bae1dSRodney W. Grimes if (opts) 337df8bae1dSRodney W. Grimes m_freem(opts); 338df8bae1dSRodney W. Grimes } 339df8bae1dSRodney W. Grimes 340df8bae1dSRodney W. Grimes /* 341df8bae1dSRodney W. Grimes * Notify a udp user of an asynchronous error; 342df8bae1dSRodney W. Grimes * just wake up so that he can collect error status. 343df8bae1dSRodney W. Grimes */ 344df8bae1dSRodney W. Grimes static void 345df8bae1dSRodney W. Grimes udp_notify(inp, errno) 346df8bae1dSRodney W. Grimes register struct inpcb *inp; 347df8bae1dSRodney W. Grimes int errno; 348df8bae1dSRodney W. Grimes { 349df8bae1dSRodney W. Grimes inp->inp_socket->so_error = errno; 350df8bae1dSRodney W. Grimes sorwakeup(inp->inp_socket); 351df8bae1dSRodney W. Grimes sowwakeup(inp->inp_socket); 352df8bae1dSRodney W. Grimes } 353df8bae1dSRodney W. Grimes 354df8bae1dSRodney W. Grimes void 355b62d102cSBruce Evans udp_ctlinput(cmd, sa, vip) 356df8bae1dSRodney W. Grimes int cmd; 357df8bae1dSRodney W. Grimes struct sockaddr *sa; 358b62d102cSBruce Evans void *vip; 359df8bae1dSRodney W. Grimes { 360b62d102cSBruce Evans register struct ip *ip = vip; 361df8bae1dSRodney W. Grimes register struct udphdr *uh; 362df8bae1dSRodney W. Grimes 363df8bae1dSRodney W. Grimes if (!PRC_IS_REDIRECT(cmd) && 364df8bae1dSRodney W. Grimes ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0)) 365df8bae1dSRodney W. Grimes return; 366df8bae1dSRodney W. Grimes if (ip) { 367df8bae1dSRodney W. Grimes uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2)); 368df8bae1dSRodney W. Grimes in_pcbnotify(&udb, sa, uh->uh_dport, ip->ip_src, uh->uh_sport, 369df8bae1dSRodney W. Grimes cmd, udp_notify); 370df8bae1dSRodney W. Grimes } else 371df8bae1dSRodney W. Grimes in_pcbnotify(&udb, sa, 0, zeroin_addr, 0, cmd, udp_notify); 372df8bae1dSRodney W. Grimes } 373df8bae1dSRodney W. Grimes 3740312fbe9SPoul-Henning Kamp static int 37598271db4SGarrett Wollman udp_pcblist SYSCTL_HANDLER_ARGS 37698271db4SGarrett Wollman { 37798271db4SGarrett Wollman int error, i, n, s; 37898271db4SGarrett Wollman struct inpcb *inp, **inp_list; 37998271db4SGarrett Wollman inp_gen_t gencnt; 38098271db4SGarrett Wollman struct xinpgen xig; 38198271db4SGarrett Wollman 38298271db4SGarrett Wollman /* 38398271db4SGarrett Wollman * The process of preparing the TCB list is too time-consuming and 38498271db4SGarrett Wollman * resource-intensive to repeat twice on every request. 38598271db4SGarrett Wollman */ 38698271db4SGarrett Wollman if (req->oldptr == 0) { 38798271db4SGarrett Wollman n = udbinfo.ipi_count; 38898271db4SGarrett Wollman req->oldidx = 2 * (sizeof xig) 38998271db4SGarrett Wollman + (n + n/8) * sizeof(struct xinpcb); 39098271db4SGarrett Wollman return 0; 39198271db4SGarrett Wollman } 39298271db4SGarrett Wollman 39398271db4SGarrett Wollman if (req->newptr != 0) 39498271db4SGarrett Wollman return EPERM; 39598271db4SGarrett Wollman 39698271db4SGarrett Wollman /* 39798271db4SGarrett Wollman * OK, now we're committed to doing something. 39898271db4SGarrett Wollman */ 39998271db4SGarrett Wollman s = splnet(); 40098271db4SGarrett Wollman gencnt = udbinfo.ipi_gencnt; 40198271db4SGarrett Wollman n = udbinfo.ipi_count; 40298271db4SGarrett Wollman splx(s); 40398271db4SGarrett Wollman 40498271db4SGarrett Wollman xig.xig_len = sizeof xig; 40598271db4SGarrett Wollman xig.xig_count = n; 40698271db4SGarrett Wollman xig.xig_gen = gencnt; 40798271db4SGarrett Wollman xig.xig_sogen = so_gencnt; 40898271db4SGarrett Wollman error = SYSCTL_OUT(req, &xig, sizeof xig); 40998271db4SGarrett Wollman if (error) 41098271db4SGarrett Wollman return error; 41198271db4SGarrett Wollman 41298271db4SGarrett Wollman inp_list = malloc(n * sizeof *inp_list, M_TEMP, M_WAITOK); 41398271db4SGarrett Wollman if (inp_list == 0) 41498271db4SGarrett Wollman return ENOMEM; 41598271db4SGarrett Wollman 41698271db4SGarrett Wollman s = splnet(); 41798271db4SGarrett Wollman for (inp = udbinfo.listhead->lh_first, i = 0; inp && i < n; 41898271db4SGarrett Wollman inp = inp->inp_list.le_next) { 41975c13541SPoul-Henning Kamp if (inp->inp_gencnt <= gencnt && !prison_xinpcb(req->p, inp)) 42098271db4SGarrett Wollman inp_list[i++] = inp; 42198271db4SGarrett Wollman } 42298271db4SGarrett Wollman splx(s); 42398271db4SGarrett Wollman n = i; 42498271db4SGarrett Wollman 42598271db4SGarrett Wollman error = 0; 42698271db4SGarrett Wollman for (i = 0; i < n; i++) { 42798271db4SGarrett Wollman inp = inp_list[i]; 42898271db4SGarrett Wollman if (inp->inp_gencnt <= gencnt) { 42998271db4SGarrett Wollman struct xinpcb xi; 43098271db4SGarrett Wollman xi.xi_len = sizeof xi; 43198271db4SGarrett Wollman /* XXX should avoid extra copy */ 43298271db4SGarrett Wollman bcopy(inp, &xi.xi_inp, sizeof *inp); 43398271db4SGarrett Wollman if (inp->inp_socket) 43498271db4SGarrett Wollman sotoxsocket(inp->inp_socket, &xi.xi_socket); 43598271db4SGarrett Wollman error = SYSCTL_OUT(req, &xi, sizeof xi); 43698271db4SGarrett Wollman } 43798271db4SGarrett Wollman } 43898271db4SGarrett Wollman if (!error) { 43998271db4SGarrett Wollman /* 44098271db4SGarrett Wollman * Give the user an updated idea of our state. 44198271db4SGarrett Wollman * If the generation differs from what we told 44298271db4SGarrett Wollman * her before, she knows that something happened 44398271db4SGarrett Wollman * while we were processing this request, and it 44498271db4SGarrett Wollman * might be necessary to retry. 44598271db4SGarrett Wollman */ 44698271db4SGarrett Wollman s = splnet(); 44798271db4SGarrett Wollman xig.xig_gen = udbinfo.ipi_gencnt; 44898271db4SGarrett Wollman xig.xig_sogen = so_gencnt; 44998271db4SGarrett Wollman xig.xig_count = udbinfo.ipi_count; 45098271db4SGarrett Wollman splx(s); 45198271db4SGarrett Wollman error = SYSCTL_OUT(req, &xig, sizeof xig); 45298271db4SGarrett Wollman } 45398271db4SGarrett Wollman free(inp_list, M_TEMP); 45498271db4SGarrett Wollman return error; 45598271db4SGarrett Wollman } 45698271db4SGarrett Wollman 45798271db4SGarrett Wollman SYSCTL_PROC(_net_inet_udp, UDPCTL_PCBLIST, pcblist, CTLFLAG_RD, 0, 0, 45898271db4SGarrett Wollman udp_pcblist, "S,xinpcb", "List of active UDP sockets"); 45998271db4SGarrett Wollman 46098271db4SGarrett Wollman static int 461490d50b6SBrian Feldman udp_getcred SYSCTL_HANDLER_ARGS 462490d50b6SBrian Feldman { 463490d50b6SBrian Feldman struct sockaddr_in addrs[2]; 464490d50b6SBrian Feldman struct inpcb *inp; 465490d50b6SBrian Feldman int error, s; 466490d50b6SBrian Feldman 467490d50b6SBrian Feldman error = suser(req->p); 468490d50b6SBrian Feldman if (error) 469490d50b6SBrian Feldman return (error); 470490d50b6SBrian Feldman error = SYSCTL_IN(req, addrs, sizeof(addrs)); 471490d50b6SBrian Feldman if (error) 472490d50b6SBrian Feldman return (error); 473490d50b6SBrian Feldman s = splnet(); 474490d50b6SBrian Feldman inp = in_pcblookup_hash(&udbinfo, addrs[1].sin_addr, addrs[1].sin_port, 475490d50b6SBrian Feldman addrs[0].sin_addr, addrs[0].sin_port, 1); 476490d50b6SBrian Feldman if (inp == NULL || inp->inp_socket == NULL || 477490d50b6SBrian Feldman inp->inp_socket->so_cred == NULL) { 478490d50b6SBrian Feldman error = ENOENT; 479490d50b6SBrian Feldman goto out; 480490d50b6SBrian Feldman } 481490d50b6SBrian Feldman error = SYSCTL_OUT(req, inp->inp_socket->so_cred->pc_ucred, 482490d50b6SBrian Feldman sizeof(struct ucred)); 483490d50b6SBrian Feldman out: 484490d50b6SBrian Feldman splx(s); 485490d50b6SBrian Feldman return (error); 486490d50b6SBrian Feldman } 487490d50b6SBrian Feldman 488490d50b6SBrian Feldman SYSCTL_PROC(_net_inet_udp, OID_AUTO, getcred, CTLTYPE_OPAQUE|CTLFLAG_RW, 489490d50b6SBrian Feldman 0, 0, udp_getcred, "S,ucred", "Get the ucred of a UDP connection"); 490490d50b6SBrian Feldman 491490d50b6SBrian Feldman static int 492a29f300eSGarrett Wollman udp_output(inp, m, addr, control, p) 493df8bae1dSRodney W. Grimes register struct inpcb *inp; 494df8bae1dSRodney W. Grimes register struct mbuf *m; 49557bf258eSGarrett Wollman struct sockaddr *addr; 49657bf258eSGarrett Wollman struct mbuf *control; 497a29f300eSGarrett Wollman struct proc *p; 498df8bae1dSRodney W. Grimes { 499df8bae1dSRodney W. Grimes register struct udpiphdr *ui; 500df8bae1dSRodney W. Grimes register int len = m->m_pkthdr.len; 501df8bae1dSRodney W. Grimes struct in_addr laddr; 50275c13541SPoul-Henning Kamp struct sockaddr_in *sin; 50326f9a767SRodney W. Grimes int s = 0, error = 0; 504df8bae1dSRodney W. Grimes 505df8bae1dSRodney W. Grimes if (control) 506df8bae1dSRodney W. Grimes m_freem(control); /* XXX */ 507df8bae1dSRodney W. Grimes 508430d30d8SBill Fenner if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) { 509430d30d8SBill Fenner error = EMSGSIZE; 510430d30d8SBill Fenner goto release; 511430d30d8SBill Fenner } 512430d30d8SBill Fenner 513df8bae1dSRodney W. Grimes if (addr) { 51475c13541SPoul-Henning Kamp sin = (struct sockaddr_in *)addr; 51575c13541SPoul-Henning Kamp prison_remote_ip(p, 0, &sin->sin_addr.s_addr); 516df8bae1dSRodney W. Grimes laddr = inp->inp_laddr; 517df8bae1dSRodney W. Grimes if (inp->inp_faddr.s_addr != INADDR_ANY) { 518df8bae1dSRodney W. Grimes error = EISCONN; 519df8bae1dSRodney W. Grimes goto release; 520df8bae1dSRodney W. Grimes } 521df8bae1dSRodney W. Grimes /* 522df8bae1dSRodney W. Grimes * Must block input while temporarily connected. 523df8bae1dSRodney W. Grimes */ 524df8bae1dSRodney W. Grimes s = splnet(); 525a29f300eSGarrett Wollman error = in_pcbconnect(inp, addr, p); 526df8bae1dSRodney W. Grimes if (error) { 527df8bae1dSRodney W. Grimes splx(s); 528df8bae1dSRodney W. Grimes goto release; 529df8bae1dSRodney W. Grimes } 530df8bae1dSRodney W. Grimes } else { 531df8bae1dSRodney W. Grimes if (inp->inp_faddr.s_addr == INADDR_ANY) { 532df8bae1dSRodney W. Grimes error = ENOTCONN; 533df8bae1dSRodney W. Grimes goto release; 534df8bae1dSRodney W. Grimes } 535df8bae1dSRodney W. Grimes } 536df8bae1dSRodney W. Grimes /* 537df8bae1dSRodney W. Grimes * Calculate data length and get a mbuf 538df8bae1dSRodney W. Grimes * for UDP and IP headers. 539df8bae1dSRodney W. Grimes */ 540df8bae1dSRodney W. Grimes M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT); 541df8bae1dSRodney W. Grimes if (m == 0) { 542df8bae1dSRodney W. Grimes error = ENOBUFS; 5431c09f774SGarrett Wollman if (addr) 5441c09f774SGarrett Wollman splx(s); 545df8bae1dSRodney W. Grimes goto release; 546df8bae1dSRodney W. Grimes } 547df8bae1dSRodney W. Grimes 548df8bae1dSRodney W. Grimes /* 549df8bae1dSRodney W. Grimes * Fill in mbuf with extended UDP header 550df8bae1dSRodney W. Grimes * and addresses and length put into network format. 551df8bae1dSRodney W. Grimes */ 552df8bae1dSRodney W. Grimes ui = mtod(m, struct udpiphdr *); 5536effc713SDoug Rabson bzero(ui->ui_x1, sizeof(ui->ui_x1)); 554df8bae1dSRodney W. Grimes ui->ui_pr = IPPROTO_UDP; 555df8bae1dSRodney W. Grimes ui->ui_len = htons((u_short)len + sizeof (struct udphdr)); 556df8bae1dSRodney W. Grimes ui->ui_src = inp->inp_laddr; 557df8bae1dSRodney W. Grimes ui->ui_dst = inp->inp_faddr; 558df8bae1dSRodney W. Grimes ui->ui_sport = inp->inp_lport; 559df8bae1dSRodney W. Grimes ui->ui_dport = inp->inp_fport; 560df8bae1dSRodney W. Grimes ui->ui_ulen = ui->ui_len; 561df8bae1dSRodney W. Grimes 562df8bae1dSRodney W. Grimes /* 563df8bae1dSRodney W. Grimes * Stuff checksum and output datagram. 564df8bae1dSRodney W. Grimes */ 565df8bae1dSRodney W. Grimes ui->ui_sum = 0; 566df8bae1dSRodney W. Grimes if (udpcksum) { 567df8bae1dSRodney W. Grimes if ((ui->ui_sum = in_cksum(m, sizeof (struct udpiphdr) + len)) == 0) 568df8bae1dSRodney W. Grimes ui->ui_sum = 0xffff; 569df8bae1dSRodney W. Grimes } 570df8bae1dSRodney W. Grimes ((struct ip *)ui)->ip_len = sizeof (struct udpiphdr) + len; 571ca98b82cSDavid Greenman ((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl; /* XXX */ 572ca98b82cSDavid Greenman ((struct ip *)ui)->ip_tos = inp->inp_ip_tos; /* XXX */ 573df8bae1dSRodney W. Grimes udpstat.udps_opackets++; 574df8bae1dSRodney W. Grimes error = ip_output(m, inp->inp_options, &inp->inp_route, 575df8bae1dSRodney W. Grimes inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST), 576df8bae1dSRodney W. Grimes inp->inp_moptions); 577df8bae1dSRodney W. Grimes 578df8bae1dSRodney W. Grimes if (addr) { 579df8bae1dSRodney W. Grimes in_pcbdisconnect(inp); 58057bf258eSGarrett Wollman inp->inp_laddr = laddr; /* XXX rehash? */ 581df8bae1dSRodney W. Grimes splx(s); 582df8bae1dSRodney W. Grimes } 583df8bae1dSRodney W. Grimes return (error); 584df8bae1dSRodney W. Grimes 585df8bae1dSRodney W. Grimes release: 586df8bae1dSRodney W. Grimes m_freem(m); 587df8bae1dSRodney W. Grimes return (error); 588df8bae1dSRodney W. Grimes } 589df8bae1dSRodney W. Grimes 5900312fbe9SPoul-Henning Kamp static u_long udp_sendspace = 9216; /* really max datagram size */ 591df8bae1dSRodney W. Grimes /* 40 1K datagrams */ 5920312fbe9SPoul-Henning Kamp SYSCTL_INT(_net_inet_udp, UDPCTL_MAXDGRAM, maxdgram, CTLFLAG_RW, 5933d177f46SBill Fumerola &udp_sendspace, 0, "Maximum outgoing UDP datagram size"); 5940312fbe9SPoul-Henning Kamp 5950312fbe9SPoul-Henning Kamp static u_long udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in)); 5960312fbe9SPoul-Henning Kamp SYSCTL_INT(_net_inet_udp, UDPCTL_RECVSPACE, recvspace, CTLFLAG_RW, 5973d177f46SBill Fumerola &udp_recvspace, 0, "Maximum incoming UDP datagram size"); 598df8bae1dSRodney W. Grimes 599d0390e05SGarrett Wollman static int 600d0390e05SGarrett Wollman udp_abort(struct socket *so) 601df8bae1dSRodney W. Grimes { 602d0390e05SGarrett Wollman struct inpcb *inp; 603df8bae1dSRodney W. Grimes int s; 604df8bae1dSRodney W. Grimes 605d0390e05SGarrett Wollman inp = sotoinpcb(so); 606d0390e05SGarrett Wollman if (inp == 0) 607d0390e05SGarrett Wollman return EINVAL; /* ??? possible? panic instead? */ 608d0390e05SGarrett Wollman soisdisconnected(so); 609d0390e05SGarrett Wollman s = splnet(); 610d0390e05SGarrett Wollman in_pcbdetach(inp); 611d0390e05SGarrett Wollman splx(s); 612d0390e05SGarrett Wollman return 0; 613df8bae1dSRodney W. Grimes } 614df8bae1dSRodney W. Grimes 615d0390e05SGarrett Wollman static int 616a29f300eSGarrett Wollman udp_attach(struct socket *so, int proto, struct proc *p) 617d0390e05SGarrett Wollman { 618d0390e05SGarrett Wollman struct inpcb *inp; 619d0390e05SGarrett Wollman int s, error; 620d0390e05SGarrett Wollman 621d0390e05SGarrett Wollman inp = sotoinpcb(so); 622d0390e05SGarrett Wollman if (inp != 0) 623d0390e05SGarrett Wollman return EINVAL; 624d0390e05SGarrett Wollman 625df8bae1dSRodney W. Grimes s = splnet(); 626a29f300eSGarrett Wollman error = in_pcballoc(so, &udbinfo, p); 627df8bae1dSRodney W. Grimes splx(s); 628df8bae1dSRodney W. Grimes if (error) 629d0390e05SGarrett Wollman return error; 630df8bae1dSRodney W. Grimes error = soreserve(so, udp_sendspace, udp_recvspace); 631df8bae1dSRodney W. Grimes if (error) 632d0390e05SGarrett Wollman return error; 633ca98b82cSDavid Greenman ((struct inpcb *) so->so_pcb)->inp_ip_ttl = ip_defttl; 634d0390e05SGarrett Wollman return 0; 635df8bae1dSRodney W. Grimes } 636d0390e05SGarrett Wollman 637d0390e05SGarrett Wollman static int 63857bf258eSGarrett Wollman udp_bind(struct socket *so, struct sockaddr *nam, struct proc *p) 639d0390e05SGarrett Wollman { 640d0390e05SGarrett Wollman struct inpcb *inp; 641d0390e05SGarrett Wollman int s, error; 642d0390e05SGarrett Wollman 643d0390e05SGarrett Wollman inp = sotoinpcb(so); 644d0390e05SGarrett Wollman if (inp == 0) 645d0390e05SGarrett Wollman return EINVAL; 646df8bae1dSRodney W. Grimes s = splnet(); 647a29f300eSGarrett Wollman error = in_pcbbind(inp, nam, p); 648d0390e05SGarrett Wollman splx(s); 649d0390e05SGarrett Wollman return error; 650d0390e05SGarrett Wollman } 651d0390e05SGarrett Wollman 652d0390e05SGarrett Wollman static int 65357bf258eSGarrett Wollman udp_connect(struct socket *so, struct sockaddr *nam, struct proc *p) 654d0390e05SGarrett Wollman { 655d0390e05SGarrett Wollman struct inpcb *inp; 656d0390e05SGarrett Wollman int s, error; 65775c13541SPoul-Henning Kamp struct sockaddr_in *sin; 658d0390e05SGarrett Wollman 659d0390e05SGarrett Wollman inp = sotoinpcb(so); 660d0390e05SGarrett Wollman if (inp == 0) 661d0390e05SGarrett Wollman return EINVAL; 662d0390e05SGarrett Wollman if (inp->inp_faddr.s_addr != INADDR_ANY) 663d0390e05SGarrett Wollman return EISCONN; 664d0390e05SGarrett Wollman s = splnet(); 66575c13541SPoul-Henning Kamp sin = (struct sockaddr_in *)nam; 66675c13541SPoul-Henning Kamp prison_remote_ip(p, 0, &sin->sin_addr.s_addr); 667a29f300eSGarrett Wollman error = in_pcbconnect(inp, nam, p); 668df8bae1dSRodney W. Grimes splx(s); 669df8bae1dSRodney W. Grimes if (error == 0) 670df8bae1dSRodney W. Grimes soisconnected(so); 671d0390e05SGarrett Wollman return error; 672df8bae1dSRodney W. Grimes } 673d0390e05SGarrett Wollman 674d0390e05SGarrett Wollman static int 675d0390e05SGarrett Wollman udp_detach(struct socket *so) 676d0390e05SGarrett Wollman { 677d0390e05SGarrett Wollman struct inpcb *inp; 678d0390e05SGarrett Wollman int s; 679d0390e05SGarrett Wollman 680d0390e05SGarrett Wollman inp = sotoinpcb(so); 681d0390e05SGarrett Wollman if (inp == 0) 682d0390e05SGarrett Wollman return EINVAL; 683d0390e05SGarrett Wollman s = splnet(); 684d0390e05SGarrett Wollman in_pcbdetach(inp); 685d0390e05SGarrett Wollman splx(s); 686d0390e05SGarrett Wollman return 0; 687d0390e05SGarrett Wollman } 688d0390e05SGarrett Wollman 689d0390e05SGarrett Wollman static int 690d0390e05SGarrett Wollman udp_disconnect(struct socket *so) 691d0390e05SGarrett Wollman { 692d0390e05SGarrett Wollman struct inpcb *inp; 693d0390e05SGarrett Wollman int s; 694d0390e05SGarrett Wollman 695d0390e05SGarrett Wollman inp = sotoinpcb(so); 696d0390e05SGarrett Wollman if (inp == 0) 697d0390e05SGarrett Wollman return EINVAL; 698d0390e05SGarrett Wollman if (inp->inp_faddr.s_addr == INADDR_ANY) 699d0390e05SGarrett Wollman return ENOTCONN; 700d0390e05SGarrett Wollman 701df8bae1dSRodney W. Grimes s = splnet(); 702df8bae1dSRodney W. Grimes in_pcbdisconnect(inp); 703df8bae1dSRodney W. Grimes inp->inp_laddr.s_addr = INADDR_ANY; 704df8bae1dSRodney W. Grimes splx(s); 705df8bae1dSRodney W. Grimes so->so_state &= ~SS_ISCONNECTED; /* XXX */ 706d0390e05SGarrett Wollman return 0; 707df8bae1dSRodney W. Grimes } 708df8bae1dSRodney W. Grimes 709d0390e05SGarrett Wollman static int 71057bf258eSGarrett Wollman udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, 711a29f300eSGarrett Wollman struct mbuf *control, struct proc *p) 712d0390e05SGarrett Wollman { 713d0390e05SGarrett Wollman struct inpcb *inp; 714d0390e05SGarrett Wollman 715d0390e05SGarrett Wollman inp = sotoinpcb(so); 716d0390e05SGarrett Wollman if (inp == 0) { 717d0390e05SGarrett Wollman m_freem(m); 718d0390e05SGarrett Wollman return EINVAL; 719d0390e05SGarrett Wollman } 720a29f300eSGarrett Wollman return udp_output(inp, m, addr, control, p); 721d0390e05SGarrett Wollman } 722d0390e05SGarrett Wollman 723d0390e05SGarrett Wollman static int 724d0390e05SGarrett Wollman udp_shutdown(struct socket *so) 725d0390e05SGarrett Wollman { 726d0390e05SGarrett Wollman struct inpcb *inp; 727d0390e05SGarrett Wollman 728d0390e05SGarrett Wollman inp = sotoinpcb(so); 729d0390e05SGarrett Wollman if (inp == 0) 730d0390e05SGarrett Wollman return EINVAL; 731d0390e05SGarrett Wollman socantsendmore(so); 732d0390e05SGarrett Wollman return 0; 733d0390e05SGarrett Wollman } 734d0390e05SGarrett Wollman 735d0390e05SGarrett Wollman struct pr_usrreqs udp_usrreqs = { 736117bcae7SGarrett Wollman udp_abort, pru_accept_notsupp, udp_attach, udp_bind, udp_connect, 737117bcae7SGarrett Wollman pru_connect2_notsupp, in_control, udp_detach, udp_disconnect, 738117bcae7SGarrett Wollman pru_listen_notsupp, in_setpeeraddr, pru_rcvd_notsupp, 739117bcae7SGarrett Wollman pru_rcvoob_notsupp, udp_send, pru_sense_null, udp_shutdown, 740f8f6cbbaSPeter Wemm in_setsockaddr, sosend, soreceive, sopoll 741d0390e05SGarrett Wollman }; 74251508de1SMatthew Dillon 743