3 *
4 * The contents of this file are subject to the terms of the
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 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 */
24
25 /*
26 * MAC Services Module - misc utilities
27 */
28
29 #include <sys/types.h>
30 #include <sys/mac.h>
31 #include <sys/mac_impl.h>
32 #include <sys/mac_client_priv.h>
33 #include <sys/mac_client_impl.h>
34 #include <sys/mac_soft_ring.h>
35 #include <sys/strsubr.h>
36 #include <sys/strsun.h>
37 #include <sys/vlan.h>
38 #include <sys/pattr.h>
39 #include <sys/pci_tools.h>
40 #include <inet/ip.h>
41 #include <inet/ip_impl.h>
42 #include <inet/ip6.h>
474 * headers (hop-by-hop, destination, routing and fragment). The header length
475 * and next header value (a transport header) is captured.
476 *
477 * Returns B_FALSE if all the IP headers are not in the same mblk otherwise
478 * returns B_TRUE.
479 */
480 boolean_t
481 mac_ip_hdr_length_v6(ip6_t *ip6h, uint8_t *endptr, uint16_t *hdr_length,
482 uint8_t *next_hdr, ip6_frag_t **fragp)
483 {
484 uint16_t length;
485 uint_t ehdrlen;
486 uint8_t *whereptr;
487 uint8_t *nexthdrp;
488 ip6_dest_t *desthdr;
489 ip6_rthdr_t *rthdr;
490 ip6_frag_t *fraghdr;
491
492 if (((uchar_t *)ip6h + IPV6_HDR_LEN) > endptr)
493 return (B_FALSE);
494 ASSERT(IPH_HDR_VERSION(ip6h) == IPV6_VERSION);
495 length = IPV6_HDR_LEN;
496 whereptr = ((uint8_t *)&ip6h[1]); /* point to next hdr */
497
498 if (fragp != NULL)
499 *fragp = NULL;
500
501 nexthdrp = &ip6h->ip6_nxt;
502 while (whereptr < endptr) {
503 /* Is there enough left for len + nexthdr? */
504 if (whereptr + MIN_EHDR_LEN > endptr)
505 break;
506
507 switch (*nexthdrp) {
508 case IPPROTO_HOPOPTS:
509 case IPPROTO_DSTOPTS:
510 /* Assumes the headers are identical for hbh and dst */
511 desthdr = (ip6_dest_t *)whereptr;
512 ehdrlen = 8 * (desthdr->ip6d_len + 1);
513 if ((uchar_t *)desthdr + ehdrlen > endptr)
514 return (B_FALSE);
|
3 *
4 * The contents of this file are subject to the terms of the
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 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright 2018 Joyent, Inc.
24 */
25
26 /*
27 * MAC Services Module - misc utilities
28 */
29
30 #include <sys/types.h>
31 #include <sys/mac.h>
32 #include <sys/mac_impl.h>
33 #include <sys/mac_client_priv.h>
34 #include <sys/mac_client_impl.h>
35 #include <sys/mac_soft_ring.h>
36 #include <sys/strsubr.h>
37 #include <sys/strsun.h>
38 #include <sys/vlan.h>
39 #include <sys/pattr.h>
40 #include <sys/pci_tools.h>
41 #include <inet/ip.h>
42 #include <inet/ip_impl.h>
43 #include <inet/ip6.h>
475 * headers (hop-by-hop, destination, routing and fragment). The header length
476 * and next header value (a transport header) is captured.
477 *
478 * Returns B_FALSE if all the IP headers are not in the same mblk otherwise
479 * returns B_TRUE.
480 */
481 boolean_t
482 mac_ip_hdr_length_v6(ip6_t *ip6h, uint8_t *endptr, uint16_t *hdr_length,
483 uint8_t *next_hdr, ip6_frag_t **fragp)
484 {
485 uint16_t length;
486 uint_t ehdrlen;
487 uint8_t *whereptr;
488 uint8_t *nexthdrp;
489 ip6_dest_t *desthdr;
490 ip6_rthdr_t *rthdr;
491 ip6_frag_t *fraghdr;
492
493 if (((uchar_t *)ip6h + IPV6_HDR_LEN) > endptr)
494 return (B_FALSE);
495 /*
496 * NOTE: Version-check failure here may cause mismatched IP versions
497 * to propagate ENOBUFS in some callers, instead of letting the
498 * packet reach the appropriate IP input function, where version check
499 * errors are logged & counted.
500 */
501 if (IPH_HDR_VERSION(ip6h) != IPV6_VERSION)
502 return (B_FALSE);
503 length = IPV6_HDR_LEN;
504 whereptr = ((uint8_t *)&ip6h[1]); /* point to next hdr */
505
506 if (fragp != NULL)
507 *fragp = NULL;
508
509 nexthdrp = &ip6h->ip6_nxt;
510 while (whereptr < endptr) {
511 /* Is there enough left for len + nexthdr? */
512 if (whereptr + MIN_EHDR_LEN > endptr)
513 break;
514
515 switch (*nexthdrp) {
516 case IPPROTO_HOPOPTS:
517 case IPPROTO_DSTOPTS:
518 /* Assumes the headers are identical for hbh and dst */
519 desthdr = (ip6_dest_t *)whereptr;
520 ehdrlen = 8 * (desthdr->ip6d_len + 1);
521 if ((uchar_t *)desthdr + ehdrlen > endptr)
522 return (B_FALSE);
|