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 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #include <inet/ip.h>
27 #include <inet/ip6.h>
28 #include <inet/sctp/sctp_stack.h>
29 #include <inet/sctp/sctp_impl.h>
30 #include <sys/sunddi.h>
31
32 /* Max size IP datagram is 64k - 1 */
33 #define SCTP_MSS_MAX_IPV4 (IP_MAXPACKET - (sizeof (ipha_t) + \
34 sizeof (sctp_hdr_t)))
35 #define SCTP_MSS_MAX_IPV6 (IP_MAXPACKET - (sizeof (ip6_t) + \
36 sizeof (sctp_hdr_t)))
37 /* Max of the above */
38 #define SCTP_MSS_MAX SCTP_MSS_MAX_IPV4
39
40 /*
41 * returns the current list of listener limit configuration.
42 */
43 /* ARGSUSED */
44 static int
45 sctp_listener_conf_get(void *cbarg, mod_prop_info_t *pinfo, const char *ifname,
46 void *val, uint_t psize, uint_t flags)
47 {
48 sctp_stack_t *sctps = (sctp_stack_t *)cbarg;
49 sctp_listener_t *sl;
50 char *pval = val;
51 size_t nbytes = 0, tbytes = 0;
52 uint_t size;
53 int err = 0;
54
55 bzero(pval, psize);
56 size = psize;
57
58 if (flags & (MOD_PROP_DEFAULT|MOD_PROP_PERM|MOD_PROP_POSSIBLE))
59 return (0);
60
61 mutex_enter(&sctps->sctps_listener_conf_lock);
62 for (sl = list_head(&sctps->sctps_listener_conf); sl != NULL;
63 sl = list_next(&sctps->sctps_listener_conf, sl)) {
64 if (psize == size)
65 nbytes = snprintf(pval, size, "%d:%d", sl->sl_port,
66 sl->sl_ratio);
67 else
68 nbytes = snprintf(pval, size, ",%d:%d", sl->sl_port,
69 sl->sl_ratio);
70 size -= nbytes;
71 pval += nbytes;
72 tbytes += nbytes;
73 if (tbytes >= psize) {
74 /* Buffer overflow, stop copying information */
75 err = ENOBUFS;
76 break;
77 }
78 }
79
80 mutex_exit(&sctps->sctps_listener_conf_lock);
81 return (err);
82 }
83
84 /*
85 * add a new listener limit configuration.
86 */
87 /* ARGSUSED */
88 static int
89 sctp_listener_conf_add(void *cbarg, cred_t *cr, mod_prop_info_t *pinfo,
90 const char *ifname, const void* pval, uint_t flags)
91 {
92 sctp_listener_t *new_sl;
93 sctp_listener_t *sl;
94 long lport;
95 long ratio;
96 char *colon;
97 sctp_stack_t *sctps = (sctp_stack_t *)cbarg;
98
99 if (flags & MOD_PROP_DEFAULT)
100 return (ENOTSUP);
101
102 if (ddi_strtol(pval, &colon, 10, &lport) != 0 || lport <= 0 ||
103 lport > USHRT_MAX || *colon != ':') {
104 return (EINVAL);
105 }
106 if (ddi_strtol(colon + 1, NULL, 10, &ratio) != 0 || ratio <= 0)
107 return (EINVAL);
108
109 mutex_enter(&sctps->sctps_listener_conf_lock);
110 for (sl = list_head(&sctps->sctps_listener_conf); sl != NULL;
111 sl = list_next(&sctps->sctps_listener_conf, sl)) {
112 /* There is an existing entry, so update its ratio value. */
113 if (sl->sl_port == lport) {
114 sl->sl_ratio = ratio;
115 mutex_exit(&sctps->sctps_listener_conf_lock);
116 return (0);
117 }
118 }
119
120 if ((new_sl = kmem_alloc(sizeof (sctp_listener_t), KM_NOSLEEP)) ==
121 NULL) {
122 mutex_exit(&sctps->sctps_listener_conf_lock);
123 return (ENOMEM);
124 }
125
126 new_sl->sl_port = lport;
127 new_sl->sl_ratio = ratio;
128 list_insert_tail(&sctps->sctps_listener_conf, new_sl);
129 mutex_exit(&sctps->sctps_listener_conf_lock);
130 return (0);
131 }
132
133 /*
134 * remove a listener limit configuration.
135 */
136 /* ARGSUSED */
137 static int
138 sctp_listener_conf_del(void *cbarg, cred_t *cr, mod_prop_info_t *pinfo,
139 const char *ifname, const void* pval, uint_t flags)
140 {
141 sctp_listener_t *sl;
142 long lport;
143 sctp_stack_t *sctps = (sctp_stack_t *)cbarg;
144
145 if (flags & MOD_PROP_DEFAULT)
146 return (ENOTSUP);
147
148 if (ddi_strtol(pval, NULL, 10, &lport) != 0 || lport <= 0 ||
149 lport > USHRT_MAX) {
150 return (EINVAL);
151 }
152 mutex_enter(&sctps->sctps_listener_conf_lock);
153 for (sl = list_head(&sctps->sctps_listener_conf); sl != NULL;
154 sl = list_next(&sctps->sctps_listener_conf, sl)) {
155 if (sl->sl_port == lport) {
156 list_remove(&sctps->sctps_listener_conf, sl);
157 mutex_exit(&sctps->sctps_listener_conf_lock);
158 kmem_free(sl, sizeof (sctp_listener_t));
159 return (0);
160 }
161 }
162 mutex_exit(&sctps->sctps_listener_conf_lock);
163 return (ESRCH);
164 }
165
166 /*
167 * All of these are alterable, within the min/max values given, at run time.
168 *
169 * Note: All those tunables which do not start with "_" are Committed and
170 * therefore are public. See PSARC 2010/080.
171 */
172 mod_prop_info_t sctp_propinfo_tbl[] = {
173 { "_max_init_retr", MOD_PROTO_SCTP,
174 mod_set_uint32, mod_get_uint32,
175 {0, 128, 8}, {8} },
176
177 { "_pa_max_retr", MOD_PROTO_SCTP,
178 mod_set_uint32, mod_get_uint32,
179 {1, 128, 10}, {10} },
180
181 { "_pp_max_retr", MOD_PROTO_SCTP,
182 mod_set_uint32, mod_get_uint32,
183 {1, 128, 5}, {5} },
184
185 { "_cwnd_max", MOD_PROTO_SCTP,
186 mod_set_uint32, mod_get_uint32,
187 {128, (1<<30), 1024*1024}, {1024*1024} },
188
189 { "smallest_nonpriv_port", MOD_PROTO_SCTP,
190 mod_set_uint32, mod_get_uint32,
191 {1024, (32*1024), 1024}, {1024} },
192
193 { "_ipv4_ttl", MOD_PROTO_SCTP,
194 mod_set_uint32, mod_get_uint32,
195 {1, 255, 64}, {64} },
196
197 { "_heartbeat_interval", MOD_PROTO_SCTP,
198 mod_set_uint32, mod_get_uint32,
199 {0, 1*DAYS, 30*SECONDS}, {30*SECONDS} },
200
201 { "_initial_mtu", MOD_PROTO_SCTP,
202 mod_set_uint32, mod_get_uint32,
203 {68, 65535, 1500}, {1500} },
204
205 { "_mtu_probe_interval", MOD_PROTO_SCTP,
206 mod_set_uint32, mod_get_uint32,
207 {0, 1*DAYS, 10*MINUTES}, {10*MINUTES} },
218 { "_snd_lowat_fraction", MOD_PROTO_SCTP,
219 mod_set_uint32, mod_get_uint32,
220 {0, 16, 0}, {0} },
221
222 { "_ignore_path_mtu", MOD_PROTO_SCTP,
223 mod_set_boolean, mod_get_boolean,
224 {B_FALSE}, {B_FALSE} },
225
226 { "_initial_ssthresh", MOD_PROTO_SCTP,
227 mod_set_uint32, mod_get_uint32,
228 {1024, UINT32_MAX, SCTP_RECV_HIWATER}, { SCTP_RECV_HIWATER} },
229
230 { "smallest_anon_port", MOD_PROTO_SCTP,
231 mod_set_uint32, mod_get_uint32,
232 {1024, ULP_MAX_PORT, 32*1024}, {32*1024} },
233
234 { "largest_anon_port", MOD_PROTO_SCTP,
235 mod_set_uint32, mod_get_uint32,
236 {1024, ULP_MAX_PORT, ULP_MAX_PORT}, {ULP_MAX_PORT} },
237
238 { "send_maxbuf", MOD_PROTO_SCTP,
239 mod_set_uint32, mod_get_uint32,
240 {SCTP_XMIT_LOWATER, (1<<30), SCTP_XMIT_HIWATER},
241 {SCTP_XMIT_HIWATER} },
242
243 { "_xmit_lowat", MOD_PROTO_SCTP,
244 mod_set_uint32, mod_get_uint32,
245 {SCTP_XMIT_LOWATER, (1<<30), SCTP_XMIT_LOWATER},
246 {SCTP_XMIT_LOWATER} },
247
248 { "recv_maxbuf", MOD_PROTO_SCTP,
249 mod_set_uint32, mod_get_uint32,
250 {SCTP_RECV_LOWATER, (1<<30), SCTP_RECV_HIWATER},
251 {SCTP_RECV_HIWATER} },
252
253 { "_max_buf", MOD_PROTO_SCTP,
254 mod_set_uint32, mod_get_uint32,
255 {8192, (1<<30), 1024*1024}, {1024*1024} },
256
257 /* tunable - 20 */
258 { "_rtt_updates", MOD_PROTO_SCTP,
259 mod_set_uint32, mod_get_uint32,
260 {0, 65536, 20}, {20} },
261
262 { "_ipv6_hoplimit", MOD_PROTO_SCTP,
263 mod_set_uint32, mod_get_uint32,
264 {0, IPV6_MAX_HOPS, IPV6_DEFAULT_HOPS}, {IPV6_DEFAULT_HOPS} },
265
266 { "_rto_min", MOD_PROTO_SCTP,
267 mod_set_uint32, mod_get_uint32,
268 {500*MS, 60*SECONDS, 1*SECONDS}, {1*SECONDS} },
269
270 { "_rto_max", MOD_PROTO_SCTP,
271 mod_set_uint32, mod_get_uint32,
272 {1*SECONDS, 60000*SECONDS, 60*SECONDS}, {60*SECONDS} },
273
274 { "_rto_initial", MOD_PROTO_SCTP,
275 mod_set_uint32, mod_get_uint32,
|
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 /*
23 * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Copyright (c) 2013 by Delphix. All rights reserved.
25 */
26
27 #include <inet/ip.h>
28 #include <inet/ip6.h>
29 #include <inet/sctp/sctp_stack.h>
30 #include <inet/sctp/sctp_impl.h>
31 #include <sys/sunddi.h>
32
33 /* Max size IP datagram is 64k - 1 */
34 #define SCTP_MSS_MAX_IPV4 (IP_MAXPACKET - (sizeof (ipha_t) + \
35 sizeof (sctp_hdr_t)))
36 #define SCTP_MSS_MAX_IPV6 (IP_MAXPACKET - (sizeof (ip6_t) + \
37 sizeof (sctp_hdr_t)))
38 /* Max of the above */
39 #define SCTP_MSS_MAX SCTP_MSS_MAX_IPV4
40
41 /*
42 * returns the current list of listener limit configuration.
43 */
44 /* ARGSUSED */
45 static int
46 sctp_listener_conf_get(netstack_t *stack, mod_prop_info_t *pinfo,
47 const char *ifname, void *val, uint_t psize, uint_t flags)
48 {
49 sctp_stack_t *sctps = stack->netstack_sctp;
50 sctp_listener_t *sl;
51 char *pval = val;
52 size_t nbytes = 0, tbytes = 0;
53 uint_t size;
54 int err = 0;
55
56 bzero(pval, psize);
57 size = psize;
58
59 if (flags & (MOD_PROP_DEFAULT|MOD_PROP_PERM|MOD_PROP_POSSIBLE))
60 return (0);
61
62 mutex_enter(&sctps->sctps_listener_conf_lock);
63 for (sl = list_head(&sctps->sctps_listener_conf); sl != NULL;
64 sl = list_next(&sctps->sctps_listener_conf, sl)) {
65 if (psize == size)
66 nbytes = snprintf(pval, size, "%d:%d", sl->sl_port,
67 sl->sl_ratio);
68 else
69 nbytes = snprintf(pval, size, ",%d:%d", sl->sl_port,
70 sl->sl_ratio);
71 size -= nbytes;
72 pval += nbytes;
73 tbytes += nbytes;
74 if (tbytes >= psize) {
75 /* Buffer overflow, stop copying information */
76 err = ENOBUFS;
77 break;
78 }
79 }
80
81 mutex_exit(&sctps->sctps_listener_conf_lock);
82 return (err);
83 }
84
85 /*
86 * add a new listener limit configuration.
87 */
88 /* ARGSUSED */
89 static int
90 sctp_listener_conf_add(netstack_t *stack, cred_t *cr, mod_prop_info_t *pinfo,
91 const char *ifname, const void* pval, uint_t flags)
92 {
93 sctp_listener_t *new_sl;
94 sctp_listener_t *sl;
95 long lport;
96 long ratio;
97 char *colon;
98 sctp_stack_t *sctps = stack->netstack_sctp;
99
100 if (flags & MOD_PROP_DEFAULT)
101 return (ENOTSUP);
102
103 if (ddi_strtol(pval, &colon, 10, &lport) != 0 || lport <= 0 ||
104 lport > USHRT_MAX || *colon != ':') {
105 return (EINVAL);
106 }
107 if (ddi_strtol(colon + 1, NULL, 10, &ratio) != 0 || ratio <= 0)
108 return (EINVAL);
109
110 mutex_enter(&sctps->sctps_listener_conf_lock);
111 for (sl = list_head(&sctps->sctps_listener_conf); sl != NULL;
112 sl = list_next(&sctps->sctps_listener_conf, sl)) {
113 /* There is an existing entry, so update its ratio value. */
114 if (sl->sl_port == lport) {
115 sl->sl_ratio = ratio;
116 mutex_exit(&sctps->sctps_listener_conf_lock);
117 return (0);
118 }
119 }
120
121 if ((new_sl = kmem_alloc(sizeof (sctp_listener_t), KM_NOSLEEP)) ==
122 NULL) {
123 mutex_exit(&sctps->sctps_listener_conf_lock);
124 return (ENOMEM);
125 }
126
127 new_sl->sl_port = lport;
128 new_sl->sl_ratio = ratio;
129 list_insert_tail(&sctps->sctps_listener_conf, new_sl);
130 mutex_exit(&sctps->sctps_listener_conf_lock);
131 return (0);
132 }
133
134 /*
135 * remove a listener limit configuration.
136 */
137 /* ARGSUSED */
138 static int
139 sctp_listener_conf_del(netstack_t *stack, cred_t *cr, mod_prop_info_t *pinfo,
140 const char *ifname, const void* pval, uint_t flags)
141 {
142 sctp_listener_t *sl;
143 long lport;
144 sctp_stack_t *sctps = stack->netstack_sctp;
145
146 if (flags & MOD_PROP_DEFAULT)
147 return (ENOTSUP);
148
149 if (ddi_strtol(pval, NULL, 10, &lport) != 0 || lport <= 0 ||
150 lport > USHRT_MAX) {
151 return (EINVAL);
152 }
153 mutex_enter(&sctps->sctps_listener_conf_lock);
154 for (sl = list_head(&sctps->sctps_listener_conf); sl != NULL;
155 sl = list_next(&sctps->sctps_listener_conf, sl)) {
156 if (sl->sl_port == lport) {
157 list_remove(&sctps->sctps_listener_conf, sl);
158 mutex_exit(&sctps->sctps_listener_conf_lock);
159 kmem_free(sl, sizeof (sctp_listener_t));
160 return (0);
161 }
162 }
163 mutex_exit(&sctps->sctps_listener_conf_lock);
164 return (ESRCH);
165 }
166
167 static int
168 sctp_set_buf_prop(netstack_t *stack, cred_t *cr, mod_prop_info_t *pinfo,
169 const char *ifname, const void *pval, uint_t flags)
170 {
171 return (mod_set_buf_prop(stack->netstack_sctp->sctps_propinfo_tbl,
172 stack, cr, pinfo, ifname, pval, flags));
173 }
174
175 static int
176 sctp_get_buf_prop(netstack_t *stack, mod_prop_info_t *pinfo, const char *ifname,
177 void *val, uint_t psize, uint_t flags)
178 {
179 return (mod_get_buf_prop(stack->netstack_sctp->sctps_propinfo_tbl,
180 stack, pinfo, ifname, val, psize, flags));
181 }
182
183 /*
184 * All of these are alterable, within the min/max values given, at run time.
185 *
186 * Note: All those tunables which do not start with "_" are Committed and
187 * therefore are public. See PSARC 2010/080.
188 */
189 mod_prop_info_t sctp_propinfo_tbl[] = {
190 { "_max_init_retr", MOD_PROTO_SCTP,
191 mod_set_uint32, mod_get_uint32,
192 {0, 128, 8}, {8} },
193
194 { "_pa_max_retr", MOD_PROTO_SCTP,
195 mod_set_uint32, mod_get_uint32,
196 {1, 128, 10}, {10} },
197
198 { "_pp_max_retr", MOD_PROTO_SCTP,
199 mod_set_uint32, mod_get_uint32,
200 {1, 128, 5}, {5} },
201
202 { "_cwnd_max", MOD_PROTO_SCTP,
203 mod_set_uint32, mod_get_uint32,
204 {128, ULP_MAX_BUF, 1024*1024}, {1024*1024} },
205
206 { "smallest_nonpriv_port", MOD_PROTO_SCTP,
207 mod_set_uint32, mod_get_uint32,
208 {1024, (32*1024), 1024}, {1024} },
209
210 { "_ipv4_ttl", MOD_PROTO_SCTP,
211 mod_set_uint32, mod_get_uint32,
212 {1, 255, 64}, {64} },
213
214 { "_heartbeat_interval", MOD_PROTO_SCTP,
215 mod_set_uint32, mod_get_uint32,
216 {0, 1*DAYS, 30*SECONDS}, {30*SECONDS} },
217
218 { "_initial_mtu", MOD_PROTO_SCTP,
219 mod_set_uint32, mod_get_uint32,
220 {68, 65535, 1500}, {1500} },
221
222 { "_mtu_probe_interval", MOD_PROTO_SCTP,
223 mod_set_uint32, mod_get_uint32,
224 {0, 1*DAYS, 10*MINUTES}, {10*MINUTES} },
235 { "_snd_lowat_fraction", MOD_PROTO_SCTP,
236 mod_set_uint32, mod_get_uint32,
237 {0, 16, 0}, {0} },
238
239 { "_ignore_path_mtu", MOD_PROTO_SCTP,
240 mod_set_boolean, mod_get_boolean,
241 {B_FALSE}, {B_FALSE} },
242
243 { "_initial_ssthresh", MOD_PROTO_SCTP,
244 mod_set_uint32, mod_get_uint32,
245 {1024, UINT32_MAX, SCTP_RECV_HIWATER}, { SCTP_RECV_HIWATER} },
246
247 { "smallest_anon_port", MOD_PROTO_SCTP,
248 mod_set_uint32, mod_get_uint32,
249 {1024, ULP_MAX_PORT, 32*1024}, {32*1024} },
250
251 { "largest_anon_port", MOD_PROTO_SCTP,
252 mod_set_uint32, mod_get_uint32,
253 {1024, ULP_MAX_PORT, ULP_MAX_PORT}, {ULP_MAX_PORT} },
254
255 { "send_buf", MOD_PROTO_SCTP,
256 sctp_set_buf_prop, sctp_get_buf_prop,
257 {SCTP_XMIT_LOWATER, ULP_MAX_BUF, SCTP_XMIT_HIWATER},
258 {SCTP_XMIT_HIWATER} },
259
260 { "_xmit_lowat", MOD_PROTO_SCTP,
261 mod_set_uint32, mod_get_uint32,
262 {SCTP_XMIT_LOWATER, ULP_MAX_BUF, SCTP_XMIT_LOWATER},
263 {SCTP_XMIT_LOWATER} },
264
265 { "recv_buf", MOD_PROTO_SCTP,
266 sctp_set_buf_prop, sctp_get_buf_prop,
267 {SCTP_RECV_LOWATER, ULP_MAX_BUF, SCTP_RECV_HIWATER},
268 {SCTP_RECV_HIWATER} },
269
270 { "max_buf", MOD_PROTO_SCTP,
271 mod_set_uint32, mod_get_uint32,
272 {8192, ULP_MAX_BUF, 1024*1024}, {1024*1024} },
273
274 /* tunable - 20 */
275 { "_rtt_updates", MOD_PROTO_SCTP,
276 mod_set_uint32, mod_get_uint32,
277 {0, 65536, 20}, {20} },
278
279 { "_ipv6_hoplimit", MOD_PROTO_SCTP,
280 mod_set_uint32, mod_get_uint32,
281 {0, IPV6_MAX_HOPS, IPV6_DEFAULT_HOPS}, {IPV6_DEFAULT_HOPS} },
282
283 { "_rto_min", MOD_PROTO_SCTP,
284 mod_set_uint32, mod_get_uint32,
285 {500*MS, 60*SECONDS, 1*SECONDS}, {1*SECONDS} },
286
287 { "_rto_max", MOD_PROTO_SCTP,
288 mod_set_uint32, mod_get_uint32,
289 {1*SECONDS, 60000*SECONDS, 60*SECONDS}, {60*SECONDS} },
290
291 { "_rto_initial", MOD_PROTO_SCTP,
292 mod_set_uint32, mod_get_uint32,
|