Print this page
13175 Add support for IP_RECVTOS
13182 CMSG_ macros should have man pages
Change-ID: I784aa36cfd3c17e3cccbf1fd329fa7e69b663ef9

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/inet/tcp/tcp_input.c
          +++ new/usr/src/uts/common/inet/tcp/tcp_input.c
↓ open down ↓ 16 lines elided ↑ open up ↑
  17   17   * information: Portions Copyright [yyyy] [name of copyright owner]
  18   18   *
  19   19   * CDDL HEADER END
  20   20   */
  21   21  
  22   22  /*
  23   23   * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
  24   24   * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
  25   25   * Copyright 2019 Joyent, Inc.
  26   26   * Copyright (c) 2014, 2016 by Delphix. All rights reserved.
       27 + * Copyright 2020 OmniOS Community Edition (OmniOSce) Association.
  27   28   */
  28   29  
  29   30  /* This file contains all TCP input processing functions. */
  30   31  
  31   32  #include <sys/types.h>
  32   33  #include <sys/stream.h>
  33   34  #include <sys/strsun.h>
  34   35  #include <sys/strsubr.h>
  35   36  #include <sys/stropts.h>
  36   37  #include <sys/strlog.h>
↓ open down ↓ 5064 lines elided ↑ open up ↑
5101 5102          struct T_optdata_ind *todi;
5102 5103          int optlen;
5103 5104          uchar_t *optptr;
5104 5105          struct T_opthdr *toh;
5105 5106          crb_t addflag;  /* Which pieces to add */
5106 5107          mblk_t *mp1;
5107 5108          conn_t  *connp = tcp->tcp_connp;
5108 5109  
5109 5110          optlen = 0;
5110 5111          addflag.crb_all = 0;
     5112 +
     5113 +        /* If app asked for TOS and it has changed ... */
     5114 +        if (connp->conn_recv_ancillary.crb_recvtos &&
     5115 +            ipp->ipp_type_of_service != tcp->tcp_recvtos &&
     5116 +            (ira->ira_flags & IRAF_IS_IPV4)) {
     5117 +                optlen += sizeof (struct T_opthdr) +
     5118 +                    P2ROUNDUP(sizeof (uint8_t), __TPI_ALIGN_SIZE);
     5119 +                addflag.crb_recvtos = 1;
     5120 +        }
5111 5121          /* If app asked for pktinfo and the index has changed ... */
5112 5122          if (connp->conn_recv_ancillary.crb_ip_recvpktinfo &&
5113 5123              ira->ira_ruifindex != tcp->tcp_recvifindex) {
5114 5124                  optlen += sizeof (struct T_opthdr) +
5115 5125                      sizeof (struct in6_pktinfo);
5116 5126                  addflag.crb_ip_recvpktinfo = 1;
5117 5127          }
5118 5128          /* If app asked for hoplimit and it has changed ... */
5119 5129          if (connp->conn_recv_ancillary.crb_ipv6_recvhoplimit &&
5120 5130              ipp->ipp_hoplimit != tcp->tcp_recvhops) {
5121 5131                  optlen += sizeof (struct T_opthdr) + sizeof (uint_t);
5122 5132                  addflag.crb_ipv6_recvhoplimit = 1;
5123 5133          }
5124 5134          /* If app asked for tclass and it has changed ... */
5125 5135          if (connp->conn_recv_ancillary.crb_ipv6_recvtclass &&
5126 5136              ipp->ipp_tclass != tcp->tcp_recvtclass) {
5127 5137                  optlen += sizeof (struct T_opthdr) + sizeof (uint_t);
5128 5138                  addflag.crb_ipv6_recvtclass = 1;
5129 5139          }
     5140 +
5130 5141          /*
5131      -         * If app asked for hopbyhop headers and it has changed ...
     5142 +         * If app asked for hop-by-hop headers and it has changed ...
5132 5143           * For security labels, note that (1) security labels can't change on
5133 5144           * a connected socket at all, (2) we're connected to at most one peer,
5134 5145           * (3) if anything changes, then it must be some other extra option.
5135 5146           */
5136 5147          if (connp->conn_recv_ancillary.crb_ipv6_recvhopopts &&
5137 5148              ip_cmpbuf(tcp->tcp_hopopts, tcp->tcp_hopoptslen,
5138 5149              (ipp->ipp_fields & IPPF_HOPOPTS),
5139 5150              ipp->ipp_hopopts, ipp->ipp_hopoptslen)) {
5140 5151                  optlen += sizeof (struct T_opthdr) + ipp->ipp_hopoptslen;
5141 5152                  addflag.crb_ipv6_recvhopopts = 1;
↓ open down ↓ 57 lines elided ↑ open up ↑
5199 5210          mp1->b_cont = mp;
5200 5211          mp = mp1;
5201 5212          mp->b_wptr += sizeof (*todi) + optlen;
5202 5213          mp->b_datap->db_type = M_PROTO;
5203 5214          todi = (struct T_optdata_ind *)mp->b_rptr;
5204 5215          todi->PRIM_type = T_OPTDATA_IND;
5205 5216          todi->DATA_flag = 1;    /* MORE data */
5206 5217          todi->OPT_length = optlen;
5207 5218          todi->OPT_offset = sizeof (*todi);
5208 5219          optptr = (uchar_t *)&todi[1];
     5220 +
     5221 +        /* If app asked for TOS and it has changed ... */
     5222 +        if (addflag.crb_recvtos) {
     5223 +                toh = (struct T_opthdr *)optptr;
     5224 +                toh->level = IPPROTO_IP;
     5225 +                toh->name = IP_RECVTOS;
     5226 +                toh->len = sizeof (*toh) +
     5227 +                    P2ROUNDUP(sizeof (uint8_t), __TPI_ALIGN_SIZE);
     5228 +                toh->status = 0;
     5229 +                optptr += sizeof (*toh);
     5230 +                *(uint8_t *)optptr = ipp->ipp_type_of_service;
     5231 +                optptr = (uchar_t *)toh + toh->len;
     5232 +                ASSERT(__TPI_TOPT_ISALIGNED(optptr));
     5233 +                /* Save as "last" value */
     5234 +                tcp->tcp_recvtos = ipp->ipp_type_of_service;
     5235 +        }
     5236 +
5209 5237          /*
5210 5238           * If app asked for pktinfo and the index has changed ...
5211 5239           * Note that the local address never changes for the connection.
5212 5240           */
5213 5241          if (addflag.crb_ip_recvpktinfo) {
5214 5242                  struct in6_pktinfo *pkti;
5215 5243                  uint_t ifindex;
5216 5244  
5217 5245                  ifindex = ira->ira_ruifindex;
5218 5246                  toh = (struct T_opthdr *)optptr;
↓ open down ↓ 692 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX