Print this page
7127 remove -Wno-missing-braces from Makefile.uts
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/ipp/meters/tswtclddi.c
+++ new/usr/src/uts/common/ipp/meters/tswtclddi.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 /*
23 23 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 26
27 27 #include <sys/types.h>
28 28 #include <sys/atomic.h>
29 29 #include <sys/systm.h>
30 30 #include <sys/socket.h>
31 31 #include <netinet/in.h>
32 32 #include <sys/modctl.h>
33 33 #include <sys/sunddi.h>
34 34 #include <ipp/ipp.h>
35 35 #include <ipp/ipp_config.h>
36 36 #include <inet/common.h>
37 37 #include <ipp/meters/meter_impl.h>
38 38
39 39 #define D_SM_COMMENT "IPP Sliding Window Meter"
40 40
41 41 /* DDI file for tswtcl ipp module */
42 42
43 43 static int tswtcl_create_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
44 44 static int tswtcl_modify_action(ipp_action_id_t, nvlist_t **, ipp_flags_t);
45 45 static int tswtcl_destroy_action(ipp_action_id_t, ipp_flags_t);
46 46 static int tswtcl_info(ipp_action_id_t, int (*)(nvlist_t *, void *), void *,
47 47 ipp_flags_t);
48 48 static int tswtcl_invoke_action(ipp_action_id_t, ipp_packet_t *);
49 49
50 50 /* Stats init function */
51 51 static int tswtcl_statinit(ipp_action_id_t, tswtcl_data_t *);
52 52
53 53 /* Stats callback function */
54 54 static int tswtcl_update_stats(ipp_stat_t *, void *, int);
55 55
56 56 ipp_ops_t tswtcl_ops = {
57 57 IPPO_REV,
58 58 tswtcl_create_action, /* ippo_action_create */
59 59 tswtcl_modify_action, /* ippo_action_modify */
60 60 tswtcl_destroy_action, /* ippo_action_destroy */
61 61 tswtcl_info, /* ippo_action_info */
62 62 tswtcl_invoke_action /* ippo_action_invoke */
63 63 };
64 64
65 65 extern struct mod_ops mod_ippops;
66 66
67 67 /*
↓ open down ↓ |
67 lines elided |
↑ open up ↑ |
68 68 * Module linkage information for the kernel.
69 69 */
70 70 static struct modlipp modlipp = {
71 71 &mod_ippops,
72 72 D_SM_COMMENT,
73 73 &tswtcl_ops
74 74 };
75 75
76 76 static struct modlinkage modlinkage = {
77 77 MODREV_1,
78 - (void *)&modlipp,
79 - NULL
78 + { (void *)&modlipp, NULL }
80 79 };
81 80
82 81
83 82 int
84 83 _init(void)
85 84 {
86 85 return (mod_install(&modlinkage));
87 86 }
88 87
89 88 int
90 89 _fini(void)
91 90 {
92 91 return (mod_remove(&modlinkage));
93 92 }
94 93
95 94 int
96 95 _info(struct modinfo *modinfop)
97 96 {
98 97 return (mod_info(&modlinkage, modinfop));
99 98 }
100 99
101 100 /* ARGSUSED */
102 101 static int
103 102 tswtcl_create_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
104 103 {
105 104 nvlist_t *nvlp;
106 105 tswtcl_data_t *tswtcl_data;
107 106 tswtcl_cfg_t *cfg_parms;
108 107 char *next_action;
109 108 uint32_t bstats;
110 109 int rc, rc2;
111 110
112 111 nvlp = *nvlpp;
113 112 *nvlpp = NULL; /* nvlist should be NULL on return */
114 113
115 114
116 115 if ((cfg_parms = kmem_alloc(TSWTCL_CFG_SZ, KM_NOSLEEP)) == NULL) {
117 116 nvlist_free(nvlp);
118 117 return (ENOMEM);
119 118 }
120 119
121 120 /* parse red next action name */
122 121 if ((rc = nvlist_lookup_string(nvlp, TSWTCL_RED_ACTION_NAME,
123 122 &next_action)) != 0) {
124 123 nvlist_free(nvlp);
125 124 tswtcl0dbg(("tswtcl_create_action:invalid config, red action" \
126 125 " name missing\n"));
127 126 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
128 127 return (rc);
129 128 }
130 129 if ((cfg_parms->red_action = ipp_action_lookup(next_action))
131 130 == IPP_ACTION_INVAL) {
132 131 nvlist_free(nvlp);
133 132 tswtcl0dbg(("tswtcl_create_action: red action invalid\n"));
134 133 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
135 134 return (EINVAL);
136 135 }
137 136
138 137 /* parse yellow next action name */
139 138 if ((rc = nvlist_lookup_string(nvlp, TSWTCL_YELLOW_ACTION_NAME,
140 139 &next_action)) != 0) {
141 140 nvlist_free(nvlp);
142 141 tswtcl0dbg(("tswtcl_create_action:invalid config, yellow " \
143 142 "action name missing\n"));
144 143 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
145 144 return (rc);
146 145 }
147 146 if ((cfg_parms->yellow_action = ipp_action_lookup(next_action))
148 147 == IPP_ACTION_INVAL) {
149 148 nvlist_free(nvlp);
150 149 tswtcl0dbg(("tswtcl_create_action: yellow action invalid\n"));
151 150 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
152 151 return (EINVAL);
153 152 }
154 153
155 154 /* parse green next action name */
156 155 if ((rc = nvlist_lookup_string(nvlp, TSWTCL_GREEN_ACTION_NAME,
157 156 &next_action)) != 0) {
158 157 nvlist_free(nvlp);
159 158 tswtcl0dbg(("tswtcl_create_action:invalid config, green " \
160 159 "action name missing\n"));
161 160 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
162 161 return (rc);
163 162 }
164 163 if ((cfg_parms->green_action = ipp_action_lookup(next_action))
165 164 == IPP_ACTION_INVAL) {
166 165 nvlist_free(nvlp);
167 166 tswtcl0dbg(("tswtcl_create_action: green action invalid\n"));
168 167 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
169 168 return (EINVAL);
170 169 }
171 170
172 171 /* parse committed rate - in bits / sec */
173 172 if ((rc = nvlist_lookup_uint32(nvlp, TSWTCL_COMMITTED_RATE,
174 173 &cfg_parms->committed_rate)) != 0) {
175 174 nvlist_free(nvlp);
176 175 tswtcl0dbg(("tswtcl_create_action: invalid config, "\
177 176 " committed rate missing\n"));
178 177 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
179 178 return (rc);
180 179 }
181 180
182 181 /* parse peak rate - in bits / sec */
183 182 if ((rc = nvlist_lookup_uint32(nvlp, TSWTCL_PEAK_RATE,
184 183 &cfg_parms->peak_rate)) != 0) {
185 184 nvlist_free(nvlp);
186 185 tswtcl0dbg(("tswtcl_create_action: invalid config, "\
187 186 " peak rate missing\n"));
188 187 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
189 188 return (rc);
190 189 }
191 190
192 191 if (cfg_parms->peak_rate < cfg_parms->committed_rate) {
193 192 nvlist_free(nvlp);
194 193 tswtcl0dbg(("tswtcl_create_action: invalid config, "\
195 194 " peak rate < committed rate\n"));
196 195 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
197 196 return (EINVAL);
198 197 }
199 198
200 199 /* parse window - in msec */
201 200 if ((rc = nvlist_lookup_uint32(nvlp, TSWTCL_WINDOW,
202 201 &cfg_parms->window)) != 0) {
203 202 nvlist_free(nvlp);
204 203 tswtcl0dbg(("tswtcl_create_action: invalid config, "\
205 204 " window missing\n"));
206 205 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
207 206 return (rc);
208 207 }
209 208 /* convert to nsec */
210 209 cfg_parms->nsecwindow = (uint64_t)cfg_parms->window *
211 210 METER_MSEC_TO_NSEC;
212 211
213 212 /* parse stats */
214 213 if ((rc = nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats))
215 214 != 0) {
216 215 cfg_parms->stats = B_FALSE;
217 216 } else {
218 217 cfg_parms->stats = (boolean_t)bstats;
219 218 }
220 219
221 220 nvlist_free(nvlp);
222 221
223 222 /* Initialize other stuff */
224 223 tswtcl_data = kmem_zalloc(TSWTCL_DATA_SZ, KM_NOSLEEP);
225 224 if (tswtcl_data == NULL) {
226 225 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
227 226 return (ENOMEM);
228 227 }
229 228
230 229 if (cfg_parms->stats) {
231 230 if ((rc = tswtcl_statinit(aid, tswtcl_data)) != 0) {
232 231 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
233 232 kmem_free(tswtcl_data, TSWTCL_DATA_SZ);
234 233 return (rc);
235 234 }
236 235 }
237 236
238 237 /* set action chain reference */
239 238 if ((rc = ipp_action_ref(aid, cfg_parms->red_action, flags)) != 0) {
240 239 tswtcl0dbg(("tswtcl_create_action: ipp_action_ref " \
241 240 "returned with error %d", rc));
242 241 goto cleanup;
243 242 }
244 243 if ((rc = ipp_action_ref(aid, cfg_parms->yellow_action, flags)) != 0) {
245 244 tswtcl0dbg(("tswtcl_create_action: ipp_action_ref " \
246 245 "returned with error %d", rc));
247 246 rc2 = ipp_action_unref(aid, cfg_parms->red_action, flags);
248 247 ASSERT(rc2 == 0);
249 248 goto cleanup;
250 249 }
251 250 if ((rc = ipp_action_ref(aid, cfg_parms->green_action, flags)) != 0) {
252 251 tswtcl0dbg(("tswtcl_create_action: ipp_action_ref " \
253 252 "returned with error %d", rc));
254 253 rc2 = ipp_action_unref(aid, cfg_parms->red_action, flags);
255 254 ASSERT(rc2 == 0);
256 255 rc2 = ipp_action_unref(aid, cfg_parms->yellow_action, flags);
257 256 ASSERT(rc2 == 0);
258 257 goto cleanup;
259 258 }
260 259
261 260 /* Initializations */
262 261 cfg_parms->pminusc = cfg_parms->peak_rate - cfg_parms->committed_rate;
263 262 tswtcl_data->cfg_parms = cfg_parms;
264 263 tswtcl_data->avg_rate = cfg_parms->committed_rate;
265 264 mutex_init(&tswtcl_data->tswtcl_lock, NULL, MUTEX_DEFAULT, 0);
266 265 tswtcl_data->win_front = gethrtime();
267 266 ipp_action_set_ptr(aid, (void *)tswtcl_data);
268 267
269 268 return (0);
270 269
271 270 cleanup:
272 271 if (cfg_parms->stats) {
273 272 ipp_stat_destroy(tswtcl_data->stats);
274 273 }
275 274 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
276 275 kmem_free(tswtcl_data, TSWTCL_DATA_SZ);
277 276 return (rc);
278 277
279 278 }
280 279
281 280 static int
282 281 tswtcl_modify_action(ipp_action_id_t aid, nvlist_t **nvlpp, ipp_flags_t flags)
283 282 {
284 283
285 284 nvlist_t *nvlp;
286 285 int err = 0, err2;
287 286 uint8_t config_type;
288 287 char *next_action_name;
289 288 ipp_action_id_t next_action;
290 289 uint32_t rate;
291 290 tswtcl_cfg_t *cfg_parms, *old_cfg;
292 291 tswtcl_data_t *tswtcl_data;
293 292 uint32_t bstats;
294 293
295 294 nvlp = *nvlpp;
296 295 *nvlpp = NULL; /* nvlist should be NULL when this returns */
297 296
298 297 if ((err = nvlist_lookup_byte(nvlp, IPP_CONFIG_TYPE, &config_type))
299 298 != 0) {
300 299 nvlist_free(nvlp);
301 300 tswtcl0dbg(("tswtcl_modify_action:invalid configuration type"));
302 301 return (err);
303 302 }
304 303
305 304 if (config_type != IPP_SET) {
306 305 nvlist_free(nvlp);
307 306 tswtcl0dbg(("tswtcl_modify_action:invalid configuration type " \
308 307 "%d", config_type));
309 308 return (EINVAL);
310 309 }
311 310
312 311 tswtcl_data = (tswtcl_data_t *)ipp_action_get_ptr(aid);
313 312 old_cfg = tswtcl_data->cfg_parms;
314 313
315 314 cfg_parms = kmem_alloc(TSWTCL_CFG_SZ, KM_NOSLEEP);
316 315 if (cfg_parms == NULL) {
317 316 nvlist_free(nvlp);
318 317 tswtcl0dbg(("tswtcl_modify_action:mem. allocation failure\n"));
319 318 return (ENOMEM);
320 319 }
321 320
322 321 /* Just copy all and change as needed */
323 322 bcopy(old_cfg, cfg_parms, TSWTCL_CFG_SZ);
324 323
325 324 /* parse red action name, if present */
326 325 if ((err = nvlist_lookup_string(nvlp, TSWTCL_RED_ACTION_NAME,
327 326 &next_action_name)) == 0) {
328 327 /* Get action id */
329 328 if ((next_action = ipp_action_lookup(next_action_name))
330 329 == IPP_ACTION_INVAL) {
331 330 nvlist_free(nvlp);
332 331 tswtcl0dbg(("tswtcl_modify_action: red next_action"\
333 332 " invalid\n"));
334 333 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
335 334 return (EINVAL);
336 335 }
337 336 cfg_parms->red_action = next_action;
338 337 }
339 338
340 339 /* parse yellow action name, if present */
341 340 if ((err = nvlist_lookup_string(nvlp, TSWTCL_YELLOW_ACTION_NAME,
342 341 &next_action_name)) == 0) {
343 342 /* Get action id */
344 343 if ((next_action = ipp_action_lookup(next_action_name))
345 344 == IPP_ACTION_INVAL) {
346 345 nvlist_free(nvlp);
347 346 tswtcl0dbg(("tswtcl_modify_action: yellow next_action"\
348 347 " invalid\n"));
349 348 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
350 349 return (EINVAL);
351 350 }
352 351 cfg_parms->yellow_action = next_action;
353 352 }
354 353
355 354 /* parse green action name, if present */
356 355 if ((err = nvlist_lookup_string(nvlp, TSWTCL_GREEN_ACTION_NAME,
357 356 &next_action_name)) == 0) {
358 357 /* Get action id */
359 358 if ((next_action = ipp_action_lookup(next_action_name))
360 359 == IPP_ACTION_INVAL) {
361 360 nvlist_free(nvlp);
362 361 tswtcl0dbg(("tswtcl_modify_action: green next_action"\
363 362 " invalid\n"));
364 363 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
365 364 return (EINVAL);
366 365 }
367 366 cfg_parms->green_action = next_action;
368 367 }
369 368
370 369 /* parse committed rate, if present */
371 370 if ((err = nvlist_lookup_uint32(nvlp, TSWTCL_COMMITTED_RATE, &rate))
372 371 == 0) {
373 372 cfg_parms->committed_rate = rate;
374 373 }
375 374
376 375 /* parse peak rate, if present */
377 376 if ((err = nvlist_lookup_uint32(nvlp, TSWTCL_PEAK_RATE, &rate))
378 377 == 0) {
379 378 cfg_parms->peak_rate = rate;
380 379 }
381 380
382 381 if (cfg_parms->peak_rate < cfg_parms->committed_rate) {
383 382 nvlist_free(nvlp);
384 383 tswtcl0dbg(("tswtcl_create_action: invalid config, "\
385 384 " peak rate < committed rate\n"));
386 385 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
387 386 return (EINVAL);
388 387 }
389 388
390 389 /* parse window - in msec */
391 390 if ((err = nvlist_lookup_uint32(nvlp, TSWTCL_WINDOW,
392 391 &cfg_parms->window)) != 0) {
393 392 cfg_parms->nsecwindow = (uint64_t)cfg_parms->window *
394 393 METER_MSEC_TO_NSEC;
395 394 }
396 395
397 396 /* parse stats, if present */
398 397 if (nvlist_lookup_uint32(nvlp, IPP_ACTION_STATS_ENABLE, &bstats) == 0) {
399 398 cfg_parms->stats = (boolean_t)bstats;
400 399 if (cfg_parms->stats && !old_cfg->stats) {
401 400 if ((err = tswtcl_statinit(aid, tswtcl_data)) != 0) {
402 401 nvlist_free(nvlp);
403 402 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
404 403 return (err);
405 404 }
406 405 } else if (!cfg_parms->stats && old_cfg->stats) {
407 406 ipp_stat_destroy(tswtcl_data->stats);
408 407 }
409 408 }
410 409
411 410 /* Can we ref all the new actions? */
412 411 if ((err = ipp_action_ref(aid, cfg_parms->red_action, flags)) != 0) {
413 412 tswtcl0dbg(("tswtcl_modify_data: can't ref. red action\n"));
414 413 nvlist_free(nvlp);
415 414 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
416 415 return (err);
417 416 }
418 417
419 418 if ((err = ipp_action_ref(aid, cfg_parms->yellow_action, flags)) != 0) {
420 419 tswtcl0dbg(("tswtcl_modify_data:can't ref. yellow action\n"));
421 420 nvlist_free(nvlp);
422 421 err2 = ipp_action_unref(aid, cfg_parms->red_action, flags);
423 422 ASSERT(err2 == 0);
424 423 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
425 424 return (err);
426 425 }
427 426
428 427 if ((err = ipp_action_ref(aid, cfg_parms->green_action, flags)) != 0) {
429 428 tswtcl0dbg(("tswtcl_modify_data:can't ref. green action\n"));
430 429 nvlist_free(nvlp);
431 430 err2 = ipp_action_unref(aid, cfg_parms->red_action, flags);
432 431 ASSERT(err2 == 0);
433 432 err2 = ipp_action_unref(aid, cfg_parms->yellow_action, flags);
434 433 ASSERT(err2 == 0);
435 434 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
436 435 return (err);
437 436 }
438 437
439 438 /* Re-compute pminusc */
440 439 cfg_parms->pminusc = cfg_parms->peak_rate - cfg_parms->committed_rate;
441 440
442 441 /* Actually modify the configuration */
443 442 mutex_enter(&tswtcl_data->tswtcl_lock);
444 443 tswtcl_data->cfg_parms = cfg_parms;
445 444 mutex_exit(&tswtcl_data->tswtcl_lock);
446 445
447 446 /* Un-ref the old actions */
448 447 err = ipp_action_unref(aid, old_cfg->red_action, flags);
449 448 ASSERT(err == 0);
450 449 err = ipp_action_unref(aid, old_cfg->yellow_action, flags);
451 450 ASSERT(err == 0);
452 451 err = ipp_action_unref(aid, old_cfg->green_action, flags);
453 452 ASSERT(err == 0);
454 453
455 454 /* Free the old configuration */
456 455 kmem_free(old_cfg, TSWTCL_CFG_SZ);
457 456
458 457 nvlist_free(nvlp);
459 458
460 459 return (0);
461 460 }
462 461
463 462 static int
464 463 tswtcl_destroy_action(ipp_action_id_t aid, ipp_flags_t flags)
465 464 {
466 465 tswtcl_data_t *tswtcl_data;
467 466 tswtcl_cfg_t *cfg_parms;
468 467 int rc;
469 468
470 469 tswtcl_data = (tswtcl_data_t *)ipp_action_get_ptr(aid);
471 470 ASSERT(tswtcl_data != NULL);
472 471
473 472 cfg_parms = tswtcl_data->cfg_parms;
474 473
475 474 if (cfg_parms->stats) {
476 475 ipp_stat_destroy(tswtcl_data->stats);
477 476 }
478 477
479 478 /* unreference the action */
480 479 rc = ipp_action_unref(aid, cfg_parms->red_action, flags);
481 480 ASSERT(rc == 0);
482 481 rc = ipp_action_unref(aid, cfg_parms->yellow_action, flags);
483 482 ASSERT(rc == 0);
484 483 rc = ipp_action_unref(aid, cfg_parms->green_action, flags);
485 484 ASSERT(rc == 0);
486 485
487 486 mutex_destroy(&tswtcl_data->tswtcl_lock);
488 487 kmem_free(cfg_parms, TSWTCL_CFG_SZ);
489 488 kmem_free(tswtcl_data, TSWTCL_DATA_SZ);
490 489 return (0);
491 490 }
492 491
493 492 static int
494 493 tswtcl_invoke_action(ipp_action_id_t aid, ipp_packet_t *packet)
495 494 {
496 495 tswtcl_data_t *tswtcl_data;
497 496 ipp_action_id_t next_action;
498 497 mblk_t *mp = NULL;
499 498 int rc;
500 499
501 500 /* get mblk from ipp_packet structure */
502 501 mp = ipp_packet_get_data(packet);
503 502 tswtcl_data = (tswtcl_data_t *)ipp_action_get_ptr(aid);
504 503 ASSERT(tswtcl_data != NULL);
505 504
506 505 /* tswtcl packet as configured */
507 506 if ((rc = tswtcl_process(&mp, tswtcl_data, &next_action)) != 0) {
508 507 return (rc);
509 508 } else {
510 509 return (ipp_packet_next(packet, next_action));
511 510 }
512 511 }
513 512
514 513 static int
515 514 tswtcl_statinit(ipp_action_id_t aid, tswtcl_data_t *tswtcl_data)
516 515 {
517 516 int rc = 0;
518 517 meter_stat_t *statsp;
519 518
520 519 /* install stats entry */
521 520 if ((rc = ipp_stat_create(aid, TSWTCL_STATS_STRING, METER_STATS_COUNT,
522 521 tswtcl_update_stats, tswtcl_data, &tswtcl_data->stats)) != 0) {
523 522 tswtcl0dbg(("tswtcl_statinit:ipp_stat_create failed "\
524 523 " with %d\n", rc));
525 524 return (rc);
526 525 }
527 526
528 527 statsp = (meter_stat_t *)(tswtcl_data->stats)->ipps_data;
529 528 ASSERT(statsp != NULL);
530 529
531 530 if ((rc = ipp_stat_named_init(tswtcl_data->stats, "red_packets",
532 531 IPP_STAT_UINT64, &statsp->red_packets)) != 0) {
533 532 tswtcl0dbg(("tswtcl_statinit:ipp_stat_create failed "\
534 533 " with %d\n", rc));
535 534 return (rc);
536 535 }
537 536 if ((rc = ipp_stat_named_init(tswtcl_data->stats, "red_bits",
538 537 IPP_STAT_UINT64, &statsp->red_bits)) != 0) {
539 538 tswtcl0dbg(("tswtcl_statinit:ipp_stat_create failed "\
540 539 " with %d\n", rc));
541 540 return (rc);
542 541 }
543 542 if ((rc = ipp_stat_named_init(tswtcl_data->stats, "yellow_packets",
544 543 IPP_STAT_UINT64, &statsp->yellow_packets)) != 0) {
545 544 tswtcl0dbg(("tswtcl_statinit:ipp_stat_named_init failed "\
546 545 " with %d\n", rc));
547 546 return (rc);
548 547 }
549 548 if ((rc = ipp_stat_named_init(tswtcl_data->stats, "yellow_bits",
550 549 IPP_STAT_UINT64, &statsp->yellow_bits)) != 0) {
551 550 tswtcl0dbg(("tswtcl_statinit:ipp_stat_create failed "\
552 551 " with %d\n", rc));
553 552 return (rc);
554 553 }
555 554 if ((rc = ipp_stat_named_init(tswtcl_data->stats, "green_packets",
556 555 IPP_STAT_UINT64, &statsp->green_packets)) != 0) {
557 556 tswtcl0dbg(("tswtcl_statinit:ipp_stat_named_init failed "\
558 557 " with %d\n", rc));
559 558 return (rc);
560 559 }
561 560 if ((rc = ipp_stat_named_init(tswtcl_data->stats, "green_bits",
562 561 IPP_STAT_UINT64, &statsp->green_bits)) != 0) {
563 562 tswtcl0dbg(("tswtcl_statinit:ipp_stat_create failed "\
564 563 " with %d\n", rc));
565 564 return (rc);
566 565 }
567 566 if ((rc = ipp_stat_named_init(tswtcl_data->stats, "epackets",
568 567 IPP_STAT_UINT64, &statsp->epackets)) != 0) {
569 568 tswtcl0dbg(("tswtcl_statinit:ipp_stat_named_init failed "\
570 569 " with %d\n", rc));
571 570 return (rc);
572 571 }
573 572 ipp_stat_install(tswtcl_data->stats);
574 573
575 574 return (rc);
576 575
577 576 }
578 577
579 578 static int
580 579 tswtcl_update_stats(ipp_stat_t *sp, void *args, int rw)
581 580 {
582 581 tswtcl_data_t *tswtcl_data = (tswtcl_data_t *)args;
583 582 meter_stat_t *stats = (meter_stat_t *)sp->ipps_data;
584 583
585 584 ASSERT((tswtcl_data != NULL) && (stats != NULL));
586 585
587 586 (void) ipp_stat_named_op(&stats->red_packets, &tswtcl_data->red_packets,
588 587 rw);
589 588 (void) ipp_stat_named_op(&stats->yellow_packets,
590 589 &tswtcl_data->yellow_packets, rw);
591 590 (void) ipp_stat_named_op(&stats->green_packets,
592 591 &tswtcl_data->green_packets, rw);
593 592
594 593 (void) ipp_stat_named_op(&stats->red_bits, &tswtcl_data->red_bits, rw);
595 594 (void) ipp_stat_named_op(&stats->yellow_bits,
596 595 &tswtcl_data->yellow_bits, rw);
597 596 (void) ipp_stat_named_op(&stats->green_bits,
598 597 &tswtcl_data->green_bits, rw);
599 598
600 599 (void) ipp_stat_named_op(&stats->epackets, &tswtcl_data->epackets,
601 600 rw);
602 601
603 602 return (0);
604 603 }
605 604
606 605 /* ARGSUSED */
607 606 static int
608 607 tswtcl_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
609 608 ipp_flags_t flags)
610 609 {
611 610 nvlist_t *nvlp;
612 611 tswtcl_data_t *tswtcl_data;
613 612 tswtcl_cfg_t *cfg_parms;
614 613 char *next_action;
615 614 int rc;
616 615
617 616 tswtcl_data = (tswtcl_data_t *)ipp_action_get_ptr(aid);
618 617 ASSERT(tswtcl_data != NULL);
619 618
620 619 cfg_parms = tswtcl_data->cfg_parms;
621 620
622 621 /* allocate nvlist to be passed back */
623 622 if ((rc = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_NOSLEEP)) != 0) {
624 623 tswtcl0dbg(("tswtcl_info: memory allocation failure\n"));
625 624 return (rc);
626 625 }
627 626
628 627 /* look up red next action with the next action id */
629 628 if ((rc = ipp_action_name(cfg_parms->red_action, &next_action)) != 0) {
630 629 tswtcl0dbg(("tswtcl_info: red action not available\n"));
631 630 nvlist_free(nvlp);
632 631 return (rc);
633 632 }
634 633
635 634 /* add next action name */
636 635 if ((rc = nvlist_add_string(nvlp, TSWTCL_RED_ACTION_NAME,
637 636 next_action)) != 0) {
638 637 tswtcl0dbg(("tswtcl_info: error adding\n"));
639 638 nvlist_free(nvlp);
640 639 kmem_free(next_action, (strlen(next_action) + 1));
641 640 return (rc);
642 641 }
643 642
644 643 /* free action name */
645 644 kmem_free(next_action, (strlen(next_action) + 1));
646 645
647 646 /* look up yellow next action with the next action id */
648 647 if ((rc = ipp_action_name(cfg_parms->yellow_action,
649 648 &next_action)) != 0) {
650 649 tswtcl0dbg(("tswtcl_info: yellow action not available\n"));
651 650 nvlist_free(nvlp);
652 651 return (rc);
653 652 }
654 653
655 654 /* add next action name */
656 655 if ((rc = nvlist_add_string(nvlp, TSWTCL_YELLOW_ACTION_NAME,
657 656 next_action)) != 0) {
658 657 tswtcl0dbg(("tswtcl_info: error adding yellow action\n"));
659 658 nvlist_free(nvlp);
660 659 kmem_free(next_action, (strlen(next_action) + 1));
661 660 return (rc);
662 661 }
663 662 /* free action name */
664 663 kmem_free(next_action, (strlen(next_action) + 1));
665 664
666 665 /* look up green next action with the next action id */
667 666 if ((rc = ipp_action_name(cfg_parms->green_action,
668 667 &next_action)) != 0) {
669 668 tswtcl0dbg(("tswtcl_info: green action not available\n"));
670 669 nvlist_free(nvlp);
671 670 return (rc);
672 671 }
673 672
674 673 /* add next action name */
675 674 if ((rc = nvlist_add_string(nvlp, TSWTCL_GREEN_ACTION_NAME,
676 675 next_action)) != 0) {
677 676 tswtcl0dbg(("tswtcl_info: error adding green action\n"));
678 677 nvlist_free(nvlp);
679 678 kmem_free(next_action, (strlen(next_action) + 1));
680 679 return (rc);
681 680 }
682 681
683 682 /* free action name */
684 683 kmem_free(next_action, (strlen(next_action) + 1));
685 684
686 685 /* add config type */
687 686 if ((rc = nvlist_add_byte(nvlp, IPP_CONFIG_TYPE, IPP_SET)) != 0) {
688 687 tswtcl0dbg(("tswtcl_info: error adding config_type\n"));
689 688 nvlist_free(nvlp);
690 689 return (rc);
691 690 }
692 691
693 692 /* add committed_rate */
694 693 if ((rc = nvlist_add_uint32(nvlp, TSWTCL_COMMITTED_RATE,
695 694 cfg_parms->committed_rate)) != 0) {
696 695 tswtcl0dbg(("tswtcl_info: error adding committed_rate\n"));
697 696 nvlist_free(nvlp);
698 697 return (rc);
699 698 }
700 699
701 700 /* add peak_rate */
702 701 if ((rc = nvlist_add_uint32(nvlp, TSWTCL_PEAK_RATE,
703 702 cfg_parms->peak_rate)) != 0) {
704 703 tswtcl0dbg(("tswtcl_info: error adding peak_rate\n"));
705 704 nvlist_free(nvlp);
706 705 return (rc);
707 706 }
708 707
709 708 /* add window */
710 709 if ((rc = nvlist_add_uint32(nvlp, TSWTCL_WINDOW,
711 710 cfg_parms->window)) != 0) {
712 711 tswtcl0dbg(("tswtcl_info: error adding window\n"));
713 712 nvlist_free(nvlp);
714 713 return (rc);
715 714 }
716 715
717 716 if ((rc = nvlist_add_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
718 717 (uint32_t)(uintptr_t)tswtcl_data->stats)) != 0) {
719 718 tswtcl0dbg(("tswtcl_info: error adding stats status\n"));
720 719 nvlist_free(nvlp);
721 720 return (rc);
722 721 }
723 722
724 723 /* call back with nvlist */
725 724 rc = fn(nvlp, arg);
726 725
727 726 nvlist_free(nvlp);
728 727 return (rc);
729 728 }
↓ open down ↓ |
640 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX