2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
5 * The Regents of the University of California.
6 * Copyright (c) 2008 Robert N. M. Watson
7 * Copyright (c) 2010-2011 Juniper Networks, Inc.
8 * Copyright (c) 2014 Kevin Lo
11 * Portions of this software were developed by Robert N. M. Watson under
12 * contract to Juniper Networks, Inc.
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 * 3. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
45 #include "opt_inet6.h"
46 #include "opt_ipsec.h"
49 #include <sys/param.h>
50 #include <sys/domain.h>
51 #include <sys/eventhandler.h>
53 #include <sys/kernel.h>
55 #include <sys/malloc.h>
59 #include <sys/protosw.h>
61 #include <sys/signalvar.h>
62 #include <sys/socket.h>
63 #include <sys/socketvar.h>
65 #include <sys/sysctl.h>
66 #include <sys/syslog.h>
67 #include <sys/systm.h>
72 #include <net/if_var.h>
73 #include <net/route.h>
74 #include <net/route/nhop.h>
75 #include <net/rss_config.h>
77 #include <netinet/in.h>
78 #include <netinet/in_kdtrace.h>
79 #include <netinet/in_pcb.h>
80 #include <netinet/in_systm.h>
81 #include <netinet/in_var.h>
82 #include <netinet/ip.h>
84 #include <netinet/ip6.h>
86 #include <netinet/ip_icmp.h>
87 #include <netinet/icmp_var.h>
88 #include <netinet/ip_var.h>
89 #include <netinet/ip_options.h>
91 #include <netinet6/ip6_var.h>
93 #include <netinet/udp.h>
94 #include <netinet/udp_var.h>
95 #include <netinet/udplite.h>
96 #include <netinet/in_rss.h>
98 #include <netipsec/ipsec_support.h>
100 #include <machine/in_cksum.h>
102 #include <security/mac/mac_framework.h>
105 * UDP and UDP-Lite protocols implementation.
106 * Per RFC 768, August, 1980.
107 * Per RFC 3828, July, 2004.
111 * BSD 4.2 defaulted the udp checksum to be off. Turning off udp checksums
112 * removes the only data integrity mechanism for packets and malformed
113 * packets that would otherwise be discarded due to bad checksums, and may
114 * cause problems (especially for NFS data blocks).
116 VNET_DEFINE(int, udp_cksum) = 1;
117 SYSCTL_INT(_net_inet_udp, UDPCTL_CHECKSUM, checksum, CTLFLAG_VNET | CTLFLAG_RW,
118 &VNET_NAME(udp_cksum), 0, "compute udp checksum");
120 VNET_DEFINE(int, udp_log_in_vain) = 0;
121 SYSCTL_INT(_net_inet_udp, OID_AUTO, log_in_vain, CTLFLAG_VNET | CTLFLAG_RW,
122 &VNET_NAME(udp_log_in_vain), 0, "Log all incoming UDP packets");
124 VNET_DEFINE(int, udp_blackhole) = 0;
125 SYSCTL_INT(_net_inet_udp, OID_AUTO, blackhole, CTLFLAG_VNET | CTLFLAG_RW,
126 &VNET_NAME(udp_blackhole), 0,
127 "Do not send port unreachables for refused connects");
129 u_long udp_sendspace = 9216; /* really max datagram size */
130 SYSCTL_ULONG(_net_inet_udp, UDPCTL_MAXDGRAM, maxdgram, CTLFLAG_RW,
131 &udp_sendspace, 0, "Maximum outgoing UDP datagram size");
133 u_long udp_recvspace = 40 * (1024 +
135 sizeof(struct sockaddr_in6)
137 sizeof(struct sockaddr_in)
139 ); /* 40 1K datagrams */
141 SYSCTL_ULONG(_net_inet_udp, UDPCTL_RECVSPACE, recvspace, CTLFLAG_RW,
142 &udp_recvspace, 0, "Maximum space for incoming UDP datagrams");
144 VNET_DEFINE(struct inpcbhead, udb); /* from udp_var.h */
145 VNET_DEFINE(struct inpcbinfo, udbinfo);
146 VNET_DEFINE(struct inpcbhead, ulitecb);
147 VNET_DEFINE(struct inpcbinfo, ulitecbinfo);
148 VNET_DEFINE_STATIC(uma_zone_t, udpcb_zone);
149 #define V_udpcb_zone VNET(udpcb_zone)
152 #define UDBHASHSIZE 128
155 VNET_PCPUSTAT_DEFINE(struct udpstat, udpstat); /* from udp_var.h */
156 VNET_PCPUSTAT_SYSINIT(udpstat);
157 SYSCTL_VNET_PCPUSTAT(_net_inet_udp, UDPCTL_STATS, stats, struct udpstat,
158 udpstat, "UDP statistics (struct udpstat, netinet/udp_var.h)");
161 VNET_PCPUSTAT_SYSUNINIT(udpstat);
164 static void udp_detach(struct socket *so);
165 static int udp_output(struct inpcb *, struct mbuf *, struct sockaddr *,
166 struct mbuf *, struct thread *);
170 udp_zone_change(void *tag)
173 uma_zone_set_max(V_udbinfo.ipi_zone, maxsockets);
174 uma_zone_set_max(V_udpcb_zone, maxsockets);
178 udp_inpcb_init(void *mem, int size, int flags)
183 INP_LOCK_INIT(inp, "inp", "udpinp");
188 udplite_inpcb_init(void *mem, int size, int flags)
193 INP_LOCK_INIT(inp, "inp", "udpliteinp");
202 * For now default to 2-tuple UDP hashing - until the fragment
203 * reassembly code can also update the flowid.
205 * Once we can calculate the flowid that way and re-establish
206 * a 4-tuple, flip this to 4-tuple.
208 in_pcbinfo_init(&V_udbinfo, "udp", &V_udb, UDBHASHSIZE, UDBHASHSIZE,
209 "udp_inpcb", udp_inpcb_init, IPI_HASHFIELDS_2TUPLE);
210 V_udpcb_zone = uma_zcreate("udpcb", sizeof(struct udpcb),
211 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
212 uma_zone_set_max(V_udpcb_zone, maxsockets);
213 uma_zone_set_warning(V_udpcb_zone, "kern.ipc.maxsockets limit reached");
214 EVENTHANDLER_REGISTER(maxsockets_change, udp_zone_change, NULL,
215 EVENTHANDLER_PRI_ANY);
222 in_pcbinfo_init(&V_ulitecbinfo, "udplite", &V_ulitecb, UDBHASHSIZE,
223 UDBHASHSIZE, "udplite_inpcb", udplite_inpcb_init,
224 IPI_HASHFIELDS_2TUPLE);
228 * Kernel module interface for updating udpstat. The argument is an index
229 * into udpstat treated as an array of u_long. While this encodes the
230 * general layout of udpstat into the caller, it doesn't encode its location,
231 * so that future changes to add, for example, per-CPU stats support won't
232 * cause binary compatibility problems for kernel modules.
235 kmod_udpstat_inc(int statnum)
238 counter_u64_add(VNET(udpstat)[statnum], 1);
242 udp_newudpcb(struct inpcb *inp)
246 up = uma_zalloc(V_udpcb_zone, M_NOWAIT | M_ZERO);
254 udp_discardcb(struct udpcb *up)
257 uma_zfree(V_udpcb_zone, up);
262 udp_destroy(void *unused __unused)
265 in_pcbinfo_destroy(&V_udbinfo);
266 uma_zdestroy(V_udpcb_zone);
268 VNET_SYSUNINIT(udp, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, udp_destroy, NULL);
271 udplite_destroy(void *unused __unused)
274 in_pcbinfo_destroy(&V_ulitecbinfo);
276 VNET_SYSUNINIT(udplite, SI_SUB_PROTO_DOMAIN, SI_ORDER_FOURTH, udplite_destroy,
282 * Subroutine of udp_input(), which appends the provided mbuf chain to the
283 * passed pcb/socket. The caller must provide a sockaddr_in via udp_in that
284 * contains the source address. If the socket ends up being an IPv6 socket,
285 * udp_append() will convert to a sockaddr_in6 before passing the address
286 * into the socket code.
288 * In the normal case udp_append() will return 0, indicating that you
289 * must unlock the inp. However if a tunneling protocol is in place we increment
290 * the inpcb refcnt and unlock the inp, on return from the tunneling protocol we
291 * then decrement the reference count. If the inp_rele returns 1, indicating the
292 * inp is gone, we return that to the caller to tell them *not* to unlock
293 * the inp. In the case of multi-cast this will cause the distribution
294 * to stop (though most tunneling protocols known currently do *not* use
298 udp_append(struct inpcb *inp, struct ip *ip, struct mbuf *n, int off,
299 struct sockaddr_in *udp_in)
301 struct sockaddr *append_sa;
303 struct mbuf *tmpopts, *opts = NULL;
305 struct sockaddr_in6 udp_in6;
309 INP_LOCK_ASSERT(inp);
312 * Engage the tunneling protocol.
315 if (up->u_tun_func != NULL) {
318 (*up->u_tun_func)(n, off, inp, (struct sockaddr *)&udp_in[0],
321 return (in_pcbrele_rlocked(inp));
324 off += sizeof(struct udphdr);
326 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
327 /* Check AH/ESP integrity. */
328 if (IPSEC_ENABLED(ipv4) &&
329 IPSEC_CHECK_POLICY(ipv4, n, inp) != 0) {
333 if (up->u_flags & UF_ESPINUDP) {/* IPSec UDP encaps. */
334 if (IPSEC_ENABLED(ipv4) &&
335 UDPENCAP_INPUT(n, off, AF_INET) != 0)
336 return (0); /* Consumed. */
340 if (mac_inpcb_check_deliver(inp, n) != 0) {
345 if (inp->inp_flags & INP_CONTROLOPTS ||
346 inp->inp_socket->so_options & (SO_TIMESTAMP | SO_BINTIME)) {
348 if (inp->inp_vflag & INP_IPV6)
349 (void)ip6_savecontrol_v4(inp, n, &opts, NULL);
352 ip_savecontrol(inp, &opts, ip, n);
354 if ((inp->inp_vflag & INP_IPV4) && (inp->inp_flags2 & INP_ORIGDSTADDR)) {
355 tmpopts = sbcreatecontrol((caddr_t)&udp_in[1],
356 sizeof(struct sockaddr_in), IP_ORIGDSTADDR, IPPROTO_IP);
359 tmpopts->m_next = opts;
366 if (inp->inp_vflag & INP_IPV6) {
367 bzero(&udp_in6, sizeof(udp_in6));
368 udp_in6.sin6_len = sizeof(udp_in6);
369 udp_in6.sin6_family = AF_INET6;
370 in6_sin_2_v4mapsin6(&udp_in[0], &udp_in6);
371 append_sa = (struct sockaddr *)&udp_in6;
374 append_sa = (struct sockaddr *)&udp_in[0];
377 so = inp->inp_socket;
378 SOCKBUF_LOCK(&so->so_rcv);
379 if (sbappendaddr_locked(&so->so_rcv, append_sa, n, opts) == 0) {
380 SOCKBUF_UNLOCK(&so->so_rcv);
384 UDPSTAT_INC(udps_fullsock);
386 sorwakeup_locked(so);
391 udp_input(struct mbuf **mp, int *offp, int proto)
397 uint16_t len, ip_len;
398 struct inpcbinfo *pcbinfo;
400 struct sockaddr_in udp_in[2];
402 struct m_tag *fwd_tag;
403 int cscov_partial, iphlen;
407 ifp = m->m_pkthdr.rcvif;
409 UDPSTAT_INC(udps_ipackets);
412 * Strip IP options, if any; should skip this, make available to
413 * user, and use on returned packets, but we don't yet have a way to
414 * check the checksum with options still present.
416 if (iphlen > sizeof (struct ip)) {
418 iphlen = sizeof(struct ip);
422 * Get IP and UDP header together in first mbuf.
424 if (m->m_len < iphlen + sizeof(struct udphdr)) {
425 if ((m = m_pullup(m, iphlen + sizeof(struct udphdr))) == NULL) {
426 UDPSTAT_INC(udps_hdrops);
427 return (IPPROTO_DONE);
430 ip = mtod(m, struct ip *);
431 uh = (struct udphdr *)((caddr_t)ip + iphlen);
432 cscov_partial = (proto == IPPROTO_UDPLITE) ? 1 : 0;
435 * Destination port of 0 is illegal, based on RFC768.
437 if (uh->uh_dport == 0)
441 * Construct sockaddr format source address. Stuff source address
442 * and datagram in user buffer.
444 bzero(&udp_in[0], sizeof(struct sockaddr_in) * 2);
445 udp_in[0].sin_len = sizeof(struct sockaddr_in);
446 udp_in[0].sin_family = AF_INET;
447 udp_in[0].sin_port = uh->uh_sport;
448 udp_in[0].sin_addr = ip->ip_src;
449 udp_in[1].sin_len = sizeof(struct sockaddr_in);
450 udp_in[1].sin_family = AF_INET;
451 udp_in[1].sin_port = uh->uh_dport;
452 udp_in[1].sin_addr = ip->ip_dst;
455 * Make mbuf data length reflect UDP length. If not enough data to
456 * reflect UDP length, drop.
458 len = ntohs((u_short)uh->uh_ulen);
459 ip_len = ntohs(ip->ip_len) - iphlen;
460 if (proto == IPPROTO_UDPLITE && (len == 0 || len == ip_len)) {
461 /* Zero means checksum over the complete packet. */
467 if (len > ip_len || len < sizeof(struct udphdr)) {
468 UDPSTAT_INC(udps_badlen);
471 if (proto == IPPROTO_UDP)
472 m_adj(m, len - ip_len);
476 * Save a copy of the IP header in case we want restore it for
477 * sending an ICMP error message in response.
479 if (!V_udp_blackhole)
482 memset(&save_ip, 0, sizeof(save_ip));
485 * Checksum extended UDP header and data.
490 if ((m->m_pkthdr.csum_flags & CSUM_DATA_VALID) &&
492 if (m->m_pkthdr.csum_flags & CSUM_PSEUDO_HDR)
493 uh_sum = m->m_pkthdr.csum_data;
495 uh_sum = in_pseudo(ip->ip_src.s_addr,
496 ip->ip_dst.s_addr, htonl((u_short)len +
497 m->m_pkthdr.csum_data + proto));
502 bcopy(((struct ipovly *)ip)->ih_x1, b, 9);
503 bzero(((struct ipovly *)ip)->ih_x1, 9);
504 ((struct ipovly *)ip)->ih_len = (proto == IPPROTO_UDP) ?
505 uh->uh_ulen : htons(ip_len);
506 uh_sum = in_cksum(m, len + sizeof (struct ip));
507 bcopy(b, ((struct ipovly *)ip)->ih_x1, 9);
510 UDPSTAT_INC(udps_badsum);
512 return (IPPROTO_DONE);
515 if (proto == IPPROTO_UDP) {
516 UDPSTAT_INC(udps_nosum);
518 /* UDPLite requires a checksum */
519 /* XXX: What is the right UDPLite MIB counter here? */
521 return (IPPROTO_DONE);
525 pcbinfo = udp_get_inpcbinfo(proto);
526 if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr)) ||
527 in_broadcast(ip->ip_dst, ifp)) {
529 struct inpcbhead *pcblist;
533 pcblist = udp_get_pcblist(proto);
535 CK_LIST_FOREACH(inp, pcblist, inp_list) {
536 if (inp->inp_lport != uh->uh_dport)
539 if ((inp->inp_vflag & INP_IPV4) == 0)
542 if (inp->inp_laddr.s_addr != INADDR_ANY &&
543 inp->inp_laddr.s_addr != ip->ip_dst.s_addr)
545 if (inp->inp_faddr.s_addr != INADDR_ANY &&
546 inp->inp_faddr.s_addr != ip->ip_src.s_addr)
548 if (inp->inp_fport != 0 &&
549 inp->inp_fport != uh->uh_sport)
554 if (__predict_false(inp->inp_flags2 & INP_FREED)) {
560 * XXXRW: Because we weren't holding either the inpcb
561 * or the hash lock when we checked for a match
562 * before, we should probably recheck now that the
563 * inpcb lock is held.
567 * Handle socket delivery policy for any-source
568 * and source-specific multicast. [RFC3678]
570 if (IN_MULTICAST(ntohl(ip->ip_dst.s_addr))) {
571 struct ip_moptions *imo;
572 struct sockaddr_in group;
575 imo = inp->inp_moptions;
580 bzero(&group, sizeof(struct sockaddr_in));
581 group.sin_len = sizeof(struct sockaddr_in);
582 group.sin_family = AF_INET;
583 group.sin_addr = ip->ip_dst;
585 blocked = imo_multi_filter(imo, ifp,
586 (struct sockaddr *)&group,
587 (struct sockaddr *)&udp_in[0]);
588 if (blocked != MCAST_PASS) {
589 if (blocked == MCAST_NOTGMEMBER)
590 IPSTAT_INC(ips_notmember);
591 if (blocked == MCAST_NOTSMEMBER ||
592 blocked == MCAST_MUTED)
593 UDPSTAT_INC(udps_filtermcast);
601 if ((n = m_copym(m, 0, M_COPYALL, M_NOWAIT)) !=
603 if (proto == IPPROTO_UDPLITE)
604 UDPLITE_PROBE(receive, NULL, last, ip,
607 UDP_PROBE(receive, NULL, last, ip, last,
609 if (udp_append(last, ip, n, iphlen,
618 * Don't look for additional matches if this one does
619 * not have either the SO_REUSEPORT or SO_REUSEADDR
620 * socket options set. This heuristic avoids
621 * searching through all pcbs in the common case of a
622 * non-shared port. It assumes that an application
623 * will never clear these options after setting them.
625 if ((last->inp_socket->so_options &
626 (SO_REUSEPORT|SO_REUSEPORT_LB|SO_REUSEADDR)) == 0)
632 * No matching pcb found; discard datagram. (No need
633 * to send an ICMP Port Unreachable for a broadcast
634 * or multicast datgram.)
636 UDPSTAT_INC(udps_noportbcast);
641 if (proto == IPPROTO_UDPLITE)
642 UDPLITE_PROBE(receive, NULL, last, ip, last, uh);
644 UDP_PROBE(receive, NULL, last, ip, last, uh);
645 if (udp_append(last, ip, m, iphlen, udp_in) == 0)
648 return (IPPROTO_DONE);
652 * Locate pcb for datagram.
656 * Grab info from PACKET_TAG_IPFORWARD tag prepended to the chain.
658 if ((m->m_flags & M_IP_NEXTHOP) &&
659 (fwd_tag = m_tag_find(m, PACKET_TAG_IPFORWARD, NULL)) != NULL) {
660 struct sockaddr_in *next_hop;
662 next_hop = (struct sockaddr_in *)(fwd_tag + 1);
665 * Transparently forwarded. Pretend to be the destination.
666 * Already got one like this?
668 inp = in_pcblookup_mbuf(pcbinfo, ip->ip_src, uh->uh_sport,
669 ip->ip_dst, uh->uh_dport, INPLOOKUP_RLOCKPCB, ifp, m);
672 * It's new. Try to find the ambushing socket.
673 * Because we've rewritten the destination address,
674 * any hardware-generated hash is ignored.
676 inp = in_pcblookup(pcbinfo, ip->ip_src,
677 uh->uh_sport, next_hop->sin_addr,
678 next_hop->sin_port ? htons(next_hop->sin_port) :
679 uh->uh_dport, INPLOOKUP_WILDCARD |
680 INPLOOKUP_RLOCKPCB, ifp);
682 /* Remove the tag from the packet. We don't need it anymore. */
683 m_tag_delete(m, fwd_tag);
684 m->m_flags &= ~M_IP_NEXTHOP;
686 inp = in_pcblookup_mbuf(pcbinfo, ip->ip_src, uh->uh_sport,
687 ip->ip_dst, uh->uh_dport, INPLOOKUP_WILDCARD |
688 INPLOOKUP_RLOCKPCB, ifp, m);
690 if (V_udp_log_in_vain) {
691 char src[INET_ADDRSTRLEN];
692 char dst[INET_ADDRSTRLEN];
695 "Connection attempt to UDP %s:%d from %s:%d\n",
696 inet_ntoa_r(ip->ip_dst, dst), ntohs(uh->uh_dport),
697 inet_ntoa_r(ip->ip_src, src), ntohs(uh->uh_sport));
699 if (proto == IPPROTO_UDPLITE)
700 UDPLITE_PROBE(receive, NULL, NULL, ip, NULL, uh);
702 UDP_PROBE(receive, NULL, NULL, ip, NULL, uh);
703 UDPSTAT_INC(udps_noport);
704 if (m->m_flags & (M_BCAST | M_MCAST)) {
705 UDPSTAT_INC(udps_noportbcast);
710 if (badport_bandlim(BANDLIM_ICMP_UNREACH) < 0)
713 icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
714 return (IPPROTO_DONE);
718 * Check the minimum TTL for socket.
720 INP_RLOCK_ASSERT(inp);
721 if (inp->inp_ip_minttl && inp->inp_ip_minttl > ip->ip_ttl) {
722 if (proto == IPPROTO_UDPLITE)
723 UDPLITE_PROBE(receive, NULL, inp, ip, inp, uh);
725 UDP_PROBE(receive, NULL, inp, ip, inp, uh);
728 return (IPPROTO_DONE);
734 if (up->u_rxcslen == 0 || up->u_rxcslen > len) {
737 return (IPPROTO_DONE);
741 if (proto == IPPROTO_UDPLITE)
742 UDPLITE_PROBE(receive, NULL, inp, ip, inp, uh);
744 UDP_PROBE(receive, NULL, inp, ip, inp, uh);
745 if (udp_append(inp, ip, m, iphlen, udp_in) == 0)
747 return (IPPROTO_DONE);
751 return (IPPROTO_DONE);
756 * Notify a udp user of an asynchronous error; just wake up so that they can
757 * collect error status.
760 udp_notify(struct inpcb *inp, int errno)
763 INP_WLOCK_ASSERT(inp);
764 if ((errno == EHOSTUNREACH || errno == ENETUNREACH ||
765 errno == EHOSTDOWN) && inp->inp_route.ro_nh) {
766 NH_FREE(inp->inp_route.ro_nh);
767 inp->inp_route.ro_nh = (struct nhop_object *)NULL;
770 inp->inp_socket->so_error = errno;
771 sorwakeup(inp->inp_socket);
772 sowwakeup(inp->inp_socket);
778 udp_common_ctlinput(int cmd, struct sockaddr *sa, void *vip,
779 struct inpcbinfo *pcbinfo)
783 struct in_addr faddr;
786 faddr = ((struct sockaddr_in *)sa)->sin_addr;
787 if (sa->sa_family != AF_INET || faddr.s_addr == INADDR_ANY)
790 if (PRC_IS_REDIRECT(cmd)) {
791 /* signal EHOSTDOWN, as it flushes the cached route */
792 in_pcbnotifyall(&V_udbinfo, faddr, EHOSTDOWN, udp_notify);
797 * Hostdead is ugly because it goes linearly through all PCBs.
799 * XXX: We never get this from ICMP, otherwise it makes an excellent
800 * DoS attack on machines with many connections.
802 if (cmd == PRC_HOSTDEAD)
804 else if ((unsigned)cmd >= PRC_NCMDS || inetctlerrmap[cmd] == 0)
807 uh = (struct udphdr *)((caddr_t)ip + (ip->ip_hl << 2));
808 inp = in_pcblookup(pcbinfo, faddr, uh->uh_dport,
809 ip->ip_src, uh->uh_sport, INPLOOKUP_WLOCKPCB, NULL);
811 INP_WLOCK_ASSERT(inp);
812 if (inp->inp_socket != NULL) {
813 udp_notify(inp, inetctlerrmap[cmd]);
817 inp = in_pcblookup(pcbinfo, faddr, uh->uh_dport,
818 ip->ip_src, uh->uh_sport,
819 INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB, NULL);
827 func = up->u_icmp_func;
830 (*func)(cmd, sa, vip, ctx);
834 in_pcbnotifyall(pcbinfo, faddr, inetctlerrmap[cmd],
838 udp_ctlinput(int cmd, struct sockaddr *sa, void *vip)
841 return (udp_common_ctlinput(cmd, sa, vip, &V_udbinfo));
845 udplite_ctlinput(int cmd, struct sockaddr *sa, void *vip)
848 return (udp_common_ctlinput(cmd, sa, vip, &V_ulitecbinfo));
853 udp_pcblist(SYSCTL_HANDLER_ARGS)
856 struct epoch_tracker et;
860 if (req->newptr != 0)
863 if (req->oldptr == 0) {
866 n = V_udbinfo.ipi_count;
867 n += imax(n / 8, 10);
868 req->oldidx = 2 * (sizeof xig) + n * sizeof(struct xinpcb);
872 if ((error = sysctl_wire_old_buffer(req, 0)) != 0)
875 bzero(&xig, sizeof(xig));
876 xig.xig_len = sizeof xig;
877 xig.xig_count = V_udbinfo.ipi_count;
878 xig.xig_gen = V_udbinfo.ipi_gencnt;
879 xig.xig_sogen = so_gencnt;
880 error = SYSCTL_OUT(req, &xig, sizeof xig);
885 for (inp = CK_LIST_FIRST(V_udbinfo.ipi_listhead);
887 inp = CK_LIST_NEXT(inp, inp_list)) {
889 if (inp->inp_gencnt <= xig.xig_gen &&
890 cr_canseeinpcb(req->td->td_ucred, inp) == 0) {
893 in_pcbtoxinpcb(inp, &xi);
895 error = SYSCTL_OUT(req, &xi, sizeof xi);
905 * Give the user an updated idea of our state. If the
906 * generation differs from what we told her before, she knows
907 * that something happened while we were processing this
908 * request, and it might be necessary to retry.
910 xig.xig_gen = V_udbinfo.ipi_gencnt;
911 xig.xig_sogen = so_gencnt;
912 xig.xig_count = V_udbinfo.ipi_count;
913 error = SYSCTL_OUT(req, &xig, sizeof xig);
919 SYSCTL_PROC(_net_inet_udp, UDPCTL_PCBLIST, pcblist,
920 CTLTYPE_OPAQUE | CTLFLAG_RD | CTLFLAG_MPSAFE, NULL, 0,
921 udp_pcblist, "S,xinpcb",
922 "List of active UDP sockets");
926 udp_getcred(SYSCTL_HANDLER_ARGS)
929 struct sockaddr_in addrs[2];
930 struct epoch_tracker et;
934 error = priv_check(req->td, PRIV_NETINET_GETCRED);
937 error = SYSCTL_IN(req, addrs, sizeof(addrs));
941 inp = in_pcblookup(&V_udbinfo, addrs[1].sin_addr, addrs[1].sin_port,
942 addrs[0].sin_addr, addrs[0].sin_port,
943 INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB, NULL);
946 INP_RLOCK_ASSERT(inp);
947 if (inp->inp_socket == NULL)
950 error = cr_canseeinpcb(req->td->td_ucred, inp);
952 cru2x(inp->inp_cred, &xuc);
957 error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
961 SYSCTL_PROC(_net_inet_udp, OID_AUTO, getcred,
962 CTLTYPE_OPAQUE | CTLFLAG_RW | CTLFLAG_PRISON | CTLFLAG_MPSAFE,
963 0, 0, udp_getcred, "S,xucred",
964 "Get the xucred of a UDP connection");
968 udp_ctloutput(struct socket *so, struct sockopt *sopt)
972 int isudplite, error, optval;
975 isudplite = (so->so_proto->pr_protocol == IPPROTO_UDPLITE) ? 1 : 0;
977 KASSERT(inp != NULL, ("%s: inp == NULL", __func__));
979 if (sopt->sopt_level != so->so_proto->pr_protocol) {
981 if (INP_CHECK_SOCKAF(so, AF_INET6)) {
983 error = ip6_ctloutput(so, sopt);
986 #if defined(INET) && defined(INET6)
992 error = ip_ctloutput(so, sopt);
998 switch (sopt->sopt_dir) {
1000 switch (sopt->sopt_name) {
1001 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
1004 if (!IPSEC_ENABLED(ipv4)) {
1006 return (ENOPROTOOPT);
1008 error = UDPENCAP_PCBCTL(inp, sopt);
1012 case UDPLITE_SEND_CSCOV:
1013 case UDPLITE_RECV_CSCOV:
1016 error = ENOPROTOOPT;
1020 error = sooptcopyin(sopt, &optval, sizeof(optval),
1024 inp = sotoinpcb(so);
1025 KASSERT(inp != NULL, ("%s: inp == NULL", __func__));
1027 up = intoudpcb(inp);
1028 KASSERT(up != NULL, ("%s: up == NULL", __func__));
1029 if ((optval != 0 && optval < 8) || (optval > 65535)) {
1034 if (sopt->sopt_name == UDPLITE_SEND_CSCOV)
1035 up->u_txcslen = optval;
1037 up->u_rxcslen = optval;
1042 error = ENOPROTOOPT;
1047 switch (sopt->sopt_name) {
1048 #if defined(IPSEC) || defined(IPSEC_SUPPORT)
1051 if (!IPSEC_ENABLED(ipv4)) {
1053 return (ENOPROTOOPT);
1055 error = UDPENCAP_PCBCTL(inp, sopt);
1059 case UDPLITE_SEND_CSCOV:
1060 case UDPLITE_RECV_CSCOV:
1063 error = ENOPROTOOPT;
1066 up = intoudpcb(inp);
1067 KASSERT(up != NULL, ("%s: up == NULL", __func__));
1068 if (sopt->sopt_name == UDPLITE_SEND_CSCOV)
1069 optval = up->u_txcslen;
1071 optval = up->u_rxcslen;
1073 error = sooptcopyout(sopt, &optval, sizeof(optval));
1077 error = ENOPROTOOPT;
1087 udp_output(struct inpcb *inp, struct mbuf *m, struct sockaddr *addr,
1088 struct mbuf *control, struct thread *td)
1090 struct udpiphdr *ui;
1091 int len = m->m_pkthdr.len;
1092 struct in_addr faddr, laddr;
1094 struct inpcbinfo *pcbinfo;
1095 struct sockaddr_in *sin, src;
1096 struct epoch_tracker et;
1097 int cscov_partial = 0;
1100 u_short fport, lport;
1104 uint32_t flowid = 0;
1105 uint8_t flowtype = M_HASHTYPE_NONE;
1107 if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
1115 sin = (struct sockaddr_in *)addr;
1118 * udp_output() may need to temporarily bind or connect the current
1119 * inpcb. As such, we don't know up front whether we will need the
1120 * pcbinfo lock or not. Do any work to decide what is needed up
1121 * front before acquiring any locks.
1123 * We will need network epoch in either case, to safely lookup into
1127 (inp->inp_laddr.s_addr == INADDR_ANY && inp->inp_lport == 0))
1131 NET_EPOCH_ENTER(et);
1132 tos = inp->inp_ip_tos;
1133 if (control != NULL) {
1135 * XXX: Currently, we assume all the optional information is
1136 * stored in a single mbuf.
1138 if (control->m_next) {
1143 for (; control->m_len > 0;
1144 control->m_data += CMSG_ALIGN(cm->cmsg_len),
1145 control->m_len -= CMSG_ALIGN(cm->cmsg_len)) {
1146 cm = mtod(control, struct cmsghdr *);
1147 if (control->m_len < sizeof(*cm) || cm->cmsg_len == 0
1148 || cm->cmsg_len > control->m_len) {
1152 if (cm->cmsg_level != IPPROTO_IP)
1155 switch (cm->cmsg_type) {
1156 case IP_SENDSRCADDR:
1158 CMSG_LEN(sizeof(struct in_addr))) {
1162 bzero(&src, sizeof(src));
1163 src.sin_family = AF_INET;
1164 src.sin_len = sizeof(src);
1165 src.sin_port = inp->inp_lport;
1167 *(struct in_addr *)CMSG_DATA(cm);
1171 if (cm->cmsg_len != CMSG_LEN(sizeof(u_char))) {
1175 tos = *(u_char *)CMSG_DATA(cm);
1179 if (cm->cmsg_len != CMSG_LEN(sizeof(uint32_t))) {
1183 flowid = *(uint32_t *) CMSG_DATA(cm);
1187 if (cm->cmsg_len != CMSG_LEN(sizeof(uint32_t))) {
1191 flowtype = *(uint32_t *) CMSG_DATA(cm);
1195 case IP_RSSBUCKETID:
1196 if (cm->cmsg_len != CMSG_LEN(sizeof(uint32_t))) {
1200 /* This is just a placeholder for now */
1204 error = ENOPROTOOPT;
1215 pr = inp->inp_socket->so_proto->pr_protocol;
1216 pcbinfo = udp_get_inpcbinfo(pr);
1219 * If the IP_SENDSRCADDR control message was specified, override the
1220 * source address for this datagram. Its use is invalidated if the
1221 * address thus specified is incomplete or clobbers other inpcbs.
1223 laddr = inp->inp_laddr;
1224 lport = inp->inp_lport;
1225 if (src.sin_family == AF_INET) {
1226 INP_HASH_LOCK_ASSERT(pcbinfo);
1228 (laddr.s_addr == INADDR_ANY &&
1229 src.sin_addr.s_addr == INADDR_ANY)) {
1233 error = in_pcbbind_setup(inp, (struct sockaddr *)&src,
1234 &laddr.s_addr, &lport, td->td_ucred);
1240 * If a UDP socket has been connected, then a local address/port will
1241 * have been selected and bound.
1243 * If a UDP socket has not been connected to, then an explicit
1244 * destination address must be used, in which case a local
1245 * address/port may not have been selected and bound.
1248 INP_LOCK_ASSERT(inp);
1249 if (inp->inp_faddr.s_addr != INADDR_ANY) {
1255 * Jail may rewrite the destination address, so let it do
1256 * that before we use it.
1258 error = prison_remote_ip4(td->td_ucred, &sin->sin_addr);
1263 * If a local address or port hasn't yet been selected, or if
1264 * the destination address needs to be rewritten due to using
1265 * a special INADDR_ constant, invoke in_pcbconnect_setup()
1266 * to do the heavy lifting. Once a port is selected, we
1267 * commit the binding back to the socket; we also commit the
1268 * binding of the address if in jail.
1270 * If we already have a valid binding and we're not
1271 * requesting a destination address rewrite, use a fast path.
1273 if (inp->inp_laddr.s_addr == INADDR_ANY ||
1274 inp->inp_lport == 0 ||
1275 sin->sin_addr.s_addr == INADDR_ANY ||
1276 sin->sin_addr.s_addr == INADDR_BROADCAST) {
1277 INP_HASH_LOCK_ASSERT(pcbinfo);
1278 error = in_pcbconnect_setup(inp, addr, &laddr.s_addr,
1279 &lport, &faddr.s_addr, &fport, NULL,
1285 * XXXRW: Why not commit the port if the address is
1288 /* Commit the local port if newly assigned. */
1289 if (inp->inp_laddr.s_addr == INADDR_ANY &&
1290 inp->inp_lport == 0) {
1291 INP_WLOCK_ASSERT(inp);
1293 * Remember addr if jailed, to prevent
1296 if (prison_flag(td->td_ucred, PR_IP4))
1297 inp->inp_laddr = laddr;
1298 inp->inp_lport = lport;
1299 INP_HASH_WLOCK(pcbinfo);
1300 error = in_pcbinshash(inp);
1301 INP_HASH_WUNLOCK(pcbinfo);
1307 inp->inp_flags |= INP_ANONPORT;
1310 faddr = sin->sin_addr;
1311 fport = sin->sin_port;
1314 INP_LOCK_ASSERT(inp);
1315 faddr = inp->inp_faddr;
1316 fport = inp->inp_fport;
1317 if (faddr.s_addr == INADDR_ANY) {
1324 * Calculate data length and get a mbuf for UDP, IP, and possible
1325 * link-layer headers. Immediate slide the data pointer back forward
1326 * since we won't use that space at this layer.
1328 M_PREPEND(m, sizeof(struct udpiphdr) + max_linkhdr, M_NOWAIT);
1333 m->m_data += max_linkhdr;
1334 m->m_len -= max_linkhdr;
1335 m->m_pkthdr.len -= max_linkhdr;
1338 * Fill in mbuf with extended UDP header and addresses and length put
1339 * into network format.
1341 ui = mtod(m, struct udpiphdr *);
1342 bzero(ui->ui_x1, sizeof(ui->ui_x1)); /* XXX still needed? */
1343 ui->ui_v = IPVERSION << 4;
1347 ui->ui_sport = lport;
1348 ui->ui_dport = fport;
1349 ui->ui_ulen = htons((u_short)len + sizeof(struct udphdr));
1350 if (pr == IPPROTO_UDPLITE) {
1354 up = intoudpcb(inp);
1355 cscov = up->u_txcslen;
1356 plen = (u_short)len + sizeof(struct udphdr);
1359 ui->ui_len = htons(plen);
1360 ui->ui_ulen = htons(cscov);
1362 * For UDP-Lite, checksum coverage length of zero means
1363 * the entire UDPLite packet is covered by the checksum.
1365 cscov_partial = (cscov == 0) ? 0 : 1;
1369 * Set the Don't Fragment bit in the IP header.
1371 if (inp->inp_flags & INP_DONTFRAG) {
1374 ip = (struct ip *)&ui->ui_i;
1375 ip->ip_off |= htons(IP_DF);
1379 if (inp->inp_socket->so_options & SO_DONTROUTE)
1380 ipflags |= IP_ROUTETOIF;
1381 if (inp->inp_socket->so_options & SO_BROADCAST)
1382 ipflags |= IP_ALLOWBROADCAST;
1383 if (inp->inp_flags & INP_ONESBCAST)
1384 ipflags |= IP_SENDONES;
1387 mac_inpcb_create_mbuf(inp, m);
1391 * Set up checksum and output datagram.
1394 if (pr == IPPROTO_UDPLITE) {
1395 if (inp->inp_flags & INP_ONESBCAST)
1396 faddr.s_addr = INADDR_BROADCAST;
1397 if (cscov_partial) {
1398 if ((ui->ui_sum = in_cksum(m, sizeof(struct ip) + cscov)) == 0)
1399 ui->ui_sum = 0xffff;
1401 if ((ui->ui_sum = in_cksum(m, sizeof(struct udpiphdr) + len)) == 0)
1402 ui->ui_sum = 0xffff;
1404 } else if (V_udp_cksum) {
1405 if (inp->inp_flags & INP_ONESBCAST)
1406 faddr.s_addr = INADDR_BROADCAST;
1407 ui->ui_sum = in_pseudo(ui->ui_src.s_addr, faddr.s_addr,
1408 htons((u_short)len + sizeof(struct udphdr) + pr));
1409 m->m_pkthdr.csum_flags = CSUM_UDP;
1410 m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
1412 ((struct ip *)ui)->ip_len = htons(sizeof(struct udpiphdr) + len);
1413 ((struct ip *)ui)->ip_ttl = inp->inp_ip_ttl; /* XXX */
1414 ((struct ip *)ui)->ip_tos = tos; /* XXX */
1415 UDPSTAT_INC(udps_opackets);
1418 * Setup flowid / RSS information for outbound socket.
1420 * Once the UDP code decides to set a flowid some other way,
1421 * this allows the flowid to be overridden by userland.
1423 if (flowtype != M_HASHTYPE_NONE) {
1424 m->m_pkthdr.flowid = flowid;
1425 M_HASHTYPE_SET(m, flowtype);
1429 uint32_t hash_val, hash_type;
1431 * Calculate an appropriate RSS hash for UDP and
1434 * The called function will take care of figuring out
1435 * whether a 2-tuple or 4-tuple hash is required based
1436 * on the currently configured scheme.
1438 * Later later on connected socket values should be
1439 * cached in the inpcb and reused, rather than constantly
1440 * re-calculating it.
1442 * UDP Lite is a different protocol number and will
1443 * likely end up being hashed as a 2-tuple until
1444 * RSS / NICs grow UDP Lite protocol awareness.
1446 if (rss_proto_software_hash_v4(faddr, laddr, fport, lport,
1447 pr, &hash_val, &hash_type) == 0) {
1448 m->m_pkthdr.flowid = hash_val;
1449 M_HASHTYPE_SET(m, hash_type);
1454 * Don't override with the inp cached flowid value.
1456 * Depending upon the kind of send being done, the inp
1457 * flowid/flowtype values may actually not be appropriate
1458 * for this particular socket send.
1460 * We should either leave the flowid at zero (which is what is
1461 * currently done) or set it to some software generated
1462 * hash value based on the packet contents.
1464 ipflags |= IP_NODEFAULTFLOWID;
1467 if (pr == IPPROTO_UDPLITE)
1468 UDPLITE_PROBE(send, NULL, inp, &ui->ui_i, inp, &ui->ui_u);
1470 UDP_PROBE(send, NULL, inp, &ui->ui_i, inp, &ui->ui_u);
1471 error = ip_output(m, inp->inp_options,
1472 INP_WLOCKED(inp) ? &inp->inp_route : NULL, ipflags,
1473 inp->inp_moptions, inp);
1486 udp_abort(struct socket *so)
1489 struct inpcbinfo *pcbinfo;
1491 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
1492 inp = sotoinpcb(so);
1493 KASSERT(inp != NULL, ("udp_abort: inp == NULL"));
1495 if (inp->inp_faddr.s_addr != INADDR_ANY) {
1496 INP_HASH_WLOCK(pcbinfo);
1497 in_pcbdisconnect(inp);
1498 inp->inp_laddr.s_addr = INADDR_ANY;
1499 INP_HASH_WUNLOCK(pcbinfo);
1500 soisdisconnected(so);
1506 udp_attach(struct socket *so, int proto, struct thread *td)
1508 static uint32_t udp_flowid;
1510 struct inpcbinfo *pcbinfo;
1513 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
1514 inp = sotoinpcb(so);
1515 KASSERT(inp == NULL, ("udp_attach: inp != NULL"));
1516 error = soreserve(so, udp_sendspace, udp_recvspace);
1519 INP_INFO_WLOCK(pcbinfo);
1520 error = in_pcballoc(so, pcbinfo);
1522 INP_INFO_WUNLOCK(pcbinfo);
1526 inp = sotoinpcb(so);
1527 inp->inp_vflag |= INP_IPV4;
1528 inp->inp_ip_ttl = V_ip_defttl;
1529 inp->inp_flowid = atomic_fetchadd_int(&udp_flowid, 1);
1530 inp->inp_flowtype = M_HASHTYPE_OPAQUE;
1532 error = udp_newudpcb(inp);
1536 INP_INFO_WUNLOCK(pcbinfo);
1541 INP_INFO_WUNLOCK(pcbinfo);
1547 udp_set_kernel_tunneling(struct socket *so, udp_tun_func_t f, udp_tun_icmp_t i, void *ctx)
1552 KASSERT(so->so_type == SOCK_DGRAM,
1553 ("udp_set_kernel_tunneling: !dgram"));
1554 inp = sotoinpcb(so);
1555 KASSERT(inp != NULL, ("udp_set_kernel_tunneling: inp == NULL"));
1557 up = intoudpcb(inp);
1558 if ((up->u_tun_func != NULL) ||
1559 (up->u_icmp_func != NULL)) {
1564 up->u_icmp_func = i;
1565 up->u_tun_ctx = ctx;
1572 udp_bind(struct socket *so, struct sockaddr *nam, struct thread *td)
1575 struct inpcbinfo *pcbinfo;
1578 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
1579 inp = sotoinpcb(so);
1580 KASSERT(inp != NULL, ("udp_bind: inp == NULL"));
1582 INP_HASH_WLOCK(pcbinfo);
1583 error = in_pcbbind(inp, nam, td->td_ucred);
1584 INP_HASH_WUNLOCK(pcbinfo);
1590 udp_close(struct socket *so)
1593 struct inpcbinfo *pcbinfo;
1595 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
1596 inp = sotoinpcb(so);
1597 KASSERT(inp != NULL, ("udp_close: inp == NULL"));
1599 if (inp->inp_faddr.s_addr != INADDR_ANY) {
1600 INP_HASH_WLOCK(pcbinfo);
1601 in_pcbdisconnect(inp);
1602 inp->inp_laddr.s_addr = INADDR_ANY;
1603 INP_HASH_WUNLOCK(pcbinfo);
1604 soisdisconnected(so);
1610 udp_connect(struct socket *so, struct sockaddr *nam, struct thread *td)
1612 struct epoch_tracker et;
1614 struct inpcbinfo *pcbinfo;
1615 struct sockaddr_in *sin;
1618 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
1619 inp = sotoinpcb(so);
1620 KASSERT(inp != NULL, ("udp_connect: inp == NULL"));
1622 if (inp->inp_faddr.s_addr != INADDR_ANY) {
1626 sin = (struct sockaddr_in *)nam;
1627 error = prison_remote_ip4(td->td_ucred, &sin->sin_addr);
1632 NET_EPOCH_ENTER(et);
1633 INP_HASH_WLOCK(pcbinfo);
1634 error = in_pcbconnect(inp, nam, td->td_ucred);
1635 INP_HASH_WUNLOCK(pcbinfo);
1644 udp_detach(struct socket *so)
1647 struct inpcbinfo *pcbinfo;
1650 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
1651 inp = sotoinpcb(so);
1652 KASSERT(inp != NULL, ("udp_detach: inp == NULL"));
1653 KASSERT(inp->inp_faddr.s_addr == INADDR_ANY,
1654 ("udp_detach: not disconnected"));
1655 INP_INFO_WLOCK(pcbinfo);
1657 up = intoudpcb(inp);
1658 KASSERT(up != NULL, ("%s: up == NULL", __func__));
1659 inp->inp_ppcb = NULL;
1662 INP_INFO_WUNLOCK(pcbinfo);
1667 udp_disconnect(struct socket *so)
1670 struct inpcbinfo *pcbinfo;
1672 pcbinfo = udp_get_inpcbinfo(so->so_proto->pr_protocol);
1673 inp = sotoinpcb(so);
1674 KASSERT(inp != NULL, ("udp_disconnect: inp == NULL"));
1676 if (inp->inp_faddr.s_addr == INADDR_ANY) {
1680 INP_HASH_WLOCK(pcbinfo);
1681 in_pcbdisconnect(inp);
1682 inp->inp_laddr.s_addr = INADDR_ANY;
1683 INP_HASH_WUNLOCK(pcbinfo);
1685 so->so_state &= ~SS_ISCONNECTED; /* XXX */
1692 udp_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr,
1693 struct mbuf *control, struct thread *td)
1697 inp = sotoinpcb(so);
1698 KASSERT(inp != NULL, ("udp_send: inp == NULL"));
1699 return (udp_output(inp, m, addr, control, td));
1704 udp_shutdown(struct socket *so)
1708 inp = sotoinpcb(so);
1709 KASSERT(inp != NULL, ("udp_shutdown: inp == NULL"));
1717 struct pr_usrreqs udp_usrreqs = {
1718 .pru_abort = udp_abort,
1719 .pru_attach = udp_attach,
1720 .pru_bind = udp_bind,
1721 .pru_connect = udp_connect,
1722 .pru_control = in_control,
1723 .pru_detach = udp_detach,
1724 .pru_disconnect = udp_disconnect,
1725 .pru_peeraddr = in_getpeeraddr,
1726 .pru_send = udp_send,
1727 .pru_soreceive = soreceive_dgram,
1728 .pru_sosend = sosend_dgram,
1729 .pru_shutdown = udp_shutdown,
1730 .pru_sockaddr = in_getsockaddr,
1731 .pru_sosetlabel = in_pcbsosetlabel,
1732 .pru_close = udp_close,