xref: /titanic_41/usr/src/uts/common/fs/sockfs/nl7cnca.c (revision d29b2c4438482eb00488be49a1f5d6835f455546)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 
30 #include <sys/types.h>
31 #include <sys/conf.h>
32 #include <sys/modctl.h>
33 #include <sys/stream.h>
34 #include <sys/strsubr.h>
35 #include <sys/stropts.h>
36 #define	_SUN_TPI_VERSION 2
37 #include <sys/ddi.h>
38 #include <sys/sunddi.h>
39 #include <sys/cmn_err.h>
40 #include <sys/debug.h>
41 #include <sys/vtrace.h>
42 #include <sys/errno.h>
43 #include <inet/common.h>
44 #include <inet/led.h>
45 #include <inet/mi.h>
46 #include <inet/nd.h>
47 #include <sys/strsun.h>
48 
49 #include <fs/sockfs/nl7c.h>
50 #include <fs/sockfs/nl7curi.h>
51 
52 #include <inet/nca/nca.h>
53 #include <inet/nca/ncalogd.h>
54 
55 /*
56  * This file is for NCA compatability, specifically it provides ndd
57  * support for existing NCA ndd ...
58  */
59 
60 extern boolean_t	nl7c_logd_enabled;
61 extern nca_fio_t	*nl7c_logd_fio;
62 extern clock_t		nl7c_uri_ttl;
63 extern boolean_t	nl7c_use_kmem;
64 extern uint64_t		nl7c_file_prefetch;
65 extern uint64_t		nl7c_uri_max;
66 extern uint64_t		nl7c_uri_bytes;
67 
68 extern void		nl7c_mi_report_addr(mblk_t *);
69 
70 #define	MS	1L
71 #define	SECONDS	(1000 * MS)
72 #define	MINUTES	(60 * SECONDS)
73 #define	HOURS	(60 * MINUTES)
74 #define	DAYS	(24 * HOURS)
75 
76 #define	PARAM_MAX UINT_MAX
77 #define	PARAML_MAX ULONG_MAX
78 
79 #include <inet/nca/ncandd.h>
80 
81 uint32_t nca_major_version = 1;
82 uint32_t nca_minor_version = 3;
83 uint32_t nca_httpd_version = NCA_HTTP_VERSION1;
84 uint32_t nca_logd_version = NCA_LOG_VERSION1;
85 
86 caddr_t	nca_g_nd;	/* Head of 'named dispatch' variable list */
87 
88 /*
89  * min, max, and value are int64_t's, addr is the optional address of an
90  * external int64_t to be updated at init/set, name is the ndd name used
91  * to access. Note, if min == max then only get is allowed, i.e. RO.
92  */
93 
94 /* BEGIN CSTYLED */
95 ncaparam_t	nca_param_arr[] = {
96  /*min	max		value		name */
97  { 0,	1,		1,		"nca_log_cycle"},
98  { 0,	1,		0,		"no_caching"},
99  { 0,	PARAML_MAX,    	0,		"nca_log_size"},
100  { 0,	PARAM_MAX,     	10000000,	"nca_max_cache_size"},
101  { 0,	PARAM_MAX,	300*SECONDS,	"nca_http_timeout"},
102  { 0,	PARAM_MAX,	15*SECONDS,	"nca_http_keep_alive_timeout"},
103  { 0,	PARAM_MAX,	100,		"nca_http_keep_alive_max"},
104  { 0,	1,		1,		"nca_inq_nointr"},
105  { 0,	1,		1,		"nca_use_hwcksum"},
106  { 0,	PARAM_MAX,	0,		"nca_segmap_min_size"},
107 };
108 
109 /*
110  * Obsolete ip variables, use "/dev/ip" instead.
111  */
112 
113 ncaparam_t	nca_ip_obsolete_arr[] = {
114  { 0, 0, 0, "ip_forwarding"},
115  { 0, 0, 0, "ip_respond_to_address_mask_broadcast"},
116  { 0, 0, 0, "ip_respond_to_echo_broadcast"},
117  { 0, 0, 0, "ip_respond_to_timestamp"},
118  { 0, 0, 0, "ip_respond_to_timestamp_broadcast"},
119  { 0, 0, 0, "ip_send_redirects"},
120  { 0, 0, 0, "ip_forward_directed_broadcasts"},
121  { 0, 0, 0, "ip_debug"},
122  { 0, 0, 0, "ip_mrtdebug"},
123  { 0, 0, 0, "ip_ire_cleanup_interval" },
124  { 0, 0, 0, "ip_ire_flush_interval" },
125  { 0, 0, 0, "ip_ire_redirect_interval" },
126  { 0, 0, 0, "ip_def_ttl" },
127  { 0, 0, 0, "ip_forward_src_routed"},
128  { 0, 0, 0, "ip_wroff_extra" },
129  { 0, 0, 0, "ip_ire_pathmtu_interval" },
130  { 0, 0, 0, "ip_icmp_return_data_bytes" },
131  { 0, 0, 0, "ip_send_source_quench" },
132  { 0, 0, 0, "ip_path_mtu_discovery" },
133  { 0, 0, 0, "ip_ignore_delete_time" },
134  { 0, 0, 0, "ip_ignore_redirect" },
135  { 0, 0, 0, "ip_output_queue" },
136  { 0, 0, 0, "ip_broadcast_ttl" },
137  { 0, 0, 0, "ip_icmp_err_interval" },
138  { 0, 0, 0, "ip_reass_queue_bytes" },
139  { 0, 0, 0, "ip_strict_dst_multihoming" },
140  { 0, 0, 0, "ip_addrs_per_if"},
141 };
142 
143 /*
144  * Obsolete tcp variables, use "/dev/tcp" instead.
145  */
146 
147 ncaparam_t	nca_tcp_obsolete_arr[] = {
148  { 0, 0, 0, "tcp_time_wait_interval"},
149  { 0, 0, 0, "tcp_conn_req_max_q" },
150  { 0, 0, 0, "tcp_conn_req_max_q0" },
151  { 0, 0, 0, "tcp_conn_req_min" },
152  { 0, 0, 0, "tcp_conn_grace_period" },
153  { 0, 0, 0, "tcp_cwnd_max" },
154  { 0, 0, 0, "tcp_debug" },
155  { 0, 0, 0, "tcp_smallest_nonpriv_port"},
156  { 0, 0, 0, "tcp_ip_abort_cinterval"},
157  { 0, 0, 0, "tcp_ip_abort_linterval"},
158  { 0, 0, 0, "tcp_ip_abort_interval"},
159  { 0, 0, 0, "tcp_ip_notify_cinterval"},
160  { 0, 0, 0, "tcp_ip_notify_interval"},
161  { 0, 0, 0, "tcp_ip_ttl"},
162  { 0, 0, 0, "tcp_keepalive_interval"},
163  { 0, 0, 0, "tcp_maxpsz_multiplier" },
164  { 0, 0, 0, "tcp_mss_def"},
165  { 0, 0, 0, "tcp_mss_max"},
166  { 0, 0, 0, "tcp_mss_min"},
167  { 0, 0, 0, "tcp_naglim_def"},
168  { 0, 0, 0, "tcp_rexmit_interval_initial"},
169  { 0, 0, 0, "tcp_rexmit_interval_max"},
170  { 0, 0, 0, "tcp_rexmit_interval_min"},
171  { 0, 0, 0, "tcp_wroff_xtra" },
172  { 0, 0, 0, "tcp_deferred_ack_interval" },
173  { 0, 0, 0, "tcp_snd_lowat_fraction" },
174  { 0, 0, 0, "tcp_sth_rcv_hiwat" },
175  { 0, 0, 0, "tcp_sth_rcv_lowat" },
176  { 0, 0, 0, "tcp_dupack_fast_retransmit" },
177  { 0, 0, 0, "tcp_ignore_path_mtu" },
178  { 0, 0, 0, "tcp_rcv_push_wait" },
179  { 0, 0, 0, "tcp_smallest_anon_port"},
180  { 0, 0, 0, "tcp_largest_anon_port"},
181  { 0, 0, 0, "tcp_xmit_hiwat"},
182  { 0, 0, 0, "tcp_xmit_lowat"},
183  { 0, 0, 0, "tcp_recv_hiwat"},
184  { 0, 0, 0, "tcp_recv_hiwat_minmss"},
185  { 0, 0, 0, "tcp_fin_wait_2_flush_interval"},
186  { 0, 0, 0, "tcp_co_min"},
187  { 0, 0, 0, "tcp_max_buf"},
188  { 0, 0, 0, "tcp_strong_iss"},
189  { 0, 0, 0, "tcp_rtt_updates"},
190  { 0, 0, 0, "tcp_wscale_always"},
191  { 0, 0, 0, "tcp_tstamp_always"},
192  { 0, 0, 0, "tcp_tstamp_if_wscale"},
193  { 0, 0, 0, "tcp_rexmit_interval_extra"},
194  { 0, 0, 0, "tcp_deferred_acks_max"},
195  { 0, 0, 0, "tcp_slow_start_after_idle"},
196  { 0, 0, 0, "tcp_slow_start_initial"},
197  { 0, 0, 0, "tcp_co_timer_interval"},
198  { 0, 0, 0, "tcp_sack_permitted"},
199 #ifdef DEBUG
200  { 0, 0, 0, "tcp_drop_oob"},
201 #endif
202 };
203 
204 /*
205  * Obsolete nca variables, just warn.
206  */
207 
208 ncaparam_t	nca_nca_obsolete_arr[] = {
209  { 0, 0, 0, "nca_ipport_table_bucket"},
210  { 0, 0, 0, "nca_ipport_table_size"},
211  { 0, 0, 0, "nca_ipport_table_expand"},
212  { 0, 0, 0, "nca_ipport_table_shrink"},
213  { 0, 0, 0, "nca_ip_virtual_hosting"},
214  { 0, 0, 0, "httpd_door_address"},
215  { 0, 0, 0, "httpd_door_path"},
216  { 0, 0, 0, "httpd_downdoor_path"},
217  { 0, 0, 0, "nca_ppmax"},
218  { 0, 0, 0, "nca_vpmax"},
219  { 0, 0, 0, "nca_use_segmap"},
220  { 0, 0, 0, "nca_availrmem"},
221  { 0, 0, 0, "nca_maxkmem"},
222  { 0, 0, 0, "nca_log_file"},
223  { 0, 0, 0, "conn_status"},
224  { 0, 0, 0, "conn_status_all"},
225  { 0, 0, 0, "nca_conn_req_max_q"},
226  { 0, 0, 0, "nca_conn_req_max_q0"},
227  { 0, 0, 0, "cache_clear"},
228  { 0, 0, 0, "nca_node_hash"},
229  { 0, 0, 0, "node_status"},
230 #ifdef DEBUG
231  { 0, 0, 0, "nca_debug_counter"},
232 #endif
233 };
234 /* END CSTYLED */
235 
236 static int
237 /*ARGSUSED*/
238 nl7c_uri_ttl_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
239 {
240 	(void) mi_mpprintf(mp, "%ld", nl7c_uri_ttl);
241 	return (0);
242 }
243 
244 static int
245 /*ARGSUSED*/
246 nl7c_uri_ttl_set(queue_t *q, mblk_t *mp, char *value, caddr_t nu, cred_t *cr)
247 {
248 	if (ddi_strtol(value, NULL, 10, &nl7c_uri_ttl) != 0)
249 		return (EINVAL);
250 	return (0);
251 }
252 
253 static int
254 /*ARGSUSED*/
255 nca_logging_on_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
256 {
257 	(void) mi_mpprintf(mp, "%d", nl7c_logd_enabled);
258 	return (0);
259 }
260 
261 static int
262 /*ARGSUSED*/
263 nca_logging_on_set(queue_t *q, mblk_t *mp, char *value, caddr_t nu, cred_t *cr)
264 {
265 	long new_value;
266 
267 	if (ddi_strtol(value, NULL, 10, &new_value) != 0 || new_value < 0 ||
268 	    new_value > 1) {
269 		return (EINVAL);
270 	}
271 	if (nca_fio_cnt(nl7c_logd_fio) == 0)
272 		return (EINVAL);
273 	nl7c_logd_enabled = new_value;
274 
275 	return (0);
276 }
277 
278 static int
279 /*ARGSUSED*/
280 nca_version_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
281 {
282 	(void) mi_mpprintf(mp, "%d.%d", nca_major_version, nca_minor_version);
283 	return (0);
284 }
285 
286 static int
287 /*ARGSUSED*/
288 nca_httpd_version_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
289 {
290 	(void) mi_mpprintf(mp, "%d", nca_httpd_version);
291 	return (0);
292 }
293 
294 static int
295 /*ARGSUSED*/
296 nca_logd_version_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
297 {
298 	(void) mi_mpprintf(mp, "%d", nca_logd_version);
299 	return (0);
300 }
301 
302 static int
303 /*ARGSUSED*/
304 nca_httpd_door_inst_get(queue_t *q, mblk_t *mp, caddr_t nu, cred_t *cr)
305 {
306 	nl7c_mi_report_addr(mp);
307 	return (0);
308 }
309 
310 static int
311 /*ARGSUSED*/
312 nca_param_get(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
313 {
314 	ncaparam_t	*ncapa = (ncaparam_t *)cp;
315 
316 	(void) mi_mpprintf(mp, "%ld", ncapa->param_val);
317 	return (0);
318 }
319 
320 static int
321 /*ARGSUSED*/
322 nca_param_set(queue_t *q, mblk_t *mp, char *value, caddr_t cp, cred_t *cr)
323 {
324 	ulong_t		new_value;
325 	ncaparam_t	*ncapa = (ncaparam_t *)cp;
326 
327 	if (ddi_strtoul(value, NULL, 10, &new_value) != 0 ||
328 	    new_value < ncapa->param_min || new_value > ncapa->param_max) {
329 		return (EINVAL);
330 	}
331 	ncapa->param_val = new_value;
332 	return (0);
333 }
334 
335 static int
336 /*ARGSUSED*/
337 nca_obsolete(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
338 {
339 	(void) mi_mpprintf(mp, "obsolete");
340 	return (0);
341 }
342 
343 static int
344 /*ARGSUSED*/
345 nca_ip_obsolete(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
346 {
347 	(void) mi_mpprintf(mp, "obsolete for /dev/nca, use /dev/ip");
348 	return (0);
349 }
350 
351 static int
352 /*ARGSUSED*/
353 nca_tcp_obsolete(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
354 {
355 	(void) mi_mpprintf(mp, "obsolete for /dev/nca, use /dev/tcp");
356 	return (0);
357 }
358 
359 static int
360 /*ARGSUSED*/
361 nca_nca_obsolete(queue_t *q, mblk_t *mp, caddr_t cp, cred_t *cr)
362 {
363 	(void) mi_mpprintf(mp, "obsolete for /dev/nca");
364 	return (0);
365 }
366 
367 static boolean_t
368 nca_param_register(ncaparam_t *ncapa, int cnt)
369 {
370 	for (; cnt-- > 0; ncapa++) {
371 		if (ncapa->param_name && ncapa->param_name[0]) {
372 			if (!nd_load(&nca_g_nd, ncapa->param_name,
373 			    nca_param_get, nca_param_set,
374 			    (caddr_t)ncapa)) {
375 				goto error;
376 			}
377 		}
378 
379 	}
380 	if (!nd_load(&nca_g_nd, "nca_version", nca_version_get, nil(pfi_t),
381 			nil(caddr_t))) {
382 		goto error;
383 	}
384 	if (!nd_load(&nca_g_nd, "nca_logd_version", nca_logd_version_get,
385 			nil(pfi_t), nil(caddr_t))) {
386 		goto error;
387 	}
388 	if (!nd_load(&nca_g_nd, "nca_logging_on", nca_logging_on_get,
389 	    nca_logging_on_set, nil(caddr_t))) {
390 		goto error;
391 	}
392 
393 	if (!nd_load(&nca_g_nd, "uri_time_to_live", nl7c_uri_ttl_get,
394 	    nl7c_uri_ttl_set, nil(caddr_t))) {
395 		goto error;
396 	}
397 	if (!nd_load(&nca_g_nd, "nca_httpd_version", nca_httpd_version_get,
398 			nil(pfi_t), nil(caddr_t))) {
399 		goto error;
400 	}
401 	if (!nd_load(&nca_g_nd, "httpd_door_instance", nca_httpd_door_inst_get,
402 			nil(pfi_t), nil(caddr_t))) {
403 		nd_free(&nca_g_nd);
404 		return (B_FALSE);
405 	}
406 
407 	ncapa = nca_ip_obsolete_arr;
408 	cnt = A_CNT(nca_ip_obsolete_arr);
409 	for (; cnt-- > 0; ncapa++) {
410 		if (ncapa->param_name && ncapa->param_name[0]) {
411 			if (!nd_load(&nca_g_nd, ncapa->param_name,
412 			    nca_ip_obsolete, NULL, (caddr_t)ncapa)) {
413 				goto error;
414 			}
415 		}
416 
417 	}
418 
419 	ncapa = nca_tcp_obsolete_arr;
420 	cnt = A_CNT(nca_tcp_obsolete_arr);
421 	for (; cnt-- > 0; ncapa++) {
422 		if (ncapa->param_name && ncapa->param_name[0]) {
423 			if (!nd_load(&nca_g_nd, ncapa->param_name,
424 			    nca_tcp_obsolete, NULL, (caddr_t)ncapa)) {
425 				goto error;
426 			}
427 		}
428 
429 	}
430 
431 	ncapa = nca_nca_obsolete_arr;
432 	cnt = A_CNT(nca_nca_obsolete_arr);
433 	for (; cnt-- > 0; ncapa++) {
434 		if (ncapa->param_name && ncapa->param_name[0]) {
435 			if (!nd_load(&nca_g_nd, ncapa->param_name,
436 			    nca_nca_obsolete, NULL, (caddr_t)ncapa)) {
437 				goto error;
438 			}
439 		}
440 
441 	}
442 
443 	return (B_TRUE);
444 
445 error:
446 	nd_free(&nca_g_nd);
447 	return (B_FALSE);
448 }
449 
450 void
451 nl7c_nca_init(void)
452 {
453 	if (! nca_g_nd) {
454 		if (! nca_param_register(nca_param_arr, A_CNT(nca_param_arr)))
455 			cmn_err(CE_WARN,
456 			    "nl7c: /dev/nca ndd initialization failed.");
457 	}
458 }
459