Mercurial > illumos > illumos-gate
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 |
rev | line source |
---|---|
0 | 1 /* |
2 * CDDL HEADER START | |
3 * | |
4 * The contents of this file are subject to the terms of the | |
6512 | 5 * Common Development and Distribution License (the "License"). |
6 * You may not use this file except in compliance with the License. | |
0 | 7 * |
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE | |
9 * or http://www.opensolaris.org/os/licensing. | |
10 * See the License for the specific language governing permissions | |
11 * and limitations under the License. | |
12 * | |
13 * When distributing Covered Code, include this CDDL HEADER in each | |
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. | |
15 * If applicable, add the following below this CDDL HEADER, with the | |
16 * fields enclosed by brackets "[]" replaced with your own identifying | |
17 * information: Portions Copyright [yyyy] [name of copyright owner] | |
18 * | |
19 * CDDL HEADER END | |
20 */ | |
21 /* | |
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 | 23 * Use is subject to license terms. |
24 */ | |
25 | |
26 /* | |
27 * Copyright (c) 1990 Mentat Inc. | |
28 * ndd.c 2.1, last change 11/14/90 | |
29 */ | |
30 | |
31 #include <stdio.h> | |
32 #include <errno.h> | |
33 #include <ctype.h> | |
34 #include <stdarg.h> | |
35 #include <fcntl.h> | |
36 #include <unistd.h> | |
37 #include <sys/types.h> | |
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 | 40 #include <inet/nd.h> |
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 | 43 #include <stdlib.h> |
6512 | 44 #include <libdllink.h> |
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 | 47 |
48 static boolean_t do_getset(int fd, int cmd, char *buf, int buf_len); | |
49 static int get_value(char *msg, char *buf, int buf_len); | |
50 static void name_print(char *buf); | |
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 | 53 static char *errmsg(int err); |
54 static void fatal(char *fmt, ...); | |
55 static void printe(boolean_t print_errno, char *fmt, ...); | |
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 | 59 static char usage_str[] = "usage: ndd -set device_name name value\n" |
60 " ndd [-get] device_name name [name ...]"; | |
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 | 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 | 317 { |
318 datalink_id_t linkid; | |
319 dladm_status_t status; | |
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 | 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 | 324 |
325 link = strrchr(module, '/'); | |
326 if (link == NULL) | |
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 | 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 | 346 } |
347 | |
0 | 348 /* ARGSUSED */ |
349 int | |
350 main(int argc, char **argv) | |
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 | 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 | 355 |
0 | 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 | 358 getset_interactive(fd); |
359 (void) close(fd); | |
360 } | |
361 return (EXIT_SUCCESS); | |
362 } | |
363 | |
364 cmd = ND_GET; | |
365 if (cp[0] == '-') { | |
366 if (strncmp(&cp[1], "set", 3) == 0) | |
367 cmd = ND_SET; | |
368 else if (strncmp(&cp[1], "get", 3) != 0) | |
369 fatal(usage_str); | |
370 if (!(cp = *++argv)) | |
371 fatal(usage_str); | |
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 | 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 | 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 | 390 if (!(cp = *++argv)) { |
391 getset_interactive(fd); | |
392 (void) close(fd); | |
393 return (EXIT_SUCCESS); | |
394 } | |
395 | |
396 if (cmd == ND_SET) { | |
397 if (!(value = *++argv)) | |
398 fatal(usage_str); | |
399 (void) snprintf(gbuf, sizeof (gbuf), "%s%c%s%c", cp, '\0', | |
400 value, '\0'); | |
401 if (!do_getset(fd, cmd, gbuf, sizeof (gbuf))) | |
402 return (EXIT_FAILURE); | |
403 } else { | |
404 do { | |
405 (void) memset(gbuf, '\0', sizeof (gbuf)); | |
406 (void) strlcpy(gbuf, cp, sizeof (gbuf)); | |
407 if (!do_getset(fd, cmd, gbuf, sizeof (gbuf))) | |
408 return (EXIT_FAILURE); | |
409 if (cp = *++argv) | |
410 (void) putchar('\n'); | |
411 } while (cp); | |
412 } | |
413 | |
414 (void) close(fd); | |
415 return (EXIT_SUCCESS); | |
416 } | |
417 | |
418 static void | |
419 name_print(char *buf) | |
420 { | |
421 char *cp, *rwtag; | |
422 | |
423 for (cp = buf; cp[0]; ) { | |
424 for (rwtag = cp; !isspace(*rwtag); rwtag++) | |
425 ; | |
426 *rwtag++ = '\0'; | |
427 while (isspace(*rwtag)) | |
428 rwtag++; | |
429 (void) printf("%-30s%s\n", cp, rwtag); | |
430 for (cp = rwtag; *cp++; ) | |
431 ; | |
432 } | |
433 } | |
434 | |
435 /* | |
436 * This function is vile, but it's better here than in the kernel. | |
437 */ | |
438 static boolean_t | |
439 is_obsolete(const char *param) | |
440 { | |
441 if (strcmp(param, "ip_enable_group_ifs") == 0 || | |
442 strcmp(param, "ifgrp_status") == 0) { | |
443 (void) fprintf(stderr, "The \"%s\" tunable has been superseded " | |
444 "by IP Multipathing.\nPlease see the IP Network " | |
445 "Multipathing Administration Guide for details.\n", param); | |
446 return (B_TRUE); | |
447 } | |
448 return (B_FALSE); | |
449 } | |
450 | |
451 static boolean_t | |
452 do_getset(int fd, int cmd, char *buf, int buf_len) | |
453 { | |
454 char *cp; | |
455 struct strioctl stri; | |
456 boolean_t is_name_get; | |
457 | |
458 if (is_obsolete(buf)) | |
459 return (B_TRUE); | |
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 | 468 stri.ic_cmd = cmd; |
469 stri.ic_timout = 0; | |
470 stri.ic_len = buf_len; | |
471 stri.ic_dp = buf; | |
472 is_name_get = stri.ic_cmd == ND_GET && buf[0] == '?' && buf[1] == '\0'; | |
473 | |
474 if (ioctl(fd, I_STR, &stri) == -1) { | |
475 if (errno == ENOENT) | |
476 (void) printf("name is non-existent for this module\n" | |
477 "for a list of valid names, use name '?'\n"); | |
478 else | |
479 (void) printf("operation failed: %s\n", errmsg(errno)); | |
480 return (B_FALSE); | |
481 } | |
482 if (is_name_get) | |
483 name_print(buf); | |
484 else if (stri.ic_cmd == ND_GET) { | |
485 for (cp = buf; *cp != '\0'; cp += strlen(cp) + 1) | |
486 (void) puts(cp); | |
487 } | |
488 (void) fflush(stdout); | |
489 return (B_TRUE); | |
490 } | |
491 | |
492 static int | |
493 get_value(char *msg, char *buf, int buf_len) | |
494 { | |
495 int len; | |
496 | |
497 (void) printf("%s", msg); | |
498 (void) fflush(stdout); | |
499 | |
500 buf[buf_len-1] = '\0'; | |
501 if (fgets(buf, buf_len-1, stdin) == NULL) | |
502 exit(EXIT_SUCCESS); | |
503 len = strlen(buf); | |
504 if (buf[len-1] == '\n') | |
505 buf[len - 1] = '\0'; | |
506 else | |
507 len++; | |
508 return (len); | |
509 } | |
510 | |
511 static void | |
512 getset_interactive(int fd) | |
513 { | |
514 int cmd; | |
515 char *cp; | |
516 int len, buf_len; | |
517 char len_buf[10]; | |
518 | |
519 for (;;) { | |
520 (void) memset(gbuf, '\0', sizeof (gbuf)); | |
521 len = get_value("name to get/set ? ", gbuf, sizeof (gbuf)); | |
522 if (len == 1 || (gbuf[0] == 'q' && gbuf[1] == '\0')) | |
523 return; | |
524 for (cp = gbuf; cp < &gbuf[len]; cp++) { | |
525 if (isspace(*cp)) | |
526 *cp = '\0'; | |
527 } | |
528 cmd = ND_GET; | |
529 if (gbuf[0] != '?' && | |
530 get_value("value ? ", &gbuf[len], sizeof (gbuf) - len) > 1) | |
531 cmd = ND_SET; | |
532 if (cmd == ND_GET && gbuf[0] != '?' && | |
533 get_value("length ? ", len_buf, sizeof (len_buf)) > 1) { | |
534 if (!isdigit(len_buf[0])) { | |
535 (void) printf("invalid length\n"); | |
536 continue; | |
537 } | |
538 buf_len = atoi(len_buf); | |
539 } else | |
540 buf_len = sizeof (gbuf); | |
541 (void) do_getset(fd, cmd, gbuf, buf_len); | |
542 } | |
543 } | |
544 | |
545 static void | |
546 printe(boolean_t print_errno, char *fmt, ...) | |
547 { | |
548 va_list ap; | |
549 int error = errno; | |
550 | |
551 va_start(ap, fmt); | |
552 (void) printf("*ERROR* "); | |
553 (void) vprintf(fmt, ap); | |
554 va_end(ap); | |
555 | |
556 if (print_errno) | |
557 (void) printf(": %s\n", errmsg(error)); | |
558 else | |
559 (void) printf("\n"); | |
560 } | |
561 | |
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 | 564 { |
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 | 567 |
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 | 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 | 573 return (-1); |
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 | 587 } |
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 | 590 |
0 | 591 if (isastream(fd)) |
592 return (fd); | |
593 | |
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 | 596 } |
597 } | |
598 | |
599 static void | |
600 fatal(char *fmt, ...) | |
601 { | |
602 va_list ap; | |
603 | |
604 va_start(ap, fmt); | |
605 (void) vfprintf(stderr, fmt, ap); | |
606 va_end(ap); | |
607 (void) fprintf(stderr, "\n"); | |
608 | |
609 exit(EXIT_FAILURE); | |
610 } | |
611 | |
612 static char * | |
613 errmsg(int error) | |
614 { | |
615 char *msg = strerror(error); | |
616 | |
617 return (msg != NULL ? msg : "unknown error"); | |
618 } |