724 (void) ipf_property_g_update(dip);
725
726 if (ddi_soft_state_init(&ipf_state, sizeof (ipf_devstate_t), 1)
727 != 0) {
728 ddi_prop_remove_all(dip);
729 return (DDI_FAILURE);
730 }
731
732 for (i = 0; ((s = ipf_devfiles[i]) != NULL); i++) {
733 s = strrchr(s, '/');
734 if (s == NULL)
735 continue;
736 s++;
737 if (ddi_create_minor_node(dip, s, S_IFCHR, i,
738 DDI_PSEUDO, 0) == DDI_FAILURE)
739 goto attach_failed;
740 }
741
742 ipf_dev_info = dip;
743
744 ipfncb = net_instance_alloc(NETINFO_VERSION);
745 if (ipfncb == NULL)
746 goto attach_failed;
747
748 ipfncb->nin_name = "ipf";
749 ipfncb->nin_create = ipf_stack_create;
750 ipfncb->nin_destroy = ipf_stack_destroy;
751 ipfncb->nin_shutdown = ipf_stack_shutdown;
752 if (net_instance_register(ipfncb) == DDI_FAILURE) {
753 net_instance_free(ipfncb);
754 goto attach_failed;
755 }
756
757 ipf_minor = vmem_create("ipf_minor", (void *)1, UINT32_MAX - 1,
758 1, NULL, NULL, NULL, 0, VM_SLEEP | VMC_IDENTIFIER);
759
760 #ifdef IPFDEBUG
761 cmn_err(CE_CONT, "IP Filter:stack_create callback_reg=%d", i);
762 #endif
763
764 return (DDI_SUCCESS);
765 /* NOTREACHED */
766 default:
767 break;
768 }
769
770 attach_failed:
771 ddi_remove_minor_node(dip, NULL);
772 ddi_prop_remove_all(dip);
773 ddi_soft_state_fini(&ipf_state);
774 return (DDI_FAILURE);
775 }
776
777
778 static int ipf_detach(dip, cmd)
779 dev_info_t *dip;
780 ddi_detach_cmd_t cmd;
781 {
782 int i;
783
784 #ifdef IPFDEBUG
785 cmn_err(CE_NOTE, "IP Filter: ipf_detach(%p,%x)", dip, cmd);
786 #endif
787 switch (cmd) {
788 case DDI_DETACH:
789 if (ipf_detach_check_all() != 0)
790 return (DDI_FAILURE);
791
792 /*
793 * Undo what we did in ipf_attach, freeing resources
794 * and removing things we installed. The system
795 * framework guarantees we are not active with this devinfo
796 * node in any other entry points at this time.
797 */
798 ddi_prop_remove_all(dip);
799 i = ddi_get_instance(dip);
800 ddi_remove_minor_node(dip, NULL);
801 if (i > 0) {
802 cmn_err(CE_CONT, "IP Filter: still attached (%d)\n", i);
803 return (DDI_FAILURE);
804 }
805
806 vmem_destroy(ipf_minor);
807 ddi_soft_state_fini(&ipf_state);
808
809 (void) net_instance_unregister(ipfncb);
810 net_instance_free(ipfncb);
811
812 return (DDI_SUCCESS);
813 /* NOTREACHED */
814 default:
815 break;
816 }
817 cmn_err(CE_NOTE, "IP Filter: failed to detach\n");
|
724 (void) ipf_property_g_update(dip);
725
726 if (ddi_soft_state_init(&ipf_state, sizeof (ipf_devstate_t), 1)
727 != 0) {
728 ddi_prop_remove_all(dip);
729 return (DDI_FAILURE);
730 }
731
732 for (i = 0; ((s = ipf_devfiles[i]) != NULL); i++) {
733 s = strrchr(s, '/');
734 if (s == NULL)
735 continue;
736 s++;
737 if (ddi_create_minor_node(dip, s, S_IFCHR, i,
738 DDI_PSEUDO, 0) == DDI_FAILURE)
739 goto attach_failed;
740 }
741
742 ipf_dev_info = dip;
743
744 if (ipf_cfw_ring_resize(IPF_CFW_RING_ALLOCATE) != 0)
745 goto attach_failed;
746
747 ipfncb = net_instance_alloc(NETINFO_VERSION);
748 if (ipfncb == NULL)
749 goto attach_failed;
750
751 ipfncb->nin_name = "ipf";
752 ipfncb->nin_create = ipf_stack_create;
753 ipfncb->nin_destroy = ipf_stack_destroy;
754 ipfncb->nin_shutdown = ipf_stack_shutdown;
755 if (net_instance_register(ipfncb) == DDI_FAILURE) {
756 net_instance_free(ipfncb);
757 goto attach_failed;
758 }
759
760 ipf_minor = vmem_create("ipf_minor", (void *)1, UINT32_MAX - 1,
761 1, NULL, NULL, NULL, 0, VM_SLEEP | VMC_IDENTIFIER);
762
763 #ifdef IPFDEBUG
764 cmn_err(CE_CONT, "IP Filter:stack_create callback_reg=%d", i);
765 #endif
766
767 return (DDI_SUCCESS);
768 /* NOTREACHED */
769 default:
770 break;
771 }
772
773 attach_failed:
774 (void) ipf_cfw_ring_resize(IPF_CFW_RING_DESTROY);
775 ddi_remove_minor_node(dip, NULL);
776 ddi_prop_remove_all(dip);
777 ddi_soft_state_fini(&ipf_state);
778 return (DDI_FAILURE);
779 }
780
781
782 static int ipf_detach(dip, cmd)
783 dev_info_t *dip;
784 ddi_detach_cmd_t cmd;
785 {
786 int i;
787
788 #ifdef IPFDEBUG
789 cmn_err(CE_NOTE, "IP Filter: ipf_detach(%p,%x)", dip, cmd);
790 #endif
791 switch (cmd) {
792 case DDI_DETACH:
793 if (ipf_detach_check_all() != 0)
794 return (DDI_FAILURE);
795
796 /*
797 * Undo what we did in ipf_attach, freeing resources
798 * and removing things we installed. The system
799 * framework guarantees we are not active with this devinfo
800 * node in any other entry points at this time.
801 */
802 (void) ipf_cfw_ring_resize(IPF_CFW_RING_DESTROY);
803 ddi_prop_remove_all(dip);
804 i = ddi_get_instance(dip);
805 ddi_remove_minor_node(dip, NULL);
806 if (i > 0) {
807 cmn_err(CE_CONT, "IP Filter: still attached (%d)\n", i);
808 return (DDI_FAILURE);
809 }
810
811 vmem_destroy(ipf_minor);
812 ddi_soft_state_fini(&ipf_state);
813
814 (void) net_instance_unregister(ipfncb);
815 net_instance_free(ipfncb);
816
817 return (DDI_SUCCESS);
818 /* NOTREACHED */
819 default:
820 break;
821 }
822 cmn_err(CE_NOTE, "IP Filter: failed to detach\n");
|