| 771 | }; |
| 772 | |
| 773 | static int |
| 774 | div_modevent(module_t mod, int type, void *unused) |
| 775 | { |
| 776 | int err = 0; |
| 777 | |
| 778 | switch (type) { |
| 779 | case MOD_LOAD: |
| 780 | /* |
| 781 | * Protocol will be initialized by pf_proto_register(). |
| 782 | * We don't have to register ip_protox because we are not |
| 783 | * a true IP protocol that goes over the wire. |
| 784 | */ |
| 785 | err = pf_proto_register(PF_INET, &div_protosw); |
| 786 | if (err != 0) |
| 787 | return (err); |
| 788 | ip_divert_ptr = divert_packet; |
| 789 | ip_divert_event_tag = EVENTHANDLER_REGISTER(maxsockets_change, |
| 790 | div_zone_change, NULL, EVENTHANDLER_PRI_ANY); |
| 791 | break; |
| 792 | case MOD_QUIESCE: |
| 793 | /* |
| 794 | * IPDIVERT may normally not be unloaded because of the |
| 795 | * potential race conditions. Tell kldunload we can't be |
| 796 | * unloaded unless the unload is forced. |
| 797 | */ |
| 798 | err = EPERM; |
| 799 | break; |
| 800 | case MOD_UNLOAD: |
| 801 | /* |
| 802 | * Forced unload. |
| 803 | * |
| 804 | * Module ipdivert can only be unloaded if no sockets are |
| 805 | * connected. Maybe this can be changed later to forcefully |
| 806 | * disconnect any open sockets. |
| 807 | * |
| 808 | * XXXRW: Note that there is a slight race here, as a new |
| 809 | * socket open request could be spinning on the lock and then |
| 810 | * we destroy the lock. |
| 811 | */ |
| 812 | INP_INFO_WLOCK(&V_divcbinfo); |
| 813 | if (V_divcbinfo.ipi_count != 0) { |
| 814 | err = EBUSY; |
| 815 | INP_INFO_WUNLOCK(&V_divcbinfo); |
| 816 | break; |
| 817 | } |
| 818 | ip_divert_ptr = NULL; |
| 819 | err = pf_proto_unregister(PF_INET, IPPROTO_DIVERT, SOCK_RAW); |
| 820 | INP_INFO_WUNLOCK(&V_divcbinfo); |
| 821 | #ifndef VIMAGE |
| 822 | div_destroy(NULL); |
| 823 | #endif |
| 824 | EVENTHANDLER_DEREGISTER(maxsockets_change, ip_divert_event_tag); |
| 825 | break; |
| 826 | default: |
| 827 | err = EOPNOTSUPP; |
| 828 | break; |
| 829 | } |
| 830 | return err; |
nothing calls this directly
no test coverage detected