Wed Jun 6 14:49:42 2018 UTC ()
Pull up following revision(s) (requested by maxv in ticket #1607):

	sys/netinet/udp_usrreq.c: revision 1.237 (via patch)

Fix three pretty bad mistakes in NAT-T:

 * If we got a keepalive packet, we need to call m_freem, not m_free.
   Here the next mbufs in the chain are not freed. Seems easy to remotely
   DoS the system by sending fragmented keepalives in a loop.

 * If !ipsec_used, free the mbuf.

 * In udp_input, we need to update 'uh', because udp4_realinput may have
   modified the chain. Perhaps we also need to re-enforce alignment, so
   add an XXX.


(martin)
diff -r1.217 -r1.217.10.1 src/sys/netinet/udp_usrreq.c

cvs diff -r1.217 -r1.217.10.1 src/sys/netinet/udp_usrreq.c (switch to unified diff)

--- src/sys/netinet/udp_usrreq.c 2014/08/09 05:33:01 1.217
+++ src/sys/netinet/udp_usrreq.c 2018/06/06 14:49:41 1.217.10.1
@@ -1,1440 +1,1449 @@ @@ -1,1440 +1,1449 @@
1/* $NetBSD: udp_usrreq.c,v 1.217 2014/08/09 05:33:01 rtr Exp $ */ 1/* $NetBSD: udp_usrreq.c,v 1.217.10.1 2018/06/06 14:49:41 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 4 * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the project nor the names of its contributors 15 * 3. Neither the name of the project nor the names of its contributors
16 * may be used to endorse or promote products derived from this software 16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission. 17 * without specific prior written permission.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 19 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 22 * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE. 29 * SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995 33 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1995
34 * The Regents of the University of California. All rights reserved. 34 * The Regents of the University of California. All rights reserved.
35 * 35 *
36 * Redistribution and use in source and binary forms, with or without 36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions 37 * modification, are permitted provided that the following conditions
38 * are met: 38 * are met:
39 * 1. Redistributions of source code must retain the above copyright 39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer. 40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright 41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the 42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution. 43 * documentation and/or other materials provided with the distribution.
44 * 3. Neither the name of the University nor the names of its contributors 44 * 3. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software 45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission. 46 * without specific prior written permission.
47 * 47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE. 58 * SUCH DAMAGE.
59 * 59 *
60 * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95 60 * @(#)udp_usrreq.c 8.6 (Berkeley) 5/23/95
61 */ 61 */
62 62
63/* 63/*
64 * UDP protocol implementation. 64 * UDP protocol implementation.
65 * Per RFC 768, August, 1980. 65 * Per RFC 768, August, 1980.
66 */ 66 */
67 67
68#include <sys/cdefs.h> 68#include <sys/cdefs.h>
69__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.217 2014/08/09 05:33:01 rtr Exp $"); 69__KERNEL_RCSID(0, "$NetBSD: udp_usrreq.c,v 1.217.10.1 2018/06/06 14:49:41 martin Exp $");
70 70
71#include "opt_inet.h" 71#include "opt_inet.h"
72#include "opt_compat_netbsd.h" 72#include "opt_compat_netbsd.h"
73#include "opt_ipsec.h" 73#include "opt_ipsec.h"
74#include "opt_inet_csum.h" 74#include "opt_inet_csum.h"
75#include "opt_ipkdb.h" 75#include "opt_ipkdb.h"
76#include "opt_mbuftrace.h" 76#include "opt_mbuftrace.h"
77 77
78#include <sys/param.h> 78#include <sys/param.h>
79#include <sys/mbuf.h> 79#include <sys/mbuf.h>
80#include <sys/once.h> 80#include <sys/once.h>
81#include <sys/protosw.h> 81#include <sys/protosw.h>
82#include <sys/socket.h> 82#include <sys/socket.h>
83#include <sys/socketvar.h> 83#include <sys/socketvar.h>
84#include <sys/systm.h> 84#include <sys/systm.h>
85#include <sys/proc.h> 85#include <sys/proc.h>
86#include <sys/domain.h> 86#include <sys/domain.h>
87#include <sys/sysctl.h> 87#include <sys/sysctl.h>
88 88
89#include <net/if.h> 89#include <net/if.h>
90#include <net/route.h> 90#include <net/route.h>
91 91
92#include <netinet/in.h> 92#include <netinet/in.h>
93#include <netinet/in_systm.h> 93#include <netinet/in_systm.h>
94#include <netinet/in_var.h> 94#include <netinet/in_var.h>
95#include <netinet/ip.h> 95#include <netinet/ip.h>
96#include <netinet/in_pcb.h> 96#include <netinet/in_pcb.h>
97#include <netinet/ip_var.h> 97#include <netinet/ip_var.h>
98#include <netinet/ip_icmp.h> 98#include <netinet/ip_icmp.h>
99#include <netinet/udp.h> 99#include <netinet/udp.h>
100#include <netinet/udp_var.h> 100#include <netinet/udp_var.h>
101#include <netinet/udp_private.h> 101#include <netinet/udp_private.h>
102 102
103#ifdef INET6 103#ifdef INET6
104#include <netinet/ip6.h> 104#include <netinet/ip6.h>
105#include <netinet/icmp6.h> 105#include <netinet/icmp6.h>
106#include <netinet6/ip6_var.h> 106#include <netinet6/ip6_var.h>
107#include <netinet6/ip6_private.h> 107#include <netinet6/ip6_private.h>
108#include <netinet6/in6_pcb.h> 108#include <netinet6/in6_pcb.h>
109#include <netinet6/udp6_var.h> 109#include <netinet6/udp6_var.h>
110#include <netinet6/udp6_private.h> 110#include <netinet6/udp6_private.h>
111#endif 111#endif
112 112
113#ifndef INET6 113#ifndef INET6
114/* always need ip6.h for IP6_EXTHDR_GET */ 114/* always need ip6.h for IP6_EXTHDR_GET */
115#include <netinet/ip6.h> 115#include <netinet/ip6.h>
116#endif 116#endif
117 117
118#ifdef IPSEC 118#ifdef IPSEC
119#include <netipsec/ipsec.h> 119#include <netipsec/ipsec.h>
120#include <netipsec/ipsec_var.h> 120#include <netipsec/ipsec_var.h>
121#include <netipsec/ipsec_private.h> 121#include <netipsec/ipsec_private.h>
122#include <netipsec/esp.h> 122#include <netipsec/esp.h>
123#ifdef INET6 123#ifdef INET6
124#include <netipsec/ipsec6.h> 124#include <netipsec/ipsec6.h>
125#endif 125#endif
126#endif /* IPSEC */ 126#endif /* IPSEC */
127 127
128#ifdef COMPAT_50 128#ifdef COMPAT_50
129#include <compat/sys/socket.h> 129#include <compat/sys/socket.h>
130#endif 130#endif
131 131
132#ifdef IPKDB 132#ifdef IPKDB
133#include <ipkdb/ipkdb.h> 133#include <ipkdb/ipkdb.h>
134#endif 134#endif
135 135
136int udpcksum = 1; 136int udpcksum = 1;
137int udp_do_loopback_cksum = 0; 137int udp_do_loopback_cksum = 0;
138 138
139struct inpcbtable udbtable; 139struct inpcbtable udbtable;
140 140
141percpu_t *udpstat_percpu; 141percpu_t *udpstat_percpu;
142 142
143#ifdef INET 143#ifdef INET
144#ifdef IPSEC 144#ifdef IPSEC
145static int udp4_espinudp (struct mbuf **, int, struct sockaddr *, 145static int udp4_espinudp (struct mbuf **, int, struct sockaddr *,
146 struct socket *); 146 struct socket *);
147#endif 147#endif
148static void udp4_sendup (struct mbuf *, int, struct sockaddr *, 148static void udp4_sendup (struct mbuf *, int, struct sockaddr *,
149 struct socket *); 149 struct socket *);
150static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *, 150static int udp4_realinput (struct sockaddr_in *, struct sockaddr_in *,
151 struct mbuf **, int); 151 struct mbuf **, int);
152static int udp4_input_checksum(struct mbuf *, const struct udphdr *, int, int); 152static int udp4_input_checksum(struct mbuf *, const struct udphdr *, int, int);
153#endif 153#endif
154#ifdef INET 154#ifdef INET
155static void udp_notify (struct inpcb *, int); 155static void udp_notify (struct inpcb *, int);
156#endif 156#endif
157 157
158#ifndef UDBHASHSIZE 158#ifndef UDBHASHSIZE
159#define UDBHASHSIZE 128 159#define UDBHASHSIZE 128
160#endif 160#endif
161int udbhashsize = UDBHASHSIZE; 161int udbhashsize = UDBHASHSIZE;
162 162
163/* 163/*
164 * For send - really max datagram size; for receive - 40 1K datagrams. 164 * For send - really max datagram size; for receive - 40 1K datagrams.
165 */ 165 */
166static int udp_sendspace = 9216; 166static int udp_sendspace = 9216;
167static int udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in)); 167static int udp_recvspace = 40 * (1024 + sizeof(struct sockaddr_in));
168 168
169#ifdef MBUFTRACE 169#ifdef MBUFTRACE
170struct mowner udp_mowner = MOWNER_INIT("udp", ""); 170struct mowner udp_mowner = MOWNER_INIT("udp", "");
171struct mowner udp_rx_mowner = MOWNER_INIT("udp", "rx"); 171struct mowner udp_rx_mowner = MOWNER_INIT("udp", "rx");
172struct mowner udp_tx_mowner = MOWNER_INIT("udp", "tx"); 172struct mowner udp_tx_mowner = MOWNER_INIT("udp", "tx");
173#endif 173#endif
174 174
175#ifdef UDP_CSUM_COUNTERS 175#ifdef UDP_CSUM_COUNTERS
176#include <sys/device.h> 176#include <sys/device.h>
177 177
178#if defined(INET) 178#if defined(INET)
179struct evcnt udp_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, 179struct evcnt udp_hwcsum_bad = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
180 NULL, "udp", "hwcsum bad"); 180 NULL, "udp", "hwcsum bad");
181struct evcnt udp_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, 181struct evcnt udp_hwcsum_ok = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
182 NULL, "udp", "hwcsum ok"); 182 NULL, "udp", "hwcsum ok");
183struct evcnt udp_hwcsum_data = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, 183struct evcnt udp_hwcsum_data = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
184 NULL, "udp", "hwcsum data"); 184 NULL, "udp", "hwcsum data");
185struct evcnt udp_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, 185struct evcnt udp_swcsum = EVCNT_INITIALIZER(EVCNT_TYPE_MISC,
186 NULL, "udp", "swcsum"); 186 NULL, "udp", "swcsum");
187 187
188EVCNT_ATTACH_STATIC(udp_hwcsum_bad); 188EVCNT_ATTACH_STATIC(udp_hwcsum_bad);
189EVCNT_ATTACH_STATIC(udp_hwcsum_ok); 189EVCNT_ATTACH_STATIC(udp_hwcsum_ok);
190EVCNT_ATTACH_STATIC(udp_hwcsum_data); 190EVCNT_ATTACH_STATIC(udp_hwcsum_data);
191EVCNT_ATTACH_STATIC(udp_swcsum); 191EVCNT_ATTACH_STATIC(udp_swcsum);
192#endif /* defined(INET) */ 192#endif /* defined(INET) */
193 193
194#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++ 194#define UDP_CSUM_COUNTER_INCR(ev) (ev)->ev_count++
195#else 195#else
196#define UDP_CSUM_COUNTER_INCR(ev) /* nothing */ 196#define UDP_CSUM_COUNTER_INCR(ev) /* nothing */
197#endif /* UDP_CSUM_COUNTERS */ 197#endif /* UDP_CSUM_COUNTERS */
198 198
199static void sysctl_net_inet_udp_setup(struct sysctllog **); 199static void sysctl_net_inet_udp_setup(struct sysctllog **);
200 200
201static int 201static int
202do_udpinit(void) 202do_udpinit(void)
203{ 203{
204 204
205 in_pcbinit(&udbtable, udbhashsize, udbhashsize); 205 in_pcbinit(&udbtable, udbhashsize, udbhashsize);
206 udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS); 206 udpstat_percpu = percpu_alloc(sizeof(uint64_t) * UDP_NSTATS);
207 207
208 MOWNER_ATTACH(&udp_tx_mowner); 208 MOWNER_ATTACH(&udp_tx_mowner);
209 MOWNER_ATTACH(&udp_rx_mowner); 209 MOWNER_ATTACH(&udp_rx_mowner);
210 MOWNER_ATTACH(&udp_mowner); 210 MOWNER_ATTACH(&udp_mowner);
211 211
212 return 0; 212 return 0;
213} 213}
214 214
215void 215void
216udp_init_common(void) 216udp_init_common(void)
217{ 217{
218 static ONCE_DECL(doudpinit); 218 static ONCE_DECL(doudpinit);
219 219
220 RUN_ONCE(&doudpinit, do_udpinit); 220 RUN_ONCE(&doudpinit, do_udpinit);
221} 221}
222 222
223void 223void
224udp_init(void) 224udp_init(void)
225{ 225{
226 226
227 sysctl_net_inet_udp_setup(NULL); 227 sysctl_net_inet_udp_setup(NULL);
228 228
229 udp_init_common(); 229 udp_init_common();
230} 230}
231 231
232/* 232/*
233 * Checksum extended UDP header and data. 233 * Checksum extended UDP header and data.
234 */ 234 */
235 235
236int 236int
237udp_input_checksum(int af, struct mbuf *m, const struct udphdr *uh, 237udp_input_checksum(int af, struct mbuf *m, const struct udphdr *uh,
238 int iphlen, int len) 238 int iphlen, int len)
239{ 239{
240 240
241 switch (af) { 241 switch (af) {
242#ifdef INET 242#ifdef INET
243 case AF_INET: 243 case AF_INET:
244 return udp4_input_checksum(m, uh, iphlen, len); 244 return udp4_input_checksum(m, uh, iphlen, len);
245#endif 245#endif
246#ifdef INET6 246#ifdef INET6
247 case AF_INET6: 247 case AF_INET6:
248 return udp6_input_checksum(m, uh, iphlen, len); 248 return udp6_input_checksum(m, uh, iphlen, len);
249#endif 249#endif
250 } 250 }
251#ifdef DIAGNOSTIC 251#ifdef DIAGNOSTIC
252 panic("udp_input_checksum: unknown af %d", af); 252 panic("udp_input_checksum: unknown af %d", af);
253#endif 253#endif
254 /* NOTREACHED */ 254 /* NOTREACHED */
255 return -1; 255 return -1;
256} 256}
257 257
258#ifdef INET 258#ifdef INET
259 259
260/* 260/*
261 * Checksum extended UDP header and data. 261 * Checksum extended UDP header and data.
262 */ 262 */
263 263
264static int 264static int
265udp4_input_checksum(struct mbuf *m, const struct udphdr *uh, 265udp4_input_checksum(struct mbuf *m, const struct udphdr *uh,
266 int iphlen, int len) 266 int iphlen, int len)
267{ 267{
268 268
269 /* 269 /*
270 * XXX it's better to record and check if this mbuf is 270 * XXX it's better to record and check if this mbuf is
271 * already checked. 271 * already checked.
272 */ 272 */
273 273
274 if (uh->uh_sum == 0) 274 if (uh->uh_sum == 0)
275 return 0; 275 return 0;
276 276
277 switch (m->m_pkthdr.csum_flags & 277 switch (m->m_pkthdr.csum_flags &
278 ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv4) | 278 ((m->m_pkthdr.rcvif->if_csum_flags_rx & M_CSUM_UDPv4) |
279 M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) { 279 M_CSUM_TCP_UDP_BAD | M_CSUM_DATA)) {
280 case M_CSUM_UDPv4|M_CSUM_TCP_UDP_BAD: 280 case M_CSUM_UDPv4|M_CSUM_TCP_UDP_BAD:
281 UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad); 281 UDP_CSUM_COUNTER_INCR(&udp_hwcsum_bad);
282 goto badcsum; 282 goto badcsum;
283 283
284 case M_CSUM_UDPv4|M_CSUM_DATA: { 284 case M_CSUM_UDPv4|M_CSUM_DATA: {
285 u_int32_t hw_csum = m->m_pkthdr.csum_data; 285 u_int32_t hw_csum = m->m_pkthdr.csum_data;
286 286
287 UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data); 287 UDP_CSUM_COUNTER_INCR(&udp_hwcsum_data);
288 if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR) { 288 if (m->m_pkthdr.csum_flags & M_CSUM_NO_PSEUDOHDR) {
289 const struct ip *ip = 289 const struct ip *ip =
290 mtod(m, const struct ip *); 290 mtod(m, const struct ip *);
291 291
292 hw_csum = in_cksum_phdr(ip->ip_src.s_addr, 292 hw_csum = in_cksum_phdr(ip->ip_src.s_addr,
293 ip->ip_dst.s_addr, 293 ip->ip_dst.s_addr,
294 htons(hw_csum + len + IPPROTO_UDP)); 294 htons(hw_csum + len + IPPROTO_UDP));
295 } 295 }
296 if ((hw_csum ^ 0xffff) != 0) 296 if ((hw_csum ^ 0xffff) != 0)
297 goto badcsum; 297 goto badcsum;
298 break; 298 break;
299 } 299 }
300 300
301 case M_CSUM_UDPv4: 301 case M_CSUM_UDPv4:
302 /* Checksum was okay. */ 302 /* Checksum was okay. */
303 UDP_CSUM_COUNTER_INCR(&udp_hwcsum_ok); 303 UDP_CSUM_COUNTER_INCR(&udp_hwcsum_ok);
304 break; 304 break;
305 305
306 default: 306 default:
307 /* 307 /*
308 * Need to compute it ourselves. Maybe skip checksum 308 * Need to compute it ourselves. Maybe skip checksum
309 * on loopback interfaces. 309 * on loopback interfaces.
310 */ 310 */
311 if (__predict_true(!(m->m_pkthdr.rcvif->if_flags & 311 if (__predict_true(!(m->m_pkthdr.rcvif->if_flags &
312 IFF_LOOPBACK) || 312 IFF_LOOPBACK) ||
313 udp_do_loopback_cksum)) { 313 udp_do_loopback_cksum)) {
314 UDP_CSUM_COUNTER_INCR(&udp_swcsum); 314 UDP_CSUM_COUNTER_INCR(&udp_swcsum);
315 if (in4_cksum(m, IPPROTO_UDP, iphlen, len) != 0) 315 if (in4_cksum(m, IPPROTO_UDP, iphlen, len) != 0)
316 goto badcsum; 316 goto badcsum;
317 } 317 }
318 break; 318 break;
319 } 319 }
320 320
321 return 0; 321 return 0;
322 322
323badcsum: 323badcsum:
324 UDP_STATINC(UDP_STAT_BADSUM); 324 UDP_STATINC(UDP_STAT_BADSUM);
325 return -1; 325 return -1;
326} 326}
327 327
328void 328void
329udp_input(struct mbuf *m, ...) 329udp_input(struct mbuf *m, ...)
330{ 330{
331 va_list ap; 331 va_list ap;
332 struct sockaddr_in src, dst; 332 struct sockaddr_in src, dst;
333 struct ip *ip; 333 struct ip *ip;
334 struct udphdr *uh; 334 struct udphdr *uh;
335 int iphlen; 335 int iphlen;
336 int len; 336 int len;
337 int n; 337 int n;
338 u_int16_t ip_len; 338 u_int16_t ip_len;
339 339
340 va_start(ap, m); 340 va_start(ap, m);
341 iphlen = va_arg(ap, int); 341 iphlen = va_arg(ap, int);
342 (void)va_arg(ap, int); /* ignore value, advance ap */ 342 (void)va_arg(ap, int); /* ignore value, advance ap */
343 va_end(ap); 343 va_end(ap);
344 344
345 MCLAIM(m, &udp_rx_mowner); 345 MCLAIM(m, &udp_rx_mowner);
346 UDP_STATINC(UDP_STAT_IPACKETS); 346 UDP_STATINC(UDP_STAT_IPACKETS);
347 347
348 /* 348 /*
349 * Get IP and UDP header together in first mbuf. 349 * Get IP and UDP header together in first mbuf.
350 */ 350 */
351 ip = mtod(m, struct ip *); 351 ip = mtod(m, struct ip *);
352 IP6_EXTHDR_GET(uh, struct udphdr *, m, iphlen, sizeof(struct udphdr)); 352 IP6_EXTHDR_GET(uh, struct udphdr *, m, iphlen, sizeof(struct udphdr));
353 if (uh == NULL) { 353 if (uh == NULL) {
354 UDP_STATINC(UDP_STAT_HDROPS); 354 UDP_STATINC(UDP_STAT_HDROPS);
355 return; 355 return;
356 } 356 }
357 KASSERT(UDP_HDR_ALIGNED_P(uh)); 357 KASSERT(UDP_HDR_ALIGNED_P(uh));
358 358
359 /* destination port of 0 is illegal, based on RFC768. */ 359 /* destination port of 0 is illegal, based on RFC768. */
360 if (uh->uh_dport == 0) 360 if (uh->uh_dport == 0)
361 goto bad; 361 goto bad;
362 362
363 /* 363 /*
364 * Make mbuf data length reflect UDP length. 364 * Make mbuf data length reflect UDP length.
365 * If not enough data to reflect UDP length, drop. 365 * If not enough data to reflect UDP length, drop.
366 */ 366 */
367 ip_len = ntohs(ip->ip_len); 367 ip_len = ntohs(ip->ip_len);
368 len = ntohs((u_int16_t)uh->uh_ulen); 368 len = ntohs((u_int16_t)uh->uh_ulen);
369 if (ip_len != iphlen + len) { 369 if (ip_len != iphlen + len) {
370 if (ip_len < iphlen + len || len < sizeof(struct udphdr)) { 370 if (ip_len < iphlen + len || len < sizeof(struct udphdr)) {
371 UDP_STATINC(UDP_STAT_BADLEN); 371 UDP_STATINC(UDP_STAT_BADLEN);
372 goto bad; 372 goto bad;
373 } 373 }
374 m_adj(m, iphlen + len - ip_len); 374 m_adj(m, iphlen + len - ip_len);
375 } 375 }
376 376
377 /* 377 /*
378 * Checksum extended UDP header and data. 378 * Checksum extended UDP header and data.
379 */ 379 */
380 if (udp4_input_checksum(m, uh, iphlen, len)) 380 if (udp4_input_checksum(m, uh, iphlen, len))
381 goto badcsum; 381 goto badcsum;
382 382
383 /* construct source and dst sockaddrs. */ 383 /* construct source and dst sockaddrs. */
384 sockaddr_in_init(&src, &ip->ip_src, uh->uh_sport); 384 sockaddr_in_init(&src, &ip->ip_src, uh->uh_sport);
385 sockaddr_in_init(&dst, &ip->ip_dst, uh->uh_dport); 385 sockaddr_in_init(&dst, &ip->ip_dst, uh->uh_dport);
386 386
387 if ((n = udp4_realinput(&src, &dst, &m, iphlen)) == -1) { 387 if ((n = udp4_realinput(&src, &dst, &m, iphlen)) == -1) {
388 UDP_STATINC(UDP_STAT_HDROPS); 388 UDP_STATINC(UDP_STAT_HDROPS);
389 return; 389 return;
390 } 390 }
391 if (m == NULL) { 391 if (m == NULL) {
392 /* 392 /*
393 * packet has been processed by ESP stuff - 393 * packet has been processed by ESP stuff -
394 * e.g. dropped NAT-T-keep-alive-packet ... 394 * e.g. dropped NAT-T-keep-alive-packet ...
395 */ 395 */
396 return; 396 return;
397 } 397 }
 398
398 ip = mtod(m, struct ip *); 399 ip = mtod(m, struct ip *);
 400 IP6_EXTHDR_GET(uh, struct udphdr *, m, iphlen, sizeof(struct udphdr));
 401 if (uh == NULL) {
 402 UDP_STATINC(UDP_STAT_HDROPS);
 403 return;
 404 }
 405 /* XXX Re-enforce alignment? */
 406
399#ifdef INET6 407#ifdef INET6
400 if (IN_MULTICAST(ip->ip_dst.s_addr) || n == 0) { 408 if (IN_MULTICAST(ip->ip_dst.s_addr) || n == 0) {
401 struct sockaddr_in6 src6, dst6; 409 struct sockaddr_in6 src6, dst6;
402 410
403 memset(&src6, 0, sizeof(src6)); 411 memset(&src6, 0, sizeof(src6));
404 src6.sin6_family = AF_INET6; 412 src6.sin6_family = AF_INET6;
405 src6.sin6_len = sizeof(struct sockaddr_in6); 413 src6.sin6_len = sizeof(struct sockaddr_in6);
406 src6.sin6_addr.s6_addr[10] = src6.sin6_addr.s6_addr[11] = 0xff; 414 src6.sin6_addr.s6_addr[10] = src6.sin6_addr.s6_addr[11] = 0xff;
407 memcpy(&src6.sin6_addr.s6_addr[12], &ip->ip_src, 415 memcpy(&src6.sin6_addr.s6_addr[12], &ip->ip_src,
408 sizeof(ip->ip_src)); 416 sizeof(ip->ip_src));
409 src6.sin6_port = uh->uh_sport; 417 src6.sin6_port = uh->uh_sport;
410 memset(&dst6, 0, sizeof(dst6)); 418 memset(&dst6, 0, sizeof(dst6));
411 dst6.sin6_family = AF_INET6; 419 dst6.sin6_family = AF_INET6;
412 dst6.sin6_len = sizeof(struct sockaddr_in6); 420 dst6.sin6_len = sizeof(struct sockaddr_in6);
413 dst6.sin6_addr.s6_addr[10] = dst6.sin6_addr.s6_addr[11] = 0xff; 421 dst6.sin6_addr.s6_addr[10] = dst6.sin6_addr.s6_addr[11] = 0xff;
414 memcpy(&dst6.sin6_addr.s6_addr[12], &ip->ip_dst, 422 memcpy(&dst6.sin6_addr.s6_addr[12], &ip->ip_dst,
415 sizeof(ip->ip_dst)); 423 sizeof(ip->ip_dst));
416 dst6.sin6_port = uh->uh_dport; 424 dst6.sin6_port = uh->uh_dport;
417 425
418 n += udp6_realinput(AF_INET, &src6, &dst6, m, iphlen); 426 n += udp6_realinput(AF_INET, &src6, &dst6, m, iphlen);
419 } 427 }
420#endif 428#endif
421 429
422 if (n == 0) { 430 if (n == 0) {
423 if (m->m_flags & (M_BCAST | M_MCAST)) { 431 if (m->m_flags & (M_BCAST | M_MCAST)) {
424 UDP_STATINC(UDP_STAT_NOPORTBCAST); 432 UDP_STATINC(UDP_STAT_NOPORTBCAST);
425 goto bad; 433 goto bad;
426 } 434 }
427 UDP_STATINC(UDP_STAT_NOPORT); 435 UDP_STATINC(UDP_STAT_NOPORT);
428#ifdef IPKDB 436#ifdef IPKDB
429 if (checkipkdb(&ip->ip_src, uh->uh_sport, uh->uh_dport, 437 if (checkipkdb(&ip->ip_src, uh->uh_sport, uh->uh_dport,
430 m, iphlen + sizeof(struct udphdr), 438 m, iphlen + sizeof(struct udphdr),
431 m->m_pkthdr.len - iphlen - sizeof(struct udphdr))) { 439 m->m_pkthdr.len - iphlen - sizeof(struct udphdr))) {
432 /* 440 /*
433 * It was a debugger connect packet, 441 * It was a debugger connect packet,
434 * just drop it now 442 * just drop it now
435 */ 443 */
436 goto bad; 444 goto bad;
437 } 445 }
438#endif 446#endif
439 icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0); 447 icmp_error(m, ICMP_UNREACH, ICMP_UNREACH_PORT, 0, 0);
440 m = NULL; 448 m = NULL;
441 } 449 }
442 450
443bad: 451bad:
444 if (m) 452 if (m)
445 m_freem(m); 453 m_freem(m);
446 return; 454 return;
447 455
448badcsum: 456badcsum:
449 m_freem(m); 457 m_freem(m);
450} 458}
451#endif 459#endif
452 460
453#ifdef INET 461#ifdef INET
454static void 462static void
455udp4_sendup(struct mbuf *m, int off /* offset of data portion */, 463udp4_sendup(struct mbuf *m, int off /* offset of data portion */,
456 struct sockaddr *src, struct socket *so) 464 struct sockaddr *src, struct socket *so)
457{ 465{
458 struct mbuf *opts = NULL; 466 struct mbuf *opts = NULL;
459 struct mbuf *n; 467 struct mbuf *n;
460 struct inpcb *inp = NULL; 468 struct inpcb *inp = NULL;
461 469
462 if (!so) 470 if (!so)
463 return; 471 return;
464 switch (so->so_proto->pr_domain->dom_family) { 472 switch (so->so_proto->pr_domain->dom_family) {
465 case AF_INET: 473 case AF_INET:
466 inp = sotoinpcb(so); 474 inp = sotoinpcb(so);
467 break; 475 break;
468#ifdef INET6 476#ifdef INET6
469 case AF_INET6: 477 case AF_INET6:
470 break; 478 break;
471#endif 479#endif
472 default: 480 default:
473 return; 481 return;
474 } 482 }
475 483
476#if defined(IPSEC) 484#if defined(IPSEC)
477 /* check AH/ESP integrity. */ 485 /* check AH/ESP integrity. */
478 if (ipsec_used && so != NULL && ipsec4_in_reject_so(m, so)) { 486 if (ipsec_used && so != NULL && ipsec4_in_reject_so(m, so)) {
479 IPSEC_STATINC(IPSEC_STAT_IN_POLVIO); 487 IPSEC_STATINC(IPSEC_STAT_IN_POLVIO);
480 if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) 488 if ((n = m_copypacket(m, M_DONTWAIT)) != NULL)
481 icmp_error(n, ICMP_UNREACH, ICMP_UNREACH_ADMIN_PROHIBIT, 489 icmp_error(n, ICMP_UNREACH, ICMP_UNREACH_ADMIN_PROHIBIT,
482 0, 0); 490 0, 0);
483 return; 491 return;
484 } 492 }
485#endif /*IPSEC*/ 493#endif /*IPSEC*/
486 494
487 if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) { 495 if ((n = m_copypacket(m, M_DONTWAIT)) != NULL) {
488 if (inp && (inp->inp_flags & INP_CONTROLOPTS 496 if (inp && (inp->inp_flags & INP_CONTROLOPTS
489#ifdef SO_OTIMESTAMP 497#ifdef SO_OTIMESTAMP
490 || so->so_options & SO_OTIMESTAMP 498 || so->so_options & SO_OTIMESTAMP
491#endif 499#endif
492 || so->so_options & SO_TIMESTAMP)) { 500 || so->so_options & SO_TIMESTAMP)) {
493 struct ip *ip = mtod(n, struct ip *); 501 struct ip *ip = mtod(n, struct ip *);
494 ip_savecontrol(inp, &opts, ip, n); 502 ip_savecontrol(inp, &opts, ip, n);
495 } 503 }
496 504
497 m_adj(n, off); 505 m_adj(n, off);
498 if (sbappendaddr(&so->so_rcv, src, n, 506 if (sbappendaddr(&so->so_rcv, src, n,
499 opts) == 0) { 507 opts) == 0) {
500 m_freem(n); 508 m_freem(n);
501 if (opts) 509 if (opts)
502 m_freem(opts); 510 m_freem(opts);
503 so->so_rcv.sb_overflowed++; 511 so->so_rcv.sb_overflowed++;
504 UDP_STATINC(UDP_STAT_FULLSOCK); 512 UDP_STATINC(UDP_STAT_FULLSOCK);
505 } else 513 } else
506 sorwakeup(so); 514 sorwakeup(so);
507 } 515 }
508} 516}
509#endif 517#endif
510 518
511#ifdef INET 519#ifdef INET
512static int 520static int
513udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst, 521udp4_realinput(struct sockaddr_in *src, struct sockaddr_in *dst,
514 struct mbuf **mp, int off /* offset of udphdr */) 522 struct mbuf **mp, int off /* offset of udphdr */)
515{ 523{
516 u_int16_t *sport, *dport; 524 u_int16_t *sport, *dport;
517 int rcvcnt; 525 int rcvcnt;
518 struct in_addr *src4, *dst4; 526 struct in_addr *src4, *dst4;
519 struct inpcb_hdr *inph; 527 struct inpcb_hdr *inph;
520 struct inpcb *inp; 528 struct inpcb *inp;
521 struct mbuf *m = *mp; 529 struct mbuf *m = *mp;
522 530
523 rcvcnt = 0; 531 rcvcnt = 0;
524 off += sizeof(struct udphdr); /* now, offset of payload */ 532 off += sizeof(struct udphdr); /* now, offset of payload */
525 533
526 if (src->sin_family != AF_INET || dst->sin_family != AF_INET) 534 if (src->sin_family != AF_INET || dst->sin_family != AF_INET)
527 goto bad; 535 goto bad;
528 536
529 src4 = &src->sin_addr; 537 src4 = &src->sin_addr;
530 sport = &src->sin_port; 538 sport = &src->sin_port;
531 dst4 = &dst->sin_addr; 539 dst4 = &dst->sin_addr;
532 dport = &dst->sin_port; 540 dport = &dst->sin_port;
533 541
534 if (IN_MULTICAST(dst4->s_addr) || 542 if (IN_MULTICAST(dst4->s_addr) ||
535 in_broadcast(*dst4, m->m_pkthdr.rcvif)) { 543 in_broadcast(*dst4, m->m_pkthdr.rcvif)) {
536 /* 544 /*
537 * Deliver a multicast or broadcast datagram to *all* sockets 545 * Deliver a multicast or broadcast datagram to *all* sockets
538 * for which the local and remote addresses and ports match 546 * for which the local and remote addresses and ports match
539 * those of the incoming datagram. This allows more than 547 * those of the incoming datagram. This allows more than
540 * one process to receive multi/broadcasts on the same port. 548 * one process to receive multi/broadcasts on the same port.
541 * (This really ought to be done for unicast datagrams as 549 * (This really ought to be done for unicast datagrams as
542 * well, but that would cause problems with existing 550 * well, but that would cause problems with existing
543 * applications that open both address-specific sockets and 551 * applications that open both address-specific sockets and
544 * a wildcard socket listening to the same port -- they would 552 * a wildcard socket listening to the same port -- they would
545 * end up receiving duplicates of every unicast datagram. 553 * end up receiving duplicates of every unicast datagram.
546 * Those applications open the multiple sockets to overcome an 554 * Those applications open the multiple sockets to overcome an
547 * inadequacy of the UDP socket interface, but for backwards 555 * inadequacy of the UDP socket interface, but for backwards
548 * compatibility we avoid the problem here rather than 556 * compatibility we avoid the problem here rather than
549 * fixing the interface. Maybe 4.5BSD will remedy this?) 557 * fixing the interface. Maybe 4.5BSD will remedy this?)
550 */ 558 */
551 559
552 /* 560 /*
553 * KAME note: traditionally we dropped udpiphdr from mbuf here. 561 * KAME note: traditionally we dropped udpiphdr from mbuf here.
554 * we need udpiphdr for IPsec processing so we do that later. 562 * we need udpiphdr for IPsec processing so we do that later.
555 */ 563 */
556 /* 564 /*
557 * Locate pcb(s) for datagram. 565 * Locate pcb(s) for datagram.
558 */ 566 */
559 TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) { 567 TAILQ_FOREACH(inph, &udbtable.inpt_queue, inph_queue) {
560 inp = (struct inpcb *)inph; 568 inp = (struct inpcb *)inph;
561 if (inp->inp_af != AF_INET) 569 if (inp->inp_af != AF_INET)
562 continue; 570 continue;
563 571
564 if (inp->inp_lport != *dport) 572 if (inp->inp_lport != *dport)
565 continue; 573 continue;
566 if (!in_nullhost(inp->inp_laddr)) { 574 if (!in_nullhost(inp->inp_laddr)) {
567 if (!in_hosteq(inp->inp_laddr, *dst4)) 575 if (!in_hosteq(inp->inp_laddr, *dst4))
568 continue; 576 continue;
569 } 577 }
570 if (!in_nullhost(inp->inp_faddr)) { 578 if (!in_nullhost(inp->inp_faddr)) {
571 if (!in_hosteq(inp->inp_faddr, *src4) || 579 if (!in_hosteq(inp->inp_faddr, *src4) ||
572 inp->inp_fport != *sport) 580 inp->inp_fport != *sport)
573 continue; 581 continue;
574 } 582 }
575 583
576 udp4_sendup(m, off, (struct sockaddr *)src, 584 udp4_sendup(m, off, (struct sockaddr *)src,
577 inp->inp_socket); 585 inp->inp_socket);
578 rcvcnt++; 586 rcvcnt++;
579 587
580 /* 588 /*
581 * Don't look for additional matches if this one does 589 * Don't look for additional matches if this one does
582 * not have either the SO_REUSEPORT or SO_REUSEADDR 590 * not have either the SO_REUSEPORT or SO_REUSEADDR
583 * socket options set. This heuristic avoids searching 591 * socket options set. This heuristic avoids searching
584 * through all pcbs in the common case of a non-shared 592 * through all pcbs in the common case of a non-shared
585 * port. It assumes that an application will never 593 * port. It assumes that an application will never
586 * clear these options after setting them. 594 * clear these options after setting them.
587 */ 595 */
588 if ((inp->inp_socket->so_options & 596 if ((inp->inp_socket->so_options &
589 (SO_REUSEPORT|SO_REUSEADDR)) == 0) 597 (SO_REUSEPORT|SO_REUSEADDR)) == 0)
590 break; 598 break;
591 } 599 }
592 } else { 600 } else {
593 /* 601 /*
594 * Locate pcb for datagram. 602 * Locate pcb for datagram.
595 */ 603 */
596 inp = in_pcblookup_connect(&udbtable, *src4, *sport, *dst4, 604 inp = in_pcblookup_connect(&udbtable, *src4, *sport, *dst4,
597 *dport, 0); 605 *dport, 0);
598 if (inp == 0) { 606 if (inp == 0) {
599 UDP_STATINC(UDP_STAT_PCBHASHMISS); 607 UDP_STATINC(UDP_STAT_PCBHASHMISS);
600 inp = in_pcblookup_bind(&udbtable, *dst4, *dport); 608 inp = in_pcblookup_bind(&udbtable, *dst4, *dport);
601 if (inp == 0) 609 if (inp == 0)
602 return rcvcnt; 610 return rcvcnt;
603 } 611 }
604 612
605#ifdef IPSEC 613#ifdef IPSEC
606 /* Handle ESP over UDP */ 614 /* Handle ESP over UDP */
607 if (inp->inp_flags & INP_ESPINUDP_ALL) { 615 if (inp->inp_flags & INP_ESPINUDP_ALL) {
608 struct sockaddr *sa = (struct sockaddr *)src; 616 struct sockaddr *sa = (struct sockaddr *)src;
609 617
610 switch(udp4_espinudp(mp, off, sa, inp->inp_socket)) { 618 switch(udp4_espinudp(mp, off, sa, inp->inp_socket)) {
611 case -1: /* Error, m was freeed */ 619 case -1: /* Error, m was freeed */
612 rcvcnt = -1; 620 rcvcnt = -1;
613 goto bad; 621 goto bad;
614 break; 622 break;
615 623
616 case 1: /* ESP over UDP */ 624 case 1: /* ESP over UDP */
617 rcvcnt++; 625 rcvcnt++;
618 goto bad; 626 goto bad;
619 break; 627 break;
620 628
621 case 0: /* plain UDP */ 629 case 0: /* plain UDP */
622 default: /* Unexpected */ 630 default: /* Unexpected */
623 /*  631 /*
624 * Normal UDP processing will take place  632 * Normal UDP processing will take place
625 * m may have changed. 633 * m may have changed.
626 */ 634 */
627 m = *mp; 635 m = *mp;
628 break; 636 break;
629 } 637 }
630 } 638 }
631#endif 639#endif
632 640
633 /* 641 /*
634 * Check the minimum TTL for socket. 642 * Check the minimum TTL for socket.
635 */ 643 */
636 if (mtod(m, struct ip *)->ip_ttl < inp->inp_ip_minttl) 644 if (mtod(m, struct ip *)->ip_ttl < inp->inp_ip_minttl)
637 goto bad; 645 goto bad;
638 646
639 udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket); 647 udp4_sendup(m, off, (struct sockaddr *)src, inp->inp_socket);
640 rcvcnt++; 648 rcvcnt++;
641 } 649 }
642 650
643bad: 651bad:
644 return rcvcnt; 652 return rcvcnt;
645} 653}
646#endif 654#endif
647 655
648#ifdef INET 656#ifdef INET
649/* 657/*
650 * Notify a udp user of an asynchronous error; 658 * Notify a udp user of an asynchronous error;
651 * just wake up so that he can collect error status. 659 * just wake up so that he can collect error status.
652 */ 660 */
653static void 661static void
654udp_notify(struct inpcb *inp, int errno) 662udp_notify(struct inpcb *inp, int errno)
655{ 663{
656 inp->inp_socket->so_error = errno; 664 inp->inp_socket->so_error = errno;
657 sorwakeup(inp->inp_socket); 665 sorwakeup(inp->inp_socket);
658 sowwakeup(inp->inp_socket); 666 sowwakeup(inp->inp_socket);
659} 667}
660 668
661void * 669void *
662udp_ctlinput(int cmd, const struct sockaddr *sa, void *v) 670udp_ctlinput(int cmd, const struct sockaddr *sa, void *v)
663{ 671{
664 struct ip *ip = v; 672 struct ip *ip = v;
665 struct udphdr *uh; 673 struct udphdr *uh;
666 void (*notify)(struct inpcb *, int) = udp_notify; 674 void (*notify)(struct inpcb *, int) = udp_notify;
667 int errno; 675 int errno;
668 676
669 if (sa->sa_family != AF_INET 677 if (sa->sa_family != AF_INET
670 || sa->sa_len != sizeof(struct sockaddr_in)) 678 || sa->sa_len != sizeof(struct sockaddr_in))
671 return NULL; 679 return NULL;
672 if ((unsigned)cmd >= PRC_NCMDS) 680 if ((unsigned)cmd >= PRC_NCMDS)
673 return NULL; 681 return NULL;
674 errno = inetctlerrmap[cmd]; 682 errno = inetctlerrmap[cmd];
675 if (PRC_IS_REDIRECT(cmd)) 683 if (PRC_IS_REDIRECT(cmd))
676 notify = in_rtchange, ip = 0; 684 notify = in_rtchange, ip = 0;
677 else if (cmd == PRC_HOSTDEAD) 685 else if (cmd == PRC_HOSTDEAD)
678 ip = 0; 686 ip = 0;
679 else if (errno == 0) 687 else if (errno == 0)
680 return NULL; 688 return NULL;
681 if (ip) { 689 if (ip) {
682 uh = (struct udphdr *)((char *)ip + (ip->ip_hl << 2)); 690 uh = (struct udphdr *)((char *)ip + (ip->ip_hl << 2));
683 in_pcbnotify(&udbtable, satocsin(sa)->sin_addr, uh->uh_dport, 691 in_pcbnotify(&udbtable, satocsin(sa)->sin_addr, uh->uh_dport,
684 ip->ip_src, uh->uh_sport, errno, notify); 692 ip->ip_src, uh->uh_sport, errno, notify);
685 693
686 /* XXX mapped address case */ 694 /* XXX mapped address case */
687 } else 695 } else
688 in_pcbnotifyall(&udbtable, satocsin(sa)->sin_addr, errno, 696 in_pcbnotifyall(&udbtable, satocsin(sa)->sin_addr, errno,
689 notify); 697 notify);
690 return NULL; 698 return NULL;
691} 699}
692 700
693int 701int
694udp_ctloutput(int op, struct socket *so, struct sockopt *sopt) 702udp_ctloutput(int op, struct socket *so, struct sockopt *sopt)
695{ 703{
696 int s; 704 int s;
697 int error = 0; 705 int error = 0;
698 struct inpcb *inp; 706 struct inpcb *inp;
699 int family; 707 int family;
700 int optval; 708 int optval;
701 709
702 family = so->so_proto->pr_domain->dom_family; 710 family = so->so_proto->pr_domain->dom_family;
703 711
704 s = splsoftnet(); 712 s = splsoftnet();
705 switch (family) { 713 switch (family) {
706#ifdef INET 714#ifdef INET
707 case PF_INET: 715 case PF_INET:
708 if (sopt->sopt_level != IPPROTO_UDP) { 716 if (sopt->sopt_level != IPPROTO_UDP) {
709 error = ip_ctloutput(op, so, sopt); 717 error = ip_ctloutput(op, so, sopt);
710 goto end; 718 goto end;
711 } 719 }
712 break; 720 break;
713#endif 721#endif
714#ifdef INET6 722#ifdef INET6
715 case PF_INET6: 723 case PF_INET6:
716 if (sopt->sopt_level != IPPROTO_UDP) { 724 if (sopt->sopt_level != IPPROTO_UDP) {
717 error = ip6_ctloutput(op, so, sopt); 725 error = ip6_ctloutput(op, so, sopt);
718 goto end; 726 goto end;
719 } 727 }
720 break; 728 break;
721#endif 729#endif
722 default: 730 default:
723 error = EAFNOSUPPORT; 731 error = EAFNOSUPPORT;
724 goto end; 732 goto end;
725 } 733 }
726 734
727 735
728 switch (op) { 736 switch (op) {
729 case PRCO_SETOPT: 737 case PRCO_SETOPT:
730 inp = sotoinpcb(so); 738 inp = sotoinpcb(so);
731 739
732 switch (sopt->sopt_name) { 740 switch (sopt->sopt_name) {
733 case UDP_ENCAP: 741 case UDP_ENCAP:
734 error = sockopt_getint(sopt, &optval); 742 error = sockopt_getint(sopt, &optval);
735 if (error) 743 if (error)
736 break; 744 break;
737 745
738 switch(optval) { 746 switch(optval) {
739 case 0: 747 case 0:
740 inp->inp_flags &= ~INP_ESPINUDP_ALL; 748 inp->inp_flags &= ~INP_ESPINUDP_ALL;
741 break; 749 break;
742 750
743 case UDP_ENCAP_ESPINUDP: 751 case UDP_ENCAP_ESPINUDP:
744 inp->inp_flags &= ~INP_ESPINUDP_ALL; 752 inp->inp_flags &= ~INP_ESPINUDP_ALL;
745 inp->inp_flags |= INP_ESPINUDP; 753 inp->inp_flags |= INP_ESPINUDP;
746 break; 754 break;
747 755
748 case UDP_ENCAP_ESPINUDP_NON_IKE: 756 case UDP_ENCAP_ESPINUDP_NON_IKE:
749 inp->inp_flags &= ~INP_ESPINUDP_ALL; 757 inp->inp_flags &= ~INP_ESPINUDP_ALL;
750 inp->inp_flags |= INP_ESPINUDP_NON_IKE; 758 inp->inp_flags |= INP_ESPINUDP_NON_IKE;
751 break; 759 break;
752 default: 760 default:
753 error = EINVAL; 761 error = EINVAL;
754 break; 762 break;
755 } 763 }
756 break; 764 break;
757  765
758 default: 766 default:
759 error = ENOPROTOOPT; 767 error = ENOPROTOOPT;
760 break; 768 break;
761 } 769 }
762 break; 770 break;
763 771
764 default: 772 default:
765 error = EINVAL; 773 error = EINVAL;
766 break; 774 break;
767 } 775 }
768 776
769end: 777end:
770 splx(s); 778 splx(s);
771 return error; 779 return error;
772} 780}
773 781
774 782
775int 783int
776udp_output(struct mbuf *m, ...) 784udp_output(struct mbuf *m, ...)
777{ 785{
778 struct inpcb *inp; 786 struct inpcb *inp;
779 struct udpiphdr *ui; 787 struct udpiphdr *ui;
780 struct route *ro; 788 struct route *ro;
781 int len = m->m_pkthdr.len; 789 int len = m->m_pkthdr.len;
782 int error = 0; 790 int error = 0;
783 va_list ap; 791 va_list ap;
784 792
785 MCLAIM(m, &udp_tx_mowner); 793 MCLAIM(m, &udp_tx_mowner);
786 va_start(ap, m); 794 va_start(ap, m);
787 inp = va_arg(ap, struct inpcb *); 795 inp = va_arg(ap, struct inpcb *);
788 va_end(ap); 796 va_end(ap);
789 797
790 /* 798 /*
791 * Calculate data length and get a mbuf 799 * Calculate data length and get a mbuf
792 * for UDP and IP headers. 800 * for UDP and IP headers.
793 */ 801 */
794 M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT); 802 M_PREPEND(m, sizeof(struct udpiphdr), M_DONTWAIT);
795 if (m == 0) { 803 if (m == 0) {
796 error = ENOBUFS; 804 error = ENOBUFS;
797 goto release; 805 goto release;
798 } 806 }
799 807
800 /* 808 /*
801 * Compute the packet length of the IP header, and 809 * Compute the packet length of the IP header, and
802 * punt if the length looks bogus. 810 * punt if the length looks bogus.
803 */ 811 */
804 if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) { 812 if (len + sizeof(struct udpiphdr) > IP_MAXPACKET) {
805 error = EMSGSIZE; 813 error = EMSGSIZE;
806 goto release; 814 goto release;
807 } 815 }
808 816
809 /* 817 /*
810 * Fill in mbuf with extended UDP header 818 * Fill in mbuf with extended UDP header
811 * and addresses and length put into network format. 819 * and addresses and length put into network format.
812 */ 820 */
813 ui = mtod(m, struct udpiphdr *); 821 ui = mtod(m, struct udpiphdr *);
814 ui->ui_pr = IPPROTO_UDP; 822 ui->ui_pr = IPPROTO_UDP;
815 ui->ui_src = inp->inp_laddr; 823 ui->ui_src = inp->inp_laddr;
816 ui->ui_dst = inp->inp_faddr; 824 ui->ui_dst = inp->inp_faddr;
817 ui->ui_sport = inp->inp_lport; 825 ui->ui_sport = inp->inp_lport;
818 ui->ui_dport = inp->inp_fport; 826 ui->ui_dport = inp->inp_fport;
819 ui->ui_ulen = htons((u_int16_t)len + sizeof(struct udphdr)); 827 ui->ui_ulen = htons((u_int16_t)len + sizeof(struct udphdr));
820 828
821 ro = &inp->inp_route; 829 ro = &inp->inp_route;
822 830
823 /* 831 /*
824 * Set up checksum and output datagram. 832 * Set up checksum and output datagram.
825 */ 833 */
826 if (udpcksum) { 834 if (udpcksum) {
827 /* 835 /*
828 * XXX Cache pseudo-header checksum part for 836 * XXX Cache pseudo-header checksum part for
829 * XXX "connected" UDP sockets. 837 * XXX "connected" UDP sockets.
830 */ 838 */
831 ui->ui_sum = in_cksum_phdr(ui->ui_src.s_addr, 839 ui->ui_sum = in_cksum_phdr(ui->ui_src.s_addr,
832 ui->ui_dst.s_addr, htons((u_int16_t)len + 840 ui->ui_dst.s_addr, htons((u_int16_t)len +
833 sizeof(struct udphdr) + IPPROTO_UDP)); 841 sizeof(struct udphdr) + IPPROTO_UDP));
834 m->m_pkthdr.csum_flags = M_CSUM_UDPv4; 842 m->m_pkthdr.csum_flags = M_CSUM_UDPv4;
835 m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum); 843 m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
836 } else 844 } else
837 ui->ui_sum = 0; 845 ui->ui_sum = 0;
838 ((struct ip *)ui)->ip_len = htons(sizeof (struct udpiphdr) + len); 846 ((struct ip *)ui)->ip_len = htons(sizeof (struct udpiphdr) + len);
839 ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */ 847 ((struct ip *)ui)->ip_ttl = inp->inp_ip.ip_ttl; /* XXX */
840 ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */ 848 ((struct ip *)ui)->ip_tos = inp->inp_ip.ip_tos; /* XXX */
841 UDP_STATINC(UDP_STAT_OPACKETS); 849 UDP_STATINC(UDP_STAT_OPACKETS);
842 850
843 return (ip_output(m, inp->inp_options, ro, 851 return (ip_output(m, inp->inp_options, ro,
844 inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST), 852 inp->inp_socket->so_options & (SO_DONTROUTE | SO_BROADCAST),
845 inp->inp_moptions, inp->inp_socket)); 853 inp->inp_moptions, inp->inp_socket));
846 854
847release: 855release:
848 m_freem(m); 856 m_freem(m);
849 return (error); 857 return (error);
850} 858}
851 859
852static int 860static int
853udp_attach(struct socket *so, int proto) 861udp_attach(struct socket *so, int proto)
854{ 862{
855 struct inpcb *inp; 863 struct inpcb *inp;
856 int error; 864 int error;
857 865
858 KASSERT(sotoinpcb(so) == NULL); 866 KASSERT(sotoinpcb(so) == NULL);
859 867
860 /* Assign the lock (must happen even if we will error out). */ 868 /* Assign the lock (must happen even if we will error out). */
861 sosetlock(so); 869 sosetlock(so);
862 870
863#ifdef MBUFTRACE 871#ifdef MBUFTRACE
864 so->so_mowner = &udp_mowner; 872 so->so_mowner = &udp_mowner;
865 so->so_rcv.sb_mowner = &udp_rx_mowner; 873 so->so_rcv.sb_mowner = &udp_rx_mowner;
866 so->so_snd.sb_mowner = &udp_tx_mowner; 874 so->so_snd.sb_mowner = &udp_tx_mowner;
867#endif 875#endif
868 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) { 876 if (so->so_snd.sb_hiwat == 0 || so->so_rcv.sb_hiwat == 0) {
869 error = soreserve(so, udp_sendspace, udp_recvspace); 877 error = soreserve(so, udp_sendspace, udp_recvspace);
870 if (error) { 878 if (error) {
871 return error; 879 return error;
872 } 880 }
873 } 881 }
874 882
875 error = in_pcballoc(so, &udbtable); 883 error = in_pcballoc(so, &udbtable);
876 if (error) { 884 if (error) {
877 return error; 885 return error;
878 } 886 }
879 inp = sotoinpcb(so); 887 inp = sotoinpcb(so);
880 inp->inp_ip.ip_ttl = ip_defttl; 888 inp->inp_ip.ip_ttl = ip_defttl;
881 KASSERT(solocked(so)); 889 KASSERT(solocked(so));
882 890
883 return error; 891 return error;
884} 892}
885 893
886static void 894static void
887udp_detach(struct socket *so) 895udp_detach(struct socket *so)
888{ 896{
889 struct inpcb *inp; 897 struct inpcb *inp;
890 898
891 KASSERT(solocked(so)); 899 KASSERT(solocked(so));
892 inp = sotoinpcb(so); 900 inp = sotoinpcb(so);
893 KASSERT(inp != NULL); 901 KASSERT(inp != NULL);
894 in_pcbdetach(inp); 902 in_pcbdetach(inp);
895} 903}
896 904
897static int 905static int
898udp_accept(struct socket *so, struct mbuf *nam) 906udp_accept(struct socket *so, struct mbuf *nam)
899{ 907{
900 KASSERT(solocked(so)); 908 KASSERT(solocked(so));
901 909
902 panic("udp_accept"); 910 panic("udp_accept");
903 911
904 return EOPNOTSUPP; 912 return EOPNOTSUPP;
905} 913}
906 914
907static int 915static int
908udp_bind(struct socket *so, struct mbuf *nam, struct lwp *l) 916udp_bind(struct socket *so, struct mbuf *nam, struct lwp *l)
909{ 917{
910 struct inpcb *inp = sotoinpcb(so); 918 struct inpcb *inp = sotoinpcb(so);
911 int error = 0; 919 int error = 0;
912 int s; 920 int s;
913 921
914 KASSERT(solocked(so)); 922 KASSERT(solocked(so));
915 KASSERT(inp != NULL); 923 KASSERT(inp != NULL);
916 KASSERT(nam != NULL); 924 KASSERT(nam != NULL);
917 925
918 s = splsoftnet(); 926 s = splsoftnet();
919 error = in_pcbbind(inp, nam, l); 927 error = in_pcbbind(inp, nam, l);
920 splx(s); 928 splx(s);
921 929
922 return error; 930 return error;
923} 931}
924 932
925static int 933static int
926udp_listen(struct socket *so, struct lwp *l) 934udp_listen(struct socket *so, struct lwp *l)
927{ 935{
928 KASSERT(solocked(so)); 936 KASSERT(solocked(so));
929 937
930 return EOPNOTSUPP; 938 return EOPNOTSUPP;
931} 939}
932 940
933static int 941static int
934udp_connect(struct socket *so, struct mbuf *nam, struct lwp *l) 942udp_connect(struct socket *so, struct mbuf *nam, struct lwp *l)
935{ 943{
936 struct inpcb *inp = sotoinpcb(so); 944 struct inpcb *inp = sotoinpcb(so);
937 int error = 0; 945 int error = 0;
938 int s; 946 int s;
939 947
940 KASSERT(solocked(so)); 948 KASSERT(solocked(so));
941 KASSERT(inp != NULL); 949 KASSERT(inp != NULL);
942 KASSERT(nam != NULL); 950 KASSERT(nam != NULL);
943 951
944 s = splsoftnet(); 952 s = splsoftnet();
945 error = in_pcbconnect(inp, nam, l); 953 error = in_pcbconnect(inp, nam, l);
946 if (! error) 954 if (! error)
947 soisconnected(so); 955 soisconnected(so);
948 splx(s); 956 splx(s);
949 return error; 957 return error;
950} 958}
951 959
952static int 960static int
953udp_connect2(struct socket *so, struct socket *so2) 961udp_connect2(struct socket *so, struct socket *so2)
954{ 962{
955 KASSERT(solocked(so)); 963 KASSERT(solocked(so));
956 964
957 return EOPNOTSUPP; 965 return EOPNOTSUPP;
958} 966}
959 967
960static int 968static int
961udp_disconnect(struct socket *so) 969udp_disconnect(struct socket *so)
962{ 970{
963 struct inpcb *inp = sotoinpcb(so); 971 struct inpcb *inp = sotoinpcb(so);
964 int s; 972 int s;
965 973
966 KASSERT(solocked(so)); 974 KASSERT(solocked(so));
967 KASSERT(inp != NULL); 975 KASSERT(inp != NULL);
968 976
969 s = splsoftnet(); 977 s = splsoftnet();
970 /*soisdisconnected(so);*/ 978 /*soisdisconnected(so);*/
971 so->so_state &= ~SS_ISCONNECTED; /* XXX */ 979 so->so_state &= ~SS_ISCONNECTED; /* XXX */
972 in_pcbdisconnect(inp); 980 in_pcbdisconnect(inp);
973 inp->inp_laddr = zeroin_addr; /* XXX */ 981 inp->inp_laddr = zeroin_addr; /* XXX */
974 in_pcbstate(inp, INP_BOUND); /* XXX */ 982 in_pcbstate(inp, INP_BOUND); /* XXX */
975 splx(s); 983 splx(s);
976 984
977 return 0; 985 return 0;
978} 986}
979 987
980static int 988static int
981udp_shutdown(struct socket *so) 989udp_shutdown(struct socket *so)
982{ 990{
983 int s; 991 int s;
984 992
985 KASSERT(solocked(so)); 993 KASSERT(solocked(so));
986 994
987 s = splsoftnet(); 995 s = splsoftnet();
988 socantsendmore(so); 996 socantsendmore(so);
989 splx(s); 997 splx(s);
990 998
991 return 0; 999 return 0;
992} 1000}
993 1001
994static int 1002static int
995udp_abort(struct socket *so) 1003udp_abort(struct socket *so)
996{ 1004{
997 KASSERT(solocked(so)); 1005 KASSERT(solocked(so));
998 1006
999 panic("udp_abort"); 1007 panic("udp_abort");
1000 1008
1001 return EOPNOTSUPP; 1009 return EOPNOTSUPP;
1002} 1010}
1003 1011
1004static int 1012static int
1005udp_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp) 1013udp_ioctl(struct socket *so, u_long cmd, void *nam, struct ifnet *ifp)
1006{ 1014{
1007 return in_control(so, cmd, nam, ifp); 1015 return in_control(so, cmd, nam, ifp);
1008} 1016}
1009 1017
1010static int 1018static int
1011udp_stat(struct socket *so, struct stat *ub) 1019udp_stat(struct socket *so, struct stat *ub)
1012{ 1020{
1013 KASSERT(solocked(so)); 1021 KASSERT(solocked(so));
1014 1022
1015 /* stat: don't bother with a blocksize. */ 1023 /* stat: don't bother with a blocksize. */
1016 return 0; 1024 return 0;
1017} 1025}
1018 1026
1019static int 1027static int
1020udp_peeraddr(struct socket *so, struct mbuf *nam) 1028udp_peeraddr(struct socket *so, struct mbuf *nam)
1021{ 1029{
1022 int s; 1030 int s;
1023 1031
1024 KASSERT(solocked(so)); 1032 KASSERT(solocked(so));
1025 KASSERT(sotoinpcb(so) != NULL); 1033 KASSERT(sotoinpcb(so) != NULL);
1026 KASSERT(nam != NULL); 1034 KASSERT(nam != NULL);
1027 1035
1028 s = splsoftnet(); 1036 s = splsoftnet();
1029 in_setpeeraddr(sotoinpcb(so), nam); 1037 in_setpeeraddr(sotoinpcb(so), nam);
1030 splx(s); 1038 splx(s);
1031 1039
1032 return 0; 1040 return 0;
1033} 1041}
1034 1042
1035static int 1043static int
1036udp_sockaddr(struct socket *so, struct mbuf *nam) 1044udp_sockaddr(struct socket *so, struct mbuf *nam)
1037{ 1045{
1038 int s; 1046 int s;
1039 1047
1040 KASSERT(solocked(so)); 1048 KASSERT(solocked(so));
1041 KASSERT(sotoinpcb(so) != NULL); 1049 KASSERT(sotoinpcb(so) != NULL);
1042 KASSERT(nam != NULL); 1050 KASSERT(nam != NULL);
1043 1051
1044 s = splsoftnet(); 1052 s = splsoftnet();
1045 in_setsockaddr(sotoinpcb(so), nam); 1053 in_setsockaddr(sotoinpcb(so), nam);
1046 splx(s); 1054 splx(s);
1047 1055
1048 return 0; 1056 return 0;
1049} 1057}
1050 1058
1051static int 1059static int
1052udp_rcvd(struct socket *so, int flags, struct lwp *l) 1060udp_rcvd(struct socket *so, int flags, struct lwp *l)
1053{ 1061{
1054 KASSERT(solocked(so)); 1062 KASSERT(solocked(so));
1055 1063
1056 return EOPNOTSUPP; 1064 return EOPNOTSUPP;
1057} 1065}
1058 1066
1059static int 1067static int
1060udp_recvoob(struct socket *so, struct mbuf *m, int flags) 1068udp_recvoob(struct socket *so, struct mbuf *m, int flags)
1061{ 1069{
1062 KASSERT(solocked(so)); 1070 KASSERT(solocked(so));
1063 1071
1064 return EOPNOTSUPP; 1072 return EOPNOTSUPP;
1065} 1073}
1066 1074
1067static int 1075static int
1068udp_send(struct socket *so, struct mbuf *m, struct mbuf *nam, 1076udp_send(struct socket *so, struct mbuf *m, struct mbuf *nam,
1069 struct mbuf *control, struct lwp *l) 1077 struct mbuf *control, struct lwp *l)
1070{ 1078{
1071 struct inpcb *inp = sotoinpcb(so); 1079 struct inpcb *inp = sotoinpcb(so);
1072 int error = 0; 1080 int error = 0;
1073 struct in_addr laddr; /* XXX */ 1081 struct in_addr laddr; /* XXX */
1074 int s; 1082 int s;
1075 1083
1076 KASSERT(solocked(so)); 1084 KASSERT(solocked(so));
1077 KASSERT(inp != NULL); 1085 KASSERT(inp != NULL);
1078 KASSERT(m != NULL); 1086 KASSERT(m != NULL);
1079 1087
1080 if (control && control->m_len) { 1088 if (control && control->m_len) {
1081 m_freem(control); 1089 m_freem(control);
1082 m_freem(m); 1090 m_freem(m);
1083 return EINVAL; 1091 return EINVAL;
1084 } 1092 }
1085 1093
1086 memset(&laddr, 0, sizeof laddr); 1094 memset(&laddr, 0, sizeof laddr);
1087 1095
1088 s = splsoftnet(); 1096 s = splsoftnet();
1089 if (nam) { 1097 if (nam) {
1090 laddr = inp->inp_laddr; /* XXX */ 1098 laddr = inp->inp_laddr; /* XXX */
1091 if ((so->so_state & SS_ISCONNECTED) != 0) { 1099 if ((so->so_state & SS_ISCONNECTED) != 0) {
1092 error = EISCONN; 1100 error = EISCONN;
1093 goto die; 1101 goto die;
1094 } 1102 }
1095 error = in_pcbconnect(inp, nam, l); 1103 error = in_pcbconnect(inp, nam, l);
1096 if (error) 1104 if (error)
1097 goto die; 1105 goto die;
1098 } else { 1106 } else {
1099 if ((so->so_state & SS_ISCONNECTED) == 0) { 1107 if ((so->so_state & SS_ISCONNECTED) == 0) {
1100 error = ENOTCONN; 1108 error = ENOTCONN;
1101 goto die; 1109 goto die;
1102 } 1110 }
1103 } 1111 }
1104 error = udp_output(m, inp); 1112 error = udp_output(m, inp);
1105 m = NULL; 1113 m = NULL;
1106 if (nam) { 1114 if (nam) {
1107 in_pcbdisconnect(inp); 1115 in_pcbdisconnect(inp);
1108 inp->inp_laddr = laddr; /* XXX */ 1116 inp->inp_laddr = laddr; /* XXX */
1109 in_pcbstate(inp, INP_BOUND); /* XXX */ 1117 in_pcbstate(inp, INP_BOUND); /* XXX */
1110 } 1118 }
1111 die: 1119 die:
1112 if (m) 1120 if (m)
1113 m_freem(m); 1121 m_freem(m);
1114 1122
1115 splx(s); 1123 splx(s);
1116 return error; 1124 return error;
1117} 1125}
1118 1126
1119static int 1127static int
1120udp_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control) 1128udp_sendoob(struct socket *so, struct mbuf *m, struct mbuf *control)
1121{ 1129{
1122 KASSERT(solocked(so)); 1130 KASSERT(solocked(so));
1123 1131
1124 m_freem(m); 1132 m_freem(m);
1125 m_freem(control); 1133 m_freem(control);
1126 1134
1127 return EOPNOTSUPP; 1135 return EOPNOTSUPP;
1128} 1136}
1129 1137
1130static int 1138static int
1131udp_purgeif(struct socket *so, struct ifnet *ifp) 1139udp_purgeif(struct socket *so, struct ifnet *ifp)
1132{ 1140{
1133 int s; 1141 int s;
1134 1142
1135 s = splsoftnet(); 1143 s = splsoftnet();
1136 mutex_enter(softnet_lock); 1144 mutex_enter(softnet_lock);
1137 in_pcbpurgeif0(&udbtable, ifp); 1145 in_pcbpurgeif0(&udbtable, ifp);
1138 in_purgeif(ifp); 1146 in_purgeif(ifp);
1139 in_pcbpurgeif(&udbtable, ifp); 1147 in_pcbpurgeif(&udbtable, ifp);
1140 mutex_exit(softnet_lock); 1148 mutex_exit(softnet_lock);
1141 splx(s); 1149 splx(s);
1142 1150
1143 return 0; 1151 return 0;
1144} 1152}
1145 1153
1146static int 1154static int
1147udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, 1155udp_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam,
1148 struct mbuf *control, struct lwp *l) 1156 struct mbuf *control, struct lwp *l)
1149{ 1157{
1150 KASSERT(req != PRU_ATTACH); 1158 KASSERT(req != PRU_ATTACH);
1151 KASSERT(req != PRU_DETACH); 1159 KASSERT(req != PRU_DETACH);
1152 KASSERT(req != PRU_ACCEPT); 1160 KASSERT(req != PRU_ACCEPT);
1153 KASSERT(req != PRU_BIND); 1161 KASSERT(req != PRU_BIND);
1154 KASSERT(req != PRU_LISTEN); 1162 KASSERT(req != PRU_LISTEN);
1155 KASSERT(req != PRU_CONNECT); 1163 KASSERT(req != PRU_CONNECT);
1156 KASSERT(req != PRU_CONNECT2); 1164 KASSERT(req != PRU_CONNECT2);
1157 KASSERT(req != PRU_DISCONNECT); 1165 KASSERT(req != PRU_DISCONNECT);
1158 KASSERT(req != PRU_SHUTDOWN); 1166 KASSERT(req != PRU_SHUTDOWN);
1159 KASSERT(req != PRU_ABORT); 1167 KASSERT(req != PRU_ABORT);
1160 KASSERT(req != PRU_CONTROL); 1168 KASSERT(req != PRU_CONTROL);
1161 KASSERT(req != PRU_SENSE); 1169 KASSERT(req != PRU_SENSE);
1162 KASSERT(req != PRU_PEERADDR); 1170 KASSERT(req != PRU_PEERADDR);
1163 KASSERT(req != PRU_SOCKADDR); 1171 KASSERT(req != PRU_SOCKADDR);
1164 KASSERT(req != PRU_RCVD); 1172 KASSERT(req != PRU_RCVD);
1165 KASSERT(req != PRU_RCVOOB); 1173 KASSERT(req != PRU_RCVOOB);
1166 KASSERT(req != PRU_SEND); 1174 KASSERT(req != PRU_SEND);
1167 KASSERT(req != PRU_SENDOOB); 1175 KASSERT(req != PRU_SENDOOB);
1168 KASSERT(req != PRU_PURGEIF); 1176 KASSERT(req != PRU_PURGEIF);
1169 1177
1170 KASSERT(solocked(so)); 1178 KASSERT(solocked(so));
1171 1179
1172 if (sotoinpcb(so) == NULL) 1180 if (sotoinpcb(so) == NULL)
1173 return EINVAL; 1181 return EINVAL;
1174 1182
1175 panic("udp_usrreq"); 1183 panic("udp_usrreq");
1176 1184
1177 return 0; 1185 return 0;
1178} 1186}
1179 1187
1180static int 1188static int
1181sysctl_net_inet_udp_stats(SYSCTLFN_ARGS) 1189sysctl_net_inet_udp_stats(SYSCTLFN_ARGS)
1182{ 1190{
1183 1191
1184 return (NETSTAT_SYSCTL(udpstat_percpu, UDP_NSTATS)); 1192 return (NETSTAT_SYSCTL(udpstat_percpu, UDP_NSTATS));
1185} 1193}
1186 1194
1187/* 1195/*
1188 * Sysctl for udp variables. 1196 * Sysctl for udp variables.
1189 */ 1197 */
1190static void 1198static void
1191sysctl_net_inet_udp_setup(struct sysctllog **clog) 1199sysctl_net_inet_udp_setup(struct sysctllog **clog)
1192{ 1200{
1193 1201
1194 sysctl_createv(clog, 0, NULL, NULL, 1202 sysctl_createv(clog, 0, NULL, NULL,
1195 CTLFLAG_PERMANENT, 1203 CTLFLAG_PERMANENT,
1196 CTLTYPE_NODE, "inet", NULL, 1204 CTLTYPE_NODE, "inet", NULL,
1197 NULL, 0, NULL, 0, 1205 NULL, 0, NULL, 0,
1198 CTL_NET, PF_INET, CTL_EOL); 1206 CTL_NET, PF_INET, CTL_EOL);
1199 sysctl_createv(clog, 0, NULL, NULL, 1207 sysctl_createv(clog, 0, NULL, NULL,
1200 CTLFLAG_PERMANENT, 1208 CTLFLAG_PERMANENT,
1201 CTLTYPE_NODE, "udp", 1209 CTLTYPE_NODE, "udp",
1202 SYSCTL_DESCR("UDPv4 related settings"), 1210 SYSCTL_DESCR("UDPv4 related settings"),
1203 NULL, 0, NULL, 0, 1211 NULL, 0, NULL, 0,
1204 CTL_NET, PF_INET, IPPROTO_UDP, CTL_EOL); 1212 CTL_NET, PF_INET, IPPROTO_UDP, CTL_EOL);
1205 1213
1206 sysctl_createv(clog, 0, NULL, NULL, 1214 sysctl_createv(clog, 0, NULL, NULL,
1207 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 1215 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1208 CTLTYPE_INT, "checksum", 1216 CTLTYPE_INT, "checksum",
1209 SYSCTL_DESCR("Compute UDP checksums"), 1217 SYSCTL_DESCR("Compute UDP checksums"),
1210 NULL, 0, &udpcksum, 0, 1218 NULL, 0, &udpcksum, 0,
1211 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_CHECKSUM, 1219 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_CHECKSUM,
1212 CTL_EOL); 1220 CTL_EOL);
1213 sysctl_createv(clog, 0, NULL, NULL, 1221 sysctl_createv(clog, 0, NULL, NULL,
1214 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 1222 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1215 CTLTYPE_INT, "sendspace", 1223 CTLTYPE_INT, "sendspace",
1216 SYSCTL_DESCR("Default UDP send buffer size"), 1224 SYSCTL_DESCR("Default UDP send buffer size"),
1217 NULL, 0, &udp_sendspace, 0, 1225 NULL, 0, &udp_sendspace, 0,
1218 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_SENDSPACE, 1226 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_SENDSPACE,
1219 CTL_EOL); 1227 CTL_EOL);
1220 sysctl_createv(clog, 0, NULL, NULL, 1228 sysctl_createv(clog, 0, NULL, NULL,
1221 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 1229 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1222 CTLTYPE_INT, "recvspace", 1230 CTLTYPE_INT, "recvspace",
1223 SYSCTL_DESCR("Default UDP receive buffer size"), 1231 SYSCTL_DESCR("Default UDP receive buffer size"),
1224 NULL, 0, &udp_recvspace, 0, 1232 NULL, 0, &udp_recvspace, 0,
1225 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_RECVSPACE, 1233 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_RECVSPACE,
1226 CTL_EOL); 1234 CTL_EOL);
1227 sysctl_createv(clog, 0, NULL, NULL, 1235 sysctl_createv(clog, 0, NULL, NULL,
1228 CTLFLAG_PERMANENT|CTLFLAG_READWRITE, 1236 CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
1229 CTLTYPE_INT, "do_loopback_cksum", 1237 CTLTYPE_INT, "do_loopback_cksum",
1230 SYSCTL_DESCR("Perform UDP checksum on loopback"), 1238 SYSCTL_DESCR("Perform UDP checksum on loopback"),
1231 NULL, 0, &udp_do_loopback_cksum, 0, 1239 NULL, 0, &udp_do_loopback_cksum, 0,
1232 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_LOOPBACKCKSUM, 1240 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_LOOPBACKCKSUM,
1233 CTL_EOL); 1241 CTL_EOL);
1234 sysctl_createv(clog, 0, NULL, NULL, 1242 sysctl_createv(clog, 0, NULL, NULL,
1235 CTLFLAG_PERMANENT, 1243 CTLFLAG_PERMANENT,
1236 CTLTYPE_STRUCT, "pcblist", 1244 CTLTYPE_STRUCT, "pcblist",
1237 SYSCTL_DESCR("UDP protocol control block list"), 1245 SYSCTL_DESCR("UDP protocol control block list"),
1238 sysctl_inpcblist, 0, &udbtable, 0, 1246 sysctl_inpcblist, 0, &udbtable, 0,
1239 CTL_NET, PF_INET, IPPROTO_UDP, CTL_CREATE, 1247 CTL_NET, PF_INET, IPPROTO_UDP, CTL_CREATE,
1240 CTL_EOL); 1248 CTL_EOL);
1241 sysctl_createv(clog, 0, NULL, NULL, 1249 sysctl_createv(clog, 0, NULL, NULL,
1242 CTLFLAG_PERMANENT, 1250 CTLFLAG_PERMANENT,
1243 CTLTYPE_STRUCT, "stats", 1251 CTLTYPE_STRUCT, "stats",
1244 SYSCTL_DESCR("UDP statistics"), 1252 SYSCTL_DESCR("UDP statistics"),
1245 sysctl_net_inet_udp_stats, 0, NULL, 0, 1253 sysctl_net_inet_udp_stats, 0, NULL, 0,
1246 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_STATS, 1254 CTL_NET, PF_INET, IPPROTO_UDP, UDPCTL_STATS,
1247 CTL_EOL); 1255 CTL_EOL);
1248} 1256}
1249#endif 1257#endif
1250 1258
1251void 1259void
1252udp_statinc(u_int stat) 1260udp_statinc(u_int stat)
1253{ 1261{
1254 1262
1255 KASSERT(stat < UDP_NSTATS); 1263 KASSERT(stat < UDP_NSTATS);
1256 UDP_STATINC(stat); 1264 UDP_STATINC(stat);
1257} 1265}
1258 1266
1259#if defined(INET) && defined(IPSEC) 1267#if defined(INET) && defined(IPSEC)
1260/* 1268/*
1261 * Returns: 1269 * Returns:
1262 * 1 if the packet was processed 1270 * 1 if the packet was processed
1263 * 0 if normal UDP processing should take place 1271 * 0 if normal UDP processing should take place
1264 * -1 if an error occurent and m was freed 1272 * -1 if an error occurent and m was freed
1265 */ 1273 */
1266static int 1274static int
1267udp4_espinudp(struct mbuf **mp, int off, struct sockaddr *src, 1275udp4_espinudp(struct mbuf **mp, int off, struct sockaddr *src,
1268 struct socket *so) 1276 struct socket *so)
1269{ 1277{
1270 size_t len; 1278 size_t len;
1271 void *data; 1279 void *data;
1272 struct inpcb *inp; 1280 struct inpcb *inp;
1273 size_t skip = 0; 1281 size_t skip = 0;
1274 size_t minlen; 1282 size_t minlen;
1275 size_t iphdrlen; 1283 size_t iphdrlen;
1276 struct ip *ip; 1284 struct ip *ip;
1277 struct m_tag *tag; 1285 struct m_tag *tag;
1278 struct udphdr *udphdr; 1286 struct udphdr *udphdr;
1279 u_int16_t sport, dport; 1287 u_int16_t sport, dport;
1280 struct mbuf *m = *mp; 1288 struct mbuf *m = *mp;
1281 1289
1282 /* 1290 /*
1283 * Collapse the mbuf chain if the first mbuf is too short 1291 * Collapse the mbuf chain if the first mbuf is too short
1284 * The longest case is: UDP + non ESP marker + ESP 1292 * The longest case is: UDP + non ESP marker + ESP
1285 */ 1293 */
1286 minlen = off + sizeof(u_int64_t) + sizeof(struct esp); 1294 minlen = off + sizeof(u_int64_t) + sizeof(struct esp);
1287 if (minlen > m->m_pkthdr.len) 1295 if (minlen > m->m_pkthdr.len)
1288 minlen = m->m_pkthdr.len; 1296 minlen = m->m_pkthdr.len;
1289 1297
1290 if (m->m_len < minlen) { 1298 if (m->m_len < minlen) {
1291 if ((*mp = m_pullup(m, minlen)) == NULL) { 1299 if ((*mp = m_pullup(m, minlen)) == NULL) {
1292 printf("udp4_espinudp: m_pullup failed\n"); 1300 printf("udp4_espinudp: m_pullup failed\n");
1293 return -1; 1301 return -1;
1294 } 1302 }
1295 m = *mp; 1303 m = *mp;
1296 } 1304 }
1297 1305
1298 len = m->m_len - off; 1306 len = m->m_len - off;
1299 data = mtod(m, char *) + off; 1307 data = mtod(m, char *) + off;
1300 inp = sotoinpcb(so); 1308 inp = sotoinpcb(so);
1301 1309
1302 /* Ignore keepalive packets */ 1310 /* Ignore keepalive packets */
1303 if ((len == 1) && (*(unsigned char *)data == 0xff)) { 1311 if ((len == 1) && (*(unsigned char *)data == 0xff)) {
1304 m_free(m); 1312 m_freem(m);
1305 *mp = NULL; /* avoid any further processiong by caller ... */ 1313 *mp = NULL; /* avoid any further processiong by caller ... */
1306 return 1; 1314 return 1;
1307 } 1315 }
1308 1316
1309 /* 1317 /*
1310 * Check that the payload is long enough to hold 1318 * Check that the payload is long enough to hold
1311 * an ESP header and compute the length of encapsulation 1319 * an ESP header and compute the length of encapsulation
1312 * header to remove 1320 * header to remove
1313 */ 1321 */
1314 if (inp->inp_flags & INP_ESPINUDP) { 1322 if (inp->inp_flags & INP_ESPINUDP) {
1315 u_int32_t *st = (u_int32_t *)data; 1323 u_int32_t *st = (u_int32_t *)data;
1316 1324
1317 if ((len <= sizeof(struct esp)) || (*st == 0)) 1325 if ((len <= sizeof(struct esp)) || (*st == 0))
1318 return 0; /* Normal UDP processing */ 1326 return 0; /* Normal UDP processing */
1319 1327
1320 skip = sizeof(struct udphdr); 1328 skip = sizeof(struct udphdr);
1321 } 1329 }
1322 1330
1323 if (inp->inp_flags & INP_ESPINUDP_NON_IKE) { 1331 if (inp->inp_flags & INP_ESPINUDP_NON_IKE) {
1324 u_int32_t *st = (u_int32_t *)data; 1332 u_int32_t *st = (u_int32_t *)data;
1325 1333
1326 if ((len <= sizeof(u_int64_t) + sizeof(struct esp)) 1334 if ((len <= sizeof(u_int64_t) + sizeof(struct esp))
1327 || ((st[0] | st[1]) != 0)) 1335 || ((st[0] | st[1]) != 0))
1328 return 0; /* Normal UDP processing */ 1336 return 0; /* Normal UDP processing */
1329 1337
1330 skip = sizeof(struct udphdr) + sizeof(u_int64_t); 1338 skip = sizeof(struct udphdr) + sizeof(u_int64_t);
1331 } 1339 }
1332 1340
1333 /* 1341 /*
1334 * Get the UDP ports. They are handled in network  1342 * Get the UDP ports. They are handled in network
1335 * order everywhere in IPSEC_NAT_T code. 1343 * order everywhere in IPSEC_NAT_T code.
1336 */ 1344 */
1337 udphdr = (struct udphdr *)((char *)data - skip); 1345 udphdr = (struct udphdr *)((char *)data - skip);
1338 sport = udphdr->uh_sport; 1346 sport = udphdr->uh_sport;
1339 dport = udphdr->uh_dport; 1347 dport = udphdr->uh_dport;
1340 1348
1341 /* 1349 /*
1342 * Remove the UDP header (and possibly the non ESP marker) 1350 * Remove the UDP header (and possibly the non ESP marker)
1343 * IP header lendth is iphdrlen 1351 * IP header lendth is iphdrlen
1344 * Before: 1352 * Before:
1345 * <--- off ---> 1353 * <--- off --->
1346 * +----+------+-----+ 1354 * +----+------+-----+
1347 * | IP | UDP | ESP | 1355 * | IP | UDP | ESP |
1348 * +----+------+-----+ 1356 * +----+------+-----+
1349 * <-skip-> 1357 * <-skip->
1350 * After: 1358 * After:
1351 * +----+-----+ 1359 * +----+-----+
1352 * | IP | ESP | 1360 * | IP | ESP |
1353 * +----+-----+ 1361 * +----+-----+
1354 * <-skip-> 1362 * <-skip->
1355 */ 1363 */
1356 iphdrlen = off - sizeof(struct udphdr); 1364 iphdrlen = off - sizeof(struct udphdr);
1357 memmove(mtod(m, char *) + skip, mtod(m, void *), iphdrlen); 1365 memmove(mtod(m, char *) + skip, mtod(m, void *), iphdrlen);
1358 m_adj(m, skip); 1366 m_adj(m, skip);
1359 1367
1360 ip = mtod(m, struct ip *); 1368 ip = mtod(m, struct ip *);
1361 ip->ip_len = htons(ntohs(ip->ip_len) - skip); 1369 ip->ip_len = htons(ntohs(ip->ip_len) - skip);
1362 ip->ip_p = IPPROTO_ESP; 1370 ip->ip_p = IPPROTO_ESP;
1363 1371
1364 /* 1372 /*
1365 * We have modified the packet - it is now ESP, so we should not 1373 * We have modified the packet - it is now ESP, so we should not
1366 * return to UDP processing ...  1374 * return to UDP processing ...
1367 * 1375 *
1368 * Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember 1376 * Add a PACKET_TAG_IPSEC_NAT_T_PORT tag to remember
1369 * the source UDP port. This is required if we want 1377 * the source UDP port. This is required if we want
1370 * to select the right SPD for multiple hosts behind  1378 * to select the right SPD for multiple hosts behind
1371 * same NAT  1379 * same NAT
1372 */ 1380 */
1373 if ((tag = m_tag_get(PACKET_TAG_IPSEC_NAT_T_PORTS, 1381 if ((tag = m_tag_get(PACKET_TAG_IPSEC_NAT_T_PORTS,
1374 sizeof(sport) + sizeof(dport), M_DONTWAIT)) == NULL) { 1382 sizeof(sport) + sizeof(dport), M_DONTWAIT)) == NULL) {
1375 printf("udp4_espinudp: m_tag_get failed\n"); 1383 printf("udp4_espinudp: m_tag_get failed\n");
1376 m_freem(m); 1384 m_freem(m);
1377 return -1; 1385 return -1;
1378 } 1386 }
1379 ((u_int16_t *)(tag + 1))[0] = sport; 1387 ((u_int16_t *)(tag + 1))[0] = sport;
1380 ((u_int16_t *)(tag + 1))[1] = dport; 1388 ((u_int16_t *)(tag + 1))[1] = dport;
1381 m_tag_prepend(m, tag); 1389 m_tag_prepend(m, tag);
1382 1390
1383#ifdef IPSEC 1391#ifdef IPSEC
1384 if (ipsec_used) 1392 if (ipsec_used)
1385 ipsec4_common_input(m, iphdrlen, IPPROTO_ESP); 1393 ipsec4_common_input(m, iphdrlen, IPPROTO_ESP);
1386 /* XXX: else */ 1394 else
 1395 m_freem(m);
1387#else 1396#else
1388 esp4_input(m, iphdrlen); 1397 esp4_input(m, iphdrlen);
1389#endif 1398#endif
1390 1399
1391 /* We handled it, it shouldn't be handled by UDP */ 1400 /* We handled it, it shouldn't be handled by UDP */
1392 *mp = NULL; /* avoid free by caller ... */ 1401 *mp = NULL; /* avoid free by caller ... */
1393 return 1; 1402 return 1;
1394} 1403}
1395#endif 1404#endif
1396 1405
1397PR_WRAP_USRREQS(udp) 1406PR_WRAP_USRREQS(udp)
1398#define udp_attach udp_attach_wrapper 1407#define udp_attach udp_attach_wrapper
1399#define udp_detach udp_detach_wrapper 1408#define udp_detach udp_detach_wrapper
1400#define udp_accept udp_accept_wrapper 1409#define udp_accept udp_accept_wrapper
1401#define udp_bind udp_bind_wrapper 1410#define udp_bind udp_bind_wrapper
1402#define udp_listen udp_listen_wrapper 1411#define udp_listen udp_listen_wrapper
1403#define udp_connect udp_connect_wrapper 1412#define udp_connect udp_connect_wrapper
1404#define udp_connect2 udp_connect2_wrapper 1413#define udp_connect2 udp_connect2_wrapper
1405#define udp_disconnect udp_disconnect_wrapper 1414#define udp_disconnect udp_disconnect_wrapper
1406#define udp_shutdown udp_shutdown_wrapper 1415#define udp_shutdown udp_shutdown_wrapper
1407#define udp_abort udp_abort_wrapper 1416#define udp_abort udp_abort_wrapper
1408#define udp_ioctl udp_ioctl_wrapper 1417#define udp_ioctl udp_ioctl_wrapper
1409#define udp_stat udp_stat_wrapper 1418#define udp_stat udp_stat_wrapper
1410#define udp_peeraddr udp_peeraddr_wrapper 1419#define udp_peeraddr udp_peeraddr_wrapper
1411#define udp_sockaddr udp_sockaddr_wrapper 1420#define udp_sockaddr udp_sockaddr_wrapper
1412#define udp_rcvd udp_rcvd_wrapper 1421#define udp_rcvd udp_rcvd_wrapper
1413#define udp_recvoob udp_recvoob_wrapper 1422#define udp_recvoob udp_recvoob_wrapper
1414#define udp_send udp_send_wrapper 1423#define udp_send udp_send_wrapper
1415#define udp_sendoob udp_sendoob_wrapper 1424#define udp_sendoob udp_sendoob_wrapper
1416#define udp_purgeif udp_purgeif_wrapper 1425#define udp_purgeif udp_purgeif_wrapper
1417#define udp_usrreq udp_usrreq_wrapper 1426#define udp_usrreq udp_usrreq_wrapper
1418 1427
1419const struct pr_usrreqs udp_usrreqs = { 1428const struct pr_usrreqs udp_usrreqs = {
1420 .pr_attach = udp_attach, 1429 .pr_attach = udp_attach,
1421 .pr_detach = udp_detach, 1430 .pr_detach = udp_detach,
1422 .pr_accept = udp_accept, 1431 .pr_accept = udp_accept,
1423 .pr_bind = udp_bind, 1432 .pr_bind = udp_bind,
1424 .pr_listen = udp_listen, 1433 .pr_listen = udp_listen,
1425 .pr_connect = udp_connect, 1434 .pr_connect = udp_connect,
1426 .pr_connect2 = udp_connect2, 1435 .pr_connect2 = udp_connect2,
1427 .pr_disconnect = udp_disconnect, 1436 .pr_disconnect = udp_disconnect,
1428 .pr_shutdown = udp_shutdown, 1437 .pr_shutdown = udp_shutdown,
1429 .pr_abort = udp_abort, 1438 .pr_abort = udp_abort,
1430 .pr_ioctl = udp_ioctl, 1439 .pr_ioctl = udp_ioctl,
1431 .pr_stat = udp_stat, 1440 .pr_stat = udp_stat,
1432 .pr_peeraddr = udp_peeraddr, 1441 .pr_peeraddr = udp_peeraddr,
1433 .pr_sockaddr = udp_sockaddr, 1442 .pr_sockaddr = udp_sockaddr,
1434 .pr_rcvd = udp_rcvd, 1443 .pr_rcvd = udp_rcvd,
1435 .pr_recvoob = udp_recvoob, 1444 .pr_recvoob = udp_recvoob,
1436 .pr_send = udp_send, 1445 .pr_send = udp_send,
1437 .pr_sendoob = udp_sendoob, 1446 .pr_sendoob = udp_sendoob,
1438 .pr_purgeif = udp_purgeif, 1447 .pr_purgeif = udp_purgeif,
1439 .pr_generic = udp_usrreq, 1448 .pr_generic = udp_usrreq,
1440}; 1449};