Hi all, I want to implement a package filtering hook in opensolaris2009.06 111b, and I download Darren's full.c from website, and write my own code, then compile and install the module, but after install the my hook module, the cpu usage is 90%, and can't do anything. at first, I think maybe something wrong in my code, and I build Darren's full.c, and install it, unfortunately, it's same, the cpu usage is 90%. I don't why. who can tell me what's wrong in my code or Makefile?
wl...@opensolaris2009:~/projects/msanet2.2# cc -V cc: Sun C 5.10 SunOS_i386 2009/06/03 usage: cc [ options] files. Use 'cc -flags' for details wl...@opensolaris2009:~/projects/msanet2.2# isainfo -b 64 wl...@opensolaris2009:~/projects/msanet2.2# psrinfo -pv The physical processor has 2 virtual processors (0 1) x86 (GenuineIntel F4A family 15 model 4 step 10 clock 3200 MHz) Intel(r) Pentium(r) 4 CPU 3.20GHz wl...@opensolaris2009:~/projects/msanet2.2# uname -a SunOS opensolaris2009 5.11 snv_111b i86pc i386 i86pc ====== before install msahook module, cpu usage ========= wl...@opensolaris2009:~/projects/msanet2.2# mpstat 5 CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 442 0 31 394 168 734 29 41 41 0 2055 7 4 0 89 1 377 0 10 141 36 749 28 42 39 0 1979 6 3 0 91 CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 0 0 3 307 104 146 1 9 1 0 146 1 0 0 99 1 5 0 2 84 38 110 1 9 1 0 269 1 0 0 98 CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 0 0 2 340 139 152 1 10 2 0 152 1 1 0 98 1 0 0 2 95 41 210 2 11 3 0 381 2 0 0 98 CPU minf mjf xcal intr ithr csw icsw migr smtx srw syscl usr sys wt idl 0 0 0 2 305 103 128 2 12 1 0 188 1 1 0 99 1 6 0 0 91 32 128 3 11 1 0 228 3 0 0 97 ====== after install msahook module, cpu usage ========== the idl value is 10~20, it means the dual cpu are very busy, but I don't know what they busy for. ====== Source Code ============== #include "msa_hook.h" #include "msa_debug.h" net_instance_t *msahook = NULL; msahook_ctx_t *msactx = NULL; msahook_table_t disptable[5000] = {0x0}; // 5000 is for test, will modify later uint32_t disptable_index = 0; kmutex_t disptable_mutex; static void * msahook_create(const netid_t); static void msahook_destroy(const netid_t, void*); static void msahook_shutdown(const netid_t, void*); static int msahook_protocol(hook_notify_cmd_t cmd, void *arg, const char* proto, const char* event, const char* hook); static int msahook_event(hook_notify_cmd_t cmd, void *arg, const char* parent, const char* event, const char *hook); static struct modldrv modlmisc = { &mod_miscops, "msahook module v1.0", }; static struct modlinkage modlinkage = { MODREV_1, &modlmisc, NULL }; int _init(void) { MSA_DEBUG1(">>>_init"); msahook = net_instance_alloc(NETINFO_VERSION); if (msahook != NULL) { msahook->nin_create = msahook_create; msahook->nin_shutdown = msahook_shutdown; msahook->nin_destroy= msahook_destroy; msahook->nin_name = "msahook dispatcher"; if (net_instance_register(msahook) != DDI_SUCCESS) { MSA_DEBUG1("net_instance_register failed."); net_instance_free(msahook); } } mod_install(&modlinkage); MSA_DEBUG1("<<<_init"); } int _fini(void) { MSA_DEBUG1(">>>_fini"); mod_remove(&modlinkage); MSA_DEBUG1("<<<_fini"); } int _info(struct modinfo *info) { MSA_DEBUG1(">>>_info"); MSA_DEBUG1("<<<_info"); return (0); } void * msahook_create(const netid_t id) { MSA_DEBUG1(">>>msahook_create"); msahook_ctx_t *ctx = NULL; int rv = 0; ctx = kmem_zalloc(sizeof(msahook_ctx_t), KM_SLEEP); ctx->instance_id = id; ctx->kssl_addr.s_addr = htonl(KSSL_DEFAULT_ADDR); ctx->kssl_port = htons(KSSL_DEFAULT_PORT); ctx->msa_addr.s_addr = htonl(MSA_DEFAULT_ADDR); ctx->msa_port = htons(MSA_DEFAULT_PORT); MSA_DEBUG2("Allocate ctx - 0x%p", ctx); rv = net_instance_notify_register(id, msahook_protocol, ctx); MSA_DEBUG2("<<<msahook_create - rv: %d", rv); return (ctx); } void msahook_destroy(const netid_t id, void* arg) { MSA_DEBUG1(">>>msahook_destroy"); msahook_ctx_t *ctx = arg; kmem_free(ctx, sizeof(*ctx)); MSA_DEBUG1("<<<msahook_destroy"); } void msahook_shutdown(const netid_t id, void* arg) { MSA_DEBUG1(">>>msahook_shutdown"); msahook_ctx_t *ctx = arg; net_instance_notify_unregister(id, msahook_protocol); if (ctx->v4 != NULL) { if (ctx->hook_in != NULL) { net_hook_unregister(ctx->v4, NH_PHYSICAL_IN, ctx->hook_in); hook_free(ctx->hook_in); ctx->hook_in = NULL; } if (ctx->hook_out != NULL) { net_hook_unregister(ctx->v4, NH_PHYSICAL_OUT, ctx->hook_out); hook_free(ctx->hook_out); ctx->hook_out = NULL; } } MSA_DEBUG1("<<<msahook_shutdown"); } static int msahook_protocol(hook_notify_cmd_t cmd, void *arg, const char* proto, const char* event, const char* hook) { MSA_DEBUG1(">>>msahook_protocol"); msahook_ctx_t *ctx = arg; if (ctx == NULL) { MSA_DEBUG1("ctx is NULL"); return (0); } if (strcmp(proto, NHF_INET) != 0) { MSA_DEBUG2("protocol is not NHF_INET - %s", proto); return (0); } switch(cmd) { case HN_REGISTER: ctx->v4 = net_protocol_lookup(ctx->instance_id, proto); net_protocol_notify_register(ctx->v4, msahook_event, ctx); break; case HN_UNREGISTER: case HN_NONE: break; } MSA_DEBUG1("<<<msahook_protocol"); return (0); } static int msahook_pkthook(hook_event_token_t tok, hook_data_t data, void *ctx) { MSA_DEBUG1(">>>msahook_pkthook"); MSA_DEBUG1("<<<msahook_pkthook"); return (0); } static int msahook_event(hook_notify_cmd_t cmd, void *arg, const char* parent, const char* event, const char *hook) { MSA_DEBUG1(">>>msahook_event"); msahook_ctx_t *ctx = arg; //char buffer[32] = {0x00}; hook_t *hinc, *hout; // all incoming and IPv4 packages if( (strcmp(event, NH_PHYSICAL_IN) == 0) && (strcmp(parent, NHF_INET) == 0) ) { //sprintf(buffer, "msahook_inc_%s_%s", parent, event); hinc = hook_alloc(HOOK_VERSION); hinc->h_hint = HH_NONE; hinc->h_arg = ctx; hinc->h_name = "msahook_inc";//strdup(buffer); hinc->h_func = msahook_pkthook; ctx->hook_in = hinc; net_hook_register(ctx->v4, (char*)event, hinc); } else { hinc = NULL; hout = NULL; } MSA_DEBUG1("<<<msahook_event"); return (0); } ===]>>_info Dec 10 17:38:05 opensolaris2009 msahook: [ID 395548 kern.notice] <<<_info Dec 10 17:38:05 opensolaris2009 msahook: [ID 564022 kern.notice] >>>_init Dec 10 17:38:05 opensolaris2009 msahook: [ID 877698 kern.notice] >>>msahook_create Dec 10 17:38:05 opensolaris2009 msahook: [ID 365319 kern.notice] allocate ctx - 0xffffff0114bbf138 Dec 10 17:38:05 opensolaris2009 msahook: [ID 539202 kern.notice] <<<msahook_create - rv: 0 Dec 10 17:38:05 opensolaris2009 msahook: [ID 757230 kern.notice] <<<_init ------> I don't know why msahook_protocol didn't be called????? -- This message posted from opensolaris.org _______________________________________________ networking-discuss mailing list networking-discuss@opensolaris.org