Print this page
4838 Fix for 4596 has some inverted booleans
Reviewed by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>


2716                 ixa->ixa_flags |= IXAF_IS_IPV4;
2717         } else if (sin6 != NULL) {
2718                 boolean_t v4mapped;
2719 
2720                 v6dst = sin6->sin6_addr;
2721                 dstport = sin6->sin6_port;
2722                 flowinfo = sin6->sin6_flowinfo;
2723                 srcid = sin6->__sin6_src_id;
2724                 if (IN6_IS_ADDR_LINKSCOPE(&v6dst) && sin6->sin6_scope_id != 0) {
2725                         ixa->ixa_scopeid = sin6->sin6_scope_id;
2726                         ixa->ixa_flags |= IXAF_SCOPEID_SET;
2727                 } else {
2728                         ixa->ixa_flags &= ~IXAF_SCOPEID_SET;
2729                 }
2730                 v4mapped = IN6_IS_ADDR_V4MAPPED(&v6dst);
2731                 if (v4mapped)
2732                         ixa->ixa_flags |= IXAF_IS_IPV4;
2733                 else
2734                         ixa->ixa_flags &= ~IXAF_IS_IPV4;
2735                 if (srcid != 0 && IN6_IS_ADDR_UNSPECIFIED(&v6src)) {
2736                         if (ip_srcid_find_id(srcid, &v6src, IPCL_ZONEID(connp),
2737                             v4mapped, connp->conn_netstack)) {
2738                                 /* Mismatch - v4mapped/v6 specified by srcid. */
2739                                 mutex_exit(&connp->conn_lock);
2740                                 error = EADDRNOTAVAIL;
2741                                 goto failed;    /* Does freemsg() and mib. */
2742                         }
2743                 }
2744         } else {
2745                 /* Connected case */
2746                 v6dst = connp->conn_faddr_v6;
2747                 dstport = connp->conn_fport;
2748                 flowinfo = connp->conn_flowinfo;
2749         }
2750         mutex_exit(&connp->conn_lock);
2751 
2752         /* Handle IP_PKTINFO/IPV6_PKTINFO setting source address. */
2753         if (ipp->ipp_fields & IPPF_ADDR) {
2754                 if (ixa->ixa_flags & IXAF_IS_IPV4) {
2755                         if (IN6_IS_ADDR_V4MAPPED(&ipp->ipp_addr))
2756                                 v6src = ipp->ipp_addr;


3737                 ixa->ixa_flags |= IXAF_IS_IPV4;
3738         } else {
3739                 boolean_t v4mapped;
3740 
3741                 v6dst = sin6->sin6_addr;
3742                 dstport = sin6->sin6_port;
3743                 flowinfo = sin6->sin6_flowinfo;
3744                 srcid = sin6->__sin6_src_id;
3745                 if (IN6_IS_ADDR_LINKSCOPE(&v6dst) && sin6->sin6_scope_id != 0) {
3746                         ixa->ixa_scopeid = sin6->sin6_scope_id;
3747                         ixa->ixa_flags |= IXAF_SCOPEID_SET;
3748                 } else {
3749                         ixa->ixa_flags &= ~IXAF_SCOPEID_SET;
3750                 }
3751                 v4mapped = IN6_IS_ADDR_V4MAPPED(&v6dst);
3752                 if (v4mapped)
3753                         ixa->ixa_flags |= IXAF_IS_IPV4;
3754                 else
3755                         ixa->ixa_flags &= ~IXAF_IS_IPV4;
3756                 if (srcid != 0 && IN6_IS_ADDR_UNSPECIFIED(&v6src)) {
3757                         if (ip_srcid_find_id(srcid, &v6src, IPCL_ZONEID(connp),
3758                             v4mapped, connp->conn_netstack)) {
3759                                 /* Mismatched v4mapped/v6 specified by srcid. */
3760                                 mutex_exit(&connp->conn_lock);
3761                                 error = EADDRNOTAVAIL;
3762                                 goto ud_error;
3763                         }
3764                 }
3765         }
3766         /* Handle IP_PKTINFO/IPV6_PKTINFO setting source address. */
3767         if (connp->conn_xmit_ipp.ipp_fields & IPPF_ADDR) {
3768                 ip_pkt_t *ipp = &connp->conn_xmit_ipp;
3769 
3770                 if (ixa->ixa_flags & IXAF_IS_IPV4) {
3771                         if (IN6_IS_ADDR_V4MAPPED(&ipp->ipp_addr))
3772                                 v6src = ipp->ipp_addr;
3773                 } else {
3774                         if (!IN6_IS_ADDR_V4MAPPED(&ipp->ipp_addr))
3775                                 v6src = ipp->ipp_addr;
3776                 }
3777         }


5554                  * Should never happen
5555                  */
5556                 return (EINVAL);
5557 
5558         case sizeof (sin_t):
5559                 sin = (sin_t *)sa;
5560                 v4dst = sin->sin_addr.s_addr;
5561                 dstport = sin->sin_port;
5562                 IN6_IPADDR_TO_V4MAPPED(v4dst, &v6dst);
5563                 ASSERT(connp->conn_ipversion == IPV4_VERSION);
5564                 ipversion = IPV4_VERSION;
5565                 break;
5566 
5567         case sizeof (sin6_t):
5568                 sin6 = (sin6_t *)sa;
5569                 v6dst = sin6->sin6_addr;
5570                 dstport = sin6->sin6_port;
5571                 srcid = sin6->__sin6_src_id;
5572                 v4mapped = IN6_IS_ADDR_V4MAPPED(&v6dst);
5573                 if (srcid != 0 && IN6_IS_ADDR_UNSPECIFIED(&v6src)) {
5574                         if (ip_srcid_find_id(srcid, &v6src, IPCL_ZONEID(connp),
5575                             v4mapped, connp->conn_netstack)) {
5576                                 /* Mismatch v4mapped/v6 specified by srcid. */
5577                                 return (EADDRNOTAVAIL);
5578                         }
5579                 }
5580                 if (v4mapped) {
5581                         if (connp->conn_ipv6_v6only)
5582                                 return (EADDRNOTAVAIL);
5583 
5584                         /*
5585                          * Destination adress is mapped IPv6 address.
5586                          * Source bound address should be unspecified or
5587                          * IPv6 mapped address as well.
5588                          */
5589                         if (!IN6_IS_ADDR_UNSPECIFIED(
5590                             &connp->conn_bound_addr_v6) &&
5591                             !IN6_IS_ADDR_V4MAPPED(&connp->conn_bound_addr_v6)) {
5592                                 return (EADDRNOTAVAIL);
5593                         }
5594                         IN6_V4MAPPED_TO_IPADDR(&v6dst, v4dst);




2716                 ixa->ixa_flags |= IXAF_IS_IPV4;
2717         } else if (sin6 != NULL) {
2718                 boolean_t v4mapped;
2719 
2720                 v6dst = sin6->sin6_addr;
2721                 dstport = sin6->sin6_port;
2722                 flowinfo = sin6->sin6_flowinfo;
2723                 srcid = sin6->__sin6_src_id;
2724                 if (IN6_IS_ADDR_LINKSCOPE(&v6dst) && sin6->sin6_scope_id != 0) {
2725                         ixa->ixa_scopeid = sin6->sin6_scope_id;
2726                         ixa->ixa_flags |= IXAF_SCOPEID_SET;
2727                 } else {
2728                         ixa->ixa_flags &= ~IXAF_SCOPEID_SET;
2729                 }
2730                 v4mapped = IN6_IS_ADDR_V4MAPPED(&v6dst);
2731                 if (v4mapped)
2732                         ixa->ixa_flags |= IXAF_IS_IPV4;
2733                 else
2734                         ixa->ixa_flags &= ~IXAF_IS_IPV4;
2735                 if (srcid != 0 && IN6_IS_ADDR_UNSPECIFIED(&v6src)) {
2736                         if (!ip_srcid_find_id(srcid, &v6src, IPCL_ZONEID(connp),
2737                             v4mapped, connp->conn_netstack)) {
2738                                 /* Mismatch - v4mapped/v6 specified by srcid. */
2739                                 mutex_exit(&connp->conn_lock);
2740                                 error = EADDRNOTAVAIL;
2741                                 goto failed;    /* Does freemsg() and mib. */
2742                         }
2743                 }
2744         } else {
2745                 /* Connected case */
2746                 v6dst = connp->conn_faddr_v6;
2747                 dstport = connp->conn_fport;
2748                 flowinfo = connp->conn_flowinfo;
2749         }
2750         mutex_exit(&connp->conn_lock);
2751 
2752         /* Handle IP_PKTINFO/IPV6_PKTINFO setting source address. */
2753         if (ipp->ipp_fields & IPPF_ADDR) {
2754                 if (ixa->ixa_flags & IXAF_IS_IPV4) {
2755                         if (IN6_IS_ADDR_V4MAPPED(&ipp->ipp_addr))
2756                                 v6src = ipp->ipp_addr;


3737                 ixa->ixa_flags |= IXAF_IS_IPV4;
3738         } else {
3739                 boolean_t v4mapped;
3740 
3741                 v6dst = sin6->sin6_addr;
3742                 dstport = sin6->sin6_port;
3743                 flowinfo = sin6->sin6_flowinfo;
3744                 srcid = sin6->__sin6_src_id;
3745                 if (IN6_IS_ADDR_LINKSCOPE(&v6dst) && sin6->sin6_scope_id != 0) {
3746                         ixa->ixa_scopeid = sin6->sin6_scope_id;
3747                         ixa->ixa_flags |= IXAF_SCOPEID_SET;
3748                 } else {
3749                         ixa->ixa_flags &= ~IXAF_SCOPEID_SET;
3750                 }
3751                 v4mapped = IN6_IS_ADDR_V4MAPPED(&v6dst);
3752                 if (v4mapped)
3753                         ixa->ixa_flags |= IXAF_IS_IPV4;
3754                 else
3755                         ixa->ixa_flags &= ~IXAF_IS_IPV4;
3756                 if (srcid != 0 && IN6_IS_ADDR_UNSPECIFIED(&v6src)) {
3757                         if (!ip_srcid_find_id(srcid, &v6src, IPCL_ZONEID(connp),
3758                             v4mapped, connp->conn_netstack)) {
3759                                 /* Mismatched v4mapped/v6 specified by srcid. */
3760                                 mutex_exit(&connp->conn_lock);
3761                                 error = EADDRNOTAVAIL;
3762                                 goto ud_error;
3763                         }
3764                 }
3765         }
3766         /* Handle IP_PKTINFO/IPV6_PKTINFO setting source address. */
3767         if (connp->conn_xmit_ipp.ipp_fields & IPPF_ADDR) {
3768                 ip_pkt_t *ipp = &connp->conn_xmit_ipp;
3769 
3770                 if (ixa->ixa_flags & IXAF_IS_IPV4) {
3771                         if (IN6_IS_ADDR_V4MAPPED(&ipp->ipp_addr))
3772                                 v6src = ipp->ipp_addr;
3773                 } else {
3774                         if (!IN6_IS_ADDR_V4MAPPED(&ipp->ipp_addr))
3775                                 v6src = ipp->ipp_addr;
3776                 }
3777         }


5554                  * Should never happen
5555                  */
5556                 return (EINVAL);
5557 
5558         case sizeof (sin_t):
5559                 sin = (sin_t *)sa;
5560                 v4dst = sin->sin_addr.s_addr;
5561                 dstport = sin->sin_port;
5562                 IN6_IPADDR_TO_V4MAPPED(v4dst, &v6dst);
5563                 ASSERT(connp->conn_ipversion == IPV4_VERSION);
5564                 ipversion = IPV4_VERSION;
5565                 break;
5566 
5567         case sizeof (sin6_t):
5568                 sin6 = (sin6_t *)sa;
5569                 v6dst = sin6->sin6_addr;
5570                 dstport = sin6->sin6_port;
5571                 srcid = sin6->__sin6_src_id;
5572                 v4mapped = IN6_IS_ADDR_V4MAPPED(&v6dst);
5573                 if (srcid != 0 && IN6_IS_ADDR_UNSPECIFIED(&v6src)) {
5574                         if (!ip_srcid_find_id(srcid, &v6src, IPCL_ZONEID(connp),
5575                             v4mapped, connp->conn_netstack)) {
5576                                 /* Mismatch v4mapped/v6 specified by srcid. */
5577                                 return (EADDRNOTAVAIL);
5578                         }
5579                 }
5580                 if (v4mapped) {
5581                         if (connp->conn_ipv6_v6only)
5582                                 return (EADDRNOTAVAIL);
5583 
5584                         /*
5585                          * Destination adress is mapped IPv6 address.
5586                          * Source bound address should be unspecified or
5587                          * IPv6 mapped address as well.
5588                          */
5589                         if (!IN6_IS_ADDR_UNSPECIFIED(
5590                             &connp->conn_bound_addr_v6) &&
5591                             !IN6_IS_ADDR_V4MAPPED(&connp->conn_bound_addr_v6)) {
5592                                 return (EADDRNOTAVAIL);
5593                         }
5594                         IN6_V4MAPPED_TO_IPADDR(&v6dst, v4dst);