annotate usr/src/cmd/cmd-inet/usr.sbin/ndd.c @ 12016:0248e987199b

PSARC 2009/306 Brussels II - ipadm and libipadm PSARC 2010/080 Brussels II addendum 6827318 Brussels Phase II aka ipadm(1m) 6731945 need BSD getifaddrs() API 6909065 explicitly disallow non-contiguous netmasks in the next minor release 6853922 ifconfig dumps core when ether address is non-hexadecimal. 6815806 ipReasmTimeout value should be variable 6567083 nd_getset has some dead and confusing code. 6884466 remove unused tcp/sctp ndd tunables 6928813 Comments at odds with default value of tcp_time_wait_interval 6236982 ifconfig usesrc lets adapter use itself as source address 6936855 modifying the ip6_strict_src_multihoming to non-zero value will unbind V4 IREs
author Girish Moodalbail <Girish.Moodalbail@Sun.COM>
date Fri, 26 Mar 2010 17:53:11 -0400
parents 90d41bc81368
children 34b1540309cc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
1 /*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
2 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
3 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
4 * The contents of this file are subject to the terms of the
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
5 * Common Development and Distribution License (the "License").
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
6 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
7 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
9 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
10 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
11 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
12 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
13 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
15 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
16 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
17 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
18 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
19 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
20 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
21 /*
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
22 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
23 * Use is subject to license terms.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
24 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
25
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
26 /*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
27 * Copyright (c) 1990 Mentat Inc.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
28 * ndd.c 2.1, last change 11/14/90
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
29 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
30
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
31 #include <stdio.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
32 #include <errno.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
33 #include <ctype.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
34 #include <stdarg.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
35 #include <fcntl.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
36 #include <unistd.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
37 #include <sys/types.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
38 #include <stropts.h>
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
39 #include <inet/tunables.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
40 #include <inet/nd.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
41 #include <string.h>
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
42 #include <strings.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
43 #include <stdlib.h>
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
44 #include <libdllink.h>
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
45 #include <libintl.h>
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
46 #include <libipadm.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
47
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
48 static boolean_t do_getset(int fd, int cmd, char *buf, int buf_len);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
49 static int get_value(char *msg, char *buf, int buf_len);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
50 static void name_print(char *buf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
51 static void getset_interactive(int fd);
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
52 static int open_device(void);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
53 static char *errmsg(int err);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
54 static void fatal(char *fmt, ...);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
55 static void printe(boolean_t print_errno, char *fmt, ...);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
56
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
57 static char modpath[128]; /* path to module */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
58 static char gbuf[65536]; /* need large buffer to retrieve all names */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
59 static char usage_str[] = "usage: ndd -set device_name name value\n"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
60 " ndd [-get] device_name name [name ...]";
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
61
7776
b44ee007dfbf 6753521 show-linkprop should not return ENOTSUP for DEFAULT value of props like speed.
Sowmini Varadhan <Sowmini.Varadhan@Sun.COM>
parents: 6512
diff changeset
62 /*
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
63 * Maps old ndd_name to the new ipadm_name. Any ndd property that is moved to
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
64 * libipadm should have an entry here to ensure backward compatibility
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
65 */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
66 typedef struct ndd2ipadm_map {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
67 char *ndd_name;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
68 char *ipadm_name;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
69 uint_t ipadm_proto;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
70 uint_t ipadm_flags;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
71 uint_t ndd_perm;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
72 } ndd2ipadm_map_t;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
73
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
74 static ndd2ipadm_map_t map[] = {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
75 { "ip_def_ttl", "ttl", MOD_PROTO_IPV4, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
76 { "ip6_def_hops", "hoplimit", MOD_PROTO_IPV6, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
77 { "ip_forwarding", "forwarding", MOD_PROTO_IPV4, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
78 { "ip6_forwarding", "forwarding", MOD_PROTO_IPV6, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
79 { "icmp_recv_hiwat", "recv_maxbuf", MOD_PROTO_RAWIP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
80 { "icmp_xmit_hiwat", "send_maxbuf", MOD_PROTO_RAWIP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
81 { "tcp_ecn_permitted", "ecn", MOD_PROTO_TCP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
82 { "tcp_extra_priv_ports_add", "extra_priv_ports", MOD_PROTO_TCP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
83 IPADM_OPT_APPEND, MOD_PROP_PERM_WRITE },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
84 { "tcp_extra_priv_ports_del", "extra_priv_ports", MOD_PROTO_TCP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
85 IPADM_OPT_REMOVE, MOD_PROP_PERM_WRITE },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
86 { "tcp_extra_priv_ports", "extra_priv_ports", MOD_PROTO_TCP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
87 0, MOD_PROP_PERM_READ },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
88 { "tcp_largest_anon_port", "largest_anon_port", MOD_PROTO_TCP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
89 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
90 { "tcp_recv_hiwat", "recv_maxbuf", MOD_PROTO_TCP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
91 { "tcp_sack_permitted", "sack", MOD_PROTO_TCP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
92 { "tcp_xmit_hiwat", "send_maxbuf", MOD_PROTO_TCP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
93 { "tcp_smallest_anon_port", "smallest_anon_port", MOD_PROTO_TCP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
94 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
95 { "tcp_smallest_nonpriv_port", "smallest_nonpriv_port", MOD_PROTO_TCP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
96 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
97 { "udp_extra_priv_ports_add", "extra_priv_ports", MOD_PROTO_UDP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
98 IPADM_OPT_APPEND, MOD_PROP_PERM_WRITE },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
99 { "udp_extra_priv_ports_del", "extra_priv_ports", MOD_PROTO_UDP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
100 IPADM_OPT_REMOVE, MOD_PROP_PERM_WRITE },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
101 { "udp_extra_priv_ports", "extra_priv_ports", MOD_PROTO_UDP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
102 0, MOD_PROP_PERM_READ },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
103 { "udp_largest_anon_port", "largest_anon_port", MOD_PROTO_UDP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
104 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
105 { "udp_recv_hiwat", "recv_maxbuf", MOD_PROTO_UDP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
106 { "udp_xmit_hiwat", "send_maxbuf", MOD_PROTO_UDP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
107 { "udp_smallest_anon_port", "smallest_anon_port", MOD_PROTO_UDP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
108 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
109 { "udp_smallest_nonpriv_port", "smallest_nonpriv_port", MOD_PROTO_UDP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
110 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
111 { "sctp_extra_priv_ports_add", "extra_priv_ports", MOD_PROTO_SCTP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
112 IPADM_OPT_APPEND, MOD_PROP_PERM_WRITE },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
113 { "sctp_extra_priv_ports_del", "extra_priv_ports", MOD_PROTO_SCTP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
114 IPADM_OPT_REMOVE, MOD_PROP_PERM_WRITE },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
115 { "sctp_extra_priv_ports", "extra_priv_ports", MOD_PROTO_SCTP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
116 0, MOD_PROP_PERM_READ },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
117 { "sctp_largest_anon_port", "largest_anon_port", MOD_PROTO_SCTP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
118 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
119 { "sctp_recv_hiwat", "recv_maxbuf", MOD_PROTO_SCTP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
120 { "sctp_xmit_hiwat", "send_maxbuf", MOD_PROTO_SCTP, 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
121 { "sctp_smallest_anon_port", "smallest_anon_port", MOD_PROTO_SCTP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
122 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
123 { "sctp_smallest_nonpriv_port", "smallest_nonpriv_port", MOD_PROTO_SCTP,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
124 0, 0 },
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
125 { NULL, NULL, 0, 0, 0 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
126 };
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
127
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
128 static uint_t
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
129 ndd_str2proto(const char *protostr)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
130 {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
131 if (strcmp(protostr, "tcp") == 0 ||
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
132 strcmp(protostr, "tcp6") == 0) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
133 return (MOD_PROTO_TCP);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
134 } else if (strcmp(protostr, "udp") == 0 ||
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
135 strcmp(protostr, "udp6") == 0) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
136 return (MOD_PROTO_UDP);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
137 } else if (strcmp(protostr, "ip") == 0 ||
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
138 strcmp(protostr, "ip6") == 0 ||
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
139 strcmp(protostr, "arp") == 0) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
140 return (MOD_PROTO_IP);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
141 } else if (strcmp(protostr, "icmp") == 0 ||
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
142 strcmp(protostr, "icmp6") == 0) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
143 return (MOD_PROTO_RAWIP);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
144 } else if (strcmp(protostr, "sctp") == 0 ||
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
145 strcmp(protostr, "sctp6") == 0) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
146 return (MOD_PROTO_SCTP);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
147 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
148 return (MOD_PROTO_NONE);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
149 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
150
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
151 static char *
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
152 ndd_perm2str(uint_t perm)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
153 {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
154 switch (perm) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
155 case MOD_PROP_PERM_READ:
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
156 return ("read only");
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
157 case MOD_PROP_PERM_WRITE:
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
158 return ("write only");
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
159 case MOD_PROP_PERM_RW:
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
160 return ("read and write");
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
161 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
162
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
163 return (NULL);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
164 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
165
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
166 /*
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
167 * This function converts any new property names to old ndd name by consulting
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
168 * ndd2ipadm_map_t. This is done to preserve backward compatibility.
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
169 */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
170 static void
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
171 print_ipadm2ndd(char *oldbuf, uint_t obufsize)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
172 {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
173 ndd2ipadm_map_t *nimap;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
174 char *pname, *rwtag, *protostr;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
175 uint_t proto, perm;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
176 boolean_t matched;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
177
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
178 pname = oldbuf;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
179 while (pname[0] && pname < (oldbuf + obufsize - 1)) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
180 for (protostr = pname; !isspace(*protostr); protostr++)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
181 ;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
182 *protostr++ = '\0';
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
183 /* protostr now points to protocol */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
184
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
185 for (rwtag = protostr; !isspace(*rwtag); rwtag++)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
186 ;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
187 *rwtag++ = '\0';
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
188 /* rwtag now points to permissions */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
189
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
190 proto = atoi(protostr);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
191 perm = atoi(rwtag);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
192 matched = B_FALSE;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
193 for (nimap = map; nimap->ndd_name != NULL; nimap++) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
194 if (strcmp(pname, nimap->ipadm_name) != 0 ||
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
195 !(nimap->ipadm_proto & proto))
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
196 continue;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
197
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
198 matched = B_TRUE;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
199 if (nimap->ndd_perm != 0)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
200 perm = nimap->ndd_perm;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
201 (void) printf("%-30s (%s)\n", nimap->ndd_name,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
202 ndd_perm2str(perm));
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
203 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
204 if (!matched)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
205 (void) printf("%-30s (%s)\n", pname,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
206 ndd_perm2str(perm));
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
207 for (pname = rwtag; *pname++; )
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
208 ;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
209 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
210 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
211
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
212 /*
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
213 * get/set the value for a given property by calling into libipadm. The
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
214 * IPH_LEGACY flag is used by libipadm for special handling. For some
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
215 * properties, libipadm.so displays strings (for e.g., on/off,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
216 * never/passive/active, et al) instead of numerals. However ndd(1M) always
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
217 * printed numberals. This flag will help in avoiding printing strings.
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
218 */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
219 static boolean_t
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
220 do_ipadm_getset(int cmd, char *buf, int buflen)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
221 {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
222 ndd2ipadm_map_t *nimap;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
223 ipadm_handle_t iph = NULL;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
224 ipadm_status_t status;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
225 char *mod;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
226 uint_t proto, perm = 0, flags = 0;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
227 char *pname, *pvalp;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
228 int i;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
229
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
230 if ((mod = strrchr(modpath, '/')) == NULL)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
231 mod = modpath;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
232 else
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
233 ++mod;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
234 if ((proto = ndd_str2proto(mod)) == MOD_PROTO_NONE)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
235 return (B_FALSE);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
236
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
237 if ((status = ipadm_open(&iph, IPH_LEGACY)) != IPADM_SUCCESS)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
238 goto fail;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
239
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
240 pname = buf;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
241 for (nimap = map; nimap->ndd_name != NULL; nimap++) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
242 if (strcmp(pname, nimap->ndd_name) == 0)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
243 break;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
244 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
245 if (nimap->ndd_name != NULL) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
246 pname = nimap->ipadm_name;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
247 proto = nimap->ipadm_proto;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
248 flags = nimap->ipadm_flags;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
249 perm = nimap->ndd_perm;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
250 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
251 if (cmd == ND_GET) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
252 char propval[MAXPROPVALLEN], allprop[64536];
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
253 uint_t pvalsz;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
254 sa_family_t af = AF_UNSPEC;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
255 int err;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
256
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
257 if (perm == MOD_PROP_PERM_WRITE)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
258 fatal("operation failed: Permission denied");
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
259
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
260 if (strcmp(pname, "?") == 0) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
261 pvalp = allprop;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
262 pvalsz = sizeof (allprop);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
263 } else {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
264 pvalp = propval;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
265 pvalsz = sizeof (propval);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
266 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
267
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
268 status = ipadm_get_prop(iph, pname, pvalp, &pvalsz, proto,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
269 IPADM_OPT_ACTIVE);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
270 if (status != IPADM_SUCCESS)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
271 goto fail;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
272
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
273 if (strcmp(pname, "?") == 0) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
274 (void) print_ipadm2ndd(pvalp, pvalsz);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
275 } else {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
276 char *tmp = pvalp;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
277
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
278 /*
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
279 * For backward compatibility if there are multiple
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
280 * values print each value in it's own line.
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
281 */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
282 while (*tmp != '\0') {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
283 if (*tmp == ',')
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
284 *tmp = '\n';
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
285 tmp++;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
286 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
287 (void) printf("%s\n", pvalp);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
288 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
289 (void) fflush(stdout);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
290 } else {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
291 if (perm == MOD_PROP_PERM_READ)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
292 fatal("operation failed: Permission denied");
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
293
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
294 /* walk past the property name to find the property value */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
295 for (i = 0; buf[i] != '\0'; i++)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
296 ;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
297
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
298 pvalp = &buf[++i];
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
299 status = ipadm_set_prop(iph, pname, pvalp, proto,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
300 flags|IPADM_OPT_ACTIVE);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
301 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
302 fail:
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
303 ipadm_close(iph);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
304 if (status != IPADM_SUCCESS)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
305 fatal("operation failed: %s", ipadm_status2str(status));
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
306 return (B_TRUE);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
307 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
308
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
309 /*
7776
b44ee007dfbf 6753521 show-linkprop should not return ENOTSUP for DEFAULT value of props like speed.
Sowmini Varadhan <Sowmini.Varadhan@Sun.COM>
parents: 6512
diff changeset
310 * gldv3_warning() catches the case of /sbin/ndd abuse to administer
b44ee007dfbf 6753521 show-linkprop should not return ENOTSUP for DEFAULT value of props like speed.
Sowmini Varadhan <Sowmini.Varadhan@Sun.COM>
parents: 6512
diff changeset
311 * ethernet/MII props. Note that /sbin/ndd has not been abused
b44ee007dfbf 6753521 show-linkprop should not return ENOTSUP for DEFAULT value of props like speed.
Sowmini Varadhan <Sowmini.Varadhan@Sun.COM>
parents: 6512
diff changeset
312 * for administration of other datalink types, which makes it permissible
b44ee007dfbf 6753521 show-linkprop should not return ENOTSUP for DEFAULT value of props like speed.
Sowmini Varadhan <Sowmini.Varadhan@Sun.COM>
parents: 6512
diff changeset
313 * to test for support of the flowctrl property.
b44ee007dfbf 6753521 show-linkprop should not return ENOTSUP for DEFAULT value of props like speed.
Sowmini Varadhan <Sowmini.Varadhan@Sun.COM>
parents: 6512
diff changeset
314 */
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
315 static void
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
316 gldv3_warning(char *module)
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
317 {
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
318 datalink_id_t linkid;
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
319 dladm_status_t status;
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
320 char buf[DLADM_PROP_VAL_MAX], *cp;
7776
b44ee007dfbf 6753521 show-linkprop should not return ENOTSUP for DEFAULT value of props like speed.
Sowmini Varadhan <Sowmini.Varadhan@Sun.COM>
parents: 6512
diff changeset
321 uint_t cnt = 1;
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
322 char *link;
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
323 dladm_handle_t handle;
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
324
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
325 link = strrchr(module, '/');
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
326 if (link == NULL)
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
327 return;
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
328
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
329 if (dladm_open(&handle) != DLADM_STATUS_OK)
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
330 return;
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
331
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
332 status = dladm_name2info(handle, ++link, &linkid, NULL, NULL, NULL);
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
333 if (status == DLADM_STATUS_OK) {
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
334 cp = buf;
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
335 status = dladm_get_linkprop(handle, linkid,
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
336 DLADM_PROP_VAL_CURRENT, "flowctrl", &cp, &cnt);
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
337 if (status == DLADM_STATUS_OK) {
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
338 (void) fprintf(stderr, gettext(
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
339 "WARNING: The ndd commands for datalink "
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
340 "administration are obsolete and may be "
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
341 "removed in a future release of Solaris. "
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
342 "Use dladm(1M) to manage datalink tunables.\n"));
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
343 }
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
344 }
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
345 dladm_close(handle);
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
346 }
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
347
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
348 /* ARGSUSED */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
349 int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
350 main(int argc, char **argv)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
351 {
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
352 char *cp, *value, *mod;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
353 int cmd;
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
354 int fd = 0;
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
355
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
356 if (!(cp = *++argv)) {
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
357 while ((fd = open_device()) != -1) {
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
358 getset_interactive(fd);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
359 (void) close(fd);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
360 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
361 return (EXIT_SUCCESS);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
362 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
363
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
364 cmd = ND_GET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
365 if (cp[0] == '-') {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
366 if (strncmp(&cp[1], "set", 3) == 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
367 cmd = ND_SET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
368 else if (strncmp(&cp[1], "get", 3) != 0)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
369 fatal(usage_str);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
370 if (!(cp = *++argv))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
371 fatal(usage_str);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
372 }
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
373
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
374 gldv3_warning(cp);
8453
15fa4bb77d8c 6745288 libdladm is executing open() of dld control device everywhere
Anurag S. Maskey <Anurag.Maskey@Sun.COM>
parents: 7776
diff changeset
375
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
376 mod = strrchr(cp, '/');
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
377 if (mod != NULL)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
378 mod++;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
379 else
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
380 mod = cp;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
381
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
382 if (ndd_str2proto(mod) == MOD_PROTO_NONE) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
383 if ((fd = open(cp, O_RDWR)) == -1)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
384 fatal("open of %s failed: %s", cp, errmsg(errno));
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
385 if (!isastream(fd))
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
386 fatal("%s is not a streams device", cp);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
387 }
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
388
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
389 (void) strlcpy(modpath, cp, sizeof (modpath));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
390 if (!(cp = *++argv)) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
391 getset_interactive(fd);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
392 (void) close(fd);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
393 return (EXIT_SUCCESS);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
394 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
395
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
396 if (cmd == ND_SET) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
397 if (!(value = *++argv))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
398 fatal(usage_str);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
399 (void) snprintf(gbuf, sizeof (gbuf), "%s%c%s%c", cp, '\0',
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
400 value, '\0');
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
401 if (!do_getset(fd, cmd, gbuf, sizeof (gbuf)))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
402 return (EXIT_FAILURE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
403 } else {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
404 do {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
405 (void) memset(gbuf, '\0', sizeof (gbuf));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
406 (void) strlcpy(gbuf, cp, sizeof (gbuf));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
407 if (!do_getset(fd, cmd, gbuf, sizeof (gbuf)))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
408 return (EXIT_FAILURE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
409 if (cp = *++argv)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
410 (void) putchar('\n');
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
411 } while (cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
412 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
413
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
414 (void) close(fd);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
415 return (EXIT_SUCCESS);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
416 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
417
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
418 static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
419 name_print(char *buf)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
420 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
421 char *cp, *rwtag;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
422
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
423 for (cp = buf; cp[0]; ) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
424 for (rwtag = cp; !isspace(*rwtag); rwtag++)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
425 ;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
426 *rwtag++ = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
427 while (isspace(*rwtag))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
428 rwtag++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
429 (void) printf("%-30s%s\n", cp, rwtag);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
430 for (cp = rwtag; *cp++; )
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
431 ;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
432 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
433 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
434
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
435 /*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
436 * This function is vile, but it's better here than in the kernel.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
437 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
438 static boolean_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
439 is_obsolete(const char *param)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
440 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
441 if (strcmp(param, "ip_enable_group_ifs") == 0 ||
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
442 strcmp(param, "ifgrp_status") == 0) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
443 (void) fprintf(stderr, "The \"%s\" tunable has been superseded "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
444 "by IP Multipathing.\nPlease see the IP Network "
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
445 "Multipathing Administration Guide for details.\n", param);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
446 return (B_TRUE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
447 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
448 return (B_FALSE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
449 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
450
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
451 static boolean_t
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
452 do_getset(int fd, int cmd, char *buf, int buf_len)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
453 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
454 char *cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
455 struct strioctl stri;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
456 boolean_t is_name_get;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
457
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
458 if (is_obsolete(buf))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
459 return (B_TRUE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
460
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
461 /*
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
462 * See if libipadm can handle this request, i.e., properties on
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
463 * following modules arp, ip, ipv4, ipv6, tcp, udp and sctp
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
464 */
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
465 if (do_ipadm_getset(cmd, buf, buf_len))
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
466 return (B_TRUE);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
467
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
468 stri.ic_cmd = cmd;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
469 stri.ic_timout = 0;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
470 stri.ic_len = buf_len;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
471 stri.ic_dp = buf;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
472 is_name_get = stri.ic_cmd == ND_GET && buf[0] == '?' && buf[1] == '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
473
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
474 if (ioctl(fd, I_STR, &stri) == -1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
475 if (errno == ENOENT)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
476 (void) printf("name is non-existent for this module\n"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
477 "for a list of valid names, use name '?'\n");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
478 else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
479 (void) printf("operation failed: %s\n", errmsg(errno));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
480 return (B_FALSE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
481 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
482 if (is_name_get)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
483 name_print(buf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
484 else if (stri.ic_cmd == ND_GET) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
485 for (cp = buf; *cp != '\0'; cp += strlen(cp) + 1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
486 (void) puts(cp);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
487 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
488 (void) fflush(stdout);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
489 return (B_TRUE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
490 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
491
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
492 static int
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
493 get_value(char *msg, char *buf, int buf_len)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
494 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
495 int len;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
496
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
497 (void) printf("%s", msg);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
498 (void) fflush(stdout);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
499
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
500 buf[buf_len-1] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
501 if (fgets(buf, buf_len-1, stdin) == NULL)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
502 exit(EXIT_SUCCESS);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
503 len = strlen(buf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
504 if (buf[len-1] == '\n')
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
505 buf[len - 1] = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
506 else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
507 len++;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
508 return (len);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
509 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
510
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
511 static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
512 getset_interactive(int fd)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
513 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
514 int cmd;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
515 char *cp;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
516 int len, buf_len;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
517 char len_buf[10];
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
518
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
519 for (;;) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
520 (void) memset(gbuf, '\0', sizeof (gbuf));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
521 len = get_value("name to get/set ? ", gbuf, sizeof (gbuf));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
522 if (len == 1 || (gbuf[0] == 'q' && gbuf[1] == '\0'))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
523 return;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
524 for (cp = gbuf; cp < &gbuf[len]; cp++) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
525 if (isspace(*cp))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
526 *cp = '\0';
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
527 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
528 cmd = ND_GET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
529 if (gbuf[0] != '?' &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
530 get_value("value ? ", &gbuf[len], sizeof (gbuf) - len) > 1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
531 cmd = ND_SET;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
532 if (cmd == ND_GET && gbuf[0] != '?' &&
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
533 get_value("length ? ", len_buf, sizeof (len_buf)) > 1) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
534 if (!isdigit(len_buf[0])) {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
535 (void) printf("invalid length\n");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
536 continue;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
537 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
538 buf_len = atoi(len_buf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
539 } else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
540 buf_len = sizeof (gbuf);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
541 (void) do_getset(fd, cmd, gbuf, buf_len);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
542 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
543 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
544
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
545 static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
546 printe(boolean_t print_errno, char *fmt, ...)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
547 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
548 va_list ap;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
549 int error = errno;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
550
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
551 va_start(ap, fmt);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
552 (void) printf("*ERROR* ");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
553 (void) vprintf(fmt, ap);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
554 va_end(ap);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
555
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
556 if (print_errno)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
557 (void) printf(": %s\n", errmsg(error));
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
558 else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
559 (void) printf("\n");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
560 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
561
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
562 static int
8589
90d41bc81368 6793122 ndd fails to open dladm handle on local zones
Vasumathi Sundaram - Sun Microsystems <Vasumathi.Sundaram@Sun.COM>
parents: 8453
diff changeset
563 open_device()
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
564 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
565 int fd, len;
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
566 char *mod;
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
567
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
568 for (;;) {
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
569 len = get_value("module to query ? ", modpath,
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
570 sizeof (modpath));
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
571 if (len <= 1 ||
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
572 (len == 2 && (modpath[0] == 'q' || modpath[0] == 'Q')))
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
573 return (-1);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
574
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
575 mod = strrchr(modpath, '/');
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
576 if (mod != NULL)
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
577 mod++;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
578 else
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
579 mod = modpath;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
580 if (ndd_str2proto(mod) == MOD_PROTO_NONE) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
581 if ((fd = open(modpath, O_RDWR)) == -1) {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
582 printe(B_TRUE, "open of %s failed", modpath);
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
583 continue;
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
584 }
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
585 } else {
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
586 return (0);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
587 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
588
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
589 gldv3_warning(modpath);
6512
707ffe0297ab PSARC/2008/171 Brussels: NDD compatiblity support
sowmini
parents: 0
diff changeset
590
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
591 if (isastream(fd))
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
592 return (fd);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
593
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
594 (void) close(fd);
12016
0248e987199b PSARC 2009/306 Brussels II - ipadm and libipadm
Girish Moodalbail <Girish.Moodalbail@Sun.COM>
parents: 8589
diff changeset
595 printe(B_FALSE, "%s is not a streams device", modpath);
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
596 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
597 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
598
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
599 static void
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
600 fatal(char *fmt, ...)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
601 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
602 va_list ap;
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
603
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
604 va_start(ap, fmt);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
605 (void) vfprintf(stderr, fmt, ap);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
606 va_end(ap);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
607 (void) fprintf(stderr, "\n");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
608
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
609 exit(EXIT_FAILURE);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
610 }
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
611
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
612 static char *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
613 errmsg(int error)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
614 {
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
615 char *msg = strerror(error);
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
616
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
617 return (msg != NULL ? msg : "unknown error");
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
618 }