Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/ipp/dscpmk/dscpmkddi.c
+++ new/usr/src/uts/common/ipp/dscpmk/dscpmkddi.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 #include <sys/types.h>
27 27 #include <sys/systm.h>
28 28 #include <sys/socket.h>
29 29 #include <netinet/in.h>
30 30 #include <sys/modctl.h>
31 31 #include <sys/sunddi.h>
32 32 #include <ipp/ipp.h>
33 33 #include <ipp/ipp_config.h>
34 34 #include <inet/common.h>
35 35 #include <ipp/dscpmk/dscpmk_impl.h>
36 36
37 37 #define D_SM_COMMENT "IPP dscpmk marker module"
38 38
39 39 /* DDI file for dscpmk ipp module */
40 40
41 41 /* default dscp map - dscp unchanged */
42 42 uint8_t default_dscp_map[DSCPMK_ARRAY_COUNT] = {
43 43 0, 1, 2, 3,
44 44 4, 5, 6, 7,
45 45 8, 9, 10, 11,
46 46 12, 13, 14, 15,
47 47 16, 17, 18, 19,
48 48 20, 21, 22, 23,
49 49 24, 25, 26, 27,
50 50 28, 29, 30, 31,
51 51 32, 33, 34, 35,
52 52 36, 37, 38, 39,
53 53 40, 41, 42, 43,
54 54 44, 45, 46, 47,
55 55 48, 49, 50, 51,
56 56 52, 53, 54, 55,
57 57 56, 57, 58, 59,
58 58 60, 61, 62, 63
59 59 };
60 60
61 61 static int dscpmk_create_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
62 62 static int dscpmk_modify_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
63 63 static int dscpmk_destroy_action(ipp_action_id_t, ipp_flags_t);
64 64 static int dscpmk_info(ipp_action_id_t, int (*)(nvlist_t *, void *), void *,
65 65 ipp_flags_t);
66 66 static int dscpmk_invoke_action(ipp_action_id_t, ipp_packet_t *);
67 67
68 68 /* Creating and updating summary stats */
69 69 static int dscpmk_summ_statinit(ipp_action_id_t, dscpmk_data_t *);
70 70 static int dscpmk_update_stats(ipp_stat_t *, void *, int);
71 71
72 72 /* Creating and updating per-dscp stats */
73 73 static int dscpmk_det_statinit(ipp_action_id_t, dscpmk_data_t *, int);
74 74 static int dscpmk_update_det_stats(ipp_stat_t *, void *, int);
75 75
76 76 /* Entry points for this IPP module */
77 77 ipp_ops_t dscpmk_ops = {
78 78 IPPO_REV,
79 79 dscpmk_create_action, /* ippo_action_create */
80 80 dscpmk_modify_action, /* ippo_action_modify */
81 81 dscpmk_destroy_action, /* ippo_action_destroy */
82 82 dscpmk_info, /* ippo_action_info */
83 83 dscpmk_invoke_action /* ippo_action_invoke */
84 84 };
85 85
86 86 extern struct mod_ops mod_ippops;
87 87
88 88 /*
↓ open down ↓ |
88 lines elided |
↑ open up ↑ |
89 89 * Module linkage information for the kernel.
90 90 */
91 91 static struct modlipp modlipp = {
92 92 &mod_ippops,
93 93 D_SM_COMMENT,
94 94 &dscpmk_ops
95 95 };
96 96
97 97 static struct modlinkage modlinkage = {
98 98 MODREV_1,
99 - (void *)&modlipp,
100 - NULL
99 + { (void *)&modlipp, NULL }
101 100 };
102 101
103 102
104 103 int
105 104 _init(void)
106 105 {
107 106 return (mod_install(&modlinkage));
108 107 }
109 108
110 109 int
111 110 _fini(void)
112 111 {
113 112 return (mod_remove(&modlinkage));
114 113 }
115 114
116 115 int
117 116 _info(struct modinfo *modinfop)
118 117 {
119 118 return (mod_info(&modlinkage, modinfop));
120 119 }
121 120
122 121 static int
123 122 dscpmk_create_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
124 123 {
125 124 nvlist_t *nvlp;
126 125 dscpmk_data_t *dscpmk_data;
127 126 char *next_action;
128 127 int err, cnt;
129 128 int32_t *tbl;
130 129 uint_t nelem = DSCPMK_ARRAY_COUNT;
131 130 uint32_t bstats;
132 131
133 132 ASSERT((nvlpp != NULL) && (*nvlpp != NULL));
134 133
135 134 nvlp = *nvlpp;
136 135 *nvlpp = NULL; /* nvlist should be NULL on return */
137 136
138 137 if ((dscpmk_data = kmem_zalloc(DSCPMK_DATA_SZ, KM_NOSLEEP)) == NULL) {
139 138 nvlist_free(nvlp);
140 139 return (ENOMEM);
141 140 }
142 141
143 142 /* parse next action name */
144 143 if ((err = nvlist_lookup_string(nvlp, DSCPMK_NEXT_ACTION_NAME,
145 144 &next_action)) != 0) {
146 145 nvlist_free(nvlp);
147 146 dscpmk0dbg(("dscpmk_create_action: invalid config, " \
148 147 "next_action name missing\n"));
149 148 kmem_free(dscpmk_data, DSCPMK_DATA_SZ);
150 149 return (err);
151 150 }
152 151
153 152 if ((dscpmk_data->next_action = ipp_action_lookup(next_action))
154 153 == IPP_ACTION_INVAL) {
155 154 nvlist_free(nvlp);
156 155 dscpmk0dbg(("dscpmk_create_action: next_action "\
157 156 "invalid\n"));
158 157 kmem_free(dscpmk_data, DSCPMK_DATA_SZ);
159 158 return (EINVAL);
160 159 }
161 160
162 161 /* Fill in the default value */
163 162 bcopy(default_dscp_map, dscpmk_data->dscp_map,
164 163 sizeof (default_dscp_map));
165 164 /*
166 165 * parse dscp_map, if present. Note that the module gets
167 166 * the entire array with unchanged entries marked with -1.
168 167 */
169 168 if ((err = nvlist_lookup_int32_array(nvlp, DSCPMK_DSCP_MAP,
170 169 &tbl, &nelem)) == 0) {
171 170 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
172 171 if ((tbl[cnt] != DSCPMK_UNCHANGED_DSCP) && (tbl[cnt] !=
173 172 dscpmk_data->dscp_map[cnt])) {
174 173 dscpmk_data->dscp_map[cnt] = tbl[cnt];
175 174 }
176 175 }
177 176 }
178 177
179 178
180 179 /* parse summary_stats boolean */
181 180 if ((err = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats))
182 181 != 0) {
183 182 dscpmk_data->summary_stats = B_FALSE;
184 183 } else {
185 184 dscpmk_data->summary_stats = (bstats != 0) ? B_TRUE : B_FALSE;
186 185 /* If stats is needed, initialize the stats structure */
187 186 if (dscpmk_data->summary_stats) {
188 187 if ((err = dscpmk_summ_statinit(aid, dscpmk_data))
189 188 != 0) {
190 189 nvlist_free(nvlp);
191 190 kmem_free(dscpmk_data, DSCPMK_DATA_SZ);
192 191 return (err);
193 192 }
194 193 }
195 194 }
196 195
197 196 /*
198 197 * Initialize per-dscp stats; B_FALSE in present indicates a dscp
199 198 * with this value (count) is not present in the map.
200 199 */
201 200 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
202 201 dscpmk_data->dscp_stats[cnt].present = B_FALSE;
203 202 dscpmk_data->dscp_stats[cnt].npackets = 0;
204 203 }
205 204
206 205 /* parse detailed_stats boolean */
207 206 if ((err = nvlist_lookup_uint32(nvlp, DSCPMK_DETAILED_STATS, &bstats))
208 207 != 0) {
209 208 dscpmk_data->detailed_stats = B_FALSE;
210 209 } else {
211 210 dscpmk_data->detailed_stats = (bstats != 0) ? B_TRUE : B_FALSE;
212 211 /* If stats is needed, initialize the stats structure */
213 212 if (dscpmk_data->detailed_stats) {
214 213 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
215 214 int val = dscpmk_data->dscp_map[cnt];
216 215 if (dscpmk_data->dscp_stats[val].present) {
217 216 continue;
218 217 }
219 218 dscpmk_data->dscp_stats[val].present = B_TRUE;
220 219 if ((err = dscpmk_det_statinit(aid, dscpmk_data,
221 220 val)) != 0) {
222 221 nvlist_free(nvlp);
223 222 kmem_free(dscpmk_data, DSCPMK_DATA_SZ);
224 223 return (err);
225 224 }
226 225 }
227 226 }
228 227 }
229 228
230 229 /* Free the nvlist */
231 230 nvlist_free(nvlp);
232 231
233 232 /* set action chain reference */
234 233 if ((err = ipp_action_ref(aid, dscpmk_data->next_action, flags)) != 0) {
235 234 dscpmk0dbg(("dscpmk_create_action: ipp_action_ref " \
236 235 "returned with error %d\n", err));
237 236 if (dscpmk_data->summary_stats) {
238 237 ipp_stat_destroy(dscpmk_data->stats);
239 238 }
240 239 if (dscpmk_data->detailed_stats) {
241 240 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
242 241 if (dscpmk_data->dscp_stats[cnt].present) {
243 242 ipp_stat_destroy(
244 243 dscpmk_data->dscp_stats[cnt].stats);
245 244 }
246 245 }
247 246 }
248 247 kmem_free(dscpmk_data, DSCPMK_DATA_SZ);
249 248 return (err);
250 249 }
251 250
252 251 ipp_action_set_ptr(aid, (void *)dscpmk_data);
253 252 return (0);
254 253 }
255 254
256 255 static int
257 256 dscpmk_modify_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
258 257 {
259 258 nvlist_t *nvlp;
260 259 int err = 0, cnt;
261 260 uint8_t config_type;
262 261 char *next_action_name;
263 262 uint32_t bstats;
264 263 uint_t nelem = DSCPMK_ARRAY_COUNT;
265 264 int32_t *tbl;
266 265 ipp_action_id_t next_action;
267 266 dscpmk_data_t *dscpmk_data;
268 267
269 268 ASSERT((nvlpp != NULL) && (*nvlpp != NULL));
270 269
271 270 nvlp = *nvlpp;
272 271 *nvlpp = NULL; /* nvlist should be NULL when this returns */
273 272
274 273 if ((err = nvlist_lookup_byte(nvlp, IPP_CONFIG_TYPE, &config_type))
275 274 != 0) {
276 275 nvlist_free(nvlp);
277 276 dscpmk0dbg(("dscpmk_modify_action: invalid cfg. type\n"));
278 277 return (err);
279 278 }
280 279
281 280 if (config_type != IPP_SET) {
282 281 nvlist_free(nvlp);
283 282 dscpmk0dbg(("dscpmk_modify_action: invalid cfg. type " \
284 283 "%d\n", config_type));
285 284 return (EINVAL);
286 285 }
287 286
288 287 dscpmk_data = (dscpmk_data_t *)ipp_action_get_ptr(aid);
289 288 ASSERT(dscpmk_data != NULL);
290 289
291 290 /* parse next action name, if present */
292 291 if ((err = nvlist_lookup_string(nvlp, DSCPMK_NEXT_ACTION_NAME,
293 292 &next_action_name)) == 0) {
294 293 /* lookup action name to get action id */
295 294 if ((next_action = ipp_action_lookup(next_action_name))
296 295 == IPP_ACTION_INVAL) {
297 296 nvlist_free(nvlp);
298 297 dscpmk0dbg(("dscpmk_modify_action: next_action "\
299 298 "invalid\n"));
300 299 return (EINVAL);
301 300 }
302 301 /* reference new action */
303 302 if ((err = ipp_action_ref(aid, next_action, flags)) != 0) {
304 303 nvlist_free(nvlp);
305 304 dscpmk0dbg(("dscpmk_modify_action: ipp_action_ref " \
306 305 "returned with error %d\n", err));
307 306 return (err);
308 307 }
309 308 /* unref old action */
310 309 err = ipp_action_unref(aid, dscpmk_data->next_action, flags);
311 310 ASSERT(err == 0);
312 311 dscpmk_data->next_action = next_action;
313 312 }
314 313
315 314 /*
316 315 * parse dscp_map, if present. Note that the module gets
317 316 * the entire array with unchanged entries marked with -1.
318 317 * If this array is absent during modification, it means revert to
319 318 * the default table.
320 319 */
321 320 if ((err = nvlist_lookup_int32_array(nvlp, DSCPMK_DSCP_MAP,
322 321 &tbl, &nelem)) == 0) {
323 322 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
324 323 if ((tbl[cnt] != DSCPMK_UNCHANGED_DSCP) && (tbl[cnt] !=
325 324 dscpmk_data->dscp_map[cnt])) {
326 325 dscpmk_data->dscp_map[cnt] = tbl[cnt];
327 326 }
328 327 }
329 328 } else {
330 329 bcopy(default_dscp_map, dscpmk_data->dscp_map,
331 330 sizeof (default_dscp_map));
332 331 }
333 332
334 333 /* parse summary_stats boolean, if present */
335 334 if ((err = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats))
336 335 == 0) {
337 336 boolean_t val = (bstats != 0) ? B_TRUE : B_FALSE;
338 337 /* Turning on stats */
339 338 if (!dscpmk_data->summary_stats && val) {
340 339 if ((err = dscpmk_summ_statinit(aid, dscpmk_data))
341 340 != 0) {
342 341 nvlist_free(nvlp);
343 342 return (err);
344 343 }
345 344 /* Turning off stats */
346 345 } else if (!val && dscpmk_data->summary_stats) {
347 346 ipp_stat_destroy(dscpmk_data->stats);
348 347
349 348 }
350 349 dscpmk_data->summary_stats = val;
351 350 }
352 351
353 352 /* parse detailed_stats boolean */
354 353 if ((err = nvlist_lookup_uint32(nvlp, DSCPMK_DETAILED_STATS, &bstats))
355 354 == 0) {
356 355 boolean_t val = (bstats != 0) ? B_TRUE : B_FALSE;
357 356 if (dscpmk_data->detailed_stats && !val) {
358 357 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
359 358 if (dscpmk_data->dscp_stats[cnt].present) {
360 359 dscpmk_data->dscp_stats[cnt].present =
361 360 B_FALSE;
362 361 ipp_stat_destroy(dscpmk_data->
363 362 dscp_stats[cnt].stats);
364 363 }
365 364 }
366 365 }
367 366 dscpmk_data->detailed_stats = val;
368 367 }
369 368
370 369 /* The map might have changed */
371 370 if (dscpmk_data->detailed_stats) {
372 371 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
373 372 int val = dscpmk_data->dscp_map[cnt];
374 373 if (!dscpmk_data->dscp_stats[val].present) {
375 374 dscpmk_data->dscp_stats[val].present = B_TRUE;
376 375 if ((err = dscpmk_det_statinit(aid, dscpmk_data,
377 376 val)) != 0) {
378 377 nvlist_free(nvlp);
379 378 return (err);
380 379 }
381 380 }
382 381 }
383 382 }
384 383
385 384 /* Free the nvlist */
386 385 nvlist_free(nvlp);
387 386 return (0);
388 387 }
389 388
390 389 static int
391 390 dscpmk_destroy_action(ipp_action_id_t aid, ipp_flags_t flags)
392 391 {
393 392 dscpmk_data_t *dscpmk_data;
394 393 int err, cnt;
395 394
396 395 dscpmk_data = (dscpmk_data_t *)ipp_action_get_ptr(aid);
397 396 ASSERT(dscpmk_data != NULL);
398 397
399 398 /* Destroy stats, if gathered */
400 399 if (dscpmk_data->summary_stats) {
401 400 ipp_stat_destroy(dscpmk_data->stats);
402 401 }
403 402
404 403 if (dscpmk_data->detailed_stats) {
405 404 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
406 405 if (dscpmk_data->dscp_stats[cnt].present) {
407 406 ipp_stat_destroy(dscpmk_data->dscp_stats[cnt].
408 407 stats);
409 408 }
410 409 }
411 410 }
412 411
413 412 /* unreference the action */
414 413 err = ipp_action_unref(aid, dscpmk_data->next_action, flags);
415 414 ASSERT(err == 0);
416 415
417 416 kmem_free(dscpmk_data, DSCPMK_DATA_SZ);
418 417 return (0);
419 418 }
420 419
421 420 static int
422 421 dscpmk_invoke_action(ipp_action_id_t aid, ipp_packet_t *packet)
423 422 {
424 423 dscpmk_data_t *dscpmk_data;
425 424 mblk_t *mp = NULL;
426 425 ip_priv_t *priv;
427 426 int err;
428 427
429 428 ASSERT(packet != NULL);
430 429
431 430 /* get mblk from ipp_packet structure */
432 431 mp = ipp_packet_get_data(packet);
433 432 priv = (ip_priv_t *)ipp_packet_get_private(packet);
434 433
435 434 dscpmk_data = (dscpmk_data_t *)ipp_action_get_ptr(aid);
436 435 ASSERT(dscpmk_data != NULL);
437 436
438 437 /* dscpmk packet as configured */
439 438 if ((err = dscpmk_process(&mp, dscpmk_data, priv->proc)) != 0) {
440 439 return (err);
441 440 } else {
442 441 /* return packet with next action set */
443 442 return (ipp_packet_next(packet, dscpmk_data->next_action));
444 443 }
445 444 }
446 445
447 446 static int
448 447 dscpmk_det_statinit(ipp_action_id_t aid, dscpmk_data_t *dscpmk_data, int val)
449 448 {
450 449 int err = 0;
451 450 dscpmk_dscp_stats_t *statp;
452 451 char stats_string[15];
453 452
454 453 (void) sprintf(stats_string, "dscpmk_dscp0x%x", val);
455 454
456 455 /* install stats entry */
457 456 if ((err = ipp_stat_create(aid, stats_string, DSCPMK_DSCP_STATS_COUNT,
458 457 dscpmk_update_det_stats, dscpmk_data,
459 458 &dscpmk_data->dscp_stats[val].stats)) != 0) {
460 459 dscpmk0dbg(("dscpmk_det_statinit: ipp_stat_create returned "\
461 460 "with error %d\n", err));
462 461 return (err);
463 462 }
464 463
465 464 statp = (dscpmk_dscp_stats_t *)
466 465 (dscpmk_data->dscp_stats[val].stats)->ipps_data;
467 466 ASSERT(statp != NULL);
468 467
469 468 if ((err = ipp_stat_named_init(dscpmk_data->dscp_stats[val].stats,
470 469 "dscp", IPP_STAT_UINT32, &statp->dscp)) != 0) {
471 470 dscpmk0dbg(("dscpmk_det_statinit: ipp_stat_named_init "\
472 471 "returned with error %d\n", err));
473 472 return (err);
474 473 }
475 474
476 475 if ((err = ipp_stat_named_init(dscpmk_data->dscp_stats[val].stats,
477 476 "npackets", IPP_STAT_UINT64, &statp->npackets)) != 0) {
478 477 dscpmk0dbg(("dscpmk_det_statinit: ipp_stat_named_init "\
479 478 "returned with error %d\n", err));
480 479 return (err);
481 480 }
482 481
483 482 ipp_stat_install(dscpmk_data->dscp_stats[val].stats);
484 483 return (0);
485 484 }
486 485
487 486
488 487 static int
489 488 dscpmk_summ_statinit(ipp_action_id_t aid, dscpmk_data_t *dscpmk_data)
490 489 {
491 490 int err = 0;
492 491 dscpmk_stat_t *statp;
493 492
494 493 /* install stats entry */
495 494 if ((err = ipp_stat_create(aid, DSCPMK_STATS_STRING, DSCPMK_STATS_COUNT,
496 495 dscpmk_update_stats, dscpmk_data, &dscpmk_data->stats)) != 0) {
497 496 dscpmk0dbg(("dscpmk_create_action: ipp_stat_create returned " \
498 497 "with error %d\n", err));
499 498 return (err);
500 499 }
501 500
502 501 statp = (dscpmk_stat_t *)(dscpmk_data->stats)->ipps_data;
503 502 ASSERT(statp != NULL);
504 503
505 504 if ((err = ipp_stat_named_init(dscpmk_data->stats, "npackets",
506 505 IPP_STAT_UINT64, &statp->npackets)) != 0) {
507 506 dscpmk0dbg(("dscpmk_summ_statinit: ipp_stat_named_init " \
508 507 "returned with error %d\n", err));
509 508 return (err);
510 509 }
511 510
512 511 if ((err = ipp_stat_named_init(dscpmk_data->stats, "dscp_changed",
513 512 IPP_STAT_UINT64, &statp->dscp_changed)) != 0) {
514 513 dscpmk0dbg(("dscpmk_summ_statinit: ipp_stat_named_init " \
515 514 "returned with error %d\n", err));
516 515 return (err);
517 516 }
518 517
519 518 if ((err = ipp_stat_named_init(dscpmk_data->stats, "dscp_unchanged",
520 519 IPP_STAT_UINT64, &statp->dscp_unchanged)) != 0) {
521 520 dscpmk0dbg(("dscpmk_summ_statinit: ipp_stat_named_init " \
522 521 "returned with error %d\n", err));
523 522 return (err);
524 523 }
525 524
526 525 if ((err = ipp_stat_named_init(dscpmk_data->stats, "ipackets",
527 526 IPP_STAT_UINT64, &statp->ipackets)) != 0) {
528 527 dscpmk0dbg(("dscpmk_summ_statinit: ipp_stat_named_init " \
529 528 "returned with error %d\n", err));
530 529 return (err);
531 530 }
532 531
533 532 if ((err = ipp_stat_named_init(dscpmk_data->stats, "epackets",
534 533 IPP_STAT_UINT64, &statp->epackets)) != 0) {
535 534 dscpmk0dbg(("dscpmk_summ_statinit: ipp_stat_named_init " \
536 535 "returned with error %d\n", err));
537 536 return (err);
538 537 }
539 538
540 539 ipp_stat_install(dscpmk_data->stats);
541 540 return (0);
542 541 }
543 542
544 543 /* ARGSUSED */
545 544 static int
546 545 dscpmk_update_det_stats(ipp_stat_t *sp, void *arg, int rw)
547 546 {
548 547 dscpmk_data_t *dscpmk_data = (dscpmk_data_t *)arg;
549 548 dscpmk_dscp_stats_t *statp;
550 549 uint32_t count;
551 550
552 551 for (count = 0; count < DSCPMK_ARRAY_COUNT; count++) {
553 552 if (!dscpmk_data->dscp_stats[count].present)
554 553 continue;
555 554 statp = (dscpmk_dscp_stats_t *)
556 555 (dscpmk_data->dscp_stats[count].stats)->ipps_data;
557 556 ASSERT(statp != NULL);
558 557 (void) ipp_stat_named_op(&statp->npackets,
559 558 &dscpmk_data->dscp_stats[count].npackets, rw);
560 559 (void) ipp_stat_named_op(&statp->dscp, &count, rw);
561 560 }
562 561 return (0);
563 562 }
564 563
565 564 static int
566 565 dscpmk_update_stats(ipp_stat_t *sp, void *arg, int rw)
567 566 {
568 567 dscpmk_data_t *dscpmk_data = (dscpmk_data_t *)arg;
569 568 dscpmk_stat_t *snames = (dscpmk_stat_t *)sp->ipps_data;
570 569 ASSERT(dscpmk_data != NULL);
571 570 ASSERT(snames != NULL);
572 571
573 572 (void) ipp_stat_named_op(&snames->npackets, &dscpmk_data->npackets, rw);
574 573 (void) ipp_stat_named_op(&snames->dscp_changed, &dscpmk_data->changed,
575 574 rw);
576 575 (void) ipp_stat_named_op(&snames->dscp_unchanged,
577 576 &dscpmk_data->unchanged, rw);
578 577 (void) ipp_stat_named_op(&snames->ipackets, &dscpmk_data->ipackets, rw);
579 578 (void) ipp_stat_named_op(&snames->epackets, &dscpmk_data->epackets, rw);
580 579
581 580 return (0);
582 581 }
583 582
584 583 /* ARGSUSED */
585 584 static int
586 585 dscpmk_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
587 586 ipp_flags_t flags)
588 587 {
589 588 nvlist_t *nvlp;
590 589 dscpmk_data_t *dscpmk_data;
591 590 char *next_action;
592 591 int err, cnt;
593 592 int32_t dscp_map[DSCPMK_ARRAY_COUNT];
594 593
595 594 ASSERT(fn != NULL);
596 595
597 596 dscpmk_data = (dscpmk_data_t *)ipp_action_get_ptr(aid);
598 597 ASSERT(dscpmk_data != NULL);
599 598
600 599 /* allocate nvlist to be passed back */
601 600 if ((err = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_NOSLEEP)) != 0) {
602 601 dscpmk0dbg(("dscpmk_info: error allocating memory\n"));
603 602 return (err);
604 603 }
605 604
606 605 /* look up next action with the next action id */
607 606 if ((err = ipp_action_name(dscpmk_data->next_action,
608 607 &next_action)) != 0) {
609 608 dscpmk0dbg(("dscpmk_info: next action not available\n"));
610 609 nvlist_free(nvlp);
611 610 return (err);
612 611 }
613 612
614 613 /* add next action name */
615 614 if ((err = nvlist_add_string(nvlp, DSCPMK_NEXT_ACTION_NAME,
616 615 next_action)) != 0) {
617 616 dscpmk0dbg(("dscpmk_info: error adding next action\n"));
618 617 nvlist_free(nvlp);
619 618 kmem_free(next_action, (strlen(next_action) + 1));
620 619 return (err);
621 620 }
622 621
623 622 /* free action name */
624 623 kmem_free(next_action, (strlen(next_action) + 1));
625 624
626 625 /* add config type */
627 626 if ((err = nvlist_add_byte(nvlp, IPP_CONFIG_TYPE, IPP_SET)) != 0) {
628 627 dscpmk0dbg(("dscpmk_info: error adding config type\n"));
629 628 nvlist_free(nvlp);
630 629 return (err);
631 630 }
632 631
633 632 /* add dscp map */
634 633 bcopy(dscpmk_data->dscp_map, dscp_map, sizeof (dscp_map));
635 634 for (cnt = 0; cnt < DSCPMK_ARRAY_COUNT; cnt++) {
636 635 dscp_map[cnt] = dscpmk_data->dscp_map[cnt];
637 636 }
638 637 if ((err = nvlist_add_int32_array(nvlp, DSCPMK_DSCP_MAP,
639 638 dscp_map, DSCPMK_ARRAY_COUNT)) != 0) {
640 639 dscpmk0dbg(("dscpmk_info: error adding dscp map\n"));
641 640 nvlist_free(nvlp);
642 641 return (err);
643 642 }
644 643
645 644 /* add summary stats boolean */
646 645 if ((err = nvlist_add_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
647 646 (dscpmk_data->summary_stats ? 1 : 0))) != 0) {
648 647 dscpmk0dbg(("dscpmk_info: error adding stats status\n"));
649 648 nvlist_free(nvlp);
650 649 return (err);
651 650 }
652 651
653 652 /* add detailed stats boolean */
654 653 if ((err = nvlist_add_uint32(nvlp, DSCPMK_DETAILED_STATS,
655 654 (dscpmk_data->detailed_stats ? 1 : 0))) != 0) {
656 655 dscpmk0dbg(("dscpmk_info: error adding det stats status\n"));
657 656 nvlist_free(nvlp);
658 657 return (err);
659 658 }
660 659
661 660 /* call back with nvlist */
662 661 err = fn(nvlp, arg);
663 662
664 663 nvlist_free(nvlp);
665 664 return (err);
666 665 }
↓ open down ↓ |
556 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX