Print this page
9832 Original bug discovered as 9560 has friends IPv4 packets coming in as IPv6 creating chaos
Reviewed by: Robert Mustacchi <rm@joyent.com>


   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.


  25  */
  26 
  27 #include <sys/strsun.h>
  28 #include <sys/sdt.h>
  29 #include <sys/mac.h>
  30 #include <sys/mac_impl.h>
  31 #include <sys/mac_client_impl.h>
  32 #include <sys/mac_stat.h>
  33 #include <sys/dls.h>
  34 #include <sys/dls_impl.h>
  35 #include <sys/mac_soft_ring.h>
  36 #include <sys/ethernet.h>
  37 #include <sys/cpupart.h>
  38 #include <sys/pool.h>
  39 #include <sys/pool_pset.h>
  40 #include <sys/vlan.h>
  41 #include <inet/ip.h>
  42 #include <inet/ip6.h>
  43 #include <netinet/tcp.h>
  44 #include <netinet/udp.h>


1937         flow_l2info_t   *l2info = &s->fs_l2info;
1938         flow_l3info_t   *l3info = &s->fs_l3info;
1939         uint16_t        sap = l2info->l2_sap;
1940         uchar_t         *l3_start;
1941 
1942         l3_start = l2info->l2_start + l2info->l2_hdrsize;
1943 
1944         /*
1945          * Adjust start pointer if we're at the end of an mblk.
1946          */
1947         CHECK_AND_ADJUST_START_PTR(s, l3_start);
1948 
1949         l3info->l3_start = l3_start;
1950         if (!OK_32PTR(l3_start))
1951                 return (EINVAL);
1952 
1953         switch (sap) {
1954         case ETHERTYPE_IP: {
1955                 ipha_t  *ipha = (ipha_t *)l3_start;
1956 


1957                 if (PKT_TOO_SMALL(s, l3_start + IP_SIMPLE_HDR_LENGTH))
1958                         return (ENOBUFS);
1959 
1960                 l3info->l3_hdrsize = IPH_HDR_LENGTH(ipha);
1961                 l3info->l3_protocol = ipha->ipha_protocol;
1962                 l3info->l3_version = IPV4_VERSION;
1963                 l3info->l3_fragmented =
1964                     IS_V4_FRAGMENT(ipha->ipha_fragment_offset_and_flags);
1965                 break;
1966         }
1967         case ETHERTYPE_IPV6: {
1968                 ip6_t           *ip6h = (ip6_t *)l3_start;
1969                 ip6_frag_t      *frag = NULL;
1970                 uint16_t        ip6_hdrlen;
1971                 uint8_t         nexthdr;

1972 
1973                 if (!mac_ip_hdr_length_v6(ip6h, s->fs_mp->b_wptr, &ip6_hdrlen,
1974                     &nexthdr, &frag)) {
1975                         return (ENOBUFS);
1976                 }




1977                 l3info->l3_hdrsize = ip6_hdrlen;
1978                 l3info->l3_protocol = nexthdr;
1979                 l3info->l3_version = IPV6_VERSION;
1980                 l3info->l3_fragmented = (frag != NULL);
1981                 break;
1982         }
1983         default:
1984                 return (EINVAL);
1985         }
1986         return (0);
1987 }
1988 
1989 /* ARGSUSED */
1990 static int
1991 flow_ip_proto_accept_fe(flow_tab_t *ft, flow_entry_t *flent)
1992 {
1993         flow_desc_t     *fd = &flent->fe_flow_desc;
1994 
1995         switch (fd->fd_protocol) {
1996         case IPPROTO_TCP:




   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 
  22 /*
  23  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Copyright 2019, Joyent, Inc.
  27  */
  28 
  29 #include <sys/strsun.h>
  30 #include <sys/sdt.h>
  31 #include <sys/mac.h>
  32 #include <sys/mac_impl.h>
  33 #include <sys/mac_client_impl.h>
  34 #include <sys/mac_stat.h>
  35 #include <sys/dls.h>
  36 #include <sys/dls_impl.h>
  37 #include <sys/mac_soft_ring.h>
  38 #include <sys/ethernet.h>
  39 #include <sys/cpupart.h>
  40 #include <sys/pool.h>
  41 #include <sys/pool_pset.h>
  42 #include <sys/vlan.h>
  43 #include <inet/ip.h>
  44 #include <inet/ip6.h>
  45 #include <netinet/tcp.h>
  46 #include <netinet/udp.h>


1939         flow_l2info_t   *l2info = &s->fs_l2info;
1940         flow_l3info_t   *l3info = &s->fs_l3info;
1941         uint16_t        sap = l2info->l2_sap;
1942         uchar_t         *l3_start;
1943 
1944         l3_start = l2info->l2_start + l2info->l2_hdrsize;
1945 
1946         /*
1947          * Adjust start pointer if we're at the end of an mblk.
1948          */
1949         CHECK_AND_ADJUST_START_PTR(s, l3_start);
1950 
1951         l3info->l3_start = l3_start;
1952         if (!OK_32PTR(l3_start))
1953                 return (EINVAL);
1954 
1955         switch (sap) {
1956         case ETHERTYPE_IP: {
1957                 ipha_t  *ipha = (ipha_t *)l3_start;
1958 
1959                 if (IPH_HDR_VERSION(ipha) != IPV4_VERSION)
1960                         return (EINVAL);
1961                 if (PKT_TOO_SMALL(s, l3_start + IP_SIMPLE_HDR_LENGTH))
1962                         return (ENOBUFS);
1963 
1964                 l3info->l3_hdrsize = IPH_HDR_LENGTH(ipha);
1965                 l3info->l3_protocol = ipha->ipha_protocol;
1966                 l3info->l3_version = IPV4_VERSION;
1967                 l3info->l3_fragmented =
1968                     IS_V4_FRAGMENT(ipha->ipha_fragment_offset_and_flags);
1969                 break;
1970         }
1971         case ETHERTYPE_IPV6: {
1972                 ip6_t           *ip6h = (ip6_t *)l3_start;
1973                 ip6_frag_t      *frag = NULL;
1974                 uint16_t        ip6_hdrlen;
1975                 uint8_t         nexthdr;
1976                 int             errno;
1977 
1978                 errno = mac_ip_hdr_length_v6(ip6h, s->fs_mp->b_wptr,
1979                     &ip6_hdrlen, &nexthdr, &frag);
1980                 /*
1981                  * ENOBUFS is not ENOSPC, but the semantics are the
1982                  * same for this caller.
1983                  */
1984                 if (errno != 0)
1985                         return (errno == ENOSPC ? ENOBUFS : errno);
1986                 l3info->l3_hdrsize = ip6_hdrlen;
1987                 l3info->l3_protocol = nexthdr;
1988                 l3info->l3_version = IPV6_VERSION;
1989                 l3info->l3_fragmented = (frag != NULL);
1990                 break;
1991         }
1992         default:
1993                 return (EINVAL);
1994         }
1995         return (0);
1996 }
1997 
1998 /* ARGSUSED */
1999 static int
2000 flow_ip_proto_accept_fe(flow_tab_t *ft, flow_entry_t *flent)
2001 {
2002         flow_desc_t     *fd = &flent->fe_flow_desc;
2003 
2004         switch (fd->fd_protocol) {
2005         case IPPROTO_TCP: