sctp6_usrreq.c (583b625ba8ba19799bfdf5600b566ddb46f28292) sctp6_usrreq.c (4a91aa8fc9b626834dec65629decf48d1e3d5036)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 544 unchanged lines hidden (view full) ---

553 return (0);
554}
555
556static int
557sctp6_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
558{
559 struct sctp_inpcb *inp;
560 int error;
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 2001-2007, by Cisco Systems, Inc. All rights reserved.
5 * Copyright (c) 2008-2012, by Randall Stewart. All rights reserved.
6 * Copyright (c) 2008-2012, by Michael Tuexen. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 544 unchanged lines hidden (view full) ---

553 return (0);
554}
555
556static int
557sctp6_bind(struct socket *so, struct sockaddr *addr, struct thread *p)
558{
559 struct sctp_inpcb *inp;
560 int error;
561 u_char vflagsav;
561
562 inp = (struct sctp_inpcb *)so->so_pcb;
563 if (inp == NULL) {
564 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
565 return (EINVAL);
566 }
567
568 if (addr) {

--- 14 unchanged lines hidden (view full) ---

583 }
584 break;
585#endif
586 default:
587 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
588 return (EINVAL);
589 }
590 }
562
563 inp = (struct sctp_inpcb *)so->so_pcb;
564 if (inp == NULL) {
565 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
566 return (EINVAL);
567 }
568
569 if (addr) {

--- 14 unchanged lines hidden (view full) ---

584 }
585 break;
586#endif
587 default:
588 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
589 return (EINVAL);
590 }
591 }
592 vflagsav = inp->ip_inp.inp.inp_vflag;
591 inp->ip_inp.inp.inp_vflag &= ~INP_IPV4;
592 inp->ip_inp.inp.inp_vflag |= INP_IPV6;
593 if ((addr != NULL) && (SCTP_IPV6_V6ONLY(inp) == 0)) {
594 switch (addr->sa_family) {
595#ifdef INET
596 case AF_INET:
597 /* binding v4 addr to v6 socket, so reset flags */
598 inp->ip_inp.inp.inp_vflag |= INP_IPV4;

--- 13 unchanged lines hidden (view full) ---

612#ifdef INET
613 if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
614 struct sockaddr_in sin;
615
616 in6_sin6_2_sin(&sin, sin6_p);
617 inp->ip_inp.inp.inp_vflag |= INP_IPV4;
618 inp->ip_inp.inp.inp_vflag &= ~INP_IPV6;
619 error = sctp_inpcb_bind(so, (struct sockaddr *)&sin, NULL, p);
593 inp->ip_inp.inp.inp_vflag &= ~INP_IPV4;
594 inp->ip_inp.inp.inp_vflag |= INP_IPV6;
595 if ((addr != NULL) && (SCTP_IPV6_V6ONLY(inp) == 0)) {
596 switch (addr->sa_family) {
597#ifdef INET
598 case AF_INET:
599 /* binding v4 addr to v6 socket, so reset flags */
600 inp->ip_inp.inp.inp_vflag |= INP_IPV4;

--- 13 unchanged lines hidden (view full) ---

614#ifdef INET
615 if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
616 struct sockaddr_in sin;
617
618 in6_sin6_2_sin(&sin, sin6_p);
619 inp->ip_inp.inp.inp_vflag |= INP_IPV4;
620 inp->ip_inp.inp.inp_vflag &= ~INP_IPV6;
621 error = sctp_inpcb_bind(so, (struct sockaddr *)&sin, NULL, p);
620 return (error);
622 goto out;
621 }
622#endif
623 break;
624 }
625#endif
626 default:
627 break;
628 }
629 } else if (addr != NULL) {
630 struct sockaddr_in6 *sin6_p;
631
632 /* IPV6_V6ONLY socket */
633#ifdef INET
634 if (addr->sa_family == AF_INET) {
635 /* can't bind v4 addr to v6 only socket! */
636 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
623 }
624#endif
625 break;
626 }
627#endif
628 default:
629 break;
630 }
631 } else if (addr != NULL) {
632 struct sockaddr_in6 *sin6_p;
633
634 /* IPV6_V6ONLY socket */
635#ifdef INET
636 if (addr->sa_family == AF_INET) {
637 /* can't bind v4 addr to v6 only socket! */
638 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
637 return (EINVAL);
639 error = EINVAL;
640 goto out;
638 }
639#endif
640 sin6_p = (struct sockaddr_in6 *)addr;
641
642 if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
643 /* can't bind v4-mapped addrs either! */
644 /* NOTE: we don't support SIIT */
645 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
641 }
642#endif
643 sin6_p = (struct sockaddr_in6 *)addr;
644
645 if (IN6_IS_ADDR_V4MAPPED(&sin6_p->sin6_addr)) {
646 /* can't bind v4-mapped addrs either! */
647 /* NOTE: we don't support SIIT */
648 SCTP_LTRACE_ERR_RET(inp, NULL, NULL, SCTP_FROM_SCTP6_USRREQ, EINVAL);
646 return (EINVAL);
649 error = EINVAL;
650 goto out;
647 }
648 }
649 error = sctp_inpcb_bind(so, addr, NULL, p);
651 }
652 }
653 error = sctp_inpcb_bind(so, addr, NULL, p);
654out:
655 if (error != 0)
656 inp->ip_inp.inp.inp_vflag = vflagsav;
650 return (error);
651}
652
653
654static void
655sctp6_close(struct socket *so)
656{
657 sctp_close(so);

--- 519 unchanged lines hidden ---
657 return (error);
658}
659
660
661static void
662sctp6_close(struct socket *so)
663{
664 sctp_close(so);

--- 519 unchanged lines hidden ---