17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
545916cdjpk * Common Development and Distribution License (the "License").
645916cdjpk * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
217c478bdstevel@tonic-gate/*
2266cd0f6Kacheong Poon * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
233d0a255Garrett D'Amore * Copyright (c) 2011 Nexenta Systems, Inc. All rights reserved.
24d499451Cody Peter Mello * Copyright 2019 Joyent, Inc.
25c12492cSebastien Roy * Copyright (c) 2016 by Delphix. All rights reserved.
267c478bdstevel@tonic-gate */
277c478bdstevel@tonic-gate
287c478bdstevel@tonic-gate#include <sys/types.h>
297c478bdstevel@tonic-gate#include <sys/stream.h>
307c478bdstevel@tonic-gate#define	_SUN_TPI_VERSION 2
317c478bdstevel@tonic-gate#include <sys/tihdr.h>
327c478bdstevel@tonic-gate#include <sys/socket.h>
337c478bdstevel@tonic-gate#include <sys/xti_xtiopt.h>
347c478bdstevel@tonic-gate#include <sys/xti_inet.h>
35721fffeKacheong Poon#include <sys/policy.h>
367c478bdstevel@tonic-gate
37d499451Cody Peter Mello#include <inet/cc.h>
387c478bdstevel@tonic-gate#include <inet/common.h>
397c478bdstevel@tonic-gate#include <netinet/ip6.h>
407c478bdstevel@tonic-gate#include <inet/ip.h>
417c478bdstevel@tonic-gate
427c478bdstevel@tonic-gate#include <netinet/in.h>
437c478bdstevel@tonic-gate#include <netinet/tcp.h>
447c478bdstevel@tonic-gate#include <inet/optcom.h>
45721fffeKacheong Poon#include <inet/proto_set.h>
46bd670b3Erik Nordmark#include <inet/tcp_impl.h>
477c478bdstevel@tonic-gate
48ca3c8f4David Höppnerstatic int	tcp_opt_default(queue_t *, int, int, uchar_t *);
49ca3c8f4David Höppner
507c478bdstevel@tonic-gate/*
517c478bdstevel@tonic-gate * Table of all known options handled on a TCP protocol stack.
527c478bdstevel@tonic-gate *
537c478bdstevel@tonic-gate * Note: This table contains options processed by both TCP and IP levels
547c478bdstevel@tonic-gate *       and is the superset of options that can be performed on a TCP over IP
557c478bdstevel@tonic-gate *       stack.
567c478bdstevel@tonic-gate */
577c478bdstevel@tonic-gateopdes_t	tcp_opt_arr[] = {
587c478bdstevel@tonic-gate
59bd670b3Erik Nordmark{ SO_LINGER,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
607c478bdstevel@tonic-gate	sizeof (struct linger), 0 },
617c478bdstevel@tonic-gate
62bd670b3Erik Nordmark{ SO_DEBUG,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
63bd670b3Erik Nordmark{ SO_KEEPALIVE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
64bd670b3Erik Nordmark{ SO_DONTROUTE,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
65bd670b3Erik Nordmark{ SO_USELOOPBACK, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
667c478bdstevel@tonic-gate	},
67bd670b3Erik Nordmark{ SO_BROADCAST,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
68bd670b3Erik Nordmark{ SO_REUSEADDR, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
69bd670b3Erik Nordmark{ SO_OOBINLINE, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
70bd670b3Erik Nordmark{ SO_TYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
71bd670b3Erik Nordmark{ SO_SNDBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
72bd670b3Erik Nordmark{ SO_RCVBUF,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
73bd670b3Erik Nordmark{ SO_SNDTIMEO,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
743986c91anders	sizeof (struct timeval), 0 },
75bd670b3Erik Nordmark{ SO_RCVTIMEO,	SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0,
763986c91anders	sizeof (struct timeval), 0 },
77bd670b3Erik Nordmark{ SO_DGRAM_ERRIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
787c478bdstevel@tonic-gate	},
797c478bdstevel@tonic-gate{ SO_SND_COPYAVOID, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
80bd670b3Erik Nordmark{ SO_ANON_MLP, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
815d0bc3esommerfe	0 },
82bd670b3Erik Nordmark{ SO_MAC_EXEMPT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
835d0bc3esommerfe	0 },
84bd670b3Erik Nordmark{ SO_MAC_IMPLICIT, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
855d3b8cbBill Sommerfeld	0 },
86bd670b3Erik Nordmark{ SO_ALLZONES, SOL_SOCKET, OA_R, OA_RW, OP_CONFIG, 0, sizeof (int),
875d0bc3esommerfe	0 },
88bd670b3Erik Nordmark{ SO_EXCLBIND, SOL_SOCKET, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
89ae34757kcpoon
90bd670b3Erik Nordmark{ SO_DOMAIN,	SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
9188cda07kcpoon
92bd670b3Erik Nordmark{ SO_PROTOTYPE,	SOL_SOCKET, OA_R, OA_R, OP_NP, 0, sizeof (int), 0 },
9388cda07kcpoon
94bd670b3Erik Nordmark{ TCP_NODELAY,	IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
957c478bdstevel@tonic-gate	},
96bd670b3Erik Nordmark{ TCP_MAXSEG,	IPPROTO_TCP, OA_R, OA_R, OP_NP, 0, sizeof (uint_t),
977c478bdstevel@tonic-gate	536 },
987c478bdstevel@tonic-gate
997c478bdstevel@tonic-gate{ TCP_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
100bd670b3Erik Nordmark	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
1017c478bdstevel@tonic-gate
1027c478bdstevel@tonic-gate{ TCP_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
103bd670b3Erik Nordmark	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
1047c478bdstevel@tonic-gate
1057c478bdstevel@tonic-gate{ TCP_CONN_NOTIFY_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
106bd670b3Erik Nordmark	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
1077c478bdstevel@tonic-gate
1087c478bdstevel@tonic-gate{ TCP_CONN_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
109bd670b3Erik Nordmark	OP_DEF_FN, sizeof (int), -1 /* not initialized */ },
1107c478bdstevel@tonic-gate
111bd670b3Erik Nordmark{ TCP_RECVDSTADDR, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int),
1127c478bdstevel@tonic-gate	0 },
1137c478bdstevel@tonic-gate
114bd670b3Erik Nordmark{ TCP_ANONPRIVBIND, IPPROTO_TCP, OA_R, OA_RW, OP_PRIVPORT, 0,
1157c478bdstevel@tonic-gate	sizeof (int), 0 },
1167c478bdstevel@tonic-gate
117bd670b3Erik Nordmark{ TCP_EXCLBIND, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0
1187c478bdstevel@tonic-gate	},
1197c478bdstevel@tonic-gate
120bd670b3Erik Nordmark{ TCP_INIT_CWND, IPPROTO_TCP, OA_RW, OA_RW, OP_CONFIG, 0,
1217c478bdstevel@tonic-gate	sizeof (int), 0 },
1227c478bdstevel@tonic-gate
123bd670b3Erik Nordmark{ TCP_KEEPALIVE_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0,
1247c478bdstevel@tonic-gate	sizeof (int), 0	},
1257c478bdstevel@tonic-gate
1263d0a255Garrett D'Amore{ TCP_KEEPIDLE, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
1273d0a255Garrett D'Amore
1283d0a255Garrett D'Amore{ TCP_KEEPCNT, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
1293d0a255Garrett D'Amore
1303d0a255Garrett D'Amore{ TCP_KEEPINTVL, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
1313d0a255Garrett D'Amore
132bd670b3Erik Nordmark{ TCP_KEEPALIVE_ABORT_THRESHOLD, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0,
1337c478bdstevel@tonic-gate	sizeof (int), 0	},
1347c478bdstevel@tonic-gate
135bd670b3Erik Nordmark{ TCP_CORK, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
1367c478bdstevel@tonic-gate
137707e74bKacheong Poon{ TCP_RTO_INITIAL, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
138707e74bKacheong Poon
139707e74bKacheong Poon{ TCP_RTO_MIN, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
140707e74bKacheong Poon
141707e74bKacheong Poon{ TCP_RTO_MAX, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (uint32_t), 0 },
142707e74bKacheong Poon
143707e74bKacheong Poon{ TCP_LINGER2, IPPROTO_TCP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
144707e74bKacheong Poon
145d499451Cody Peter Mello{ TCP_CONGESTION, IPPROTO_TCP, OA_RW, OA_RW, OP_NP,
146d499451Cody Peter Mello	OP_VARLEN, CC_ALGO_NAME_MAX, 0 },
147d499451Cody Peter Mello
1487c478bdstevel@tonic-gate{ IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
149bd670b3Erik Nordmark	(OP_VARLEN|OP_NODEFAULT),
1500f1702cYu Xiangning<Eric.Yu@Sun.COM>	IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
1517c478bdstevel@tonic-gate{ T_IP_OPTIONS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP,
152bd670b3Erik Nordmark	(OP_VARLEN|OP_NODEFAULT),
1530f1702cYu Xiangning<Eric.Yu@Sun.COM>	IP_MAX_OPT_LENGTH + IP_ADDR_LEN, -1 /* not initialized */ },
1547c478bdstevel@tonic-gate
155bd670b3Erik Nordmark{ IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
156bd670b3Erik Nordmark{ T_IP_TOS,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
157bd670b3Erik Nordmark{ IP_TTL,	IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
1587c478bdstevel@tonic-gate	sizeof (int), -1 /* not initialized */ },
1597c478bdstevel@tonic-gate
160bd670b3Erik Nordmark{ IP_SEC_OPT, IPPROTO_IP, OA_RW, OA_RW, OP_NP, OP_NODEFAULT,
1617c478bdstevel@tonic-gate	sizeof (ipsec_req_t), -1 /* not initialized */ },
1627c478bdstevel@tonic-gate
163bd670b3Erik Nordmark{ IP_BOUND_IF, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0,
1647c478bdstevel@tonic-gate	sizeof (int),	0 /* no ifindex */ },
1657c478bdstevel@tonic-gate
166bd670b3Erik Nordmark{ IP_UNSPEC_SRC, IPPROTO_IP, OA_R, OA_RW, OP_RAW, 0,
1677c478bdstevel@tonic-gate	sizeof (int), 0 },
1687c478bdstevel@tonic-gate
169bd670b3Erik Nordmark{ IPV6_UNICAST_HOPS, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, OP_DEF_FN,
1707c478bdstevel@tonic-gate	sizeof (int), -1 /* not initialized */ },
1717c478bdstevel@tonic-gate
172bd670b3Erik Nordmark{ IPV6_BOUND_IF, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP, 0,
1737c478bdstevel@tonic-gate	sizeof (int),	0 /* no ifindex */ },
1747c478bdstevel@tonic-gate
175bd670b3Erik Nordmark{ IP_DONTFRAG, IPPROTO_IP, OA_RW, OA_RW, OP_NP, 0, sizeof (int), 0 },
176bd670b3Erik Nordmark
177bd670b3Erik Nordmark{ IP_NEXTHOP, IPPROTO_IP, OA_R, OA_RW, OP_CONFIG, 0,
17843d18f1priyanka	sizeof (in_addr_t),	-1 /* not initialized  */ },
17943d18f1priyanka
180bd670b3Erik Nordmark{ IPV6_UNSPEC_SRC, IPPROTO_IPV6, OA_R, OA_RW, OP_RAW, 0,
1817c478bdstevel@tonic-gate	sizeof (int), 0 },
1827c478bdstevel@tonic-gate
1837c478bdstevel@tonic-gate{ IPV6_PKTINFO, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
184bd670b3Erik Nordmark	(OP_NODEFAULT|OP_VARLEN),
1857c478bdstevel@tonic-gate	sizeof (struct in6_pktinfo), -1 /* not initialized */ },
1867c478bdstevel@tonic-gate{ IPV6_NEXTHOP, IPPROTO_IPV6, OA_RW, OA_RW, OP_NP,
187