| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: in6_pcb.c,v 1.107 2009/04/30 18:18:34 elad Exp $ */ | | 1 | /* $NetBSD: in6_pcb.c,v 1.108 2009/05/02 18:58:03 elad Exp $ */ |
2 | /* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */ | | 2 | /* $KAME: in6_pcb.c,v 1.84 2001/02/08 18:02:08 itojun Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -52,27 +52,27 @@ | | | @@ -52,27 +52,27 @@ |
52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | | 52 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE |
53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 53 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 54 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 55 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 56 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 57 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 58 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
59 | * SUCH DAMAGE. | | 59 | * SUCH DAMAGE. |
60 | * | | 60 | * |
61 | * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94 | | 61 | * @(#)in_pcb.c 8.2 (Berkeley) 1/4/94 |
62 | */ | | 62 | */ |
63 | | | 63 | |
64 | #include <sys/cdefs.h> | | 64 | #include <sys/cdefs.h> |
65 | __KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.107 2009/04/30 18:18:34 elad Exp $"); | | 65 | __KERNEL_RCSID(0, "$NetBSD: in6_pcb.c,v 1.108 2009/05/02 18:58:03 elad Exp $"); |
66 | | | 66 | |
67 | #include "opt_inet.h" | | 67 | #include "opt_inet.h" |
68 | #include "opt_ipsec.h" | | 68 | #include "opt_ipsec.h" |
69 | | | 69 | |
70 | #include <sys/param.h> | | 70 | #include <sys/param.h> |
71 | #include <sys/systm.h> | | 71 | #include <sys/systm.h> |
72 | #include <sys/malloc.h> | | 72 | #include <sys/malloc.h> |
73 | #include <sys/mbuf.h> | | 73 | #include <sys/mbuf.h> |
74 | #include <sys/protosw.h> | | 74 | #include <sys/protosw.h> |
75 | #include <sys/socket.h> | | 75 | #include <sys/socket.h> |
76 | #include <sys/socketvar.h> | | 76 | #include <sys/socketvar.h> |
77 | #include <sys/ioctl.h> | | 77 | #include <sys/ioctl.h> |
78 | #include <sys/errno.h> | | 78 | #include <sys/errno.h> |
| @@ -334,48 +334,50 @@ in6_pcbbind_port(struct in6pcb *in6p, st | | | @@ -334,48 +334,50 @@ in6_pcbbind_port(struct in6pcb *in6p, st |
334 | } | | 334 | } |
335 | | | 335 | |
336 | LIST_REMOVE(&in6p->in6p_head, inph_lhash); | | 336 | LIST_REMOVE(&in6p->in6p_head, inph_lhash); |
337 | LIST_INSERT_HEAD(IN6PCBHASH_PORT(table, in6p->in6p_lport), | | 337 | LIST_INSERT_HEAD(IN6PCBHASH_PORT(table, in6p->in6p_lport), |
338 | &in6p->in6p_head, inph_lhash); | | 338 | &in6p->in6p_head, inph_lhash); |
339 | | | 339 | |
340 | return (0); | | 340 | return (0); |
341 | } | | 341 | } |
342 | | | 342 | |
343 | int | | 343 | int |
344 | in6_pcbbind(void *v, struct mbuf *nam, struct lwp *l) | | 344 | in6_pcbbind(void *v, struct mbuf *nam, struct lwp *l) |
345 | { | | 345 | { |
346 | struct in6pcb *in6p = v; | | 346 | struct in6pcb *in6p = v; |
| | | 347 | struct sockaddr_in6 lsin6; |
347 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)NULL; | | 348 | struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)NULL; |
348 | int error; | | 349 | int error; |
349 | | | 350 | |
350 | if (in6p->in6p_af != AF_INET6) | | 351 | if (in6p->in6p_af != AF_INET6) |
351 | return (EINVAL); | | 352 | return (EINVAL); |
352 | | | 353 | |
353 | /* | | 354 | /* |
354 | * If we already have a local port or a local address it means we're | | 355 | * If we already have a local port or a local address it means we're |
355 | * bounded. | | 356 | * bounded. |
356 | */ | | 357 | */ |
357 | if (in6p->in6p_lport || !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) | | 358 | if (in6p->in6p_lport || !IN6_IS_ADDR_UNSPECIFIED(&in6p->in6p_laddr)) |
358 | return (EINVAL); | | 359 | return (EINVAL); |
359 | | | 360 | |
360 | if (nam != NULL) { | | 361 | if (nam != NULL) { |
361 | /* We were provided a sockaddr_in6 to use. */ | | 362 | /* We were provided a sockaddr_in6 to use. */ |
362 | sin6 = mtod(nam, struct sockaddr_in6 *); | | 363 | sin6 = mtod(nam, struct sockaddr_in6 *); |
363 | if (nam->m_len != sizeof(*sin6)) | | 364 | if (nam->m_len != sizeof(*sin6)) |
364 | return (EINVAL); | | 365 | return (EINVAL); |
365 | } else { | | 366 | } else { |
366 | /* We always bind to *something*, even if it's "anything". */ | | 367 | /* We always bind to *something*, even if it's "anything". */ |
367 | sin6 = (struct sockaddr_in6 *) | | 368 | lsin6 = *((const struct sockaddr_in6 *) |
368 | __UNCONST(in6p->in6p_socket->so_proto->pr_domain->dom_sa_any); | | 369 | in6p->in6p_socket->so_proto->pr_domain->dom_sa_any); |
| | | 370 | sin6 = &lsin6; |
369 | } | | 371 | } |
370 | | | 372 | |
371 | /* Bind address. */ | | 373 | /* Bind address. */ |
372 | error = in6_pcbbind_addr(in6p, sin6, l); | | 374 | error = in6_pcbbind_addr(in6p, sin6, l); |
373 | if (error) | | 375 | if (error) |
374 | return (error); | | 376 | return (error); |
375 | | | 377 | |
376 | /* Bind port. */ | | 378 | /* Bind port. */ |
377 | error = in6_pcbbind_port(in6p, sin6, l); | | 379 | error = in6_pcbbind_port(in6p, sin6, l); |
378 | if (error) { | | 380 | if (error) { |
379 | /* | | 381 | /* |
380 | * Reset the address here to "any" so we don't "leak" the | | 382 | * Reset the address here to "any" so we don't "leak" the |
381 | * in6pcb. | | 383 | * in6pcb. |