Lines Matching defs:ins

117  *  mutex acquired                mutex_enter(ins->ipdn_lock);       |
119 * mutex_enter(ins->ipdn_lock); | mutex_enter(ins->ipdn_lock);
122 * | mutex_exit(ins->ipdn_lock); |
252 ipd_nextrand(ipd_netstack_t *ins)
254 ins->ipdn_rand = ins->ipdn_rand * 1103515245L + 12345;
255 return (ins->ipdn_rand & 0x7fffffff);
266 * grab the ins lock to basically get a copy of all the data that we need to do
281 ipd_netstack_t *ins = arg;
284 mutex_enter(&ins->ipdn_lock);
285 status = ins->ipdn_status;
286 dwait = ins->ipdn_delay;
287 corrupt = ins->ipdn_corrupt;
288 drop = ins->ipdn_drop;
289 rand = ipd_nextrand(ins);
290 mutex_exit(&ins->ipdn_lock);
304 ipd_ksbump(&ins->ipdn_ksdata.ink_ndrops);
314 ipd_ksbump(&ins->ipdn_ksdata.ink_ndelays);
345 ipd_ksbump(&ins->ipdn_ksdata.ink_ncorrupts);
360 ipd_setup_hooks(ipd_netstack_t *ins)
362 ASSERT(MUTEX_HELD(&ins->ipdn_lock));
363 ins->ipdn_v4hdl = net_protocol_lookup(ins->ipdn_netid, NHF_INET);
364 if (ins->ipdn_v4hdl == NULL)
367 ins->ipdn_v6hdl = net_protocol_lookup(ins->ipdn_netid, NHF_INET6);
368 if (ins->ipdn_v6hdl == NULL)
371 ins->ipdn_v4in = hook_alloc(HOOK_VERSION);
372 if (ins->ipdn_v4in == NULL)
375 ins->ipdn_v4in->h_flags = 0;
376 ins->ipdn_v4in->h_hint = HH_NONE;
377 ins->ipdn_v4in->h_hintvalue = 0;
378 ins->ipdn_v4in->h_func = ipd_hook;
379 ins->ipdn_v4in->h_arg = ins;
380 ins->ipdn_v4in->h_name = "ipd IPv4 in";
382 if (net_hook_register(ins->ipdn_v4hdl, NH_PHYSICAL_IN,
383 ins->ipdn_v4in) != 0)
385 ins->ipdn_hooked |= IPDN_HOOK_V4IN;
387 ins->ipdn_v4out = hook_alloc(HOOK_VERSION);
388 if (ins->ipdn_v4out == NULL)
390 ins->ipdn_v4out->h_flags = 0;
391 ins->ipdn_v4out->h_hint = HH_NONE;
392 ins->ipdn_v4out->h_hintvalue = 0;
393 ins->ipdn_v4out->h_func = ipd_hook;
394 ins->ipdn_v4out->h_arg = ins;
395 ins->ipdn_v4out->h_name = "ipd IPv4 out";
397 if (net_hook_register(ins->ipdn_v4hdl, NH_PHYSICAL_OUT,
398 ins->ipdn_v4out) != 0)
400 ins->ipdn_hooked |= IPDN_HOOK_V4OUT;
402 ins->ipdn_v6in = hook_alloc(HOOK_VERSION);
403 if (ins->ipdn_v6in == NULL)
405 ins->ipdn_v6in->h_flags = 0;
406 ins->ipdn_v6in->h_hint = HH_NONE;
407 ins->ipdn_v6in->h_hintvalue = 0;
408 ins->ipdn_v6in->h_func = ipd_hook;
409 ins->ipdn_v6in->h_arg = ins;
410 ins->ipdn_v6in->h_name = "ipd IPv6 in";
412 if (net_hook_register(ins->ipdn_v6hdl, NH_PHYSICAL_IN,
413 ins->ipdn_v6in) != 0)
415 ins->ipdn_hooked |= IPDN_HOOK_V6IN;
417 ins->ipdn_v6out = hook_alloc(HOOK_VERSION);
418 if (ins->ipdn_v6out == NULL)
420 ins->ipdn_v6out->h_flags = 0;
421 ins->ipdn_v6out->h_hint = HH_NONE;
422 ins->ipdn_v6out->h_hintvalue = 0;
423 ins->ipdn_v6out->h_func = ipd_hook;
424 ins->ipdn_v6out->h_arg = ins;
425 ins->ipdn_v6out->h_name = "ipd IPv6 out";
427 if (net_hook_register(ins->ipdn_v6hdl, NH_PHYSICAL_OUT,
428 ins->ipdn_v6out) != 0)
430 ins->ipdn_hooked |= IPDN_HOOK_V6OUT;
438 if (ins->ipdn_hooked & IPDN_HOOK_V6OUT)
439 (void) net_hook_unregister(ins->ipdn_v6hdl, NH_PHYSICAL_OUT,
440 ins->ipdn_v6out);
442 if (ins->ipdn_hooked & IPDN_HOOK_V6IN)
443 (void) net_hook_unregister(ins->ipdn_v6hdl, NH_PHYSICAL_IN,
444 ins->ipdn_v6in);
446 if (ins->ipdn_hooked & IPDN_HOOK_V4OUT)
447 (void) net_hook_unregister(ins->ipdn_v4hdl, NH_PHYSICAL_OUT,
448 ins->ipdn_v4out);
450 if (ins->ipdn_hooked & IPDN_HOOK_V4IN)
451 (void) net_hook_unregister(ins->ipdn_v4hdl, NH_PHYSICAL_IN,
452 ins->ipdn_v4in);
454 ins->ipdn_hooked = IPDN_HOOK_NONE;
456 if (ins->ipdn_v6out != NULL)
457 hook_free(ins->ipdn_v6out);
459 if (ins->ipdn_v6in != NULL)
460 hook_free(ins->ipdn_v6in);
462 if (ins->ipdn_v4out != NULL)
463 hook_free(ins->ipdn_v4out);
465 if (ins->ipdn_v4in != NULL)
466 hook_free(ins->ipdn_v4in);
468 if (ins->ipdn_v6hdl != NULL)
469 (void) net_protocol_release(ins->ipdn_v6hdl);
471 if (ins->ipdn_v4hdl != NULL)
472 (void) net_protocol_release(ins->ipdn_v4hdl);
478 ipd_teardown_hooks(ipd_netstack_t *ins)
480 ASSERT(ins->ipdn_hooked == IPDN_HOOK_ALL);
481 VERIFY(net_hook_unregister(ins->ipdn_v6hdl, NH_PHYSICAL_OUT,
482 ins->ipdn_v6out) == 0);
483 VERIFY(net_hook_unregister(ins->ipdn_v6hdl, NH_PHYSICAL_IN,
484 ins->ipdn_v6in) == 0);
485 VERIFY(net_hook_unregister(ins->ipdn_v4hdl, NH_PHYSICAL_OUT,
486 ins->ipdn_v4out) == 0);
487 VERIFY(net_hook_unregister(ins->ipdn_v4hdl, NH_PHYSICAL_IN,
488 ins->ipdn_v4in) == 0);
490 ins->ipdn_hooked = IPDN_HOOK_NONE;
492 hook_free(ins->ipdn_v6out);
493 hook_free(ins->ipdn_v6in);
494 hook_free(ins->ipdn_v4out);
495 hook_free(ins->ipdn_v4in);
497 VERIFY(net_protocol_release(ins->ipdn_v6hdl) == 0);
498 VERIFY(net_protocol_release(ins->ipdn_v4hdl) == 0);
506 ipd_check_hooks(ipd_netstack_t *ins, int type, boolean_t enable)
509 olden = ins->ipdn_enabled;
512 ins->ipdn_enabled |= type;
514 ins->ipdn_enabled &= ~type;
519 if (olden == 0 && ins->ipdn_enabled != 0) {
520 rval = ipd_setup_hooks(ins);
522 ins->ipdn_enabled &= ~type;
523 ASSERT(ins->ipdn_enabled == 0);
530 if (olden != 0 && ins->ipdn_enabled == 0) {
549 mutex_exit(&ins->ipdn_lock);
550 ipd_teardown_hooks(ins);
551 mutex_enter(&ins->ipdn_lock);
558 ASSERT((olden == 0) == (ins->ipdn_enabled == 0));
563 ipd_toggle_corrupt(ipd_netstack_t *ins, int percent)
567 ASSERT(MUTEX_HELD(&ins->ipdn_lock));
576 if (percent == ins->ipdn_corrupt)
579 ins->ipdn_corrupt = percent;
580 rval = ipd_check_hooks(ins, IPD_CORRUPT, percent != 0);
588 ins->ipdn_corrupt = 0;
594 ipd_toggle_delay(ipd_netstack_t *ins, uint32_t delay)
598 ASSERT(MUTEX_HELD(&ins->ipdn_lock));
607 if (delay == ins->ipdn_delay)
610 ins->ipdn_delay = delay;
611 rval = ipd_check_hooks(ins, IPD_DELAY, delay != 0);
619 ins->ipdn_delay = 0;
624 ipd_toggle_drop(ipd_netstack_t *ins, int percent)
628 ASSERT(MUTEX_HELD(&ins->ipdn_lock));
637 if (percent == ins->ipdn_drop)
640 ins->ipdn_drop = percent;
641 rval = ipd_check_hooks(ins, IPD_DROP, percent != 0);
649 ins->ipdn_drop = 0;
658 ipd_netstack_t *ins;
682 for (ins = list_head(&ipd_nsl); ins != NULL;
683 ins = list_next(&ipd_nsl, ins)) {
684 if (ins->ipdn_zoneid == ipi->ipip_zoneid)
688 if (ins == NULL) {
693 mutex_enter(&ins->ipdn_lock);
695 if (ins->ipdn_status & IPDN_STATUS_CONDEMNED) {
702 rval = ipd_toggle_corrupt(ins, ipi->ipip_arg);
705 rval = ipd_toggle_delay(ins, ipi->ipip_arg);
708 rval = ipd_toggle_drop(ins, ipi->ipip_arg);
713 mutex_exit(&ins->ipdn_lock);
722 ipd_netstack_t *ins;
737 for (ins = list_head(&ipd_nsl); ins != NULL;
738 ins = list_next(&ipd_nsl, ins)) {
739 if (ins->ipdn_zoneid == ipi->ipip_zoneid)
743 if (ins == NULL) {
748 mutex_enter(&ins->ipdn_lock);
758 if (ins->ipdn_status & IPDN_STATUS_CONDEMNED) {
770 ins->ipdn_corrupt = 0;
771 (void) ipd_check_hooks(ins, IPD_CORRUPT, B_FALSE);
776 ins->ipdn_delay = 0;
777 (void) ipd_check_hooks(ins, IPD_DELAY, B_FALSE);
782 ins->ipdn_drop = 0;
783 (void) ipd_check_hooks(ins, IPD_DROP, B_FALSE);
788 mutex_exit(&ins->ipdn_lock);
811 ipd_netstack_t *ins;
849 for (ins = list_head(&ipd_nsl); ins != NULL;
850 ins = list_next(&ipd_nsl, ins)) {
851 if (ins->ipdn_enabled == 0)
856 if (zid == GLOBAL_ZONEID || zid == ins->ipdn_zoneid) {
857 configs[cur].ipii_zoneid = ins->ipdn_zoneid;
859 mutex_enter(&ins->ipdn_lock);
860 configs[cur].ipii_corrupt = ins->ipdn_corrupt;
861 configs[cur].ipii_delay = ins->ipdn_delay;
862 configs[cur].ipii_drop = ins->ipdn_drop;
863 mutex_exit(&ins->ipdn_lock);
868 if (zid != GLOBAL_ZONEID && zid == ins->ipdn_zoneid)
897 ipd_netstack_t *ins;
900 ins = kmem_zalloc(sizeof (ipd_netstack_t), KM_SLEEP);
901 ins->ipdn_status = IPDN_STATUS_DISABLED;
902 ins->ipdn_netid = id;
903 ins->ipdn_zoneid = netstackid_to_zoneid(id);
904 ins->ipdn_rand = gethrtime();
905 mutex_init(&ins->ipdn_lock, NULL, MUTEX_DRIVER, NULL);
907 ins->ipdn_kstat = net_kstat_create(id, "ipd", ins->ipdn_zoneid,
912 if (ins->ipdn_kstat != NULL) {
913 if (ins->ipdn_zoneid != GLOBAL_ZONEID)
914 kstat_zone_add(ins->ipdn_kstat, GLOBAL_ZONEID);
916 ink = &ins->ipdn_ksdata;
917 ins->ipdn_kstat->ks_data = ink;
923 kstat_install(ins->ipdn_kstat);
927 list_insert_tail(&ipd_nsl, ins);
930 return (ins);
936 ipd_netstack_t *ins = arg;
938 VERIFY(id == ins->ipdn_netid);
939 mutex_enter(&ins->ipdn_lock);
940 ASSERT(ins->ipdn_status == IPDN_STATUS_DISABLED ||
941 ins->ipdn_status == IPDN_STATUS_ENABLED);
942 ins->ipdn_status |= IPDN_STATUS_CONDEMNED;
943 if (ins->ipdn_kstat != NULL)
944 net_kstat_delete(id, ins->ipdn_kstat);
945 mutex_exit(&ins->ipdn_lock);
952 ipd_netstack_t *ins = arg;
962 list_remove(&ipd_nsl, ins);
965 if (ins->ipdn_hooked)
966 ipd_teardown_hooks(ins);
967 mutex_destroy(&ins->ipdn_lock);
968 kmem_free(ins, sizeof (ipd_netstack_t));