17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 1990 Mentat Inc.
24 */
25
26 #include <inet/tunables.h>
27 #include <sys/md5.h>
28 #include <inet/common.h>
29 #include <inet/ip.h>
30 #include <inet/ip6.h>
31 #include <netinet/icmp6.h>
32 #include <inet/ip_stack.h>
33 #include <inet/rawip_impl.h>
34 #include <inet/tcp_stack.h>
35 #include <inet/tcp_impl.h>
36 #include <inet/udp_impl.h>
37 #include <inet/sctp/sctp_stack.h>
38 #include <inet/sctp/sctp_impl.h>
39 #include <inet/tunables.h>
40
41 static int
42 prop_perm2const(mod_prop_info_t *pinfo)
43 {
44 if (pinfo->mpi_setf == NULL)
45 return (MOD_PROP_PERM_READ);
46 if (pinfo->mpi_getf == NULL)
47 return (MOD_PROP_PERM_WRITE);
48 return (MOD_PROP_PERM_RW);
49 }
50
51 /*
52 * Modifies the value of the property to default value or to the `pval'
53 * specified by the user.
54 */
55 /* ARGSUSED */
56 int
188 nbytes = snprintf(pval, psize, "%u", pinfo->prop_cur_uval);
189 if (nbytes >= psize)
190 return (ENOBUFS);
191 return (0);
192 }
193
194 /*
195 * Implements /sbin/ndd -get /dev/ip ?, for all the modules. Needed for
196 * backward compatibility with /sbin/ndd.
197 */
198 /* ARGSUSED */
199 int
200 mod_get_allprop(void *cbarg, mod_prop_info_t *pinfo, const char *ifname,
201 void *val, uint_t psize, uint_t flags)
202 {
203 char *pval = val;
204 mod_prop_info_t *ptbl, *prop;
205 ip_stack_t *ipst;
206 tcp_stack_t *tcps;
207 sctp_stack_t *sctps;
208 udp_stack_t *us;
209 icmp_stack_t *is;
210 uint_t size;
211 size_t nbytes = 0, tbytes = 0;
212
213 bzero(pval, psize);
214 size = psize;
215
216 switch (pinfo->mpi_proto) {
217 case MOD_PROTO_IP:
218 case MOD_PROTO_IPV4:
219 case MOD_PROTO_IPV6:
220 ipst = (ip_stack_t *)cbarg;
221 ptbl = ipst->ips_propinfo_tbl;
222 break;
223 case MOD_PROTO_RAWIP:
224 is = (icmp_stack_t *)cbarg;
225 ptbl = is->is_propinfo_tbl;
226 break;
227 case MOD_PROTO_TCP:
228 tcps = (tcp_stack_t *)cbarg;
229 ptbl = tcps->tcps_propinfo_tbl;
230 break;
231 case MOD_PROTO_UDP:
232 us = (udp_stack_t *)cbarg;
233 ptbl = us->us_propinfo_tbl;
234 break;
235 case MOD_PROTO_SCTP:
236 sctps = (sctp_stack_t *)cbarg;
237 ptbl = sctps->sctps_propinfo_tbl;
238 break;
239 default:
240 return (EINVAL);
241 }
242
243 for (prop = ptbl; prop->mpi_name != NULL; prop++) {
244 if (prop->mpi_name[0] == '\0' ||
245 strcmp(prop->mpi_name, "?") == 0) {
246 continue;
247 }
248 nbytes = snprintf(pval, size, "%s %d %d", prop->mpi_name,
249 prop->mpi_proto, prop_perm2const(prop));
250 size -= nbytes + 1;
251 pval += nbytes + 1;
252 tbytes += nbytes + 1;
253 if (tbytes >= psize) {
254 /* Buffer overflow, stop copying information */
255 return (ENOBUFS);
256 }
257 }
258 return (0);
|
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright (c) 1991, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 1990 Mentat Inc.
24 */
25
26 #include <inet/tunables.h>
27 #include <sys/md5.h>
28 #include <inet/common.h>
29 #include <inet/ip.h>
30 #include <inet/ip6.h>
31 #include <netinet/icmp6.h>
32 #include <inet/ip_stack.h>
33 #include <inet/rawip_impl.h>
34 #include <inet/tcp_stack.h>
35 #include <inet/tcp_impl.h>
36 #include <inet/udp_impl.h>
37 #include <inet/dccp/dccp_stack.h>
38 #include <inet/dccp/dccp_impl.h>
39 #include <inet/sctp/sctp_stack.h>
40 #include <inet/sctp/sctp_impl.h>
41 #include <inet/tunables.h>
42
43 static int
44 prop_perm2const(mod_prop_info_t *pinfo)
45 {
46 if (pinfo->mpi_setf == NULL)
47 return (MOD_PROP_PERM_READ);
48 if (pinfo->mpi_getf == NULL)
49 return (MOD_PROP_PERM_WRITE);
50 return (MOD_PROP_PERM_RW);
51 }
52
53 /*
54 * Modifies the value of the property to default value or to the `pval'
55 * specified by the user.
56 */
57 /* ARGSUSED */
58 int
190 nbytes = snprintf(pval, psize, "%u", pinfo->prop_cur_uval);
191 if (nbytes >= psize)
192 return (ENOBUFS);
193 return (0);
194 }
195
196 /*
197 * Implements /sbin/ndd -get /dev/ip ?, for all the modules. Needed for
198 * backward compatibility with /sbin/ndd.
199 */
200 /* ARGSUSED */
201 int
202 mod_get_allprop(void *cbarg, mod_prop_info_t *pinfo, const char *ifname,
203 void *val, uint_t psize, uint_t flags)
204 {
205 char *pval = val;
206 mod_prop_info_t *ptbl, *prop;
207 ip_stack_t *ipst;
208 tcp_stack_t *tcps;
209 sctp_stack_t *sctps;
210 dccp_stack_t *dccps;
211 udp_stack_t *us;
212 icmp_stack_t *is;
213 uint_t size;
214 size_t nbytes = 0, tbytes = 0;
215
216 bzero(pval, psize);
217 size = psize;
218
219 switch (pinfo->mpi_proto) {
220 case MOD_PROTO_IP:
221 case MOD_PROTO_IPV4:
222 case MOD_PROTO_IPV6:
223 ipst = (ip_stack_t *)cbarg;
224 ptbl = ipst->ips_propinfo_tbl;
225 break;
226 case MOD_PROTO_RAWIP:
227 is = (icmp_stack_t *)cbarg;
228 ptbl = is->is_propinfo_tbl;
229 break;
230 case MOD_PROTO_TCP:
231 tcps = (tcp_stack_t *)cbarg;
232 ptbl = tcps->tcps_propinfo_tbl;
233 break;
234 case MOD_PROTO_UDP:
235 us = (udp_stack_t *)cbarg;
236 ptbl = us->us_propinfo_tbl;
237 break;
238 case MOD_PROTO_SCTP:
239 sctps = (sctp_stack_t *)cbarg;
240 ptbl = sctps->sctps_propinfo_tbl;
241 break;
242 case MOD_PROTO_DCCP:
243 dccps = (dccp_stack_t *)cbarg;
244 ptbl = dccps->dccps_propinfo_tbl;
245 break;
246 default:
247 return (EINVAL);
248 }
249
250 for (prop = ptbl; prop->mpi_name != NULL; prop++) {
251 if (prop->mpi_name[0] == '\0' ||
252 strcmp(prop->mpi_name, "?") == 0) {
253 continue;
254 }
255 nbytes = snprintf(pval, size, "%s %d %d", prop->mpi_name,
256 prop->mpi_proto, prop_perm2const(prop));
257 size -= nbytes + 1;
258 pval += nbytes + 1;
259 tbytes += nbytes + 1;
260 if (tbytes >= psize) {
261 /* Buffer overflow, stop copying information */
262 return (ENOBUFS);
263 }
264 }
265 return (0);
|